Error with displaying on serials monitor

Hello,

I am running an Adafruit LSM9DS1 accelerometer on an Arduino Uno. It was working fine and then all of a sudden I uploaded and it stopped printing values on the serial monitor. Every now and then I also get this message before it finishes uploading.

java.io.IOException: jssc.SerialPortException: Port name - COM5; Method name - setEventsMask(); Exception type - Can't set mask.
at processing.app.Serial.dispose(Serial.java:171)
at processing.app.SerialMonitor.close(SerialMonitor.java:147)
at processing.app.AbstractMonitor.suspend(AbstractMonitor.java:113)
at processing.app.Editor$UploadHandler.run(Editor.java:2049)
at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - COM5; Method name - setEventsMask(); Exception type - Can't set mask.
at jssc.SerialPort.setEventsMask(SerialPort.java:279)
at jssc.SerialPort.removeEventListener(SerialPort.java:1064)
at jssc.SerialPort.closePort(SerialPort.java:1090)
at processing.app.Serial.dispose(Serial.java:168)
... 4 more

Anyone have any idea what I can do to solve this issue? My code is below but note that this is the demo code that comes with the sensor.

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS1.h>
#include <Adafruit_Sensor.h> // not used in this demo but required!

// i2c
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1();

#define LSM9DS1_SCK A5
#define LSM9DS1_MISO 12
#define LSM9DS1_MOSI A4
#define LSM9DS1_XGCS 6
#define LSM9DS1_MCS 5
// You can also use software SPI
//Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1(LSM9DS1_SCK, LSM9DS1_MISO, LSM9DS1_MOSI, LSM9DS1_XGCS, LSM9DS1_MCS);
// Or hardware SPI! In this case, only CS pins are passed in
//Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1(LSM9DS1_XGCS, LSM9DS1_MCS);

void setupSensor()
{
// 1.) Set the accelerometer range
lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_2G);
//lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_4G);
//lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_8G);
//lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_16G);

// 2.) Set the magnetometer sensitivity
lsm.setupMag(lsm.LSM9DS1_MAGGAIN_4GAUSS);
//lsm.setupMag(lsm.LSM9DS1_MAGGAIN_8GAUSS);
//lsm.setupMag(lsm.LSM9DS1_MAGGAIN_12GAUSS);
//lsm.setupMag(lsm.LSM9DS1_MAGGAIN_16GAUSS);

// 3.) Setup the gyroscope
lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_245DPS);
//lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_500DPS);
//lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_2000DPS);
}

void setup()
{
Serial.begin(115200);

while (!Serial) {
delay(1); // will pause Zero, Leonardo, etc until serial console opens
}

Serial.println("LSM9DS1 data read demo");

// Try to initialise and warn if we couldn't detect the chip
if (!lsm.begin())
{
Serial.println("Oops ... unable to initialize the LSM9DS1. Check your wiring!");
while (1);
}
Serial.println("Found LSM9DS1 9DOF");

// helper to just set the default scaling we want, see above!
setupSensor();
}

void loop()
{
lsm.read(); /* ask it to read in the data */

/* Get a new sensor event */
sensors_event_t a, m, g, temp;

lsm.getEvent(&a, &m, &g, &temp);

Serial.print("Accel X: "); Serial.print(a.acceleration.x); Serial.print(" m/s^2");
Serial.print("\tY: "); Serial.print(a.acceleration.y); Serial.print(" m/s^2 ");
Serial.print("\tZ: "); Serial.print(a.acceleration.z); Serial.println(" m/s^2 ");

Serial.print("Mag X: "); Serial.print(m.magnetic.x); Serial.print(" uT");
Serial.print("\tY: "); Serial.print(m.magnetic.y); Serial.print(" uT");
Serial.print("\tZ: "); Serial.print(m.magnetic.z); Serial.println(" uT");

Serial.print("Gyro X: "); Serial.print(g.gyro.x); Serial.print(" rad/s");
Serial.print("\tY: "); Serial.print(g.gyro.y); Serial.print(" rad/s");
Serial.print("\tZ: "); Serial.print(g.gyro.z); Serial.println(" rad/s");

//Serial.print("temp:"); Serial.print(temp.temperature); Serial.print("degrees C");

Serial.println();
delay(200);
}

Please follow the advice on posting a programming question given in Read this before posting a programming question

In particular note the advice to Auto format code in the IDE and to use code tags when posting code here as it prevents some combinations of characters in code being interpreted as HTML commands such as italics, bold or a smiley character, all of which render the code useless

if you get errormessages before uploading has finished it is NOT a problem of your code. Your code is not executing through upload it must be a problem of the upload-process.
the most common advice for all modern electronic equipment is: install new and reboot all devices. This means install Arduino ide new

best regards Stefan

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Are you running Processing program to take the data and display it on your PC?

If so, then you need to stop the processing code before loading your code, Processing is using the same com port that the IDE monitor would do.

Thanks.. Tom.. :slight_smile:

Thank you all for your replies. I just tried to uninstall and reinstall the IDE and ended up with the same result of only getting "LSM9DS1 data read demo" to print on the serial monitor twice. I can get other sensors to work so I don't think its an issue with the IDE.

Attached below is an image of my hookup and hand drawn circuit. Thank you for the instructions on formatting the post. I am new to the forum and would appreciate any advice/instruction you have.

-Katie

Hi Katie,

do I understand right you tried to upload the code new and then the serial output stopped completely?

You wrote that the serial monitor show "LSM9DS1 data read demo" twice

LSM9DS1 data read demo
LSM9DS1 data read demo

Are you using the democode like described here?

can you please post the serial output as a code-section?

best regards Stefan

Yes that is correct the only thing that appears on the serial monitor is code just like you have in your reply:

LSM9DS1 data read demo
LSM9DS1 data read demo

Sometimes it posts without a new line character like this:

LSM9DS1 data read demoLSM9DS1 data read demo

And yes I am using the exact demo code from that tutorial called lsm9ds1. Any advice on why nothing else is showing up on the serial monitor I would be appreciated.
-Katie

Hi Katie,

please post your code as a codesection

press Ctrl-T inside Arduino-IDE
then do a right-click with the mouse
choose "copy for forum"

this will copy the whole sketch into the clipboard and add the code-tags automatically

then switch to the browser and press Ctrl-V to paste the clipboard-content into the forum-textfield.
the original code uses a println

 Serial.println("LSM9DS1 data read demo");

This includes a newline so the there shouldn't be

LSM9DS1 data read demoLSM9DS1 data read demo

this is very strange

please post the details of your computer
brand, type, operating system and a screenshot of your serial monitor

best regards Stefan

I decided to check the soldering and the Vin pin of the accelerometer was not soldered on at all so I took it off and used an IC hook with pigtail to directly to connect to the pad (sadly I am working from home and don't have a soldering kit to fix it with). It works great now. Thank you for your help!

-Katie

You must select the right option in serial monitor (carriage return, new line, etc...)