How can I send this Matlab code to Arduino?

조회 수: 5 (최근 30일)
Thakshila Dayani
Thakshila Dayani 2022년 1월 31일
댓글: Walter Roberson 2022년 1월 31일
How can I send this Matlab code to Arduino? Then how does it transmit?
I need to transmit Matlab image binary data using Ardunio.
This is my matlab code:
filename = 'dog.jpg';
img = imread(filename);
bitstream = reshape((dec2bin(img(:), 8) - '0').', 1, []);
reconstructed = uint8( reshape(bin2dec(reshape(char(bitstream + '0'), 8, []).'), size(img)) );
imshow(img);
title('original');
imshow(reconstructed);
title('reconstructed');

답변 (1개)

Walter Roberson
Walter Roberson 2022년 1월 31일
You cannot send that code to Arduino.
In order to send MATLAB code to Arduino, you need to use MATLAB Coder, or you need to write the code as a Simulink MATLAB Function Block and configure Simulink to target Arduino.
However, the Arduino has no file system (or other operating system), and so it is not possible to imread() on an Arduino.
It is also not generally possible to create graphics on Arduino. However if you are using Simulink then you could use the Simulink Hardware Support Package for Arduino together with the block that can write to an LCD display.
If the question is how you can send the content of bitstream to the Arduino, then the answer is that you create an arduino() object and you fwrite() to it.
But as I have already advised you, it is not efficient to convert your original data into one byte per bit and send those bytes. It is more efficient to write entire bytes and have the arduino extract the bits.

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by