IV22 clock software

Posted on by

This post discusses about the basic software architecture as it at the publish date. I’ll update it as things change over time.
I’ve decided to use the Arduino environment for it’s existing libraries.

I’ve added the ESP32 support provided by Espressif by following their instructions from this page: arduino-esp32 github page
The code uses the FreeRTOS stack to ensure the timing of the IV22 refresh code and to provide inter-task synchronization and control.
I’m using the following libraries from the Arduino system:

  • Adafruit_BME680 to handle the BME680 sensor control
  • ESP32 OTA for the remote software update feature, provided in the ESP32 Arduino stack

The code is broken down in several blocks that handle one specific feature:

  • main_code that takes care of system initialization in the setup() and the main loop() required by Arduino
  • display.cpp that takes care of continuously refreshing the tubes, as they are multiplexed
  • task scheduler that controls the way different screens are displayed
  • BME680 code that holds the code that display the environmental sensors data
  • TIME display code that handles the time and data display screens

The display handling code takes care of properly configuring the V_SPI peripheral and associated GPIO pins (LOAD and BLANK). The actual display refresh is done by the vRefreshDisplayTask periodic task, that’s started up with a higher priority over the other system tasks.
vRefreshDisplayTask will update one digit at a time, in 1ms intervals. The display data is double-buffered to reduce the risk of flickering digits. The buffers are synchronized once the last digit is updated.
Some simple data update functions are provided, that directly write the secondary display buffer.
Also, some simple fonts are provided to cover 0-9 numerals and most of the Latin letters.

The BME680 code configures the BME680 sensor and then starts vRefreshBme680Task
vRefreshBme680Task is controlled by vUiDisplaySchedTask via xEventGroupWaitBits(). Once it’s enabled, it refreshes it’s data from the sensor and then it will show several information screens: temperature, humidity, pressure and VOC resistor. Each screen is displayed for about 5s

The TIME handling code start the NTP time synchronization and start vRefreshTimeTask and vRefreshDateTask that are also controlled by vUiDisplaySchedTask.
vRefreshTimeTask displays the time in 24H format, with a dot between each digit group. IT will continue refreshing the display data as long as SCHED_TIME_WAIT_BIT bit is set.
vRefreshDateTask will display the year in 4 digit format for 5s and then will display the month and day number for another 5s

vUiDisplaySchedTask handles the display screen timing. It works by manipulating a set of bits under a EventGroupHandle. Each bit controls one of the display functions. Also, there is a feedback bit from each function, that will prevent the task scheduler to enable the next display task if the current one is still running.
The display order is stored in an array that’s populated in the setup() function. The array stores a pair of control bits and display times. The code will loop over this array, set the specified bit with xEventGroupSetBits, wait for the configured amount of time and clear the bit with xEventGroupClearBits. After this, it will wait for the feedback-bits to be cleared with xEventGroupWaitBits.
The next step is to increment the array index, and roll-over if necessary.

The OTA code is a 100% copy of the ESP32-OTA sample code. It will allow firmware updates once the device is mounted in the case. It’s the only piece of code that will break the display control timing, during the update the display will flicker.

Right now the code is very simple, it offers just the basic functionality and it’s mostly a test for the different modules.
The next important thing is to add a web page that will allow to change the device settings.
Also, the WiFi configuration is hard-coded, so the device will fail to start-up if the WiFi setup fails. Code needs to be added to create a local network if that fails, so the user can still access the configuration page.

As with the hardware page, I’ll update this once new things are available.

Category: IV22 clock
Comments are disabled