Arduino -> Processing serial confusion?
hey all, i'm testing new toy i'm building, , having issues serial communication ... upload code stream arduino serial data between 0 & 127, , if use serial watcher in arduino, numbers come correctly. if try watch numbers in processing 10, 16, 13, 5, 14... want data in, without weirdness... here's sources:
any appreciated.
code: [select]
/* ####################################################################
arduino code :
####################################################################*/
int apin0 = 0; // potentiometer wiper (middle terminal) connected
to analog pin 3
// outside leads ground , +5v
float smoothedval;
void setup()
{
serial.begin(38400); // setup baud rate(midi = 31250)
}
void loop()
{
smoothedval = smooth(analogread(apin0)/8, 0.5, smoothedval);
serial.println(smoothedval, dec); //note data
}
int smooth(int data, float filterval, float smoothedval){
if (filterval > 1){ // check make sure param's within range
filterval = .99;
}
else if (filterval <= 0){
filterval = 0;
}
smoothedval = (data * (1 - filterval)) + (smoothedval * filterval);
return (int)smoothedval;
}
/* ####################################################################
processing code :
####################################################################*/
// learning processing
// daniel shiffman
// learningprocessing.com
// example 19-8: reading serial port
import processing.serial.*;
int val = 0; // store data serial port, used color background
serial port; // serial port object
void setup() {
size(200,200);
// in case want see list of available ports
// println(serial.list());
// using first available port (might different on computer)
port = new serial(this, "com14", 38400);
}
void draw() {
// serial data used color background.
background(val);
}
// called whenever there available read
void serialevent(serial port) {
// data serial port read in serialevent() using the
read() function , assigned global variable: val
val = port.read();
// debugging
println( "input:" + val);
}any appreciated.
you sending data arduino multi byte decimal number 127 3 byte 1 followed 2 followed 7. in ascii send 0x31, 0x32, 0x37;
in processing receiving single byte, 1 byte of number. that's why don't match up.
in processing receiving single byte, 1 byte of number. that's why don't match up.
Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Arduino -> Processing serial confusion?
arduino
Comments
Post a Comment