Pages: [1]   Go Down
Author Topic: Simple analogRead problem with Firmata  (Read 1060 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have recreated this little circuit: http://arduinobasics.blogspot.com/2011/06/arduino-uno-photocell-sensing-light.html

which just sends the output of a photocell to the A0 analog pin on the Arduino. All I want to do is read this value and display it on my screen with Processing. I did this successfully without Firmatta, but I'll need to do some more complex interactions later on and need to use Firmatta for communications.

The problem is that the analogRead function doesn't seem to work - the value stays at 0 and doesn't change. Here is my code:

In setup, I initiate the arduino and set the pin mode:
Code:
arduino = new Arduino(this, Arduino.list()[0], 57600);
arduino.pinMode(0, Arduino.INPUT);

I have tried changing the pin number to 16 (no change), and the mode to ANALOG and OUTPUT (no change).

In draw, I write some text to the screen with the value from analogRead:
Code:
text("Sensor Reading: " + arduino.analogRead(0), width/20, height/2);

I tried changing the pin number to 16 here, but that crashes the app with the error ArrayIndexOutOfBoundsException.

What is the issue? I feel like I have tried all the combinations of possible parameters - is there some setup step I am missing?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
In setup, I initiate the arduino and set the pin mode:
Which, of course is silly, since analog pins are INPUT only. The pinMode function does not know that it should do anything with analog pins, because there is nothing it can do with analog pins. So, it knows that the pin number you input refers to a digital pin. Diddling with a serial pin is really not a good idea.

Quote
I feel like I have tried all the combinations of possible parameters - is there some setup step I am missing?
Except perhaps the most obvious which is to not use pinMode() at all, because it is not needed
Logged

Pages: [1]   Go Up
Jump to: