In the simplified example below, my Master sends out the address of a Slave, when the Slave receives its address it should turn on its LED, and turn it off if a different address is received. However this is not the case... I don't seem to be correctly sending and receiving the byte. I know there is Serial activity as I can flash the LED when serial is available. This is an RS485 network with a single Master and currently a single Slave.
Yes - I'm really troubleshooting at the most basic level.
Change SLAVE to this and retest...
Still nothing.
I have now got rid of all circuits boards, and instead have two arduino's connected: RX->TX, TX->RX, sharing ground. Two LEDs on Pins 13 & 12. The code below, still fails to acknowledge the address byte on Pin 13, but pin 12 flash with each byte received....I really don't understand!
{
if (Serial.available())
{
byte inByte = Serial.read();
if (inByte == address)
{
digitalWrite(13, HIGH);
}
Well this wont work because the variable adress have inside a value 0x31 that in decimal is 49 (see ascii table) inbyte variable will have a value 49 (serial.read returns a decimal)
So when you do the compare on the if (if (inByte == address) you are comparing 0x31 with 49 !!!! and so return false
0x31 does == 49 DEC, they are the same at the binary level we just chose to represent them differently on occasion to make code more human readable, but the processor doesn't care.
after you read the byte from the serial port. If it still doesn't work then the problem is local, if it now works you aren't getting the value you think you are.
This is how you divide and conquer to narrow down where the problem is.