0

I've trying to write my code in plain C++ dropping out the Arduino's IDE. Although I've succeed in compiling the code, whenever I try to upload it to the board it doesn't run, seems that it stucks at some unknown point.

After that, everytime I try to upload a new code to the board it stops responding and avrdude throws this message:

$ ino upload -m leonardo -p /dev/ttyACM1
/dev/ttyACM1 doesn't exist. Is Arduino connected?

It doesn't matter if I unplug and then plug again the board, that message is still showing up.

In order to restart the board, I open the Arduino IDE and then I upload any sketch, then the board comes to live again.

The first time I tried overriding the main() function and the program didn't run I thought it was the tool I was using at that moment, arduino.mk, the one that was doing something strange.

Then I tried the ino tool, but the result was the same.

I don't think avrdude is failing because it actually uploads the .hex to the board.

My original main() code was:

#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
    return 0;
}

Then I tried to mimic the one that comes with Arduino:

#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

#if defined (USBCON)
    USBDevice.attach();
#endif  

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);

        if (serialEventRun) serialEventRun();
    }
    return 0;
}

Sadly, with both codes the board gets stucked at some point.

While I figure out how to solve this issue I've been exercising this solution inside a sketch:

const int LED_PIN = 13;

void setup() {                
}

void loop() {
    pinMode(LED_PIN, OUTPUT);     

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
}

Any ideas that led me to a solution? Thank you!

1

Solved!

It was a (big) silly mistake of my own. I overloocked the init() function right after entering the main() function. I'm shure it initializes the hardware and the entire system, so my board stucks when I skipped it.

So my code now looks like this:

#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    init();


#if defined (USBCON)
    USBDevice.attach();
#endif  

    pinMode(LED_PIN, OUTPUT);

    while (1)
    {

        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);

        if (serialEventRun) serialEventRun();
    }

    return 0;
}

BTW, the mix: Arduino + Vim + ino, rocks! Now I can do whatever I want from the console :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.