Go Down

Topic: Struggling with manipulating data from serial buffer (Read 1 time) previous topic - next topic

o0timbo0o

I am reading data from the serial buffer into a variable char bufferData

I would like to manipulate some of this data by scrapping off the 1st 11 chars and print the remaining data to the lcd.write(bufferData)

I can write all  the data stored in the variable to the LCD with no issues. Lack of knowledge is preventing me going any further.



Delta_G

Lack of knowledge is preventing me going any further.
And the lack of seeing your code is stopping us from helping you.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

PaulS

If the data is in an array called bufferData, Serial.print(bufferData) will print the data starting at position 0.

Serial.print(&bufferData[10]) will print the data starting in position 11. Perhaps a clue will present itself.
The art of getting good answers lies in asking good questions.

o0timbo0o

#3
Dec 15, 2015, 07:01 pm Last Edit: Dec 15, 2015, 07:18 pm by o0timbo0o
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 ..


Code: [Select]


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);
}

PaulS

Quote
***SOMEHOW MANIPULATE THE VARIABLE HERE TO DISCARD 1ST 11 CHARS***
             
             lcd.write(bufferData);
You don't need to "manipulate the variable". You just need to define where to start printing:
Code: [Select]
   lcd.write(&bufferData[10]);
The art of getting good answers lies in asking good questions.

o0timbo0o

You don't need to "manipulate the variable". You just need to define where to start printing:
Code: [Select]
   lcd.write(&bufferData[10]);
doesn't like it


exit status 1
invalid types 'char[int]' for array subscript

PaulS

All of your code and the EXACT error message, or stop wasting our time.
The art of getting good answers lies in asking good questions.

o0timbo0o

#7
Dec 15, 2015, 07:54 pm Last Edit: Dec 15, 2015, 08:21 pm by o0timbo0o
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

 
Code: [Select]

#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);




}



GoForSmoke

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.
1) http://gammon.com.au/blink  <-- tasking Arduino 1-2-3
2) http://gammon.com.au/serial <-- techniques howto
3) http://gammon.com.au/interrupts
Your sketch can sense ongoing process events in time.
Your sketch can make events to control it over time.

PaulS

Code: [Select]
char bufferData;
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.
The art of getting good answers lies in asking good questions.

Delta_G

|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

PaulS

Is it time to go here?

http://snippets-r-us.com/
No. Complete code is in reply #7. Code that doesn't do what OP says it does, but complete anyway.

Code: [Select]
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?
The art of getting good answers lies in asking good questions.

o0timbo0o

No. Complete code is in reply #7. Code that doesn't do what OP says it does, but complete anyway.

Code: [Select]
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".






Robin2

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.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Delta_G

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.
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Go Up