Hi there,
I am sending data across serial communication protocol from Simulink/Matlab to Arduino, I am trying to debugg what kind of data I am receiving, The code above reads a single sent data from matlab & displays it in an lcd screen. does anyone have an idea about what I am receiving ?
here are the sent & received data
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display
int foundValue = 0;
int cursor = 0;
void setup() {
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
byte rc;
rc = Serial.read();
lcd.setCursor(cursor, 0); //Set cursor to character 2 on line 0
cursor += lcd.print(rc); //print serial value to LCD
cursor += lcd.print(" ");
}
delay(1000); //Wait for 1s
if (cursor >= 16) {
lcd.clear();
cursor = 0;
}
}```
what arduino are you using?
are you sure the LCD is displaying correctly? e.g. does a simple test writing text to the display work OK
make sure both Matlab and the arduino are using the same baudrate, data bits, etc
if Matlab is transmitting ASCII text Serial.read reads a byte try Serial.readString()
yes, it works well! I already tried it with Hello world code & it works well!
you can verify that baudrate is the same in the provided arduino code & in this simulink picture
I'll give it a tray & I'll get back to you !
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x3F for a 16 chars and 2 line display
int foundValue = 0;
int cursor = 0;
void setup() {
lcd.init();
lcd.clear();
lcd.backlight(); // Make sure backlight is on
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
String rc;
rc = Serial.readString();
lcd.setCursor(cursor, 0); //Set cursor to character 2 on line 0
cursor += lcd.print(rc); //print serial value to LCD
cursor += lcd.print(" ");
}
delay(1000); //Wait for 1s
if (cursor >= 16) {
lcd.clear();
cursor = 0;
}
}```
if you use the Arduino Serial Monitor and type characters on the keyboard do they appear OK on the LCD? if so this proves you can receive ASCII text and display it OK
is Simulink transmitting ASCII text or binary (I have used Matlab but not Simulink)
if text try adding a newline terminator ('\n' in C)