Ilmainen toimitus yli 100 euron tilauksille - Tuotteiden toimitukset Suomesta - Viiveitä johtuen kuljetuslakosta

Ruuvi Firmware – Part 3: LED Blinking

Ruuvi Firmware series intro image

In this part of the tutorial we’ll use GPIO drivers made in part 1 to finally make our RuuviTag blink LEDs. Final code of this blog post can be downloaded at Ruuvi GitHub in the ruuviblog-branch, tag 3.3.0-alpha. Please follow part 1 of the series for details on how to clone the repository and compile the code. If you want to download compiled hex, you can get it from


As our program becomes more complicated, we’ll split it into separate independent tasks rather than keep everything in main.c. As before, previously introduced parts are in blue, modified parts have gradient and new parts are in green.

ruuvi firmware.c architecture 3.3.0
Architecture as of 3.3.0

We add 3 tasks for LEDs. Init configures the pins, write sets an LED to desired state and cycle goes through the LEDs turning them on and then off in sequence.


In addition to the function definitions we’ll add enum for the led state. We could use RUUVI_BOARD_LEDS_ACTIVE_STATE and !RUUVI_BOARD_LEDS_ACTIVE_STATE directly just as well. Actual implementation is extremely simple, we just call the GPIO driver implemented in part 1 of the posts:


Finally we’ll call these tasks in the main.c:


The flow of program is similar to the current official RuuviTag firmware. We’ll boot up logging and peripherals, and then turn the RED LED on. Once self-test has passed, we turn the RED LED off and turn GREEN LED on. After one second we start the main loop, LED blinking in this case.

Power Consumption

Our delay implementation does not sleep the tag, it rather keeps the MCU active until the timeout occurs. Therefore our power consumption is several milliamperes, absolutely not feasible for battery powered operation.

Power profile of Ruuvi Firmware 3.3.0-alpha
Power profile of Ruuvi Firmware 3.3.0-alpha

It is easy to see the LEDs turning on and off in the steps of the profile. Right now our power consumption is approximately 1750 times the consumption we had in previous post, so obviously this is not acceptable solution for the long run.

In the next part of Ruuvi Firmware blog we’ll add interrupts from the button to program flow, which will allow us to sleep until the next button press occurs.

Stay tuned and follow @ojousima and @ruuvicom on Twitter for #FirmwareFriday posts!

Suosituimmat tuotteet

Valitse parhaat tuotteet juuri sinun mittaustarpeisiisi
  • RuuviTag mittaa lämpöä, ilmankosteutta, ilmanpainetta ja liikettä.Varastossa
    RuuviTag on Bluetooth-anturi, joka lähettää tiedon lämpötilasta, ilmankosteudesta, ilmanpaineesta...
    Lue lisää

    RuuviTag-anturi (4in1)

  • Ruuvi KitVarastossa
    Jokaisen Ruuvi Gateway -tuotteen mukana toimitetaan 6...
    Lue lisää

    Ruuvi Kit -mittauspaketti

  • Ruuvi GatewayVarastossa
    Jokaisen Ruuvi Gateway -tuotteen mukana toimitetaan 6...
    Lue lisää

    Ruuvi Gateway -reititin

  • RuuviTag Pro 3in1 measures temperature, air humidity and motionVarastossa
    Valitse sopiva malli (2in1 tai 3in1) tarpeidesi mukaan. RuuviTag...
    Lue lisää

    RuuviTag Pro -anturi