Skip to content

Software Guide

Freeze-FF edited this page May 1, 2024 · 6 revisions

Sequence Diagram of the Code of the Smart Toothbrush

image

Challenges and Solutions in Software Development

  • First, to avoid an inconsistent sampling frequency, a buffer is being used, to achieve a constant sampling rate. That way the data does not have to be transferred directly from the IMU to the microSD card, because this would cause the problem of always having to write the data in blocks of 512 bytes. To write large amounts of data at once without losing any new values in the meantime, a first-in first-out (FIFO) buffer was chosen. This buffer is filled with data, and when a defined threshold is reached, it is transferred in one step to the microSD card, without new values being lost in the meantime.
  • Second, In order to save energy, the ESP32 processor is in deep sleep when not used. Therefore, a wake-up mechanism is being used to switch from deep sleep to the active mode. An interrupt is used for that.
  • To overcome these two challenges, we use the IMU GY-LSM6DS3, since it provides a built-in 4 kB FIFO buffer and it offers the possibility to generate interrupts for defined motion sequences.
  • Third, since the internal RTC of the ESP32 processor is very inaccurate during deep sleep mode, the Real-Time-Clock-Module DS3231SN is used as an external RTC.

Software Overview

  • The ESP32 is an Arduino-based System on a Chip (SoC) microcontroller. We utilize the Arduino Integrated Development Environment (IDE) for writing and transferring program code. An important feature of the ESP32 processor is the deep sleep mode, which is used when the toothbrush is not in use to save energy.

  • When movement is being detected and the motion threshold is exceeded, the IMU generates an interrupt to activate the ESP32, which then changes from deep sleep mode to active mode. A txt file with the current boot count as name is created on the microSD card. The current time is retrieved from the RTC and written to the txt file. Then the IMU initializes the FIFO buffer and starts filling and emptying it by writing the data cyclically to the microSD card as soon as the threshold of 1200 bytes is reached.

  • To stop the measurement once the toothbrush is not being used anymore, a motion flag is used to store the current motion condition. Each time the FIFO buffer is emptied the motion condition gets checked to see if the toothbrush is still being used. Once the motion condition is false, the FIFO buffer is terminated, and the txt file is saved to the microSD card and closed to prevent any data loss. The IMU is set again with the parameters for wake up generation and low power consumption in deep sleep mode. The last step is to put the ESP32 back into deep sleep mode.