I2C prints 0 or 1 instead of string

I'm trying to print message from HM-10 on my LCD (16x2) by the following code

#include <SoftwareSerial.h>
#include <LCD_I2C.h>

SoftwareSerial HM10(2, 3);

LCD_I2C lcd(0x27, 16, 2);

char appData;  
String inData = "";

bool needUpdateScreen;

void setup()
{
    lcd.begin();
    lcd.backlight();
    Serial.begin(9600);
    HM10.begin(9600);
}

void loop()
{

  HM10.listen();
  while (HM10.available() > 0) { 
    appData = HM10.read();
    inData = String(appData);
    Serial.write(inData.c_str());
    Serial.write(appData);
    needUpdateScreen = true;
  }

  if(needUpdateScreen){
    lcd.clear();
    lcd.print(inData);
    //lcd.print("TEST");
    needUpdateScreen = false;
  }
}

When I print "TEST" it works without any problem. When I print "inData" I see only 1 or 0.
Something wrong with types?
Many thanks!

Solved by using

void serialRead() { 
  while (HM10.available()) {
  delay(10);  
  if (HM10.available() >0) {
    char c = HM10.read();
    readString += c;}
  }
}

What do you see on serial monitor? Perhaps 1 and 0 is what is being received?

In serial monitor I see the whole string.

But what is the whole string?

1 Like

I send "MM1" or "MM0" from my ios app. Now, with the serialRead function I can print the whole message. The strange thing was that serial was printing whole message even without "serialRead" function.

What function is that? I don't see it in your code. If you meant to say Serial.read(), why do you think that would be needed?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.