Serial not working

edited November 2017 in Arduino

Hi, I've been writing this code since yesterday and it was fine until now. I don't know what happened but the SerialEvent() is never triggered. Context: win10 x64, using a bluetooth HC-06 module with arduino. Tested with Bluetooth serial terminal application and all working. In processing, the COM port selected is correct (doesn't throw any error) but the SerialEvent() is never triggered therefore no values are received by processing. This was working perfectly an hour ago and I have no idea why it does not work anymore. Basically the BT module is always blinking (which means it's not connected). It used to stop blinking when I run the application (and data was received)

This is extract of my code. None of the print statement inside serialEvent() are actually ever exectued. Again, I receive the values correctly if I run the Bluetooth Serial Terminal application

void setup(){
    size(800, 800, P3D);
    //fullScreen(P3D, 1);

    // OSC stuff
    oscP5 = new OscP5(this, 10000);
    destination = new NetAddress("127.0.0.1", oscPort);

    //Serial stuff
    String portName = Serial.list()[1];
    my_port = new Serial(this, portName, 9600);
    my_port.bufferUntil('\n');

    background(0);
}

void serialEvent(Serial my_port){
  println("MESS");
  if(my_port != null){
    String str = my_port.readStringUntil('\n');

    if(str.charAt(0) == '#'){
      str = trim(str.substring(1));

      int gyro[] = int(split(str,','));

      for(int i = 0; i < gyro.length;i++){
          gyroVals[i] = (int) map(gyro[i], 0, 360, -180, 180);
          print(i + ": " + gyroVals[i] + " // "); 
      }  
        println();
    }
  } 
} //serialEvent

Answers

  • Hi plux, Several possibilities:

    • Processing has left a process running that is still using the port, and is preventing your re-run getting the port. Kill processes or logout/in or reboot.

    • after the comment "Serial stuff" the code assumes that you want to use the 1th port item. Maybe that's not the right one now. I prefer e.g. portname = "COM21". Look in device manager, and the BT config, see if the port you are using is still there.

    • go and get putty (terminal emulator), use that to connect to the com port, see the output.

    Hope this helps,

    Richard.

Sign In or Register to comment.