Baby Monitoring System
Loading...
Searching...
No Matches
BabySide.c File Reference

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.
 

Detailed Description

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.

Authors
Caitlyn Rawlings, Hao Tian
Date
2024-08-12

Macro Definition Documentation

◆ BUZZER_PIN

#define BUZZER_PIN   9

Buzzer pin.

◆ DHT_PIN

#define DHT_PIN   6

Pin for temperature/humidity sensor.

◆ GO_DOWN

#define GO_DOWN ( y)    ((y) == 4095)

Check if joystick is moved down.

◆ GO_LEFT

#define GO_LEFT ( x)    ((x) < 300)

Check if joystick is moved left.

◆ GO_UP

#define GO_UP ( y)    ((y) < 400)

Check if joystick is moved up.

◆ LIGHT_PIN

#define LIGHT_PIN   2

Light level sensor.

◆ MOTION_PIN

#define MOTION_PIN   7

Motion detector.

◆ NUM_SENSORS

#define NUM_SENSORS   6

Number of sensors getting input from.

◆ SOUND_ANA_PIN

#define SOUND_ANA_PIN   3

Sound detector.

◆ SW_PIN

#define SW_PIN   17

Joystick switch pin.

◆ WATER_PIN

#define WATER_PIN   1

Water detector.

◆ X_PIN

#define X_PIN   13

Joystick X-axis pin.

◆ Y_PIN

#define Y_PIN   14

Joystick Y-axis pin.

Enumeration Type Documentation

◆ lcdView

enum lcdView

Defines the possible LCD view options.

Enumerator
MENU 

Menu view that displays all the sensor names.

Menu displays sensor and song options.

SENSOR_VIEW 

Sensor view that shows details of a single sensor and its value.

View of one sensor and its value.

◆ sensorIDs

enum sensorIDs

Defines sensor IDs for different sensors.

Enumerator
NOISE 

ID for the noise sensor.

Sensor ID for noise detection.

TEMP 

ID for the temperature sensor.

Sensor ID for temperature measurement.

HUMIDITY 

ID for the humidity sensor.

Sensor ID for humidity measurement.

MOTION 

ID for the motion sensor.

Sensor ID for motion detection.

WATER 

ID for the water level sensor.

Sensor ID for water detection.

LIGHT 

ID for the light level sensor.

Sensor ID for light measurement.

Function Documentation

◆ debounce()

bool debounce ( int * lastInputTime)

Checks if the specified debounce interval has passed since the last recorded input time.

Parameters
lastInputTimePointer to the last input time.
Returns
True if sufficient time has elapsed, otherwise false.

◆ dht()

Bonezegei_DHT11 dht ( DHT_PIN )

◆ lcd()

LiquidCrystal_I2C lcd ( 0x27 ,
16 ,
2  )

◆ lcdDisplayTask()

void lcdDisplayTask ( void * arg)

FreeRTOS task that handles LCD display.

FreeRTOS task that handles LCD display updates.

Parameters
argTask 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.

Parameters
argPointer to task argument (unused).

◆ loop()

void loop ( )

◆ moveCursor()

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.

◆ onDataReceived()

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.

Parameters
macMAC address of the sender.
incomingDataPointer to the incoming data.
lenLength of the incoming data.

◆ onDataSent()

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.

Parameters
mac_addrMAC address of the recipient.
statusStatus of the send operation.
mac_addrPointer to the MAC address of the recipient.
statusStatus of the send operation.

◆ onTimer50Hz()

void IRAM_ATTR onTimer50Hz ( )

ISR for Timer. Triggers playSongTask to run.

◆ playSongTask()

void playSongTask ( void * arg)

FreeRTOS task that plays a song if instructed to by the parent board.

Parameters
argTask argument (unused).

◆ printMenu()

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.

◆ printSensorPreviews()

void printSensorPreviews ( )

Prints two sensor names to the LCD.

This function retrieves and displays the names of two sensors on the LCD.

◆ printSensorView()

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.

◆ processSensorInfoTask()

void processSensorInfoTask ( void * arg)

FreeRTOS task that processes data from the queue and sends it to the parent board.

Parameters
argTask argument (unused).

◆ readSensorsTask()

void readSensorsTask ( void * arg)

FreeRTOS task that updates sensor values and sends them to the queue.

Parameters
argTask argument (unused).

◆ setup()

void setup ( )

Variable Documentation

◆ broadcastAddress

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.

◆ currLcdView

enum lcdView currLcdView = MENU

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.

◆ cursorLine

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.

◆ incomingMessage

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.

◆ lastSwInputTime

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.

◆ lastXInputTime

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.

◆ lastYInputTime

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.

◆ lcdDisplayTaskHandle

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.

◆ messageReceived

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.

◆ playSongTaskHandle

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.

◆ processSensorInfoTaskHandle

TaskHandle_t processSensorInfoTaskHandle

Task handle for processing sensor information.

This handle is used to manage the task responsible for processing and managing sensor information.

◆ readSensorsTaskHandle

TaskHandle_t readSensorsTaskHandle

Task handle for reading sensor data.

This handle is used to manage the task responsible for reading data from sensors.

◆ sensorOnTopLcdLineID

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.

◆ sensorQueue

QueueHandle_t sensorQueue

Queue handle for managing sensor data.

This handle represents a queue used to pass sensor data between tasks.

◆ sensorValues

SensorInfo sensorValues[6]
Initial value:
= {
{NOISE, "Noise level", 0},
{TEMP, "Temperature", 0},
{HUMIDITY, "Humidity", 0},
{MOTION, "Motion", 0},
{WATER, "Water level", 0},
{LIGHT, "Light level", 0}
}
@ MOTION
ID for the motion sensor.
Definition BabySide.c:78
@ TEMP
ID for the temperature sensor.
Definition BabySide.c:78
@ WATER
ID for the water level sensor.
Definition BabySide.c:78
@ NOISE
ID for the noise sensor.
Definition BabySide.c:78
@ LIGHT
ID for the light level sensor.
Definition BabySide.c:78
@ HUMIDITY
ID for the humidity sensor.
Definition BabySide.c:78

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.

◆ timer50Hz

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.