How can I send this Matlab code to Arduino?

4 views (last 30 days)
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');

Answers (1)

Walter Roberson
Walter Roberson on 31 Jan 2022
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.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!