Hi guys,
I just finished my sketch which seems to be working OK for the most part.
It pulls serial data from an ORP stamp from Atlas Scientific and displays it on the serial plotter fine. With some more code I got it to display on an LCD display as well but the only problem is that it is displaying a character I would like to have removed.
I believe it is a carriage return or new line character that is read from the serial data, but cant be to sure. It looks Korean on the display..
I tried to find a solution and the closest I got was to define a new string and try to remove this character:
inString = inString.replace("\n","");
My code looks a bit different, you can find it below in the full code of the sketch. Close to the end: tst = sensorstring.replace("\n","");
But this does not seem to work for me. I get an error:
exit status 1
no match for 'operator=' (operand types are 'String' and 'void')
I tried left and right to figure it out but am lost. Why is the code not working in my example? What have I done wrong here?
Below my full code:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // Using version 1.2.1
// The LCD constructor - address shown is 0x27 - may or may not be correct for yours
// Also based on YWRobot LCM1602 IIC V1
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Strings clearen
String inputstring = "";
String sensorstring = "";
String tst = "";
// waar of niet waar dat de input_string compleet is op false zetten
boolean input_stringcomplete = false;
boolean sensor_stringcomplete = false;
// Setup
void setup(){
// Init LCD
lcd.begin(16,2); // sixteen characters across - 2 lines
lcd.backlight();
// Init Serial
Serial.begin(38400);
Serial3.begin(38400);
inputstring.reserve(5);
sensorstring.reserve(30);
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
}
void serialEvent() {
char inchar = (char)
Serial.read();
inputstring += inchar;
if(inchar == '\r') {input_stringcomplete = true;}
}
void serialEvent3(){
char inchar = (char)Serial3.read();
sensorstring += inchar;
if(inchar == '\r') {sensor_stringcomplete = true;}
}
void loop(){ //here we go....
if (input_stringcomplete){
Serial3.print(inputstring);
inputstring = "";
input_stringcomplete = false;
}
if (sensor_stringcomplete){
Serial.println(sensorstring);
// Temp loop
sensors.requestTemperatures(); // Send the command to get temperatures
// Replace-code which is going wrong during compiling
tst = sensorstring.replace("\n","");
// print to LCD
lcd.setCursor(0,0);
lcd.print("ORP waarde: " + sensorstring);
lcd.setCursor(0,1);
lcd.print("Temperatuur: ");
lcd.print(sensors.getTempCByIndex(0));
sensorstring = "";
sensor_stringcomplete = false;
}
}
If you guys could hep getting the replace code to do what I need it to do that would be greatly appreciated. But any other solution to removing the character would also be fine.
Thx!