Change analog reference voltage using Arduino IO Package.

10 views (last 30 days)
I'm trying to change the analog reference voltage on an Arduino Duemilanove from the default (5v) to an external reference (in my case 3.3v) connected to the Aref pin. The Arduino is interfaced with MATLAB using the Arduino IO Package.
From line 1392 of the included Arduino.m file, this should be achieved with
a.analogReference('external');
However, running any code after that command causes MATLAB to hang on 'Busy' for a few seconds before displaying the following error:
Warning: A timeout occurred before the Terminator was reached.
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> testIR at 8
data(n) = a.analogRead(analogPin);
Here is my minimal test code:
a = arduino('my COM port here') % connect to Arduino
analogPin = 1;
a.analogReference('external'); % change aref voltage
a.analogRead(analogPin) % read from sensor connected to analog pin
The only way I've found to successfully change the reference voltage is by adding the command to the setup() section of the adiosrv.pde code before uploading it to the board using the Arduino IDE. This isn't ideal, as I'd like to be able to change it from within MATLAB, and that does seem to be a supported feature.
Any help is much appreciated. Thank you!

Accepted Answer

Nicholas Flenghi
Nicholas Flenghi on 5 Oct 2011
For anyone interested,
It turns out you must be using the srv.pde sketch to be able to change the analog reference voltage from within MATLAB.
Note that srv.pde requires the adafruit motor shield libraries (AFmotor) be installed as well.
  1 Comment
Krishnakumar Gopalakrishnan
Can you please elaborate on this further? How does one go about changing the reference by editing srv.pde? What are the exact steps? Any help will be much appreciated.

Sign in to comment.

More Answers (0)

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!