I'm on Arch Linux, using Arduino 1.6.5 and Processing 3.0b6
Using code from https://www.arduino.cc/en/Tutorial/Graph
I'm trying to graph the input from my Arduino DUE, with the following code:
Tools -> Boards : Arduino DUE (Programming Port)
Tools -> Port -> /dev/ttyACM0
Open Arduino IDE, paste this:
void setup() {
// initialize the serial communication:
Serial.begin(9600);
}
void loop() {
// send the value of analog input 0:
Serial.println(analogRead(A0));
// wait a bit for the analog-to-digital converter
// to stabilize after the last reading:
delay(2);
}
Chmod A+RW /dev/ttyAMC0
Open Processing, paste this:
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
void setup () {
// set the window size:
size(400, 300);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
// draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
Hit Run.
Problem: Console output
/dev/ttyACM0 /dev/ttyS0 /dev/ttyS1 /dev/ttyS2 /dev/ttyS3
map(NaN, 0, 1023, 0, 300) called, which returns NaN (not a number)
And a window with black background and nothing else appears.
Please help, the graph code won't work on Windows either.
Please check if my step has anything wrong with it.
Thanks.
Please note that I don't give input to A0 (A0 not wired), and the serial monitor still gives me a stream of random number 0-1023.