Thank you for your help. Basically I'll have a master unit asking for up to 16 arduinos the local temperature on a RS-485 BUS. I'm trying to send a poll sequence like T01\r .... up to T15\r to the local arduinos send back the temp status to the master arduino. So, I need to compare the number Txx\r (XX) received by the COM PORT and if its matches, the local arduino addressed will report the temp to the master unit. Here is the code, thank you
#include <stdio.h>
#include <string.h>
int i;
int enablePin = 6;
int address;
int addcomp;
char addressch;
String comrx;
void setup()
{
Serial.begin(19200); // initialize serial at baudrate 9600:
Serial.setTimeout(30); // set serial timeout
pinMode(enablePin, OUTPUT);
pinMode(13, OUTPUT);
pinMode(9, INPUT_PULLUP); // Pin Dip-Switch(1) - address MSB
pinMode(10, INPUT_PULLUP); // Pin Dip-Switch(2)
pinMode(11, INPUT_PULLUP); // Pin Dip-Switch(3)
pinMode(12, INPUT_PULLUP); // Pin Dip-Switch(4) - address LSB
Serial.println("Boot OK");
// convert bits from dip switches to an internal address 0-15
address = byte((!digitalRead(9)*8)+(!digitalRead(10)*4)+(!digitalRead(11)*2)+!digitalRead(12));
Serial.println(address);
Serial.println(address,HEX);
}
void loop() {
if(Serial.available() > 0)
{
comrx = Serial.readStringUntil('\r'); // supposed to receive from COM PORT: "Txx\r" where xx = 00 to 15
Serial.println(comrx);
for (int i = 0; i <= 15; i++) {
char s [10];
sprintf (s, "TO%d", i);
printf (" %4s %4s %4d\n", comrx, s, strcmp (comrx, s));
}
int n;
sscanf (comrx, "TO%d", & n);
printf (" n = %d\n", n);
return 0;
// IF STRING "Txx\r" where xx is the INTERNAL ADDRESS, the unit should report this string out to the COM PORT (RS-485)
if
{
delay(50);
digitalWrite(enablePin, HIGH);
delay(10);
Serial.println("Temp=");
delay(200);
digitalWrite(enablePin, LOW);
}
}
}