Neopixels brightness

Issue #244 resolved
Geek created an issue

Hello!
I am creating a control/monitoring with Microblocks for a small aquarium.
I want to control lighting with neopixels, simulating sunrise, sunset and moonlight. I use an ESP32 and so far I have not achieved the maximum brightness of the neopixels. They start to illuminate from values close to 40, and at 255 the luminosity is low. I have done the tests with an Arduino and the Adafruit libraries and they work correctly, so I suppose it is not a problem with the neopixels.
Could it be a bug in the microblocks library?
Thanks!

Comments (8)

  1. John Maloney repo owner

    You’re right, and that behavior is intentional.

    In MicroBlocks workshops, we mostly use NeoPixels as decorations on craft projects and costumes. People look directly into the NeoPixels, rather than using them for illumination. We found their maximum brightness to be painful to look at, so the RGB values from a MicroBlocks program go through a mapping function that only uses the lowest part of the NeoPixel brightness range. The maximum value for each color channel is 40. So you’re correct, you’re seeing only a fraction of the total brightness range.

    The limited range also serves another purpose – it avoids drawing too much current. With the original micro:bit, setting a string of 10 NeoPixels to their full brightness on all channels would cause the micro:bit to get a “brownout” reset. In a workshop involving both servos and NeoPixels, one girl's delicate kinetic sculpture was damaged when the brownout caused the servos to spin madly before she was able to remove power. Most microcontrollers, including the micro:bit v2, can supply more current than the micro:bit v1, but the current draw from full-powered NeoPixels is still a consideration.

    One possible solution for you would be to prototype your system with MicroBlocks, then port the logic to Arduino code, which does allow the full brightness range. Another option is a hybrid soltuion: a microcontroller running MicroBlocks send commands via the serial port to an ESP32 running a simple Arduino program that drives the NeoPixels. A third option would be to build a custom version of the MicroBlocks VM that disables the MicroBlocks brightness mapping. That’s a one-line change to outputPrims.cpp. Simply have the gamma() function return it’s input rather than mapping it.

    Be sure to compute the maximum current you might need and check that against the specs of your microconroller. See this Adafruit article.

    Hope that helps!

  2. Geek reporter

    Thank you very much for the quick answer.

    I'm going to try to get into the VM. I hope I don't break anything ;)

    You may think that microblocks is only useful in education, but it is an extraordinary tool for those of us, like me, who like to play and experiment with technology to carry out small home projects.

    Thanks again

  3. John Maloney repo owner

    Glad MicroBlocks is useful to you! To compile the VM, you can use either the Arduino IDE or Platformio. Good luck!

  4. Bernat Romagosa

    @John Maloney , I would vote for a solution that lets hobbyists use the full brightness range without having to recompile the VM themselves. One of reasons behind MicroBlocks is precisely to not force people through the hurdle of compiling anything 🙂

    What about a hidden block -only in advanced mode- that turns the full range on and off? Something like:

  5. Geek reporter

    I have been experimenting and have compiled the VM with platformio. It works perfectly in micro:bit.

    With ESP32 I have instability in the luminosity beyond the 9th neopixel. I use 10W power supply. Keep investigating

    Thank you.

    Anyway, I think Bernat's idea is a great solution ;)

  6. John Maloney repo owner

    @Bernat While your suggestion would be easy to implement, the problem is that full Neopixel brightness on a 10 Neopixel strip can actually brown out a board such as a micro:bit. It could even damage the board (i.e. fry the voltage regulator) or, as it did in a workshop, make a servo spin crazily and damage a student’s project.

    This isn’t just theoretical, it actually happened several times in an early workshop I did with Jen Lavalle. I worry that inquisitive students might discover the “full brightness range” block while exploring and brown out their board. We try super hard to avoid features that might crash the VM, let alone cause hardware damage. That lets people feel free to explore without fear that they will break something.

  7. Log in to comment