The next update will be the final project completed !!
Test code of 5 bytes of data from the Arduino to the Raspberry Pi is working and being melded with functionality for meeting the final project goal + some scope creep that just fit in too well.
Thank you to these resources whose examples helped me the most to figure out the code:
https://oscarliang.com/raspberry-pi-arduino-connected-i2c/
https://roboticsbackend.com/raspberry-pi-master-arduino-slave-i2c-communication-with-wiringpi/
https://36projectsblog.wordpress.com/8-raspberry-pi-reading-i2c-sensors-using-python/
I still had to overcome my own stumblings - like reading the Arduino analog values over I2C, reconstructing the values to INT from bytes, then typing in an incorrect scale factor on the high byte.
Added a feature to enable/disable the rotor main motor using the joystick push down switch. Unfortunately I forgot the switch N.O. contact was pulled down to zero rather than a pulled up to 5V.
This is the working Raspberry Pi Python code to read 5 bytes from the Arduino Nano.
I kept some of the code that didnt work in the python file , commented out, as a reminder of how NOT to do it.
The python code looks small, but it involves alot of suffering, mental anguish, and mindless determination :-)
I almost pulled out a scope to start troubleshooting the I2C data, realizing a data analyzer really is the needed tool - I'll be on watch for a Road Test opportunity for one of those :-)
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 = 0x08
IOarray=([ 0,0,0,0,0,0])
## 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:
time.sleep(2)
JoystickData = bus.read_i2c_block_data(0x08, 0x00, 5)
print (" JoystickData=", JoystickData)
LeftRightJoystick=(JoystickData[0]+(JoystickData[1]*256))
print (" LeftRightJoystick =", LeftRightJoystick)
FwdBackJoystick=(JoystickData[2]+(JoystickData[3]*256))
print (" FwdBackJoystick =", FwdBackJoystick)
EnableServos = JoystickData[4]
print (" EnableServos =", EnableServos)
#the array line by byte doesnt work correctly. Shown as a warning to not do it this way
#IOarray[0] = bus.read_byte_data(address,0x00) ## this does not work right to read multiple bytes
#IOarray[1] = bus.read_byte_data(address,0x01) ##right hi byte
#IOarray[2] = bus.read_byte_data(address,0x02) ##back lo byte
#IOarray[3] = bus.read_byte_data(address,0x03) ##fwd hi byte
#IOarray[4] = bus.read_byte_data(address,0x04) ## constant 16
#print ("IOArray[0]=", IOarray[0])
#print ("IOArray[1]=", IOarray[1])
#print ("IOArray[2]=", IOarray[2])
#print ("IOArray[3]=", IOarray[3])
#print ("IOArray[4]=", IOarray[4])
Up Next - the final python code, Arduino code, schematic, and an action video of the working project - sorry Vin Diesel was not available to operate the joystick