ENG-CANSAT-PICO-MISSION1-CAPTURE

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche

Introduction

The following Wiring is used to capture

  • Air temperature
  • Air pressure

and transmitting the information via the RFM69HCW radio module.

Wiring on a Pico

Wire the barometric sensor

The BMP280 is wired on the I2C bus of the Pico.

ENG-CANSAT-PICO-BMP280-20.jpg

Wire the temperature sensor

Then connect the TMP36 sensor as follows:

  • The pin 1 (on the left) to a power source (3.3V),
  • The pin 3 (the the right) to the ground/GND.
  • The pin 2 (middle one) to the ADC0 (GP26) analog input.

ENG-CANSAT-PICO-TMP36-01.jpg

Wire the radio module

Finally wire the RFM69HCW radio as follows:

ENG-CANSAT-PICO-RFM69HCW-to-Pico.jpg

Here is the description of wiring between the Pico and the RFM69 module.

RFM69HCW PICO
RST
GP3
CS GP5 (Slave Select)
MOSI GP7 (Miso)
MISO GP4 (Mosi)
SCK GP6 (Clock)
GND GND
VIN 3V3

Wiring on Kit Cansat for Pico

Wire the barometric sensor

The Kit Cansat avec Pico does already fire a StemmaQt/Qwiic connector. Just connect the Qwiic/StemmaQt wires between the board and the sensor. The Qwiic connector is wired to the I2C(0) bus.

The BMP280 is wired to the Pico via the Qwiic connector.

ENG-CANSAT-FEATHER-PICO-I2C-02.png

Wire the temperature sensor

Then connect the TMP36 sensor as follows:

  • The pin 1 (on the left) to a power source (3.3V),
  • The pin 3 (the the right) to the ground/GND.
  • The pin 2 (middle one) to the ADC0 (GP26) analog input.

The Pico pad on the board are large enough to quickly solder the TMP36 on the board. The TMP36 can also bee soldered under the board.

ENG-CANSAT-PICO-TMP36-10.png

Wire the radio module

Finally wire the RFM69HCW radio as follows

640px

RFM69HCW UEXT pin PICO Remark
RST GP3
CS GP5 keep the same pin as receiver.
Otherwise use UEXT 10 (=gp10)
MOSI 7 GP4 = MISO
MISO 8 GP7 = MOSI
SCK 9 GP6 = SCK
GND 2 PICO GND
VIN 1 PICO 3.3V

Download the code

The code is available for download on the GitHub associated to this wiki.

Download-icon.pngTéléchargez Mission1 Cansat Emitter script (cansat.py)

Without any comments, extra lines and print statement (used to debug), the script makes 33 lines long for the full fledged features.

As showned in the following picture, the intermediate script testing runs for about 80.000 iterations and message sending without an issue.

ENG-CANSAT-PICO-MISSION1-CAPTURE-10.png

About testing

Now, we will move forward in several steps.

  1. Getting data from sensors + send them it over the REPL/Shell connection (to confirm good working) + transmit over radio
  2. Testing the radio reception
  3. Going autonomous + add the Lipo

The code proposed here under has been tested up to 80000 iterations without issue, time when we decided to ends the test :-) .

Once the script uploaded to your Pico, open the REPL/Shell over the USB-serial (with Thonny, Putty, MPRemote). The script can be started from REPL with import cansat .

You should see the following messages appears on the Serial Monitor.

ENG-CANSAT-PICO-MISSION1-CAPTURE-20.png

Where we could see the transmitted messages with the iteration counter, timing and data.

Structuring the data

The radio module only sends buffer of binary data to the receiver. This is a bit rough but efficient.

So to transport the data to the receiver, we need to transform the values (float, integer) into their string representation.

When having multiple data in their string representation is not enough, they must also been organized.

The final format must be easy to parse and very compact (smaller is the radio message and higher is the chance for him to get to the ground without error).

We propose the following format:

:data1,data2,data3,data4;

where:

  • : is the begin of data stream
  • ; is the end of data stream
  • , is the separator between data items (like CSV format).
  • datax are the string representation of the various data. The characters ;:, are forbidden in this area.

we would also recommend to use:

  • counter as data1. packetnum is a simple variable increment of one unit after each transmission. This would allow the receiver to detect lost message (since it would exist holes in the numbering of received messages).
  • time_sec as data2. This would help to create timing chart or time based data analysis. We suggest to use the time.time() function which count the number of seconds since the last microcontroler reset.

As explained later in the code the msg variable contains the message to be transmitted to the ground. The python language offers facilities to format string and transform typed data to their string representation.

msg = ":%i,%i,%6.2f,%5.2f,%5.2f;" % (counter,time.time()-ctime,hpa,temp,t)
print( msg )
# Send over RFM69HCW module
rfm.send( bytes(msg , "utf-8") )

The ":%i,%i,%6.2f,%5.2f,%5.2f;" string formating use %i to format an integer and %6.2f or %5.2f to format floating point value. The parameter to be formatted are given with the tuple (having 5 entries) just being the % sign.

As the rfm.send() only acept bytes/binary data, the msg is transformed into an array of bytes with bytes() . bytes() array can only contains ASCII < 127, any other character must be appropriately encoded! This is why the call to bytes(msg , "utf-8") mentions the source string encoding (wich is UTF-8 nowadays).


Written by Meurisse D. for MCHobby


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.