We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › getting value from arduino
Page Index Toggle Pages: 1
getting value from arduino (Read 5018 times)
getting value from arduino
Apr 20th, 2008, 1:35am
 
hi, beeing a newbie, i need some help,
i would like to get a simple value in processing coming from my arduino via my serial port.
here is my arduino code:

int pin1 = 0;
int led = 13;
int val = 0;
void setup()
{
pinMode(led, OUTPUT);
pinMode(pin1, INPUT);
beginSerial(9600);
}
void loop()
{
val = analogRead(pin1);
digitalWrite(led, HIGH);
delay(val);
digitalWrite(led, LOW);
delay(val);
}
so i get my expected value in the serial monitor, but the problem is in precessing,
i dont really know how to get my value in precessing,
what's the easiest way to do that?  serial libray or firmata? i'm a bit lost and tried several things without succeeding  .
sorry for this simple question.

this is my procesing sketch, just to see if the value is received...
but nothing changes.

import processing.serial.*;

Serial port;  
int val;      

void setup()
{
size(100, 100);
 port = new Serial(this, 9600);
}

void draw()
{
 if (0 < port.available()) {  
   val = port.read();        
   }
 background(val/4);
}
 

thanks for your help.

Re: getting value from arduino
Reply #1 - Apr 20th, 2008, 11:45pm
 
The Serial library will do just fine for this. Check these library examples for some simple examples.
Re: getting value from arduino
Reply #2 - Jun 15th, 2008, 5:24am
 
I use
http://www.arduino.cc/playground/Interfacing/Firmata
to get values via serial port - don't forget to adjust the serial port values in the Firmata processing scripts to get the right one

I just posted:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Exhibition;action=display;num=1213500039

maybe it'll help? =]

best of luck,
-Jeff
Re: getting value from arduino
Reply #3 - Oct 30th, 2009, 2:03am
 
Hi there,

trying to get values form a Sharp proximity sensor attached to an analog input. Unfortunately nothing happens, the value is 0. I tried the arduino with max/msp where it worked perfectly. Where did I go wrong in this sketch?

Quote:
import cc.arduino.*;

import processing.serial.*;

import promidi.*;

Arduino arduino;

MidiIO midiIO;
MidiOut midiOut;

int sensorv;

void setup(){
  size(200,200);
  arduino = new Arduino(this, Arduino.list()[0], 57600);
  midiIO = MidiIO.getInstance(this);
  midiOut = midiIO.getMidiOut(1,"IAC Driver - Bus 1");

  midiIO.printDevices();
  println(Arduino.list());

}
void draw(){
  background(0);
  sensorv = arduino.analogRead(0);
  midiOut.sendController(new Controller(1,sensorv));
  println(sensorv);
}













Re: getting value from arduino
Reply #4 - Nov 7th, 2009, 4:02pm
 
I use this code for reading values from Arduino:

Arduino reads analog input and sends float variable.
Code:
int analogPin = 0;
float temp = 0;

void setup() {
Serial.begin(9600);
}

void loop() {
temp=analogRead(analogPin);
temp=(map(temp,0,1024,0,5000)/10.0);
Serial.println(temp); // println add Linefeed to my float
delay(1000);
}


Processing reads and displays float from serial.
Code:
import processing.serial.*;

int lf = 10; // Linefeed in ASCII
String myString = null;
Serial myPort; // Serial port you are using
float num;

void setup() {
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.clear();
}

void draw() {
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if (myString != null) {
print(myString); // Prints String
num=float(myString); // Converts and prints float
println(num);
}
}
myPort.clear();
}
Page Index Toggle Pages: 1