Created
June 29, 2020 23:25
-
-
Save mikegreen/74d98e87224508c242eac10d024426b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this goes with https://gist.github.com/mikegreen/8a0860901c57e3b02277c82561754a1c | |
import RPi.GPIO as gpio | |
import smbus | |
import time | |
import sys | |
import struct | |
from datetime import datetime | |
bus = smbus.SMBus(1) | |
address = 0x04 | |
def main(): | |
print(str(datetime.now()) + " Starting up...") | |
# gpio.setmode(gpio.BCM) | |
# gpio.setup(17, gpio.OUT) | |
status = False | |
while 1: | |
# gpio.output(17, status) | |
status = not status | |
bus.write_byte(address, 1 if status else 0) | |
time.sleep(3) | |
# print(bus.read_byte(address)) | |
arduinoData = (bus.read_i2c_block_data(address, 0, 32)) # read 32 chars | |
# print(arduinoData); | |
# print("".join(map(chr, arduinoData))) | |
teensyData = ("".join(map(chr, arduinoData))) | |
# print(teensyData.strip()) | |
# print(teensyData) | |
voltsStart = teensyData.find("Volts:",0) | |
voltsEnd = teensyData.find(":",voltsStart) + 1 | |
voltsDataEnd = teensyData.find("|",voltsStart+6) | |
voltsVal = teensyData[voltsEnd:voltsDataEnd] | |
print(str(datetime.now()) + " " + "Volts: " + voltsVal) | |
analogStart = teensyData.find("RawAnalog:",0) | |
analogEnd = teensyData.find(":",analogStart) + 1 | |
analogDataEnd = teensyData.find("|",analogStart+10) | |
analogVal = teensyData[analogEnd:analogDataEnd] | |
print(str(datetime.now()) + " " + "RawAnalog: " + analogVal) | |
time.sleep(1) | |
if __name__ == '__main__': | |
try: | |
main() | |
except KeyboardInterrupt: | |
print('Interrupted') | |
gpio.cleanup() | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment