{"id":19236554,"url":"https://github.com/xddcore/sleeppanda","last_synced_at":"2026-03-17T13:41:01.224Z","repository":{"id":65387079,"uuid":"589616441","full_name":"xddcore/SleepPanda","owner":"xddcore","description":"SleepPanda, a caring sleep manager","archived":false,"fork":false,"pushed_at":"2023-05-05T07:03:14.000Z","size":282084,"stargazers_count":10,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T05:42:21.179Z","etag":null,"topics":["cpp","linux","nerual-network","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xddcore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-16T14:39:24.000Z","updated_at":"2024-04-05T06:50:50.000Z","dependencies_parsed_at":"2024-11-09T16:35:41.991Z","dependency_job_id":null,"html_url":"https://github.com/xddcore/SleepPanda","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/xddcore/SleepPanda","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xddcore%2FSleepPanda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xddcore%2FSleepPanda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xddcore%2FSleepPanda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xddcore%2FSleepPanda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xddcore","download_url":"https://codeload.github.com/xddcore/SleepPanda/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xddcore%2FSleepPanda/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263802583,"owners_count":23513864,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","linux","nerual-network","raspberry-pi"],"created_at":"2024-11-09T16:21:24.496Z","updated_at":"2026-03-17T13:40:56.197Z","avatar_url":"https://github.com/xddcore.png","language":"C++","readme":"\u003c!--\n * @Author: Chengsen Dong 1034029664@qq.com\n * @Date: 2023-01-18 00:44:11\n\u003c\u003c\u003c\u003c\u003c\u003c\u003c HEAD\n * @LastEditors: Chengsen Dong 1034029664@qq.com\n * @LastEditTime: 2023-04-19 09:13:35\n=======\n * @LastEditors: Chengsen Dong 1034029664@qq.com\n * @LastEditTime: 2023-02-15 16:27:55\n\u003e\u003e\u003e\u003e\u003e\u003e\u003e 249ff8955d897cad0304e78fe3cb63d7f345510c\n * @FilePath: /SleepPanda/README.md\n * @Description: \n * Copyright (c) 2023 by Chengsen Dong 1034029664@qq.com(www.github.com/xddcore), All Rights Reserved. \n--\u003e\n# SleepPanda, a caring sleep manager\n\n![Logo](./img/Sleep_Panda_LOGO.png)\n\n[![Open Source Love](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/ )\n\n![GPL V3 License](https://img.shields.io/github/license/xddcore/SleepPanda)\n\n![Youtube](https://img.shields.io/youtube/channel/subscribers/UCP2-6ywKLy2js1dzJQ5hR_g?style=social)\n\n\u003e[Click me to visit the Youtube channel](https://www.youtube.com/@SleepPanda666)    \n\u003e[Click me to visit the Facebook Account](https://www.facebook.com/profile.php?id=100090653119559)    \n\u003e[Click me to visit the Instagram Account](https://instagram.com/sleeppandapanda?igshid=ZDdkNTZiNTM=)    \n\u003e[Click me to visit the Twitter Account](https://twitter.com/SleepPanda32?t=1ddNsPfxyXBGGOhH1Kmxfg\u0026s=09)    \n\u003e[Click me to visit the TikTok Account](https://www.tiktok.com/@sleeppanda32?_t=8bIzVLx8Wd4\u0026_r=1)    \n\nChange README Language: [English](./README.md) ｜ [Chinese](./README_ZH.md)\n\n## Auto Unit Test\n| Source | Status |\n| ---- | ---- |\n| helloworld.cpp | ![Helloworld cpp test](https://img.shields.io/github/actions/workflow/status/xddcore/SleepPanda/helloworld_action.yml) |\n| rpi4b-qemu-env | ![rpi4b-qemu-env](https://img.shields.io/github/actions/workflow/status/xddcore/SleepPanda/rpi4b-qemu_action.yml) |\n| . | . |\n| . | . |\n\n\n## Project Description\nSleepPanda is a sleep monitoring system based on Raspberry Pi 4b (bcm2711). SleepPanda uses a variety of sensors to collect sleep data of users, ~~and analyzes and processes the data through dsp, convolutional neural network and other algorithms.~~ Finally, the data processing results are presented to users in various ways.\n\n## Project Features\n1. Heart rate, blood oxygen monitoring\n2. Sleep position monitoring\n3. Early warning of apnea syndrome\n4. Alarm threshold setting\n\n## Project Contributors\n| Name | ID | Role |\n| ---- | ---- | ---- |\n| Chengsen Dong | 2789825d | Embedded Engineer |\n| Rui Liu | 2756138L | Project Management \u0026 Publicity \u0026 Software Engineer |\n| Hui Wang | 2810919W | Hardware Engineer \u0026 Test Engineer |\n| Yihan Wang | 2696441W | Software Engineer |\n\u003e If you have any suggestions for this project, please email to xddcore@gmail.com\n\n## DEMO\n![SleepPanda Demo Video](./img/SleepPanda_Demo_Video.gif)\n\u003cp align=\"center\"\u003eSleepPanda Demo Video\u003c/p\u003e  \n\n## Project Development Planning\n\n\u003e[Click here to view the minutes of the development meeting](./doc/meeting/)  \n\u003e[Click me to visit the Gantt chart](./doc/project%20management/)\n\n#### Global\n- [x] Build the Github warehouse \u0026 README document, complete the basic development environment configuration, fix the Linux kernel source code, and test the compilation of the kernel module.\n- [x] build dev branch\n- [x] Buy all hardware (except touchscreen)\n- [x] Pitch Session PPT slide draft\n- [x] Final draft of Pitch Session PPT slides\n- [x] 14:20:00, 25/01/2023 Pitch Session\n\n#### Chengsen Dong\n- [x] Update the README document (synchronized with the development process)\n- [x] Buzzer driver development\n- [x] MAX30101 driver development\n- [x] 4K 30FPS camera (opencv c++ framework)\n- [x] Touch screen (QT-based GUI) development \u0026 top-level C++ logic\n- [x] Check memory management and memory leaks (using STL to manage memory)\n\n#### Yihan Wang\n- [x] Synchronously update the contents of README_ZH.md \u0026 README.md (once a week)\n- [x] Simultaneous updates of the minutesmeeting (once a week)\n- [x] Creation of a Youtube channel to promote the SleepPanda project\n- [x] Pitch Session PPT slide draft\n- [x] Make cost accounting \u0026 original row selection Excel table\n- [x] Sound Sensor Driver Development\n- [x] WM8960 driver development (low priority)\n- [ ] To do later...\n\n#### Rui Liu\n- [x] Synchronously update the contents of README_ZH.md \u0026 README.md (once a week)\n- [x] Simultaneous updates of the minutesmeeting (once a week)\n- [x] Create Gantt charts to organise tasks according to the classification of people\n- [x] Design SleepPanda Logo\n- [x] Pitch Session PPT slide final draft \u0026 pitch session speech preparation\n- [x] Make cost accounting \u0026 original row selection Excel table\n- [x] ink screen driver development (virtual zoo)\n- [ ] To do later...\n\n#### Hui Wang\n- [x] Query the data sheets of all sensors/chips and upload them to the github repository\n- [x] MLX90640 driver development\n- [ ] To do later...\n\n# guide\n\n## 1. System deployment\n\n### 1.1 Software and hardware version\n\n0. **C++11 Standard Template Library**\n1. Raspberry Pi 4B (4GB/8GB)｜bcm2711\n2. Linux distribution: Ubuntu Desktop 22.04.01 LTS (64Bit)\n3. Kernel version: 5.15.0-1023-raspi | Retrieve all Linux kernel `apt-cache search linux-raspi-headers`\n4. g++: `g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0`\n5. gcc: `gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0`\n6. Unit Test Framework: Google Test + ctest\n\n### 1.2 Separate Raspberry Pi from keyboard, mouse \u0026 monitor\n0. Software that needs to be installed on a Windows computer: `1.Termius (for SSH)` `2.Microsoft Remote Desktop (for remote desktop) 3.Visual Studio code (universal editor)`\n1. Use Raspberry Pi Image to burn the image to SD card (ubuntu image: `https://ubuntu.com/raspberry-pi/desktop`)\n2. Use an external monitor, keyboard and mouse to complete the initialization of ubuntu. The system language is English, the created user name is `ubuntu`, and the password is `ubuntu`.\n3. Packages to be installed: ssh vim gcc g++ screen htop git make\n```\nsudo apt-get update\nsudo apt-get upgrade\nsudo apt-get install ssh vim gcc g++ screen htop git make\n```\n\u003eNote: Note that the `sudo apt-get upgrade` command will upgrade the kernel to the latest version by default, please manually keep the kernel version to 5.15.0-1023-raspi\n4. Open ubuntu remote desktop: Setting-share-open remote desktop-change username and password to `ubuntu`\n\n    4.1 Allow hdmi hot plugging to avoid inability to access remote desktop when hdmi is not plugged in. | `Unresolved! ! ! `|Try to use HDMI dummy load to resolve\n    Enter the following command: `sudo vim /boot/firmware/config.txt`, and add the following content to the config.txt file:\n    ```\n    [hdmi]\n    #allow remote desktop when no hdmi wire\n    hdmi_force_hotplug=1\n    hdmi_drive=2\n    ```\n    4.2 Fix the remote desktop login password to prevent the password from being randomly generated after each restart and unable to access the remote desktop\n    Application-password\u0026keys-default key\u0026login-change password-do not set a password (leave blank)-finally cancel encryption\n    4.3 Use the Microsoft Remote Desktop software to access the Raspberry Pi desktop | Raspberry Pi's LAN IP + user name and password are `ubuntu`\n    \u003eHow to get Raspberry Pi IP: 1. If it is under the same router, it can be obtained by accessing the background of the router. 2. If you cannot access the router backend, obtain the Raspberry Pi’s LAN IP through `arp -a(windows)` and other methods.\n\n5. Prevent Raspberry Pi from sleeping: Setting-Power-Nerver sleep\n6. At this point, the Raspberry Pi is completely separated from the keyboard, mouse and monitor, and can be operated remotely by other computers\n7. Use Termius software to SSH to connect to the LAN IP of the Raspberry Pi. Username: `ubuntu` Password: `ubuntu`\n\n### 1.3 Take the Raspberry Pi off the keypad \u0026 monitor (For Raspberry Pi OS)\n\n0. Software to be installed on your Windows PC: `1.Termius (for SSH)` `2.VNC Viewer (for remote desktop, download link https://www.realvnc.com/en/connect/download/viewer/)` `3.Visual Studio code (Universal Editor)` `Raspberry Pi Image (image burning) ` `5.Github Desktop(Optional)`\n1. Burn the `Raspberry Pi OS(32bit)` image to the SD card using Raspberry Pi Image (Raspberry Pi OS image:`https://www.raspberrypi.com/software/operating-systems/`)\n\u003eBefore burning, click on the gear button in the bottom right hand corner to configure the following:\n\u003e 1. check Set hostname -\u003e raspberrypi.local\n\u003e 2. check Enable SSH service -\u003e Login with password\n\u003e 3. Check Set username and password -\u003e Username: pi | Password: pi\n\u003e 4. Click Save\n2. Connect the Raspberry Pi to the power supply and start the Raspberry Pi. Wait for a while and then connect to the Raspberry Pi via SSH with `termius` software. \n3. Enter the `sudo raspi-config` command and use the **direction keys** to configure the following:\n\u003e 1. Set the boot option to automatically log into the desktop. `System Options -\u003e Boot/Auto Login -\u003e Desktop Autologin`\n\u003e 2. Open VNC Remote Desktop. `Interface Options -\u003e VNC -\u003e YES` \n\u003e 3. Open the SPI port. ` Interface Options -\u003e SPI -\u003e YES` \n\u003e 4. Open the IIC port. `Interface Options -\u003e I2C -\u003e YES` \n\u003e 5. Select Finish to save the settings. \n4. Enter the `reboot` command to reboot the Raspberry Pi. (Wait a while after performing this step) \n5. At this point, the Raspberry Pi is ready to be accessed via `VNC Viewer` remote desktop.\n\u003eThe corresponding VNC package on the Raspberry Pi is `realvnc-vnc-server` (Raspberry Pi OS comes with it, no need to install it)\n6. packages to be installed: ssh vim gcc g++ screen htop git make, execute the following command:\n```\nsudo apt-get update\nsudo apt-get upgrade\nsudo apt-get install ssh vim gcc g++ screen htop git make\n```\n4. Enter the `reboot` command to reboot the Raspberry Pi. At this point, the basic environment configuration is complete.\n\n### 1.4 Build cross-compilation environment \u0026 local compilation environment\nConsidering that the computing power of the Raspberry Pi is insufficient, using a server will significantly improve compilation efficiency, version control, code backup, and collaborative work. We use a centralized server (`I9-12900k+RTX3090TI+32GB DDR4+512G SSD`) during the development of this project, and build a cross-compilation environment in the server.\n\n#### 1.4.1 Cross-compilation environment (server)\n\n1. Install the aarch64-linux-gnu-cross-compilation toolchain, and other compilation tools required to compile the linux kernel\n2. Get the Raspberry Pi kernel source code\n```\napt-get source linux-image-$(uname -r) #5.15.0-1023-raspi\n```\n3. Compile the kernel source code\n\u003eRef: https://www.raspberrypi.com/documentation/computers/linux_kernel.html\n4. Compile `helloworld` module code\n5. Test the `helloworld` module\n\n![helloworld_modinfo](./img/helloworld_modinfo.png)\n\n#### 1.4.2 Local compilation environment (Raspberry Pi)\n\n1. Compile `helloworld` module code\n\n```\nmake -C /usr/src/linux-headers-5.15.0-1023-raspi/ M=`pwd` modules\n```\n2. Test the `helloworld` module\n\u003eTest result same as above\n\n---\n\nQ1: The module is not signed problem:\nIt looks like your system vendor has enabled kernel module signature verification on your kernel, which means it won't load any modules that the vendor hasn't signed. In other words, your patched module is not (correctly) signed and the kernel will refuse to load it.\n\u003e Solution: cmd run `CONFIG_MODULE_SIG=n`\n\nQ2: When `sudo apt-get upgrade` is executed, some packs (such as the linux kernel) are reserved and cannot be upgraded.\n\u003e `sudo apt-get --with-new-pkgs upgrade`\n\n\n### 1.5 Sensors \u0026 Actuators \u0026 Servers\n\n\u003e[Click me to download BOM](./doc/BOM/SleepPanda_BOM.xlsx)\n\n\u003e[Click me to download datasheet](./doc/datasheet/)\n\n**sensor**\n1. Speaker \u0026 Microphone: WM8960(Control:IIC;Audio:IIS)+Sound Sensor(Voltage Comparator Dout)-✅\n2. Body temperature (thermal imaging) \u0026 gesture control: MLX90640(IIC)-✅\n3. Heart rate \u0026 blood oxygen: MAX30101(IIC)-✅\n4. Sleeping position monitoring: 4K 30FPS camera (USB+OpenCV)-✅\n\n**Actuator**\n1. Ink Screen:SSD1608(Virtual Zoo) (SPI)-✅\n2. Touch screen (QT-based GUI) (Video: HDMI, Touch: USB)\n3. Buzzer: Emergency abnormal alarm (High/Low Pin Level)-✅\n\n**other**\n\n1. Several DuPont lines-✅\n\n\n**server**\nFacing the world, it is responsible for storing user data and undertaking visits/animal exchanges between virtual zoos.\n\n\n## 2. System development\n\n### 2.1 Get the source code of SleepPanda\n\n`git clone https://github.com/xddcore/SleepPanda.git`\n\n**Note: If you are a developer, remember to switch to the dev branch with the following command:**\n```\ngit checkout dev\ngit branch -l\n```\n\n### 2.2 cpp unit testing framework\n\n#### 2.2.1 cppunit\n\n```\n#install cppunit-lib\nsudo apt install -y libcppunit-dev\n```\n\u003e#include \u003ccppunit/TestRunner.h\u003e\n\n\u003e because:\n\u003e1. Google test is relatively simple to use. Writing a test case does not need to be divided into two parts: declaration and definition, and there is no need to register the test suite yourself.\n\u003e2. The assert of google test is richer\n\u003e So this project uses google test (gtest) for unit testing\n\n#### 2.2.2 google test(gtest)\n##### 2.2.2.1 Directly load the compiled dynamic link library file\n\n###### 2.2.2.1.1 For Ubuntu Desktop 22.04 64bit\n\ngtest dynamic link library path `SleepPanda/tools/gtest/lib/`, gtest header file path `SleepPanda/tools/gtest/include/`\n\n```\n# g++ build demo\n\n# cd to workscape\ncd /SleepPanda/src/app/gtest_demo\n\n# build code\ng++ -std=c++14 ./gtest_demo.cpp -I ../../../tools/gtest/include/ ../../../tools/gtest/lib/libgtest.so -lpthread -o gtest_demo\n\n# Export the gtest dynamic link library to the system environment variable (temporary)\nexport LD_LIBRARY_PATH=../../../tools/gtest/lib/:$LD_LIBRARY_PATH\n\n# run gtest demo\n./gtest_demo\n```\n\n###### 2.2.2.1.2 For Raspberry Pi OS 32bit**\n\ngtest dynamic link library path`SleepPanda/tools/gtest/rpios_32bit/lib/`\ngtest header file path`SleepPanda/tools/gtest/rpios_32bit/include/`\n\n* Compile using g++ (choose one of the two compilation methods, or try both)\n```\n# g++ build demo\n\n# cd to workscape\ncd ./SleepPanda/src/app/gtest_demo\n\n# build code\ng++ -std=c++14 ./gtest_demo.cpp -I ../../../tools/gtest/rpios_32bit/include/ ../../../tools/gtest/rpios_32bit/lib/libgtest.so -lpthread -o gtest_demo\n\n# Export the gtest dynamic link library to the system environment variable (temporary)\nexport LD_LIBRARY_PATH=../../../tools/gtest/rpios_32bit/lib/:$LD_LIBRARY_PATH\n\n# run gtest demo\n./gtest_demo\n```\n\n* Compile with cmake (choose one of the two compilation methods, or try both)\n```\n# g++ build demo\n\n# cd to workscape\ncd ./SleepPanda/src/app/gtest_demo/build\n\n# build code\ncmake .. \u0026\u0026 make\n\n# Export the gtest dynamic link library to the system environment variable (temporary)\nexport LD_LIBRARY_PATH=../../../tools/gtest/rpios_32bit/lib/:$LD_LIBRARY_PATH\n\n# run gtest demo\n./gtest_demo\n```\n**Error: When compiling with cmake, the following error may occur:**\n```\nCMake Error: The source \"/home/pi/xddcore/SleepPanda/src/app/gtest_demo/CMakeLists.txt\" does not match the source \"/home/ubuntu/xddcore/SleepPanda/src/app/gtest_demo/CMakeLists.txt\" used to generate cache.  Re-run cmake with a different source directory.\n```\n**Solution:**\n```\n# remove /build dir\nrm -rf build/\n\n# create new /build dir\nmkdir build\n\n# go to build dir\ncd build\n\n# build code\ncmake .. \u0026\u0026 make\n\n# run gtest demo code\ncd .. \u0026\u0026 ./gtest_demo\n\n```\n\nTheoretically, you will get the following running result:\n```\n./gtest_demo\n[==========] Running 2 tests from 1 test suite.\n[----------] Global test environment set-up.\n[----------] 2 tests from FooTest\n[ RUN      ] FooTest.test_add\n[       OK ] FooTest.test_add (0 ms)\n[ RUN      ] FooTest.test_minus\n./gtest_demo.cpp:54: Failure\nExpected equality of these values:\n  foo-\u003eGetNum()\n    Which is: 1\n  0\n[  FAILED  ] FooTest.test_minus (0 ms)\n[----------] 2 tests from FooTest (1 ms total)\n\n[----------] Global test environment tear-down\n[==========] 2 tests from 1 test suite ran. (2 ms total)\n[  PASSED  ] 1 test.\n[  FAILED  ] 1 test, listed below:\n[  FAILED  ] FooTest.test_minus\n```\n\n##### 2.2.2.2 Compile the dynamic link library file by yourself through the google test source code\n```\n# install dependencies\nsudo apt-get install cmake\n\n# install google test lib\n\n# get source\ngit clone https://github.com/google/googletest.git\n\n#build\ncd googletest\nmkdir build\ncd build\ncmake -DCMAKE_INSTALL_PREFIX=`pwd`/install -DBUILD_SHARED_LIBS=ON ..\nmake -j8\nmake install\n\n# Then the corresponding dynamic library of gtest will be generated in the build/install directory\nls install /\n# include lib\n\n```\n\n### 2.3 Hardware Architecture\n\n![Hardware_Architecture](./img/Hardware_Architecture.png)\n\n\u003eRef:https://abyz.me.uk/rpi/pigpio/index.html\n\n\u003e If you want to query GPIO more quickly, you can visit the following URL: https://pinout.xyz/pinout/\n\n![Pigpio-Rpi-PinMap](./img/pigpio_rpi_pinmap.jpeg)\n\n### 2.4 Software Architecture\n\n![Software_Architecture](./img/Software_Architecture.png) \n\n|Index| Layer|-|Comments|\n|:----:|:----:|:----:|:----:|\n|7(Top)|GUI Interface Layer(QT)|-|Interaction with users|\n|6|C++ Logic Layer|-|Opencv, TensorFlow Lite, MQTT Client, etc.|\n|5|Hardware Driver Layer (Sensor Class)|-|Configuration/Driver of Hardware (Sensor, etc.)|\n|~~4~~|~~Hardware Isolation Layer (Rpi4b Class)~~|-|~~Isolate software logic and hardware dependencies, the purpose is to run/test the upper layer code independently of the underlying hardware dependencies (such as pigpio).~~|\n|3|Pigpiod Nested Word Communication Process|-|Drive rpi4b(bcm2711) register|\n|2|System Call|-|Provided by the linux kernel|\n|1(Bottom)|Linux Kernel Modules|-|Allocate interrupt|\n\n### 2.5 Sensor \u0026 Actuator Driver Development\n\n\u003eRef:\n\u003e https://berndporr.github.io/realtime_cpp_coding/\n\u003e https://github.com/berndporr/realtime_cpp_coding\n\n**Before you start**, you need to execute the following commands to install the necessary dependencies. Here, I would like to express my sincere thanks to the developers of the pigpio library (https://github.com/joan2937/pigpio).\n\n**How to install Raspberry Pi OS**\n\nRun the following command to install piopig with one click\n\n```\nsudo apt-get install libpigpio-dev\n```\n\n**Other operating system installation methods**\n\n```\napt-get install cmake\n# Download and install latest version(pigpio)\nwget https://github.com/joan2937/pigpio/archive/master.zip\nunzip master.zip\ncd pigpio-master\nmake\nsudo make install\n\n#If the Python part of the install fails it may be because you need the setup tools.\nsudo apt install python-setuptools python3-setuptools\n```\n\nFinally, in order to verify whether pigpio lib is installed correctly, we also **recommend you to run the following test command**:\n```\ncd pigpio-master #(if you are not in this dir)\nsudo ./x_pigpio # check C I/F\n\n# To start the pigpio daemon\nsudo pigpiod\n./x_pigpiod_if2 # check C I/F to daemon\n# Then you should get PASS\n\n# To stop the pigpio daemon\nsudo killall pigpiod\n./x_pigpiod_if2 # check C I/F to daemon\n# Then you should get 'pigpio initialisation failed (-2003).', because pigpio daemon not running.\n```\n\u003eNote: Every time you use pigpio, you should first run `sudo pigpiod` to start the daemon.\n\nTheoretically, you will get the following running result:\n```\nTesting pigpio C I/F\npigpio version 79.\nHardware revision 13644052.\nMode/PUD/read/write tests.\nTEST  1.1  PASS (set mode, get mode: 0)\nTEST  1.2  PASS (set pull up down, read: 1)\nTEST  1.3  PASS (set pull up down, read: 0)\nTEST  1.4  PASS (write, get mode: 1)\nTEST  1.5  PASS (read: 0)\nTEST  1.6  PASS (write, read: 1)\nPWM dutycycle/range/frequency tests.\nTEST  2.1  PASS (set PWM range, set/get PWM frequency: 10)\nTEST  2.2  PASS (get PWM dutycycle: 0)\nTEST  2.3  PASS (set PWM dutycycle, callback: 0)\nTEST  2.4  PASS (get PWM dutycycle: 12\n\n...etc\n```\n\n---\nQ1: ERROR: **initAllocDMAMem: mbox open failed(No such device or address)**\n```\n:~$ sudo pigpiod\nOR\n:~$ ./x_pigpio\nthen get\n:~$ initAllocDMAMem: mbox open failed(No such device or address)\n```\nFixup: Run `sudo modprobe vcio`\nOR\n`./x_pigpio` is a program that uses mailboxes to allocate memory. If under certain conditions (e.g. qemu env), you won't have GPU memory to allocate. pigpio will use the mailbox to allocate DMA memory (unless you request a large buffer). When pigpiod is started with the `-a1` option, page mapping is used to allocate DMA memory.\n```\nsudo pigpiod -a1 #force use PMAP allocate DMA memory\n./x_pigpiod_if2 # check C I/F to daemon\n```\n\nQ2: ERROR: **modprobe: FATAL: Module vcio not found in directory**\n```\n:~$ sudo modprobe vcio\n:~$ modprobe: FATAL: Module vcio not found in directory /lib/modules/5.15.0-1031-azure\n```\nFixup: Run `sudo apt-get install -y linux-modules-extra-$(uname -r)`\nOR\n`You need install Ubuntu Desktop Image, and then you will have vcio(videocore io)`\n\nQ3: ERROR: **initInitialise: Can't lock /var/run/pigpio.pid**\n```\n:~$ sudo ./x_pigpio\n:~$ initInitialise: Can't lock /var/run/pigpio.pid\npigpio initialisation failed.\n```\nFixup: Run `sudo killall pigpiod`\n\nQ4: In the QEMU environment, pigpio cannot be emulated\n```\n2023-01-27 09:02:23 initAllocDMAMem: mbox open failed(No such device or address)\nCan't initialize pigpio library\npigpio initialisation failed (-2003).\n```\nFixup: Because pigpio relies on the BCM2711 chip hardware function to achieve ultra-low-latency DMA operations, and qemu's DMA cannot support this operation, so pigpio simulation cannot be completed in the QEMU environment.\n\n#### 2.5.1 Buzzer\n\u003eAuthor: Chengsen Dong\n\n**Features:**   \nThe module is driven by S8550 transistor.   \nWorking voltage 3.3V-5V.    \nLow level trigger.   \nDesigned with holes for fixing with bolt, so it is easy to assemble.    \nVCC: External 3.3V-5V voltage (can be directly connected with 5V single-chip microcomputer and 3.3V single-chip microcomputer)    \nGND: External GND   \nI/O: External micro-controller IO port   \n\n**Unit Test DEMO**\n\nWhen the unit test program runs:\nIf you hear the buzzer, please use the keyboard to type \"Y\" and press ENTER.\n\nExecute the following command to run unit tests:\n```\n## change to work dir\ncd SleepPanda/src/app/Buzzer/build\n\n# build, and run unit test(gtest)\ncmake .. \u0026\u0026 make \u0026\u0026 sudo ctest --verbose\n```\n\n#### 2.5.2 Sound Sensor\n\u003eAuthor: Yihan Wang\n\n**Specification:**\nWorking Voltage: DC 3.3V-5.5V  \nNominal Frequency: 40KHz  \nPCB Size: 35 x 15mm / 1.38 x 0.59\" (LxW)  \nFixed Hole Diameter: 3mm  \nMain chip:LM393, Electret condenser microphone  \nOutput form: Digital and Analog Output  \n\n**Note:**\nAO outputs real-time voltage signal of the microphone.  \nDO outputs low and high lever signal when the sound intensity reaches a threshold  \nSensitivity is adjustable by adjusting the potentiometer \n\n**Unit Test DEMO**\n\nWhat you will see: Make a sound, the DO pin level of the sound sensor will jump from low level to high level (rising edge interrupt), trigger a sound event, and the screen will print `Rpi_SoundSensor Class DEBUG: SoundSensor_SoundEvent_Handle() was triggered .`. \n\nWhen the unit test program runs:\nMake a sound and press ENTER on your keyboard.\n\nExecute the following command to run unit tests:\n```\n## change to work dir\ncd SleepPanda/src/app/SoundSensor/build\n\n# build, and run unit test(gtest)\ncmake .. \u0026\u0026 make \u0026\u0026 sudo ctest --verbose\n```\n\n#### 2.5.3 MAX30101\n\u003eAuthor:Chengsen Dong\n\n\u003eRef:\n\u003e1. https://github.com/pimoroni/max30105-python\n\u003e2. https://shop.pimoroni.com/products/max30101-breakout-heart-rate-oximeter-smoke-sensor?variant=21482065985619\n\n\u003eNote: Through the `raspi-gpio get` query, it is found that the Interrupt Pin -4 originally planned to be used is occupied by other programs, resulting in the input level being always 0, and the external interrupt function cannot be realized. So will use GPIO6 to connect to INT pin of MAX30101.\n\n**Unit Test DEMO**\n\nExecute the following command to run unit tests:\n```\n## change to work dir\ncd SleepPanda/src/app/MAX30101/build\n\n# build, and run unit test(gtest)\ncmake .. \u0026\u0026 make \u0026\u0026 sudo ctest --verbose\n```\n\nWhat you'll see: Put your fingertip on the MAX30101 sensor, wait 15 seconds, and press the Enter key on your keyboard. Unit testing is complete. The program will output the current heart rate and blood oxygen values. You will get output similar to:\n```\n1: Rpi_MAX30101 Class DEBUG: MAX30101_DataReadyEvent_Handle() was triggered.|heart_rate: 71, spo2: 99.525826\n1: ir_mean: 136982.530000, red_mean: 121904.060000\n1: beta_ir: -4.232085, beta_red: -2.549403\n1: n_last_peak_interval test = GOOD\n1: boundary test = GOOD\n1: Rpi_MAX30101 Class DEBUG: MAX30101_DataReadyEvent_Handle() was triggered.|heart_rate: 78, spo2: 99.414008\n1: ir_mean: 136578.920000, red_mean: 121704.060000\n1: beta_ir: 4.154383, beta_red: 0.232127\n1: n_last_peak_interval test = GOOD\n1: boundary test = GOOD\n1: Rpi_MAX30101 Class DEBUG: MAX30101_DataReadyEvent_Handle() was triggered.|heart_rate: 83, spo2: 99.427597\n1: ir_mean: 137294.050000, red_mean: 121818.950000\n1: beta_ir: 8.709769, beta_red: 1.685311\n1: n_last_peak_interval test = GOOD\n1: boundary test = GOOD\n1: Rpi_MAX30101 Class DEBUG: MAX30101_DataReadyEvent_Handle() was triggered.|heart_rate: 75, spo2: 99.445994\n1: Rpi_MAX30101.ISR_CheckPoint: 1\n1: RPI DEBUG: MAX30101 Delete.\n1: [ OK ] MAX30101_Test.Check_MAX30101_ISR_HeartRate_SPO2 (45287 ms)\n1: [----------] 1 test from MAX30101_Test (45287 ms total)\n1: \n1: [----------] Global test environment tear-down\n1: [==========] 1 test from 1 test suite ran. (45287 ms total)\n1: [ PASSED ] 1 test.\n1/1 Test #1: MAX30101_Test ................... Passed 45.30 sec\n\n100% tests passed, 0 tests failed out of 1\n\nTotal Test time (real) = 45.30 sec\n```\n\n#### 2.5.4 WM8960\n\u003eAuthor:Yihan Wang\n\n\u003eRef:\n\u003e1. https://wiki.seeedstudio.com/ReSpeaker_2_Mics_Pi_HAT/\n\u003e2. https://shop.pimoroni.com/products/respeaker-2-mics-phat?variant=49979573706\n\nAfter using the arecord command that comes with the system, the system Log is as follows:\nApparently, the sound card driver is not supported.\n```\nsudo arecord -D hw:3,0 -d 2 -f cd -c 2 -v -t wav test.wav\n\nRecording WAVE 'test.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo\narecord: set_params:1407: Unable to install hw params:\nACCESS: RW_INTERLEAVED\nFORMAT: S16_LE\nSUBFORMAT: STD\nSAMPLE_BITS: 16\nFRAME_BITS: 32\nCHANNELS: 2\nRATE: 44100\nPERIOD_TIME: (125011 125012)\nPERIOD_SIZE: 5513\nPERIOD_BYTES: 22052\nPERIODS: 4\nBUFFER_TIME: (500045 500046)\nBUFFER_SIZE: 22052\nBUFFER_BYTES: 88208\nTICK_TIME: 0\n```\nsolution:\n\u003e 1. https://github.com/respeaker/seeed-voicecard/pull/323\n\u003e 2. https://github.com/respeaker/seeed-voicecard/issues/326\n\u003e 3. https://github.com/HinTak/seeed-voicecard\n\nExecute the following command (using an unofficial fork to fix bugs):\n```\ngit clone https://github.com/HinTak/seeed-voicecard.git\ncd seen-voicecard\nsudo ./install.sh\nsudo reboot now\n```\n---\n**WM8960 device driver test**\n\nPlayback device:\n```\naplay -l\n**** List of PLAYBACK Hardware Devices ****\ncard 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]\n   Subdevices: 8/8\n   Subdevice #0: subdevice #0\n   Subdevice #1: subdevice #1\n   Subdevice #2: subdevice #2\n   Subdevice #3: subdevice #3\n   Subdevice #4: subdevice #4\n   Subdevice #5: subdevice #5\n   Subdevice #6: subdevice #6\n   Subdevice #7: subdevice #7\ncard 1: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]\n   Subdevices: 1/1\n   Subdevice #0: subdevice #0\ncard 2: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]\n   Subdevices: 1/1\n   Subdevice #0: subdevice #0\ncard 3: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0 [bcm2835-i2s-wm8960-hifi wm8960-hifi-0]\n   Subdevices: 1/1\n   Subdevice #0: subdevice #0\n```\n\nRecording equipment:\n```\narecord -l\n**** List of CAPTURE Hardware Devices ****\ncard 3: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0 [bcm2835-i2s-wm8960-hifi wm8960-hifi-0]\n   Subdevices: 1/1\n   Subdevice #0: subdevice #0\n```\n\n**Recording command**:\n```\narecord -D \"plughw:3,0\" -d 2 -f cd -c 2 -v -t wav test.wav\n```\n\u003e-D specifies the recording device\n-d set recording duration\n-f recording sample format\n-c specifies the channel\n-t file type of recording output\npath and name of test.wav output file\n\n**Play command**:\n```\naplay -D \"plughw:3,0\" test.wav\n```\n\n**Unit Test DEMO**\n\nWhat you will see: WM8960 will record for 3 seconds and create a Record_Wav_File_Test.wav file.\n\nWhen the unit test program runs:\nPlease make a sound/play a song.\n\nExecute the following command to run unit tests:\n```\n## change to work dir\ncd SleepPanda/src/app/WM8960/build\n\n# build, and run unit test(gtest)\ncmake .. \u0026\u0026 make \u0026\u0026 sudo ctest --verbose\n```\n\u003eNote: If the Record_Wav_File_Test.wav file is successfully created, but there is no sound when it is opened and played, please use the `alsamixer` sound card management program to enable the microphone of the WM8960 sound card.\n\n#### 2.5.5 Ink Screen(SSD1608)\n\u003eAuthor:Rui Liu\n\u003eRef:\n\u003e1. https://github.com/pimoroni/inky\n\u003e2. https://shop.pimoroni.com/products/inky-phat?variant=12549254905939\n\n**Features：**\n2.13\" EPD display\nInky pHAT pinout\nCompatible with all 40-pin header Raspberry Pi models\nPython library\nComes fully assembled\n\n**Note：**\nOverall dimensions: 65x30x8.5mm (WxHxD, depth includes header and display)\nDisplay usable area dimensions: 48.5x23.8mm (WxH), 2.13\" diagonal\n\n#### 2.5.6 MLX90640\n\u003eAuthor:Hui Wang\n\n\u003eRef:\n\u003e1. https://github.com/pimoroni/mlx90640-library\n\u003e2. https://shop.pimoroni.com/products/mlx90640-thermal-camera-breakout?variant=12536948654163\n\u003e3. https://blog.csdn.net/duxi222333/article/details/126100446?\n\n**Features：**\nSmall size, low power cells, 32*24 pixel infrared array；\nI2C Compatible Digital Interface；\nProgrammable refresh rate 0.5Hz-60Hz；\nSupply voltage 3.3V；\nCurrent consumption ≤23mA；\nWorking temperature: -45-85°C；\nTemperature range: -40-300°C；\n\n**Pin definition**\nSDA: I²C serial interface data line (input/output)；\nVDD: positive power supply；\nGND: power negative；\nSCL: I²C serial interface clock line (input)；\n\n**notes**\n1. Hardware design considerations: MLX90640 uses 3.3V power supply, and uses the power supply voltage as the reference voltage for temperature measurement, so it has high requirements for power supply stability. The power supply current needs to be able to output 100mA in balance.\n2. Notes on software design: calculate the corresponding functions in the API library for design.\n3. Pay attention to the calculated value of Vdd during operation. If the difference between this value and the actual value exceeds 0.1V, you should check the problem.\n\n\n#### 2.5.7 USB Camera\n\u003eAuthor:Chengsen Dong\n\n##### 2.5.7.1 Install OpenCV\n\n**Step 0:Update GPU Memory**\nBoth CPUs and GPUs use physical RAM chips. On a Raspberry Pi 2 or 3, the GPU is allocated 64 MB by default. The Raspberry Pi 4 has a GPU memory size of 76 MB. It might be a bit small for a visual project, it's best to change it to 128 MB for now. To increase the amount of memory for the GPU, use the following menus:\n\n![Change_GPU_Memory_Size_1](./img/Change_GPU_Memory_Size_1.png)\n![Change_GPU_Memory_Size_2](./img/Change_GPU_Memory_Size_2.png)\n\n\n**Step 1: Download openCV source code**\n```\ngit clone https://github.com/opencv/opencv.git\n```\n\n**Step 2: Install dependency packages**\n```\nsudo apt-get install cmake\nsudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg-dev libswscale-dev libtiff5-dev\nsudo apt-get install libgtk2.0-dev\nsudo apt-get install pkg-config\n```\n\n**Step 3: Compile and install openCV**\n```\n# change to your dir\ncd /home/opencv\n\nmkdir build\ncd build\ncmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local ..\nsudo make\nsudo make install\n```\n\n**Step 4: Configure the OpenCV environment**\n```\ncd /etc/ld.so.conf.d/\nsudo touch opencv4.conf\nsudo sh -c 'echo \"/usr/local/lib\" \u003e opencv4.conf'\n```\n\n**Step 5: Update linker configuration (pkg-config)**\n```\nsudo ldconfig\n```\n\n**Step 6: Copy the opencv.pc file to /usr/lib/pkgconfig/**\n```\nsudo cp -f /usr/local/lib/arm-linux-gnueabihf/pkgconfig/opencv4.pc /usr/lib/pkgconfig/\n```\n\n**Step 7: Add environment variables**\n```\nsudo vim /etc/bash.bashrc\n\n#Add at the end of the file:\nPKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig\nexport PKG_CONFIG_PATH\n```\n\n**Step 8: Test whether the installation is successful**\n```\npkg-config --modversion opencv4\n\n#maybe output: 4.7.0\n```\n\n**Step 9: Test procedure**\n```\n#include \u003copencv2/imgcodecs.hpp\u003e\n#include \u003copencv2/highgui.hpp\u003e\n#include \u003copencv2/imgproc.hpp\u003e\n#include \u003ciostream\u003e\n \nusing namespace cv;\nusing namespace std;\n \nint main()\n{\nMat img(512, 512, CV_8UC3, Scalar(255, 255, 255));\ncircle(img, Point(256, 256), 256, Scalar(0, 0, 255), FILLED);\nRect roi(128, 128, 256, 256);\nrectangle(img, roi, Scalar(255, 255, 255), FILLED);\nline(img, Point(256, 128), Point(256, 256), Scalar(255, 255, 0), 3);\nputText(img, \"I'am CV\", Point(256, 128), FONT_HERSHEY_DUPLEX, 1, Scalar(0, 0, 0), 2);\nimshow(\"img\", img);\nwaitKey(0);\n     return 0;\n}\n```\n\n**Step 10: Compile the test program (SleepPanda/src/app/Camera/OpenCV_Test):**\n```\ng++ OpenCV_Test.cpp -o OpenCV_Test `pkg-config --cflags --libs opencv4`\n```\n```\nsudo ./OpenCV_Test\n```\n\u003eIf an error occurs: ./OpenCV_Test: error while loading shared libraries: libopencv_highgui.so.407: cannot open shared object file: No such file or directory\n\nPlease update the linker configuration with the following command:\n```\nsudo ldconfig\n```\n\n##### 2.5.7.2 Light sleep/deep sleep judgment ideas\n\nCascade Detection: Face \u0026 Profile -\u003e Eyes\n\nWhen a positive face (red circle) is detected at the same time, it means that the user is sleeping. When only the side face (blue circle) is detected, it means the user is sleeping on the side.\nBy measuring the user's state change per unit time (the change frequency of sleeping on the side and sleeping on the side), it is judged whether the user is in deep sleep or light sleep.\n\n```\nwget https://github.com/opencv/opencv/raw/master/data/haarcascades/haarcascades_upperbody.xml\n\nwget https://github.com/opencv/opencv/raw/master/data/haarcascades/haarcascade_profileface.xml\n\nwget https://github.com/opencv/opencv/raw/master/data/haarcascades/haarcascade_frontalface_alt.xml\n\nwget https://github.com/opencv/opencv/raw/master/data/haarcascades/haarcascade_eye_tree_eyeglasses.xml\n```\n\n##### 2.5.7.3 Frame asynchronous (interrupt) implementation ideas\n\n1.\nIt is realized by creating new threads, mutexes, and queues.\nThe worker thread reads the new Frame continuously, and when the new Frame is valid, the main thread is notified to fetch the Frame through the queue.\n\n2.\nUse Qt's QTime class, timeout() event to trigger camera frame reading.\n\u003eCamera FPS=30, the processing speed of the test program is lower than the camera FPS, so it is appropriate to use the QTime class timeout() event.\n\n**Finally use Thread and Callback to achieve frame acquisition**\n\n**Unit Test DEMO**\n\nWhat you will see: The camera image is displayed in real time, the frontal face and eyes are marked with red circles, and the side face and eyes are marked with blue circles.\n\nExecute the following command to run unit tests:\n\u003e**Note**: Make sure you are in a graphical desktop environment. The command line environment cannot display a GUI.\n```\n## change to work dir\ncd SleepPanda/src/app/Camera/build\n\n# build, and run unit test(gtest)\ncmake .. \u0026\u0026 make \u0026\u0026 sudo ctest --verbose\n```\n\nYou will see the following effect:\n![Opencv_Test1](./img/Opencv_Test1.jpeg)\n\u003cp align=\"center\"\u003eSleeping (marked with a red circle)\u003c/p\u003e\n\n![Opencv_Test2](./img/Opencv_Test2.jpeg)\n\u003cp align=\"center\"\u003eSleeping on your side (marked with a blue circle)\u003c/p\u003e\n\n### 2.6 QT\u0026C++ logic development\n\n#### 2.6.1 QT5 and Qwt\n\n**Package required to install QT5**\n```\nsudo apt-get install qtdeclarative5-dev-tools\nsudo apt-get install libqwt-qt5-dev\nsudo apt-get install qtbase5-dev\nsudo apt-get install qtdeclarative5-dev\n```\n\n**Development Record**\n\n\u003e Proudly use pure C++ to write GUI, not using Qt Creator, which will avoid introducing QML.\n\n**Unit Test DEMO**\n\nWhat you will see: The GUI developed with QT5 will be displayed.\n\nExecute the following command to run unit tests:\n```\n## change to work dir\ncd SleepPanda/src/app/Window/build\n\n# build, and run unit test(gtest)\ncmake .. \u0026\u0026 make \u0026\u0026 sudo ctest --verbose\n```\n\u003e**Note**: Make sure you are in a graphical desktop environment. The command line environment cannot display a GUI.\n\nYou will see the following effect:\n![GUI](./img/GUI.jpeg)\n\u003cp align=\"center\"\u003eSleep Panda GUI\u003c/p\u003e\n\n### 2.7 Assemble Unit Code \u0026\u0026 get the final software\nRun the following code to execute the SleepPanda software:\n\u003e**Note**: Make sure you are in a graphical desktop environment. The command line environment cannot display a GUI.\n```\ncd SleepPanda/src/app/build\n\n# Rebuild code\ncmake .. \u0026\u0026 make\n\n# Run SleepPanda\nsudo ./SleepPanda\n```\nYou will get the following result:\n![SleepPanda](./img/SleepPanda_GUI.jpeg)\n\u003cp align=\"center\"\u003eSleepPanda GUI\u003c/p\u003e\n\n### 2.8 So far, all the development work of SleepPanda has been completed, thank you for your efforts! ! !","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxddcore%2Fsleeppanda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxddcore%2Fsleeppanda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxddcore%2Fsleeppanda/lists"}