In addition to the reading below, you can watch this video for guidance!
IMPORTANT Before wiring your Pico, UNPLUG IT FROM YOUR COMPUTER. If plugged in while wiring, you risk damaging the Pico or GT-U7 module.
Wire the GT-U7 to the Raspberry Pi Pico. GT-U7 Pins | Description | Pi Pico Pins ———— | ———– | ———— VCC | (Voltage In): Provides power. Connect to the 5V pin on Pico | 5V (40) GND | (Ground): Connect to the ground pin on Pico | GND (38) PPS | (Pulse Per Second): Assists with synchronization | N/A TXD | (Transmit): Transmission pin used for serial communication | UART1 RX / GP5 (7) RXD | (Receive): Receiver pin used for serial communication | UART1 TX / GP4 (6)
Drivers are code modules for enabling certain functionality. One such driver allows us to read data from the GTU-7 module. This driver is called gtu7.py
and is located in the Raspberry Pi Pico /drivers/src/ location. The following steps will result in saving this driver to the Raspberry Pi Pico so the driver can be used by our Python code.
Download the driver called gtu7.py
located in the Raspberry Pi Pico /drivers/src/ location to a directory/file/location of your choice. Remember where you downloaded the driver to for a later step.
Connect your Raspberry Pi Pico to your computer using the USB cable.
Open the Thonny IDE. Stop/Restart the backend to refresh the connection.
You should now see Raspberry Pi Pico
displayed in the left-hand navigation of Thonny.If the “Files” window is not displaying add it from the View > Files menu.
If one does not already exist, create a new directory in Thonny on the Raspberry Pi Pic called drivers
.
Using Thonny, select File then Open from the menu. Choose This Computer. Navigate to the location where you downloaded gtu7.py
in step 1. Select the file and click Open.
Save the gtu7.py
file to the Raspberry Pi Pico. This allows our code to use the driver to perform GT-U7 actions in MicroPython when running on the Pi Pico.
Click File then Save as…. Choose Raspberry Pi Pico. Double-click the drivers
folder created in a previous step. Then save the gtu7.py
file being sure to name it gtu7.py
.
If a file called __init__.py
does not already exist in the /drivers
folder, create a new file in Thonny called __init__.py
.
Click File then New. Then click File then Save as…. Choose Raspberry Pi Pico and save this empty file to the same drivers
location as the previous step. Name the file __init__.py
. This empty file is used by Python to indicate the drivers
folder is to be used for Python modules.
Your finished folders and files should look like this:
The steps in this section will use the previous hardware and driver sections to allow reading temperature, pressure, and altitude from the GT-U7 module. The code example for this lesson is located in Lesson 4: /src/main.py.
Using Thonny, open the main.py
file in Lesson 4: /src/main.py.
Run the script.
Output will be generated to the console in Thonny describing the actions being taken. You will see output for latitude, longitude, number of satellites, and time returned from the GPS module.
Example output:
Latitude: 4026.774
Longitude: -8902.08
Satellites: 6
Time: 18:46:14
In some locations, such as the center of a building or in a basement, the GPS module cannot receive a GPS signal. To aid in these scenarios, an update was made to the GTU7 module to support “fake” data returned similar to real data. This can be useful for testing purposes, or to gain familiarity with what to expect as a response.
If you want to generate fake data, use the following syntax for either GPGGA data or GPRMC data. Note the use of fake=True
being passed in.
:information_source: TypeError: unexpected keyword argument ‘fake’
The fake data feature was added to the GTU7 module in an update. If you encounter the unexpected argument error, follow the steps earlier in the lesson on installing the GTU7 driver, ensuring you are using the latest copy of the driver located in this project.
gpgga_data = gps_module.gpgga(fake=True)
gprmc_data = gps_module.gprmc(fake=True)
Congratulations! You have successfully completed Lesson 4.
If you have finished with the base lesson, check out the items below.
Update the code to do any/all of the following:
Things to think about, validate, and/or try:
Modify your code to handle exceptions.
This challenge will introduce you to using Python Try Except code blocks for exception handling. The Try Except code block is very useful in handling errors and exceptions from functions or code attempts. In its basic implementation, this code block tries something, except if something unexpected happens (like an error), try something else. If all else fails, finally take one last action.
A successful implementation of this code will result in the following:
IndexError: list index out of range
HINT: One method of recreating this error is by flipping the TX and RX wires.As you think through this code, also consider how it might be applied to previous lessons. Similarly, keep this code in mind for future lessons. It is a useful approach for offering more informed responses to errors, or alternatively taking new actions if an error is encountered.
ERROR: No GPS data returned
If you are not receiving GPS data, the following may be the case:
ERROR: No module named (drivers, bmp180, ...)
If you see this error it means Python is not able to locate a module to be imported. This can occur because the version of MicroPyhon you are using does not support the module you are trying to import. Specifically for this lesson it likely applies to the drivers
step. Ensure the drivers
folder and its contents, gtu7.py
and __init__.py
, are saved to the Raspberry Pi Pico device and not your computer.
Also be aware the case-sensitivity of the drivers
folder name (lower case) and how its referenced in your Python code. Be sure everything is in lower case.
Example error message:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ImportError: no module named 'drivers'
ERROR: IndexError: list index out of range
Specific to the code in this lesson, this error occurs when we attempt to format the GPS data for printed output, but there is no data to format. In other words we are attempted to format an empty array. The cause for no data being returned could be related to:
Example error message:
Traceback (most recent call last):
File "<stdin>", line 22, in <module>
IndexError: list index out of range
ERROR: TypeError: unexpected keyword argument 'fake'
On occasion the drivers will be updated. The GTU7 driver received an update that allowed fake data to be created in the scenario where GPS signal cannot be acquired. If the user attempts to pass in fake=True
and receives this error, the GTU7 driver is out of date. Follow the steps in the lesson above to install the GTU7 driver, overwriting the existing version on your Pi Pico.
Example error message:
Traceback (most recent call last):
File "<stdin>", line 19, in <module>
TypeError: unexpected keyword argument 'fake'
Watch the walk-through video for guidance!