Arduino Nano crashes at Serial connection

Hello,

I have created a measurement instrument with Arduino Nano. It works as intended (now after a lot of work :slight_smile: )

The arduino sends the data to the PC via the serial hardware interface and the FTDI converter.

With Arduino Terminal and with Hyperterminal it all works fine.

Now I have found a PC program (SerialComInstruments), which can display data from the Arduino on graphical analog and digital instruments / meters. The data from the Arduino has to be a specific string for the PC program to deceipher it. Supposedly, this PC program works with Arduino.

Now when I hit the connect button in that PC program, then the Arduino hangs up. As much as it looks like, it does not continue to execute the program. Off course, I cannot tell for sure, because the arduino is not in debug mode at that time.

Only disconnecting the USB cable and a power up reset will bring the arduino back.

The arduino is only sending to the PC via serial, it does not expect anything from the PC via serial.

Supposedly, when the Arduino detects something on the serial interface, it goes through a reset. If that is the case, it would not completely execute the reset, but stop midway.

I'm happy for suggestions / ideas.

The reason why I chose SerialComInstruments is because it's darn simple to use. It took me 2h until I had what I wanted. So using another visualisation program is an option, but I don't want to spend days to work myself into it and weeks to make it work.

Thanks in advance + BR

I think that the software which you used can't establish a proper connection with the Arduino. Whenever the Arduino gets a Serial request, it goes to a reset. But Arduino IDE has compiatable software so it knows this behaviour of the Arduino. The software you use, whenever tries to connect to Arduino, the Arduino resets and the software sends another request while the Arduino is being reset. So the requests repeat and the Arduino continuosly resets and it hangs up. Please check if the version of software you are using isn't a beta one and should be a stable version. If it doesn't work, then you shouldn't use it as it can damage the Arduino.

If not mistaken, resets on the Nano can be recognised by a couple of quick flashes of the builtin LED; that would the same as on an Uno.

If you get those quick flashes continuously, it wouldindicate reset following reset following reset ...

I corrected the functions, reduced the baud rate & used delay in between Serial.print() & it was solved. Don’t know why it was fixed but that method worked for me while using GPS with arduino UNO & WIN7 X64.

Thanks for the answers.

Yes, when the arduino resets, then the LED is on.

When the firmwere on the arduino executes, the LED blinks every 2 sec.

When I hit the connect button on the PC program, then the LED is off. No blinking nothing.

From that perspective, maybe, the arduino does not hang in a reset, but hangs in a loop. I just would not know in which loop it could hang? It does not wait for a response from the Serial I/F.

The baudrate is 9600, so rather slow already.

Sebastian, you mean, to insert a 1sec delay between every serial command which is getting sent to the PC? What would that help with? If the PC program cannot handle the amount of data, that should not affect the arduino?

Did a couple a more tests.

Everytime I connect Hyperterminal, the arduino goes through a reset.

When I disconnect Hyperterminal and connect the SerialComInstruments, then it freezes.

When I disconnect SerialComInstruments and connect Hyperterminal again, then the arduino goes through a reset and resumes work.

I'm lost.

I’ve installed SerialCommInstruments and tested with below code at both 9600 and 115200 on both a SparkFun Redboard and an original Uno; difference between the two is the USB-to-TTL converter where the Sparkfun closest matches a Nano.

The bad newsis that I can’t reproduce the behaviour that you experience.

const byte ledPin = LED_BUILTIN;
byte ledState = HIGH;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, ledState);
}

void loop()
{
  // counter for led toggle
  static byte cnt;

  // send data
  Serial.print("#41M15.345<");

  // increment counter
  cnt++;
  // if time to toggle led
  if (cnt == 10)
  {
    // toggle led
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    // reset counter
    cnt = 0;
  }
  // a little delay
  delay(100);
}

Results; I basically only used interface connect/disconnect and observed the behaviour of the leds

9600 SparkFun Redboard
disconnected → flashing led 13
connected → flashing led 13 and flashing TX led
disconnected → flashing led 13 and TX led keeps on flashing for a little, next off
connected → flashing led 13 and flashing TX led

9600 Arduino
disconnected → flashing led 13
connected → flashing led 13 and flashing TX led
disconnected → flashing led13 and TX led keeps on flashing for a little, next steady on
connected → flashing led 13 and flashing TX led

115200 SparkFun Redboard
disconnected → flashing led 13
connected → flashing led 13 and flashing TX led
disconnected → flashing led 13 and TX led keeps on flashing for a little, next off
connected → flashing led 13 and flashing TX led

115200 Arduino
disconnected → flashing led 13
connected → flashing led 13 and flashing TX led
disconnected → flashing led 13 and TX led nearly instantly steady on
connected → flashing led 13 and flashing TX led

The flashing led 13 indicates that the board is not hanging.

In non of the above I observed a reset (the few quick flashes) which indicates that SerialComInstruments does not control it (clever).

The TX led is controlled by the USB-to-TTL converter (both boards). That the TX led stops flashing seems to indicate that SerialComInstruments can control the USB-to-TTL converter on the board; I’ve never seen this before (but this does not indicate an error).

Please test the code that I provided and post the observations.

For further help, please post your code.

Hello sterretje,

thanks a lot.

Your code works, mine does not.

I've used another arduino nano board I have and tried your code and it works fine.

So now the question is, why my code does not work?

Debugging again ....

BR

You can post your code and somebody can have a look at it.

Hello Serretje,

I have downloaded the firmware to the other arduino board, the one which previously was running your code => and it does not hang up.

Now, there is no hardware attached to this board, so I hope it’s not the hardware, but as said, it all works on Hyperterminal.

The one board I have been using has a CH340 USB2Uart converter, while the other which is in the hardware has an FTDI. Not sure, if that is the origin of the problem. Hard do believe however.

Now my code, is quite big (>20k). Do you want it all, or only the main, which contains all the Serial.print commands?

If you want it all, shall I privide a *.zip?

BR

P.S. thanks for your help again

Here the main program without the rest.

Arduino_EffMeter_wCOMV5.ino (13.8 KB)

Serretje,

I have loaded your code into the arduino board which is in my hardware.
And it hangs up as well.

So maybe it is the FTDI chip?

I doubt it’s the FTDI chip; my Sparkfun Redboard also uses a FTDI. I’ve unfortunately misplaced my Nanos so can’t test with them.

It definitely sounds like the hardware. Can you take your board out of your setup and test it separately?

I’ve noticed that you blink a LED in loop(); I assume that it stops blinking when your Nano hangs?

A wiring diagram can be useful (photo of pencil / paper if needed); make sure that every component including power supplies (if any) is on there and all wiring. Hardware is not my strong point though.

Is it possible that SerialComInstruments does not like some of the stuff that you print to serial? You’re printing all kinds of stuff in between the actual data.

I don’t have your hardware so testing will be impossible for me; I can only simulate. Can you save some data in HyperTerm (about 20k) and attach it here so that I can play it out from an Arduino and see how SerialComInstruments behaves?

You can post your complete code (zipped); please provide links to any library that you use ( specifically for the I2C as there are a few different ones for that and I don’t feel like digging :wink: ). I don’t know if it will ring any bells to me but at least I will be able to compile and check for oddities.

Hello Sterretje,

thanks a lot for looking so deeply into my problem.

Today, I have swapped the Nano with the CH340 against the Nano with the FTDI and now the problem happens on the Nano with the CH340 and the Nano with the FTDI works fine ...

So, it has nothing to do with the firmware, it is a problem in my hardware, in my measurement device.

Then I disconnected everything from the Nano and step by step plugged things back togehter.
The problem is the 5V power supply to the Nano. I need power which is independent from USB when the measurement device works stand alone. Once that 5V power supply is disconnected, it works with SerialComInstruments. So when only USB supplies the Nano, then it works.

So there must be some mismatch / incompatibility between the 5V supply I provide from the measurement device and the USB supply. Why it only kicks in, when I connect SerialComInstruments is a mystery to me however.

There is a diode from USB to the 5V rail on the Nano, so when I apply 5V from the instrument, things should still be fine, nothing going back into USB.

I need to check that out tomorrow with the Osci. Today, I don't have it available.

BR

So, I got it working.

The additional supply from my measurement device had ~100mV bumps in it. This should not be a problem, but apparently it is.

Adding a 100uF lytic and a 100nF ceramic to the Nano changed nothing.

Seperating the additional supply from the Nano with a Vf=200mV diode solved the problem.

Don't ask me why, it is still a mystery to me, but it works.

Thanks to all for your support.

BR