How to read analog data instantaneously from Arduino to MATLAB?

15 ビュー (過去 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
  1 件のコメント
KEVIN PAUL
KEVIN PAUL 2023 年 2 月 21 日
Thank you so much for the timely help

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by