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 everything on 1 Mega, getting the bugs worked out and then splitting the code across my 2 boards and the EasyTransfer.h library for communications
I had my split code working perfectly with just the topside board giving pot values and the bottom board moving the servos for my camera turret. So I wanted to move onto my sensor array, and started coding it as one piece and got it working perfectly. But when I tried to split it apart things go sideways. my servos are really laggy and jumping 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. I tried deleting one of the sensor equation to see if sending less data made any difference but it did not, bottom side code is still less the one water sensor,
Here are the codes
Topside Mega
Code: Select all
#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);
}
}
Code: Select all
#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);
}