intermittent NULL error while communicating between arduino and processing

edited January 2017 in Arduino

I am using modified code that came with a 9DOF sensor from adafruit... It included a processing and Arduino sketch. I used the communication part of the sketch but deleted the GUI portion... The communication works but only 1 out of 4 or 5 times... the rest of the time I get this error in processing 3:

Error, disabling serialEvent() for COM17 null

I cant figure out how to resolve this intermittency... hope you can help

the relevant part of the processing sketch:

void setup()
{
  size(displayWidth, displayHeight);
  smooth();
 setSerialPort("COM17");

  //robot setup
  try
  {
    robby = new Robot();
  }
  catch (AWTException e)
  {
    println("Robot class not supported by your system!");
    exit();
  }
  robby.mouseMove(screenResX/2, screenResY/2); //test line to move cursor
}

void serialEvent(Serial p) 
{
  String incoming = p.readString();
  if (printSerial) {
    //println(incoming);
  }

  if ((incoming.length() > 8))
  {
    String[] list = split(incoming, " ");
    if ( (list.length > 0) && (list[0].equals("Orientation:")) ) 
    {
      leftClick = float(list[5]);
      rightClick = float(list[4]);
      roll  = float(list[3]); 
      pitch = float(list[2]); // Pitch = Y 
      yaw   = float(list[1]); // yawLeftRight
    }
  }
}

// Set serial port to desired value.
void setSerialPort(String portName) {
  // Close the port if it's currently open.
  if (port != null) {
    port.stop();
  }
  try {
    // Open port.
    port = new Serial(this, portName, 115200);
    port.bufferUntil('\n');
    // Persist port in configuration.
    saveStrings(serialConfigFile, new String[] { portName });
  }
  catch (RuntimeException ex) {
    // Swallow error if port can't be opened, keep port closed.
    port = null;
  }
}

HERE IS THE FULL ARDUINO CODE:

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

/** 
   History
   =======
   2015/MAR/03  - First release (KTOWN)
*/

/** Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)

Adafruit_BNO055 bno = Adafruit_BNO055(55);


void displaySensorDetails(void)
{
  sensor_t sensor;
  bno.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" xxx");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" xxx");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" xxx");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

void setup(void)
{
  Serial.begin(115200);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);

  /** Initialise the sensor */
  if(!bno.begin())
  {
    /** There was a problem detecting the BNO055 ... check your connections */
    Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
    while(1);
  }

  delay(1000);

  /** Use external crystal for better accuracy */
  bno.setExtCrystalUse(true);
}


void loop(void)
{
  int rightClick = digitalRead(6);
  int leftClick = digitalRead(5);
  /** Get a new sensor event */
  sensors_event_t event;
  bno.getEvent(&event);

  /** The processing sketch expects data as roll, pitch, heading */
  Serial.print(F("Orientation: "));
  Serial.print((float)event.orientation.x);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.y);
  Serial.print(F(" "));
  Serial.print((float)event.orientation.z);
  Serial.print(F(" "));

  Serial.print((float)rightClick);
  Serial.print(F(" "));
  Serial.print((float)leftClick);
  Serial.println(F(""));

  delay(BNO055_SAMPLERATE_DELAY_MS);
}

Answers

  • after some more debugging I found that the program seems to work just fine as long as I omit the robot class from my sketch... I cant figure out if I am calling the class incorrectly or if there is some incompatibility issue with the serial library..

  • the error I get from processing is: Error, disabling serialEvent() for COM17 null the program does not shut down, but just hangs and doesnt receive serial data the mouse does move to the spot on the screen in setup() and stays there until I escape out of the sketch...

  • Continue this post here: https://forum.processing.org/two/discussion/20346/how-do-you-implement-java-awt-robot-into-a-sketch#la

    @fxmech Don't duplicate posts as it confuses ppl. You should consider adding your Arduino code from this post into your other post. My suggestion: in the other post, edit your first post and add there the Arduino code.

    Kf

This discussion has been closed.