Using Espressif’s ESP32 MCU
The need for connected smart devices can be found anywhere these days, and that includes paddling sports. In this project article, learn how these Camosun College students built an ESP32 MCU-based device that collects information from paddlers out on the water, and streams data via Bluetooth to an app on the paddler’s phone.
Paddling sports are increasing in popularity in the Pacific Northwest. Outrigger canoe and surf-ski paddlers often seek out rough conditions with the aim to surf on waves. Admittedly, this can be dangerous, due to the inherent risk of capsizing in cold ocean waters. The paddler’s safety could rely on a rescue if a self-recovery were not possible. There is currently no paddling-specific tool to automatically send an alert when a paddler capsizes.
We are a team of four students working on our Capstone Project for our final term at Camosun College in Victoria, British Columbia. The Fairway Gorge Paddling Club, our sponsor, approached us to develop a tool to provide safety monitoring to the club and training metrics to paddlers. Using the skills we’ve gained from our education at Camosun, our team set out to design such a tool. We determined the device must detect capsize events, passively report the location of paddlers back to the club and provide a Bluetooth connection to stream training data to an app on a paddler’s phone. The device we developed to meet these criteria is called the OceanPro Sentinel (Figure 1).
Once we established the requirements for the Sentinel, we set out to choose a cellular modem, GPS receiver, an inertial measurement unit (IMU) and a microcontroller (MCU). We had a turnaround time of three months to build a functional prototype, so a lot of thought went into selecting the hardware. We needed to choose components that were readily available, cost effective and had proven reliability. Figure 2 details the hardware and inter-communication protocols in a flow chart format.
Because there will be an inherent exposure to water, we chose a prefabricated IP67-rated enclosure, which suited our requirements in volume, profile, functionality, cost and aesthetics. However, a waterproof rating is not enough if there are additional points of water ingress, such as external IO connectors, on the case. To further minimize risk of water damage, we incorporated wireless QI charging, to eliminate the need for external connectors.
For the MCU, we chose the ESP32-WROVER-E from Espressif Systems. The chip uses a dual-core Xtensa LX6 processor and features Bluetooth Low Energy (BLE) and I2C and SPI controllers for interfacing with additional sensors. Another key feature of the ESP32 is the ability to run FreeRTOS, which makes scheduling tasks easy. Combined with excellent documentation, its low price and its various power-saving modes, the ESP32 was our first component choice before moving on to the peripheral devices.
Three peripheral devices are connected to the ESP32. The first is an MPU-6050 inertial measurement unit (IMU) from SparkFun, used to measure both the acceleration and orientation of the watercraft. The MPU-6050 is a low-cost and robust solution, combining a MEMS gyroscope and accelerometer with an onboard Digital Motion Processor. The second component is the U-blox NEO-M8Q GNSS receiver. We chose this GNSS receiver because it supports a location update interval up to a maximum of 18Hz, which is necessary for providing accurate, real-time training output for paddlers. The third major component is SIMCom Wireless Solutions’ SIM7070G cellular modem for LTE-M communication. We chose this modem because it is globally compatible with LTE-M networks, and because of its pricing and available documentation. It includes other useful features, such as onboard analog-to-digital converter (ADC) and additional GPIO that can be controlled through serial communication with the module.
After choosing the major components, we began designing the PCB. Our Capstone Project is carried out within a 14 week semester, so we started with the PCB design. Lead times from PCB factories in China concerned us, and we needed to order our PCB quickly to ensure we would have enough time for a design revision, if necessary. To help mitigate issues with signal interference, we employed active antennas for both the GNSS receiver and the cellular modem. Along with adding local decoupling capacitors on each active component, we also minimized trace lengths for high-speed digital signals, matched impedances with any RF signal lines, and used low-inductance power and ground planes. Figure 3 shows a rendered 3D model of our four-layer PCB.
After we finished the design, over 100 surface-mount components were on our PCB. We did not have access to a reflow oven, so we outsourced the fabrication to PCBWay in Shenzhen, China. There were a few setbacks in the design process regarding component sourcing, but we were able to work with PCBWay to solve them by tracking down the parts ourselves, and ensuring the correct components were delivered. While PCBWay was busy constructing our PCB, we began to work on the Sentinel’s firmware and the other hardware considerations, such as the enclosure and batteries.
The Sentinel has two primary modes of operation. In the first mode (passive), the monitor is used strictly as a safety tool. In the second mode (active), the monitor retains all the safety features, but also operates as a training tool for the paddler. The overall firmware layout is detailed throughout the flowchart in Figure 4.
In passive mode, the user is not interacting with the Sentinel. The device sends its GPS data to the server at a set interval, such that the device speed, heading, latitude and longitude can be tracked from a remote location. Meanwhile, if the Sentinel detects a capsize event, it will send out a notification to the server detailing the event, which can then be responded to by personnel.
In active mode, the user can interact with the device. The Sentinel is paired with our companion mobile app, enabling the phone to function as a screen to display the metrics streaming from the device over BLE. Active tracking mode retains the full functionality of passive tracking, while additionally monitoring speed, heading and paddle stroke rate.
The Sentinel is battery powered, so power consumption had been a design factor from the beginning. In passive tracking mode, all peripherals on the device are powered down and the ESP32 is placed into deep-sleep mode, with current consumption in the hundreds of microamperes. Our firmware has the MCU exiting deep sleep every 10 seconds to check the status of the accelerometer, which gets woken up briefly to generate a reading on the Z-axis. In passive tracking mode, the battery lasts for about 2 weeks without requiring a charge.
Active mode requires more power consumption than does passive tracking mode, since the ESP32, cellular modem, GNSS receiver and the IMU are all continually powered on. The added functionality of active mode reduces the battery life to approximately 30 hours of nonstop operation. The small form factor and wireless QI charging allow the device to be easily removed from the boats, and recharged without needing proprietary equipment or tools. To help the user, we included LED indicators displaying the charge status of the device. When the light turns green, the Sentinel is ready to go.
We used two 3,500mA-hour LG Chem MJ1 18650s batteries to power the Sentinel. They are well-tested and proven to be reliable. Due to the dimensions of the enclosure, we had to create a custom battery sled to fit our batteries and hold the buzzer in place. We designed the sled in Autodesk’s Fusion360 before producing it on a 3D printer. To charge the batteries, we are using Consonance Electronic’s CN3065 lithium-ion battery charger IC, a low-cost unit that is easy to set up. To facilitate the higher 1A charging current, we added extra copper pours around the CN3065 to dissipate the additional heat generated by the higher currents. Figure 5 shows the hardware assembled.
We used the PlatformIO extension within Microsoft’s Visual Studio Code to program the ESP32. Created specifically for embedded development, PlatformIO helped us program the ESP32 without having to use the Arduino IDE, which is popular but lacks the professional debug tools offered in other IDEs. Visual Studio Code also integrates seamlessly with Git version control software.
The ESP32’s dual core Xtensa processor with FreeRTOS enabled us to run multiple tasks at the same time, with execution based on task priority. Core 0 handles most of the initializations and wake-ups, and the cellular modem. Core 1 handles the main loops for the GNSS module, BLE transmissions and paddle stroke rate calculations. The benefits of using both cores were instantly apparent: Time-critical operations can be processed at the same time as other lengthy tasks running on a separate core.
Because active mode is centered around stroke rate and speed, we had to ensure the MPU-6050 worked reliably and accurately. We established communication with the module through the I2C protocol. To determine stroke rate, we initialize the digital motion processor on the Sentinel and read processed sensor data live from the FIFO buffer, using interrupt-based function callbacks and continually saving the data in circular buffers. To prevent issues with differing orientation and placement of each device, we calculated the vector sum of the acceleration on each axis before using a low-pass filter to smooth out the high-frequency noise in the acceleration curve. We then used some peak detection algorithms to detect when a stroke had occurred.
Using the U-blox NEO-M8Q, we can get quick GNSS location fixes in passive mode and accurately track the speed of the user to within 0.01km/hour. The libraries for this module were based on UART communication, so we had to modify the library to communicate over SPI, because that was how we configured our PCB. The module outputs raw NMEA sentences, which are then parsed before getting saved onto the device. When not in use, we enable power-saving mode on the receiver, which saves around 25mA. When we want new fix data, the MCU wakes the GNSS module, reading the latitude, longitude and margin of error from the flow of NMEA strings. We continually get new fixes until the combined latitude and longitude error is within a 10m radius, providing an accurate location to send to the database over LTE-M.
The best way to connect to a network was with a cellular modem, since cellular towers are accessible in popular areas of paddling. By interfacing with the SIM7070G modem through UART communication, we can use the ESP32’s hardware serial functionality. We control the modem by a set of manufacturer commands known as AT commands. We used these successfully to connect the modem to our local LTE-M network. Advantages of the LTE-M network include better range than 4G and LTE, and significantly lower power consumption. We are using a Hologram SIM card, which means the device can be used anywhere in the world with a single, unchanging data rate plan.
Communication protocol: Our device can now communicate over the LTE-M network, but what will we do with that connection? The Paddling Club and its staff need a way to monitor the various boats on the water, and a client in a boat needs a convenient way of accessing the device. We decided on several ways to access the generated data. Paddling Club staff needed a visual map to track the location and status of watercraft. Likewise, the paddler needed a way to easily access the live metrics. Above all else, the Sentinel needed a method to communicate all these data over the LTE-M network, without driving up the price of our cellular bill. The flowchart for the software is shown in Figure 6.
We chose MQTT for our communication protocol, because it is both fast and lightweight—perfect for a low-power and low-data-rate application such as ours. After researching broker setups, we chose CloudMQTT, which offers a secure broker service through hosting Mosquitto servers on the Cloud. The service level we selected can handle up to 25 devices connected concurrently. If we ever pursue a larger client base, we can simply scale up with the click of a button to have 10,000 devices connected to our same broker.
Data storage and distribution: For data storage and distribution, we set up a Firebase Realtime Database through the Google Cloud Platform. Firebase is an increasingly popular tool for handing data in mobile and Web applications. It requires a secure Web connection and authorization for viewing and editing the contained data. We designed the database so additional devices won’t require further setup. Just turn on the Sentinel, and it will automatically connect and store the current metrics into a device-specific hierarchy, initialized upon first connection.
By logging onto the Web portal, the user can view the live metrics from each Sentinel on a custom map, complete with moving, directional icons to depict the location of each device. If a capsize or recovery is detected, the map will generate a warning and open a list of all recent capsize event details, with links that pan the viewport to the exact location of the event. Figure 7 is an example map showing actual devices on the water in Victoria, BC.
Paddler metrics for training purposes: Given the limited amount of time for development, we created a mobile application to display the live metrics to the paddler. We developed the app using Flutter, Google’s UI toolkit. Flutter, with Dart as the programming language, is used for developing cross-platform applications under a single codebase. We wanted the app to be as user friendly as possible. By pressing the search button on the bottom right of the screen, the app filters through Bluetooth devices and lists only the available Sentinel devices in range. The screen displays stroke rate, speed, and other metrics upon selecting and connecting to a Sentinel device. We also included a Settings menu, where users can select metrics of interest, switch the app between dark and light modes, change the category of boat for display on the Real-time Map and view the remaining battery percentage of the device. The app is shown in Figure 8.
First off, a mention of COVID-19: At the time of writing this article, the pandemic continues to affect people across the globe. For us and many others in our class, the pandemic completely changed how we approached our Capstone Projects. Fortunately, Camosun supplied our group with the necessary testing equipment to continue our project. Furthermore, our group skirted the issue of not meeting in person by using collaborative tools such as EasyEDA and GitHub. Although it was tough in the beginning, proper version control techniques ended up being fundamental to the success of our project. The overall result was that every struggle grew into an acquired skill. COVID-19 removed our means to work in the same room, but it never took away our ability to work as a team (Figure 9).
We designed the Ocean Pro Sentinel to fill an important void in paddler safety. The Sentinel works passively in the background—always on standby, reporting paddler locations, ready to send an alert in the event of a capsize. Our choice of LTE-M means the Sentinel uses a reliable and widespread network supported by existing infrastructure. By using LTE-M, the Sentinel takes advantage of a global low-power communication technology at a reasonable cost to the end user, utilizing data providers such as Hologram that function worldwide.
The hardware capabilities of our PCB exceed the present operational requirements of our device, leaving the potential for further development using the same hardware. Although the Sentinel was created for a paddling club, it could prove useful for any business renting watercraft or requiring a passive or active tracking solution. With the Sentinel, the staff can monitor the location and the status of a boat with the Real-time Map, and a paddler can use the app to check the metrics needed to improve. Go back and see Figure 1 showing the Sentinel project in its final form.
This final semester was not without its share of mistakes, missteps and miscalculations. All that said, we pulled through and developed a project we are proud of. In the span of three months, we designed, built, tested and launched a device that monitors a boat and its occupant, acting as a virtual lifeline for the paddler. We are proud to have completed the project in a time of considerable uncertainty. We like to think that it will help make the world of ocean sports a little bit safer. And we look forward to seeing you out on the water one day.
Autodesk | www.autodesk.com
CloudMQTT | www.cloudmqtt.com
Consonance Electronic | www.consonance-elec.com
EasyEDA | www.easyeda.com
Espressif Systems | www.espressif.com
Microsoft | www.microsoft.com
PCBWay | www.pcbway.com
SIMCom Wireless Solutions | www.simcom.com
SparkFun Electronics | www.sparkfun.com
U-blox | www.u-blox.com
PUBLISHED IN CIRCUIT CELLAR MAGAZINE • JUNE 2021 #371 – Get a PDF of the issueSponsor this Article
Sandy Charlton was a designer in a previous life and brings over a decade of drafting and modeling experience to the project. He decided to go back to school at Camosun College to accelerate his career and narrow his focus in the field of Electronics Engineering. When not working, he enjoys playing and making video games, cooking, and spending time with his two dogs, Ghost and Spooky.
Rylen Enger worked in Project Management for 5 years prior to enrolling at Camosun. Combining hard-earned skills and newfound knowledge, he has developed multiple electronics and software projects over the course of the program. Rylen will be continuing his education to earn a degree in Electrical Engineering at the University of Victoria.
Dave Hodgson worked in the forest industry before coming to Camosun. Dave applied his knowledge gained from Camosun to a co-op job as a firmware developer over the past summer and plans to continue his education at the University of Victoria. In his spare time Dave enjoys tinkering with electronics and exploring nature with his border collie.
Miles Krakowec Tickner rowed for 4 years before switching to paddling for the past three, competing nationally and internationally for each. Miles has applied his knowledge at Camosun College into multiple electronics projects outside of school, and will continue his learning at the University of Victoria in the future.