SerialSocketEvent not firing

2019-08-13 16:55发布

问题:

I have copied this code:http://playground.arduino.cc/Interfacing/Java to a java project, and i tried this:

void setup(){
Serial.begin(9600);
while(!Serial);
}

void loop(){
Serial.println("Test");
}

on my arduino UNO, with great results, but when i tried it on my esplora, the program did not even fire the event listener for the java project.

回答1:

An Esplora and leonardo (both use ATmega32u4) require you to wait until the cdc serial is ready. The Uno has a dedicated Atmega8/16u2 controlling the Serial/USB comms.

In your code, after your Serial.begin() call, add a loop to wait until ready:

Serial.begin(9600);

while (!Serial) {
  ; // wait for serial port to connect.
}

Cheers



标签: java arduino