Move code from M0 express feather board to M4 express board

This commit is contained in:
Pierrick C 2018-08-11 15:57:35 +02:00
parent 69ab6d4c2c
commit 4acb6bee45
2 changed files with 31 additions and 23 deletions

View File

@ -4,13 +4,14 @@ import board
import digitalio
import storage
switch = digitalio.DigitalInOut(board.D5)
switch.direction = digitalio.Direction.INPUT
switch.pull = digitalio.Pull.UP
jumper = digitalio.DigitalInOut(board.D5)
jumper.direction = digitalio.Direction.INPUT
jumper.pull = digitalio.Pull.UP
led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT
# If the D0 is connected to ground with a wire
# CircuitPython can write to the drive
storage.remount("/", switch.value)
led.value = switch.value
storage.remount("/", jumper.value)
led.value = jumper.value
print("Read-only:{}".format(jumper.value))

View File

@ -18,7 +18,7 @@
Author : Pierrick "Arofarn" Couturier
Use with:
* Adafruit Feather M0 Express (CircuitPython firmware)
* Adafruit Feather M4 Express (CircuitPython firmware)
* Adafruit Ultimate GPS FeatherWing
* Bosch BME280 sensor (air temperature, humidity, atmospheric pressure) on I2C
@ -45,7 +45,7 @@ neopixel_max_value =const(70) #max value instead of brightness to spare some mem
#######################
import microcontroller
import microcontroller, board
import gc, os
# import micropython
import time, rtc
@ -200,6 +200,7 @@ class Data:
def check_data_dir():
"""Check if data directories exists"""
try:
if 'data' not in os.listdir():
os.mkdir('data')
os.mkdir('data/hourly')
@ -208,6 +209,12 @@ def check_data_dir():
os.mkdir('data/hourly')
elif 'daily' not in os.listdir('data'):
os.mkdir('data/daily')
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
def set_clock_from_GPS(treshold=5.0):
"""Compare internal RTC and date-time from GPS (if enable and fixed) and set
@ -255,28 +262,28 @@ clock = rtc.RTC()
#clock.datetime = time.struct_time((2018, 7, 29, 15, 31, 30, 0, 0, 0))
# BME280 sensors (I2C)
i2c = I2C(microcontroller.pin.PA23, microcontroller.pin.PA22)
i2c = I2C(board.SCL, board.SDA)
# i2c addresses for BME280 breakout :
# 0x77 = adafruit breakout board
# 0x76 = tiny chinese board
bme280 = Adafruit_BME280_I2C(i2c, address=0x76)
# Battery voltage
vbat = AnalogIn(microcontroller.pin.PA07)
vbat = AnalogIn(board.VOLTAGE_MONITOR)
#Set the pin to control the power to GPS module
gps_en_pin = DigitalInOut(microcontroller.pin.PB02)
gps_en_pin = DigitalInOut(board.A5)
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 = DigitalInOut(board.D13)
led13.direction = Direction.OUTPUT
led13.value = False
# 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,
gps_uart = UART(board.TX, board.RX,
baudrate=9600, timeout=3000)
gps = GPS(gps_uart)
# Turn on the basic GGA and RMC info
@ -285,16 +292,16 @@ if gps_enable:
# Second UART to communicate with raspberry pi (throught GPIO)
if send_json_data:
rpi_uart = UART(microcontroller.pin.PB10, microcontroller.pin.PB11,
rpi_uart = UART(board.D10, board.D11,
baudrate=115200, timeout=2000)
# 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)
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=1)
else:
#if neopixel is disable : turn off the LED
pixel = neopixel.NeoPixel(microcontroller.pin.PA06, 1, brightness=1)
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=1)
pixel[0] = (0,0,0)
pixel = None