Skip to content

Instantly share code, notes, and snippets.

@sergiomtzlosa
Created January 5, 2019 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiomtzlosa/ac0bdb416f55b6de1230a298e218e4df to your computer and use it in GitHub Desktop.
Save sergiomtzlosa/ac0bdb416f55b6de1230a298e218e4df to your computer and use it in GitHub Desktop.
#!/bin/python
import smbus
import time
# This is the address we setup in the Arduino Program
address = 0x2d
def writeNumber(value):
try:
bus.write_byte(address, value)
# bus.write_byte_data(address, 0, value)
return -1
except Exception:
pass
def readNumber():
try:
number = bus.read_byte(address)
# number = bus.read_byte_data(address, 1)
return number
except Exception:
pass
while True:
# for RPI version 1, use "bus = smbus.SMBus(0)"
global bus
try:
# Commands to send via i2c:
#
# 0x01 --> Buzzer ON, LEDs OFF
# 0x10 --> Buzzer OFF, LEDs ON
# 0x11 --> Buzzer ON, LEDs ON
var = input("Enter an option: ")
if not var or (var != 0x01 and var != 0x10 and var != 0x11):
continue
bus = smbus.SMBus(1)
time.sleep(1)
writeNumber(var)
print "Sending input to Attiny85 ", var
number = readNumber()
print "Attiny85 received an option: ", number
print ""
time.sleep(2)
writeNumber(0x00)
time.sleep(20)
except Exception:
print "reset bus"
pass
except KeyboardInterrupt:
quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment