SerialSocketEvent not firing

拥有回忆 提交于 2019-12-11 10:26:11

问题


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



来源:https://stackoverflow.com/questions/31601099/serialsocketevent-not-firing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!