Hey, Its my first time connecting the arduino to processing. I followed a tutorial to the T and double checked the code but i am still getting an error. can someone tell me where i went wrong?
Processing Code —
import processing.serial.*;
Serial mySerial;
String myString = null;
int ml = 10;
float myVal;
void setup(){
size(200,400);
String myPort = Serial.list() [1];
mySerial = new Serial(this, myPort, 9600);
}
void draw(){
while (mySerial.available() > 0){
myString = mySerial.readStringUntil(ml);//striping data
if (myString != null) {
background(0);
myVal = float(myString); //data#
// myVal = myVal/100 *height;
println(myVal);
// rectMode(CENTER);
// rect(width/2,height =(myVal/2), 100, myVal);
}
}
}
Arduino Code-----
void setup() {
//Int serial port for data
Serial.begin(9600);
}
void loop() {
// capture data in arduino
int variable1 = int(random(100));
Serial.println(variable1);
delay(100);
}
void setup()
{
//Int serial port for data
Serial.begin(9600);
}
void loop()
{
// capture data in arduino
int variable1 = int(random(100));
Serial.println(variable1);
delay(100);
}
Processing:
import processing.serial.*;
Serial mySerial;
String myString = null;
int ml = 10;
float myVal;
void setup()
{
size(200, 400);
// List all the available serial ports
printArray(Serial.list());
String myPort = Serial.list() [0];
mySerial = new Serial(this, myPort, 9600);
}
void draw()
{
while (mySerial.available() > 0)
{
myString = mySerial.readStringUntil(ml); //striping data
if (myString != null)
{
background(0);
myVal = float(myString);
println(myVal);
}
}
}