Blinking red light [Solved]

Hi everyone ! I’m facing a weird issue with my arduboy.
I’m working on a pretty heavy program (which is also compiled using a weird method, but I don’t think that’s relevant). The point is : this program probably uses quite a lot of SRAM. When I flash it to the arduboy, everything goes correctly, but as soon as the program start, the red led (the one on PIN10, not the charging one) starts blinking, and the program stops (the program is supposed to compute a large calculation, and then turn on either the green or red light depending on the result).
I’m thinking the blinking red light probably signals an out of memory error from the card, but I’d like to check. Anybody encountered this error before ?
Thanks for your help !

There’s nothing in the libraries that will cause the LEDs to blink due to any type of error (including “out of memory”), so it has to be caused by a problem with your code. Running out of RAM could cause any number of strange symptoms.

How much RAM does it report at compile time? Are you dynamically allocating memory within the program??

Can you post your code somewhere so we can at least rule out a possible problem with the code?

@filmote I do allocate memory at runtime. As for the static allocation, it’s kind of hard to check, because of the weird compilation process I talked about.
So here is the process : the source code is not in C, but in OCaml, which is a statically typed functional programming language. I then use a compiler called OMicroB (developed by two of my colleagues) which does the following things :

  • Compile the OCaml source to OCaml bytecode using the ocamlc program
  • Transform the bytecode into a C source code (which is basically still a list of instructions)
  • Compile this C source code using the avr-g++

@Pharap I can post the code, but I’m not sure it’s going to be really helpful… It’s available on GitHub. As I said, it’s OCaml code, using a library I made (called OContrainte) used to do constraint programming in OCaml (and optimized to be used with OMicroB on a micro-controller. The code basically solves the n-queens problem, and then lights up a green light if it found a solution (red otherwise). The point is, you can’t read the C code directly (well, you can, but it’s like 1000 lines of assembly-like instructions). The problem may be coming from OMicroB, but since I’ve successfully ran a smaller, less RAM intensive program (the one called basic), I’m pretty sure it’s working fine.

Sorry about this wall of text ^^

The fact you’re using a non-standard development environment is pretty important and probably should have been mentioned in the first post.

If it emits C code and not C++ code, I take it you’re not using the Arduboy2 library?
Hence why you’re relying on the LED?

The fact there’s dynamic memory allocation involved is important because there’s no mechanism to detect when the stack and the heap collide, they just collide with each other and you get nasal demons.
(Or at least that’s how it normally behaves using C++ and the Arduino IDE, I have no idea what OMicroB decides to do when it runs out of memory. Maybe OMicroB is the one flashing the LED?)

Does your version of OCaml use a garbage collector?
If so that could be another problem (and I’d wonder how it would work without threading).

What happens if you swap r and g in your code?
Does it still flash red or does it flash green?


Good question … as it will show that your code is ‘intentionally’ doing it.

1 Like

No, I’m not using any Arduboy-specific library. I have not tried using the screen for now.
Good point about OMicroB flashing the led ! I didn’t think of that. I will ask the developer right away. Also, there is indeed a garbage collector. By default, it uses a Mark and Compact algorithm, but it can be switched to Stop&Copy. I could try that, it may be interesting.
@filmote As for the leds, I can indeed swap then. Moreover, when I set the number of queens to 0 or 1 the green led turns on (because there is enough memory for 0 or 1 queen) and when I set it to 2, the red led turns on (because there is no solution for 2 or 3 queens). More queens however, and I get the blinking light…

EDIT : no luck with a change of GC…

The point of suggesting swapping them was to find out if the LED starts flashing green instead of red when you swap them around.

If it still flashes red, that rules out a subtle logic bug and points towards either being the result of undefined behaviour or something your programming environment does to tell you you’re out of memory.

In that case it’s looking most likely that the flashing LED is OMicroB telling you that the GC has hit the memory limit and thus absolutely nothing to do with the Arduboy.
I.e. you’d get the same result from any ATMega32u4 chip.

In which case you’d have more luck contacting the author of that than asking us since (as far as I’m aware) nobody here has any experience using it with the Arduboy.

Sorry to get back so late ! I have indeed emailed the author, and it does seem that the blinking led is intentionally triggered by OMibroC (for any error actually, not only for memory issues). Thank you all for your help !