RS485_non_blocking for send value [HALF SOLVED]

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  **********************************

Some part of the sketch was cut because of space limited, refer to Sketc 'Rolling Master' of this link:

As illustrated on my page you quoted, you can send and receive a "struct" which can be multiple bytes.

Thanks for the reply Nick,

but what I need to change to send a numeric value greater?

or do I divide by reassemble in the receiver?

With this code:

// fill in other stuff here (eg. switch positions, analog reads, **************************
 
  
  message.switches [a34] = analogRead (analog);

I put in the variable a34 the value read from the PIN (analog) from 0 to 1023
and I expected to receive in full with this code:

// make our LED match the switch of the previous device in ************************
 if (message.address == (myAddress - 1))
   
   analog = (message.switches [a34]);

 digitalWrite (OK_PIN, LOW);
 } // end of processMessage

but I get to the maximum value of 255

Please post your whole code, not a snippet, as I can't make any sense of what you are doing there.

ok, this is the rolling master that send the value:

/// id 2
#include <RS485_non_blocking.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
// the data we broadcast to each other device
struct
  {
  byte address;
  byte switches [10];
  int  status;
  
  }  message;

const unsigned long BAUD_RATE = 19200;
const float TIME_PER_BYTE = 1.0 / (BAUD_RATE / 10.0);  // seconds per sending one byte
const unsigned long PACKET_LENGTH = ((sizeof (message) * 3) + 6); // 2 bytes per payload byte plus STX/ETC/CRC
const unsigned long PACKET_TIME =  TIME_PER_BYTE * PACKET_LENGTH * 1000000;  // microseconds

// 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;


int analog = A7; // analog value to send**********************************************
int a34 = 0 ;// the wold of trasmission*******************

// times in microseconds
const unsigned long TIME_BETWEEN_MESSAGES = 3000;
unsigned long noMessagesTimeout;

byte nextAddress;
unsigned long lastMessageTime;
unsigned long lastCommsTime;
unsigned long randomTime;

SoftwareSerial rs485 (RX_PIN, TX_PIN);  // receive pin, transmit pin

// what state we are in
enum {
   STATE_NO_DEVICES,
   STATE_RECENT_RESPONSE,
   STATE_TIMED_OUT,
} state;

// callbacks for the non-blocking RS485 library
size_t fWrite (const byte what)
  {
  rs485.write (what);
  }

int fAvailable ()
  {
  return rs485.available ();
  }

int fRead ()
  {
  lastCommsTime = micros ();
  return rs485.read ();
  }

// RS485 library instance
RS485 myChannel (fRead, fAvailable, fWrite, 20);

// from EEPROM
byte myAddress;        // who we are
byte numberOfDevices;  // maximum devices on the bus

// Initial seed for JKISS32
static unsigned long x = 123456789,
                     y = 234567891,
                     z = 345678912,
                     w = 456789123,
                     c = 0;

// Simple Random Number Generator
unsigned long JKISS32 ()
  {
  long t;
  y ^= y << 5;
  y ^= y >> 7;
  y ^= y << 22;
  t = z + w + c;
  z = w;
  c = t < 0;
  w = t & 2147483647;
  x += 1411392427;
  return x + y + w;
  }  // end of JKISS32

void Seed_JKISS32 (const unsigned long newseed)
  {
  if (newseed != 0)
    {
    x = 123456789;
    y = newseed;
    z = 345678912;
    w = 456789123;
    c = 0;
    }
  }  // end of Seed_JKISS32

void setup ()
  {
  // debugging prints
  Serial.begin (115200);
  // software serial for talking to other devices
  rs485.begin (BAUD_RATE);
  // initialize the RS485 library
  myChannel.begin ();

  // debugging prints
  Serial.println ();
  Serial.println (F("Commencing"));
  myAddress = EEPROM.read (0);
  Serial.print (F("My address is "));
  Serial.println (int (myAddress));
  numberOfDevices = EEPROM.read (1);
  Serial.print (F("Max address is "));
  Serial.println (int (numberOfDevices));

  if (myAddress >= numberOfDevices)
    Serial.print (F("** WARNING ** - device number is out of range, will not be detected."));

  Serial.print (F("Packet length = "));
  Serial.print (PACKET_LENGTH);
  Serial.println (F(" bytes."));

  Serial.print (F("Packet time = "));
  Serial.print (PACKET_TIME);
  Serial.println (F(" microseconds."));

  // calculate how long to assume nothing is responding
  noMessagesTimeout = (PACKET_TIME + TIME_BETWEEN_MESSAGES) * numberOfDevices * 2;

  Serial.print (F("Timeout for no messages = "));
  Serial.print (noMessagesTimeout);
  Serial.println (F(" microseconds."));

  // set up various pins
  pinMode (XMIT_ENABLE_PIN, OUTPUT);

  // demo action pins******************************************************
  
  pinMode (analog,INPUT);
  pinMode (LED_PIN13, OUTPUT);
  pinMode (LED_PIN12, OUTPUT);
  pinMode (LED_PINa3, OUTPUT);
  

  // debugging pins
  pinMode (OK_PIN, OUTPUT);
  pinMode (TIMEOUT_PIN, OUTPUT);
  pinMode (SEND_PIN, OUTPUT);
  pinMode (SEARCHING_PIN, OUTPUT);
  pinMode (ERROR_PIN, OUTPUT);

  // seed the PRNG
  Seed_JKISS32 (myAddress + 1000);

  state = STATE_NO_DEVICES;
  nextAddress = 0;

  randomTime = JKISS32 () % 500000;  // microseconds
  }  // end of setup

// set the next expected address, wrap around at the maximum
void setNextAddress (const byte current)
  {
  nextAddress = current;
  if (nextAddress >= numberOfDevices)
    nextAddress = 0;
  }  // end of setNextAddress


// Here to process an incoming message
void processMessage ()
  {

  // we cannot receive a message from ourself
  // someone must have given two devices the same address
  if (message.address == myAddress)
    {
    digitalWrite (ERROR_PIN, HIGH);
    while (true)
      { }  // give up
    }  // can't receive our address

  digitalWrite (OK_PIN, HIGH);

  // handle the incoming message, depending on who it is from and the data in it

  // make our LED match the switch of the previous device in sequence************************
  if (message.address == (myAddress - 1))
    
    

  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 [a34] = analogRead (analog); // send the value***************************

  
  // now send it
  digitalWrite (XMIT_ENABLE_PIN, HIGH);  // enable sending
  myChannel.sendMsg ((byte *) &message, sizeof message);
  digitalWrite (XMIT_ENABLE_PIN, LOW);  // disable sending
  setNextAddress (myAddress + 1);
  digitalWrite (SEND_PIN, LOW);

  lastCommsTime = micros ();   // we count our own send as activity
  randomTime = JKISS32 () % 500000;  // microseconds
  }  // end of sendMessage
//***********************
void loop ()
  {
   Serial.println(analogRead(analog)); //  for monitor the value******************************
 
  
  // incoming message?**************************************
  if (myChannel.update ())
    {
    memset (&message, 0, sizeof message);
    int len = myChannel.getLength ();
    if (len > sizeof message)
      len = sizeof message;
    memcpy (&message, myChannel.getData (), len);
    lastMessageTime = micros ();
    setNextAddress (message.address + 1);
    processMessage ();
    state = STATE_RECENT_RESPONSE;
    }  // end of message completely received

  // switch states if too long a gap between messages
  if  (micros () - lastMessageTime > noMessagesTimeout)
    state = STATE_NO_DEVICES;
  else if  (micros () - lastCommsTime > PACKET_TIME)
    state = STATE_TIMED_OUT;

  switch (state)
    {
    // nothing heard for a long time? We'll take over then
    case STATE_NO_DEVICES:
      if (micros () - lastCommsTime >= (noMessagesTimeout + randomTime))
        {
        Serial.println (F("No devices."));
        digitalWrite (SEARCHING_PIN, HIGH);
        sendMessage ();
        digitalWrite (SEARCHING_PIN, LOW);
        }
      break;

    // we heard from another device recently
    // if it is our turn, respond
    case STATE_RECENT_RESPONSE:
      // we allow a small gap, and if it is our turn, we send our message
      if (micros () - lastCommsTime >= TIME_BETWEEN_MESSAGES && myAddress == nextAddress)
        sendMessage ();
      break;

    // a device did not respond in its slot time, move onto the next one
    case STATE_TIMED_OUT:
      digitalWrite (TIMEOUT_PIN, HIGH);
      setNextAddress (nextAddress + 1);
      lastCommsTime += PACKET_TIME;
      digitalWrite (TIMEOUT_PIN, LOW);
      state = STATE_RECENT_RESPONSE;  // pretend we got the missing response
      break;

    }  // end of switch on state

  }  // end of loop

and this is the reciver

// id 1
#include <RS485_non_blocking.h>
#include <SoftwareSerial.h>
#include <EEPROM.h>
// the data we broadcast to each other device
struct
  {
  byte address;
  byte switches [10];
  int  status;
  
  }  message;

const unsigned long BAUD_RATE = 19200;
const float TIME_PER_BYTE = 1.0 / (BAUD_RATE / 10.0);  // seconds per sending one byte
const unsigned long PACKET_LENGTH = ((sizeof (message) * 3) + 6); // 2 bytes per payload byte plus STX/ETC/CRC
const unsigned long PACKET_TIME =  TIME_PER_BYTE * PACKET_LENGTH * 1000000;  // microseconds

// 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)***************************************

int analog =0;
 
 int a34 = 0 ;

// times in microseconds
const unsigned long TIME_BETWEEN_MESSAGES = 3000;
unsigned long noMessagesTimeout;

byte nextAddress;
unsigned long lastMessageTime;
unsigned long lastCommsTime;
unsigned long randomTime;

SoftwareSerial rs485 (RX_PIN, TX_PIN);  // receive pin, transmit pin

// what state we are in
enum {
   STATE_NO_DEVICES,
   STATE_RECENT_RESPONSE,
   STATE_TIMED_OUT,
} state;

// callbacks for the non-blocking RS485 library
size_t fWrite (const byte what)
  {
  rs485.write (what);
  }

int fAvailable ()
  {
  return rs485.available ();
  }

int fRead ()
  {
  lastCommsTime = micros ();
  return rs485.read ();
  }

// RS485 library instance
RS485 myChannel (fRead, fAvailable, fWrite, 20);

// from EEPROM
byte myAddress;        // who we are
byte numberOfDevices;  // maximum devices on the bus

// Initial seed for JKISS32
static unsigned long x = 123456789,
                     y = 234567891,
                     z = 345678912,
                     w = 456789123,
                     c = 0;

// Simple Random Number Generator
unsigned long JKISS32 ()
  {
  long t;
  y ^= y << 5;
  y ^= y >> 7;
  y ^= y << 22;
  t = z + w + c;
  z = w;
  c = t < 0;
  w = t & 2147483647;
  x += 1411392427;
  return x + y + w;
  }  // end of JKISS32

void Seed_JKISS32 (const unsigned long newseed)
  {
  if (newseed != 0)
    {
    x = 123456789;
    y = newseed;
    z = 345678912;
    w = 456789123;
    c = 0;
    }
  }  // end of Seed_JKISS32

void setup ()
  {
  // debugging prints
  Serial.begin (115200);
  // software serial for talking to other devices
  rs485.begin (BAUD_RATE);
  // initialize the RS485 library
  myChannel.begin ();

  // debugging prints
  Serial.println ();
  Serial.println (F("Commencing"));
  myAddress = EEPROM.read (0);
  Serial.print (F("My address is "));
  Serial.println (int (myAddress));
  numberOfDevices = EEPROM.read (1);
  Serial.print (F("Max address is "));
  Serial.println (int (numberOfDevices));

  if (myAddress >= numberOfDevices)
    Serial.print (F("** WARNING ** - device number is out of range, will not be detected."));

  Serial.print (F("Packet length = "));
  Serial.print (PACKET_LENGTH);
  Serial.println (F(" bytes."));

  Serial.print (F("Packet time = "));
  Serial.print (PACKET_TIME);
  Serial.println (F(" microseconds."));

  // calculate how long to assume nothing is responding
  noMessagesTimeout = (PACKET_TIME + TIME_BETWEEN_MESSAGES) * numberOfDevices * 2;

  Serial.print (F("Timeout for no messages = "));
  Serial.print (noMessagesTimeout);
  Serial.println (F(" microseconds."));

  // set up various pins
  pinMode (XMIT_ENABLE_PIN, OUTPUT);

  // demo action pins*******************************************************************
   

  // debugging pins
  pinMode (OK_PIN, OUTPUT);
  pinMode (TIMEOUT_PIN, OUTPUT);
  pinMode (SEND_PIN, OUTPUT);
  pinMode (SEARCHING_PIN, OUTPUT);
  pinMode (ERROR_PIN, OUTPUT);

  // seed the PRNG
  Seed_JKISS32 (myAddress + 1000);

  state = STATE_NO_DEVICES;
  nextAddress = 0;

  randomTime = JKISS32 () % 500000;  // microseconds
  }  // end of setup

// set the next expected address, wrap around at the maximum
void setNextAddress (const byte current)
  {
  nextAddress = current;
  if (nextAddress >= numberOfDevices)
    nextAddress = 0;
  }  // end of setNextAddress


// Here to process an incoming message
void processMessage ()
  {

  // we cannot receive a message from ourself
  // someone must have given two devices the same address
  if (message.address == myAddress)
    {
    digitalWrite (ERROR_PIN, HIGH);
    while (true)
      { }  // give up
    }  // can't receive our address

  digitalWrite (OK_PIN, HIGH);

  // handle the incoming message, depending on who it is from and the data in it

  // make our LED match the switch of the previous device in sequence***************************************************
  if (message.address == (myAddress - 1))
    

    analog = (message.switches [a34]);// the analog value to recive**********************

  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.)**************************************************

 

  // now send it
  digitalWrite (XMIT_ENABLE_PIN, HIGH);  // enable sending
  myChannel.sendMsg ((byte *) &message, sizeof message);
  digitalWrite (XMIT_ENABLE_PIN, LOW);  // disable sending
  setNextAddress (myAddress + 1);
  digitalWrite (SEND_PIN, LOW);

  lastCommsTime = micros ();   // we count our own send as activity
  randomTime = JKISS32 () % 500000;  // microseconds
  }  // end of sendMessage
//*****************************************************************************************************************
void loop ()
  {
    
   
  Serial.println(analog); // for monitorin the value*****************************************
  // incoming message?*********************************************************************
  if (myChannel.update ())
    {
    memset (&message, 0, sizeof message);
    int len = myChannel.getLength ();
    if (len > sizeof message)
      len = sizeof message;
    memcpy (&message, myChannel.getData (), len);
    lastMessageTime = micros ();
    setNextAddress (message.address + 1);
    processMessage ();
    state = STATE_RECENT_RESPONSE;
    }  // end of message completely received

  // switch states if too long a gap between messages
  if  (micros () - lastMessageTime > noMessagesTimeout)
    state = STATE_NO_DEVICES;
  else if  (micros () - lastCommsTime > PACKET_TIME)
    state = STATE_TIMED_OUT;

  switch (state)
    {
    // nothing heard for a long time? We'll take over then
    case STATE_NO_DEVICES:
      if (micros () - lastCommsTime >= (noMessagesTimeout + randomTime))
        {
        Serial.println (F("No devices."));
        digitalWrite (SEARCHING_PIN, HIGH);
        sendMessage ();
        digitalWrite (SEARCHING_PIN, LOW);
        }
      break;

    // we heard from another device recently
    // if it is our turn, respond
    case STATE_RECENT_RESPONSE:
      // we allow a small gap, and if it is our turn, we send our message
      if (micros () - lastCommsTime >= TIME_BETWEEN_MESSAGES && myAddress == nextAddress)
        sendMessage ();
      break;

    // a device did not respond in its slot time, move onto the next one
    case STATE_TIMED_OUT:
      digitalWrite (TIMEOUT_PIN, HIGH);
      setNextAddress (nextAddress + 1);
      lastCommsTime += PACKET_TIME;
      digitalWrite (TIMEOUT_PIN, LOW);
      state = STATE_RECENT_RESPONSE;  // pretend we got the missing response
      break;

    }  // end of switch on state

  }  // end of loop
struct
  {
  byte address;
  byte switches [10];
  int  status;
  }  message;
...
int a34 = 0 ;// the wold of trasmission*******************
...
  message.switches [a34] = analogRead (analog); // send the value***************************

So? You are putting an analogRead into one byte. Surely you can see that? You need to change "message" to hold what you want. eg,

struct
  {
  byte address;
  int theReading;  // where the analogRead goes
  int  status;
   }  message;

Dear Nick,
Thank you for your time

here is the new working code
the sender

struct
  {
     byte address;
 // byte switches [10];
    int theReading;
    int  status;  
  }  message;
.....
int a34 = 0; //
....
  message.theReading [a34] = analogRead (analog);

the reciver

struct
  {
  byte address;
  byte switches [10];
  int theReading[1];
  int  status;
  }  message;
....
int a34 = 0 ;
.... 
analog = (message.theReading [a34]);

first I did some tests and saw that changing this

threading int [1];

with

 int theReading ;

does not work, and it does not work even if you do not enter this in the struct byte switches [10].

I tried to change this theReading int [1]; theReading with int [10]; to try to send two or more analog data but does not function.
instead it works if I post this

struct {
byte address; 
switches byte [10]; 
int theReading [1]; 
int theReading1 [1]; 
int status; 
} Message;

and endorse theAnalogreading and theAnalogreading1 words trsamission different eg. a34 and a35

Thank you very much for your help, you can mark this thread as [SOLVED]

threading int [1];

An array of one item is quite a uselessly complex way of writing something.

I tried to change this theReading int [1]; theReading with int [10]; to try to send two or more analog data but does not function.

Well, it will if you do it properly. You have somehow combined the use of arrays of one item, with discarding the array concept. Eg.

int foo1;
int foo2;
int foo3;

Can be written as:

int foo [3];

Don't thrash around writing bizarre code, work out what is going wrong and fix it.

sorry I was wrong to copy

threading int [1];

int theReading[1]; //   It is what I tried

I'm still newbie with Arduino.
So let me understand this is correct because it works

 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

but I had to add 'a6' cause I could not send more than 16 messages also asked myself this condition

struct
  {
  byte address;
  byte switches [20];
.....

why?
and why not work with repeating the condition

struct
  {
  byte address;
  byte switches [10];
  int theReading[10];
....
  message.theReading [1] = hd;
  message.theReading [2] = temp; 
  message.theReading [3] = td;
......
......
//and in the receiver
struct
  {
  byte address;
  byte switches [10];
  int theReading[10];
....
    hd = message.theReading [1] ;
 temp =  message.theReading [2] ; 
    td = message.theReading [3] ;
...

do you think something else wrong?

how do I send more data?
until now I managed to send numeric values 6 and 4 digital data.
I tried to change the structure of the message

struct
   {
   byte address;
   AnalogValue int [3];
   switches byte [10];
   // switches2 byte [10];
   int status;
   } Message;

If I change one value no longer receiving anything

Please post the full code for the sender and receiver (with the struct changed).

Hi Nick,
They will not stop thanking you.

Currently I created communication between three Arduino Nano, but I'll have to add the fourth.
two of these (ID-2 and ID-3) will have to read and send data to other two (ID-0 and ID-1) located 30 meters away.

The program of 'ID3 is not yet developed.

From the evidence that I run the code ID-0 sends 6 analog values in ID-2 by: message.AnalogValue [1 ... 6]
but in the middle it is present the ID-1 that must receive these data is send them again to get them to ID-2.

Even the ID-1 must send data to the ID-2 which will have to be queued to the output information from the ID-1.

I understand thatthe code 'rs485.non.blocking' send a train of serial data but can not be identified by a message that identifies them.

example:
the first message from ID-0 is: message.AnalogValue [1] = ptot_m;
will arrive in ID-1 of this string: Ptot = message.AnalogValue [1];
provided it is placed in the first line of the message was received, if I change the message id ([1] to [4]) the first value sent will be received by the first message ever received, regardless of whether its id [1] or [4].

Structure:
AnalogValue int [3]; as per your suggestion I added in the code, but if you put a value greater than 3 is not working but I can send qomunque six values.
switches byte [10]; if I enter a value bigger, across all modules, I do not receive anything.

the data from the ID-1 to ID-2:
on ID-1 and a sensor mounted DHT22 that I would would send values to ID-2 and subsequently the state of some digital inputs.

Attached are the three codes with comments of their duties.

I hope I was clear in my description.

Thank you,Mirko

ID_0_su_quadro_elettrico.ino (10.9 KB)

ID_1_su_piano_terra.ino (12.7 KB)

ID_2_su_plc_rx_analog.ino (12.1 KB)

  int AnalogValue[3];

...

  message.AnalogValue [1] = ptot_m;
  message.AnalogValue [2] = plh_m;
  message.AnalogValue [3] = ppr_m;
  message.AnalogValue [4] = pcu_m;
  message.AnalogValue [5] = pla_m ;  //analogRead (Pla);
  message.AnalogValue [6] = pso_m ;  //analogRead (Pso);

And:

 byte switches [10];

...

  message.switches [8] = lbs_m;
  message.switches [9] = sb_m;
  message.switches [10] = ls_m;  
  message.switches [11] = op1_in_m;

I'm not looking any further at this stage. You need to have more attention to detail. If you have an array of 3 x AnalogValue then it is quite wrong to put something into array item 6.

Ditto for 10 x switches when you are writing to the 10th and 11th array item.

For this:

byte switches [10];

Only array subscripts 0 to 9 (not 10) are valid. 0 to 9 are 10 elements.

I tried to set 4,5,6,7,8,9 and 10 for this

  int AnalogValue[3].... [10];

...

  message.AnalogValue [1] = ptot_m;
  message.AnalogValue [2] = plh_m;
  message.AnalogValue [3] = ppr_m;
  message.AnalogValue [4] = pcu_m;
  message.AnalogValue [5] = pla_m ;  //analogRead (Pla);
  message.AnalogValue [6] = pso_m ;  //analogRead (Pso);

And the same for:

 byte switches [10]...[20];

...

  message.switches [8] = lbs_m;
  message.switches [9] = sb_m;
  message.switches [10] = ls_m;  
  message.switches [11] = op1_in_m;

but I can not send more data, the better position is the one that I sent in the 3 codes.
i would like it to work well:

  int AnalogValue[7];
[code] byte switches [30];

I tried this condition, ccon ID-3 off, the transmitter:

struct {byte address;
 AnalogValue int [5];
 switches byte [10];
 // Bytes switches2 [3];
 int status;
 } Message;
........
message.Analog Value [0] = prom;
 message.Analog Value [1] = plh_m;
 message.AnalogValue [2] = ppr_m;
 message.AnalogValue [3] = pcu_m;
 message.AnalogValue [4] = pla_m; // AnalogRead (PLA); 
message.AnalogValue [5] = pso_m; // AnalogRead (PSO);
// Digital 
message.switches [8] = lbs_m;
 message.switches [9] = sb_m;
 message.switches [10] = ls_m;
 message.switches [11] = op1_in_m;
/ * 
Message.switches 2 [12] = 200; // ht; // Moisture 
message.switches2 [13] = 210; // hd; // Moisture decimal 
message.switches2 [14] = 220; // temp; // Temp 
message.switches2 [15] = 230; // td; // Decimal temp

and I visualized on debugging:
Ptot1023 Plh1023 Ppr1023 Pcu1023 Pla888 Pso1023 lbs0 sb0 LS0 op1in0
Ptot1023 Plh1023 Ppr1023 Pcu1023 Pla888 Pso1023 lbs0 sb0 LS0 op1in0
Ptot1023 Plh1023 Ppr1023 Pcu1023 Pla888 Pso1023 lbs0 sb0 LS0 op1in0
in the receiver:

struct {
byte address;
 AnalogValue int [5];
 switches byte [10];
 // Switches2 byte [10];
 int status;
........
Ptot message.AnalogValue = [0];
 Plh message.AnalogValue = [1]; 
PPR = message.AnalogValue [2];
 Pcu = message.AnalogValue [3];
 Pla= message.AnalogValue [4]; 
Pso = message.AnalogValue [5];
// ****** Digital 

 lbs_m = message.switches [8]; 
 sb_m  = message.switches [9];
 ls_m = message.switches [10];
op1_in_m = message.switches [11];
// temp e umid***

   ht =  message.switches [12];   // umidita
   hd =  message.switches [13];   // umid. decimale ***pcu
 temp =  message.switches [14];   // temp 
   td =  message.switches [15];   // decimal temp    ****pla

and I visualized on debugging:
Ptot0 Plh0 Ppr0 Pcu0 Pla0 Pso0 lbs0 sb0 LS0 op1in0 ht0 HD0 T0 TD0 m50 m60 m70 m80
Ptot0 Plh0 Ppr0 Pcu0 Pla0 Pso0 lbs0 sb0 LS0 op1in0 ht0 HD0 T0 TD0 m50 m60 m70 m80
Ptot0 Plh0 Ppr0 Pcu0 Pla0 Pso0 lbs0 sb0 LS0 op1in0 ht0 HD0 T0 TD0 m50 m60 m70 m80
Ptot0 Plh0 Ppr0 Pcu0 Pla0 Pso0 lbs0 sb0 LS0 op1in0 ht0 HD0 T0 TD0 m50 m60 m70 m80

 AnalogValue int [5];
...
message.AnalogValue [5] = pso_m; // AnalogRead (PSO);

I do not get the impression you are listening to me. That code is wrong!