HELP Arduino flowmeter code

7 Ansichten (letzte 30 Tage)
Maria
Maria am 7 Jul. 2014
Beantwortet: Sunay Poole am 26 Mär. 2015
I am using an Arduino UNO interfaced with MATLAB to read a flowmeter using water from the sink. I want to plot the results using MATLAB but I am having trouble with the code.
This are the steps I am using: 1. Connect the flowmeter with the Arduino using a Breadboard and some cables, and the Arduino to the computer through a USB 2. Upload the adioes.pde flie in the Arduino IDE Software 3. Run Matlab code
  • Matlab attempts connection with the Arduino but it doesn't recognize the encoderAttach function.
This is the MATLAB code I used:
function read_Flow2 (cycle)
global NbTopsFan Calc hallsensor a t;
a=arduino('COM5');
hallsensor =2;
Calc = (NbTopsFan * 60 / 5.5);
passo=1;
t=1;
a.pinMode(hallsensor,'input');
a.digitalWrite(hallsensor,0);
for NbTopsFan=0;
a.encoderAttach(0,hallsensor);
a.encoderRead(0);
a.encoderDebounce(0,1);
a.encoderDetach(0);
end
while (t<cycle)
state =a.digitalRead(hallsensor);
t=t+passo;
drawnow;
plot(t, state);
axis([0, cycle, 0, 300]);
grid on;
title('Flow');
xlabel('Time');
ylabel('rpm');
pause(1);
end
delete(a)
clear a
end
Thank you
  2 Kommentare
Nazrin Zaini
Nazrin Zaini am 11 Nov. 2014
so do you have the solution?
luc
luc am 16 Mär. 2015
I use the serial.print interface to connect my sensor loops to matlab. So send using serial.print and receive using:
s1 = serial('COM4'); %define serial port - where the arduino is connected
s1.BaudRate=115200; %define baud rate - 9600 for old sensor, 115200 for new
fopen(s1); %open the port
test=fscanf(s1);
Then let matlab loop while u drain data from the arduino that also loops.
Does this help you in any way?

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Gianmaria
Gianmaria am 16 Mär. 2015
Hi!
Currently i have the same issue. I'm trying to using encoderAttach command with no luck. Here what i get:
>> encoderStatus(a);
Undefined function 'encoderStatus' for input arguments of type 'arduino'
>> encoderAttach(a,0,PIN_A,PIN_B)
Undefined function 'encoderAttach' for input arguments of type 'arduino'
Using methods(a) seems that encoderAttach is not available
>> methods(a)
Methods for class arduino:
addon i2cdev spidev
configureAnalogPin playTone writeDigitalPin
configureDigitalPin readDigitalPin writePWMDutyCycle
details readVoltage writePWMVoltage
disp scanI2CBus
display servo
What could be the problem?
Thanks

Sunay Poole
Sunay Poole am 26 Mär. 2015
Hi,
Would you mind providing a link to which MATLAB support package you used? I have the same problem in a way, but with the 'playTone' function. I am currently trying to use the 'playTone' function, but it appears to not exist in the arduino class. When I enter the command 'methods(a)', 'playTone' is not listed, as it is here. I'm not sure if the library that I downloaded with the support package is equipped with this function or not.
Thanks for any help!

Kategorien

Mehr zu Instrument Control Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by