Good day everybody.
I am new to the forum and Arduino. My house lights work on the CBus automation system and I am busy with a project where I read the serial data of the CBus protocol into my Adruino board.
I have a Cbus to Serial converter board which is connected to the serial input of my Adruino board (pin 1 , ,2 ). This is a standard CBus board and handles all the protocol specific functions. It converts CBus data to serial data output and converts your serial input to CBus data.
What I am trying to do is to take this serial message I receive on my Adruino board and then switch on a specific output of the Adruino, depending on the specific message that arrives.
Below is the format of the message received on the Adruino. It is HEX Characters.
050D3800792D10 here is a breakdown of the meaning
05 Means it is a lighting message
0D Hex address of the unit(light switch) sending the message
38 Standard lighting application for CBus
00 Must always be 00 otherwise message must be ignored
79 Is the light ON command
2D is the Group address, this is the address of the output to be switched on
10 this is the checksum generated and based on the 2's compliment of the modulo 256 sum of the preceding bytes
The OFF message from the light switch looks exactly the same but instead of 79, 01 is used as off. And the checksum is different.
So the things that will change in the message is the Group address and the actual command and the checksum.
At this stage I want the Adruino to do the following:
Look at character 1and 2 and 5 and 6 if they are 0538 then the program can continue. ( this is to ensure that it only reacts on lightning messages)
Character 3 and 4 can be ignored, does not matter what light switch sends the message.
So if it detects 0538 it must now look at the group address ( in this case 2D)
Now it must look at the command on or off 79 or 01
If it is 79 and 2D the for example output 13 must be switched on
If it is 01 and 2D the output 13 must be switched off.
What I have done so far. I have connected the 2 Boards together and they are talking to each other and I am receiving the messages on the adruino and can see them in the serial monitor.
// Cbus 5000SM module to Relay output Board
int character = 0; // for incoming serial data
int ledPin = 13; // defining LED pin number
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode (13, OUTPUT); // setting pin 13 as an output
}
void loop()
{
if (Serial.available() > 0)
{
character = Serial.read();
{
Serial.write(character);
}
}
}
The code so far is just to get the serial comms between the 2 units going. Now I need to get the manipulation of this data going, I am stuck here. From the reading I have done it looks like I will have to use the data type "array" and then look for these specific values.
If anybody can point me in the right direction regarding how to write this code it will be great.
Regards