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

  • 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 R. 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 R. 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 9:42
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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.