Multiple Arduino sensor wired network - Eth shield / UDP / BME680 / 4D Display

Hi, I’m Noob and lost,

My target is to measure on 3 different places about 15m from each other, the Temperature, the Humidity and VOS (some gasValue) and put this 9 values on a display as a stand alone system.

To do this I use:

  • 3 Arduino Uno’s rev3, with WIZnet5500 ethernet shield and the Adafruit BME680 connected via I²C
  • 1 Arduino Mega 2560, with WIZnet5500 shield and 4D system Arduino shield
  • 1 4D system display Diablo uLCD-70DT
  • 1 Netgear GS105v5 unmanaged switch
  • Arduino 1.8.7 IDE

The Mega as central unit connected with the display.
The 3 Uno’s on the 3 places all with their own BME680 sensor.
The switch which connect the 4 ethernet shields using the UDP protocol.

And it all communicate, except I can’t find the reason/solution why my received packets are shifted 1 step.

I clear myself:

The code on the Uno:

#include <Wire.h>
#include <SPI.h> 
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <Ethernet.h>
#include <EthernetUdp.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME680 bme;  // create a bme object

float Temp_M1;          // declare variable for temp °C
float Humi_M1;          // declare variable for humidity %
float Gas_M1;           // declare variable for gas Kohm

byte mac[] = {  0xA8, 0x61, 0x0A, 0xAE, 0x01, 0x05 };   // MAC address Uno-M1
IPAddress ip(192, 168, 0, 100);                         // IP address Uno-M1
unsigned int localPort = 8888;                          // local port to listen on
EthernetUDP Udp;                                        // An EthernetUDP instance to let us send and receive packets over UDP
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];              // a buffer to hold incoming packet, 
String datreq;                                          // a string for our data
int packetSize;                                         // size of the packet

void setup() {
  Serial.begin(9600);               // inialize the serial port
  Ethernet.begin(mac,ip);           // inialize the ethernet
  Udp.begin(localPort);             // inialize the Udp port to communicate
  bme.begin();                      // inialize the bme680 sensor


   while (!Serial);
  Serial.println(F("BME680 async test"));

  if (!bme.begin()) {
    Serial.println(F("Could not find a valid BME680 sensor, check wiring!"));
    while (1);

 // Check for Ethernet hardware
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found. :(");
    while (true) {
      delay(1); // do nothing, no Ethernet hardware available
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable disconnected.");

  pinMode(4, OUTPUT);         // disable SD SPI
  digitalWrite(4, HIGH);
  // Set up oversampling and filter initialization
  bme.setGasHeater(320, 150); // 320*C for 150 ms

void loop() {

 if (! bme.performReading()) {
    Serial.println("Failed to perform reading :(");

Temp_M1 = bme.readTemperature();
Humi_M1 = bme.readHumidity();
Gas_M1 = bme.readGas();

  packetSize = Udp.parsePacket();                     // read the packet size
  if(packetSize>0)   {                                // if packetSize is >0, means someone has sent something,UDP_TX_PACKET_MAX_SIZE);    // read the packet into packetBufffer

    String datreq(packetBuffer);
    Serial.print("The datreq contains:   ");
    Serial.println (datreq);
    if (datreq == "Temperature_M1") {                     // do following when Temperature_M1 is requested
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Serial.print("Temp_M1=  ");
      memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);             

    if (datreq == "Humidity_M1") {                     // do following when Humidity_M1 is requested    
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Serial.print("Humi_M1=  ");
      memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);          

    if (datreq == "GasValue_M1") {                     // do following when Gas_M1 is requested     
      Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
      Udp.print(Gas_M1 / 1000);
      Serial.print("Gas_M1=  ");
      Serial.println(Gas_M1 / 1000);
      memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE);                 


The code on the Mega, please see attachment, it only contains the code to communicate with one Uno.
(was a bit to big to add it as code)

The Mega send every 3s a ‘request’ to one of the three Uno’s for the Temperature or Humidity or GasValue, this always in the same order and start first with the Temperature.
The Mega receives these values but the value of the Temperature ends in the buffer of Humidity, the Humidity in the buffer of the GasValue and the GasValue in the buffer of the Temperature.

The Serial monitors in attachment makes it clear, the top line is the first line after opening the Serial monitor.

Now the Mega send every 3s a request, if we do this every 500ms it’s a complete mess at the Mega side, but an interval of 3s it fast enough and works fine.

As Noob it tokes me already a lot of time to reach this, but now I can’t make any progress.

Thanks for your help,


Uno1-030119.ino (4 KB)

Mega-030119.ino (4.31 KB)