serial port - Weird random data being sent from Arduino to Processing -


i'm trying read data photocell resistor , arduino decimila , graph in real-time processing.

should painfully simple; growing little bit of nightmare me.

code i'm running on arduino:

int photopin;  void setup(){    photopin = 0;   serial.begin( 9600 );  }  void loop(){    int val = int( map( analogread( photopin ), 0, 1023, 0, 254 ) );   serial.println( val ); //sending data on serial  } 

code i'm running in processing:

import processing.serial.*;  serial photocell;  int[] yvals;  void setup(){    size( 300, 150 );   photocell = new serial( this, serial.list()[0], 9600 );   photocell.bufferuntil( 10 );   yvals = new int[width];  }  void draw(){    background( 0 );   for( int = 1; < width; i++ ){     yvals[i - 1] = yvals[i];   }    if( photocell.available() > 0 ){     yvals[width - 1] = photocell.read();   }    for( int = 1; < width; i++ ){     stroke( #ff0000 );     line( i, yvals[i], i, height );   }   println( photocell.read() ); // debugging } 

i've tested both bits of code separately , know work. it's when try have input arduino going processing problems start.

when view data in arduino's "serial monitor", nice constant flow of data seems valid.

but when read same data through processing, repeating pattern of random values.

halp?

you transmit data plotly arduino api, along documentation , setup available here. basic idea: can continuously stream data arduino, or transmit single chunk.

then, if want embed site, you'll want grab url , use snippet:

<iframe id="igraph" src="https://plot.ly/~abhishek.mitra.963/1/400/250/" width="400" height="250" seamless="seamless" scrolling="no"></iframe> 

you can change width/height dimensions in snippet. note: need swap in own url there stream through.

here's example of how looks stream arduino data

enter image description here

full disclosure: work plotly.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -