For this project, I connected the PmodGPS (GPS module) to the chipKIT WF32 using LabVIEW and LabVIEW MakerHub LINX. This guide will go through how to set up the UART communication, what UART basically is, and how to convert readings from the device into useful information.
Step 1: Materials
LabVIEW Home Bundle can be used for this project and is sold by Digilent. Otherwise, any LabVIEW version can be used including the free trial.
2) chipKIT WF32
3) LabVIEW MakerHub LINX
4) USB A to mini B USB cable
Step 2: Download and Install LabVIEW and LINX
Use this instructable to figure out how to get started with LabVIEW MakerHub LINX. Note that LINX supports many other boards in addition to the chipKIT WF32. Here is the full list of supported devices.
Step 3: UART Setup
UART connections have 4 data channels: RTS "Ready to Send", RX "Receive", TX "Transmit", and CTS "Clear to Send". The RX and TX lines are the ones that actually transmit and receive data so in most cases you can tie RTS and CTS to ground (or sometimes you can even leave them floating). There are also many UART connections that only have RX and TX connections.
An important thing to note about UART connections is that the RX from one board connects to the TX of the other and vice-versa. Now let's take a look at the PmodGPS data sheet here.
There are 6 connections to the PmodGPS. The first is labeled 3DF which indicates the status of the user's positional fix. When the module has a constant fix, the pin stays low and if the module is unable to get a fix then the pin will toggle every second. The second and third pins are the RX and TX lines that actually transmit the information to our board. Pin 4 is called 1PPS which drives the line high for 100ms then low for 900ms and repeats this process (honestly not sure what the point of it is). Then of course we have the ground and 3.3V lines to power the module.
Now that we know the connections, let's hook up the PmodGPS to the chipKIT WF32. The chipKIT WF32 uses UART0 to communicate with LabVIEW so we need to use UART1 (technically the data sheet calls this UART4 but there is a note about how UART4 is accessed using the runtime object Serial1). UART1 are pins 39 and 40. Pin 39 is is the RX channel and pin 40 is the TX channel.
Thus for the PmodGPS we need to connect 3DF and 1PPS to GPIO channels (if you want to read those pins) and we need to connect the RX channel on the PmodGPS to pin 40 on the WF32 and connect TX on the PmodGPS to pin 39 on the WF32. Also connect ground and 3.3V.
Step 4: LabVIEW Code
I created subVIs for the PmodGPS to make it easier to use. I have attached the subVIs below as well as the main example. There is an open VI, a read VI, and a close VI. Extract the zip file to somewhere on your computer. When opening the main VI called "PmodGPS Example", LabVIEW will prompt you to find the three subVIs. Just browse to where you extracted the zip file and select the appropriate subVI.
The open VI is pictured above. It uses the LINX UART Open VI and sets the baud rate to 9600 since that is the baud rate that the PmodGPS runs on by default.
The close VI is also pictured above. It uses the LINX UART Close VI and terminates the connection to the PmodGPS.
Next let's go over how we read the values in greater detail.
Step 5: Convert Readings to Useful Information
Our UART connection is set up and now what we need to do is read the values from our GPS. From the PmodGPS data sheet, we see that it sends data in NMEA sentences. Check out this page to see what the different NMEA sentences are.
To start the read, the first thing we need to focus on is looking for bytes available at the port. Using the UART bytes available VI, we can see how many bytes are sitting in the serial buffer. We can then use the UART read (byte array) to read the serial data at the port as a byte array. Each letter or number sent via UART is in ASCII so if the number 0 is sent, the UART read will read 48 decimal which is 0 in ASCII.
We can use the byte array to string to convert the incoming byte array into the actual NMEA string. You probably have noticed some extra calculations and shift registers but those will be addressed later.
OK we have an NMEA transmission from the GPS. We'll move forward with the example NMEA sentence $GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47.
Our first while loop breaks the transmission by the new line character since each NMEA sentence ends with this. From here, the leftovers are removed and sent into a shift register to add onto the next transmission since that will contain the rest of the sentence.
The first 6 bytes of each broken apart sentence are read to see what data type we have. In this case we read $GPGGA so we send that to a case structure so that we can read the line correctly since not all lines contain the same information. All data is comma separated so we break all the data into multiple strings and then convert those strings to useful information. If you're interested in how I did the other lines, check out the NMEA sentences and the attached LabVIEW code.
Converting readings to useful information is by far the hardest part of UART. Try using this as an example/guide to code your own UART interfaces! If you have any questions, check out the LabVIEW MakerHub Forums.