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.
Can anyone help get this board running.
This is my code so far.
#include "Arduino.h"
#include "SoftwareSerial.h"
#define rxPin 12
#define txPin 13
SoftwareSerial MySerial(rxPin, txPin); // RX, TX
long incomingByte = 0;
byte byte0 = B00000000;
byte byte1 = B00000001;
byte byte2 = B10100100;
byte byte3 = B00000000;
byte ByteArray[] = { byte0, byte1, byte2, byte3 };
void setup()
{
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
Serial.begin(9600);
MySerial.begin(19200);
}
void loop()
{
MySerial.write(ByteArray, 4);
Serial.println("Hello world!");
delay(1000);
if (MySerial.available() > 0)
{
incomingByte = MySerial.read(); // read the incoming byte:
Serial.print("I received: "); // say what you got:
Serial.println(incomingByte, BIN);
delay(1000);
}
}