- Does it output a ASCII stream which represents a single number?
- Does it output multiple ASCII streams which represent different numbers?
Simulink Conversion from uint8 to ASCII/Char
14 views (last 30 days)
Show older comments
Hey everyone,
So basically in short what I need to happen is for my Seiral Recieve (Arduino Support Hardware) to take in an input from my Ardunio Mega RX1 pin (which is getting information from the serial monitor from my USB to TTL converter) and convert it to an integer that I can work with later on.
Currently what is happening is, when I inout numbers into the serial monitor, the scope of the Serial Receive output is clearly showing the bytes represntation of the numbers, for example i put in "1" and the Serial Receive is sending "49".
My question is,
How do I convert that data type from uint8 to something i can use later on (Need the actual number).?
How do I make it such it can read double or even triple digits too? (If i put in 24, it only reads the "2" and sends back 50, would love for it to send back 24. Do I use the terminator? if so what do i put in it, and how do i ignore the 0's).
Thanks guys!
1 Comment
Malay Agarwal
on 25 Sep 2024
Could you share more details of what the Data signal of the "Serial Receive" block outputs?
For example:
Answers (1)
Deep
on 22 Oct 2024
The serial data is being sent as a string datatype, which is then interpreted as its ASCII values. It appears that you are using the default configuration of the "Serial Receive" block, which outputs data of fixed length 1. To handle multi-digit numbers, you should configure the block to use variable length data. This tutorial provides a detailed guide on how to achieve this for string data types: https://www.mathworks.com/help/simulink/supportpkg/arduino_ref/send-and-receive-data-of-variable-lengths-using-arduino-serial-communication-blocks.html. The tutorial also includes an example model that you can examine for better understanding.
Once you've configured the "Serial Receive" block to receive a variable-length string like "123", you can convert this string to a numerical data type using the "String to Single" block. More information on this block can be found here: https://www.mathworks.com/help/simulink/slref/stringtosingle.html.
0 Comments
See Also
Categories
Find more on Modeling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!