Hello everybody,
I'm using the sketch Rolling master of big Nick Gammon Gammon Forum : Electronics : Microprocessors : RS485 communications
to make communicating 3 Arduino Nano but I can not send beasts numerical values greater than 255.
in skatch with ID2 I take an analog signal and I would like to receive ID-1 but I get at most 255. I would like to receive the full value to 4 digits.
I had the same problem with the transmission of temperature and humidity value, I had to divide the whole number from the decimal, and send it on two different words, then join them again.
Someone would know help me?
The code of ID1:
// id 1
// software serial pins
const byte RX_PIN = 2;
const byte TX_PIN = 3;
// transmit enable
const byte XMIT_ENABLE_PIN = 4;
// debugging pins
const byte OK_PIN = 6;
const byte TIMEOUT_PIN = 7;
const byte SEND_PIN = 8;
const byte SEARCHING_PIN = 9;
const byte ERROR_PIN = 10;
// action pins (demo)***************************************
const byte LED_PIN13 = 13;
const byte LED_PIN12 = 12;
const byte SWITCH_PINa0 = A0;
const byte SWITCH_PINa1 = A1;
const byte SWITCH_PINa2 = A2;
// Variable - incoming and outgoing************
int analog =0; // test analog rx
int h = 0;
int hd=0;
int ht=0;
int temp=0; // temp.
int td=0; // decimal temp
// Message world **************************
int a6= 0;
int a34 = 0 ;
// demo action pins*******************************************************************
pinMode (SWITCH_PINa0, INPUT_PULLUP);
pinMode (SWITCH_PINa1, INPUT_PULLUP);
pinMode (SWITCH_PINa2, INPUT_PULLUP);
pinMode (LED_PIN13, OUTPUT);
pinMode (LED_PIN12, OUTPUT);
// make our LED match the switch of the previous device in sequence****************
if (message.address == (myAddress - 1))
digitalWrite (LED_PIN13, message.switches [3]);
digitalWrite (LED_PIN12, message.switches [1]);
ht = (message.switches [5]);
hd = (message.switches [6]);
temp = message.switches [7]; // temp
td = message.switches [8]; // decimal temp
analog = (message.switches [a34]);
digitalWrite (OK_PIN, LOW);
} // end of processMessage
// Here to send our own message
void sendMessage ()
{
digitalWrite (SEND_PIN, HIGH);
memset (&message, 0, sizeof message);
message.address = myAddress;
// fill in other stuff here (eg. switch positions, analog reads, etc.)**********************
message.switches [a6] = digitalRead (SWITCH_PINa1);
message.switches [2] = digitalRead (SWITCH_PINa0);
message.switches [9] = digitalRead (SWITCH_PINa2);
message.switches [5] = ht; //umidità
message.switches [6] = hd; // umidita decimale
message.switches [7] = temp; // temp
message.switches [8] = td; // decimal temp
void loop ()
{
// humidity reading*****************
Serial.print("Humidity: ");
Serial.print(ht);
Serial.print(".");
Serial.print(hd);
h= (ht*100)+hd;
Serial.print(" ");
Serial.print(h);
Serial.print(" \t");
// temperature reading *************
Serial.print("Temperatura: ");
Serial.print(temp);
Serial.print(".");
Serial.print(td);
// end temperature*****************
// analog reading******************
Serial.print(" ");
Serial.println(analog);
// incoming message?*****************************
and ID2 :
// id 2
// software serial pins
const byte RX_PIN = 11;
const byte TX_PIN = 13;
// transmit enable
const byte XMIT_ENABLE_PIN = 12;
// debugging pins
const byte OK_PIN = 6;
const byte TIMEOUT_PIN = 7;
const byte SEND_PIN = 8;
const byte SEARCHING_PIN = 9;
const byte ERROR_PIN = 10;
// action pins (demo)***************************************
const byte LED_PIN13 = 2;
const byte LED_PIN12 = 3;
const byte LED_PINa3 = A3;
const byte SWITCH_PINa0 = A0;
const byte SWITCH_PINa1 = A1;
int analog = A7;
// Variable - incoming and outgoing************
int ht = 0; // val humidity
int hd = 0; // decimal humidity
int temp = 0; // temp.
int td = 0; // decimal temp
// Message world **************************
int a34 = 0;
int a1 = 0;
int a2 = 0 ;
// make our LED match the switch of the previous device in sequence***************************************************
if (message.address == (myAddress - 1))
digitalWrite (LED_PIN12, message.switches [9]);
digitalWrite (LED_PIN13, message.switches [9]);
digitalWrite (LED_PINa3, message.switches [9]);
// repeater signals******************************************
ht = message.switches [5] ; //humidity
hd = message.switches [6] ; // decimal humidity
temp = message.switches [7] ; // temp
td = message.switches [8] ; // decimal temp
// end repeater signals**************************************
digitalWrite (OK_PIN, LOW);
} // end of processMessage
// Here to send our own message
void sendMessage ()
{
digitalWrite (SEND_PIN, HIGH);
memset (&message, 0, sizeof message);
message.address = myAddress;
// fill in other stuff here (eg. switch positions, analog reads, etc.)**************************************************
message.switches [a1] = digitalRead (SWITCH_PINa1);
message.switches [a2] = digitalRead (SWITCH_PINa0);
message.switches [a34] = analogRead (analog);
// repeater signals******************************************
message.switches [5] = ht; //humidity
message.switches [6] = hd; // decimal humidity
message.switches [7] = temp; // temp
message.switches [8] = td; // decimal temp
// end repeater signals******************************************
void loop ()
{
Serial.println(analogRead(analog));
// incoming message **********************************