Manipulating Serial Data to Switch Output On

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

Is there a start and stop condition ?

Some links:

http://training.clipsal.com/downloads/OpenCBus/OpenCBusProtocolDownloads.html

Perhaps you can change the title to "C-Bus and Arduino".

Thanks for the reply

I have all the CBus documentation and read through it already. Maybe I should not have mention CBus, Cbus is not important, it is just to give background on what I am doing. I just want to know how to manipulate the data I receive.

There is no start or stop condition

Regards

From the reading I have done it looks like I will have to use the data type "array"

There is no data type "array".
An array can be of any type, from simple types like "int", to arrays of structures or classes.

There is no start or stop condition

Can you expand on that comment please?

Thank you for the correction, still learning. What data type will suite this? Word?

I am not sure what you guys mean by the stop start condition, this is obviously very important and I am missing something here.

The program must run all the time from power up.

If it sees the bytes with value 0538 it must accept the message as a valid message and process the data ( on/off and which output)

Once this is done it must wait for the next message to come in.

Regards

The question about start and stop relates to how you distinguish when a packet begins and ends, so that you know when to start storing it to an array or parsing the packet, and when to stop.

Dash8:
There is no start or stop condition

Unless the thing that is supplying the data has its own mechanism for denoting message boundaries, you will need to provide some way for your sketch to determine where each message starts within the stream of bytes it is receiving. From your notes about the protocol, I suspect you could do this by looking for a sequence of 050Dxx00 or something like that. You'd need to look at the protocol carefully to check whether it would ever be possible for that sequence of bytes to occur other than at the start of a message - it's not obvious that they can't.

Thanks for the info

The nice thing about this Cbus to serial module is that you can set a parameter to filter only certain messages through. So I will only receive messages that starts with 05_ _ 38.

The module always sends an acknowledgment after each correctly transmitted message that looks like this " g. " If message is not transmitted correctly it will return g!

So I think I can use g. as the stop/start condition. After it has received g. the next thing that will come in is a new message and after the new message there will be another g.

That is the only thing I can think of at this stage