Move code from M0 express feather board to M4 express board
This commit is contained in:
parent
69ab6d4c2c
commit
4acb6bee45
@ -4,13 +4,14 @@ import board
|
|||||||
import digitalio
|
import digitalio
|
||||||
import storage
|
import storage
|
||||||
|
|
||||||
switch = digitalio.DigitalInOut(board.D5)
|
jumper = digitalio.DigitalInOut(board.D5)
|
||||||
switch.direction = digitalio.Direction.INPUT
|
jumper.direction = digitalio.Direction.INPUT
|
||||||
switch.pull = digitalio.Pull.UP
|
jumper.pull = digitalio.Pull.UP
|
||||||
led = digitalio.DigitalInOut(board.D13)
|
led = digitalio.DigitalInOut(board.D13)
|
||||||
led.direction = digitalio.Direction.OUTPUT
|
led.direction = digitalio.Direction.OUTPUT
|
||||||
|
|
||||||
# If the D0 is connected to ground with a wire
|
# If the D0 is connected to ground with a wire
|
||||||
# CircuitPython can write to the drive
|
# CircuitPython can write to the drive
|
||||||
storage.remount("/", switch.value)
|
storage.remount("/", jumper.value)
|
||||||
led.value = switch.value
|
led.value = jumper.value
|
||||||
|
print("Read-only:{}".format(jumper.value))
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
Author : Pierrick "Arofarn" Couturier
|
Author : Pierrick "Arofarn" Couturier
|
||||||
|
|
||||||
Use with:
|
Use with:
|
||||||
* Adafruit Feather M0 Express (CircuitPython firmware)
|
* Adafruit Feather M4 Express (CircuitPython firmware)
|
||||||
* Adafruit Ultimate GPS FeatherWing
|
* Adafruit Ultimate GPS FeatherWing
|
||||||
* Bosch BME280 sensor (air temperature, humidity, atmospheric pressure) on I2C
|
* 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 gc, os
|
||||||
# import micropython
|
# import micropython
|
||||||
import time, rtc
|
import time, rtc
|
||||||
@ -200,14 +200,21 @@ class Data:
|
|||||||
|
|
||||||
def check_data_dir():
|
def check_data_dir():
|
||||||
"""Check if data directories exists"""
|
"""Check if data directories exists"""
|
||||||
if 'data' not in os.listdir():
|
try:
|
||||||
os.mkdir('data')
|
if 'data' not in os.listdir():
|
||||||
os.mkdir('data/hourly')
|
os.mkdir('data')
|
||||||
os.mkdir('data/daily')
|
os.mkdir('data/hourly')
|
||||||
elif 'hourly' not in os.listdir('data'):
|
os.mkdir('data/daily')
|
||||||
os.mkdir('data/hourly')
|
elif 'hourly' not in os.listdir('data'):
|
||||||
elif 'daily' not in os.listdir('data'):
|
os.mkdir('data/hourly')
|
||||||
os.mkdir('data/daily')
|
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):
|
def set_clock_from_GPS(treshold=5.0):
|
||||||
"""Compare internal RTC and date-time from GPS (if enable and fixed) and set
|
"""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))
|
#clock.datetime = time.struct_time((2018, 7, 29, 15, 31, 30, 0, 0, 0))
|
||||||
|
|
||||||
# BME280 sensors (I2C)
|
# BME280 sensors (I2C)
|
||||||
i2c = I2C(microcontroller.pin.PA23, microcontroller.pin.PA22)
|
i2c = I2C(board.SCL, board.SDA)
|
||||||
# i2c addresses for BME280 breakout :
|
# i2c addresses for BME280 breakout :
|
||||||
# 0x77 = adafruit breakout board
|
# 0x77 = adafruit breakout board
|
||||||
# 0x76 = tiny chinese board
|
# 0x76 = tiny chinese board
|
||||||
bme280 = Adafruit_BME280_I2C(i2c, address=0x76)
|
bme280 = Adafruit_BME280_I2C(i2c, address=0x76)
|
||||||
|
|
||||||
# Battery voltage
|
# Battery voltage
|
||||||
vbat = AnalogIn(microcontroller.pin.PA07)
|
vbat = AnalogIn(board.VOLTAGE_MONITOR)
|
||||||
|
|
||||||
#Set the pin to control the power to GPS module
|
#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
|
gps_en_pin.direction = Direction.OUTPUT
|
||||||
|
|
||||||
#Set the pin N°13 to use the onboard LED as read-only/read-write indicator
|
#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.direction = Direction.OUTPUT
|
||||||
led13.value = False
|
led13.value = False
|
||||||
|
|
||||||
# Set GPS module on FeatherWing board
|
# Set GPS module on FeatherWing board
|
||||||
gps_en_pin.value = not gps_enable #Set enable pin high to disable GPS module
|
gps_en_pin.value = not gps_enable #Set enable pin high to disable GPS module
|
||||||
if gps_enable:
|
if gps_enable:
|
||||||
gps_uart = UART(microcontroller.pin.PA10, microcontroller.pin.PA11,
|
gps_uart = UART(board.TX, board.RX,
|
||||||
baudrate=9600, timeout=3000)
|
baudrate=9600, timeout=3000)
|
||||||
gps = GPS(gps_uart)
|
gps = GPS(gps_uart)
|
||||||
# Turn on the basic GGA and RMC info
|
# Turn on the basic GGA and RMC info
|
||||||
@ -285,16 +292,16 @@ if gps_enable:
|
|||||||
|
|
||||||
# Second UART to communicate with raspberry pi (throught GPIO)
|
# Second UART to communicate with raspberry pi (throught GPIO)
|
||||||
if send_json_data:
|
if send_json_data:
|
||||||
rpi_uart = UART(microcontroller.pin.PB10, microcontroller.pin.PB11,
|
rpi_uart = UART(board.D10, board.D11,
|
||||||
baudrate=115200, timeout=2000)
|
baudrate=115200, timeout=2000)
|
||||||
|
|
||||||
# Set onboard Neopixel : used as atmo data output
|
# Set onboard Neopixel : used as atmo data output
|
||||||
# brightness is fixed to 1 to spare some memory. Use neopixel_max_value instead
|
# brightness is fixed to 1 to spare some memory. Use neopixel_max_value instead
|
||||||
if data_to_neopixel:
|
if data_to_neopixel:
|
||||||
pixel = neopixel.NeoPixel(microcontroller.pin.PA06, 1, brightness=1)
|
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=1)
|
||||||
else:
|
else:
|
||||||
#if neopixel is disable : turn off the LED
|
#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[0] = (0,0,0)
|
||||||
pixel = None
|
pixel = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user