Project introduction
With the rapid development of Internet of Things technology and the growing demand for smart homes, intelligent applications based on embedded systems and cloud platforms are receiving increasing attention. This project aims to use XIAO ESP32S3 microcontroller combined with Alibaba Cloud platform to realize a camera that can automatically collect pictures, identify whether there is a hungry cat, and upload the identification results to Alibaba Cloud IoT platform. At the same time, users can issue switch commands through the cloud interface to achieve remote feeding of pets.
Function introduction
1. Camera picture acquisition: The project uses a camera module OV2640 with ESP32S3 microprocessor, which takes photos at regular intervals of 1s by programming control of the camera to ensure that it can capture clear pictures.
2. Cat recognition: The model that can recognize cats is trained by the deep learning algorithm and integrated into ESP32s3. When the camera collects pictures, the model will analyze the picture to judge whether there are cats in the picture, and report the recognition results to the Aliyun Internet of Things platform through mqtt.
3. Cloud upload and storage: The ESP32s3 uploads the recognition results to the Alibaba Cloud platform through a WiFi network. Alibaba Cloud provides stable and reliable storage services, ensuring that users can view historical recognition records at any time.
4. Cloud Recognition Results Viewing: Users can view the current cat recognition results in the remote cloud.
5. Remote Control Function: In addition to viewing the identification results, users can also remotely set the switch state of the feeder machine. After receiving the instruction from ESP32s3, the device will be operated accordingly through relay or other control modules, thereby realizing remote feeding for pets
Design ideas
1. Camera picture acquisition: Use Arduino programming to control the camera module, set appropriate shooting parameters (such as resolution, frame rate, etc.), and ensure that clear pictures are collected.
2. Cat Identification: A neural network classification model is trained on the Edgeimpulse platform and deployed to ESP32s3. When a camera takes an image, the model classifies the image to determine whether there is a cat in the current captured image.
3. Cloud upload and storage: Using the WiFi function of ESP32s3, the recognition results of the current collected pictures are uploaded to the Alibaba Cloud platform. The corresponding storage service is created on the Alibaba Cloud to ensure the security and reliability of data.
4. Cloud Recognition Results Viewing: Users can remotely view the recognition results of pictures taken by cameras.
5. Remote control function: Provide device control options, allowing users to set the switch state of smart devices. When a user issues a command, the server forwards the command to ESP32s3 through mqtt protocol, and the device side operates the device through the corresponding control module.
Software flow chart
Hardware introduction
The project is based on Seeed Studio XIAO ESP32S3 Sense. The platform integrates camera sensor, digital microphone and SD card support. Combined with the embedded ML computing power and camera capability, it can conveniently realize visual AI applications. It adopts a high-integration Xtensa processor ESP32-S3R8 SoC, which supports 2.4GHz WiFi and low-power Bluetooth® BLE 5.0 dual mode for multiple wireless applications. And has lithium battery charging management function. As an advanced version of Seeed Studio XIAO ESP32S3, the board features a plug-and-play OV2640 camera sensor that displays full resolution of 1600*1200. Its base is also compatible with OV5640, which supports up to 2592*1944 resolution. The board is also equipped with a digital microphone for voice sensing and audio recognition. XIAO ESP32S3 Sense can also run various pre-trained artificial intelligence (AI) models. The development board has a powerful SoC and built-in sensors, with 8MB PSRAM and 8MB FLASH on the chip, in addition to an SD card slot that can support up to 32GB of FAT storage space. These provide the development board with more programming space, bringing more possibilities for embedded ML application scenarios.
Function and picture display
Internet of things data model
Detect the cat and upload to the cloud
Remote control
Major code snippets and description
wifi connection
void setupWifi()
{
delay(10);
Serial.println("连接WIFI");
WiFi.begin(WIFI_SSID, WIFI_PASSWD);
while (!WiFi.isConnected())
{
Serial.print(".");
delay(500);
}
Serial.println("OK");
Serial.println("Wifi连接成功");
}
system init
void setup()
{
Serial.begin(115200);
pinMode(LED_GPIO_NUM, OUTPUT);
while (!Serial);
Serial.println("Edge Impulse Inferencing Demo");
if (ei_camera_init() == false) {
ei_printf("Failed to initialize Camera!\r\n");
}
else {
ei_printf("Camera initialized\r\n");
}
setupWifi();
AliyunIoTSDK::begin(espClient, PRODUCT_KEY, DEVICE_NAME, DEVICE_SECRET, REGION_ID);
// 绑定属性回调
AliyunIoTSDK::bindData("LEDSwitch", SwitchCallback);
}
detect cat
void detect_cat(void)
{
snapshot_buf = (uint8_t*)malloc(EI_CAMERA_RAW_FRAME_BUFFER_COLS * EI_CAMERA_RAW_FRAME_BUFFER_ROWS * EI_CAMERA_FRAME_BYTE_SIZE);
// check if allocation was successful
if(snapshot_buf == nullptr) {
ei_printf("ERR: Failed to allocate snapshot buffer!\n");
return;
}
ei::signal_t signal;
signal.total_length = EI_CLASSIFIER_INPUT_WIDTH * EI_CLASSIFIER_INPUT_HEIGHT;
signal.get_data = &ei_camera_get_data;
if (ei_camera_capture((size_t)EI_CLASSIFIER_INPUT_WIDTH, (size_t)EI_CLASSIFIER_INPUT_HEIGHT, snapshot_buf) == false) {
ei_printf("Failed to capture image\r\n");
free(snapshot_buf);
return;
}
// Run the classifier
ei_impulse_result_t result = { 0 };
EI_IMPULSE_ERROR err = run_classifier(&signal, &result, debug_nn);
if (err != EI_IMPULSE_OK) {
ei_printf("ERR: Failed to run classifier (%d)\n", err);
return;
}
// print the predictions
ei_printf("Predictions (DSP: %d ms., Classification: %d ms., Anomaly: %d ms.): \n",
result.timing.dsp, result.timing.classification, result.timing.anomaly);
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
ei_printf(" %s: %.5f\n", result.classification[ix].label,result.classification[ix].value);
}
if(result.classification[0].value < result.classification[1].value)//检测到猫咪
{
cat_detected = 0;
}else{
cat_detected = 1;
}
#if EI_CLASSIFIER_HAS_ANOMALY == 1
ei_printf(" anomaly score: %.3f\n", result.anomaly);
#endif
free(snapshot_buf);
}
switch control
void SwitchCallback(JsonVariant p)
{
int LEDSwitch = p["LEDSwitch"];
if (LEDSwitch == 1)
{
Serial.println("LED_ON");
digitalWrite(LED_GPIO_NUM, LOW);
}
else
{
Serial.println("LED_OFF");
digitalWrite(LED_GPIO_NUM, HIGH);
}
}
loop function
void loop()
{
//检测有没有断线
if (!WiFi.isConnected()) //先看WIFI是否还在连接
{
setupWifi();
}
else //如果WIFI连接了,
{
if (millis() - lastMsMain >= 1000)
{
lastMsMain = millis();
detect_cat();
// // 发送事件到阿里云平台 {"id": "123","version": "1.0","params": {},"method": "thing.event.xxx.post"}
// AliyunIoTSDK::sendEvent("xxx");
// 发送模型属性到阿里云平台
AliyunIoTSDK::send("GateState", cat_detected);
}
}
AliyunIoTSDK::loop();
}
Comments
Please log in or sign up to comment.