mirror of
https://github.com/supleed2/ELEC60013-ES-CW1.git
synced 2024-11-10 01:35:50 +00:00
Integrate Accelerometer
This commit is contained in:
parent
969454b223
commit
4db2a4d34d
|
@ -43,7 +43,7 @@ INT1_DURATION_V = bytes([0x03])
|
||||||
INT1_CFG_V = bytes([0x95])
|
INT1_CFG_V = bytes([0x95])
|
||||||
EMPTY = bytes([0x00])
|
EMPTY = bytes([0x00])
|
||||||
|
|
||||||
class lis3dh:
|
class LIS3DH:
|
||||||
def __init__(self, i2cBus, samplerate=10, i2cAddress=0x18):
|
def __init__(self, i2cBus, samplerate=10, i2cAddress=0x18):
|
||||||
sleep(0.005)
|
sleep(0.005)
|
||||||
self.i2c = i2cBus
|
self.i2c = i2cBus
|
||||||
|
|
19
main.py
19
main.py
|
@ -2,19 +2,21 @@ import os, sys
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from strictyaml import load, Map, Str, YAMLError
|
from strictyaml import load, Map, Str, YAMLError
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import json, smbus2, si7201, tmp006, hci, gpiozero
|
import json, smbus2, si7201, tmp006, lis3dh, hci, gpiozero
|
||||||
|
|
||||||
# Global Sensor Data Variables
|
# Global Sensor Data Variables
|
||||||
dailysteps = 0
|
dailysteps = 0
|
||||||
fallen = False
|
fallen = False
|
||||||
|
|
||||||
def incrementStepCount() -> None:
|
def incrementStepCount(interrupt, sensor) -> None:
|
||||||
global dailysteps
|
global dailysteps
|
||||||
dailysteps += 1
|
dailysteps += 1
|
||||||
|
sensor.resetint2()
|
||||||
|
|
||||||
def setFallen() -> None:
|
def setFallen(interrupt, sensor) -> None:
|
||||||
global fallen
|
global fallen
|
||||||
fallen = True
|
fallen = True
|
||||||
|
sensor.resetint1()
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
bus = smbus2.SMBus(1) # set up I2C bus 1
|
bus = smbus2.SMBus(1) # set up I2C bus 1
|
||||||
|
@ -25,12 +27,11 @@ temphum.reset() # reset Si7201
|
||||||
irtemp = tmp006.TMP006(bus, 0x41, tmp006.SAMPLERATE_4HZ) # set up TMP006 sensor
|
irtemp = tmp006.TMP006(bus, 0x41, tmp006.SAMPLERATE_4HZ) # set up TMP006 sensor
|
||||||
irtemp.active = 1 # turn on TMP006
|
irtemp.active = 1 # turn on TMP006
|
||||||
|
|
||||||
# accel = lis3dh.LIS3DH(bus, 0x18, otherconfigflags) # set up LIS3DH sensor
|
accel = lis3dh.LIS3DH(bus, 10, 0x18) # set up LIS3DH sensor
|
||||||
# TODO: other LIS3DH Setup
|
fall = gpiozero.Button(18, pull_up = False) # GPIO17: Freefall Interrupt (INT1)
|
||||||
step = gpiozero.Button(18, pull_up = False) # GPIO18: Step Counter Interrupt (INT1)
|
fall.when_activated = setFallen(fall, accel) # set fallen to True when Freefall Interrupt (INT1) is triggered
|
||||||
step.when_activated = incrementStepCount # increment step count when Step Counter Interrupt (INT1) is triggered
|
step = gpiozero.Button(17, pull_up = False) # GPIO18: Step Counter Interrupt (INT2)
|
||||||
fall = gpiozero.Button(17, pull_up = False) # GPIO17: Freefall Interrupt (INT2)
|
step.when_activated = incrementStepCount(step, accel) # increment step count when Step Counter Interrupt (INT2) is triggered
|
||||||
fall.when_activated = setFallen # set fallen to True when Freefall Interrupt (INT2) is triggered
|
|
||||||
|
|
||||||
with open(".secrets.yml", "r") as secrets:
|
with open(".secrets.yml", "r") as secrets:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue