Introduction: HackerBoxes 0021: Hacker Tracker
Hacker Tracker: This month, HackerBox Hackers are experimenting with data logging, satellite positioning, and location tracking. This Instructable contains information for working with HackerBoxes #0021. If you would like to receive a box like this right in your mailbox each month, now is the time to subscribe at HackerBoxes.com and join the revolution!
Topics and Learning Objectives for HackerBox 0021:
- Set up the Arduino integrated development environment
- Configure a USB-Serial bridge for the Arduino Nano
- Modify and upload program code to the Arduino Nano
- Read and Write data from the Nano to a flash memory card
- Retrieve data logged to flash memory into a computer
- Set up a GPS satellite positioning module
- Log GPS location data to flash memory
- Retrieve logged GPS data and load it into a mapping system
HackerBoxes is the monthly subscription box service for DIY electronics and computer technology. We are hobbyists, makers, and experimenters. And we are the dreamers of dreams.
Step 2: HackerBoxes 0021: Box Contents
- HackerBoxes #0021 Collectable Reference Card
- Arduino Nano V3 - 5V, 16MHz, MicroUSB
- NEO-6M GPS Module with Integrated Antenna
- MicroSD Card Reader Module
- GY-273 Three-Axis Magnetometer
- 16GB MicroSD Flash Card
- Deluxe Surface Mount PCB Ruler
- MicroUSB Cable
- Tiny USB MicroSD Card Adapter
- Solderless Breadboard
- Jumper Wire Set (65 pieces)
- Exclusive HackerBoxes "Hardware Hackers" Decal
Some other things that will be helpful:
- Soldering iron, solder, and basic soldering tools
- USB 5V Rechargeable Power Bank
- Computer with Arduino IDE
Most importantly, you will need a sense of adventure, DIY spirit, and hacker curiosity. Hardcore DIY electronics is not a trivial pursuit. It's a real challenge and when you persist and enjoy the adventure, a great deal of satisfaction can be derived from learning new technology and hopefully getting some projects working. Just take each step slowly, mind the details, and don't hesitate to ask for help.
FREQUENTLY ASKED QUESTIONS: We would like to ask all HackerBox subscribers a really big favor. Please take a moment to review the FAQ on the website prior to contacting support. The HackerBoxes membership numbers have grown and grown, which is awesome. THANK YOU! However, we are now spending an ever-increasing amount of time answering support emails. Sometimes, several hours a day. While we obviously want to help all members as much as needed, over 80% of our support emails ask simple questions that are very clearly addressed in the FAQ. Tending to these unnecessary inquiries is quite inefficient and takes time away from the creative aspects of our educational mission. And let's be frank, we know that you already understand how tracking numbers work. If you just want to reach out and make conversation, we can certainly come up with something a little more interesting to discuss. Thank you for understanding!
Step 3: Arduino Nano
The Arduino Nano is a surface-mount, breadboard-friendly, miniaturized Arduino board with integrated USB. It is amazingly full-featured and easy to hack.
- Microcontroller: Atmel ATmega328P
- Voltage: 5V
- Digital I/O Pins: 14 (6 PWM)
- Analog Input Pins: 8
- DC Current per I/O Pin: 40 mA
- Flash Memory: 32 KB (2KB for bootloader)
- SRAM: 2 KB
- EEPROM: 1 KB
- Clock Speed: 16 MHz
- Dimensions: 17mm x 43mm
This particular variant of the Arduino Nano is the black Robotdyn design. The interface is by an on-board MicroUSB port that is compatible with the same MicroUSB cables used with many mobile phones and tablets.
Arduino Nanos feature a built-in USB/Serial bridge chip. On this particular variant, the bridge chip is the CH340G. Note that there are various other types of USB/Serial bridge chips used on the various types of Arduino boards. These chips allow you computer's USB port to communicate with the serial interface on the Arduino's processor chip.
A computer's operating system requires a Device Driver to communicate with the USB/Serial chip. The driver allows the IDE to communicate with the Arduino board. The specific device driver that is needed depends upon both the OS version and also the type of USB/Serial chip. For the CH340 USB/Serial chips, there are drivers available for many operating systems (UNIX, Mac OS X, or Windows). The maker of the CH340 supplies those drivers here.
When you first plug the Arduino Nano into a USB port of your computer, the green power light should come on and shortly after the blue LED should start to blink slowly. This happens because the Nano is pre-loaded with the BLINK program, which is running on the brand new Arduino Nano.
Step 4: Arduino Integrated Development Environment (IDE)
If you do not yet have the Arduino IDE installed, you can download it from Arduino.cc
If you would like additional introductory information for working in the Arduino ecosystem, we suggest checking out the instructions for the HackerBoxes Starter Workshop.
Plug the Nano into the MicroUSB cable and the other end of the cable into a USB port on the computer, launch the Arduino IDE software, select the appropriate USB port in the IDE under tools>port (likely a name with "wchusb" in it). Also select "Arduino Nano" in the IDE under tools>board.
Finally, load up a piece of example code:
This is actually the code that was preloaded onto the Nano and should be running right now to slowly blink the blue LED. Accordingly, if we load this example code, nothing will change. Instead, let's modify the code a little bit.
Looking closely, you can see that the program turns the LED on, waits 1000 milliseconds (one second), turns the LED off, waits another second, and then does it all again - forever.
Modify the code by changing both of the "delay(1000)" statements to "delay(100)". This modification will cause the LED to blink ten times faster, right?
Let's load the modified code into the Nano by clicking the UPLOAD button (the arrow icon) just above your modified code. Watch below the code for the status info: "compiling" and then "uploading". Eventually, the IDE should indicate "Uploading Complete" and your LED should be blinking faster.
If so, congratulations! You have just hacked your first piece of embedded code.
Once your fast-flash version of blink is loaded and running, why not see if you can you change the code again to cause the LED to blink fast twice and then wait a couple of seconds before repeating? Give it a try! How about some other patterns? Once you succeed at visualizing a desired outcome, coding it, and observing it to work as planned, you have taken an enormous step toward becoming a competent hardware hacker.
Step 5: Battery Power
While working with the code on the Nano, we use the MicroUSB cable connected to a PC. This cable also supplies power to the Nano.
The easiest way to switch over to mobile (that is, battery powered) operation is to simply plug the USB cable into a USB 5V Power Bank, like this one.
A slightly more integrated option is to use the Nano's on-board voltage regulator connected to the VIN pin. Supplying a 6-9V unregulated power source (such as a battery) to the VIN pin can power the Nano. This is slightly more complicated because you need to consider how the battery is housed, how it is connected to the board, how to provide discharge protection for the battery (particularly if it is a LiPo), and also possibly how to charge the battery. Using a power bank, at least initially, abstracts these issues away in a single solution.
Step 6: Read and Write on MicroSD Flash Card
Adding a flash memory card to an embedded circuit is a great way to log data that can be accessed later. For example, the data may be stored on the card and then loaded, at a later time, into a computer for analysis.
This example shows how to read and write data to and from a MicroSD card.
We will use the code from the official Arduino tutorial.
To keep things simple, we will use the default SPI pin assignments from the tutorial.
SD MODULE - NANO VCC - 5V GND - GND MOSI - pin 11 MISO - pin 12 SCK - pin 13 CS - pin 4
Once the connections are made and the code is loaded, the results can be observed on the serial monitor (set to 9600 baud).
Hit the reset button on the Nano and each time you do, you will notice that there is another "testing 1, 2, 3." line added. This is because the file on the MicroSD card is being appended with the message each time.
Step 7: Reading the MicroSD Data Into a Comupter
The tiny USB adapter for MicroSD cards can be used to connect the MicroSD card to a computer system.
Insert the card into the adapter with the contacts down and plug the adapter into a USB port on any computer. No drivers are required on the computer. The card should show up as a standard USB storage device.
A blue LED will illuminate on the card adapter once everything is properly inserted.
Notice that the card has a file called "test.txt" containing all of the "testing 1, 2, 3." lines appended in the previous step.
Step 8: Satellite Navigation Systems
Satellite navigation (SatNav) uses a system of satellites to determine positioning information. A SatNav system with global coverage is referred to as a global navigation satellite system (GNSS). The United States operates the NAVSTAR Global Positioning System (GPS) and Russia operates GLONASS. China is in the process of expanding its regional BeiDou Navigation Satellite System into the Compass GNSS. The European Union operates the Galileo GNSS scheduled to be fully operational by 2020.
SatNav systems allow small electronic receivers to determine their location (longitude, latitude, and altitude/elevation) to high precision (within a few meters) using time signals transmitted along a line of sight by radio from satellites. The signals also allow the electronic receiver to calculate the current local time to high precision. GPS satellites continuously transmit their current time and position.
A GPS receiver monitors multiple satellites and solves equations to determine the precise position of the receiver and its deviation from true time. At a minimum, four satellites must be in view of the receiver for it to compute four unknown quantities (three position coordinates and clock deviation from satellite time).
Step 9: NEO-6M Satellite Navigation Module
The NEO-6M GPS receiver features high sensitivity, low power consumption, and advanced miniaturization. Its extremely high tracking sensitivity greatly enlarges the coverage of its positioning. It can operate where ordinary GPS receiver modules cannot, such as in narrow urban corridors or dense jungle environment.
The module can be plugged directly to a computer using a MicroUSB cable. This can be done without any wiring to the module, just a USB cable. When power is first applied to the module, the LED will glow steady. Once the satellite signals are acquired and positioning is locked, the LED will start to blink.
Using the Arduino IDE, the GPS module's USB port may be selected. The serial monitor may then be opened and set to 9600 baud rate. GPS data will appear in the NMEA format as specified by the National Marine Electronics Association (NMEA). This data will include the time which you should be able to recognize even though it is in UTC and thus likely shifted from your timezone by an integer number of hours.
Highlight and copy some of this NMEA data from the serial monitor and paste it into a text file.
Browse to the website for GPS Visualizer, select the text file with the NMEA data, and then view the geolocation results on a satellite map.
If you have a Windows computer, you may want to try out the ublox u-center software to read directly from the GPS module.
Step 10: Wire GPS Logger
A GPS position tracking logger can be implemented by combining the NEO-6M GPS module and the MicroSD card module. The measured GPS data can be logged to the MicroSD flash storage.
To use the GPS logger code shown here, the GPS module is wired up to the Nano A1 and A0 pins like so:
GPS - NANO VCC - 5V GND - GND TXD - A1 RXD - A0
The MicroSD card module is wired up as before with its chip select wired to pin 4 of the Nano.
Step 11: Mapping Logged GPS Data From a Computer
GPS data points are read from the NEO-6M and written to the MicroSD flash memory in a file called "gps.txt".
After data collection, the card can be connected to a computer using the USB adapter, and the "gps.txt" file can be selected for upload into GPS Visualizer for mapping.
In the illustrated example, we tracked GPS location points while driving a car from one side of a waterway near the HackerBoxes Headquarters to the other side of the watreway. It is easy to see that some routes are better suited to using a boat.
Step 12: Three-Axis Digital Compass
The GY-273 sensor module is based on the Honeywell HMC5883L (datasheet) 3-axis magnetometer. When it cooperates, the module can be used to implement an electronic compass. This can support adding direction, or orientation, readings to your embedded projects.
The GY-273 can communicate with the Arduino over I2C. This tutorial from Henry's Bench has some useful information on wiring up the module and using the appropriate libraries. This sparkfun guide also had some interesting information.
We have to warn however, that we have had a lot of problems with these HMC5883L modules. They are tricky to get working correctly and the MEMS sensors are prone to damage.
Step 13: Trust Your Technolust
Thank you for joining our adventures into the world of data logging, satellite positioning, and location tracking. If you have enjoyed this Instrucable and would like to have a box of electronics and computer tech projects like this delivered right to your mailbox each month, please join us by SUBSCRIBING HERE.
Reach out and share your success in the comments below and/or on the HackerBoxes Facebook page. Certainly let us know if you have any questions or need some help with anything. Thank you for being part of HackerBoxes. Please keep your suggestions and feedback coming. HackerBoxes are YOUR boxes. Let's make something great!