Creating a water quality data logger - compilation and other errors

I am building my first arduino on a mega platform to perform water quality testing in an estuary during plankton pulling and sediment sampling. I have a TDS sensor, external waterproof thermometer, lcd screen, RTC, and SD card module.

I'm trying to build the code and each time I think I have fixed something, another error pops up. I'm 10 days into this and still going nowhere. I'm a newbie and know just enough code to get myself in trouble, but not enough to know what something is/should be doing/not doing.

Here is my firmware code - I am currently getting a compilation error for a conflicting declaration "GravityTDS &onewire. I have gotten other errors for the RTC addressing (it wanted 2 wire configuration from another library), and void loop and void setup errors. I just want this thing to be able to read the temperature of the water in Celcius, the total dissolved salts in ppm, via the real-time clock of when the unit started reading/gathering data, and write the info to the SD card and display data on the LCD screen. Seems simple, but this coding has me bungled. Can you help me figure out where I am going wrong in my coding and fix any other potential errors?

// Include Libraries
#include "Arduino.h"
#include "EEPROM.h"
#include "DS18B20.h"
#include "GravityTDS.h"
#include "LiquidCrystal.h"
#include "Adafruit_NeoPixel.h"
#include "OneWire.h"
#include "DallasTemperature.h"
#include <SPI.h>
#include "SD.h"
#include "Button.h"

// Pin Definitions
#define DS18B20WP_PIN_DQ	2
#define ONE_WIRE_BUS 7
#define LCD_PIN_RS	8
#define LCD_PIN_E	7
#define LCD_PIN_DB4	3
#define LCD_PIN_DB5	4
#define LCD_PIN_DB6	5
#define LCD_PIN_DB7	6
#define LEDRGB_PIN_DIN	9
#define SDFILE_PIN_CS	53
#define TdsSensorPin 10
#define VREF 5.0      // analog reference voltage(Volt) of the ADC
#define SCOUNT  30           // sum of sample point

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int pinCS = 52; //Pin 52 on Arduino
OneWire oneWire(ONE_WIRE_BUS); 
OneWire ds(7);
GravityTDS (&oneWire);
DallasTemperature sensors(&oneWire);

 
float tdsValue = 0;
float tempSensor1
const int sensor_pin = 2, 10
const int chipSelect = 50; //chipSelect pin for SD card Reader
File mySensorData; //Data object for writing sensor data to

 
void setup() {
  Serial.begin(9600);
  pinMode(pinCS, OUTPUT)
  pinMode(sensor_pin,INPUT)

//SD Card Initialization
if (SD.begin())
{
  Serial.printIn("SD card is ready to use.");
  } else
{
Serial.printIn("SD card initialization failed.");
return;
}
//Create/Open file
mySensorData=SD.open("test.txt", FILE_WRITE)

//if the file opened okay, write to it:
if(mySensorData){
  Serial.println("Writing to file...");
  //Write to file
  mySensorData.println("Testing text 1, 2, 3...");
  mySensorData.close(); //close the file
  Serial.println("Done.");
}
//if the file didn't open, print an error:
else {
  Serial.println("Error opening test.txt");
}

//Reading the file
mySensorData=SD.open("test.txt");
if (mySensorData) {
  Serial.println("Read:");
//Reading the whole file  

while (mySensorData.available()){
Serial.write(mySensorData.read());  
}
mySensorData.close();
}
else {
  Serial.println("error opening test.txt");
}

void loop(){
  //empty
}

void setup()
{
Serial.begin(115200);
lcd.begin(16,2);
sensors.begin();
gravityTds.setPin(TdsSensorPin);
gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds.begin();  //initialization

}

void loop()
{
  lcd.setCursor(0,0);
  lcd.print("Time ");
  DateTime now = RTC.now();
  lcd.print(now.hour(), DEC);
lcd.print(": ");
lcd.setCursor(11,0);
lcd.print(now.second(), DEC);
float temp_c;
float TDS;

//Read values from the sensor
temp_c = shtlx.readTemperatureC();
TDS =  shtlx.readTDS();

// Print the values to the serial port
  lcd.setCursor(0,1);
  lcd.print("Temp ");
  lcd.setCursor(5,1);
  lcd.print(temp_c, DEC);
  lcd.setCursor(7,1);
  lcd.print(" TDS ");
  lcd.print(TDS);
  lcd.print("%");
  
  Serial.print("Temperature: ");
  Serial.print(temp_c, DEC);
  Serial.print("TDS: ");
  Serial.print(TDS);
  Serial.println("%");
 }
  }

 
void loop()
{
sensors.requestTemperatures();
 
    gravityTds.setTemperature(sensors.getTempCByIndex(0));  // set the temperature and execute temperature compensation
    gravityTds.update();  //sample and calculate
    tdsValue = gravityTds.getTdsValue();  // then get the value
    
    Serial.print(tdsValue,0);
    Serial.println("ppm");
    Serial.print("Temperature is: "); 
    Serial.print(sensors.getTempCByIndex(0));
    
    lcd.setCursor(0, 0);
    lcd.print("TDS: ");
    lcd.print(tdsValue,0);
    lcd.print(" PPM");
 
    lcd.setCursor(0, 1);
    lcd.print("Temp: ");
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print(" C");
    
    delay(1500);
    lcd.clear();
}
}


Please include the entire error message. It is easy to do if you are using the IDE. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

You have 2 setup() functions. That is illegal.

You have 3 loop() functions. That is way illegal.

Do you have 2 LCDs? Why give LCD pins names, but use different numbers in the constructor?

Pin 52 is the SPI SCK pin. The SPI bus is not going to be happy.

Pin 50 is the SPI MISO pin. The SPI bus is not going to be happy.

Your method of slapping together random bits of code needs refinement.

See here for how to combine multiple codes into one: >> http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

Another merging code page: >> Arduino Sketch Merge - Wikiversity

1 Like

looks like you're trying to do too much. guessing you're just copy&paste stuff off the web

recommend you just start with code to display something on the LCD. once that compiles, downloads and works as expected, add another small feature, one feature at a time

sometimes it may be better to work on test some feature, for example requestTemperature() without anything else, just displaying results on the serial monitor

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.