My bathroom illumination project is slowly progressing, but I trapped myself in its communication structure:
The Raspi uses an IR motion detector to, erm, detect motions. If he does, a pigpio interrupt fires and sets one gpio pin to high while at the same times it sends a 1 byte command over serial to the Arduino (meaning: make light!).
The Raspi pin is connected to a level shifter which switches on the background lighting of the LED display that shows current weather details and forecasts.
When the motion detector falls back to idle, the pin is set to Low and another byte code is sent via USB, this time “dim the lights”.
So far, everything is working nicely. But when new weather data has been received, the Raspi calculates a few color values and sends them to the Arduino again. This time on a thread and using 24 byte commands.
This is working most of the time, but it looks like it can happen that the one-byte light code is inserted by the interrupt code while sending, and so color values can be changed or the light stops working at all.
I want the light to react immediately, so I dont want to employ the threaded send method that the color routines use.
I think the best would be to use a direct pin to pin-connection for the light: The Arduino could watch one pin and react to level changes, while there will be no interference with my data transmissions anymore.
But what connection type would be recommended? I thought about using another pin of my level shifter but maybe it isnt necessary, but I am a bit concerned about connected both ground lines. Avoid reflow by a diode? Use an optocoupler? What would you recommend?