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

