Serial read from arduino Leonardo
in
Integration and Hardware
•
1 year ago
hello, I have a problem communicating with my arduino leonardo.
This is the processing code:
Do you have any idea?
thanks in advance
This is the processing code:
- import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[1];
println(Serial.list());
myPort = new Serial(this, portName, 9600);
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
val = myPort.read(); // read it and store it in val
print((char) val);
}
}
- void setup() {
Serial.begin(9600); // Start serial communication at 9600 bps
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop() {
delay(1000);
Serial.print("hoila "); // send to Processing
delay(1000);
Serial.print("hoibo "); // send to Processing
}
Do you have any idea?
thanks in advance
1