arduino_firmata icon indicating copy to clipboard operation
arduino_firmata copied to clipboard

Continuous reading from analog pin gets the same value

Open ikamen opened this issue 10 years ago • 1 comments

Hi,

I'm trying to get the value of a sensor on regular intervals. I try running this simple code

require "arduino_firmata"
arduino = ArduinoFirmata.connect "/dev/ttyACM0"
5.times do
   puts arduino.analog_read(1)
   sleep 5
end
arduino.close

but I get the same value regardless how the conditions for the sensor change. If I put the arduino initialisation and close within the loop it works, but this is far from optimal way of doing it. I'd like to be able to initialise the object and work with it for a while before closing.

I'm running it with Firmata 2.4.0 on a raspberry pi.

Any ideas?

Thanks, Kamen

ikamen avatar Jan 11 '15 19:01 ikamen

Don't forget that you need to declare that the pin is used for input: Put this right before your loop:

arduino.pin_mode 1, ArduinoFirmata::INPUT

dapicester avatar Jul 26 '16 03:07 dapicester