Nature Trail Mapper With ESP32 and RYS352A GPS Module
by taste_the_code in Circuits > Gadgets
36337 Views, 328 Favorites, 0 Comments
Nature Trail Mapper With ESP32 and RYS352A GPS Module
Today, I'm particularly excited because I've been working on a nifty little gadget using a GPS module – a device tailor-made for recording natural trails in the wild. As you may know, I love both tech and the great outdoors, so combining the two is a real treat.
The core of my homemade GPS mapper is an ESP32 microcontroller to which I've attached a RYS352A GNSS module from Reyax via TX and RX connections on a separate hardware serial port. It's powered by a supply of 3.3 volts and incorporates a data logging shield that houses a microSD card, utilizing the SPI interface for data storage. For user interaction, I installed an LED that visually indicates when the device is recording a GPS track and added a push button to initiate or cease recording. The track is neatly saved onto the microSD card in separate files for each recording session, allowing for easy organization and retrieval of the data once back from the field.
Before we dive in, I want to extend a big thank you to today's sponsor, PCBWay, and their PCBA service. They specialize in high-quality prototyping and small-volume production, ensuring your electronic projects are realized smoothly and professionally. With cutting-edge equipment and a dedicated team, they make development a breeze, whether you need as few as five pieces or more.
Now, let's get our hands on the prototype so I can explain how to make it and how it works.
Supplies
The RYS352A GNSS module used from Reyax can be found on the following links:
- RYS352A website link: https://reyax.com/products/RYS352A
- RYS352A Amazon link: https://www.amazon.com/dp/B0CM5JTJL7?ref=myi_title_dp
- Distributor First Components srl: https://www.first-components.com/en/
Other components and materials used for the project:
- ESP32 Development Board - https://s.click.aliexpress.com/e/_oEeYIs8
- MicroSD Module - https://s.click.aliexpress.com/e/_EzKL6xJ
- Prototype PCBs - https://s.click.aliexpress.com/e/_opd2j9a
- Tactile Switches - https://s.click.aliexpress.com/e/_oEsezyC
- PCB Headers - https://s.click.aliexpress.com/e/_mMw10G6
- Mini Breadboards - https://s.click.aliexpress.com/e/_mNhW5go
- Jumper Cables - https://s.click.aliexpress.com/e/_mqDNJCo
- LEDs Kit - https://s.click.aliexpress.com/e/_EJWj67T
- Assorted Resistors - https://s.click.aliexpress.com/e/_EyOblBn
- Rework Station - https://s.click.aliexpress.com/e/_oBKJvvq
- Multimeter - https://s.click.aliexpress.com/e/_mM2oryg
By buying from the links above, you support my channel at no extra cost to you!
Wiring the RYS352A GPS Module
Wiring up this GPS module is quite straightforward and I must say it is one of the easiest modules I've worked with. For this project, I'm using the Reyax RYS352A module, which is a compact, multi-constellation GNSS module capable of tracking various satellite systems like GPS, GLONASS, Galileo, and BeiDou. Its small size and built-in antenna make it a great fit for portable, outdoor projects like this one.
To connect it to my ESP32, I start by attaching the module's TX (transmit) pin to one of the ESP32's RX (receive) pins assigned for a hardware serial connection (pin 16 in this case). I then connect the module's RX pin to the corresponding TX pin on the ESP32 (pin 17), creating two-way communication between the devices. Powering the module is simple; it only requires a stable 3.3-volt connection from the ESP32, which aligns with the module's operating voltage.
There are multiple ways how you can connect the GNSS module: it features a Molex connector on the back, but I opt to solder header pins for a sturdy and permanent attachment to my device. The GPS module also has an integrated battery to keep the real-time clock running and two LEDs: one to show data communication with the microcontroller and another to indicate the presence of the PPS signal. These feedback elements are incredibly useful when testing the functionality and ensuring a proper setup before heading outdoors for the real-world trial.
Wiring the MicroSD Card Module
The microSD card module is a crucial part of the project, as I use it to store the geographical data we collect. The module comes with pre-soldered pin headers so it is easy to connect it to the ESP's SPI interface.
For the SPI (Serial Peripheral Interface) connection, which is the communication protocol used by the microSD card module, I connect the following pins on the ESP32 to the corresponding pins on the data logging shield:
- MISO (Master In Slave Out) on the ESP32 (pin 19) goes to MISO on the shield.
- MOSI (Master Out Slave In) on the ESP32 (pin 23) to MOSI on the shield.
- SCK (Serial Clock) from the ESP32 (pin 18) to SCK on the shield.
- CS (Chip Select) from a designated GPIO pin on the ESP32 (pin 5) to CS on the shield.
The CS pin is particularly important as it activates the microSD card module when data needs to be written or read. Moreover, the shield needs to be powered, so I connect the 5V and GND pins from the ESP32 to the corresponding 5V and GND on the data logging shield. Typically, the module regulator handles the conversion down to 3.3V necessary for the microSD card to prevent any damage.
If you have one of the module variants that does not come with an onboard regulator, then you need to power it from 3.3V instead.
Wiring the LEDs and the Push Button
To make my GPS tracking device user-friendly, I've incorporated some simple but effective additions: an LED indicator and a push button. These components provide visual feedback and control over the recording process, which is especially handy when I'm out in the field.
Here's how I wire them up:
For the recording LED (red), I chose a digital pin on the ESP32 to control it. I connect the positive, longer leg (anode) of the LED to this pin through a current-limiting resistor, usually around 220 ohms to prevent burning out the LED. The negative, shorter leg (cathode) of the LED goes to one of the ground pins on the ESP32. When I want to indicate that the device is recording, I simply send a HIGH signal to the chosen pin, and the LED lights up.
I incorporate a push button to start and stop recording without needing to interact with the device software or connect to a computer. To wire the push button, I connect one side to a digital pin set with a 10k pull-down resistor on the ESP32. In this case, that is pin 25, but this can be changed to any other digital input. The other side of the button is connected to 3.3V. When the button is pushed, the digital pin reads HIGH since it's being pulled to 3.3V, and I've programmed the ESP32 to react to this change by toggling the recording status.
For an even clearer indication of the device's status, I added another LED (green) to serve as a GPS fix indicator. This LED is connected in the same manner as the first one, with its own digital pin (pin 12) and current-limiting resistor. It lights up when a GPS fix is acquired, assuring me that the location data is accurate and ready to be recorded.
Making a Project PCB
Once I'm satisfied with the functionality of my project on the breadboard, I know it's time to make it more permanent and robust by transferring it to a printed circuit board, or PCB. It's a step up from the somewhat fragile breadboard setup and it makes the device durable and portable.
The best option here is to design a special PCB and have it manufactured by a professional service like PCBWay, but in my case, I opted to build the project on a prototyping PCB instead.
I first soldered headers for each of the components and then used wires to make the electrical connections as explained earlier. This is not as professional as a custom-built PCB, but it is good enough for a once-off prototype build.
Arduino Code Running on the Device
Programming the ESP32 is an essential piece of getting the GPS tracker up and running. I've written the code in Arduino—a platform I find incredibly user-friendly and versatile. If you're following along and crafting your GPS mapper, the full code will be available in the article on my website.
https://www.tastethecode.com/trail-mapping-with-gps-esp32-and-microsd-card
Let's go through the basics of what the code does:
1. The code revolves around using the TinyGPS++ library to parse the GPS data efficiently. It simplifies receiving complex GPS information, such as longitude, latitude, and altitude.
2. I initialize communication with the GPS module via one of the ESP32's UART serial ports, and I set up communication with the microSD card using the SPI protocol.
3. The push button's state is continuously monitored. Depending on its state, the recording starts or stops. This is managed through attached interrupt service routines, which make the response immediate and reliable.
4. Starting a new track involves opening a new file on the microSD card, and this is where I assign filenames incrementally. The initial file content follows the Keyhole Markup Language (KML) format, which is used for geographic visualization in software like Google Earth.
5. Recording a position translates to appending lines with the current latitude, longitude, and altitude in the KML format to the opened file.
6. Once the recording is complete, or if I decide to stop, I finalize the file with the closing tags necessary for the KML format and close the file on the SD card.
The code uses various functions for these tasks, including `finalizeFile()` for ending the recording properly, `getNewFileName()` to calculate the next file name dynamically, and `writeToFile()` for easy appending data to the current file.
In the actual code, you'll see defined pins for the GPS module, SD card, LEDs, button, and necessary variables to manage state and data. It might look daunting at first, but once you start dissecting it piece by piece, you'll see it follows a logical sequence that controls the hardware and manages data.
Feel free to dive into the code and ask any questions in the comments if there's something specific you'd like to know or if you encounter any hitches while replicating this project. Remember, it's all about creating something practical, learning, and having fun along the way.
Testing Out the Tracker
After coding and assembling everything, testing the device is the moment of truth. So, armed with my newly built GPS mapper, I decided it was time to venture outdoors and see how it performed in the wild—literally.
For the field test, I chose a hill in the vicinity of my town as my testing ground. With the push of a button, the LED lit up, and I started recording the first trail. The crisp winter air filled my lungs as I trudged along, with the GPS mapper in my arm. I made sure to closely monitor the new green LED I added, which assured me that the device was indeed capturing a valid location.
After a nice hike to test the tracker's accuracy, I returned home eager to see the fruits of my labor. I carefully dislodged the microSD card from the GPS tracker, slipped it into an adapter, and inserted it into my laptop. The data could finally unveil my path.
Upon opening Google Earth and importing the KML files, I could see the recorded trail come to life on the screen. The 3D view showed the topography I'd crossed, the steady climb, and the spots where I had to navigate around the ice. By importing subsequent files, I sketched out the complete route taken during my adventure, creating an entire mapped-out excursion of multiple segments.
The trails showed up clearly against the satellite images, giving me a tangible sense of accomplishment. The device hadn't just survived the test—it had excelled, capturing three different trails without a hitch. It was a perfect demonstration of how your DIY endeavors can bear practical, enjoyable results. With this successful test, I could envision numerous applications, from guiding hikers on documented paths to discovering and sharing new trails with a community of outdoor enthusiasts.
Next Steps and Future Adventures
Following the success of the field test, there are a few next steps to take this project further. First, I plan to refine the code a bit more for efficiency and perhaps add a few more features or even integrate it with a mobile app. I also see a great opportunity to design a custom enclosure for the device, making it weatherproof and even more outdoor-friendly.
Another step is to share the collected trail data with the community. With the detailed trails mapped, I can contribute to local hiking databases or create a guide for visitors looking to explore the area's natural beauty.
As I wrap up today's Instructable, I can't help but feel invigorated by the seamless fusion of technology and nature. The GPS mapper, a simple bundle of electronics and code, has opened up a new way to explore and document the wilderness. Whether you're an avid hiker, a casual walker, or a tech enthusiast looking for a new project, I hope this walkthrough inspires you to create something that enriches your outdoor experiences.
A big thanks once again to PCBWay for supporting this project, to Reyax for providing awesome modules to test out, and to all of you for tuning in. Your curiosity and engagement drive me to keep inventing and sharing my journey. Don't forget to hit the follow button if you enjoyed this Instructable and subscribe to my YouTube channel for more of my electronic projects and DIY adventures.
Until next time, keep creating, keep exploring, and I'll see you in the next video.
Cheers!