How to read analog data instantaneously from Arduino to MATLAB?

조회 수: 13 (최근 30일)
KEVIN PAUL
KEVIN PAUL 2022년 12월 19일
댓글: KEVIN PAUL 2023년 2월 21일
I have been developing a code where i want to read analog values from ARDUINO to MATLAB instantaneously and i want to create a heat map where the analog values should fill the matrix and display the suitable color for the matrix..I have been trying to develop a 4*4 grid.
The issue i'm facing here is cannot read analog value instantaneously from arduino to matlab instant im getting only one value and in heat map i cannot read values...any suggestions or guidance if i could read analog value and fill the analog value into the matrix which reflects the particular color for the obtained value. Thank you!.
Here is my code which i have developed in MATLAB
% code for analog value read
clc; clear all; close all;
a = arduino;
readVoltage(a,'A0');
% code for heatmap
rand('seed',10000);
A=rand(4,4);
imagesc(A);
axis equal tight.

채택된 답변

Dhruv
Dhruv 2023년 2월 20일
Making use of loop can help continuously read analog values from Arduino to MATLAB. Below mentioned is an example code to continuously read analog values from one pin (A0) of Arduino and store them in a MATLAB matrix:
% Create an arduino object
a = arduino();
% Define the pin to read from
pin = 'A0';
% Define the number of readings to store e.g. 100
numReadings = 100;
% Define the delay between readings (in seconds)
delay = 0.1;
% Initialize the data matrix
dataMatrix = zeros(numReadings, 1);
% Start reading analog values and storing them in the data matrix
for i = 1:numReadings
% Read the analog value from the pin
analogValue = readVoltage(a, pin);
% Store the analog value in the data matrix
dataMatrix(i) = analogValue;
% Pause for the specified delay
pause(delay);
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by