How to remove some characters off a char

Hey Guys and Gals :blush: :blush:

I have yet another problem,

I've gotten my SIM 900 board to speak with my arduino now I'm sending commands and its receiving them, See my updated sketch below:

#include <SoftwareSerial.h>

SoftwareSerial SIM900(2, 3);

void setup() {
  Serial.begin(9600);
  SIM900.begin(4800);
  Serial.println("Comm's initiated");
  
  SIM900power();
  Serial.println("SIM 900 Power Cycle Complete Switch On!");
}

void SIM900power()  {
  digitalWrite(8, HIGH);
  delay(5000);
  digitalWrite(8, LOW);
  delay(10000);
}

void loop() {
  
  SIM900.print("AT+CSQ\r");
  delay(5000);
  
  while (SIM900.available() > 0)  {
    char che = SIM900.read();
    Serial.print(che);
    
  }
}

My big problem now is I want my variable (che) to be smaller, see attached Serial Monitor Capture,

As you can see on the Serial Monitor it prints
AT+CSQ
+CSQ: 10,0

OK

I want to remove all the characters excluding the 10 (the ,0 isnt a train smash)

Is there someone here that can show me how to do this?

Thanks
Cal :smiley:

The examples in serial input basics may give you some ideas.

You need to think about the features that identify the data you want to extract.
For example is it always the first thing after a colon and is it always followed by a comma ?

If it is, then you can use those characters as start and end markers.

...R

Hello,

A char can hold only one character. It can't be longer or shorter than that :wink:

Your code is reading and printing one character at a time. But it's so fast, that you think it's all printed at once.

The easiest way you could do what you want, is by removing your while loop and replace it with:

Serial.println( SIM900.parseInt() );

guix:
Hello,

A char can hold only one character. It can't be longer or shorter than that :wink:

Your code is reading and printing one character at a time. But it's so fast, that you think it's all printed at once.

The easiest way you could do what you want, is by removing your while loop and replace it with:

Serial.println( SIM900.parseInt() );

This works like a charm, the only problem is it carry's the decimal point as well eg.

if the output is 10,0 the Serial Monitor outputs 10 and the next output is 0, any way I can tell it not to count the decimal point? Thanks Alot :slight_smile: :slight_smile:

I think that you just need to remove all characters from the buffer, after you have read this int.

Try:

// read and print int
Serial.println( SIM900.parseInt() );

// remove all characters after the int
while (SIM900.available() > 0)
    SIM900.read();

Also I suggest that you look and use the method from the Blink Without Delay example. Relying on delays to fix your code isn't a good solution :wink:

THAT WORKED AS WELL! Thank you! I Shall look into the Blink without delay :wink: Thank you so much again

senorcallum, can you post your updated code? I'm trying to do the same thing with a SIM900 and I can't get it to parse correctly. Thanks.