Send a sine wave out of matlab to arduino
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to output the values from a sine wave to generate pulses for an h-bridge but don't know hot to send them one by one. is it possible for some help?
Code i did till now is attached below:
arduino=serial('COM2','BaudRate',9600);
fopen(arduino);
frequency = 1; % required frequency
period = 1/frequency; % required period
%amplitude = 127 ; % required amplitude
phase = 0; % required phase angle
offset = 127; % required DC offset
t = 0:0.00001:2*period;
output = 127 * sin(2*pi*frequency*t + phase) + offset;
0 comentarios
Respuestas (1)
Gautam Vallabha
el 9 de Abr. de 2012
I assume you want to output the sinusoid values to an "analog output" (PWM) pin.
Take a look at MATLAB Support Package for Arduino. It allows you to send commands from MATLAB to Arduino, e.g.
a = arduino('COM9');
a.pinMode(13,'output'); % digital output
a.pinMode(9,'output'); % "analog output" (PWM)
% output the digital value (0 or 1) to pin 13
a.digitalWrite(13, 0)
% ouptput value on digital (pwm) pin 5
a.analogWrite(9, 120)
(The above code is from examples/example_io.m in the support package).
0 comentarios
Ver también
Categorías
Más información sobre Arduino Hardware en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!