- 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 (최근 30일)
이전 댓글 표시
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
Malay Agarwal
2024년 9월 25일
Could you share more details of what the Data signal of the "Serial Receive" block outputs?
For example:
답변 (1개)
Deep
2024년 10월 22일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Modeling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!