Serial port "read" fails and freezes arduino IDE after device is on for a while

Hello,

I am making a tracker/datalogger to measure orientation and depth underwater for scuba diving. I'm using a sparkfun pressure sensor (MS5803) and sparkfun Razor IMU M0. I have a program that works pretty well (attached to this post), but after the device has been on for a while, it stops being able to read from the serial port. As in, I can still see serial output, but when I try to send two characters, both the serial monitor window and the Arduino IDE window freeze and I can't do anything with them until I unplug the device from the computer.

I've looked for memory problems and haven't found any leaks. I eliminated just about all "String" variables from my program in favor of char arrays.

My program is several hundred lines so I've attached the file rather than used the code tags. I hope that is ok.

I've also attached a picture of my device. The 4 stainless steel prongs sticking out of the epoxy are for a usb connection. I had to sacrifice the shielding line for space.

Sparkfun9DOF_IMU_7_29_2019.ino (19.9 KB)

config.h (4.08 KB)

As in, I can still see serial output, but when I try to send two characters, both the serial monitor window and the Arduino IDE window freeze and I can't do anything with them until I unplug the device from the computer.

If this description is exact you should inspect your PC first. There should be absolutely no way for the external device to freeze your computer just by the serial interface. Your way to connect to the USB interface is definitely a quite bad hack but the driver should be robust enough to handle almost any signal from the USB controller. I guess you use the IDE on Windows as it's the only common OS that might let a window freeze if a driver is buggy. Update the Arduino serial driver to the newest version. Update your cabling to have only the shortest possible part of the USB connection unshielded.

but after the device has been on for a while

How long is a "while" in this context? 10 seconds, a minute, an hour, a day, a week?

Use strncat instead of strcat and set n to the size of the array minus 1 (C strings have a null termination byte).

A while means overnight. Possibly as short as just a few hours. I will work on shortening the cable. The prongs were the quickest way for me to make corrosion resistant contacts. If you have any better suggestions I would love to hear them.

Just to clarify, it is not the whole computer that is freezing. Just the arduino windows.

Thank you!

Just to clarify, it is not the whole computer that is freezing. Just the arduino windows.

I did understand that. Did you check for the newest version of the driver?

Does your PC provide any log output for the driver/USB port your connected your device to? At the moment it looks more like a PC problem than an Arduino software problem. My guess is that the missing shield makes the USB signals noisy and the serial port emulation driver isn't robust enough to handle that.

Try to run it on a Linux machine, if it has problems too you at least get log output that tells you where the problem might be located.

All drivers are up to date.

I feel like if it were the shielding, then I should be seeing issues with receiving information as well as sending. But I can plug it in whenever and still see the serial.write output. It is only after 2 send attempts that it freezes. With other serial communication programs like termite and putty the device just ignores any sent characters and continues writing out. So it is definitely a problem with the way that arduino handles serial communication. But regardless of the front-end, the device itself still ignores anything going into it.

I am still working on shortening the wires.