0

I am trying to use Processing with Arduino Uno board to read the change of voltage done by a potentiometer. The code is simple:

import processing.serial.*;
import cc.arduino.*;

Serial myport;
Arduino arduino;

color off = color(4, 79, 111);
color on = color(84, 145, 158);
int val=0;
float value=0;
void setup() {
  size(600, 600);
  println(Arduino.list());
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  arduino.pinMode(0, Arduino.INPUT);
}

void draw() {
  stroke(on);
  value = arduino.analogRead(0);
  println(value);
  ellipse(300,300,value,value);
  delay(100);
}

My question is: For analog pins in Arduino IDE one should type A0, A1, ... but here in Processing IDE it is an error to type so. Is it possible that Processing reads the wrong pin? Because in Serial output I always get zero, however, for the same circuit in Arduino IDE the values change as I turn the potentiometer knob. Thanks

Amin
  • 113
  • 1
  • 6
  • Have you uploaded the firmata to arduino? (instructions from arduino playground - "Run Arduino, open the Examples > Firmata > StandardFirmata sketch, and upload it to the Arduino board." – brtiberio Nov 18 '15 at 14:15
  • Yes, I already did that. Also tried different values as the port number but still the outputs are always zero – Amin Nov 18 '15 at 14:23
  • you have a typo in code? val = arduino.analogRead(0); shouldn't it be value? Because after you only use value and never val – brtiberio Nov 18 '15 at 14:44
  • it was typo in the code here but in my original code it is correct. – Amin Nov 18 '15 at 19:35
  • 1
    strange... your code works ok with me. I've shorted the 3.3v to analog A0 and your code fluctuates between 679~680 in processing screenshot. if it helps, this is the software versions I'm using: Processing - 3.0.1 Arduino IDE - 1.6.6 Firmata - 2.5.0 – brtiberio Nov 19 '15 at 09:42
  • I downloaded the new version of Firmata for Arduino and now it works. Strange! But it is solved anyway. Thank you very much. – Amin Nov 19 '15 at 11:06
  • @Personagem it seems your comment led the author to solving his problem. You should bump it down to an answer and hopefully the OP will accept it for you :) – Madivad Nov 19 '15 at 11:46

1 Answers1

0

(as suggested in comments to bump it down)

your code works ok with me. I've shorted the 3.3v to analog A0 and your code fluctuates between 679~680 in processing

screenshot

If it helps, this is the software versions I'm using: Processing - 3.0.1 Arduino IDE - 1.6.6 Firmata - 2.5.0

brtiberio
  • 926
  • 5
  • 15
  • Just a comment that can help others is that list of ports is important in order to find the right port. – Amin Nov 19 '15 at 12:47