From b8586837c3da4858e22956e4fbfb8ab010d6dbf9 Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Sun, 29 Jul 2018 16:19:44 +0200 Subject: [PATCH] Add Feather M0 internal RTC support --- circuitpython/main.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/circuitpython/main.py b/circuitpython/main.py index ca14a7e..43ac286 100644 --- a/circuitpython/main.py +++ b/circuitpython/main.py @@ -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: