Différences entre versions de « ENG-CANSAT-PICO-RFM69HCW-TEST »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 246 : Ligne 246 :
 
Only the script content will changes between the emitter and the receiver.
 
Only the script content will changes between the emitter and the receiver.
  
=== Option 1 : as the receiver ===
+
=== Wiring option 1 : as the receiver ===
 
wiring (visible here before) is identical to the receiver wiring.
 
wiring (visible here before) is identical to the receiver wiring.
  
Ligne 253 : Ligne 253 :
 
(see the [[ENG-CANSAT-PICO-RFM69HCW-TEST#Wiring|Receiver]] section for more details about the connections).
 
(see the [[ENG-CANSAT-PICO-RFM69HCW-TEST#Wiring|Receiver]] section for more details about the connections).
  
=== Option 2: with the Kit Cansat for Pico ===
+
=== Wiring option 2: with the Kit Cansat for Pico ===
 
{{pl|2271|Kit Cansat avec Raspberry-Pi Pico}} have a Raspberry-Pi Pico soldered onboard. The RFM69 module can be soldered on the UEXT connection points available between the Pico and the Ribbon connector.  
 
{{pl|2271|Kit Cansat avec Raspberry-Pi Pico}} have a Raspberry-Pi Pico soldered onboard. The RFM69 module can be soldered on the UEXT connection points available between the Pico and the Ribbon connector.  
  

Version du 3 mars 2022 à 22:58

Forewords

It is now time to establish a communication between:

  • a Data Emitter (CanSat) made with a raspberry-Pico + RFM69HCW-433MHz.
  • a Data Receiver (Base Station) made with the second RFM69HCW coupled to another Pico microcontroler.

As the kit contains contains two Pico microcontroller we will be able to create the "Data Emitter" on the CanSat as well as the Data Receiver at the ground station.

In this simple example:

  1. The Data Emitter will send a message and wait 500ms for a response (ACK).
  2. The Data Receiver will receive the message.
  3. The Data Receiver will send a ACK reply.

ENG-CANSAT-PICO-RFM69HCW-TEST-00.jpg

As we will see, there are 2 key items to be highlighted:

  1. The frequency must be identical in the emitter and the receiver (eg: 433.1 MHz in this example).
  2. The encryption key must be identical on the both side.

Installing the RFM69 library

The Adafruit's FRM69HCW are provided with a MicroPython library available on GitHub.

You can download and copy the library manually to your board from the Repository.

Download-icon.pngDownload RFM69 library

First, open the repository, then navigate to the file lib/rfm69.py .

Follow the steps describes in the "BMP280 library installation" to copy the RFM69 library to your micropython board.

Once copied, you can also check the proper installation by typing from rfm69 import * .

The RFM69 library repository contains many examples of usage. Do not hesitate to check them!

About Antennas

For this example, a simple wire twisted in the antenna hole will do a great job for testing.

Please wait before soldering the wire inside the antenna hole!. The antenna hole can be populated with:

The antenna design is a key feature to ensure a reliable communication over a long distance.

A µFl connector (also named uFl) is looking to this:

ENG-CANSAT-RFM69HCW-TEST-uFL-connector.jpg

A PCB SMA Connector is looking to this:

ENG-CANSAT-RFM69HCW-TEST-SMA-connector.jpg

Frequency, Encryption & Power

To make the module communicating together:

  • The module must be identical. You cannot mix them.
  • The tuned frequency must be identical.
  • The encryption key must be identical.

Tuned frequency

The tuned frequency is declared with a line like this:

...
rfm = RFM69( spi=spi, nss=nss, reset=rst )
rfm.frequency_mhz = 433.1

where the tuned frequency is directly assigned to the frequency_mhz property.

In packet radio, several teams can share the same frequency if they use distinct encryption key.

Like TCP (from TCP/IP network), the packet radio is able to detect packet collision and try to recover from it.

However, more teams share the same frequency, more collision we have.

Encyption Key

The module encrypts the data with AES-128.

The encryption key is defined with 16 bytes and assigned to the encryption_key property.

The code here below defines the key 1234567812345678 under binary format.

...
rfm = RFM69( spi=spi, nss=nss, reset=rst )
rfm.encryption_key = (  b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" )

It is also possible to defines the same key with a more user friendly code.

...
rfm = RFM69( spi=spi, nss=nss, reset=rst )
rfm.encryption_key = bytes( [1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8] )


When all the teams do use the same frequency and the same key then they will all receives the messages from the other teams also sending messages. Your messages will also been received by all the other teams.

Transmission Power

The transmission power is set to 13 dBm by default (it is safer across all RFM modules, the library also work for RFM95).

The transmission power can be set from 14 to 20 dBm by assigning the tx_power property.

Lowest values requires less power. Less power means higher battery life but also smaller transmission distance.

rfm = RFM69( spi=spi, nss=nss, reset=rst )
# rfm.tx_power = 13  # 13 dBm = 20mW (default value, safer for all modules)
rfm.tx_power = 20 # 20 dBm = 100mW, 20 dBm for FRM69HW only

Tips & Tricks:
It is possible to estimate the transmission power (in milliWatts) by using the following function.

def dbm_to_mw(dBm):
	""" Transform the power in dBm to its equivalent in milliWatt """
	return 10**((dBm)/10.)

Check the wiring

Before showing the details of the wiring diagrams, here is a "tip" helping to check it!

The following script "test-rfm69/test_config.py" (TODO TODO TODO TODO) from the cansat-belgium-micropython contact the RFM69 module to initialize it and read back properties.

If the script can properly establish a communication with the module, it will returns the following results:

RFM version     : 36
Freq            : 433.1
Freq. deviation : 250000.0 Hz
bitrate         : 250000.0 bits/sec
tx power        : 13 dBm
tx power        : 19.95262 mW
Temperature     : 23 Celsius
Sync on         : yes
Sync size       : 1
Sync Word Length: 2 (Sync size+1)
Sync Word       : bytearray(b'-\xd4')
crc on          : 1
Preamble Lenght : 4
aes on          : 1
Encryption Key  : bytearray(b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08')

The Receiver

We will prepare our receiver station.

The receiver stays on the ground and receives the message sent by the Emitter and forward them to a computer.

This will involve:

  • The second RFM69HCW 433 Mhz module
  • A Pico microcontroler
  • A computer to read the messages (forwared by the microcontroler)
  • An wire antenna

Wiring

Here how to wire the RFM69 module to the Raspberry-Pi Pico.

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

The code

Now we will load and executes the test_receiver.py receiver script. The script must be downloaded from the repository.

TODO DOWNLOAD

The script can be either executed from Thonny -OR- transfered to the Pico and executed directly on the microcontroler.

It will output the messages on the REPL/Shell over the serial line.

The frequency and encryption key must be updated from team to team to avoids messages collisions and cross-over transmission between the teams.

As the organisator for your team frequency according to the Frequency Plan


Update for frequency plan, encryption key:

  • The frequency used by the receiver RFM69HCW must be exactly the same as the emitter!
  • The Encryption key used by the receiver RFM69HCW must be exactly the same as the emitter!
  • The Node ID is the target node id (0..255) where the emitter must sent the messages.

Locate the following lignes:

FREQ           = 433.1
ENCRYPTION_KEY = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
NODE_ID        = 100 # ID of this node

And update the value for FREQ and ENCRYPTION_KEY.

The NODE_ID doesn't have to be updated, its is used as node identifier allowing message & ACK exchange between one receiver and several emitter (each having an unique NODE_ID (for the same ENCRYPTION_KEY and FREQ).

Openning the Serial Line:

As we want to see the received message, we will open a terminal to receives the messages over the USB-Serial line.

This can be done with the help of:

  • Thonny IDE (that will automatically open the USB-Serial port)
  • Putty (just open the USB-Serial port)
  • mpremote

Just starts the script and wait for the messages to come:

ENG-CANSAT-PICO-RFM69HCW-TEST-20.png

Voilà, We are ready to test the emitter (cansat).

The Emitter

The emitter can be made 2 different ways (shown below).

The wiring is, in facts, identical in the two options (and identical to receiver).

Only the script content will changes between the emitter and the receiver.

Wiring option 1 : as the receiver

wiring (visible here before) is identical to the receiver wiring.

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

(see the Receiver section for more details about the connections).

Wiring option 2: with the Kit Cansat for Pico

Kit Cansat avec Raspberry-Pi Pico have a Raspberry-Pi Pico soldered onboard. The RFM69 module can be soldered on the UEXT connection points available between the Pico and the Ribbon connector.

UEXT can manage almost all the signals, only RST and SS must be soldered directly on the Pico GPIOs pins. For sure, if you want to solder all the connection directly to the Pico GPIO, you can also do the connection that way.

Here how to wire the RFM69 module to the base board of Cansat Kit with Pico as recommended.

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

More info

Understanding script content

Reading the sketch would help to understand how the code works. The scripts contains many comments.

Addressed & Reliable Communication

More complex setup could used addressed communication and Reliable Datagram.

  • Addressed communication allows you to associate a unique identifier (node id, an integer from 0..255) to each RFM69 module. This allows detect the sender when receiving a message on the frequency and to act appropriately properly.
  • Reliable Datagram do a lot of management with connection to make sure that the packets were received. You do not have to send the acknowledgement in your code, the Reliable Datagram take care of it for you.

Check the examples associated the RFM69 library for more informations.


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.