Controlling RGB Lighting via Arduino using Byte Arrays

I’m finally starting to get to grips with OpenHAB and the Arduino, and have been able to set up all of my On/Off lighting controlled by rules. But I’m still quite hazy about proper communication with hardware, which shows here.

OpenHAB is set up on my RasPi. My Arduino is connected via USB. So far I have used the serial binding to send commands to my Arduino in the form of strings, which then go through a simple IF statement on the Arudino to find out what output pin to switch on/off, fairly simple.

However, now I want to control some RGB LEDs. I’ve managed a dodgey implementation wherein the RasPi sends out a string, such as Red1=255, and then I use string manipulation to extract the actual value. I realise how horribly inefficient this is, and my rather basic background in programming tells me the best way would be to send the data across as a byte or byte array.

Thing is, while I may be able to know how I want to do something in the abstract, I simply don’t know enough about these languages or the different bindings to implement it (my school taught VB…)

So say I wanted to send a byte array, who’s content would be defined by a rule in OpenHAB, to my Arduino for it to be decoded, how would I go about doing that, or where could I read more on how to do so?

I was hoping that I can use this to replace all of my strings, by having the first byte as an ID for the device to be switched/controlled, and the second byte as the value.

best place to look for answers is at the Arduino forum: http://forum.arduino.cc/

It definitely involves both, though I’m confident that I can process the bytes being received so long as I can find a way to send them, which is more specific to OpenHAB!

Use MQTT as mediator…
E.g. Arduino receives values from MQTT which OH has sent to MQTT…

It is probably worthwhile to think about your architecture, before building things.

As a personal preference: I found that using MQTT as an intermediary has solved or avoided a whole bunch of integration problems for me. It is easy to troubleshoot and test as well, as you can set-up a listener to see / verify who is sending what and when… and OH is nicely working with MQTT.