| Ligne 244 : |
Ligne 244 : |
| | * Send it over the USB-serial connection | | * Send it over the USB-serial connection |
| | * Send it over the radio link | | * Send it over the radio link |
| | + | |
| | + | First, the script will includes all the needed libraries. |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | from machine import SPI, I2C, Pin, ADC |
| | + | from rfm69 import RFM69 |
| | + | from bme280 import BME280, BMP280_I2CADDR |
| | + | import time |
| | + | </syntaxhighlight> |
| | + | |
| | + | This section is immediately followed by the various CONSTANT declaration. |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | FREQ = 433.1 |
| | + | ENCRYPTION_KEY = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08" |
| | + | NODE_ID = 120 # ID of this node |
| | + | BASESTATION_ID = 100 # ID of the node (base station) to be contacted |
| | + | </syntaxhighlight> |
| | | | |
| | {{dbox-orange|Don't forget to update the radio frequency '''FREQ''' and the '''ENCRYPTION_KEY''' encryption key. }} | | {{dbox-orange|Don't forget to update the radio frequency '''FREQ''' and the '''ENCRYPTION_KEY''' encryption key. }} |
| | | | |
| − | First, the script will includes all the needed libraries.
| + | Then we create the needed buses resources to access the various sensor. |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | spi = SPI(0, baudrate=50000, polarity=0, phase=0, firstbit=SPI.MSB) |
| | + | nss = Pin( 5, Pin.OUT, value=True ) |
| | + | rst = Pin( 3, Pin.OUT, value=False ) |
| | + | i2c = I2C(0) |
| | + | </syntaxhighlight> |
| | + | |
| | + | Next we create the RFM69 radio object (named {{fname|rfm}}) and the BMP280 radio object (named {{fname|bmp}}). |
| | + | |
| | + | <syntaxhighlight lang="python"> |
| | + | # RFM Module |
| | + | rfm = RFM69( spi=spi, nss=nss, reset=rst ) |
| | + | rfm.frequency_mhz = FREQ |
| | + | rfm.encryption_key = ( ENCRYPTION_KEY ) |
| | + | rfm.node = NODE_ID # This instance is the node 120 |
| | + | rfm.destination = BASESTATION_ID # Send to specific node 100 |
| | + | # BMP280 (uses the BME280) |
| | + | bmp = BME280( i2c=i2c, address=BMP280_I2CADDR ) |
| | + | </syntaxhighlight> |
| | | | |
| | == Fault tolerant design == | | == Fault tolerant design == |