#! /usr/bin/env python3 # # For etsting the Pi to Arduino i2c communication and # process. # #| Character | Function | #|+---------+|---------------------------------| #| w | Aim higher #| s | Aim lower #| a | Aim left #| d | Aim right #| r | Increase load arm (see note 1) #| f | reverse load arm (no effect) #| space | Stop all #| L | Move until load switch activates #| F | Fire and reload (see note 2) # #note 1: Arduino will stop automatically when the #load sensor comes on. # #note 2: For "Fire", if the load switch is not activated, it will perform a load #action first, and then move forward until the switch deactivates, and #then load again. The end result is that it is reloaded. import smbus import time bus = smbus.SMBus(1) # Match the arduino SLAVE_ADDRESS = 0x04 #def writeNumber(value): # bus.write_byte(SLAVE_ADDRESS, value) # return -1 # #def readNumber(): # number = bus.read_byte(SLAVE_ADDRESS) # return number while True: var = input("Enter asdwrf, , or F:") if not var: continue try: bus.write_byte(SLAVE_ADDRESS, ord(var[0])) print("Sent '{}' to pi.".format(ord(var[0]))) except: print("Bus I/O Error. ATMega328 may not be powered up.")