Intro: The Path Mapper
In this IoT project, we wire up a NEO-6M (GPS module) to deliver locational data through the Arduino to an Excel sheet that will be saved on the computer. Afterwards with Tableau Public, we create a data visualization of this data to map out the path we took. While this is one way of collecting and presenting real time data in a highly-correlated data viz, this process can also be applied to other data-driven projects.
Step 1: Acquiring Materials
Step 2: Setting Up the Devices
We first need to set up the GPS module with the Arduino UNO in order for the Arduino to give us an interface to show the data. Each of the four wires connected to the NEO-6M corresponds to specific ports. If your NEO-6M doesn't come with the wires, you'll have to wire it directly with jumper wires.
In the above diagram, red corresponds to power (VCC), black to ground (GND), yellow to transmit data (TxD), and white to receive data (RxD). We connect these wires to male/male jumper wires so we can connect them to the Arduino. Following the diagram above, we connect the ground wire to the GND digital pin on the Arduino, the TxD wire to 4, the RxD wire to ~3, and the VCC wire to 5V for voltage. In a future step, we'll need to define TxD and RxD with the correct numbers in the SoftwareSerial.
Once the two devices are wired up to each other, we need to provide a power source. Connect the USB 2.0 cable to your laptop and the light on the NEO-6M should light up.
Step 3: Coding the Arduino to Extract Data
Now that we have the devices set up to collect GPS data from the satellites, we will write code to parse out the GPS data we want. Assuming you have picked up a signal (my GPS module would blink blue), the NEO-6M by default prints out raw data on the serial monitor in the form of NMEA messages, which look something like $GP followed by more letters and a series of numbers. The image above gives a general idea of what should be shown on your serial monitor once the basic Arduino code is put in.
To explain the code I have attached (or if you'd like to try to code it yourself), you need to first include both the SoftwareSerial and TinyGPS++ libraries (for the latter, Sketch > Include > Add .ZIP library). SoftwareSerial allows us to have a serial connection; TinyGPS++ gives us an easy tool to print out the targeted information in a readable form. Make sure you initialize the SoftwareSerial object to the corresponding pins on the Arduino. In the setup function, we use 9600 as the baud rate.
For the purpose of this instructable, we will only print out seven types of data in the loop function: latitude (degrees), longitude (degrees), speed (km), course (degrees), altitude (km), number of satellites in use, and hdop. You can search up the syntax for printing out this information in the Arduiniana library. The general form is Serial.print(). For example to print out longitude, we would type out Serial.print(gps.location.lng(), 6). The 6 represents how many digits we want to the right of the decimal point.
My code has extra characters printed for the sake of an easily formatted regex in the next step. If you would like to stop at this step however, feel free to format the data differently for ease of view on the serial monitor.
Step 4: Utilizing Processing to Listen
While we have code for the Arduino IDE set up, we have an issue of saving this data. As of right now, we can only view the data on the serial monitor as we're collecting it. There are many ways to log this data but I chose Processing primarily because its interface mimics the Arduino IDE and it uses Java, a language I am familiar with (note that you could also control the Arduino board with Processing if you download Firmata). Processing listens in on the port connected to the Arduino and has the ability to manipulate the data that is read onto the serial monitor. To find the name of this port, refer back to your Arduino IDE file and check in Tools > Port.
I have provided the Processing code, but here is a quick overview for how the code works.
Before the setup function, make sure you have variables for the port, the resulting table, the row we will be working with, and the name of the file. Then in the setup function, there are parameters to set the size of your Run window but those numbers do not affect our functionality (for example, set them to (500, 500)). When you're initializing the port, use the name of the port in String form and a baud rate of 9600. Lastly, create the nine columns (for the seven GPS categories, time, and date) to initialize the table.
In the draw function, we use the built in date and time functions to keep track of when each set of GPS data is extracted. Now to read the stream of data from the Arduino and put it under the appropriate headers with the correct time and date, we utilize regular expressions.
I use regex to parse out the exact data with the matchAll function that looks for any expression between the equal sign and the semicolon (the delimiters I put in my Arduino code). This subsequently places all the matched tags, the numerical data, in a two-dimensional array. We can then call upon these array indices to put them under the headers of the Excel sheet.
To save the new .csv file, we use a key press to close the Run window. The longer you wait to press a key, the more data you will collect. Following the manner of another guide, I also decided to save the file to the data folder with the date and time as the file name.
Step 5: Displaying Data on Tableau Public
The final step involves some data visualization. There are many programs to create and display data visualizations i.e. Plotly, but for this project we will use Tableau. Open up Tableau Public and open the saved Excel file as a text file. To create a worksheet, click on Sheet 1 at the lower left hand.
Since we are working with GPS data, we'll use a map to depict our information. In the left column where it says Measures, we will drag Longitude into Columns and Latitude into Rows at the top. Tableau defaults both measures to AVG, so click on the drop down next to the terms and change both to Dimension. Now the map should have a path displayed using the latitude and longitude values collected.
To clean up your data for error (which can also be done before opening up Tableau), you could choose to exclude some location circles by clicking on them and selecting the option. My GPS module isn't 100% accurate, as some parts of my path have not been located, but the general path has been recorded.
Step 6: Refining the Viz
The last part is to make this data viz more readable. If you want street context, you could go to Map > Map Layer > Streets and Highways. Feel free to experiment with other Marks. I dragged Speed over Color to show how the intensity of the color increases when speed increases. I also used Detail instead of Label for Course because Label would display the numbers on the map whereas I only wanted information to pop up when you hover over the location dots.
Now that you have experienced the whole process of collecting data and displaying what you have on a data visualization, you can apply this to other projects!
by Pingdi Huang, Summer 2018