EasyTransfer Library - Lag and missing info

Hey All, I’m fairly new to arduino and programming but I have been making good progress, Im building an underwater ROV and I am using Arduinos for the control system.

Heres the layout,

  • UNO in the ROV
    connected to sensors(temp, voltage)
    IC2 to PCA9685 for servos and ESC
    0RX and 1TX go to a Fathom S Tether Interface board for RS422 comms -to the other Fathom S board connected to RX00 and TX01 on a Mega2560 - This is my topside control board.

IC2 to 20x4 LCD for sensor display
2 Pots on analog for some servo control(for now, just working with 2 pot and 2 servos right now, starting slow)

Since Im a beginner I have been coding my sections on 1 Mega, getting the bugs worked out and then splitting the code across my 2 boards and the EasyTransfer.

I had my split code working perfectly with just the topside board giving pot values and the bottom board moving the servos. So I wanted to move onto my sensor array, and started coding it as one piece. The below code worked great on one board with everything on it,

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 5

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

 float Celcius=0;
 float Fahrenheit=0;

int offset1 = -272;// set the correction offset value for voltage sensor 1
int offset2 = -182;// set the correction offset value for voltage sensor 2
int ROVtempPin = 5; // Temp input pin of ROV sensor
int BattV1 = 0; // Analog pin of #1 sensor
int BattV2 = 1;  // Analog pin of #2 sensor
LiquidCrystal_I2C lcd(0x27,20,4);  
void setup()
{
  Serial.begin(9600);
  sensors.begin();
  lcd.init();                      // initialize the lcd 
  lcd.init();
  lcd.backlight();
  pinMode(ONE_WIRE_BUS,INPUT_PULLUP);
  }


void loop()
{
 // Battery Pack 1 voltage sensor 
  int volt1 = analogRead(BattV1);// read the input
  double voltage1 = map(volt1,0,1023, 0, 2500) + offset1;// map 0-1023 to 0-2500 and add correction offset
  voltage1 /=100;// divide by 100 to get the decimal values
  Serial.print("Voltage: ");
  Serial.print(voltage1);//print the voltge
  Serial.println("V");

 // Battery Pack 2 voltage sensor 
  int volt2 = analogRead(BattV2);// read the input
  double voltage2 = map(volt2,0,1023, 0, 2500) + offset2;// map 0-1023 to 0-2500 and add correction offset
  voltage2 /=100;// divide by 100 to get the decimal values
  Serial.print("Voltage: ");
  Serial.print(voltage2);//print the voltge
  Serial.println("V");

/////////// ROV Pod Temp
 int tempReading1 = analogRead(ROVtempPin);
  // This is OK
  double tempK1 = log(10000.0 * ((1024.0 / tempReading1 - 1)));
  tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK1 * tempK1 )) * tempK1 );       //  Temp Kelvin
  float tempC1 = tempK1 - 273.15;            // Convert Kelvin to Celcius
  float tempF1 = (tempC1 * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit

////////////Water Temp
   sensors.requestTemperatures(); 
  Celcius=sensors.getTempCByIndex(0);
  Fahrenheit=sensors.toFahrenheit(Celcius);
  Serial.print(" C  ");
  Serial.print(Celcius);
  Serial.print(" F  ");
  Serial.println(Fahrenheit);

  lcd.setCursor(0,0);
  lcd.print("BatV1 ");
  lcd.print(voltage1);
  lcd.print("V");
    lcd.setCursor(0,1);
    lcd.print("BatV2 ");
    lcd.print(voltage2);
    lcd.print("V");
      lcd.setCursor(0,2);
      lcd.print("Water Temp ");
      lcd.print(Fahrenheit);
      lcd.print("F");
        lcd.setCursor(0,3);
        lcd.print("ROV Pod Temp ");
        lcd.print(tempF1);
        lcd.print("F");

  
delay(500);

}

Have to do a reply due to chara limits

And then I tried to split it for the top side and bottom side boards and thats when things went sideways, my servos are really laggy when they were decently smooth and none of my sensor data is showing on my LCD. The LCD shows the right wording but the values are just 0 (see pics)

Here are the codes - I deleted the loop for water temperature loop to try and eliminate some sending data but it didnt make a difference.

TopSide Control

#include <Servo.h>
#include <EasyTransfer.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>

EasyTransfer ETin, ETout;

#define SERVOMIN  160 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  430 // this is the 'maximum' pulse length count (out of 4096)
LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 20 chars and 4 line display

struct SEND_DATA_STRUCTURE{
  int TiltPot = 8;   //Analog Pin 8 - Pot for doing tilt
  int TiltVal;       //Varable reading from analog pin of pot
  int PanPot = 9;  //A P 9 - Pot for Pan
  int PanVal;     //Varable reading from analog pin of pot
  };
struct RECEIVE_DATA_STRUCTURE{

float Celcius=0;
float Fahrenheit=0;

int offset1 = -272;// set the correction offset value for voltage sensor 1
int offset2 = -182;// set the correction offset value for voltage sensor 2
int ROVtempPin = 5; // Temp input pin of ROV sensor
int BattV1 = 0; // Analog pin of #1 sensor
int BattV2 = 1;  // Analog pin of #2 sensor
double voltage1;
double voltage2;
float tempF1;
float tempC1;
int tempReading1;
double tempK1;

};

//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;

void setup() {
   Serial.begin(38400);
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);

  lcd.init();                      // initialize the lcd 
  lcd.init();
  lcd.backlight();
  
}

void loop() {
  
  txdata.TiltVal= analogRead(txdata.TiltPot);
    txdata.TiltVal= map(txdata.TiltVal, 0, 1023, SERVOMIN, SERVOMAX);
    

  txdata.PanVal = analogRead(txdata.PanPot);
    txdata.PanVal = map(txdata.PanVal, 0, 1023, SERVOMIN, SERVOMAX);
   
ETout.sendData();

  for(int i=0; i<5; i++){
  ETin.receiveData();

  lcd.setCursor(0,0);
  lcd.print("BatV1 ");
  lcd.print(rxdata.voltage1);
  lcd.print("V");
    lcd.setCursor(0,1);
    lcd.print("BatV2 ");
    lcd.print(rxdata.voltage2);
    lcd.print("V");
      lcd.setCursor(0,2);
      lcd.print("Water Temp ");
      lcd.print(rxdata.Fahrenheit);
      lcd.print("F");
        lcd.setCursor(0,3);
        lcd.print("ROV Pod Temp ");
        lcd.print(rxdata.tempF1);
        lcd.print("F");

 }
 delay(10);
}
}

Here is my ROV- Bottom side

#include <Adafruit_PWMServoDriver.h>
#include <Wire.h>
#include <EasyTransfer.h>
#include <OneWire.h>
#include <DallasTemperature.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

EasyTransfer ETin, ETout;

#define SERVOMIN  160 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX  430 // this is the 'maximum' pulse length count (out of 4096)
#define ONE_WIRE_BUS 5
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);


// our servo # counter
uint8_t servonum = 1;   // 0 is Servo for camera tilt 1 - Servo for camera side to side

struct SEND_DATA_STRUCTURE{

 
 float Celcius=0;
 float Fahrenheit=0;

int offset1 = -272;// set the correction offset value for voltage sensor 1
int offset2 = -182;// set the correction offset value for voltage sensor 2
int ROVtempPin = 5; // Temp input pin of ROV sensor
int BattV1 = 0; // Analog pin of #1 sensor
int BattV2 = 1;  // Analog pin of #2 sensor
int volt1;
double voltage1;
int volt2;
double voltage2;
float tempF1;
float tempC1;
int tempReading1;
double tempK1;
  };
  
struct RECEIVE_DATA_STRUCTURE{
  int TiltPot = 8;   //Analog Pin 8 - Pot for doing tilt
  int TiltVal;       //Varable reading from analog pin of pot
  int PanPot = 9;  //A P 9 - Pot for Pan
  int PanVal;     //Varable reading from analog pin of pot
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE rxdata;
SEND_DATA_STRUCTURE txdata;

void setup() {
   Serial.begin(38400);
  //start the library, pass in the data details and the name of the serial port. Can be Serial, Serial1, Serial2, etc.
  ETin.begin(details(rxdata), &Serial);
  ETout.begin(details(txdata), &Serial);
  
  pwm.begin();
  pwm.setPWMFreq(60);  // Analog servos run at ~60 Hz updates
  yield;

  sensors.begin();
  pinMode(ONE_WIRE_BUS,INPUT_PULLUP);
}

void loop() {


  for(int i=0; i<5; i++) { 
     ETin.receiveData();
  
    pwm.setPWM(0, 0, rxdata.TiltVal);

    pwm.setPWM(1, 0, rxdata.PanVal);
    
   }

{
  // Battery Pack 1 voltage sensor 
  txdata.volt1 = analogRead(txdata.BattV1);// read the input
  txdata.voltage1 = map(txdata.volt1,0,1023, 0, 2500) + txdata.offset1;// map 0-1023 to 0-2500 and add correction offset
  txdata.voltage1 /=100;// divide by 100 to get the decimal values
 

 // Battery Pack 2 voltage sensor 
  txdata.volt2 = analogRead(txdata.BattV2);// read the input
  txdata.voltage2 = map(txdata.volt2,0,1023, 0, 2500) + txdata.offset2;// map 0-1023 to 0-2500 and add correction offset
  txdata.voltage2 /=100;// divide by 100 to get the decimal values

/////////// ROV Pod Temp
 txdata.tempReading1 = analogRead(txdata.ROVtempPin);
  
  txdata.tempK1 = log(10000.0 * ((1024.0 / txdata.tempReading1 - 1)));
  txdata.tempK1 = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * txdata.tempK1 * txdata.tempK1 )) * txdata.tempK1 );       //  Temp Kelvin
  txdata.tempC1 = txdata.tempK1 - 273.15;            // Convert Kelvin to Celcius
  txdata.tempF1 = (txdata.tempC1 * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit

////////////Water Temp


 ETout.sendData();
 
  }
   delay(10);
}

Right now all the LCD values are at zero and the 2 servos jump around… I think something is wrong in the communications part but dont know where to go from here

my servos are really laggy

And yet you persist in using useless delay()s. You must LIKE laggy.

  for(int i=0; i<5; i++){
  ETin.receiveData();

Why do you receive data 5 times before sending more data?

Why
does
your
code
wander
across
the
page
like
it’s
drunk?

Why do you need to send constant data in every packet?

  yield;

What do you think that does? Any answer other than “nothing” is wrong.

  for(int i=0; i<5; i++) {
     ETin.receiveData();

How many times do you send data? You should receive data the exact same number of times.

Most of the receiveData() calls are going to time out, because there is nothing to read, which takes time, contributing to your lag issues.