More comments and informations
This commit is contained in:
parent
4cc41e8e9a
commit
b767ff9670
@ -33,15 +33,14 @@ __version__ = 0.2
|
||||
##########
|
||||
# config #
|
||||
##########
|
||||
print_data = True
|
||||
send_json_data = True
|
||||
backup_data = True
|
||||
data_to_neopixel = True
|
||||
gps_enable = True
|
||||
update_interval = const(10) # in seconds
|
||||
send_json_data = True
|
||||
datetime_format = "{:04}/{:02}/{:02}_{:02}:{:02}:{:02}"
|
||||
neopixel_max_value =const(70) #max value instead of brightness to spare some mem
|
||||
print_data = True # Print data on USB UART / REPL output ?
|
||||
send_json_data = True # Send data as JSON on second UART ?
|
||||
backup_data = True # Write data as CSV files on onboard SPI Flash ?
|
||||
data_to_neopixel = True # Display atmospheric data as color on onboard neopixel ?
|
||||
gps_enable = True # Use GPS module ?
|
||||
update_interval = const(10) # Interval between data acquisition (in seconds)
|
||||
datetime_format = "{:04}/{:02}/{:02}_{:02}:{:02}:{:02}" # Date/time format
|
||||
neopixel_max_value =const(70) #max value instead of brightness to spare some mem
|
||||
|
||||
#######################
|
||||
|
||||
@ -118,7 +117,7 @@ class Data:
|
||||
|
||||
@property
|
||||
def json(self):
|
||||
"""Serialized data to json-formatted string"""
|
||||
"""Serialized data to compact json-formatted string"""
|
||||
output = '{'
|
||||
first_source = True
|
||||
for source in self.data.keys():
|
||||
@ -150,15 +149,21 @@ class Data:
|
||||
* BLUE => humidity : max= 100%, mini=0%
|
||||
* GREEN => pression : mini=960hPa, maxi = 1030hPa (range 70hPa)
|
||||
"""
|
||||
|
||||
# RED componant calculation from temperature data
|
||||
# 10 is the min temperature, 25 is the range
|
||||
# (10+25=35°C = max temperature)
|
||||
red = int((self.data['BME']['temp']-10)*neopixel_max_value/25)
|
||||
if red > neopixel_max_value:
|
||||
red = neopixel_max_value
|
||||
if red < 0:
|
||||
red = 0
|
||||
|
||||
# BLUE componant calculation: very simple! By definition relative
|
||||
# humidity cannot be more than 100 or less than 0, physically
|
||||
blue = int(self.data['BME']['hum']*neopixel_max_value/100)
|
||||
|
||||
# GREEN component calculation : 960 is the minimum pressure and 70 is
|
||||
# the range (960+70 = 1030hPa = max pressure)
|
||||
green = int((self.data['BME']['press']-960)*neopixel_max_value/70)
|
||||
if green > neopixel_max_value:
|
||||
green = neopixel_max_value
|
||||
@ -181,6 +186,7 @@ class Data:
|
||||
except OSError as e:
|
||||
print("Err {}: readonly".format(e))
|
||||
backup_data = False #to avoid trying again till next reset
|
||||
# Turn onboard led on to indicate read-only error
|
||||
led13.value = True
|
||||
|
||||
#############
|
||||
@ -253,15 +259,17 @@ bme280 = Adafruit_BME280_I2C(i2c, address=0x76)
|
||||
# Battery voltage
|
||||
vbat = AnalogIn(microcontroller.pin.PA07)
|
||||
|
||||
#Set the pin to control the power to GPS module
|
||||
gps_en_pin = DigitalInOut(microcontroller.pin.PB02)
|
||||
gps_en_pin.direction = Direction.OUTPUT
|
||||
|
||||
#Set the pin N°13 to use the onboard LED as read-only/read-write indicator
|
||||
led13 = DigitalInOut(microcontroller.pin.PA17)
|
||||
led13.direction = Direction.OUTPUT
|
||||
led13.value = False
|
||||
|
||||
# GPS on FeatherWing board
|
||||
gps_en_pin.value = not gps_enable
|
||||
# Set GPS module on FeatherWing board
|
||||
gps_en_pin.value = not gps_enable #Set enable pin high to disable GPS module
|
||||
if gps_enable:
|
||||
gps_uart = UART(microcontroller.pin.PA10, microcontroller.pin.PA11,
|
||||
baudrate=9600, timeout=3000)
|
||||
@ -270,12 +278,13 @@ if gps_enable:
|
||||
gps.send_command('PMTK314,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0')
|
||||
gps.send_command('PMTK220,1000') # 1000 ms refresh rate
|
||||
|
||||
# second UART to communicate with raspberry pi GPIO
|
||||
# Second UART to communicate with raspberry pi (throught GPIO)
|
||||
if send_json_data:
|
||||
rpi_uart = UART(microcontroller.pin.PB10, microcontroller.pin.PB11,
|
||||
baudrate=115200, timeout=2000)
|
||||
|
||||
# Integrated Neopixel
|
||||
# Set onboard Neopixel : used as atmo data output
|
||||
# brightness is fixed to 1 to spare some memory. Use neopixel_max_value instead
|
||||
if data_to_neopixel:
|
||||
pixel = neopixel.NeoPixel(microcontroller.pin.PA06, 1, brightness=1)
|
||||
else:
|
||||
@ -284,15 +293,18 @@ else:
|
||||
pixel[0] = (0,0,0)
|
||||
pixel = None
|
||||
|
||||
#Finally check if data directories exist
|
||||
check_data_dir()
|
||||
|
||||
#############
|
||||
# Main loop #
|
||||
#############
|
||||
|
||||
#Create the Data object
|
||||
data = Data()
|
||||
last_update = time.monotonic()
|
||||
|
||||
#Init timer
|
||||
last_update = time.monotonic()
|
||||
while True:
|
||||
|
||||
if gps_enable:
|
||||
|
Loading…
Reference in New Issue
Block a user