Add Feather M0 internal RTC support

This commit is contained in:
Pierrick C 2018-07-29 16:19:44 +02:00
parent 0c2f6f22a9
commit b8586837c3
1 changed files with 27 additions and 14 deletions

View File

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