Add Feather M0 internal RTC support
This commit is contained in:
parent
0c2f6f22a9
commit
b8586837c3
@ -6,13 +6,16 @@
|
|||||||
print_data = True
|
print_data = True
|
||||||
data_to_neopixel = True
|
data_to_neopixel = True
|
||||||
gps_enable = True
|
gps_enable = True
|
||||||
update_interval = 5.0 # in seconds
|
update_interval = 5 # in seconds
|
||||||
send_json_data = True
|
send_json_data = True
|
||||||
|
datetime_format = "{:04}/{:02}/{:02}_{:02}:{:02}:{:02}"
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
import board, time, microcontroller
|
import board, microcontroller
|
||||||
import gc, micropython, os
|
import gc, os
|
||||||
|
# import micropython
|
||||||
|
import time, rtc
|
||||||
from busio import I2C, UART
|
from busio import I2C, UART
|
||||||
from analogio import AnalogIn
|
from analogio import AnalogIn
|
||||||
|
|
||||||
@ -25,15 +28,19 @@ import neopixel
|
|||||||
###########
|
###########
|
||||||
|
|
||||||
class Data:
|
class Data:
|
||||||
"""Class for handling data format and transmission"""
|
"""Class for handling data"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Read the data from various sensors and update the data dict variable"""
|
"""Read the data from various sensors and update the data dict variable"""
|
||||||
#Data from Feather board
|
#Data from Feather board
|
||||||
self.data['SYS'] = {'v_bat': { 'val': vbat.value*0.000100708, 'unit': 'V' },
|
self.data['SYS'] = {'time': {'val': datetime_format.format(*clock.datetime[0:6]),
|
||||||
'CPU_temp': { 'val': microcontroller.cpu.temperature, 'unit': '°C' }}
|
'unit': '' },
|
||||||
|
'v_bat': {'val': vbat.value*0.000100708,
|
||||||
|
'unit': 'V' },
|
||||||
|
'CPU_temp': {'val': microcontroller.cpu.temperature,
|
||||||
|
'unit': '°C' }}
|
||||||
# Note about v_bat calculation :
|
# Note about v_bat calculation :
|
||||||
# 0.000100708 = 2*3.3/65536 with
|
# 0.000100708 = 2*3.3/65536 with
|
||||||
# 2 : voltage is divided by 2
|
# 2 : voltage is divided by 2
|
||||||
@ -46,16 +53,17 @@ class Data:
|
|||||||
'press': { 'val': bme280.pressure, 'unit': 'hPa' }}
|
'press': { 'val': bme280.pressure, 'unit': 'hPa' }}
|
||||||
if gps_enable:
|
if gps_enable:
|
||||||
if gps.has_fix:
|
if gps.has_fix:
|
||||||
self.data['GPS'] = {'timestamp': '{:04}/{:02}/{:02} {:02}:{:02}:{:02}'.format(gps.timestamp_utc.tm_year,
|
self.data['GPS'] = {'timestamp': {'val': datetime_format.format(gps.timestamp_utc.tm_year,
|
||||||
gps.timestamp_utc.tm_mon,
|
gps.timestamp_utc.tm_mon,
|
||||||
gps.timestamp_utc.tm_mday,
|
gps.timestamp_utc.tm_mday,
|
||||||
gps.timestamp_utc.tm_hour,
|
gps.timestamp_utc.tm_hour,
|
||||||
gps.timestamp_utc.tm_min,
|
gps.timestamp_utc.tm_min,
|
||||||
gps.timestamp_utc.tm_sec),
|
gps.timestamp_utc.tm_sec),
|
||||||
|
'unit': ''},
|
||||||
'lat': {'val': gps.latitude, 'unit': 'deg'},
|
'lat': {'val': gps.latitude, 'unit': 'deg'},
|
||||||
'lon': {'val': gps.longitude, 'unit': 'deg'},
|
'lon': {'val': gps.longitude, 'unit': 'deg'},
|
||||||
'alt': {'val': gps.altitude_m, 'unit': 'm'},
|
'alt': {'val': gps.altitude_m, 'unit': 'm'},
|
||||||
'qual': {'val': gps.fix_quality, 'unit': None}}
|
'qual': {'val': gps.fix_quality, 'unit': ''}}
|
||||||
else:
|
else:
|
||||||
self.data['GPS'] = {'lat': {'val': None, 'unit': 'deg'},
|
self.data['GPS'] = {'lat': {'val': None, 'unit': 'deg'},
|
||||||
'lon': {'val': None, 'unit': 'deg'},
|
'lon': {'val': None, 'unit': 'deg'},
|
||||||
@ -135,7 +143,11 @@ def update_neopixel(data):
|
|||||||
#########
|
#########
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
micropython.mem_info()
|
#micropython.mem_info()
|
||||||
|
|
||||||
|
#Enable RTC of the feather M0 board
|
||||||
|
clock = rtc.RTC()
|
||||||
|
clock.datetime = time.struct_time((2018, 7, 29, 15, 31, 30, 0, 0, 0))
|
||||||
|
|
||||||
# BME280 sensors (I2C)
|
# BME280 sensors (I2C)
|
||||||
i2c = I2C(board.SCL, board.SDA)
|
i2c = I2C(board.SCL, board.SDA)
|
||||||
@ -172,6 +184,7 @@ check_data_dir()
|
|||||||
|
|
||||||
data = Data()
|
data = Data()
|
||||||
last_update = time.monotonic()
|
last_update = time.monotonic()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if gps_enable:
|
if gps_enable:
|
||||||
|
Loading…
Reference in New Issue
Block a user