Interfacing I2C LCD with Matlab and Arduino

Hi everyone,

I'm attempting to display a double variable from Matlab (ex. 79.95) on my LCD using Arduino. I was taking a look at the thread "Serial Input Basics" and the only way I can get it to display something even close to 79.95 is by using char. I have attached a picture of what the output looks like.

Here is my Arduino code:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

char matlabData;

void setup()
{
lcd.begin(); // initialize the lcd
lcd.backlight();
Serial.begin(9600);
lcd.print("Heart Rate: ");
lcd.setCursor(12,0);
lcd.blink();
}

void loop()
{
// when numbers arrive over the serial port
if (Serial.available() > 0) {
matlabData=Serial.read();
lcd.print(matlabData);
}
}

Can someone please point me in the right direction?

Thank you for reading!

1 Like

matlabData=Serial.read(); Serial.read returns a single character.
"79.95" is at least five characters.

See Robin2's excellent thread on handling serial.

Please remember to use code tags when posting code.

Does the matlab data end with a carriage return and line feed (/r/n)? That may be the odd characters after the number. Either donlt send the /r/n or remove them from the received characters. Or use Robin2's serial input basics example to read serial data with end markers and make '/r' or '/n' as the end marker.

Thank you both for the help! I ended up completing my project. It turns out that I wasn't doing a carriage return and after I placed it in my script everything worked out.