I bought a relay board from conrad which has 8 relays which Im trying to control using my arduino one. In the user manual for this relay board it says that each command should exist of 4 bytes with following frame structure:
Byte0: Command, I get to choose between one out of 8 commands
Byte1: Board address, I only have one board so it should be a one
Byte2: Data, information about which relay should be turned on/off
Byte3: Check sum (XOR from Byte0, Byte1 and Byte2)
It seems fairly simple but I can't get it to work. First of all I do not know how to create the check sum so I just ignore it and send in a bunch of zeros, but the relay board also requires a stop bit which I do not know how to create.
A stop bit is an extra bit on the end of data, in this case that would be a 9th bit. Presumably that means adding a 9th bit to those bytes. That might mean you have to size-up from a byte to an int and stick an extra bit on the end.
So for example your current byte1, 00000001 would become 0000000000000011 ... but there are probably better ways of doing this.
Post a link, as UKHB suggested: I can't find an 8-relay board on their site.
You can't just ignore the checksum. Without the correct checksum the board will not work as it will assume that there has been an error in the serial transmission. What do you get back from the board when sending your commands ?
I'm not sure how you would take care of the stop bit: in the case of RS232 that's taken care of by the sending device knowing what to do, outside of the user's application, within the comms intelligence.
UKHeliBob:
The stop bit can be configured using the Serial.begin method, although 1 stop bit is the default in any case. Serial.begin() - Arduino Reference
Ah.... I was looking for a command like Serial.stopbits! Didn't think of looking inside Serial.begin.
So there you go omegaman, that should be you sorted.....