Go Down

Topic: Processing returning 0, but arduino works. (Read 1 time) previous topic - next topic


Hi, i managed sucessfully to connected both arduino and processing.I was getting results on my graph , but i tried to organize stuff,and i change some suff on the sketchbook, now everytime i run my processing code i dont any result.
I have no idea how to fix, some insight on how it works would help.

Arduino serial monitor says like: 165, 167, 167,  etc....
Programming graph return : 0, 0, 0, 0, ........

http://gyazo.com/b0966c463337257d5c1b56dba57f6fcc Arduino serial monitor
http://gyazo.com/08264f05aed77ba21fc82b74707fb232 Processing result

ArduinoSketch Code
Code: [Select]

int sensorValue;

void setup()
 Serial.begin(9600);      // sets the serial port to 9600

void loop()
 sensorValue = analogRead(0);       // read analog input pin 0
 Serial.println(sensorValue, DEC);  // prints the value read
 delay(500);                        // wait 100ms for next reading

Processing Sketch Code

Code: [Select]
import processing.serial.*;
import cc.arduino.Arduino;

Arduino arduino;
PFont font;
int xPos=0;
boolean firstLoop = true;
String arduinoPort = "COM4";

void setup(){
 String ports[];
 ports = Arduino.list();
 for(int i=0;i<ports.length;i++) {
     if (ports[i].equals(arduinoPort)) {
 arduino = new Arduino(this, ports[i]);
 if (arduino == null) {
     throw new RuntimeException("could not find Arduino port");

 font = loadFont("MinimaSSK-96.vlw");
 textFont(font, 48);


void draw(){
   if (firstLoop) {
firstLoop = false;

   int value = arduino.analogRead(0);
   int yPos = (int)map(value, 0, 1023, height, 20);

   if (xPos > width) {
rect(min(xPos+30, width-100), max(yPos-70, 0), 100, 45);
xPos = 0;

   fill(30, 5);
   rect(0, 0, width, height);

   rect(xPos, 1, 160, height-2);
   rect(min(xPos+30, width-100), max(yPos-70, 0), 100, 45);

   plot(xPos, yPos, value);

   text(""+value, min(xPos+30, width-100), max(yPos-30, 40));

   rect(0, 0, width-1, height-1);


void plot(int x, int y, int value) {
   fill(255, map(value, 0, 1023, 255, 0), 0);
   ellipse(x, y, 30, 30);


Code: [Select]
    int value = arduino.analogRead(0);
This statement implies that the Arduino is supposed to be running a Firmata sketch. It isn't, so it's no wonder that the result is incorrect.

The art of getting good answers lies in asking good questions.


Thanks bro, i uploaded the StandardFirmata from the example and ran processing and now everything works :D
But where is my code for the sensor now, i coulndt get my head around this.
I have the code for the sensor the firmata one and one for the graph in processing.
If i upload the firmata code after my sensor code on arduino dont it get lost?


Didn't help but thanks for wasting my time too

Yes, it gets overwritten. But, the StandardFirmata code turns the Arduino into an idiot. That's what Processing is expecting. It sends a command to the Arduino, telling it to return the value of the analog or digital pin that Processing needs the value of. The Arduino responds in the correct way, after calling the same function your sketch calls.
The art of getting good answers lies in asking good questions.


Thanks, i don't get the quote but, definitely helped me.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131