Arduino + processing not working

All the code is uploaded but its not working please help.

You'll have to provide just a little more information here. ;)

Ok I have a Duemilanove with atmega 328. I think the pocessing cant find where the arduino is located.

What are you trying to do with processing? Do you have a program written in processing that talks to the Arduino? What code is on the Arduino? What do you expect the code to do, and what is it doing instead?

I am trying to do an ocilliscope.

The processing code is

/*
 * Oscilloscope
 * Scope and logic analyzer to visualize volage on arduino digital and analog pins
 * 
 * (c) 2009 David Konsumer <konsumer@jetboystudio.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.

lots of ideas from:
http://accrochages.drone.ws/en/node/90

features:
logic analyzer mode that shows 1's and 0's clearly.
pause frame
save frame
configuarable pin-count
use as many pins as will fit on screen (tested with 12 at 800x800, seems ok)
use scope class in your own thing, easy to reuse, and setup any kind of GUI

data is formatted by LF char, and scope nums are seperated by " "

*/

// TODO: add zooming
// TODO: detect things like SPI and i2C, label graph

import processing.serial.*;
import controlP5.*;

// how many scopes, you decide.
Scope[] scopes = new Scope[8];

Serial port;
ControlP5 controlP5;

PFont fontLarge;
PFont fontSmall;

int LINE_FEED=10; 

int[] vals;

void setup() 
{
  // put whatever you like, for size, in here
  // pick a neat multiple of scope count for height to amke it line up
  size(800, 800, P2D);
  background(0);
  
  controlP5 = new ControlP5(this);
  
  // set these up under tools/create font
  fontLarge = loadFont("TrebuchetMS-20.vlw");
  fontSmall = loadFont("Uni0554-8.vlw");
  
  int[] dimv = new int[2];
  dimv[0] = width-130; // 130 margin for text
  dimv[1] = height/scopes.length;
  
  // setup vals from serial
  vals = new int[scopes.length];
  
  for (int i=0;i<scopes.length;i++){
    int[] posv = new int[2];
    posv[0]=0;
    posv[1]=dimv[1]*i;

    // random color, that will look nice and be visible
    scopes[i] = new Scope(posv, dimv, color((int)random(255), (int)random(127)+127, 255));
    
    controlP5.addButton("pause",1,dimv[0]+10,posv[1]+10,32,20).setId(i);
    controlP5.addButton("logic",1,dimv[0]+52,posv[1]+10,29,20).setId(i+50);
    controlP5.addButton("save",1,dimv[0]+92,posv[1]+10,29,20).setId(i+100);
  }
  
  port = new Serial(this, Serial.list()[0], 9600);
  
  // clear and wait for linefeed
  port.clear();
  port.bufferUntil(LINE_FEED);
}

void draw()
{
  background(0);
  
  // int[] vals = getTestValuesSquare();
  
  for (int i=0;i<scopes.length;i++){
    // update and draw scopes
    scopes[i].addData(vals[i]);
    scopes[i].draw();
    
    // conversion multiplier for voltage
    float multiplier = scopes[i].multiplier/scopes[i].resolution;
    
    // convert arduino vals to voltage
    float minval = scopes[i].minval * multiplier;
    float maxval = scopes[i].maxval * multiplier;
    float pinval =  scopes[i].values[scopes[i].values.length-1] * multiplier;
    
    // add lines
    scopes[i].drawBounds();
    stroke(255);
    line(0, scopes[i].pos[1], width, scopes[i].pos[1]);
    
    // add labels
    fill(255);
    textFont(fontLarge);
    text(pinval, width-60, scopes[i].pos[1]+scopes[i].dim[1]-10);
    
    textFont(fontSmall);
    text("min: "+minval, scopes[i].dim[0]+10, scopes[i].pos[1]+40);
    text("max: "+maxval, scopes[i].dim[0]+10, scopes[i].pos[1]+48);
    
    fill(scopes[i].c);
    text("pin: "+i, scopes[i].dim[0]+10,scopes[i].pos[1]+scopes[i].dim[1]-10);
  }
  
  // draw text seperator
  stroke(255);
  line(scopes[0].dim[0], 0, scopes[0].dim[0],height);
  
  // update buttons
  controlP5.draw();
  
}

// handles button clicks
void controlEvent(ControlEvent theEvent) {
  int id = theEvent.controller().id();
  
  // button families are in chunks of 50 to avoid collisions
  if (id < 50){
    scopes[id].pause=!scopes[id].pause;
  }else if (id < 100){
    scopes[id-50].logic=!scopes[id-50].logic;
  }else if(id < 150){
    String fname = "data"+(id-100)+".csv";
    scopes[id-100].saveData(fname);
    println("Saved as "+fname);
  }
}

// handle serial data
void serialEvent(Serial p) { 
  String data = p.readStringUntil(LINE_FEED);
  if (data != null) {
    int[] vals = int(split(data, ' '));
  }
}


// for test data, you can comment, if not using
int d=0;
ControlTimer ct = new ControlTimer();


int[] getTestValuesSin(){
  int[] vals = new int[scopes.length];
  
  // this is test data
  if (d==45){
    d=0;
  }
  
  int sval = (int) abs(sin(d*2)*1023.0f);
  for (int i=0;i<scopes.length;i++){
    vals[i]=sval;
  }
  
  d++;
  
  return vals;
}

int oldtime;
int time;
boolean up=false;

int[] getTestValuesSquare(){
  int[] vals = new int[scopes.length];
  
  ct.setSpeedOfTime(25);
  oldtime=time;
  time = ct.second();  
  
  if (oldtime==time){
    up = !up;
  }
  
  for (int i=0;i<scopes.length;i++){
    if (up){
      vals[i]=1023;
    }else{
       vals[i]=0;
    }
  }
  
  return vals;
}



class Scope{
  int[] pos; // x, y start position
  int[] dim; // w, h dimensions
  color c; // color for lines
  color bounds_color=color(30); // color for center line
  color[] logic_colors; // size 2 color array for 0/1, red/green by default
  
  int[] values; // all values in the graph
  float resolution = 1024.0f; // max number that be displayed
  float multiplier = 5f; // the voltage multiplier
  
  int minval;
  int maxval;
  boolean logic = false; // use colors to show 0/1?
  boolean pause = false; // freeze input?
  
  /*
  posv is position (x,y)
  dimv is dimensions (w,h)
  cv is color for line
  */
  Scope(int[] posv, int[] dimv, color cv){
    pos = posv;
    dim = dimv;
    c = cv;
    values = new int[dim[0]];
    
    // red and green defaults for logic colors
    logic_colors = new color[2];
    logic_colors[0]=color(255,0,0);
    logic_colors[1]=color(0,255,0);
    
    // I set this high here, so it will be overidden, with first smaller value:
    minval = (int)resolution;
  }
  
  void draw(){
    if (!logic){
      stroke(c);
    }
    for (int x=1; x<dim[0]; x++) {
      if (logic){
        if (values[x] > (resolution/2)){
          stroke(logic_colors[1]);
        }else{
          stroke(logic_colors[0]);
        }
        line(pos[0] + dim[0]-x-2,   pos[1], 
             pos[0] + dim[0]-x-2, pos[1] + dim[1]);
      }else{
        line(pos[0] + dim[0]-x, pos[1] + dim[1]-getY(values[x-1])-1, 
             pos[0] + dim[0]-x, pos[1] + dim[1]-getY(values[x])-1);
      }
    }
  
  }
  
  // draw center line
  void drawBounds(){
    stroke(bounds_color);
    line(pos[0],pos[1]+(dim[1]/2), dim[0], pos[1]+(dim[1]/2));
  }
  
  // add a single point
  void addData(int val){
    if (!pause){
      for (int i=0; i<dim[0]-1; i++){
        values[i] = values[i+1];
      }
      values[dim[0]-1] = val;
      if (val < minval){
        minval = val;
      }
      if (val > maxval){
        maxval=val;
      }
    }
  }
  
  // save current frame
  void saveData(String filename){
    String[] lines = new String[values.length];
    for (int i = 0; i < values.length; i++) {
      lines[i] = "" + values[i];
    }
    saveStrings(filename, lines);
  }
  
  
  private int getY(int val){
    return (int)(val / resolution * dim[1]) - 1;
  }
  
}
[code]
Here is the arduino code

//
holds temp vals
int val;

void setup() {
// set 2-12 digital pins to read mode
for (int i=2;i<14;i++){
pinMode(i, INPUT);
}

Serial.begin(115200);
}

void loop() {
// read all analog ports, split by " "
for (int i=0;i<6;i++){
Serial.print(analogRead(i));
Serial.print(" ");
}

// read all digital ports, split by " "
for (int i=2;i<14;i++){
Serial.print(digitalRead(i));
Serial.print(" ");
}

// frame is marked by LF
Serial.println();
}[/code]

well first change the serial.list[0] in your processing code to whatever com port your arduino is on. Make sure it looks like this with quotes left in: "COM 5" . Next, your arduino is set up for 115200 serial and processing is set up for 9600 serial. you have to pick the same one on both ends. You cant always copy code and expect it to work perfectly on your system. Take a little time and read the code to understand what its doing

This is not my code but thanks!!! :P

I seem to have same problem as kellykel. I found same "arduinoscope" code, but can't get it working...

I have chanced the serial port, checked the arduino sketch with arduino serial monitor & with a processing sketch I wrote. When I run the arduinoscope sketch in processing it starts ok, but doesn't show any graphs. The tx-led in arduino, shows that the board is sending data, but somehow I don't get in to the processing.

Also when testing the arduino sketch with photoresistor it gives proper values.

The arduinoscope sketch is a bit advanced for me, but it would help me with my project. Any ideas, how to continue...

You have the exact same problem, good.

I don't know about good ;), but have you got the system working?

I have identified the problem to serial data flow. For some reason the data arduino is sending is not read by processing. I can get the arduinoscope sketch print the available ports by adjusting it a bit, but not to print the values send from arduino. Other sketches I wrote will print the values in processing window. I didn't mention before that I have windows vista - anyway it has never before been a problem with arduino and processing.

Man we are twins, pocessing worked before with arduino but not with the scope. I even have vista. :'(

I was able to contact he maker of the sketch. It didn't took many hours before I got the answer. Now there is a fixed sketch for processing. Here is the address: http://code.google.com/p/arduinoscope/source/browse/trunk/processing_oscilliscope.pde

I just chanced the serial port to right one and it works! ;D ;D

This should help you kellykel too

Unfortunatey it stil doesn't work. The processing says that "controlP5" does not exist. :'(

Ok that's simple

dowload a control IP 5 library here:

http://www.sojamo.de/libraries/controlP5/

It a .zip which you open and copy in libraries folder in your sketchbook folder for processing. Your oscilloscope should also be in sketchbook.

The sketch might also ask for some fonts, which you'll find here:

http://code.google.com/p/arduinoscope/source/detail?r=7&path=/trunk/data/TrebuchetMS-20.vlw

Put the font-files inside arduinoscope processing sketch folder . There is propably smarter way to do this processing's tool's -> create font -tool, but this one works too

Try again, it should work.

Thanks it works!!!!!!!!!!!!!!!! ;D :D ;) :)