StratoLab

Lesson 6: Bringing It All Together

Pre-requisites

Objectives

Results

Video Walk-through

In addition to the reading below, you can watch this video for guidance!

Steps

Hardware Configuration and Wiring

IMPORTANT Before wiring your Pico, UNPLUG IT FROM YOUR COMPUTER. If plugged in while wiring, you risk damaging the Pico or SDCard reader.

  1. Wire all the modules into the breadboard according to the pin out below:
    BB = Bread Board Module/Controller Pin | Description | BB/Pi Pico Pins ———– | ———– | ———— ||SD Card Module| VCC | (Voltage Common Collector): Provides power to the HW-125. | BB Power (+) GND | Ground | BB Ground (-) SCK | (Serial Clock): Accepts clock pulses from the Pico to synchronize data transmission | GP10 (14) MOSI | (Master Out Slave In): SPI input to microSD card module | GP11 (15) MISO | (Master In Slave Out): SPI output from the microSD card module | GP12 (16) CS | (Chip Select): Control pin used to select one (or set) of devices on the SPI bus | GP13 (17) ||GPS Sensor VCC | (Voltage In): Provides power. | BB Power (+) GND | Ground | BB Ground (-) 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) ||Pressure Temperature Sensor VIN | (Voltage In): Provides power to the BMP-180. | BB Power (+) GND | Ground | BB Ground (-) SCL | (Serial Clock): Accepts clock pulses from the Pico to synchronize data transmission | GP17 (22) SDA | (Serial Data): Used for data exchange | GP16 (21) ||Raspberry Pico 5V (40) | (Voltage In): Provides power. | BB Power (+) GND (38) | Ground | BB Ground (-)

bringing-it-all-together

WireUp Note: Thumb tack used to hold the GPS antenna up 😋

Main program

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.

  1. Using Thonny, open the main.py file in Lesson 6: /src/main.py.

  2. Verify that your drivers folder contains all the files needed
    files-menu

  3. Run the script.

    run-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.

    output

Congratulations! You have successfully completed Lesson 6.


Want more?

If you have finished with the base lesson, check out the items below.

Update the code to do any/all of the following:

  1. Change the order/format of the output file data to your liking.
  2. Write the output as fast as the modules can be read. What is your speed? 😵

Things to think about, validate, and/or try:

Challenge

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:

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?

Expand to see an example GTU7 function modified to use assert statements You may choose to add this code to your `main.py` as a means to clear contents from the SD card. ```python ... def init_gtu7(test=True): # By defaulting test to `True`, debugging always runs. If you do not want # debugging to run, call this function and pass in a value of `False`. # For example: `gtu7 = init_gtu7(False)` uart = UART(1, baudrate=9600, timeout=3600, tx=Pin(4), rx=Pin(5)) gtu7 = gpsdriver.GTU7(uart) if test: try: assert len(gtu7.gpgga()) == 4 # If the length of GPGGA data returned is anything but 4, fail the test except AssertionError: print("GTU7_GPGGA : ERR") else: print("GTU7_GPGGA : OK") try: assert len(gtu7.gprmc()) == 5 # If the length of GPRMC data returned is anything but 5, fail the test except AssertionError: print("GTU7_GPRMC : ERR") else: print("GTU7_GPRMC : OK") return gtu7 ... ```

Troubleshooting

Reference Material

Need help?

Watch the walk-through video for guidance!