Hi all,
I am trying to read turbidity measurements from a serial sensor with inverted polarity (Seapoint Turbidity Sensor, STM-S) on an Arduino UNO with a data logger shield (Adafruit) attached. The data logger shield has a 1307 RTC and a micro SD reader. The sensor is connected to digital pin 3 and 4, and the code that I am using is as follows:
#include <RTClib.h>
#include <SoftwareSerial.h> // for the Turbidity (STM-S) sensor
#define TIME_ADJUSTMENT 0 // Adjusting the time on RTC
#define WAIT_TO_START 1 // Wait for serial input in setup()
char Turb = '0';
RTC_DS1307 RTC; // the Real Time Clock object
// Defining the pins for Turbidity sensor for inverted poarity serial reading
SoftwareSerial TurbiditySer(3, 4, true);
void setup()
{
//initializing the Turbidity (STM-S) sensor
Serial.begin(115200);
TurbiditySer.begin(115200);
delay(500);
#if WAIT_TO_START
Serial.println("Type any character to start");
while (!Serial.available());
#endif //WAIT_TO_START
if (!RTC.begin()) {
Serial.println("RTC failed");
}
#if TIME_ADJUSTMENT
// following line sets the RTC to the date & time this sketch was compiled
Serial.println("Time adjusted!!");
RTC.adjust(DateTime(F(__DATE__), F(__TIME__)));
#endif
Serial.println("DateTime, Turbidity(NTU)");
}
void loggingTime() {
DateTime now = RTC.now();
Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.print(",");
delay(2000);
}
void loop()
{
loggingTime();
if (TurbiditySer.available()) {
Turb = TurbiditySer.read();
Serial.println(Turb);
}
}
Here is a sample of the output that I am getting:
Type any character to start
DateTime, Turbidity(NTU)
2003/19/1 1:21:48,3
2019/1/15 21:48:2,5
2019/1/15 21:48:4,.
2019/1/15 21:48:6,7
2019/1/15 21:48:8,9
2019/1/15 21:48:10,6
2019/1/15 21:48:12,,
2019/1/15 21:48:14,8
2019/1/15 21:48:16,8
2019/1/15 21:48:18,6
2019/1/15 21:48:20,7
2019/1/15 21:48:22,
However, with the same assembly without any changes, if I upload the following code I can get correct pair of reading from the sensor:
#include <SoftwareSerial.h>
SoftwareSerial mySer(3, 4, true);
char inData = '0';
void setup(){
Serial.begin(115200);
mySer.begin(115200);
delay(500);
}
void loop(){
if(mySer.available()){
inData = mySer.read();
Serial.print(inData);
}
}
which looks like:
35.958,8866.4
35.909,8865.2
35.992,8867.1
35.852,8868.5
35.927,8864.5
35.920,8865.4
Could you please help me figuring out why I can't get correct readings from the sensor?