Printing numbers and letters to I2C LCD using serial communication

27 ビュー (過去 30 日間)
N/A
N/A 2019 年 8 月 6 日
Hi everyone,
I'm currently using an Arduino Uno with a I2C LCD hooked up to it. I've browsed through a bunch of the posts and have tried numerous strategies to get my I2C display to display numbers and a string. Anything I output is just giving me whole numbers like 100, 101, 110 etc. I'm not getting any text at all. What I would like it to display on my LCD Screen is "Heart Rate: 79.95"
Here is what I have:
arduino=serial('/dev/tty.usbmodem14101','BaudRate',9600);
fopen(arduino);
heartrate=79.95;
fprintf(arduino,'Heart Rate: %d\n',heartrate);
fclose(arduino);
I've varied fprintf (ex: fprintf(arduino,'%.2f',heartrate)) to just print a decimal number and it also won't do it, I still get whole numbers.
Any ideas?

採用された回答

N/A
N/A 2019 年 8 月 8 日
I ended up solving my problem. For future reference, if you are trying to use an I2C LCD with Arduino there's a couple of steps you have to follow.
  1. Install Matlab Arduino Hardware Support Packages
  2. Install Arduino IDE
  3. Find the correct port for your device on Windows (COM) or Mac (/dev/tty or /dev/cu)
  4. Install LiquidCrystal_I2C and find your I2C address
  5. Read the thread by Robin2 and use the code that matches your needs
  6. Search for fprintf_r and install in Matlab directory
  7. This snippet of code sends the heartrate to Arduino IDE
calculated_HR = 79.95;
heartrate=num2str(calculated_HR);
fprintf(arduino,heartrate);
fprintf_r('reset');
Two things to note: First, it's really important to convert your double to a string since Arduino will be receiving it as an array of characters. Second, fprintf_r is needed because it basically sends a carriage end to Arduino to signify that's the end of the transmission.
Hope this helps.
  1 件のコメント
Phan Tien Manh
Phan Tien Manh 2023 年 12 月 7 日
I have the same problem with u, can u show me how to do

サインインしてコメントする。

その他の回答 (1 件)

MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team 2023 年 12 月 8 日
編集済み: MathWorks MATLAB Hardware Team 2023 年 12 月 8 日
Hi,
You can utilize the MATLAB Support Package for Arduino hardware along with an LCD addon in order to display the required characters.
For additional information, please refer to the following links:
Thank you,
MATLAB Hardware Team
MathWorks
  2 件のコメント
Phan Tien Manh
Phan Tien Manh 2023 年 12 月 8 日
when i write:
s = serialport("COM5",9600)
it always shows this error:Unable to connect to the serialport device at port 'COM5'. Verify that a device is connected to the port, the port is not
in use, and all serialport input arguments and parameter values are supported by the device.
See related documentation for troubleshooting steps.
Why ?
MathWorks MATLAB Hardware Team
MathWorks MATLAB Hardware Team 2023 年 12 月 11 日
Hi,
You can verify the availability of the COM5 port by using the Device Manager in Windows or by executing >> serialportlist('available') in MATLAB.
Once you have confirmed this, you can proceed with the troubleshooting steps outlined in the following link.
Also feel free to contact MathWorks Technical Support to get help on resolving this issue.
Thanks,
MATLAB Hardware Team
MathWorks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB Support Package for Arduino Hardware についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by