Ardiuno boot up problem

Hi all,

I have a problem with the Arduino micro. When I try to programm(basic-programm) the arduino it is working well. when i reset the device then it goes from the boot mode to the normal mode and then the operating system delete the arduino. I have tried it with a different windows, but this wasnt the solution. Do you know how I am able to fix the problem? I have added the code as well, but I don´t think that this is the problem. The code was already working two weeks ago

arduino.txt (14.1 KB)

The Micro is like the Leonardo, so you wait for the serial port ?

The CMD is a char *, and you print it before it has been set to something. You also free it, without an alloc.

Do you use a new version of Arduino ? Version 1.0.6 or 1.5.8 ?

I waitr for the serial port and also for the arduino itself. When I upload my programm it has no error but when it is uploaded then the arduino is not working any more. I am a little bit confused because it was working already, I only had some problems with the values of the ADC. I will check the point with the CMD. I use Version 1.0.6

wertzztrew: I have a problem with the Arduino micro.

I can't make sense of your attachment. It has an extra blank line between every line and I can't get rid of them.

Can you post the attachment as a simple .ino file ?

...R

Okay Here I have the Arduino file

Arduino_micro.ino (15.9 KB)

I'm not sure that I understand what is going on. When you upload a simple sketch (for example led blink), is that working ? Also with hardware reset ? After that you can try something with the Serial output to the computer.

When those are working, the Arduino Micro is okay.

When I upload a Basic example from Arduino everything is working fine, but when I upload my program then the operating system is killing my arduino :( I have checed it, the ADC value is working fine, maybe it is because of the function send measurement... but we use the same function to transfer digital datas and here it is working fine

but when I upload my program then the operating system is killing my arduino

No, it isn't. The Arduino is doing something that the OS doesn't like, causing the OS to stop acknowledging the Arduino.

The OS is NOT causing the problem. It is dealing with the Arduino doing something stupid.

Thanks PaulS

but I am not able to find out what happend and what is the problem, because the compiler says everything is okay…
So I am a little bit confused…

  Serial.println("Test1");
  Serial.println(CMD);
  CMD = "SMS";

Does this make sense? Print the value in CMD, and then immediately assign it a new value. Why? Why does the old value matter?

  if(CMD == "RES")
  {
    //dann Arduino schlafen legen
  }

The address of CMD will NEVER be equal to the memory location of the string literal.

Even if this were the way to compare strings, what do you suppose the chances are that "SMS" would equal "RES"?

    dateANDtime = (char*)malloc(19);
    getDATEandTIME(dateANDtime);
    SendMeasurement(Temperatur(), "TMP", sID, dateANDtime);
    Serial.println("Temperatur");
    free(dateANDtime);

It would be orders of magnitude better to declare a statically sized array ONCE than to do all this dynamic memory allocation of statically sized blocks of data.

    free(CMD);

C allows you to shoot yourself in the foot, if you want. Why you would want to is a mystery. You are NOT dynamically allocating memory for CMD, so freeing it is stupid.

 float Niederschlag()
{
  //Imput am Pin A2 einlesen
  int sensorValueA2 = analogRead(A2);
  //Den Analogen Wert (welcher von 0 - 1023 reicht) in eine Spanung (0 - 5V) umrechnen
  float Niederschlag = sensorValueA2 * (5.0 / 1023.0);
  if (sensorValueA2 == 5)
    {
        //Serial.print(Niederschlag);
        //Serial.println("0");
        return 0;
    }
        else
            {
                //Serial.print(Niederschlag);
                //Serial.println("1");
                return 1;
            }
  delay(100);
}

Why is this function defined to return a float, but the return statements return byte values? Why is it necessary to send the 0 or 1 value, using SendMeasurement() in loop()? Seems to me like it would be far more useful to have this function return Niederschlag, and send THAT.

The magic numbers in your code should be replaced with #define names, so that there is some logical explanation for the values.

  //Größe für den Sendestring
  size_t mSize = 8+strlen(unit)+strlen(sID)+strlen(DandT);
  //Speicherplatz
  char *data = (char*)malloc(mSize);
  char *temp = (char*)malloc(4);
  data[0]='\0';
  temp[0]='\0';

More unnecessary dynamic memory allocation. Use static arrays that are large enough to hold the longest value you are likely to encounter.

You fail to free temp later on, so you've built a memory leak into your program.

The 'CMD' has no value, it might be zero. Perhaps doing a Serial.println() with zero overwrites the USB part of the Arduino board. Either directly or perpaps because it is no longer executing the sketch, but going haywire. I think that is possible.

Fix the sketch and I'm confident that it will work.