This is my first embedded systems project and my first request for help from a forum.
Basically the goal is to get a Christmas light show as directed by the Pi playing a song over FM transmission while parsing a .csv file (the script of lighting control) using a python script. The Pi would send I2C bytes to addressable Arduino slaves (eventually just atmega328P MCUs) which will perform AC phase control on a set of Christmas lights (Wire library on Arduino and SMBus on the Pi). The intent is that the Pi would send a byte to a unique Arduino address to indicate the level of brightness for the lights (i.e. 0-full brightness, 100-full dim, 101-255 commands reserved for basic fade up/down at various rates). The AC phase control works on the Arduino, no real issue there albeit with 2 interrupts (the zero crossing detection and Timer1 for TRIAC control) perhaps this is part of the problem? I've read that the Wire library also uses interrupts, perhaps the problem lies there, as interrupts are conflicting?
I have successfully written information to the Arduino slave, however I continue to get random and unexplainable IOError as follows:
...
43
44
45
46
47
48
Traceback (most recent call last):
File "i2c.py", line 8, in <module>
bus.write_byte(0x30,((int(a))% 2**8))
IOError: [Errno 5] Input/output error
The test python code I'm using for the write is:
import smbus
import time
bus = smbus.SMBus(1)
a=0
while True:
bus.write_byte(0x30,((int(a))% 2**8))
time.sleep(.1)
#temp = 128-a
print a
if(a==99):
a = 0
a+=1
I've tried my code with and without the Arduino internal pulll-up resistors disabled, with and without 4k7 external resistors. The Pi and Arduino are connected using the adafruit bi-directional level shifter. I've tried writing at slower speeds (just by modifying the sleep variable). The devices are connected essentially on the same breadboard so cable run lengths *shouldn't be an issue as they are with inches of each other.
I honestly just picked this whole thing up as a hobby no more than 3 months ago with a Sparkfun Arduino Uno kit and got hooked. I've learned a ton in that short time, I'm worried though that the solution to this problem may involve either an oscilloscope and or data analyzers which I obviously do not own or even know how to use.
I'm not necessarily committed to using python as the controlling script (in fact I have more experience with Java) and it seems that the documentation for the SMBus is lacking. Does anybody have better luck using Java as the I2C controlling language when communicating from an RPI to Arduino?
Any help at all will be very much appreciated.
The Arduino code is attached.
atmegaI2C_image.ino (6.37 KB)