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 SDCard reader.
Note: Thumb tack used to hold the GPS antenna up 😋
The steps in this section will use the previous hardware and driver sections to allow writing/reading to/from a CSV file, reading GPS data, and pressure/temperature data. The code example for this lesson is located in Lesson 6: /src/main.py.
Using Thonny, open the main.py
file in Lesson 6: /src/main.py.
Verify that your drivers folder contains all the files needed
Run the script.
Output will be generated to the console in Thonny describing the actions being taken. You will also see a new directory created on the SD card called /sd
if using the example code. Within this folder is a called called data.csv
. You may choose to download this file to your computer and open the file using a program such as Microsoft Excel to read the data in a more familiar program.
Congratulations! You have successfully completed Lesson 6.
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:
Introduce in-line testing for the GTU-7 function.
This challenge will introduce you to using the Python assert keyword to test whether certain conditions in your code return True
or False
. Assertions can be a very useful approach to testing your code when a potential cause for error may already be known. A common example is using a type assertion, or verifying the type of data being used in the program. Simply put, if you expect an int
but a str
exists, your assertion would return False
.
A successful implementation of this code will result in the following:
assert
to validate individual pieces of data being returned from the GTU-7 modulePrint statements indicating a success or failure:
GTU7_GPGGA : OK
GTU7_GPRMC : OK
As you think through this code, also consider how you might add assertions to other functions such as the BMP-180 or SDCard. Additionally, how might this technique prove useful in the field on launch day when a computer is not available? What component is missing from our configuraiton so far that might help us display outputs of our debugging statements?
Errors related to individual modules
If you encounter an error not listed in this section, review the troubleshooting sections of previous lessons for modules you suspect might be causing errors. In each lesson for the modules you will find more example errors and how to fix them.
ERROR: No module named (drivers, sdcard, ...)
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, sdcard.py
and __init__.py
, are saved to the Raspberry Pi Pico device and not your computer.
Example error message:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ImportError: no module named 'drivers'
Validate that the SD card is 32GB or smaller formatted to FAT32 (How to Format SD Card on Mac, Windows, Android and Camera and partitioning)
Watch the walk-through video for guidance!