1st post, processing.org with arduino over serial example

this program takes analog input from a pot on A0 and sends it to a windows application for drawing a colored background. analogread() is really slow so I try to call it only once. this greatly improved performance. close the arduino IDE after you download your code so you don't have a conflict of two applications using the same serial port. you can still monitor your serial from the processing window. you must run your app in processing after your sketch has started running on the arduino.

put this on the arduino

  PWM fade the LED on pin 13 controlled by a pot on A0

int sensorPin = A0;
int ledPin = 13;
int potValue;
int potValueDiv;
int potValueDiv2;
void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(0, INPUT);     
  pinMode(ledPin, OUTPUT);     

void loop() {
  potValue = analogRead(sensorPin);
  potValueDiv = potValue/4;
  potValueDiv2 = potValue/32;
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(potValueDiv2);              // wait for a second
  digitalWrite(ledPin, LOW);    // set the LED off
  delay(32-potValueDiv2);              // wait for a second

this is the code for the processing language
download processing from processing.org

import processing.serial.*;
int[] dataIn = new int[2];
Serial port;
int counter;
void setup()
  port = new Serial(this, Serial.list()[1], 28800);
  size(400, 400);
  colorMode(HSB, 256);

void draw()
  if(port.available() > 0)
    dataIn[counter] = port.read();
    background(dataIn[counter], 255, 255);
    counter = (counter+1) % 1;

I have only had my arduino for 3 days and I have done many projects already. really easy to use :slight_smile:


I did something similar between Arduino and processing using an accelerometer to draw, its pretty difficult and also addictive - learning to draw by tilting a PCB.

If you don't have an accelerometer to mess around with, try making an 'etch a sketch' from two variable resistors. If your under 35 years old you probably need to google 'etch a sketch'.

I used the processing 'ellipse' function to draw small circles to plot my analogue inputs, you can see it in one of the older posts on my blog.

I used a comma separated list to send multiple values from arduino to processing and the split function to separate them back out in processing. t the cool thing about the comma separated lists is that you can log them to file or sd card and then analyse your data in excel, that's what I have done for all the g-force data on my blog.



haha yeah the etch-a-sketch did cross my mind at first.

I found this site showing off arduino + DD-WRT + processing over wifi.