|
Baby Monitoring System
|
Defines the baby side of a baby monitoring system. More...
#include <esp_now.h>#include <WiFi.h>#include <Arduino.h>#include <string.h>#include <freertos/FreeRTOS.h>#include <freertos/task.h>#include <freertos/queue.h>#include <LiquidCrystal_I2C.h>#include <Bonezegei_DHT11.h>#include "songs.h"Data Structures | |
| struct | SensorInfo |
| Stores information associated with a sensor. More... | |
Macros | |
| #define | NUM_SENSORS 6 |
| #define | SOUND_ANA_PIN 3 |
| #define | WATER_PIN 1 |
| #define | MOTION_PIN 7 |
| #define | LIGHT_PIN 2 |
| #define | DHT_PIN 6 |
| #define | BUZZER_PIN 9 |
| #define | X_PIN 13 |
| #define | Y_PIN 14 |
| #define | SW_PIN 17 |
| #define | GO_UP(y) ((y) < 400) |
| #define | GO_DOWN(y) ((y) == 4095) |
| #define | GO_LEFT(x) ((x) < 300) |
Enumerations | |
| enum | lcdView { MENU , SENSOR_VIEW } |
| Defines the possible LCD view options. More... | |
| enum | sensorIDs { NOISE , TEMP , HUMIDITY , MOTION , WATER , LIGHT } |
| Defines sensor IDs for different sensors. More... | |
Functions | |
| LiquidCrystal_I2C | lcd (0x27, 16, 2) |
| Bonezegei_DHT11 | dht (DHT_PIN) |
| void IRAM_ATTR | onTimer50Hz () |
| ISR for Timer. Triggers playSongTask to run. | |
| void IRAM_ATTR | onDataReceived (const uint8_t *mac, const uint8_t *incomingData, int len) |
| ISR that gets called when a message is received. Updates the messageReceived flag and stores the message. | |
| void | onDataSent (const uint8_t *mac_addr, esp_now_send_status_t status) |
| Callback function for sending data to parent board. | |
| bool | debounce (int *lastInputTime) |
| Checks if the specified debounce interval has passed since the last recorded input time. | |
| void | moveCursor () |
| Moves cursor on LCD to the line it's not on (from line 0 to 1, or 1 to 0). | |
| void | printSensorPreviews () |
| Prints two sensor names to the LCD. | |
| void | printMenu () |
| Prints menu screen to LCD and handles navigation logic. | |
| void | printSensorView () |
| Prints individual sensor info to the LCD and handles navigation logic. | |
| void | lcdDisplayTask (void *arg) |
| FreeRTOS task that handles LCD display. | |
| void | playSongTask (void *arg) |
| FreeRTOS task that plays a song if instructed to by the parent board. | |
| void | readSensorsTask (void *arg) |
| FreeRTOS task that updates sensor values and sends them to the queue. | |
| void | processSensorInfoTask (void *arg) |
| FreeRTOS task that processes data from the queue and sends it to the parent board. | |
| void | setup () |
| void | loop () |
Variables | |
| uint8_t | broadcastAddress [6] = {0xEC, 0xDA, 0x3B, 0x60, 0xD3, 0xAC} |
| Address of the parent board. | |
| bool | messageReceived = false |
| Flag indicating if a message was received from the parent board. | |
| char | incomingMessage [18] |
| Buffer to hold the incoming message. | |
| enum lcdView | currLcdView = MENU |
| Current LCD view. | |
| int | sensorOnTopLcdLineID = 0 |
| Sensor ID for the sensor displayed on the top line of the LCD menu. | |
| volatile int | cursorLine = 0 |
| Indicator of the currently selected line on the LCD. | |
| int | lastYInputTime = 0 |
| Last recorded time for Y-axis joystick input for debouncing. | |
| int | lastXInputTime = 0 |
| Last recorded time for X-axis joystick input for debouncing. | |
| int | lastSwInputTime = 0 |
| Last recorded time for joystick switch input for debouncing. | |
| hw_timer_t * | timer50Hz = NULL |
| Timer used for scheduling tasks at 50Hz. | |
| TaskHandle_t | readSensorsTaskHandle |
| Task handle for reading sensor data. | |
| TaskHandle_t | playSongTaskHandle |
| Task handle for playing a song. | |
| TaskHandle_t | lcdDisplayTaskHandle |
| Task handle for updating the LCD display. | |
| TaskHandle_t | processSensorInfoTaskHandle |
| Task handle for processing sensor information. | |
| QueueHandle_t | sensorQueue |
| Queue handle for managing sensor data. | |
| SensorInfo | sensorValues [6] |
| Array of sensor information. | |
Defines the baby side of a baby monitoring system.
Meant to uploaded on an Arduino Nano ESP32 Board. Reads values from sensors in the baby's room and sends them to the parent side. Plays a song to the baby if instructed by the parent side.
| #define BUZZER_PIN 9 |
Buzzer pin.
| #define DHT_PIN 6 |
Pin for temperature/humidity sensor.
| #define GO_DOWN | ( | y | ) | ((y) == 4095) |
Check if joystick is moved down.
| #define GO_LEFT | ( | x | ) | ((x) < 300) |
Check if joystick is moved left.
| #define GO_UP | ( | y | ) | ((y) < 400) |
Check if joystick is moved up.
| #define LIGHT_PIN 2 |
Light level sensor.
| #define MOTION_PIN 7 |
Motion detector.
| #define NUM_SENSORS 6 |
Number of sensors getting input from.
| #define SOUND_ANA_PIN 3 |
Sound detector.
| #define SW_PIN 17 |
Joystick switch pin.
| #define WATER_PIN 1 |
Water detector.
| #define X_PIN 13 |
Joystick X-axis pin.
| #define Y_PIN 14 |
Joystick Y-axis pin.
| enum lcdView |
| enum sensorIDs |
Defines sensor IDs for different sensors.
| 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. |
| Bonezegei_DHT11 dht | ( | DHT_PIN | ) |
| LiquidCrystal_I2C lcd | ( | 0x27 | , |
| 16 | , | ||
| 2 | ) |
| void lcdDisplayTask | ( | void * | arg | ) |
FreeRTOS task that handles LCD display.
FreeRTOS task that handles LCD display updates.
| arg | Task argument (unused). |
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 cursor on LCD to the line it's not on (from line 0 to 1, or 1 to 0).
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 onDataReceived | ( | const uint8_t * | mac, |
| const uint8_t * | incomingData, | ||
| int | len ) |
ISR that gets called when a message is received. Updates the messageReceived flag and stores the message.
| mac | MAC address of the sender. |
| incomingData | Pointer to the incoming data. |
| len | Length of the incoming data. |
| void onDataSent | ( | const uint8_t * | mac_addr, |
| esp_now_send_status_t | status ) |
Callback function for sending data to parent board.
Callback function for sending data to the baby board.
| mac_addr | MAC address of the recipient. |
| status | Status of the send operation. |
| mac_addr | Pointer to the MAC address of the recipient. |
| status | Status of the send operation. |
| void IRAM_ATTR onTimer50Hz | ( | ) |
ISR for Timer. Triggers playSongTask to run.
| void playSongTask | ( | void * | arg | ) |
FreeRTOS task that plays a song if instructed to by the parent board.
| arg | Task argument (unused). |
| void printMenu | ( | ) |
Prints menu screen to LCD and handles navigation logic.
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 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 processSensorInfoTask | ( | void * | arg | ) |
FreeRTOS task that processes data from the queue and sends it to the parent board.
| arg | Task argument (unused). |
| void readSensorsTask | ( | void * | arg | ) |
FreeRTOS task that updates sensor values and sends them to the queue.
| arg | Task argument (unused). |
| void setup | ( | ) |
| uint8_t broadcastAddress[6] = {0xEC, 0xDA, 0x3B, 0x60, 0xD3, 0xAC} |
Address of the parent board.
Address of the baby side board.
This array holds the MAC address for the parent board, used for communication.
This array holds the MAC address for the baby side board, used for communication.
Current LCD view.
Current LCD view mode.
This variable tracks the current view displayed on the LCD. It is initialized to the start menu.
This variable indicates the current view mode of the LCD display, initially set to MENU.
| volatile int cursorLine = 0 |
Indicator of the currently selected line on the LCD.
Current line selected on the LCD.
This volatile variable indicates which line of the LCD is currently selected by the user.
This variable indicates which line of the LCD is currently selected.
| char incomingMessage[18] |
Buffer to hold the incoming message.
Buffer for message from the baby side.
This buffer stores the message received from the parent board. It can hold up to 17 characters plus a null terminator.
This buffer stores incoming messages received from the baby side.
| int lastSwInputTime = 0 |
Last recorded time for joystick switch input for debouncing.
Last recorded time for the switch input for debouncing.
This variable is used to store the last time the joystick switch was pressed to implement debouncing.
This variable tracks the last time the switch input was recorded to help with debouncing.
| int lastXInputTime = 0 |
Last recorded time for X-axis joystick input for debouncing.
Last recorded time for the X input for debouncing.
This variable is used to store the last time an X-axis input was registered to implement debouncing.
This variable tracks the last time the X input was recorded to help with debouncing.
| int lastYInputTime = 0 |
Last recorded time for Y-axis joystick input for debouncing.
Last recorded time for the Y input for debouncing.
This variable is used to store the last time a Y-axis input was registered to implement debouncing.
This variable tracks the last time the Y input was recorded to help with debouncing.
| TaskHandle_t lcdDisplayTaskHandle |
Task handle for updating the LCD display.
Task handle for the LCD display task.
This handle is used to manage the task responsible for updating the information displayed on the LCD.
This handle is used to manage the task responsible for updating the LCD display.
| bool messageReceived = false |
Flag indicating if a message was received from the parent board.
This flag is set to true when a new message is received from the parent board.
| TaskHandle_t playSongTaskHandle |
Task handle for playing a song.
This handle is used to manage the task responsible for playing a song through the buzzer.
| TaskHandle_t processSensorInfoTaskHandle |
Task handle for processing sensor information.
This handle is used to manage the task responsible for processing and managing sensor information.
| TaskHandle_t readSensorsTaskHandle |
Task handle for reading sensor data.
This handle is used to manage the task responsible for reading data from sensors.
| int sensorOnTopLcdLineID = 0 |
Sensor ID for the sensor displayed on the top line of the LCD menu.
Sensor ID for the top line of the LCD in the sensor menu.
This variable holds the ID of the sensor that will be displayed on the top line of the LCD when the menu is shown.
This variable specifies which sensor will be displayed on the top line of the LCD when the sensor menu is shown.
| QueueHandle_t sensorQueue |
Queue handle for managing sensor data.
This handle represents a queue used to pass sensor data between tasks.
| SensorInfo sensorValues[6] |
Array of sensor information.
Stores sensor info for all sensors.
This array stores information about all available sensors, including their IDs, names, and current values.
This array holds the information for each sensor including ID, name, current value, alarm trigger function, and alarm status.
| hw_timer_t* timer50Hz = NULL |
Timer used for scheduling tasks at 50Hz.
This pointer represents a hardware timer configured to trigger at a 50Hz frequency.