Sorry .. it's not the whole program just the snippet regarding the data in the buffer basically it's the last line of code lcd.write(bufferData); .. I know i need to have something above this line to manipulate the data in the variable ..
char bufferData ;
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
mySerial.begin(9600); // initialize the serial communications:
}
void probe1() {
mySerial.print("#01VC\r") ; Request probe temperature
delay(100);
if (mySerial.available()) {// when characters arrive over the serial port...
delay(100);// wait a bit for the entire message to arrive
lcd.setCursor(0,0);//Select Top left line of LCD
while (mySerial.available() ) {// read all the available characters
float x = mySerial.parseFloat();// Take the buffer , strip the header text and just display the value (Data returns VC=1234.546)
lcd.print(x,3); //Display 3 decimal places
lcd.print((char)223);//Display the Celsius symbol
lcd.print("C");
mySerial.print("#01LB\r") ; // Request probe label
delay(100);
if (mySerial.available()) {// when characters arrive over the serial port...
delay(100);// wait a bit for the entire message to arrive
lcd.setCursor(0,1); // Select bottom left line of LCD
while (mySerial.available() ) {// read all the available characters
bufferData=mySerial.read();// display each character to the LCD (Data Returns "LB=DD99/99-123456"-- only require "123456"
***SOMEHOW MANIPULATE THE VARIABLE HERE TO DISCARD 1ST 11 CHARS***
lcd.write(bufferData);
}
}
}
}
}
void loop() {
probe1();
delay(100);
}
RTD_DISPLAY_WORK_IN_PROGRESS:46: error: invalid types 'char[int]' for array subscript
lcd.write(&bufferData[10]);
^
exit status 1
invalid types 'char[int]' for array subscript
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(2, 3);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
char bufferData;
void setup() {
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
mySerial.begin(9600); // initialize the serial communications:
}
void probe1() {
mySerial.print("#01VC\r") ;// Read probe temperature
delay(100);
if (mySerial.available()) {// when characters arrive over the serial port...
delay(100);// wait a bit for the entire message to arrive
//lcd.clear();// clear the screen
lcd.setCursor(0, 0);
while (mySerial.available() ) {// read all the available characters
// lcd.write(mySerial.read());
// bufferData=mySerial.read();// display each character to the LCD
// lcd.write(bufferData);
float x = mySerial.parseFloat();// Take the buffer , strip the header text and just display the value (Data returns VC=1234.546)
lcd.print(x, 3);
lcd.print((char)223);
lcd.print("C");
mySerial.print("#01LB\r") ;//read Probe identifier
delay(100);
if (mySerial.available()) {// when characters arrive over the serial port...
delay(100);// wait a bit for the entire message to arrive
lcd.setCursor(0, 1);
while (mySerial.available() ) {// read all the available characters
lcd.write(mySerial.read());
// lcd.write(&bufferData[10]);
bufferData = mySerial.read(); // display each character to the LCD
// display each character to the LCD (Data Returns "LB=DD99/99-123456"-- only require "123456"
lcd.write(bufferData);
}
}
}
}
}
void loop() {
probe1();
delay(100);
}
OTOH you can count the number of chars you Serial.read(), do nothing with the first 11 and then print the rest. And then usually the code needs to do more.
But really, you don't need to buffer anything to do what you described or a whole lot more.
A buffer is a place to hold more than one piece of data. You implied that you had a string with more than 11 characters in it. Since that was not even close to true, there is simply no way to do what you want with the codr that you have.
PaulS:
No. Complete code is in reply #7. Code that doesn't do what OP says it does, but complete anyway.
SoftwareSerial mySerial = SoftwareSerial(2, 3);
OP: Do you really have a mySerial connected to the Arduino? If not, why are you calling it mySerial?
If you get a cat, do you call it myDog?
Running an Arduino RS232 shield V2 which is required because talking to some old industrial temperature probes.
The code works with what I have , it's returning all the data i'm requesting but i'm limited to a 16x2 LCD and the probe serial number is returned with the model number and header information. I simply want to remove all but the last 6 characters.
If i send #01LB ( It's asking for the probe on address 1 for it's info . It returns "LB=DD99/99-123456" which fills the whole of second line on the LCD display . I don't need any of the header "LB=" or the model number "DD99/99-" . All I want to display on the LCD is "123456".
o0timbo0o:
If i send #01LB ( It's asking for the probe on address 1 for it's info . It returns "LB=DD99/99-123456" which fills the whole of second line on the LCD display . I don't need any of the header "LB=" or the model number "DD99/99-" . All I want to display on the LCD is "123456".
Have a look at the parse example in Serial Input Basics. You could easily adapt it to split the data on the '-' char and copy the bit you are interested in to another char array.
o0timbo0o:
Running an Arduino RS232 shield V2 which is required because talking to some old industrial temperature probes.
The code works with what I have , it's returning all the data i'm requesting but i'm limited to a 16x2 LCD and the probe serial number is returned with the model number and header information. I simply want to remove all but the last 6 characters.
If i send #01LB ( It's asking for the probe on address 1 for it's info . It returns "LB=DD99/99-123456" which fills the whole of second line on the LCD display . I don't need any of the header "LB=" or the model number "DD99/99-" . All I want to display on the LCD is "123456".
So it is not a matter of removing anything. You just want to display the last 6. If you put all of it in a char array then you can use the method @ PaulS posted earlier.
o0timbo0o:
Running an Arduino RS232 shield V2 which is required because talking to some old industrial temperature probes.
The code works with what I have , it's returning all the data i'm requesting but i'm limited to a 16x2 LCD and the probe serial number is returned with the model number and header information. I simply want to remove all but the last 6 characters.
If i send #01LB ( It's asking for the probe on address 1 for it's info . It returns "LB=DD99/99-123456" which fills the whole of second line on the LCD display . I don't need any of the header "LB=" or the model number "DD99/99-" . All I want to display on the LCD is "123456".
Is there anything else you are saving that array for? Because if not then read all the chars but only print the ones you want one at a time and you don't need to save chars. It is also no big deal to read and evaluate numbers or match words with char by char stream input without text buffering or using the string.h library at all. I've done it since the 80's. You need less RAM and it's inherently quicker when dealing with serial data. My way you finish evaluation just after the final char arrives (if not sooner like a no-match non-numeric condition may evaluate on the 1st char) and the other way you start evaluation of the buffered text with numerous string.h commands only after the final char arrives.
Using a state machine makes it easier, the 2nd Nick Gammon tutorial addressed below covers an intro state machine that can read code+value combinations as his example code. It's a step to match chars in C strings instead of 1 code letter match but not a giant leap, just keep count of chars matched.
If i send #01LB ( It's asking for the probe on address 1 for it's info . It returns "LB=DD99/99-123456" which fills the whole of second line on the LCD display . I don't need any of the header "LB=" or the model number "DD99/99-" . All I want to display on the LCD is "123456".
A simple example of capturing the characters after the - using some old code.
//zoomkat 6-29-14 Simple serial echo test
//type or paste text in serial monitor and send
// LB=DD99/99-123456
String readString, newString;
void setup() {
Serial.begin(9600);
Serial.println("Simple serial echo test"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the String readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
Serial.println(readString); //so you can see the captured String
int pos = readString.indexOf('-');
newString = readString.substring(pos+1);
Serial.print("newString is: ");
Serial.println(newString);
//int val = newString.toInt();
//Serial.print("heart rate is: ");
//Serial.println(val);
readString=""; //clears variable for new input
newString=""; //clears variable for new input
}
}
Don't use String. In spite of numerous rational discussions, a few holdouts continue to think it's OK to recommend.
Character arrays, aka C strings, are a good way to start, and will have long-term benefits. Even in the short term, it will save about 1600 bytes of program space.
/dev:
Don't use String. In spite of numerous rational discussions, a few holdouts continue to think it's OK to recommend.
Character arrays, aka C strings, are a good way to start, and will have long-term benefits. Even in the short term, it will save about 1600 bytes of program space.
Cheers,
/dev
A bunch of us tell people that all time. They are wastey of RAM and cycles, they copy themselves just to add chars and shotgun the heap in the process. None of that is a real problem on a PC but using them on AVR's because you use them in PC code is like putting a bathtub on a bicycle because you have one in your house. All it shows is a deliberate disconnect of the hardware differences.
The same people are real big on transportable code. LOL, I want to transfer the code to a 168P (1K RAM) after being profligate with RAM due to Bad Habits Learned From Trivial Example Code, what do I do then besides either learn to code more tightly or just give up because of "hardware limits".
See what you can squeeze out of less RAM and your sketch may run on the smaller device instead of ratcheting up bigger all the time to run on wastey code.