Which Arduino C simulator to pick out?

Which Arduino C simulators do you suggest? I wish I could follow each line of the program, the way the program is executed. I wrote some program, at the moment I follow program execution using hardware ... but in some moment, when I am not beside hardware... program stop with execution so I need to know where it stoped ... at which line.

Thanks,
Nesa

Single step debugging is not normally available in the Arduino programming environment. You have to examine your program, make some educated guesses about what is happening, and then insert debugging print statements or some other kind of I/O signal like flashing an LED, when the program runs you can read the debug statements or look at the state of the LED at certain times. Keep moving the statements until you narrow down the problem.

Everyone thinks they need a hardware debugger, but it's surprisingly rare to encounter a problem that can't be solved without it, and by following good programming practices and by examining the source code closely.

...but please, always make sure that your debug code doesn't create new problems (like printing so frequently that your code slows down significantly).

Yes, I am doing like that... in the program I put an LED in several places that flashes differently so that I know how the program moves .... BUT ... BUT ... BUT somehow it stops overnight. So I don't know when the program stopped working.

perakojot73:
BUT ... BUT ... BUT somehow it stops overnight. So I don't know when the program stopped working.

Coffee is the programmer's tool of choice :slight_smile:

...R

Print messages to the Serial monitor at intervals indicating the section of code that is running and the value of pertinent variables such as the index to arrays. That might give you some clues

The problem is likely to be a problem with memory usage or writing outside of an array bound. If you had posted your code it would ha been easier to make suggestions as to what might be wrong

What exactly happens when the program stops ?

Here is my problem...I alredy posted on some athet post... but here is again...

I have a BIG problem. My GSM900 shuts down after approximately 5 days of device operation ... AT328P continues with operation. I've been analyzing the program for a few weeks, but it's not clear to me... The whole day is divided into intervals of 5 minutes and the loop checks if there were any messages and based on the sent message sends a reply. Sending "0" or "1" I receive temperature or humidity value. I set SIM900 in SAFE MODE 2 , due to reduced power consumption: with NO SLEEP MODE whole device drains about 60mA.. in SLEEP MODE2 with command AT+CSCLK=2 it reduces to 16mA. Is it possible that after a while ... as far as I know I can only guess ... the SIM900 shuts down on its own ...? In order to be able to monitor the execution of the program, I set some BLINK sequences on DIGITAL PORT 13 ... everything was executed as I programmed.

The device is made with a minimum number of external components: a crystal, a pair of capacitors and a reset resistor. At the beginning I have an automatic
switch ON sequence ... maybe it somehow comes out of the loop ... WHAT SHOULD NOT HAPPEN THAT ... and it goes to the beginning and through this AUTO ON SEQUENCE turns off GSM900. I shortened the loop to go not from: i=1 to 288 but to 5, and the duration of the same to 60000ms (1 minute)
... BEHAVES THE SAME. I power it with a 4A / 12V switching adapter, and then my Step Down Module LM2596s 3A DC to DC Buck Converter... lowers to 5V.

#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include "DHT.h"
#define DHTPIN 2
#define PIN_TX    7
#define PIN_RX    8
#define BAUDRATE  9600
#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
/*code code code code code code code */
#define code "0404"
/*code code code code code code code */
int messageIndex = 0;
#define DHTTYPE DHT22
GPRS gprsTest(PIN_TX, PIN_RX, BAUDRATE); //RX,TX,BaudRate
DHT dht(DHTPIN, DHTTYPE);
char string[160];
char smsbuffer[160];
char n[20];
char phone[16];
char telephone[16];
char datetime[24];
int analogInput = A2;
float vout = 0.0;
float vin = 0.0;
int value = 0;


void setup() {
  for (int i = 2; i <= 6; i++)
  {
    pinMode(i, OUTPUT);
  }
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(analogInput, INPUT);

  Serial.begin(9600);


       
/*
************************************************
AUTO POWER ON     for GSM900
************************************************
*/

      digitalWrite(9, LOW);
      delay(1000);
      digitalWrite(9, HIGH);
      delay(2000);
      digitalWrite(9, LOW);
      delay(3000);
 
 

/*
************************************************
Waiting 30 SEK for SIM900 initialization
************************************************
*/

while (!gprsTest.init()) {

    delay(30000);
  }

/*
*******************************************************
SIM900 is connected, deleting all mesages from MEMORY
*******************************************************
*/
   gprsTest.deleteSMS(messageIndex);
   messageIndex = 0;
  
 
 
/*
*******************************************************
SEND CODE, YOU HAVE 30 SECONNDS
*******************************************************
*/ 
   digitalWrite(LED_BUILTIN, HIGH);   
   delay(30000);
   digitalWrite(LED_BUILTIN, LOW);

/*
**********************************
READ MEMORY FROM SIM900
**********************************
*/
   gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
   messageIndex = gprsTest.isSMSunread();
   

   nocode:

 /*
***************************************
SMS in MEMORY, reading  parameters
***************************************
*/
  if (messageIndex > 0) {

    gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
   
       
/*
********************************************
remember number who send code- MASTER number
********************************************
*/
    strcpy(telephone,phone);
  
/*
********************************************
deleting all mesages from MEMORY
********************************************
*/
    gprsTest.deleteSMS(messageIndex);
    messageIndex = 0;
    
/*
********************************************
compare code
********************************************
*/
    if (strcmp (message, code) == 0) {

      delay(1000);

/*
********************************************
CODE IS OK, calling MASTER number
********************************************
*/
       gprsTest.callUp(telefon);
       delay(20000);
       
    }
/*
****************************************************
CODE is NOT OK, send code again
****************************************************
*/
    else {       
     
      digitalWrite(LED_BUILTIN, HIGH);   
      delay(30000);
      digitalWrite(LED_BUILTIN, LOW);
     
      goto nocode;
    }

  }

/*
********************************************************
SMS IS NOT sent, send SMS again
********************************************************
*/
    else if (messageIndex <= 0) {
     digitalWrite(LED_BUILTIN, HIGH);   
     delay(30000);
     digitalWrite(LED_BUILTIN, LOW);
   

    goto nocode;

  }
     dht.begin();
     scale.set_scale(21950.f);
     delay(500);
     


}


       

void retlja() {

 
               
    for (int i = 1; i <= 288; i++) {


    messageIndex = gprsTest.isSMSunread();
    if (messageIndex > 0) { //At least, there is one UNREAD SMS

     
      gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, telefon, datetime);
     
      gprsTest.deleteSMS(messageIndex);
      messageIndex = 0;
      if (strcmp (message, "1") == 0) {
       
        mesage();

        gprsTest.deleteSMS(messageIndex);
        messageIndex = 0;

      }
     
        else if (strcmp (message, "0") == 0) {
        
        mesagee();
        delay(1000);
       
       
        gprsTest.deleteSMS(messageIndex);
        messageIndex = 0;
       
      }

       delay(297500);

    }

 }


void loop() {

  retlja();
}

void mesage()   {
 
  float t = dht.readTemperature();
  int temp = (t);
  int temp1 = (t * 100) - (temp * 100);
  
   
 
  gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
  sprintf(string, "Temperature: %d.%d C  ", temp, temp1 );
  
  gprsTest.sendSMS(telephone, string);
  delay (10000);
  gprsTest.deleteSMS(messageIndex);
  messageIndex = 0;
  
}


void mesagee()   {
 
  float h = dht.readHumidity();
  int pos = 0;
  int hum = (h);
  int hum1 = (h * 100) - (hum * 100);
 
  gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
  sprintf(string, "Hummidy: %d.%d ",  hum, hum1 );
  
  gprsTest.sendSMS(telephone, string);
  delay (10000);
  gprsTest.deleteSMS(messageIndex);
  messageIndex = 0;
 
}

I have noticed something... when GSM900 turns OFF... I CAN NOT power it by pressing power switch on GSM module. I must disconect power complitly, and when put power back...

Here's how ... in the beginning I set the loop parameters to: i = 1 to 288 and the interval was 5 minutes ...5 minutes*288 = 24 hours... 1 day. And then it shut off for about 5 days ... maybe a little longer. In order not to wait for the loop to be repeated for one day, I decided to shorten the parameters as short as possible ...So I decided that the parameters should be: i = 1 to 5, duration 1 minute. I thought that after the end of one loop, it falls out of it and LOOP is no longer executed .... BUT NO ... With these parameters, the loop was initially repeated up to 300 times (with parameters: i = 1 to 5, duration 1 minute) maybe more...after which it would shut down. Three days ago it was reset after 4 days ... today after 161 repeated loops, less than one day (the loop lasts... I measured 7 minutes and 20 seconds). TOTALY MADNES.