|
Baby Monitoring System
|
Defines the parent side of a baby monitoring system. More...
#include <esp_now.h>#include <WiFi.h>#include <LiquidCrystal_I2C.h>#include <string.h>#include <freertos/FreeRTOS.h>#include <freertos/task.h>#include <freertos/queue.h>#include <freertos/semphr.h>Data Structures | |
| struct | SensorInfo |
| Stores information associated with a sensor. More... | |
Macros | |
| #define | NUM_SENSORS 6 /**> Number of sensors in the system */ |
| #define | BUZZER_PIN 9 /**> Buzzer pin number */ |
| #define | X_PIN 13 |
| #define | Y_PIN 14 |
| #define | SW_PIN 17 |
| #define | GO_UP(y) ((y) < 500) |
| #define | GO_DOWN(y) ((y) == 4095) |
| #define | GO_LEFT(x) ((x) < 500) |
Enumerations | |
| enum | sensorIDs { NOISE , TEMP , HUMIDITY , MOTION , WATER , LIGHT } |
| Defines the sensor IDs. More... | |
| enum | lcdView { MENU , SENSOR_MENU , SONG_MENU , SENSOR_VIEW , SONG_VIEW , ALARM } |
| Defines the possible LCD view options. More... | |
Functions | |
| void IRAM_ATTR | onTimer32Hz () |
| ISR for Timer. Triggers buzzAlarmTask to run. | |
| void IRAM_ATTR | onDataRecv (const uint8_t *mac, const uint8_t *data, int len) |
| ISR that gets called when a message is received. Updates sensor value. | |
| void | onDataSent (const uint8_t *mac_addr, esp_now_send_status_t status) |
| Callback function for sending data to the baby board. | |
| bool | debounce (int *lastInputTime) |
| Checks if the specified debounce interval has passed since the last recorded input time. | |
| void | receiveDataTask (void *arg) |
| FreeRTOS task that handles data from the queue, parses sensor values, and checks if an alarm should trigger. | |
| void | moveCursor () |
| Moves the cursor on the LCD between lines 0 and 1. | |
| void | printMenu () |
| Prints the main menu screen to the LCD and handles navigation logic. | |
| void | printSensorPreviews () |
| Prints two sensor names to the LCD. | |
| void | printSongPreviews () |
| Prints two song names to the LCD. | |
| void | printSensorMenu () |
| Prints the sensor menu screen to the LCD and handles navigation logic. | |
| void | printSensorView () |
| Prints individual sensor info to the LCD and handles navigation logic. | |
| void | printSongMenu () |
| Prints the song menu screen to the LCD and handles navigation logic. | |
| void | printSongView () |
| Prints the selected song info to the LCD screen and handles navigation logic. | |
| void | printAlarm () |
| Prints the alarm display to the LCD screen and handles navigation logic. | |
| void | buzzAlarmTask (void *arg) |
| FreeRTOS task that handles buzzing the alarm. | |
| void | lcdDisplayTask (void *arg) |
| FreeRTOS task that handles LCD display updates. | |
| bool | checkNoise (float value) |
| Checks if the given sensor value should trigger an alarm for noise. | |
| bool | checkTempurature (float value) |
| Checks if the given sensor value should trigger an alarm for temperature. | |
| bool | checkHumidity (float value) |
| Checks if the given sensor value should trigger an alarm for humidity. | |
| bool | checkMotion (float value) |
| Checks if the given sensor value should trigger an alarm for motion. | |
| bool | checkWater (float value) |
| Checks if the given sensor value should trigger an alarm for water. | |
| bool | checkLight (float value) |
| Checks if the given sensor value should trigger an alarm for light. | |
| LiquidCrystal_I2C | lcd (0x27, 20, 4) |
| void | setup () |
| void | loop () |
Variables | |
| uint8_t | broadcastAddress [6] = {0xDC, 0xDA, 0x0C, 0x21, 0x5B, 0x94} |
| volatile char | incomingMessage [10] |
| SensorInfo | sensorValues [6] |
| char * | songs [3] |
| Array of song names. | |
| enum lcdView | currLcdView = MENU |
| int | sensorOnTopLcdLineID = 0 |
| int | songOnTopLcdLineID = 0 |
| Song ID for the top line of the LCD in the song menu. | |
| int | cursorLine = 0 |
| int | lastYInputTime = 0 |
| int | lastXInputTime = 0 |
| int | lastSwInputTime = 0 |
| hw_timer_t * | timer32Hz = NULL |
| Hardware timer for 32Hz timing. | |
| TaskHandle_t | lcdDisplayTaskHandle |
| TaskHandle_t | buzzAlarmTaskHandle |
| Task handle for the buzzer alarm task. | |
| TaskHandle_t | receiveDataTaskHandle |
| Task handle for the data reception task. | |
| QueueHandle_t | sensorDataQueue |
| Queue handle for sensor data. | |
| SemaphoreHandle_t | lcdSemaphore |
| Semaphore handle for LCD access. | |
Defines the parent side of a baby monitoring system.
This file is intended to be uploaded to an Arduino Nano ESP32 board. It allows viewing values or sensors sent from the baby side, triggering an alarm if a value is in a bad setting, and sending a song to the baby.
| #define BUZZER_PIN 9 /**> Buzzer pin number */ |
| #define GO_DOWN | ( | y | ) | ((y) == 4095) |
Joystick down movement
| #define GO_LEFT | ( | x | ) | ((x) < 500) |
Joystick left movement
| #define GO_UP | ( | y | ) | ((y) < 500) |
Joystick up movement
| #define NUM_SENSORS 6 /**> Number of sensors in the system */ |
| #define SW_PIN 17 |
Joystick SW pin
| #define X_PIN 13 |
Joystick VRX pin
| #define Y_PIN 14 |
Joystick VRY pin
| enum lcdView |
| enum sensorIDs |
| void buzzAlarmTask | ( | void * | arg | ) |
FreeRTOS task that handles buzzing the alarm.
This task manages the buzzer to sound the alarm at regular intervals. The buzzer is activated and deactivated to create an audible alarm when triggered by an interrupt.
| arg | Pointer to task argument (unused). |
| bool checkHumidity | ( | float | value | ) |
Checks if the given sensor value should trigger an alarm for humidity.
This function evaluates the sensor value and determines if it falls outside the acceptable range for humidity. If the value is out of range, the alarm is triggered, and the current LCD view is updated to the alarm screen.
| value | The sensor value to check. |
| bool checkLight | ( | float | value | ) |
Checks if the given sensor value should trigger an alarm for light.
This function evaluates the sensor value and determines if it indicates a high enough light level. If so, the alarm is triggered, and the current LCD view is updated to the alarm screen.
| value | The sensor value to check. |
| bool checkMotion | ( | float | value | ) |
Checks if the given sensor value should trigger an alarm for motion.
This function evaluates the sensor value and determines if it indicates motion. If motion is detected, the alarm is triggered, and the current LCD view is updated to the alarm screen.
| value | The sensor value to check. |
| bool checkNoise | ( | float | value | ) |
Checks if the given sensor value should trigger an alarm for noise.
This function evaluates the sensor value and determines if it exceeds the threshold for noise. If the threshold is exceeded, the alarm is triggered, and the current LCD view is updated to the alarm screen.
| value | The sensor value to check. |
| bool checkTempurature | ( | float | value | ) |
Checks if the given sensor value should trigger an alarm for temperature.
This function evaluates the sensor value and determines if it falls outside the acceptable range for temperature. If the value is out of range, the alarm is triggered, and the current LCD view is updated to the alarm screen.
| value | The sensor value to check. |
| bool checkWater | ( | float | value | ) |
Checks if the given sensor value should trigger an alarm for water.
This function evaluates the sensor value and determines if it indicates a high enough water level. If so, the alarm is triggered, and the current LCD view is updated to the alarm screen.
| value | The sensor value to check. |
| bool debounce | ( | int * | lastInputTime | ) |
Checks if the specified debounce interval has passed since the last recorded input time.
| lastInputTime | Pointer to the last input time. |
| LiquidCrystal_I2C lcd | ( | 0x27 | , |
| 20 | , | ||
| 4 | ) |
| void lcdDisplayTask | ( | void * | arg | ) |
FreeRTOS task that handles LCD display updates.
This task manages the LCD display based on the current view. It updates the display according to the state of the currLcdView variable and handles the printing of menus and sensor/song information.
| arg | Pointer to task argument (unused). |
| void loop | ( | ) |
| void moveCursor | ( | ) |
Moves the cursor on the LCD between lines 0 and 1.
This function moves the cursor on the LCD display from line 0 to line 1 or from line 1 to line 0.
| void IRAM_ATTR onDataRecv | ( | const uint8_t * | mac, |
| const uint8_t * | data, | ||
| int | len ) |
ISR that gets called when a message is received. Updates sensor value.
| mac | Pointer to the MAC address of the sender. |
| data | Pointer to the received data. |
| len | Length of the received data. |
This ISR handles incoming ESP-NOW messages by copying data into incomingMessage and sending it to sensorDataQueue.
| void onDataSent | ( | const uint8_t * | mac_addr, |
| esp_now_send_status_t | status ) |
Callback function for sending data to the baby board.
| mac_addr | Pointer to the MAC address of the recipient. |
| status | Status of the send operation. |
| void IRAM_ATTR onTimer32Hz | ( | ) |
ISR for Timer. Triggers buzzAlarmTask to run.
This ISR is triggered by a timer interrupt at 32 Hz. It signals the buzzAlarmTask to run.
| void printAlarm | ( | ) |
Prints the alarm display to the LCD screen and handles navigation logic.
This function shows which sensors triggered the alarm and allows the user to reset the alarm or send a song in response. It updates the LCD display based on user input and sensor status.
| void printMenu | ( | ) |
Prints the main menu screen to the LCD and handles navigation logic.
This function displays the main menu options on the LCD and handles user inputs to navigate between menu options.
| void printSensorMenu | ( | ) |
Prints the sensor menu screen to the LCD and handles navigation logic.
This function displays the sensor menu options on the LCD and manages user navigation within the menu.
| void printSensorPreviews | ( | ) |
Prints two sensor names to the LCD.
This function retrieves and displays the names of two sensors on the LCD.
| void printSensorView | ( | ) |
Prints individual sensor info to the LCD and handles navigation logic.
This function displays detailed information about a selected sensor and manages user navigation to go back to the sensor menu.
| void printSongMenu | ( | ) |
Prints the song menu screen to the LCD and handles navigation logic.
This function displays the song menu options on the LCD and manages user navigation within the menu.
| void printSongPreviews | ( | ) |
Prints two song names to the LCD.
This function retrieves and displays the names of two songs on the LCD.
| void printSongView | ( | ) |
Prints the selected song info to the LCD screen and handles navigation logic.
This function displays the currently selected song and allows the user to send the song to the baby or return to the song menu. It handles button presses to send the song or navigate back.
| void receiveDataTask | ( | void * | arg | ) |
FreeRTOS task that handles data from the queue, parses sensor values, and checks if an alarm should trigger.
| arg | Pointer to task argument (unused). |
This task processes sensor data from sensorDataQueue, parses the data to extract sensor IDs and values, updates sensor information, and checks for alarm conditions.
| void setup | ( | ) |
| uint8_t broadcastAddress[6] = {0xDC, 0xDA, 0x0C, 0x21, 0x5B, 0x94} |
| TaskHandle_t buzzAlarmTaskHandle |
Task handle for the buzzer alarm task.
This handle is used to manage the task responsible for triggering the buzzer alarm.
| int cursorLine = 0 |
| volatile char incomingMessage[10] |
| int lastSwInputTime = 0 |
| int lastXInputTime = 0 |
| int lastYInputTime = 0 |
| TaskHandle_t lcdDisplayTaskHandle |
| SemaphoreHandle_t lcdSemaphore |
Semaphore handle for LCD access.
This handle is used to manage access to the LCD display, ensuring synchronized updates.
| TaskHandle_t receiveDataTaskHandle |
Task handle for the data reception task.
This handle is used to manage the task responsible for receiving data from external sources.
| QueueHandle_t sensorDataQueue |
Queue handle for sensor data.
This handle is used to manage the queue that stores sensor data for processing.
| int sensorOnTopLcdLineID = 0 |
| SensorInfo sensorValues[6] |
| int songOnTopLcdLineID = 0 |
Song ID for the top line of the LCD in the song menu.
This variable specifies which song will be displayed on the top line of the LCD when the song menu is shown.
| char* songs[3] |
Array of song names.
This array contains the names of the songs available for selection.
| hw_timer_t* timer32Hz = NULL |
Hardware timer for 32Hz timing.
This pointer represents a hardware timer configured to operate at 32Hz.