Somehow debug Arduino?

Hello,

I have an Arduino board which is a smart temp sensor with SMS, Internet reporting capabilities.
The issue is that the board getting freezed and only power reset return it to normal working state.
By "freeze" I mean it stops reporting temp to my webserver and don't send any sms anymore until I power reset it.

Is there any way to add some type of debugging to catch that issue, otherwise it's like a "shadow boxing" and every line of my code is a suspect.

What I already did:

  1. Tried to do my best to improve hadware part (soldered everything I could and don't use a breadboard)
  2. Removed all Strings from my code as it was possible reason to get out of memory soon. So probably now I'm on a fixed memory volume usage and problem is not there..

What would you do if you'd be on my place?

What would you do if you'd be on my place?

Place Serial.print()s at strategic locations in the code so that you can tell which parts it is executing and the value of pertinent variables at that point

Where did you get the code from ?
Which board is it running on ?

UKHeliBob:
Place Serial.print()s at strategic locations in the code so that you can tell which parts it is executing and the value of pertinent variables at that point

Where did you get the code from ?
Which board is it running on ?

So the only way is to keep it connected to my computer and user Serial.print? Ok.

I've written the code myself using various code examples
It's running on Arduino Nano

the standard thing is to keep your arduino connected to your computer and do print serial debug

If this is not possible

If you have some free IO-pins connect some LEDs to them and change the ON/OFF pattern at different locations in your code that you suspect that the "freeze" is happening between them
four LEDs would offer 15 different ON/off-pattern

If you post your code other might have additional ideas how to debug it or maybe even see the reason why.
So instead of Strings what are you using?

arrays of char or Pstring?
writing to arrays with out of bound index is another cause for program-crash

best regards Stefan

the goal is to isolate the piece of code where things fall off the rails. having a serial print at the beginning and end of each function would hopefully isolate the function it's in when the code freezes. if that's not enough, then you need to add additional prints in various parts of the function.

another approach is using LEDs, one for each function, turning it on when entering and off when exiting.

in both cases, there should be a pairing. i wouldn't expect the last print to be the exit one, but it's conceivable the the print didn't complete before freezing.

it's usually something simple

good luck

I have an Arduino board which is a smart temp sensor with SMS, Internet reporting capabilities.

That sound a lot for a Nano. Do you get compiler warnings about low RAM ? What modules are you using ?

You also have the possibility of getting the watchdog timer to reset everything if it get stuck somewhere, but that should be regarded only as a temporary work around.

6v6gt:

I have an Arduino board which is a smart temp sensor with SMS, Internet reporting capabilities.

That sound a lot for a Nano. Do you get compiler warnings about low RAM ? What modules are you using ?

You also have the possibility of getting the watchdog timer to reset everything if it get stuck somewhere, but that should be regarded only as a temporary work around.

Yes, memory usage was a bit of challenge for me. No warnings. I removed all Strings (char arrays now), all static strings are stored into Flash memory (using _P functions) and currently it's using only half of available RAM on compile and has about 600bytes free mem at the end of loop() function. Inner functions in the loop() do not eat much of RAM as well..
I'm using Nano with sin800l module (all power requirements are met I guess as spent much of my time on it as well..)

Watchdog idea sounds as very good workaround for me! Need to read about that. I wouldn't want to unmount the sensor and bring it back home for debug purpose.. It's getting very cold outside and temp control is crucial for my environment.

Thanks for all your ideas and help!

find the problem, don't guess

Please post a system wiring diagram. Maybe you misjudged the power requirements.

char str_temp[10] = "";
float tempValInside = 20.65; // actually this value is read from the temp sensor
dtostrf(tempValInside, 4, 2, str_temp);

Probably, me setting dtostrf output string len to 4 leds to an unexpected behaviour as we have 5 chars in 20.65 value.
Or is that ok? Sorry don't have my Arduino around to test it on the device..

d187:

char str_temp[10] = "";

float tempValInside = 20.65; // actually this value is read from the temp sensor
dtostrf(tempValInside, 4, 2, str_temp);




Probably, me setting dtostrf output string len to 4 leds to an unexpected behaviour as we have 5 chars in 20.65 value. 
Or is that ok? Sorry don't have my Arduino around to test it on the device..

Actually, 20.65 is a six character string including the \0 terminator.

Correct, 6 symbols, my bad. Would that cause an issue keeping in mind that we have str_temp 10 chars long?

dtostrf() is documented here:

https://www.nongnu.org/avr-libc/user-manual/group__avr__stdlib.html

You have to be careful with these formatting function to avoid buffer overrun. It is not always very clear how big the resulting string is going to be. Best is to keep a generous buffer which can be shared by multiple function calls rather than declaring a dedicated, smallest possible, buffer for each new function call.

If you're going to use the watchdog timer, beware that the bootloader on the official Nanos made before 2018 and even many of the Chinese clone/derivative Nanos made now has a bug that causes the board to go into an endless reset loop after a watchdog reset. You'll know you have the bad bootloader if you need to select Tools > Processor > ATmega328P (Old Bootloader) in order to upload to your Nano. If you have a board with the bad bootloader, you can fix it by burning the new bootloader to the board, after which you'll be able to use the watchdog.

The watchdog timer can actually be useful for debugging. I had problems with intermittent hangs in a project that I was having a really hard time debugging and this ended up being the way I was able to track down the problem in the code. I packaged it as an Arduino library to make it easy to use:

aarg:
Please post a system wiring diagram. Maybe you misjudged the power requirements.

It freezed once again today after 19hours of working properly.. When I came to check it I noticed that SIM800L red LED is off.. I switched power on/off and it started working
Wiring diagram is attached (2 ds18b20 sensors aren't shown on this diagram)
Please advise..
Wiring diagram

Powering your Arduino Nano from 12V might be already out of specs.
Anyway this means that 12V -3.3V = 8.7V must be "burned" away.

This means the power-dissipation is 8.7V * current

let's estimate 0,050A
Powerdissipation 8.7V * 0.05A = 0.435 Watt. Sounds not very much but this might be still too much for the voltage-regulator
and the voltage-regulator may go down in shutdown caused by thermal overload.

You should measure how much current the Arduino nao is pulling if all is in action.

Is this correct that you use an Ardunio nano liek shown in the picture?

I looked up the specs of the An here
https://components101.com/microcontrollers/arduino-nano#:~:text=Vin%3A%20Input%20voltage%20to%20Arduino,Maximum%20current%20draw%20is%2050mA.

there is a 5V input. This means you could power the Arduino nano from the DC-DC-step-down-converter into the 5V Input

You didn't told anything about what you did for debugging. What was is it?
best regards Stefan

post / attach your latest sketch to this thread.

StefanL38:
Powering your Arduino Nano from 12V might be already out of specs.
Anyway this means that 12V -3.3V = 8.7V must be "burned" away.

This means the power-dissipation is 8.7V * current

let's estimate 0,050A
Powerdissipation 8.7V * 0.05A = 0.435 Watt. Sounds not very much but this might be still too much for the voltage-regulator
and the voltage-regulator may go down in shutdown caused by thermal overload.

You should measure how much current the Arduino nao is pulling if all is in action.

Is this correct that you use an Ardunio nano liek shown in the picture?

I looked up the specs of the An here
Arduino Nano Pinout, Specifications, Features, Datasheet & Programming.

there is a 5V input. This means you could power the Arduino nano from the DC-DC-step-down-converter into the 5V Input

You didn't told anything about what you did for debugging. What was is it?
best regards Stefan

  1. No it's not the Nano board I actually use (noname from AliExpress), just googled random pic for the diagram
  2. I'm debugging it to find out why it's freezing after 1-20-50 hours of working.
  3. My device consists of:
    a) power adapter 12v 2A
    b) Nano board
    c) LM2596
    d) SIM800L v2.0 (5V version)
    e) DS18B20 (2 sensors 1meter and 5meters each on different pins)
    So as you say 12v input is too much for Nano. I have another one power adapter here and it is 9v 0.6A. Would that be sufficient to supply power for Arduino and SIM800L? Or is it better to continue use 12V 2A, just reconnect Nano to LM2596 5v output instead of direct Vin 12V?
    Thanks for all you suggestions!

6v6gt:
post / attach your latest sketch to this thread.

Here is it! Thank you

temp.ino (20.6 KB)

I just had a quick glance over your sketch. You seem to be quite fluent with handling PROGMEM constructs such as:

strcat_P(warningMes, (const char*) F("2nd temp: ")) ;

so I've learnt something about wider use of the F() macro.

I guess, though, that a buffer overrun or similar could be the cause of the instability you have reported. Constructs like this, for example, where index is derived from a parsing operation could, without checks, cause an overflow, if unexpected results appear:

index = CommonA::indexOf(resStr, ",");
strtemp[0] = '\0';
memcpy(strtemp, resStr, index);

Incidentally, code like this code could be more compact, but not central to your problem:

 if (enableSmsStr == '1')
      {
        bEnableSms = true;
      }
      else
      {
        bEnableSms = false;
      }

reduces to:

bEnableSms = enableSmsStr == '1' ;