Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous reading from analog pin gets the same value #41

Open
ikamen opened this issue Jan 11, 2015 · 1 comment
Open

Continuous reading from analog pin gets the same value #41

ikamen opened this issue Jan 11, 2015 · 1 comment

Comments

@ikamen
Copy link

ikamen commented Jan 11, 2015

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

@dapicester
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants