Does softwareSerial recognise available()?

Hi all,

I am getting conflicting answers in searching and reading about using available() with softwareSerial?

Could anyone enlighten me as to the truth. Can you use for instance:

if(mySerial.available()){
      
//do stuff here
    }

cheers

Larp-fx:
Hi all,

I am getting conflicting answers in searching and reading about using available() with softwareSerial?

Could anyone enlighten me as to the truth. Can you use for instance:

if(mySerial.available()){

//do stuff here
    }




cheers

yes SoftwareSerial inherits from Stream

Excellent,

cheers

(deleted)

I did try it first, couldn’t get it to work so did some research to see if I could find the problem / solution.

I still can’t get this simple receiver for a HC12 module to work however.

So any tips would be great.

//////////////////////////

#include <SoftwareSerial.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

SoftwareSerial MySerial(4, 5); // RX, TX


#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);





void setup() {
  MySerial.begin(9600); //begins HC-12 to receive serial data
  Serial.begin(9600); //begins PC serial data
  display.begin();
  

 
  display.setTextColor(WHITE);

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Ready to receive");
  display.display();
  
}

void loop() {
 
 
  if(MySerial.available() ){//Read from HC-12 and send to OLED
  
     String input = MySerial.readString();//Get string from HC-12, store as "input"
      display.clearDisplay();    
      display.setTextSize(1);    
      display.setTextColor(WHITE);
      display.setCursor(0, 20);
      display.println(input);//Prints the string "recieve" onto the OLED"
      Serial.println(input);//print to the monitor also to check 
      display.display();
    
  }
}

Larp-fx:
I still can't get this simple receiver for a HC12 module to work however.

SoftwareSerial MySerial(4, 5); // RX, TX


#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

I wonder if sharing pin4 has anything to do with it...

Have you tried printing MySerial.available() ?

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

What does the 4 here relate to ?

Hi chaps,

TBH I am not sure what that OLED_RESET 4 means, as I just copied that across from some other code. I assumed, probably wrongly that it was needed.

I have changed it to an unused digital Pin.

Still no luck though.

I tried printing MySerial.available and that does nothing?

cheers

Larp-fx:
I tried printing MySerial.available and that does nothing?

It didn't print anything at all? Well you must have done it wrong. Why don't you post that code and let's see what you did wrong.

Larp-fx:
I assumed

Assumption is the mother of all f&%k-ups. When you don't understand something like that, then it is time to take a step back and do some learning.