modification for wall clock to show time using LEDs, using STM32F103 micro-controller and WS2812b LED strips (old firmware)
Go to file
King Kévin 67d4d8e8db get rid of @brief 2016-05-05 23:47:50 +02:00
lib get rid of @brief 2016-05-05 23:47:50 +02:00
libopencm3@ad5ec6af08 add libopencm3 and STM32duino-bootloader submodules dependencies 2016-01-15 15:36:00 +01:00
.gitignore add doxygen documentation 2016-03-24 10:37:42 +01:00
.gitmodules remove STM32duino-bootloader submodule 2016-04-11 22:45:49 +02:00
Doxyfile get rid of @brief 2016-05-05 23:47:50 +02:00
Makefile use predefined OpenOCD configuration 2016-04-13 20:58:36 +02:00
README.md button text added 2016-04-17 12:20:12 +02:00
global.h get rid of @brief 2016-05-05 23:47:50 +02:00
main.c get rid of @brief 2016-05-05 23:47:50 +02:00
stm32f103x8-dfu.ld remove STM32duino-bootloader from linker script 2016-04-11 22:48:25 +02:00
stm32f103xb-dfu.ld remove STM32duino-bootloader from linker script 2016-04-11 22:48:25 +02:00

README.md

The LED clock is an add-on for round wall clocks. The purpose is to have LEDs on the circumference of the clock to show the progress of the time using coloured light.

For that you will need:

  • a WS2812b RGB LEDs strip (long enough to go around the clock)
  • a development board with a STM32F103 micro-controller and 32.768 kHz oscillator for the Real Time Clock (such as the blue pill)
  • a coin cell battery to keep the RTC running (optional)
  • a GL5528 photo-resistor to adjust the LED brightness (optional)

project

summary

The time will be shown as arc progress bars, in addition to the hands of the clock pointing at the current time. The hours passed since the beginning of the midday are shown using blue LEDs. The minutes passed sine the beginning of the hour are shown using green LEDs. Whichever progress is higher will be shown on top of the other. For example if it's 6:45, the first half of the circle will be blue, and an additional quarter will be green. The seconds passed since the beginning of the minute are shown using a running red LED, similar to the seconds hand. The red colour might be added on top of the blue, or green colour, then showing as violet or orange. The (gamma corrected) brightness of the last LED shows how much of the hour, minute, or second has passed.

technology

The LEDs are controlled using a STM32 F1 series micro-controller (based on an ARM Cortex-M3 32-bit processor). The board needs to include a 32.768 kHz oscillator for the Real-Time-Clock (RTC). Preferably use a blue pill board. The board needs to be powered by an external 5 V power supply (e.g. through the USB port). To set the time connect using serial over the USB port (providing the CDC ACM profile) or USART1 port (TX and RX are on pin PA9 and PA10) and enter "time HH:MM:SS". Optionally connect a 3 V coin battery on the VBAT pin for the RTC to keep the correct time in case the main power supply gets disconnected. To know the charge of the coin cell connect its positive terminal to ADC channel 1 on pin PA1. The level of the battery will be shown on the LEDs just after a restart, and the voltage will be shown over serial. To avoid the micro-controller to drain the battery trough the GPIO when un-powered use an NPN transistor, with the collector on the battery, the emitter on the pin, and the base on Vcc. If you don't want to use this feature connect PA1 to ground.

For the LEDs use a 1 meter LED strip with 60 red-green-blue WS2812b LEDs. Tape the LED strip along the border/edge of the clock. Ideally the wall clock has a diameter of 32 cm for the 1 m LED strip to completely fit. Otherwise change the number of actually used LEDs in the source files. Connect the 5 V power rail of the LED strip to the 5 V pin of the board. Connect the DIN signal line of the LED strip to the MISO pin of the micro-controller on PA6. SPI is used to efficiently shift out the LED colour values to the WS2812b LEDs. A custom clock is provided for this operation using channel 3 of timer 3 on pin PB0. Simply connect this clock to the SPI CLK input on pin PA5.

The brightness of the LEDs is dependant on the ambient luminance. To measure the ambient luminance a GL5528 photo-resistor is used. Connect one leg of the photo-resistor to ADC channel 0 on pin PA0 and the other to ground. Connect one leg of a 1 kOhm resistor to ADC channel 0 on pin PA0 and the other to a 3.3 V pin. This voltage divider allows to measure the photo-sensor's resistance and determine the luminance. If you don't want to use this feature, connect PA1 to ground for the highest brightness or Vcc for the lowest brightness.

The blue pill has a 32.768 kHz oscillator for the internal RTC, but don't use the LED next to it as it disturbs the oscillator and the time won't stay right. In case the time is lagging because RTC oscillation has been skipped, add a button between Vcc and PB8 and each press will increment the time by one second. If the board does not provide a 32.768 kHz oscillator for the internal RTC it is also possible to use an external RTC such as the Maxim DS1307. The time is then read over I2C and incremented using the square wave output. A working example code is under the DS1307_4096Hz_timer tag, but needs to be integrated in the latest code state.

board

The current implementation uses a blue pill.

The underlying template also supports following board:

Which board is used is defined in the Makefile. This is required:

  • for the linker script to know the memory layout (flash and RAM)
  • map the user LED and button provided on the board

code

dependencies

The source code uses the libopencm3 library. The projects is already a git submodules. To initialize and it you just need to run once: git submodule init and git submodule update.

firmware

To compile the firmware run make.

documentation

To generate doxygen documentation run make doc.

flash

The firmware will be flashed using SWD (Serial Wire Debug). For that you need an SWD adapter. The Makefile uses a ST-Link V2, along with the OpenOCD software. To flash using SWD run make flash.

debug

SWD also allows to debug the code running on the micro-controller using GDB. To start the debugging session run make debug.

USB

The firmware offers serial communication over USART1 and USB (using the CDC ACM device class).

You can also reset the board by setting the serial width to 5 bits over USB. To reset the board run make reset. This only works if the USB CDC ACM is running correctly and the micro-controller isn't stuck.