Modifications

Sauter à la navigation Sauter à la recherche
Ligne 247 : Ligne 247 :  
First, the script will includes all the needed libraries.
 
First, the script will includes all the needed libraries.
   −
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python">from machine import SPI, I2C, Pin, ADC
from machine import SPI, I2C, Pin, ADC
   
from rfm69 import RFM69
 
from rfm69 import RFM69
 
from bme280 import BME280, BMP280_I2CADDR
 
from bme280 import BME280, BMP280_I2CADDR
Ligne 256 : Ligne 255 :  
This section is immediately followed by the various CONSTANT used in the script.
 
This section is immediately followed by the various CONSTANT used in the script.
   −
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python">FREQ          = 433.1
FREQ          = 433.1
   
ENCRYPTION_KEY = b"\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08"
 
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
 
NODE_ID        = 120 # ID of this node
Ligne 267 : Ligne 265 :  
Then we create the needed buses resources to access the various sensor.
 
Then we create the needed buses resources to access the various sensor.
   −
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python">spi = SPI(0, baudrate=50000, polarity=0, phase=0, firstbit=SPI.MSB)
spi = SPI(0, baudrate=50000, polarity=0, phase=0, firstbit=SPI.MSB)
   
nss = Pin( 5, Pin.OUT, value=True )
 
nss = Pin( 5, Pin.OUT, value=True )
 
rst = Pin( 3, Pin.OUT, value=False )
 
rst = Pin( 3, Pin.OUT, value=False )
Ligne 276 : Ligne 273 :  
Next we create the RFM69 radio object (named {{fname|rfm}}) and the BMP280 radio object (named {{fname|bmp}}).
 
Next we create the RFM69 radio object (named {{fname|rfm}}) and the BMP280 radio object (named {{fname|bmp}}).
   −
<syntaxhighlight lang="python">
+
<syntaxhighlight lang="python"># RFM Module
# RFM Module
   
rfm = RFM69( spi=spi, nss=nss, reset=rst )
 
rfm = RFM69( spi=spi, nss=nss, reset=rst )
 
rfm.frequency_mhz  = FREQ
 
rfm.frequency_mhz  = FREQ
Ligne 289 : Ligne 285 :  
At the end of initialization section, we do creates the instances for the analog reading (the TMP36, named {{fname|adc}}) and LED controling (named {{fname|led}}).
 
At the end of initialization section, we do creates the instances for the analog reading (the TMP36, named {{fname|adc}}) and LED controling (named {{fname|led}}).
   −
<syntaxhighlight lang="python">  
+
<syntaxhighlight lang="python"> # TMP36 analog pin
# TMP36 analog pin
   
adc = ADC(Pin(26))
 
adc = ADC(Pin(26))
 
# Onboard LED
 
# Onboard LED
Ligne 298 : Ligne 293 :  
Just before the main loop, the script print the essential data.
 
Just before the main loop, the script print the essential data.
   −
<syntaxhighlight lang="python">  
+
<syntaxhighlight lang="python"># Main Loop
# Main Loop
   
print( 'Frequency    :', rfm.frequency_mhz )
 
print( 'Frequency    :', rfm.frequency_mhz )
 
print( 'encryption    :', rfm.encryption_key )
 
print( 'encryption    :', rfm.encryption_key )
Ligne 309 : Ligne 303 :  
</syntaxhighlight>
 
</syntaxhighlight>
    +
=== Main Loop execution ===
 
The main loop is composed of an infinite {{fname|while}} loop.
 
The main loop is composed of an infinite {{fname|while}} loop.
   −
<syntaxhighlight lang="python">  
+
<syntaxhighlight lang="python"># Iteration counter
# Iteration counter
   
counter = 1
 
counter = 1
 
# ctime contains the time (in seconds) when the script was stared
 
# ctime contains the time (in seconds) when the script was stared
29 917

modifications

Menu de navigation