Integrate Accelerometer

This commit is contained in:
Aadi Desai 2022-03-01 16:48:55 +00:00
parent 969454b223
commit 4db2a4d34d
No known key found for this signature in database
GPG key ID: CFFFE425830EF4D9
2 changed files with 11 additions and 10 deletions

View file

@ -43,7 +43,7 @@ INT1_DURATION_V = bytes([0x03])
INT1_CFG_V = bytes([0x95])
EMPTY = bytes([0x00])
class lis3dh:
class LIS3DH:
def __init__(self, i2cBus, samplerate=10, i2cAddress=0x18):
sleep(0.005)
self.i2c = i2cBus

19
main.py
View file

@ -2,19 +2,21 @@ import os, sys
from time import sleep
from strictyaml import load, Map, Str, YAMLError
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
dailysteps = 0
fallen = False
def incrementStepCount() -> None:
def incrementStepCount(interrupt, sensor) -> None:
global dailysteps
dailysteps += 1
sensor.resetint2()
def setFallen() -> None:
def setFallen(interrupt, sensor) -> None:
global fallen
fallen = True
sensor.resetint1()
# Setup
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.active = 1 # turn on TMP006
# accel = lis3dh.LIS3DH(bus, 0x18, otherconfigflags) # set up LIS3DH sensor
# TODO: other LIS3DH Setup
step = gpiozero.Button(18, pull_up = False) # GPIO18: Step Counter Interrupt (INT1)
step.when_activated = incrementStepCount # increment step count when Step Counter Interrupt (INT1) is triggered
fall = gpiozero.Button(17, pull_up = False) # GPIO17: Freefall Interrupt (INT2)
fall.when_activated = setFallen # set fallen to True when Freefall Interrupt (INT2) is triggered
accel = lis3dh.LIS3DH(bus, 10, 0x18) # set up LIS3DH sensor
fall = gpiozero.Button(18, pull_up = False) # GPIO17: Freefall Interrupt (INT1)
fall.when_activated = setFallen(fall, accel) # set fallen to True when Freefall Interrupt (INT1) is triggered
step = gpiozero.Button(17, pull_up = False) # GPIO18: Step Counter Interrupt (INT2)
step.when_activated = incrementStepCount(step, accel) # increment step count when Step Counter Interrupt (INT2) is triggered
with open(".secrets.yml", "r") as secrets:
try: