Skip to content

Instantly share code, notes, and snippets.

@ProgVal ProgVal/I2C.py forked from Technicus/I2C.py
Created Jul 16, 2014

Embed
What would you like to do?
import smbus
import time
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(1)
# This is the address we setup in the Arduino Program
address = 0x04
def writeNumber(value):
bus.write_byte(address, value)
# bus.write_byte_data(address, 0, value)
return -1
def readNumber():
number = bus.read_byte(address)
# number = bus.read_byte_data(address, 1)
return number
while True:
var = input("Enter 1 - 255: ")
if not var:
continue
writeNumber(var)
print "RPI: Hi Arduino, I sent you ", var
# sleep one second
time.sleep(1)
number = readNumber()
print "Arduino: Hey RPI, I received a digit ", number
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.