How to read analog data instantaneously from Arduino to MATLAB?

14 vues (au cours des 30 derniers jours)
KEVIN PAUL
KEVIN PAUL le 19 Déc 2022
Commenté : KEVIN PAUL le 21 Fév 2023
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.

Réponse acceptée

Dhruv
Dhruv le 20 Fév 2023
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

Plus de réponses (0)

Catégories

En savoir plus sur Arduino Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by