Strange random data sent from Arduino to processing

I am trying to read data from a photocell resistor and my Arduino Decimila, and then draw it in real time using processing.

It should be excruciatingly simple; but for me it turned into a nightmare for me.

code I run my 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 over Serial } 

code that is executed 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 i = 1; i < width; i++ ){ yvals[i - 1] = yvals[i]; } if( photocell.available() > 0 ){ yvals[width - 1] = photocell.read(); } for( int i = 1; i < width; i++ ){ stroke( #ff0000 ); line( i, yvals[i], i, height ); } println( photocell.read() ); // for debugging } 

I tested both bits of code separately and I know that they work. This only happens when I try to get input from Arduino to handle problems starting.

When I look at the data in the Arduino "Serial Monitor", I get a nice steady stream of data that looks correct.

But when I read the same data through Processing, I get a repeating pattern of random values.

Halp?

+4
source share
2 answers

You can transfer this data using the Plotly Arduino API, which, along with documentation and configuration, is available here . The main idea: you can continuously transfer data from your Arduino or transfer one piece.

Then, if you want to embed it in the site, you will want to grab the URL and use this 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 resize the width / height in this snippet. Note: you need to change your own url to get its stream.

Here is an example of what it looks like for an Arduino data stream

enter image description here

Full disclosure: I am working on Plotly.

+2
source

After a closer look at the available resources, I realized that the problem has already been solved for me by people at http://arduino.cc

http://arduino.cc/en/Tutorial/Graph

About how much time I could save if I saw this before.

+4
source

All Articles