├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ └── bug-report.yml ├── actions │ ├── action.yml │ └── arduino-test-compile.sh └── workflows │ ├── Arduino-Lint-Check.yml │ ├── arduino-action-core-compile.yml │ └── clang-format-check.yml ├── .gitignore ├── CMakeLists.txt ├── Kconfig ├── LICENSE ├── README.md ├── component.mk ├── docs ├── M-BUS.jpg ├── Power_capabilities.md ├── arduino-ide.png ├── arduino-ide │ ├── debian_ubuntu.md │ ├── fedora.md │ ├── mac.md │ ├── opensuse.md │ ├── win-screenshots │ │ ├── arduino-ide.png │ │ ├── win-gui-1.png │ │ ├── win-gui-2.png │ │ ├── win-gui-3.png │ │ ├── win-gui-4.png │ │ ├── win-gui-5.png │ │ ├── win-gui-update-1.png │ │ └── win-gui-update-2.png │ ├── win-screenshots_cn │ │ ├── FactoryTest_result.png │ │ ├── arduino_cc_package.png │ │ ├── arduino_path.png │ │ ├── arduino_windows_installer.png │ │ ├── clone_esp32_idf.png │ │ ├── clone_esp32_idf_subdir.png │ │ ├── download_idf.png │ │ ├── download_m5stack_lib.png │ │ ├── download_xtensa_tools.png │ │ ├── mkdir_espressif.png │ │ ├── my_com.png │ │ ├── select_arduino_install_path.png │ │ ├── select_arduino_lib.png │ │ ├── select_board_and_com.png │ │ ├── select_demo.png │ │ └── select_get_exe_file.png │ └── windows.md ├── esp-idf_component.md ├── getting_started_cn.md ├── getting_started_ja.md ├── make.md └── platformio.md ├── examples ├── Advanced │ ├── Audio │ │ ├── PlayMP3FromSDToDAC │ │ │ └── PlayMP3FromSDToDAC.ino │ │ ├── PlayMP3FromSPIFFSToDAC │ │ │ ├── PlayMP3FromSPIFFSToDAC.ino │ │ │ └── data │ │ │ │ └── pno-cs.mp3 │ │ └── PlayWAVFromSDToDAC │ │ │ └── PlayWAVFromSDToDAC.ino │ ├── Blynk │ │ └── Post-DHT12 │ │ │ ├── DHT12.cpp │ │ │ ├── DHT12.h │ │ │ └── Post-DHT12.ino │ ├── Display │ │ ├── All_Free_Fonts_Demo │ │ │ ├── All_Free_Fonts_Demo.ino │ │ │ └── Free_Fonts.h │ │ ├── Bmp_Jpg_SPIFFS_draw │ │ │ ├── Bmp_Jpg_SPIFFS_draw.ino │ │ │ └── data │ │ │ │ ├── m5_logo.jpg │ │ │ │ └── pcd.bmp │ │ ├── Cellular_Automata │ │ │ └── Cellular_Automata.ino │ │ ├── Display_Unicode │ │ │ ├── CUF_24px.h │ │ │ ├── Display_Unicode.ino │ │ │ └── README.md │ │ ├── Free_Font_Demo │ │ │ ├── Free_Font_Demo.ino │ │ │ └── Free_Fonts.h │ │ ├── HZK16 │ │ │ ├── HZK16.ino │ │ │ ├── README.md │ │ │ ├── display_ch.cpp │ │ │ ├── display_ch.h │ │ │ └── str.h │ │ ├── JpegDraw │ │ │ └── JpegDraw.ino │ │ ├── RLE_Font_test │ │ │ └── RLE_Font_test.ino │ │ ├── Sprite │ │ │ ├── Sprite_RLE_Font_test │ │ │ │ └── Sprite_RLE_Font_test.ino │ │ │ ├── Sprite_TFT_Rainbow │ │ │ │ └── Sprite_TFT_Rainbow.ino │ │ │ ├── Sprite_drawPixel │ │ │ │ └── Sprite_drawPixel.ino │ │ │ ├── Sprite_scroll │ │ │ │ └── Sprite_scroll.ino │ │ │ ├── Sprite_scroll_16bit │ │ │ │ └── Sprite_scroll_16bit.ino │ │ │ ├── Sprite_scroll_8bit │ │ │ │ └── Sprite_scroll_8bit.ino │ │ │ ├── Transparent_Sprite_Demo │ │ │ │ └── Transparent_Sprite_Demo.ino │ │ │ ├── one_bit_Sprite_Demo │ │ │ │ └── one_bit_Sprite_Demo.ino │ │ │ └── one_bit_Yin_Yang │ │ │ │ └── one_bit_Yin_Yang.ino │ │ ├── TFT_ArcFill │ │ │ └── TFT_ArcFill.ino │ │ ├── TFT_Char_times │ │ │ └── TFT_Char_times.ino │ │ ├── TFT_Clock │ │ │ └── TFT_Clock.ino │ │ ├── TFT_Clock_Digital │ │ │ └── TFT_Clock_Digital.ino │ │ ├── TFT_Custom_Fonts │ │ │ └── TFT_Custom_Fonts.ino │ │ ├── TFT_Ellipse │ │ │ └── TFT_Ellipse.ino │ │ ├── TFT_FillArcSpiral │ │ │ └── TFT_FillArcSpiral.ino │ │ ├── TFT_Flash_Bitmap │ │ │ ├── Alert.h │ │ │ ├── Close.h │ │ │ ├── Info.h │ │ │ └── TFT_Flash_Bitmap.ino │ │ ├── TFT_Float_Test │ │ │ └── TFT_Float_Test.ino │ │ ├── TFT_Mandlebrot │ │ │ └── TFT_Mandlebrot.ino │ │ ├── TFT_Matrix │ │ │ └── TFT_Matrix.ino │ │ ├── TFT_Meter_linear │ │ │ └── TFT_Meter_linear.ino │ │ ├── TFT_Meters │ │ │ └── TFT_Meters.ino │ │ ├── TFT_Pie_Chart │ │ │ └── TFT_Pie_Chart.ino │ │ ├── TFT_Pong │ │ │ └── TFT_Pong.ino │ │ ├── TFT_Print_Test │ │ │ └── TFT_Print_Test.ino │ │ ├── TFT_Rainbow_one_lib │ │ │ └── TFT_Rainbow_one_lib.ino │ │ ├── TFT_Screen_Capture │ │ │ ├── TFT_Screen_Capture.ino │ │ │ ├── processing_sketch.ino │ │ │ └── screenServer.ino │ │ ├── TFT_Spiro │ │ │ └── TFT_Spiro.ino │ │ ├── TFT_Starfield │ │ │ └── TFT_Starfield.ino │ │ ├── TFT_String_Align │ │ │ └── TFT_String_Align.ino │ │ ├── TFT_Terminal │ │ │ └── TFT_Terminal.ino │ │ ├── TFT_graphicstest_PDQ │ │ │ └── TFT_graphicstest_PDQ.ino │ │ ├── TFT_graphicstest_one_lib │ │ │ └── TFT_graphicstest_one_lib.ino │ │ ├── UTFT_demo │ │ │ └── UTFT_demo.ino │ │ ├── drawXBitmap │ │ │ ├── drawXBitmap.ino │ │ │ └── xbm.h │ │ └── png_spiffs │ │ │ ├── data │ │ │ ├── test.png │ │ │ └── test1.png │ │ │ └── png_spiffs.ino │ ├── EzData │ │ └── EzData.ino │ ├── HallSensor │ │ └── HallSensor.ino │ ├── I2C_Tester │ │ └── I2C_Tester.ino │ ├── MQTT │ │ └── MQTT.ino │ ├── MultSerial │ │ └── MultSerial.ino │ ├── MultiTask │ │ └── MultiTask.ino │ ├── QRCode │ │ └── QRCode.ino │ ├── Storage │ │ ├── Counter │ │ │ └── Counter.ino │ │ ├── EEPROM │ │ │ └── EEPROM.ino │ │ └── SPIFFS │ │ │ ├── SPIFFS │ │ │ └── SPIFFS.ino │ │ │ ├── SPIFFS_Add │ │ │ └── SPIFFS_Add.ino │ │ │ └── SPIFFS_Delete │ │ │ └── SPIFFS_Delete.ino │ ├── Time │ │ └── Time.ino │ └── WIFI │ │ ├── .vscode │ │ └── settings.json │ │ ├── BasicHttpClient │ │ └── BasicHttpClient.ino │ │ ├── OTAUpload │ │ └── OTAUpload.ino │ │ ├── WiFiAccessPoint │ │ └── WiFiAccessPoint.ino │ │ ├── WiFiMulti │ │ └── WiFiMulti.ino │ │ ├── WiFiScan │ │ └── WiFiScan.ino │ │ ├── WiFiSetting │ │ ├── Parsing.cpp │ │ ├── WebServer.cpp │ │ ├── WebServer.h │ │ ├── WiFiSetting.ino │ │ └── detail │ │ │ ├── RequestHandler.h │ │ │ └── RequestHandlersImpl.h │ │ ├── WiFiSmartConfig │ │ └── WiFiSmartConfig.ino │ │ ├── WiFiTCP │ │ └── WiFiTCP.ino │ │ └── mDNS_Find │ │ └── mDNS_Find.ino ├── Basics │ ├── Button │ │ └── Button.ino │ ├── Display │ │ └── Display.ino │ ├── FactoryTest │ │ ├── FactoryTest.ino │ │ ├── bmp_map.c │ │ └── startup_music.c │ ├── HelloWorld │ │ └── HelloWorld.ino │ ├── IMU │ │ └── IMU.ino │ ├── PowerOFF │ │ └── PowerOFF.ino │ ├── Sleep │ │ └── Sleep.ino │ ├── Speaker │ │ └── Speaker.ino │ ├── TFCard │ │ └── TFCard.ino │ └── bmm150 │ │ └── bmm150.ino ├── Face │ ├── CALCULATOR │ │ └── CALCULATOR.ino │ ├── ENCODER │ │ └── ENCODER.ino │ ├── FACESII_RGB_BAR │ │ └── FACESII_RGB_BAR.ino │ ├── JOYSTICK │ │ └── JOYSTICK.ino │ ├── KEYBOARD │ │ └── KEYBOARD.ino │ ├── RFID │ │ ├── MFRC522_I2C.cpp │ │ ├── MFRC522_I2C.h │ │ └── RFID.ino │ └── Snake_Gameboy │ │ ├── GameBoard.cpp │ │ ├── GameBoard.h │ │ ├── GameboyInput.cpp │ │ ├── GameboyInput.h │ │ ├── Power.cpp │ │ ├── Power.h │ │ └── Snake_Gameboy.ino ├── Fire │ ├── Microphone │ │ └── Microphone.ino │ ├── MicrophoneSignalTFT │ │ └── MicrophoneSignalTFT.ino │ ├── MicrophoneSpectrumTFT │ │ └── MicrophoneSpectrumTFT.ino │ ├── RGB_BAR_TEST │ │ └── RGB_BAR_TEST.ino │ ├── RGB_BAR_VUmeter │ │ └── RGB_BAR_VUmeter.ino │ └── SpeakerDacSine │ │ └── SpeakerDacSine.ino ├── Games │ ├── FlappyBird │ │ └── FlappyBird.ino │ └── Tetris │ │ ├── Tetris.ino │ │ ├── tetris.jpg │ │ └── tetris_img.c ├── KIT │ ├── PM25 │ │ ├── DFRobot_SHT20.cpp │ │ ├── DFRobot_SHT20.h │ │ ├── Free_Fonts.h │ │ └── PM25.ino │ ├── PM25_SHT30 │ │ ├── Free_Fonts.h │ │ └── PM25_SHT30.ino │ └── SCALES_KIT │ │ └── SCALES_KIT.ino ├── Modules │ ├── 4EncoderMotor │ │ └── 4EncoderMotor.ino │ ├── AC-SOCKET │ │ ├── AC-SOCKET.ino │ │ ├── modbus.c │ │ ├── modbus.h │ │ ├── protocol.cpp │ │ └── protocol.h │ ├── BALA │ │ ├── BALA.ino │ │ ├── M5Bala.cpp │ │ ├── M5Bala.h │ │ ├── imuCalibration.cpp │ │ └── imuCalibration.h │ ├── BALA2 │ │ ├── BALA2.ino │ │ ├── MadgwickAHRS.cpp │ │ ├── MadgwickAHRS.h │ │ ├── bala.cpp │ │ ├── bala.h │ │ ├── bala2.bin │ │ ├── bala_img.c │ │ ├── calibration.cpp │ │ ├── calibration.h │ │ ├── imu_filter.cpp │ │ ├── imu_filter.h │ │ ├── pid.cpp │ │ └── pid.h │ ├── BaseX │ │ ├── BaseX.cpp │ │ ├── BaseX.h │ │ └── BaseX.ino │ ├── Base_PoE │ │ ├── LAN_W5500 │ │ │ └── WebServer │ │ │ │ └── WebServer.ino │ │ └── RS_485 │ │ │ └── RS_485.ino │ ├── COMMU │ │ ├── CAN │ │ │ ├── commu_can_receiver │ │ │ │ ├── commu_can_receiver.ino │ │ │ │ └── m5_logo.h │ │ │ └── commu_can_transmitter │ │ │ │ ├── commu_can_transmitter.ino │ │ │ │ └── m5_logo.h │ │ ├── MCP_CAN_lib.rar │ │ ├── RS485 │ │ │ ├── commu_rs485_A │ │ │ │ ├── commu_rs485_A.ino │ │ │ │ └── m5_logo.h │ │ │ └── commu_rs485_B │ │ │ │ ├── commu_rs485_B.ino │ │ │ │ └── m5_logo.h │ │ └── factory_test │ │ │ ├── COMMU_Test_A │ │ │ ├── COMMU_Test_A.ino │ │ │ └── m5_logo.h │ │ │ └── COMMU_Test_B │ │ │ ├── COMMU_Test_B.ino │ │ │ └── m5_logo.h │ ├── COM_CAT1_SIM7680 │ │ └── COM_CAT1_SIM7680.ino │ ├── COM_GPS │ │ └── COM_GPS.ino │ ├── COM_GSM │ │ ├── COM_GSM.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COM_LTE-DATA │ │ ├── COM_LTE-DATA.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COM_LTE │ │ ├── COM_LTE.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COM_LoRaWAN │ │ ├── LoRaWAN_Receive │ │ │ ├── LoRaWAN_Receive.ino │ │ │ ├── TFTTerminal.cpp │ │ │ └── TFTTerminal.h │ │ └── LoRaWAN_Send │ │ │ └── LoRaWAN_Send.ino │ ├── COM_LoRaWAN470 │ │ ├── COM_LoRaWAN470.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COM_LoRaWAN915 │ │ ├── COM_LoRaWAN915.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COM_NB-IoT │ │ ├── COM_NB-IoT.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COM_SigFox │ │ └── COM_SigFox.ino │ ├── COM_Zigbee_CC2630 │ │ ├── P2P_TEST │ │ │ ├── DRFZigbee.cpp │ │ │ ├── DRFZigbee.h │ │ │ ├── P2P_TEST.ino │ │ │ ├── byteArray.cpp │ │ │ ├── byteArray.h │ │ │ ├── resource.cpp │ │ │ └── resource.h │ │ └── RSSI_TEST │ │ │ ├── DRFZigbee.cpp │ │ │ ├── DRFZigbee.h │ │ │ ├── RSSI_TEST.ino │ │ │ ├── byteArray.cpp │ │ │ ├── byteArray.h │ │ │ ├── resource.cpp │ │ │ └── resource.h │ ├── DHT12 │ │ ├── DHT12.cpp │ │ ├── DHT12.h │ │ └── DHT12.ino │ ├── GPS_NEO_M8N │ │ ├── FullExample │ │ │ └── FullExample.ino │ │ └── GPSRaw │ │ │ └── GPSRaw.ino │ ├── GSM_M6315 │ │ └── GSM_M6315.ino │ ├── GoPLUS │ │ ├── GoPLUS.ino │ │ ├── GoPlus.cpp │ │ └── GoPlus.h │ ├── GoPLUS2 │ │ ├── GoPLUS2.ino │ │ ├── GoPlus2.cpp │ │ └── GoPlus2.h │ ├── LAN_W5500 │ │ └── WebServer │ │ │ └── WebServer.ino │ ├── LEGO_PLUS │ │ └── LEGO_PLUS.ino │ ├── LORA868_SX1276 │ │ └── LoRa868Duplex │ │ │ └── LoRa868Duplex.ino │ ├── LTE_M8321 │ │ └── LTE_M8321.ino │ ├── LoRa433_SX1278 │ │ ├── LoRaDumpRegisters │ │ │ └── LoRaDumpRegisters.ino │ │ ├── LoRaDuplex │ │ │ └── LoRaDuplex.ino │ │ ├── LoRaDuplexCallback │ │ │ └── LoRaDuplexCallback.ino │ │ ├── LoRaReceiver │ │ │ └── LoRaReceiver.ino │ │ ├── LoRaReceiverCallback │ │ │ └── LoRaReceiverCallback.ino │ │ ├── LoRaSender │ │ │ └── LoRaSender.ino │ │ ├── LoRaSetSpread │ │ │ └── LoRaSetSpread.ino │ │ └── LoRaSetSyncWord │ │ │ └── LoRaSetSyncWord.ino │ ├── LoRaWAN_RHF76_052 │ │ └── LoRaWAN_RHF76_052.ino │ ├── NB-IoT-PLUS_M5311GB │ │ └── NB-IoT-PLUS_M5311GB.ino │ ├── NB-IoT_M5311LV │ │ └── NB-IoT_M5311LV.ino │ ├── ODrive │ │ ├── ODrive.ino │ │ ├── odrive.cpp │ │ └── odrive.h │ ├── PLUS │ │ └── PLUS.ino │ ├── PM2.5_PMSA003 │ │ ├── DFRobot_SHT20.cpp │ │ ├── DFRobot_SHT20.h │ │ ├── Free_Fonts.h │ │ └── PM2.5_PMSA003.ino │ ├── RS232 │ │ └── RS232.ino │ ├── SERVO │ │ └── SERVO.ino │ ├── SERVO2_PCA9685 │ │ ├── Adafruit_PWMServoDriver.cpp │ │ ├── Adafruit_PWMServoDriver.h │ │ └── SERVO2_PCA9685.ino │ ├── SIM800L │ │ ├── ATCOM │ │ │ └── AT │ │ │ │ └── AT.ino │ │ ├── HTTP │ │ │ ├── HTTP.ino │ │ │ ├── TFTTerminal.cpp │ │ │ └── TFTTerminal.h │ │ ├── SIM800L_FactoryTest │ │ │ └── SIM800L_FactoryTest.ino │ │ └── send_short_message │ │ │ └── send_short_message.ino │ ├── StepmotorGRBL13.2_M035 │ │ ├── multi_control │ │ │ └── multi_control.ino │ │ └── xyz_control │ │ │ └── xyz_control.ino │ ├── StepmotorGRBL_M012 │ │ └── StepmotorGRBL_M012.ino │ └── USB_MAX3421E │ │ └── usb_mouse │ │ ├── M5Mouse.h │ │ └── usb_mouse.ino └── Unit │ ├── ACCEL_ADXL345 │ └── ACCEL_ADXL345.ino │ ├── ANGLE │ └── ANGLE.ino │ ├── Angle8 │ └── Angle8.ino │ ├── BPS_QMP6988 │ └── BPS_QMP6988.ino │ ├── BUTTON │ └── BUTTON.ino │ ├── CAN │ └── CAN.ino │ ├── CATCH │ └── CATCH.ino │ ├── CATEAR_SK6812 │ └── CATEAR_SK6812.ino │ ├── COLOR_TCS3472 │ └── COLOR_TCS3472.ino │ ├── CardKB │ └── CardKB.ino │ ├── DAC2_GP8413 │ └── DAC2_GP8413.ino │ ├── DAC_MCP4725 │ └── DAC_MCP4725.ino │ ├── DUAL_BUTTON │ └── DUAL_BUTTON.ino │ ├── EARTH │ └── EARTH.ino │ ├── EXT_IO_PCA9554PW │ └── EXT_IO_PCA9554PW.ino │ ├── FADER │ └── FADER.ino │ ├── FAN │ └── FAN.ino │ ├── GESTURE_PAJ7620U2 │ └── GESTURE_PAJ7620U2.ino │ ├── GLASS │ └── GLASS.ino │ ├── GPS_AT6558 │ ├── FullExample │ │ └── FullExample.ino │ └── GPSRaw │ │ └── GPSRaw.ino │ ├── HALL │ └── HALL.ino │ ├── HEART_MAX30100 │ ├── MAX30100_RawData │ │ └── MAX30100_RawData.ino │ └── ScreenShow │ │ └── ScreenShow.ino │ ├── HEX_SK6812 │ └── HEX_SK6812.ino │ ├── IR │ └── IR.ino │ ├── ISO485 │ └── ISO485.ino │ ├── JOYSTICK │ └── JOYSTICK.ino │ ├── KEY │ ├── KEY-DEMO1 │ │ └── KEY-DEMO1.ino │ └── KEY-DEMO2 │ │ └── KEY-DEMO2.ino │ ├── LASER │ └── LASER.ino │ ├── LCD_ST7789V2 │ └── LCD_ST7789V2.ino │ ├── LIGHT │ └── LIGHT.ino │ ├── LIMIT │ └── LIMIT.ino │ ├── MAKEY │ └── MAKEY.ino │ ├── MiniOLED │ └── MiniOLED.ino │ ├── NBIoT_SIM7020 │ └── NBIoT_SIM7020.ino │ ├── NCIR_MLX90614 │ └── NCIR_MLX90614.ino │ ├── NEOFLASH_SK6812_PIR │ ├── DisplayCurrentTime.cpp │ ├── DisplayCurrentTime.h │ └── NEOFLASH_SK6812_PIR.ino │ ├── OLED_SH1107 │ └── OLED_SH1107.ino │ ├── OP90.180_ITR9606 │ └── OP90.180_ITR9606.ino │ ├── PDM_SPM1423 │ ├── PDM_SPM1423.ino │ ├── fft.cpp │ └── fft.h │ ├── PIR │ └── PIR.ino │ ├── PaHUB_TCA9548A │ └── PaHUB_TCA9548A.ino │ ├── PbHUB │ ├── PbHUB.ino │ ├── porthub.cpp │ └── porthub.h │ ├── RCA │ ├── RCA.ino │ └── wav_unsigned_8bit_click.cpp │ ├── RF433 │ └── RF433.ino │ ├── RFID_RC522 │ ├── MFRC522_I2C.cpp │ ├── MFRC522_I2C.h │ └── RFID_RC522.ino │ ├── RGB_LED_SK6812 │ └── display_rainbow │ │ └── display_rainbow.ino │ ├── RGB_SK6812 │ └── RGB_SK6812.ino │ ├── RS485_SP485EEN │ └── RS485_SP485EEN.ino │ ├── RTC_BM8563 │ └── RTC_BM8563.ino │ ├── THERMAL_MLX90640 │ ├── MLX90640_API.cpp │ ├── MLX90640_API.h │ ├── MLX90640_I2C_Driver.cpp │ ├── MLX90640_I2C_Driver.h │ ├── THERMAL_MLX90640.ino │ └── interpolation.cpp │ ├── TRACE │ └── TRACE.ino │ ├── TVOC_SGP30 │ └── TVOC_SGP30.ino │ ├── ToF_VL53L0X │ └── ToF_VL53L0X.ino │ ├── UWB_DW1000 │ └── UWB_DW1000.ino │ ├── VIBRATOR │ └── VIBRATOR.ino │ ├── WATERING │ └── WATERING.ino │ ├── WEIGHT_HX711 │ └── WEIGHT_HX711.ino │ └── Zigbee_CC2630 │ ├── P2P_TEST │ ├── DRFZigbee.cpp │ ├── DRFZigbee.h │ ├── P2P_TEST.ino │ ├── byteArray.cpp │ ├── byteArray.h │ ├── resource.cpp │ └── resource.h │ └── RSSI_TEST │ ├── DRFZigbee.cpp │ ├── DRFZigbee.h │ ├── RSSI_TEST.ino │ ├── byteArray.cpp │ ├── byteArray.h │ ├── resource.cpp │ └── resource.h ├── keywords.txt ├── library.json ├── library.properties ├── src ├── Fonts │ ├── ASC16 │ ├── ASC16.h │ ├── Custom │ │ ├── Orbitron_Light_24.h │ │ ├── Orbitron_Light_32.h │ │ ├── Roboto_Thin_24.h │ │ ├── Satisfy_24.h │ │ └── Yellowtail_32.h │ ├── Font16.c │ ├── Font16.h │ ├── Font32rle.c │ ├── Font32rle.h │ ├── Font64rle.c │ ├── Font64rle.h │ ├── Font72rle.c │ ├── Font72rle.h │ ├── Font7srle.c │ ├── Font7srle.h │ ├── GFXFF │ │ ├── FreeMono12pt7b.h │ │ ├── FreeMono18pt7b.h │ │ ├── FreeMono24pt7b.h │ │ ├── FreeMono9pt7b.h │ │ ├── FreeMonoBold12pt7b.h │ │ ├── FreeMonoBold18pt7b.h │ │ ├── FreeMonoBold24pt7b.h │ │ ├── FreeMonoBold9pt7b.h │ │ ├── FreeMonoBoldOblique12pt7b.h │ │ ├── FreeMonoBoldOblique18pt7b.h │ │ ├── FreeMonoBoldOblique24pt7b.h │ │ ├── FreeMonoBoldOblique9pt7b.h │ │ ├── FreeMonoOblique12pt7b.h │ │ ├── FreeMonoOblique18pt7b.h │ │ ├── FreeMonoOblique24pt7b.h │ │ ├── FreeMonoOblique9pt7b.h │ │ ├── FreeSans12pt7b.h │ │ ├── FreeSans18pt7b.h │ │ ├── FreeSans24pt7b.h │ │ ├── FreeSans9pt7b.h │ │ ├── FreeSansBold12pt7b.h │ │ ├── FreeSansBold18pt7b.h │ │ ├── FreeSansBold24pt7b.h │ │ ├── FreeSansBold9pt7b.h │ │ ├── FreeSansBoldOblique12pt7b.h │ │ ├── FreeSansBoldOblique18pt7b.h │ │ ├── FreeSansBoldOblique24pt7b.h │ │ ├── FreeSansBoldOblique9pt7b.h │ │ ├── FreeSansOblique12pt7b.h │ │ ├── FreeSansOblique18pt7b.h │ │ ├── FreeSansOblique24pt7b.h │ │ ├── FreeSansOblique9pt7b.h │ │ ├── FreeSerif12pt7b.h │ │ ├── FreeSerif18pt7b.h │ │ ├── FreeSerif24pt7b.h │ │ ├── FreeSerif9pt7b.h │ │ ├── FreeSerifBold12pt7b.h │ │ ├── FreeSerifBold18pt7b.h │ │ ├── FreeSerifBold24pt7b.h │ │ ├── FreeSerifBold9pt7b.h │ │ ├── FreeSerifBoldItalic12pt7b.h │ │ ├── FreeSerifBoldItalic18pt7b.h │ │ ├── FreeSerifBoldItalic24pt7b.h │ │ ├── FreeSerifBoldItalic9pt7b.h │ │ ├── FreeSerifItalic12pt7b.h │ │ ├── FreeSerifItalic18pt7b.h │ │ ├── FreeSerifItalic24pt7b.h │ │ ├── FreeSerifItalic9pt7b.h │ │ ├── TomThumb.h │ │ ├── gfxfont.h │ │ ├── license.txt │ │ └── print.txt │ ├── HZK16 │ ├── HZK16.h │ ├── TrueType │ │ └── Not_yet_supported.txt │ └── glcdfont.c ├── Free_Fonts.h ├── IMU.cpp ├── IMU.h ├── LoRaWan.cpp ├── LoRaWan.h ├── M5Display.cpp ├── M5Display.h ├── M5Faces.cpp ├── M5Faces.h ├── M5LoRa.cpp ├── M5LoRa.h ├── M5Stack.cpp ├── M5Stack.h ├── gitTagVersion.h └── utility │ ├── Button.cpp │ ├── Button.h │ ├── CommUtil.cpp │ ├── CommUtil.h │ ├── Config.h │ ├── ILI9341_Defines.h │ ├── ILI9341_Init.h │ ├── ILI9341_Rotation.h │ ├── ILI9342C_Init.h │ ├── In_eSPI.cpp │ ├── In_eSPI.h │ ├── In_eSPI_Setup.h │ ├── M5Timer.cpp │ ├── M5Timer.h │ ├── MPU6886.cpp │ ├── MPU6886.h │ ├── MPU9250.cpp │ ├── MPU9250.h │ ├── MahonyAHRS.cpp │ ├── MahonyAHRS.h │ ├── Power.cpp │ ├── Power.h │ ├── SH200Q.cpp │ ├── SH200Q.h │ ├── Speaker.cpp │ ├── Speaker.h │ ├── Sprite.cpp │ ├── Sprite.h │ ├── pngle.c │ ├── pngle.h │ ├── qrcode.c │ ├── qrcode.h │ ├── quaternionFilters.cpp │ └── quaternionFilters.h └── tools ├── bin2code.py └── m5_logo.jpg /.github/workflows/Arduino-Lint-Check.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Lint 2 | on: 3 | push: 4 | branches: [ master ] 5 | pull_request: 6 | branches: [ master ] 7 | jobs: 8 | lint: 9 | name: Lint Check 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: arduino/arduino-lint-action@v1 14 | with: 15 | library-manager: update 16 | compliance: strict 17 | project-type: all -------------------------------------------------------------------------------- /.github/workflows/clang-format-check.yml: -------------------------------------------------------------------------------- 1 | name: Clang Format 2 | on: [push, pull_request] 3 | jobs: 4 | formatting-check: 5 | name: Formatting Check 6 | runs-on: ubuntu-latest 7 | strategy: 8 | matrix: 9 | path: 10 | - check: './' # path to include 11 | exclude: '(Fonts|utility|RFID|THERMAL_MLX90640|HEART_MAX30100|Display|AC-SOCKET|BALA2)' # path to exclude 12 | # - check: 'src' 13 | # exclude: '(Fonts)' # Exclude file paths containing "Fonts" 14 | # - check: 'examples' 15 | # exclude: '' 16 | steps: 17 | - uses: actions/checkout@v2 18 | - name: Run clang-format style check for C/C++/Protobuf programs. 19 | uses: jidicula/clang-format-action@v4.8.0 20 | with: 21 | clang-format-version: '13' 22 | check-path: ${{ matrix.path['check'] }} 23 | exclude-regex: ${{ matrix.path['exclude'] }} 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | *.svd 18 | *.cfg 19 | 20 | debug_custom.json 21 | 22 | # Windows shortcuts 23 | *.lnk 24 | 25 | # ========================= 26 | # Operating System Files 27 | # ========================= 28 | 29 | # OSX 30 | # ========================= 31 | 32 | .DS_Store 33 | .AppleDouble 34 | .LSOverride 35 | 36 | # Thumbnails 37 | ._* 38 | 39 | # Files that might appear in the root of a volume 40 | .DocumentRevisions-V100 41 | .fseventsd 42 | .Spotlight-V100 43 | .TemporaryItems 44 | .Trashes 45 | .VolumeIcon.icns 46 | 47 | # Directories potentially created on remote AFP share 48 | .AppleDB 49 | .AppleDesktop 50 | Network Trash Folder 51 | Temporary Items 52 | .apdisk 53 | 54 | examples/Advanced/Proof 55 | docs/datesheet 56 | 57 | .vscode/* 58 | 59 | examples/.DS_Store 60 | .DS_Store 61 | examples/Basics/.DS_Store 62 | .development 63 | examples/Touch/.DS_Store 64 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_SRCDIRS "src" "src/utility" "src/Fonts") 2 | set(COMPONENT_ADD_INCLUDEDIRS "src" "$ENV{IDF_PATH}/components/bt/bluedroid/api/include/api") 3 | list(APPEND COMPONENT_REQUIRES "arduino") 4 | 5 | 6 | register_component() 7 | 8 | 9 | set(DEFINITIONS "ESP32") 10 | 11 | if (CONFIG_M5STACK_BASIC OR CONFIG_M5STACK_GRAY OR CONFIG_M5STACK_FIRE) 12 | list(APPEND DEFINITIONS "M5STACK") 13 | endif (CONFIG_M5STACK_BASIC OR CONFIG_M5STACK_GRAY OR CONFIG_M5STACK_FIRE) 14 | 15 | if(CONFIG_M5STACK_FIRE) 16 | list(APPEND DEFINITIONS "M5STACK_FIRE") 17 | endif(CONFIG_M5STACK_FIRE) 18 | 19 | target_compile_definitions(${COMPONENT_NAME} PUBLIC ${DEFINITIONS}) 20 | 21 | -------------------------------------------------------------------------------- /Kconfig: -------------------------------------------------------------------------------- 1 | menu "M5Stack" 2 | 3 | choice CORE_TYPE 4 | prompt "Type of Core" 5 | default M5STACK_BASIC 6 | help 7 | Type of Core. 8 | 9 | config M5STICK 10 | bool "M5Stick" 11 | config M5STACK_BASIC 12 | bool "M5Stack Basic" 13 | config M5STACK_GRAY 14 | bool "M5Stack Gray" 15 | config M5STACK_FIRE 16 | bool "M5Stack Fire" 17 | endchoice 18 | 19 | endmenu 20 | 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 M5Stack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /component.mk: -------------------------------------------------------------------------------- 1 | # 2 | # Main Makefile. This is basically the same as a component makefile. 3 | # 4 | # (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) 5 | 6 | COMPONENT_SRCDIRS := src src/utility src/Fonts 7 | COMPONENT_ADD_INCLUDEDIRS := src 8 | -------------------------------------------------------------------------------- /docs/M-BUS.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/M-BUS.jpg -------------------------------------------------------------------------------- /docs/arduino-ide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide.png -------------------------------------------------------------------------------- /docs/arduino-ide/debian_ubuntu.md: -------------------------------------------------------------------------------- 1 | Installation instructions for Debian / Ubuntu OS 2 | ================================================= 3 | 4 | - Install latest Arduino IDE from [arduino.cc](https://www.arduino.cc/en/Main/Software) 5 | - Open Terminal and execute the following command (copy->paste and hit enter): 6 | 7 | ```bash 8 | sudo usermod -a -G dialout $USER && \ 9 | sudo apt-get install git && \ 10 | wget https://bootstrap.pypa.io/get-pip.py && \ 11 | sudo python get-pip.py && \ 12 | sudo pip install pyserial && \ 13 | mkdir -p ~/Arduino/hardware/espressif && \ 14 | cd ~/Arduino/hardware/espressif && \ 15 | git clone https://github.com/espressif/arduino-esp32.git esp32 && \ 16 | cd esp32 && \ 17 | git submodule update --init --recursive && \ 18 | cd tools && \ 19 | python2 get.py 20 | ``` 21 | Or for Ubuntu 18.04 just ```sudo apt install python-serial``` 22 | - Restart Arduino IDE 23 | 24 | 25 | 26 | - If you have Arduino.app installed to /Applications/, modify the installation as follows, beginning at `mkdir -p ~/Arduino...`: 27 | 28 | ```bash 29 | cd /Applications/Arduino_*/Contents/java/hardware/ 30 | mkdir -p espressif && \ 31 | cd espressif && \ 32 | git clone https://github.com/espressif/arduino-esp32.git esp32 && \ 33 | cd esp32 && \ 34 | git submodule update --init --recursive && \ 35 | cd tools && \ 36 | python2 get.py``` 37 | -------------------------------------------------------------------------------- /docs/arduino-ide/fedora.md: -------------------------------------------------------------------------------- 1 | Installation instructions for Fedora 2 | ===================================== 3 | 4 | - Install the latest Arduino IDE from [arduino.cc](https://www.arduino.cc/en/Main/Software). `$ sudo dnf -y install arduino` will most likely install an older release. 5 | - Open Terminal and execute the following command (copy->paste and hit enter): 6 | 7 | ```bash 8 | sudo usermod -a -G dialout $USER && \ 9 | sudo dnf install git python3-pip python3-pyserial && \ 10 | mkdir -p ~/Arduino/hardware/espressif && \ 11 | cd ~/Arduino/hardware/espressif && \ 12 | git clone https://github.com/espressif/arduino-esp32.git esp32 && \ 13 | cd esp32 && \ 14 | git submodule update --init --recursive && \ 15 | cd tools && \ 16 | python get.py 17 | ``` 18 | - Restart Arduino IDE 19 | -------------------------------------------------------------------------------- /docs/arduino-ide/mac.md: -------------------------------------------------------------------------------- 1 | Installation instructions for Mac OS 2 | ===================================== 3 | 4 | - Install latest Arduino IDE from [arduino.cc](https://www.arduino.cc/en/Main/Software) 5 | - Open Terminal and execute the following command (copy->paste and hit enter): 6 | 7 | ```bash 8 | mkdir -p ~/Documents/Arduino/hardware/espressif && \ 9 | cd ~/Documents/Arduino/hardware/espressif && \ 10 | git clone https://github.com/espressif/arduino-esp32.git esp32 && \ 11 | cd esp32 && \ 12 | git submodule update --init --recursive && \ 13 | cd tools && \ 14 | python get.py 15 | ``` 16 | - If you get the error below. Install the command line dev tools with xcode-select --install and try the command above again: 17 | 18 | ```xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun``` 19 | 20 | ```xcode-select --install``` 21 | 22 | - Restart Arduino IDE 23 | 24 | -------------------------------------------------------------------------------- /docs/arduino-ide/opensuse.md: -------------------------------------------------------------------------------- 1 | Installation instructions for openSUSE 2 | ====================================== 3 | 4 | - Install the latest Arduino IDE from [arduino.cc](https://www.arduino.cc/en/Main/Software). 5 | - Open Terminal and execute the following command (copy->paste and hit enter): 6 | 7 | ```bash 8 | sudo usermod -a -G dialout $USER && \ 9 | if [ `python --version 2>&1 | grep '2.7' | wc -l` = "1" ]; then \ 10 | sudo zypper install git python-pip python-pyserial; \ 11 | else \ 12 | sudo zypper install git python3-pip python3-pyserial; \ 13 | fi && \ 14 | mkdir -p ~/Arduino/hardware/espressif && \ 15 | cd ~/Arduino/hardware/espressif && \ 16 | git clone https://github.com/espressif/arduino-esp32.git esp32 && \ 17 | cd esp32 && \ 18 | git submodule update --init --recursive && \ 19 | cd tools && \ 20 | python get.py 21 | ``` 22 | - Restart Arduino IDE 23 | -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/arduino-ide.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/arduino-ide.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/win-gui-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/win-gui-1.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/win-gui-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/win-gui-2.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/win-gui-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/win-gui-3.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/win-gui-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/win-gui-4.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/win-gui-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/win-gui-5.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/win-gui-update-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/win-gui-update-1.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots/win-gui-update-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots/win-gui-update-2.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/FactoryTest_result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/FactoryTest_result.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/arduino_cc_package.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/arduino_cc_package.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/arduino_path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/arduino_path.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/arduino_windows_installer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/arduino_windows_installer.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/clone_esp32_idf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/clone_esp32_idf.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/clone_esp32_idf_subdir.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/clone_esp32_idf_subdir.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/download_idf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/download_idf.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/download_m5stack_lib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/download_m5stack_lib.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/download_xtensa_tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/download_xtensa_tools.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/mkdir_espressif.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/mkdir_espressif.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/my_com.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/my_com.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/select_arduino_install_path.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/select_arduino_install_path.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/select_arduino_lib.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/select_arduino_lib.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/select_board_and_com.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/select_board_and_com.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/select_demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/select_demo.png -------------------------------------------------------------------------------- /docs/arduino-ide/win-screenshots_cn/select_get_exe_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/docs/arduino-ide/win-screenshots_cn/select_get_exe_file.png -------------------------------------------------------------------------------- /docs/getting_started_cn.md: -------------------------------------------------------------------------------- 1 | # M5Stack Library 2 | 3 | [English](../README.md) | 中文 | [日本語](getting_started_ja.md) 4 | 5 | gray 6 | 7 | basic 8 | 9 | * **如果查看 Gray 的详细介绍文档,[点击这里](https://docs.m5stack.com/#/zh_CN/core/gray)** 10 | 11 | * **如果查看 Basic 的详细介绍文档,[点击这里](https://docs.m5stack.com/#/zh_CN/core/basic)** 12 | 13 | * **如果想要购买 Basic 的话,[点击这里](https://item.taobao.com/item.htm?spm=a1z10.5-c-s.w4002-22404213529.11.6b2349d8feN5U0&id=610634829528)** 14 | 15 | *我们有几款不同配置的主控 M5Cores,这是他们之间的[对比](https://docs.m5stack.com/zh_CN/products_selector/m5core_compare).* 16 | 17 | 18 | ### M-BUS 19 | ![image](../docs/M-BUS.jpg) 20 | 21 | 22 | ## 更多信息 23 | 24 | **UIFlow 快速上手**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/m5core/uiflow) 25 | 26 | **MicroPython API**: [点击这里](https://docs.m5stack.com/zh_CN/mpy/display/m5stack_lvgl) 27 | 28 | **Arduino IDE 环境搭建**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/m5core/arduino) 29 | 30 | **M5StickC Arduino API**: [点击这里](https://docs.m5stack.com/zh_CN/api/system) 31 | 32 | **Gray 引脚地图**: [点击这里](https://docs.m5stack.com/zh_CN/core/gray) 33 | 34 | **Basic 引脚地图**: [点击这里](https://docs.m5stack.com/zh_CN/core/basic) 35 | -------------------------------------------------------------------------------- /docs/make.md: -------------------------------------------------------------------------------- 1 | To use make 2 | ============ 3 | 4 | [makeEspArduino](https://github.com/plerup/makeEspArduino) is a generic makefile for any ESP8266/ESP32 Arduino project. Using make instead of the Arduino IDE makes it easier to do automated and production builds. 5 | -------------------------------------------------------------------------------- /docs/platformio.md: -------------------------------------------------------------------------------- 1 | Installation instructions for using PlatformIO 2 | ================================================= 3 | 4 | - [What is PlatformIO?](http://docs.platformio.org/en/latest/what-is-platformio.html?utm_source=github&utm_medium=arduino-esp32) 5 | - [PlatformIO IDE](http://platformio.org/platformio-ide?utm_source=github&utm_medium=arduino-esp32) 6 | - [PlatformIO Core](http://docs.platformio.org/en/latest/core.html?utm_source=github&utm_medium=arduino-esp32) (command line tool) 7 | - [Advanced usage](http://docs.platformio.org/en/latest/platforms/espressif32.html?utm_source=github&utm_medium=arduino-esp32) - 8 | custom settings, uploading to SPIFFS, Over-the-Air (OTA), staging version 9 | - [Integration with Cloud and Standalone IDEs](http://docs.platformio.org/en/latest/ide.html?utm_source=github&utm_medium=arduino-esp32) - 10 | Cloud9, Codeanywhere, Eclipse Che (Codenvy), Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, VIM, Visual Studio, and VSCode 11 | - [Project Examples](http://docs.platformio.org/en/latest/platforms/espressif32.html?utm_source=github&utm_medium=arduino-esp32#examples) 12 | -------------------------------------------------------------------------------- /examples/Advanced/Audio/PlayMP3FromSDToDAC/PlayMP3FromSDToDAC.ino: -------------------------------------------------------------------------------- 1 | #pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries 2 | /* 3 | cd ~/Arduino/libraries 4 | git clone https://github.com/earlephilhower/ESP8266Audio 5 | git clone https://github.com/Gianbacchio/ESP8266_Spiram 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | #include "AudioFileSourceID3.h" 12 | #include "AudioFileSourceSD.h" 13 | #include "AudioGeneratorMP3.h" 14 | #include "AudioOutputI2S.h" 15 | 16 | AudioGeneratorMP3 *mp3; 17 | AudioFileSourceSD *file; 18 | AudioOutputI2S *out; 19 | AudioFileSourceID3 *id3; 20 | 21 | void setup() { 22 | M5.begin(); 23 | M5.Power.begin(); 24 | WiFi.mode(WIFI_OFF); 25 | delay(500); 26 | 27 | M5.Lcd.setTextFont(2); 28 | M5.Lcd.printf("Sample MP3 playback begins...\n"); 29 | Serial.printf("Sample MP3 playback begins...\n"); 30 | 31 | // pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html 32 | file = new AudioFileSourceSD("/pno-cs.mp3"); 33 | id3 = new AudioFileSourceID3(file); 34 | out = new AudioOutputI2S(0, 1); // Output to builtInDAC 35 | out->SetOutputModeMono(true); 36 | mp3 = new AudioGeneratorMP3(); 37 | mp3->begin(id3, out); 38 | } 39 | 40 | void loop() { 41 | if (mp3->isRunning()) { 42 | if (!mp3->loop()) mp3->stop(); 43 | } else { 44 | Serial.printf("MP3 done\n"); 45 | delay(1000); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /examples/Advanced/Audio/PlayMP3FromSPIFFSToDAC/PlayMP3FromSPIFFSToDAC.ino: -------------------------------------------------------------------------------- 1 | #pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries 2 | /* 3 | cd ~/Arduino/libraries 4 | git clone https://github.com/earlephilhower/ESP8266Audio 5 | git clone https://github.com/Gianbacchio/ESP8266_Spiram 6 | 7 | Use the "Tools->ESP32 Sketch Data Upload" menu to write the MP3 to SPIFFS 8 | Then upload the sketch normally. 9 | https://github.com/me-no-dev/arduino-esp32fs-plugin 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #include "AudioFileSourceID3.h" 16 | #include "AudioFileSourceSPIFFS.h" 17 | #include "AudioGeneratorMP3.h" 18 | #include "AudioOutputI2S.h" 19 | #include "SPIFFS.h" 20 | 21 | AudioGeneratorMP3 *mp3; 22 | AudioFileSourceSPIFFS *file; 23 | AudioOutputI2S *out; 24 | AudioFileSourceID3 *id3; 25 | 26 | void setup() { 27 | M5.begin(); 28 | M5.Power.begin(); 29 | WiFi.mode(WIFI_OFF); 30 | SPIFFS.begin(); 31 | delay(500); 32 | 33 | M5.Lcd.setTextFont(2); 34 | M5.Lcd.printf("Sample MP3 playback begins...\n"); 35 | Serial.printf("Sample MP3 playback begins...\n"); 36 | 37 | // pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html 38 | file = new AudioFileSourceSPIFFS("/pno-cs.mp3"); 39 | id3 = new AudioFileSourceID3(file); 40 | out = new AudioOutputI2S(0, 1); // Output to builtInDAC 41 | out->SetOutputModeMono(true); 42 | mp3 = new AudioGeneratorMP3(); 43 | mp3->begin(id3, out); 44 | } 45 | 46 | void loop() { 47 | if (mp3->isRunning()) { 48 | if (!mp3->loop()) mp3->stop(); 49 | } else { 50 | Serial.printf("MP3 done\n"); 51 | delay(1000); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/Advanced/Audio/PlayMP3FromSPIFFSToDAC/data/pno-cs.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Advanced/Audio/PlayMP3FromSPIFFSToDAC/data/pno-cs.mp3 -------------------------------------------------------------------------------- /examples/Advanced/Audio/PlayWAVFromSDToDAC/PlayWAVFromSDToDAC.ino: -------------------------------------------------------------------------------- 1 | #pragma mark - Depend ESP8266Audio and ESP8266_Spiram libraries 2 | /* 3 | cd ~/Arduino/libraries 4 | git clone https://github.com/earlephilhower/ESP8266Audio 5 | git clone https://github.com/Gianbacchio/ESP8266_Spiram 6 | 7 | Use the "Tools->ESP32 Sketch Data Upload" menu to write the MP3 to SPIFFS 8 | Then upload the sketch normally. 9 | https://github.com/me-no-dev/arduino-esp32fs-plugin 10 | */ 11 | 12 | #include 13 | #include 14 | 15 | #include "AudioFileSourceSD.h" 16 | #include "AudioGeneratorWAV.h" 17 | #include "AudioOutputI2S.h" 18 | 19 | AudioGeneratorWAV *wav; 20 | AudioFileSourceSD *file; 21 | AudioOutputI2S *out; 22 | 23 | void setup() { 24 | M5.begin(); 25 | M5.Power.begin(); 26 | WiFi.mode(WIFI_OFF); 27 | delay(500); 28 | 29 | M5.Lcd.setTextFont(2); 30 | M5.Lcd.printf("Sample WAV playback begins...\n"); 31 | Serial.printf("Sample WAV playback begins...\n"); 32 | 33 | // pno_cs from https://ccrma.stanford.edu/~jos/pasp/Sound_Examples.html 34 | file = new AudioFileSourceSD("/pno-cs.wav"); 35 | out = new AudioOutputI2S(0, 1); // Output to builtInDAC 36 | out->SetOutputModeMono(true); 37 | wav = new AudioGeneratorWAV(); 38 | wav->begin(file, out); 39 | } 40 | 41 | void loop() { 42 | if (wav->isRunning()) { 43 | if (!wav->loop()) wav->stop(); 44 | } else { 45 | Serial.printf("WAV done\n"); 46 | delay(1000); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/Advanced/Blynk/Post-DHT12/DHT12.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DHT12.cpp - Library for DHT12 sensor. 3 | v0.0.1 Beta 4 | Created by Bobadas, July 30,2016. 5 | Released into the public domain. 6 | */ 7 | #include "DHT12.h" 8 | 9 | #include "Arduino.h" 10 | #include "Wire.h" 11 | 12 | DHT12::DHT12(byte scale, byte id) { 13 | if (id == 0 || id > 126) 14 | _id = 0x5c; 15 | else 16 | _id = id; 17 | if (scale == 0 || scale > 3) 18 | _scale = CELSIUS; 19 | else 20 | _scale = scale; 21 | } 22 | 23 | byte DHT12::read() { 24 | Wire.beginTransmission(_id); 25 | Wire.write(0); 26 | if (Wire.endTransmission() != 0) return 1; 27 | Wire.requestFrom(_id, 5); 28 | for (int i = 0; i < 5; i++) { 29 | datos[i] = Wire.read(); 30 | }; 31 | delay(50); 32 | if (Wire.available() != 0) return 2; 33 | if (datos[4] != (datos[0] + datos[1] + datos[2] + datos[3])) return 3; 34 | return 0; 35 | } 36 | 37 | float DHT12::readTemperature(byte scale) { 38 | float resultado = 0; 39 | byte error = read(); 40 | if (error != 0) return (float)error / 100; 41 | if (scale == 0) scale = _scale; 42 | switch (scale) { 43 | case CELSIUS: 44 | resultado = (datos[2] + (float)datos[3] / 10); 45 | break; 46 | case FAHRENHEIT: 47 | resultado = ((datos[2] + (float)datos[3] / 10) * 1.8 + 32); 48 | break; 49 | case KELVIN: 50 | resultado = (datos[2] + (float)datos[3] / 10) + 273.15; 51 | break; 52 | }; 53 | return resultado; 54 | } 55 | 56 | float DHT12::readHumidity() { 57 | float resultado; 58 | byte error = read(); 59 | if (error != 0) return (float)error / 100; 60 | resultado = (datos[0] + (float)datos[1] / 10); 61 | return resultado; 62 | } 63 | -------------------------------------------------------------------------------- /examples/Advanced/Blynk/Post-DHT12/DHT12.h: -------------------------------------------------------------------------------- 1 | /* 2 | DHT12.h - Library for DHT12 sensor. 3 | v0.0.1 Beta 4 | Created by Bobadas, July 30,2016. 5 | Released into the public domain. 6 | */ 7 | #ifndef DHT12_h 8 | #define DHT12_h 9 | #include "Arduino.h" 10 | #include "Wire.h" 11 | 12 | #define CELSIUS 1 13 | #define KELVIN 2 14 | #define FAHRENHEIT 3 15 | 16 | class DHT12 { 17 | public: 18 | DHT12(byte scale = 0, byte id = 0); 19 | float readTemperature(byte scale = 0); 20 | float readHumidity(); 21 | 22 | private: 23 | byte read(); 24 | byte datos[5]; 25 | byte _id; 26 | byte _scale; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/Advanced/Display/Bmp_Jpg_SPIFFS_draw/Bmp_Jpg_SPIFFS_draw.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * You only need to format SPIFFS the first time you run a 3 | test or else use the SPIFFS plugin to create a partition 4 | https://github.com/me-no-dev/arduino-esp32fs-plugin 5 | * put jpg or bmp file in (/data) 6 | * Select Tools > ESP32 Sketch Data Upload menu item. This should start 7 | uploading the files into ESP32 flash file system. 8 | */ 9 | 10 | #include "FS.h" 11 | #include "M5Stack.h" 12 | #include "SPIFFS.h" 13 | 14 | void setup() { 15 | M5.begin(true, false, true, false); 16 | M5.Power.begin(); 17 | if (!SPIFFS.begin(true)) { 18 | Serial.println("SPIFFS Mount Failed"); 19 | return; 20 | } 21 | M5.Lcd.drawJpgFile(SPIFFS, "/m5_logo.jpg", 0, 0); 22 | } 23 | 24 | void loop() { 25 | M5.update(); 26 | if (M5.BtnA.wasPressed()) { 27 | M5.Lcd.drawBmpFile(SPIFFS, "/pcd.bmp", 0, 0); 28 | } 29 | if (M5.BtnB.wasPressed()) { 30 | M5.Lcd.drawJpgFile(SPIFFS, "/m5_logo.jpg", 0, 0); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/Advanced/Display/Bmp_Jpg_SPIFFS_draw/data/m5_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Advanced/Display/Bmp_Jpg_SPIFFS_draw/data/m5_logo.jpg -------------------------------------------------------------------------------- /examples/Advanced/Display/Bmp_Jpg_SPIFFS_draw/data/pcd.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Advanced/Display/Bmp_Jpg_SPIFFS_draw/data/pcd.bmp -------------------------------------------------------------------------------- /examples/Advanced/Display/Display_Unicode/README.md: -------------------------------------------------------------------------------- 1 | Please modify /src/utility/In_eSPI_Setup.h, At the end of the file add "#define USE_M5_FONT_CREATOR" 2 | 3 | if use PlatformIO, need add "board_build.partitions = no_ota.csv" in platformio.ini 4 | 5 | if want get customize unicode, try use https://github.com/m5stack/FontCreator, create font file 6 | 7 | if add "#define USE_M5_FONT_CREATOR" and want to use standard gfx font, need modify font file 8 | #ifdef USE_M5_FONT_CREATOR 9 | 0, 0, 10 | #endif 11 | like: 12 | 13 | ``` cpp 14 | const GFXfont FreeMono12pt7b PROGMEM = { 15 | (uint8_t *)FreeMono12pt7bBitmaps, 16 | (GFXglyph *)FreeMono12pt7bGlyphs, 17 | 0x20, 0x7E, 24, 18 | #ifdef USE_M5_FONT_CREATOR 19 | 0, 0, 20 | #endif 21 | } 22 | ``` 23 | 24 | 25 | 26 | 27 | 28 | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 29 | zh: 30 | 如果编译过程中出现错误,请在/src/utility/In_eSPI_Setup.h 中最后一行添加#define USE_M5_FONT_CREATOR 31 | 32 | 如果你使用platformIO,需要在platformio.ini中添加board_build.partitions = no_ota.csv 33 | 34 | 如果你想自定义unicode,请尝试使用https://github.com/m5stack/FontCreator 去创建相关字体文件 35 | 36 | 如果添加了“#define USE_M5_FONT_CREATOR”,并且想使用标准的gfx字体,需要修改CUF_24px.h文件 37 | 38 | 39 | ```cpp 40 | #ifdef USE_M5_FONT_CREATOR 41 | #define _unicode_24px_H_ 42 | const GFXfont FreeMono12pt7b PROGMEM = { 43 | (uint8_t *)FreeMono12pt7bBitmaps, 44 | (GFXglyph *)FreeMono12pt7bGlyphs, 45 | 0x20, 0x7E, 24, 46 | }; 47 | 48 | #endif 49 | ``` 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /examples/Advanced/Display/HZK16/README.md: -------------------------------------------------------------------------------- 1 | HZK16 is the GB2312 Chinese encoding format font, so it is normal that GbkStr is displayed as garbled in the src.h file 2 | To display Chinese normally, notepad++ or other software (UTF-8 for Arduino IDE) should be used to open str.h with encoding GB2312 3 | Modify the content in GbkStr to replace it with the character you want to display 4 | 5 | HZK16为GB2312中文编码格式字库, 故在 src.h 文件中 GbkStr 显示为乱码为正常现象 6 | 若要正常显示中文应使用notepad++或其它软件(Arduino IDE 为UTF-8)使用编码GB2312打开str.h 7 | 修改GbkStr里的内容即可更换为想要显示的字符 -------------------------------------------------------------------------------- /examples/Advanced/Display/HZK16/str.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Advanced/Display/HZK16/str.h -------------------------------------------------------------------------------- /examples/Advanced/Display/JpegDraw/JpegDraw.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup(void) { 4 | M5.begin(); 5 | M5.Power.begin(); 6 | // Draw the jpeg file "p2.jpg" from TF(SD) card 7 | M5.Lcd.setBrightness(200); 8 | M5.Lcd.drawJpgFile(SD, "/p2.jpg"); 9 | // M5.Lcd.drawJpgFile(SD, "/p1.jpg", 20, 30, 40, 50); 10 | // M5.Lcd.drawJpgFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y, 11 | // uint16_t maxWidth, uint16_t maxHeight, uint16_t offX, uint16_t offY, 12 | // jpeg_div_t scale); 13 | } 14 | 15 | void loop() { 16 | } 17 | -------------------------------------------------------------------------------- /examples/Advanced/Display/TFT_Ellipse/TFT_Ellipse.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2023 by M5Stack 4 | * Equipped with M5Core sample source code 5 | * 配套 M5Core 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/gray 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray 8 | * 9 | * Describe: Ellipse drawing. 椭圆绘制 10 | * Date: 2021/7/26 11 | *******************************************************************************/ 12 | 13 | #include 14 | 15 | void setup(void) { 16 | M5.begin(); // Init M5Stack. 初始化M5Stack 17 | M5.Power.begin(); // Init power 初始化电源模块 18 | } 19 | 20 | void loop() { 21 | // Draw some random ellipses. 绘制一些随机形状的椭圆 22 | for (int i = 0; i < 40; i++) { 23 | int rx = random(60); 24 | int ry = random(60); 25 | int x = rx + random(320 - rx - rx); 26 | int y = ry + random(240 - ry - ry); 27 | M5.Lcd.fillEllipse( 28 | x, y, rx, ry, 29 | random( 30 | 0xFFFF)); // At (x, y), draw a filled ellipse with random width 31 | // and height of rx, ry with random color random 32 | // (0xFFFF). 33 | // 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的填充椭圆 34 | } 35 | 36 | delay(2000); 37 | M5.Lcd.clear(); //清空屏幕 38 | 39 | for (int i = 0; i < 40; i++) { 40 | int rx = random(60); 41 | int ry = random(60); 42 | int x = rx + random(320 - rx - rx); 43 | int y = ry + random(240 - ry - ry); 44 | M5.Lcd.drawEllipse( 45 | x, y, rx, ry, 46 | random( 47 | 0xFFFF)); // At (x, y), draw an elliptical wire frame with a 48 | // random width and height of rx, ry in a random 49 | // color (0xFFFF). 50 | // 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的椭圆线框 51 | } 52 | 53 | delay(2000); 54 | } 55 | -------------------------------------------------------------------------------- /examples/Advanced/Display/drawXBitmap/drawXBitmap.ino: -------------------------------------------------------------------------------- 1 | // Example sketch to demonstrate the drawing of X BitMap (XBM) 2 | // format image onto the display. 3 | 4 | // Information on the X BitMap (XBM) format can be found here: 5 | // https://en.wikipedia.org/wiki/X_BitMap 6 | 7 | // This example is part of the TFT_eSPI library: 8 | // https://github.com/Bodmer/TFT_eSPI 9 | 10 | // Created by Bodmer 23/14/18 11 | 12 | #include // Hardware-specific library 13 | 14 | #include "xbm.h" // Sketch tab header for xbm images 15 | 16 | void setup() { 17 | M5.begin(); // Initialise the display 18 | M5.Power.begin(); 19 | M5.Lcd.fillScreen(TFT_BLACK); // Black screen fill 20 | } 21 | 22 | void loop() { 23 | // Example 1 24 | // ========= 25 | // Random x and y coordinates 26 | int x = random(M5.Lcd.width() - logoWidth); 27 | int y = random(M5.Lcd.height() - logoHeight); 28 | 29 | // Draw bitmap with top left corner at x,y with foreground only color 30 | // Bits set to 1 plot as the defined color, bits set to 0 are not plotted 31 | // x y xbm xbm width xbm height color 32 | M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_WHITE); 33 | 34 | delay(500); 35 | 36 | // Erase old one by drawing over with background colour 37 | M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_BLACK); 38 | 39 | // Example 2 40 | // ========= 41 | // New random x and y coordinates 42 | x = random(M5.Lcd.width() - logoWidth); 43 | y = random(M5.Lcd.height() - logoHeight); 44 | 45 | // Draw bitmap with top left corner at x,y with foreground and background 46 | // colors Bits set to 1 plot as the defined fg color, bits set to 0 are 47 | // plotted as bg color 48 | // x y xbm xbm width xbm height fg color bg color 49 | M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_WHITE, TFT_RED); 50 | 51 | delay(500); 52 | 53 | // Erase old one by drawing over with background colour 54 | M5.Lcd.drawXBitmap(x, y, logo, logoWidth, logoHeight, TFT_BLACK, TFT_BLACK); 55 | } 56 | -------------------------------------------------------------------------------- /examples/Advanced/Display/png_spiffs/data/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Advanced/Display/png_spiffs/data/test.png -------------------------------------------------------------------------------- /examples/Advanced/Display/png_spiffs/data/test1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Advanced/Display/png_spiffs/data/test1.png -------------------------------------------------------------------------------- /examples/Advanced/Display/png_spiffs/png_spiffs.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Need to format SPIFFS the first time you run a 3 | test or else use the SPIFFS plugin to create a partition 4 | https://github.com/me-no-dev/arduino-esp32fs-plugin 5 | * put png file in (/data) 6 | * Select Tools > ESP32 Sketch Data Upload menu item. This should start 7 | uploading the files into ESP32 flash file system. 8 | */ 9 | #include 10 | 11 | void setup() { 12 | M5.begin(); 13 | M5.Power.begin(); 14 | if (!SPIFFS.begin(true)) { 15 | Serial.println("SPIFFS Mount Failed"); 16 | return; 17 | } 18 | 19 | M5.Lcd.drawPngFile(SPIFFS, "/test.png", 0, 0); 20 | } 21 | 22 | void loop() { 23 | M5.update(); 24 | if (M5.BtnA.wasPressed()) { 25 | M5.Lcd.drawPngFile(SPIFFS, "/test.png", 0, 0); 26 | } 27 | 28 | if (M5.BtnB.wasPressed()) { 29 | M5.Lcd.drawPngFile(SPIFFS, "/test1.png", 0, 0); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/Advanced/MultSerial/MultSerial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2023 by M5Stack 4 | * Equipped with M5Core sample source code 5 | * 配套 M5Core 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/gray 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray 8 | * 9 | * Describe: MultSerial. 多串口 10 | * Date: 2021/8/5 11 | ****************************************************************************** 12 | */ 13 | #include 14 | 15 | void setup() { 16 | M5.begin(); // Init M5Core. 初始化 M5Core 17 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 18 | // txPin, bool invert) 19 | Serial2.begin(115200, SERIAL_8N1, 16, 20 | 17); // Init serial port 2. 初始化串口2 21 | } 22 | 23 | void loop() { 24 | if (Serial 25 | .available()) { // If the serial port reads data. 如果串口读到数据 26 | int ch = Serial.read(); // Copy the data read from the serial port to 27 | // the CH. 把串口读取到的数据复制给ch 28 | Serial2.write( 29 | ch); // Serial port 2 Outputs the CH content. 串口2输出ch的内容 30 | M5.Lcd.printf("Serial:%d\n", 31 | ch); // The screen prints the data received by serial 32 | // port 2. 屏幕打印串口2收到的数据 33 | } 34 | 35 | if (Serial2.available()) { 36 | int ch = Serial2.read(); 37 | Serial.write(ch); 38 | M5.Lcd.printf("Serial2:%d\n", ch); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/Advanced/QRCode/QRCode.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2023 by M5Stack 4 | * Equipped with M5Core sample source code 5 | * 配套 M5Core 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/gray 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray 8 | * 9 | * Describe: QRcode. 创建二维码 10 | * Date: 2021/7/26 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | 16 | void setup() { 17 | M5.begin(); // Init M5Stack. 初始化M5Stack 18 | M5.Power.begin(); // Init power 初始化电源模块 19 | M5.Lcd.qrcode( 20 | "http://www.m5stack.com", 0, 0, 150, 21 | 6); // Create a QR code with a width of 150 QR code with version 6 at 22 | // (0, 0). 在(0,0)处创建一个宽为150二维码版本为6的二维码 23 | // Please select the appropriate QR code version according to the number of 24 | // characters. 请根据字符数量选择合适的二维码版本 25 | } 26 | 27 | void loop() { 28 | } 29 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/Counter/Counter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2023 by M5Stack 4 | * Equipped with M5Core sample source code 5 | * 配套 M5Core 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/gray 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray 8 | * 9 | * Describe: counter. 计数器 10 | * Date: 2021/8/3 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | Preferences preferences; 18 | 19 | void setup() { 20 | M5.begin(); // Init M5Core. 初始化 M5Core 21 | M5.Power.begin(); // Init power 初始化电源模块 22 | M5.Lcd.setTextSize(2); 23 | preferences.begin( 24 | "my-app", 25 | false); // We will open storage in RW-mode (second parameter has to be 26 | // false). 27 | // 在perferences中创建叫my-app的空间,并以rw模式打开存储(第二个参数必须为false) 28 | 29 | // preferences.clear(); // Remove all preferences under the opened 30 | // namespace.清除preferences中所有的空间 31 | 32 | // preferences.remove("counter"); // Or remove the counter key only. 33 | // 只清除counter中的值 34 | 35 | unsigned int counter = preferences.getUInt( 36 | "counter", 37 | 0); // Get the counter value in current sapce, if the key does not 38 | // exist, return a default value of 0. 39 | // 在当前空间中读取counter的值(若不存在为0),并赋值给counter 40 | counter++; // Increase counter by 1. 使计数器的值加一 41 | M5.Lcd.printf( 42 | "Current counter value: %u\n", 43 | counter); // Print the counter to Serial Monitor. 串口输出计数器的值 44 | preferences.putUInt( 45 | "counter", 46 | counter); // Store the counter to the Preferences. 存储计数器的值 47 | preferences.end(); // Close the Preferences. 关闭Preferences 48 | M5.Lcd.println("Restarting in 10 seconds.."); 49 | delay(10000); // delay 10. 延迟10s 50 | ESP.restart(); // Restart. 重启 51 | } 52 | void loop() { 53 | } 54 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/SPIFFS/SPIFFS_Delete/SPIFFS_Delete.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2023 by M5Stack 4 | * Equipped with M5Core sample source code 5 | * 配套 M5Core 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/gray 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray 8 | * 9 | * Describe: SPIFFS Delete 10 | * Date: 2021/8/4 11 | ****************************************************************************** 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | String file_name = 18 | "/M5Stack/notes.txt"; // Sets the location and name of the file to be 19 | // operated on. 设置被操作的文件位置和名称 20 | void setup() { 21 | M5.begin(); // Init M5Core. 初始化 M5Core 22 | M5.Power.begin(); // Init power 初始化电源模块 23 | M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字号大小为2 24 | if (SPIFFS.begin()) { // Start SPIFFS, return 1 on success. 25 | // 启动闪存文件系统,若成功返回1 26 | M5.Lcd.println("\nSPIFFS Started."); // Screen prints format String. 27 | // 屏幕打印格式化字符串 28 | } else { 29 | M5.Lcd.println("SPIFFS Failed to Start."); 30 | } 31 | 32 | if (SPIFFS.remove( 33 | file_name)) { // Delete file_name file from flash, return 1 on 34 | // success. 从闪存中删除file_name文件,如果成功返回1 35 | M5.Lcd.print(file_name); 36 | M5.Lcd.println(" Remove sucess"); 37 | } else { 38 | M5.Lcd.print(file_name); 39 | M5.Lcd.println(" Remove fail"); 40 | } 41 | } 42 | 43 | void loop() { 44 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "array": "cpp", 4 | "deque": "cpp", 5 | "string": "cpp", 6 | "unordered_map": "cpp", 7 | "vector": "cpp", 8 | "string_view": "cpp", 9 | "initializer_list": "cpp" 10 | } 11 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiMulti/WiFiMulti.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2023 by M5Stack 4 | * Equipped with M5Core sample source code 5 | * 配套 M5Core 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/gray 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray 8 | * 9 | * Describe: WIFI Multi. 多wifi择优 10 | * Date: 2021/7/29 11 | ******************************************************************************* 12 | * Connect to the best AP based on a given wifi list 13 | * 根据给定wifi的列表连接到最好的AP 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | WiFiMulti wifiMulti; 21 | 22 | void setup() { 23 | M5.begin(); // Init M5Core. 初始化 M5Core 24 | M5.Power.begin(); // Init power 初始化电源模块 25 | wifiMulti.addAP("wifi1", "123456"); // Storage wifi configuration 26 | // information 1. 存储wifi配置信息1 27 | wifiMulti.addAP("wifi2", "123456123456"); 28 | wifiMulti.addAP("aaa", "sadf"); 29 | M5.lcd.print("Connecting Wifi..."); // Serial port format output string. 30 | // 串口格式化输出字符串 31 | } 32 | 33 | void loop() { 34 | if (wifiMulti.run() == 35 | WL_CONNECTED) { // If the connection to wifi is established 36 | // successfully. 如果与wifi成功建立连接 37 | M5.lcd.setCursor(0, 20); 38 | M5.lcd.print("WiFi connected\n\nSSID:"); 39 | M5.lcd.println(WiFi.SSID()); // Output Network name. 输出网络名称 40 | M5.lcd.print("RSSI: "); 41 | M5.lcd.println(WiFi.RSSI()); // Output signal strength. 输出信号强度 42 | M5.lcd.print("IP address: "); 43 | M5.lcd.println(WiFi.localIP()); // Output IP Address. 输出IP地址 44 | delay(1000); 45 | M5.lcd.fillRect(0, 20, 180, 300, 46 | BLACK); // It's equivalent to partial screen clearance. 47 | // 相当于部分清屏 48 | } else { 49 | // If the connection to wifi is not established successfully. 50 | // 如果没有与wifi成功建立连接 51 | M5.lcd.print("."); 52 | delay(1000); 53 | } 54 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiSetting/detail/RequestHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef REQUESTHANDLER_H 2 | #define REQUESTHANDLER_H 3 | 4 | class RequestHandler { 5 | public: 6 | virtual ~RequestHandler() { 7 | } 8 | virtual bool canHandle(HTTPMethod method, String uri) { 9 | (void)method; 10 | (void)uri; 11 | return false; 12 | } 13 | virtual bool canUpload(String uri) { 14 | (void)uri; 15 | return false; 16 | } 17 | virtual bool handle(WebServer& server, HTTPMethod requestMethod, 18 | String requestUri) { 19 | (void)server; 20 | (void)requestMethod; 21 | (void)requestUri; 22 | return false; 23 | } 24 | virtual void upload(WebServer& server, String requestUri, 25 | HTTPUpload& upload) { 26 | (void)server; 27 | (void)requestUri; 28 | (void)upload; 29 | } 30 | 31 | RequestHandler* next() { 32 | return _next; 33 | } 34 | void next(RequestHandler* r) { 35 | _next = r; 36 | } 37 | 38 | private: 39 | RequestHandler* _next = nullptr; 40 | }; 41 | 42 | #endif // REQUESTHANDLER_H 43 | -------------------------------------------------------------------------------- /examples/Basics/HelloWorld/HelloWorld.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core sample source code 5 | * 配套 M5Core 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/gray 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/gray 8 | * 9 | * Describe: Hello World 10 | * Date: 2021/7/15 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | /* After M5Core is started or reset 16 | the program in the setUp () function will be run, and this part will only be run 17 | once. 在 M5Core 18 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 19 | void setup() { 20 | M5.begin(); // Init M5Core. 初始化 M5Core 21 | M5.Power.begin(); // Init Power module. 初始化电源模块 22 | /* Power chip connected to gpio21, gpio22, I2C device 23 | Set battery charging voltage and current 24 | If used battery, please call this function in your project */ 25 | M5.Lcd.print("Hello World"); // Print text on the screen (string) 26 | // 在屏幕上打印文本(字符串) 27 | } 28 | 29 | /* After the program in setup() runs, it runs the program in loop() 30 | The loop() function is an infinite loop in which the program runs repeatedly 31 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 32 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 33 | void loop() { 34 | } -------------------------------------------------------------------------------- /examples/Face/FACESII_RGB_BAR/FACESII_RGB_BAR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | neo pixel test 3 | 4 | hardwware: M5StackFire 5 | 6 | please install the Adafruit library first! 7 | September 2018, ChrisMicro 8 | */ 9 | 10 | #include 11 | 12 | #define M5STACK_FIRE_NEO_NUM_LEDS 10 13 | #define M5STACK_FIRE_NEO_DATA_PIN 15 14 | 15 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel( 16 | M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN, NEO_GRB + NEO_KHZ800); 17 | 18 | void setup() { 19 | pixels.begin(); 20 | } 21 | 22 | void loop() { 23 | static int pixelNumber = 0; // = random(0, M5STACK_FIRE_NEO_NUM_LEDS - 1); 24 | pixelNumber++; 25 | if (pixelNumber > 9) pixelNumber = 0; 26 | int r = 1 << random(0, 7); 27 | int g = 1 << random(0, 7); 28 | int b = 1 << random(0, 7); 29 | 30 | pixels.setPixelColor(pixelNumber, pixels.Color(r, g, b)); 31 | pixels.show(); 32 | 33 | delay(100); 34 | } 35 | -------------------------------------------------------------------------------- /examples/Face/KEYBOARD/KEYBOARD.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define KEYBOARD_I2C_ADDR 0X08 4 | #define KEYBOARD_INT 5 5 | 6 | void setup() { 7 | M5.begin(); 8 | M5.Power.begin(); 9 | Wire.begin(); 10 | M5.Lcd.setTextFont(2); 11 | M5.Lcd.println("FACES Keyboard I2C Read Example"); 12 | pinMode(KEYBOARD_INT, INPUT_PULLUP); 13 | } 14 | 15 | void loop() { 16 | if (digitalRead(KEYBOARD_INT) == LOW) { 17 | Wire.requestFrom(KEYBOARD_I2C_ADDR, 1); // request 1 byte from keyboard 18 | while (Wire.available()) { 19 | uint8_t key_val = Wire.read(); // receive a byte as character 20 | if (key_val != 0) { 21 | if (key_val >= 0x20 && key_val < 0x7F) { // ASCII String 22 | Serial.print((char)key_val); 23 | M5.Lcd.print((char)key_val); 24 | } else { 25 | Serial.printf("0x%02X ", key_val); 26 | M5.Lcd.printf("0x%02X ", key_val); 27 | } 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/Face/Snake_Gameboy/GameboyInput.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * M5Snake : Input management from Gameboy faces * 3 | * --------------------------------------------- * 4 | * Management of input coming from the face Gameboy * 5 | * Author: Olivier Staquet * 6 | * Last version available on https://github.com/ostaquet/M5Snake * 7 | *****************************************************************************/ 8 | #include "GameboyInput.h" 9 | 10 | /** 11 | * Initialize 12 | */ 13 | void GameboyInputClass::begin(uint8_t _i2c_address, uint8_t _pin_int_face) { 14 | // Store local info 15 | i2c_address = _i2c_address; 16 | pin_int_face = _pin_int_face; 17 | 18 | // Prepare the detection of activity 19 | pinMode(pin_int_face, INPUT_PULLUP); 20 | 21 | // Init the I2C 22 | Wire.begin(); 23 | } 24 | 25 | /** 26 | * Check if button pressed and return which one 27 | */ 28 | uint8_t GameboyInputClass::getActivity() { 29 | // Check if there is activity on interrupt 30 | if (digitalRead(pin_int_face) == LOW) { 31 | // If yes, request 1 byte from the panel 32 | Wire.requestFrom(i2c_address, (uint8_t)1); 33 | 34 | // Check if data on the I2C is available 35 | while (Wire.available()) { 36 | // Receive one byte as character 37 | uint8_t key_val = Wire.read(); 38 | if (key_val != 0x00) { 39 | return key_val; 40 | } 41 | } 42 | } 43 | 44 | // No activity to send back 45 | return GAMEBOY_KEY_NONE; 46 | } 47 | 48 | GameboyInputClass GameboyInput; 49 | -------------------------------------------------------------------------------- /examples/Face/Snake_Gameboy/GameboyInput.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * M5Snake : Input management from Gameboy faces * 3 | * --------------------------------------------- * 4 | * Management of input coming from the face Gameboy * 5 | * Author: Olivier Staquet * 6 | * Last version available on https://github.com/ostaquet/M5Snake * 7 | *****************************************************************************/ 8 | #ifndef _GAMEBOYINPUT_H_ 9 | #define _GAMEBOYINPUT_H_ 10 | 11 | #include 12 | 13 | #include "Wire.h" 14 | 15 | #define GAMEBOY_KEY_NONE 0x00 16 | #define GAMEBOY_KEY_RELEASED 0xFF 17 | #define GAMEBOY_KEY_START 0x7F 18 | #define GAMEBOY_KEY_SELECT 0xBF 19 | #define GAMEBOY_KEY_A 0xEF 20 | #define GAMEBOY_KEY_B 0xDF 21 | #define GAMEBOY_KEY_UP 0xFE 22 | #define GAMEBOY_KEY_DOWN 0xFD 23 | #define GAMEBOY_KEY_LEFT 0xFB 24 | #define GAMEBOY_KEY_RIGHT 0xF7 25 | 26 | class GameboyInputClass { 27 | public: 28 | // Initialize 29 | void begin(uint8_t _i2c_address = 0x08, uint8_t _pin_int_face = 5); 30 | 31 | // Check if button pressed and return which one 32 | uint8_t getActivity(); 33 | 34 | private: 35 | // I2C address 36 | uint8_t i2c_address = 0x00; 37 | // PIN for interrupt of the Face 38 | uint8_t pin_int_face = 0x00; 39 | }; 40 | 41 | extern GameboyInputClass GameboyInput; 42 | 43 | #endif // _GAMEBOYINPUT_H_ 44 | -------------------------------------------------------------------------------- /examples/Face/Snake_Gameboy/Power.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * M5Snake : Power management * 3 | * -------------------------- * 4 | * Management of the charge of the battery to avoid over charging * 5 | * Author: Olivier Staquet * 6 | * Last version available on https://github.com/ostaquet/M5Snake * 7 | *****************************************************************************/ 8 | #include "Power.h" 9 | 10 | /** 11 | * Initialize 12 | */ 13 | void PowerClass::begin() { 14 | // Initialize the power management module (based on IP5306 chip) 15 | M5.Power.begin(); 16 | 17 | // Check if the control can be operated 18 | canControl = M5.Power.canControl(); 19 | } 20 | 21 | /** 22 | * Adapt charging mode to avoid excessive charging 23 | */ 24 | void PowerClass::adaptChargeMode() { 25 | // If power management not available, ignore the routine 26 | if (!canControl) { 27 | return; 28 | } 29 | 30 | // Disable the charging if the battery is fully charged 31 | if (M5.Power.isChargeFull()) { 32 | M5.Power.setCharge(false); 33 | } else { 34 | M5.Power.setCharge(true); 35 | } 36 | 37 | // Define the shutdown time at 64s 38 | M5.Power.setLowPowerShutdownTime(M5.Power.ShutdownTime::SHUTDOWN_64S); 39 | } 40 | 41 | /** 42 | * Return battery level (0-100%) 43 | * (-1 if cannot communicate with the controller) 44 | */ 45 | int8_t PowerClass::getBatteryLevel() { 46 | return M5.Power.getBatteryLevel(); 47 | } 48 | 49 | PowerClass Power; 50 | -------------------------------------------------------------------------------- /examples/Face/Snake_Gameboy/Power.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * M5Snake : Power management * 3 | * -------------------------- * 4 | * Management of the charge of the battery to avoid over charging * 5 | * Author: Olivier Staquet * 6 | * Last version available on https://github.com/ostaquet/M5Snake * 7 | *****************************************************************************/ 8 | #ifndef _POWER_H_ 9 | #define _POWER_H_ 10 | 11 | #include 12 | #include 13 | 14 | class PowerClass { 15 | public: 16 | // Initialize 17 | void begin(); 18 | 19 | // Adjust charge mode 20 | void adaptChargeMode(); 21 | 22 | // Return battery level (0-100%) 23 | // (-1 if cannot communicate with the controller) 24 | int8_t getBatteryLevel(); 25 | 26 | private: 27 | // Power control available 28 | bool canControl = false; 29 | }; 30 | 31 | extern PowerClass Power; 32 | 33 | #endif // _POWER_H_ 34 | -------------------------------------------------------------------------------- /examples/Fire/Microphone/Microphone.ino: -------------------------------------------------------------------------------- 1 | /* 2 | microphone test 3 | 4 | hardwware: M5StackFire 5 | 6 | please use the serial plotter in the Arduino IDE to show the signal 7 | change the baudrate of the plotter to 115200 8 | 9 | September 2018, ChrisMicro 10 | */ 11 | 12 | #define M5STACKFIRE_MICROPHONE_PIN 34 13 | 14 | void setup() { 15 | Serial.begin(115200); 16 | } 17 | 18 | void loop() { 19 | int micValue = analogRead(M5STACKFIRE_MICROPHONE_PIN); 20 | 21 | Serial.println(micValue); 22 | delay(1); 23 | } 24 | -------------------------------------------------------------------------------- /examples/Fire/RGB_BAR_TEST/RGB_BAR_TEST.ino: -------------------------------------------------------------------------------- 1 | /* 2 | neo pixel test 3 | 4 | hardwware: M5StackFire 5 | 6 | please install the Adafruit library first! 7 | September 2018, ChrisMicro 8 | */ 9 | 10 | #include 11 | 12 | #define M5STACK_FIRE_NEO_NUM_LEDS 10 13 | #define M5STACK_FIRE_NEO_DATA_PIN 15 14 | 15 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel( 16 | M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN, NEO_GRB + NEO_KHZ800); 17 | 18 | void setup() { 19 | pixels.begin(); 20 | } 21 | 22 | void loop() { 23 | static int pixelNumber = 0; // = random(0, M5STACK_FIRE_NEO_NUM_LEDS - 1); 24 | pixelNumber++; 25 | if (pixelNumber > 9) pixelNumber = 0; 26 | int r = 1 << random(0, 7); 27 | int g = 1 << random(0, 7); 28 | int b = 1 << random(0, 7); 29 | 30 | pixels.setPixelColor(pixelNumber, pixels.Color(r, g, b)); 31 | pixels.show(); 32 | 33 | delay(100); 34 | } 35 | -------------------------------------------------------------------------------- /examples/Fire/RGB_BAR_VUmeter/RGB_BAR_VUmeter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | microphone neopixel VU meter 3 | 4 | Neopixel LEDS flash dependent on the microphone amplitude 5 | 6 | hardwware: M5StackFire 7 | 8 | please install the Adafruit library first! 9 | 10 | September 2018, ChrisMicro, MIT License 11 | 12 | */ 13 | 14 | #include 15 | 16 | #define M5STACK_FIRE_NEO_NUM_LEDS 10 17 | #define M5STACK_FIRE_NEO_DATA_PIN 15 18 | #define M5STACKFIRE_MICROPHONE_PIN 34 19 | 20 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel( 21 | M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN, NEO_GRB + NEO_KHZ800); 22 | 23 | void setup() { 24 | Serial.begin(115200); 25 | pixels.begin(); 26 | } 27 | 28 | #define NUMBEROFSAMPLES 1000 29 | uint16_t micValue[NUMBEROFSAMPLES]; 30 | 31 | void loop() { 32 | uint32_t power = 0; 33 | uint32_t meanValue = 0; 34 | for (uint32_t n = 0; n < NUMBEROFSAMPLES; n++) { 35 | int value = analogRead(M5STACKFIRE_MICROPHONE_PIN); 36 | micValue[n] = value; 37 | meanValue += value; 38 | delayMicroseconds(20); 39 | } 40 | meanValue /= NUMBEROFSAMPLES; 41 | for (uint32_t n = 0; n < NUMBEROFSAMPLES; n++) { 42 | power += (micValue[n] - meanValue) * (micValue[n] - meanValue); 43 | } 44 | power /= NUMBEROFSAMPLES; 45 | 46 | Serial.println(power); 47 | 48 | int threshold = 1000; 49 | for (uint8_t n = 0; n < M5STACK_FIRE_NEO_NUM_LEDS; n++) { 50 | pixels.setPixelColor(n, pixels.Color(0, 0, 1)); 51 | if (power > threshold) pixels.setPixelColor(n, pixels.Color(100, 0, 0)); 52 | threshold *= 5; 53 | } 54 | pixels.show(); 55 | delay(10); 56 | } 57 | -------------------------------------------------------------------------------- /examples/Fire/SpeakerDacSine/SpeakerDacSine.ino: -------------------------------------------------------------------------------- 1 | /* 2 | I2S sine wave 3 | This example produces a digital sine wave on the build in DAC1 4 | which is connected to the speaker 5 | 6 | Hardware: 7 | microcontroller board: M5StackFire 8 | speaker amplifier internaly connected to DAC pin 25 9 | 10 | September 2018 ChrisMicro 11 | */ 12 | 13 | #define DACPIN 25 // speaker DAC, only 8 Bit 14 | 15 | #define SAMPLINGFREQUENCY 44100 16 | #define NUMBEROFSAMPLES SAMPLINGFREQUENCY * 1 // paly 1 seconds 17 | 18 | #define DAC_MAX_AMPLITUDE 127 / 4 // max value is 127, but it is too loud 19 | 20 | #define AUDIOBUFFERLENGTH NUMBEROFSAMPLES 21 | 22 | uint8_t AudioBuffer[AUDIOBUFFERLENGTH]; 23 | 24 | void setup() { 25 | const float frequency = 440; 26 | const float amplitude = DAC_MAX_AMPLITUDE; 27 | 28 | // store sine wave in buffer 29 | for (int n = 0; n < NUMBEROFSAMPLES; n++) { 30 | int16_t sineWaveSignal = 31 | (sin(2 * PI * frequency / SAMPLINGFREQUENCY * n)) * amplitude; 32 | AudioBuffer[n] = sineWaveSignal + 128; 33 | } 34 | } 35 | 36 | void loop() { 37 | uint32_t start = micros(); 38 | 39 | for (int n = 0; n < NUMBEROFSAMPLES; n++) { 40 | // wait for next sample 41 | while (start + (1000000UL / SAMPLINGFREQUENCY) > micros()) 42 | ; 43 | start = micros(); 44 | 45 | dacWrite(DACPIN, AudioBuffer[n]); 46 | } 47 | 48 | delay(3000); 49 | } 50 | -------------------------------------------------------------------------------- /examples/Games/Tetris/tetris.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Games/Tetris/tetris.jpg -------------------------------------------------------------------------------- /examples/KIT/PM25/DFRobot_SHT20.h: -------------------------------------------------------------------------------- 1 | #ifndef DFRobot_SHT20_h 2 | #define DFRobot_SHT20_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | #include 10 | 11 | #define ERROR_I2C_TIMEOUT 998 12 | #define ERROR_BAD_CRC 999 13 | #define SLAVE_ADDRESS 0x40 14 | #define TRIGGER_TEMP_MEASURE_HOLD 0xE3 15 | #define TRIGGER_HUMD_MEASURE_HOLD 0xE5 16 | #define TRIGGER_TEMP_MEASURE_NOHOLD 0xF3 17 | #define TRIGGER_HUMD_MEASURE_NOHOLD 0xF5 18 | #define WRITE_USER_REG 0xE6 19 | #define READ_USER_REG 0xE7 20 | #define SOFT_RESET 0xFE 21 | #define USER_REGISTER_RESOLUTION_MASK 0x81 22 | #define USER_REGISTER_RESOLUTION_RH12_TEMP14 0x00 23 | #define USER_REGISTER_RESOLUTION_RH8_TEMP12 0x01 24 | #define USER_REGISTER_RESOLUTION_RH10_TEMP13 0x80 25 | #define USER_REGISTER_RESOLUTION_RH11_TEMP11 0x81 26 | #define USER_REGISTER_END_OF_BATTERY 0x40 27 | #define USER_REGISTER_HEATER_ENABLED 0x04 28 | #define USER_REGISTER_DISABLE_OTP_RELOAD 0x02 29 | #define MAX_WAIT 100 30 | #define DELAY_INTERVAL 10 31 | #define SHIFTED_DIVISOR 0x988000 32 | #define MAX_COUNTER (MAX_WAIT / DELAY_INTERVAL) 33 | 34 | class DFRobot_SHT20 { 35 | public: 36 | void checkSHT20(void); 37 | void setResolution(byte resBits); 38 | void writeUserRegister(byte val); 39 | void initSHT20(TwoWire &wirePort = Wire); 40 | void showReslut(const char *prefix, int val); 41 | float readHumidity(void); 42 | float readTemperature(void); 43 | byte readUserRegister(void); 44 | 45 | private: 46 | TwoWire *i2cPort; 47 | byte checkCRC(uint16_t message_from_sensor, 48 | uint8_t check_value_from_sensor); 49 | uint16_t readValue(byte cmd); 50 | }; 51 | 52 | #endif -------------------------------------------------------------------------------- /examples/Modules/AC-SOCKET/protocol.h: -------------------------------------------------------------------------------- 1 | #ifndef __PROTOCOL__H 2 | #define __PROTOCOL__H 3 | 4 | #include "Arduino.h" 5 | 6 | /*֡ͷ����*/ 7 | #define FRAME_HEADER_LENGTH 1U 8 | 9 | /*֡β����(��У���)*/ 10 | #define FRAME_TAIL_LENGTH 1U 11 | 12 | /*֡ͷ��ͬ�ֽ�*/ 13 | #define FRAME_HEAD_SAME_FA 0xFA 14 | 15 | /*���ջ���������*/ 16 | #define RX_BUF_LENGTH 64U 17 | #define RX_END_LENGTH 1U 18 | 19 | typedef struct { 20 | uint8_t cmd_id; 21 | uint8_t ack_flag; 22 | uint8_t *cmd_value; 23 | uint16_t cmd_length; 24 | } PayloadData; 25 | 26 | typedef struct { 27 | uint8_t src; 28 | uint8_t dst; 29 | uint8_t seq; 30 | uint8_t res; 31 | PayloadData payload; 32 | } CmdData; 33 | 34 | /*����Э�鹫������*/ 35 | typedef struct { 36 | volatile uint8_t step; /*switch �����ת����*/ 37 | volatile int8_t tmpCnt; /*���ڼ�������ʱ����*/ 38 | volatile uint8_t aRxBufIndex; /*�������ݻ���������*/ 39 | volatile uint8_t aRxCrcIndex; /*��β���ݻ���������*/ 40 | uint8_t aRxCrc[RX_END_LENGTH]; 41 | uint8_t aRxBuf[RX_BUF_LENGTH]; 42 | } protocolComType_t; 43 | 44 | extern void protocol_rec_put(uint8_t data); 45 | extern void protocol_send_data(CmdData dat); 46 | 47 | #endif -------------------------------------------------------------------------------- /examples/Modules/BALA/imuCalibration.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Sorzn 3 | * @Date: 2020-01-06 11:00:49 4 | * @LastEditTime : 2020-01-06 15:15:40 5 | * @Description: M5Stack project 6 | * @FilePath: 7 | * /home/sakabin/Arduino/libraries/M5Stack/examples/Modules/Bala/imuAuto.cpp 8 | */ 9 | 10 | #include "imuCalibration.h" 11 | 12 | static float gyroXOffset = 0; 13 | static float gyroYOffset = 0; 14 | static float gyroZOffset = 0; 15 | 16 | static float accX = 0; 17 | static float accY = 0; 18 | static float accZ = 0; 19 | 20 | static float gyroX = 0; 21 | static float gyroY = 0; 22 | static float gyroZ = 0; 23 | 24 | static float angleAccX = 0; 25 | static float angleGyroX = 0; 26 | static float angleX = 0; 27 | 28 | static uint32_t preInterval = 0; 29 | 30 | void imu_CalcInit() { 31 | M5.IMU.Init(); 32 | M5.IMU.setGyroFsr(M5.IMU.GFS_1000DPS); 33 | } 34 | 35 | void imu_setOffsetX(float x) { 36 | gyroXOffset = x; 37 | } 38 | 39 | float imu_getOffsetX() { 40 | return gyroXOffset; 41 | } 42 | 43 | void imu_calcGyroOffsets() { 44 | float x = 0, y = 0, z = 0; 45 | float x_total = 0, y_total = 0, z_total = 0; 46 | 47 | for (int i = 0; i < 3000; i++) { 48 | M5.IMU.getGyroData(&x, &y, &z); 49 | x_total += x; 50 | } 51 | 52 | gyroXOffset = x_total / 3000; 53 | } 54 | 55 | void imu_update() { 56 | float interval; 57 | if (preInterval == 0) preInterval = millis(); 58 | 59 | M5.IMU.getGyroData(&gyroX, &gyroY, &gyroZ); 60 | M5.IMU.getAccelData(&accX, &accY, &accZ); 61 | 62 | angleAccX = atan2(accY, sqrt(accZ * accZ + accX * accX)) * 360 / 2.0 / PI; 63 | 64 | gyroX -= gyroXOffset; 65 | 66 | interval = (millis() - preInterval) * 0.001; 67 | 68 | preInterval = millis(); 69 | 70 | angleX = (0.98 * (angleX + gyroX * interval)) + (0.02 * angleAccX); 71 | } 72 | 73 | float imu_getAngleX() { 74 | #ifdef M5STACK_MPU6886 || M5STACK_200Q: 75 | return 0 - angleX; 76 | #else: 77 | return angleX; 78 | #endif 79 | } 80 | -------------------------------------------------------------------------------- /examples/Modules/BALA/imuCalibration.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Sorzn 3 | * @Date: 2020-01-06 11:36:48 4 | * @LastEditTime : 2020-01-06 16:54:52 5 | * @Description: M5Stack project 6 | * @FilePath: 7 | * /home/sakabin/Arduino/libraries/M5Stack/examples/Modules/Bala/imuCalibration.h 8 | */ 9 | // #define M5STACK_MPU6050 10 | #define M5STACK_MPU6886 11 | // #define M5STACK_200Q 12 | #include "M5Stack.h" 13 | 14 | extern void imu_CalcInit(); 15 | extern void imu_calcGyroOffsets(); 16 | extern void imu_update(); 17 | extern float imu_getAngleX(); 18 | extern void imu_setOffsetX(float x); 19 | extern float imu_getOffsetX(); 20 | -------------------------------------------------------------------------------- /examples/Modules/BALA2/MadgwickAHRS.h: -------------------------------------------------------------------------------- 1 | //===================================================================================================== 2 | // MadgwickAHRS.h 3 | //===================================================================================================== 4 | // 5 | // Implementation of Madgwick's IMU and AHRS algorithms. 6 | // See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms 7 | // 8 | // Date Author Notes 9 | // 29/09/2011 SOH Madgwick Initial release 10 | // 02/10/2011 SOH Madgwick Optimised for reduced CPU load 11 | // 12 | //===================================================================================================== 13 | #ifndef MadgwickAHRS_h 14 | #define MadgwickAHRS_h 15 | 16 | //---------------------------------------------------------------------------------------------------- 17 | // Variable declaration 18 | 19 | // extern volatile float q0, q1, q2, q3; // quaternion of sensor frame 20 | // relative to auxiliary frame 21 | 22 | //--------------------------------------------------------------------------------------------------- 23 | // Function declarations 24 | 25 | void MadgwickAHRSupdate(float gx, float gy, float gz, float ax, float ay, 26 | float az, float mx, float my, float mz); 27 | void MadgwickAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, 28 | float az, float *pitch, float *roll, float *yaw); 29 | void MadgwickAHRSetBeta(float beta); 30 | #endif 31 | //===================================================================================================== 32 | // End of file 33 | //===================================================================================================== 34 | -------------------------------------------------------------------------------- /examples/Modules/BALA2/bala.h: -------------------------------------------------------------------------------- 1 | #ifndef _BALA_H__ 2 | #define _BALA_H__ 3 | 4 | #include "Arduino.h" 5 | #include "freertos/FreeRTOS.h" 6 | 7 | class Bala { 8 | public: 9 | int32_t wheel_left_encoder, wheel_right_encoder; 10 | 11 | public: 12 | Bala(); 13 | void ClearEncoder(); 14 | void GetEncoder(int32_t* wheel_left, int32_t* wheel_right); 15 | void SetEncoder(int32_t wheel_left, int32_t wheel_right); 16 | void UpdateEncoder(); 17 | 18 | // -1023 ~ 1024 19 | void SetSpeed(int16_t wheel_left, int16_t wheel_right); 20 | 21 | // 500 ~ 2500 -> 0 ~ 180 22 | void SetServoAngle(uint8_t pos, uint8_t angle); 23 | 24 | // 500 ~ 2500 25 | void SetServoPulse(uint8_t pos, uint16_t width); 26 | 27 | // used i2c lock 28 | void SetMutex(SemaphoreHandle_t* mutex); 29 | 30 | private: 31 | SemaphoreHandle_t i2c_mutex; 32 | }; 33 | #endif -------------------------------------------------------------------------------- /examples/Modules/BALA2/bala2.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Modules/BALA2/bala2.bin -------------------------------------------------------------------------------- /examples/Modules/BALA2/calibration.cpp: -------------------------------------------------------------------------------- 1 | #define M5STACK_MPU6886 2 | #include 3 | 4 | #include "M5Stack.h" 5 | 6 | Preferences preferences; 7 | 8 | void GetGyroOffset(uint16_t times, int16_t* x_offset, int16_t* y_offset, 9 | int16_t* z_offset) { 10 | int64_t x = 0, y = 0, z = 0; 11 | int16_t gyro_x, gyro_y, gyro_z; 12 | for (size_t i = 0; i < times; i++) { 13 | M5.IMU.getGyroAdc(&gyro_x, &gyro_y, &gyro_z); 14 | x += gyro_x; 15 | y += gyro_y; 16 | z += gyro_z; 17 | } 18 | 19 | *x_offset = x / times; 20 | *y_offset = y / times; 21 | *z_offset = z / times; 22 | } 23 | 24 | void calibrationInit() { 25 | preferences.begin("Bala2Cal", false); 26 | } 27 | 28 | void calibrationGet(int16_t* gyro_x_offset, int16_t* gyro_y_offset, 29 | int16_t* gyro_z_offset, float* angle_center) { 30 | *gyro_x_offset = preferences.getInt("gryo_x", 0); 31 | *gyro_y_offset = preferences.getInt("gryo_y", 0); 32 | *gyro_z_offset = preferences.getInt("gryo_z", 0); 33 | 34 | *angle_center = preferences.getFloat("angle", 0.0); 35 | } 36 | 37 | void calibrationGryo() { 38 | M5.Lcd.fillScreen(BLACK); 39 | M5.Lcd.setTextFont(2); 40 | M5.Lcd.setTextColor(GREEN); 41 | M5.Lcd.printf("Start gryo calibration\r\n"); 42 | delay(1000); 43 | 44 | M5.Lcd.printf("Please keep BALA2 still for 2 seconds\r\n"); 45 | 46 | int16_t x_offset = 0; 47 | int16_t y_offset = 0; 48 | int16_t z_offset = 0; 49 | GetGyroOffset(2000, &x_offset, &y_offset, &z_offset); 50 | M5.Lcd.printf("Finish calibration !!!\r\n"); 51 | 52 | preferences.putInt("gryo_x", x_offset); 53 | preferences.putInt("gryo_y", y_offset); 54 | preferences.putInt("gryo_z", z_offset); 55 | 56 | delay(1000); 57 | } 58 | 59 | void calibrationSaveCenterAngle(float angle) { 60 | preferences.putFloat("angle", angle); 61 | } -------------------------------------------------------------------------------- /examples/Modules/BALA2/calibration.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void calibrationGryo(); 4 | void calibrationInit(); 5 | void calibrationSaveCenterAngle(float angle); 6 | void calibrationGet(int16_t* gyro_x_offset, int16_t* gyro_y_offset, 7 | int16_t* gyro_z_offset, float* angle_center); -------------------------------------------------------------------------------- /examples/Modules/BALA2/imu_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef __IMU__H_ 2 | #define __IMU__H_ 3 | 4 | #include "Arduino.h" 5 | 6 | #define ACC_8G_RES (0.000244140625f) 7 | #define GYRO_2000DPS_RES (0.06103515625f) 8 | 9 | typedef union { 10 | uint8_t raw[14]; 11 | struct { 12 | uint8_t acc_x_h; 13 | uint8_t acc_x_l; 14 | uint8_t acc_y_h; 15 | uint8_t acc_y_l; 16 | uint8_t acc_z_h; 17 | uint8_t acc_z_l; 18 | uint8_t temp_h; 19 | uint8_t temp_l; 20 | uint8_t gyro_x_h; 21 | uint8_t gyro_x_l; 22 | uint8_t gyro_y_h; 23 | uint8_t gyro_y_l; 24 | uint8_t gyro_z_h; 25 | uint8_t gyro_z_l; 26 | } value; 27 | } ImuData_t; 28 | 29 | float getAngle(); 30 | void ImuTaskStart(int16_t x_offset, int16_t y_offset, int16_t z_offset, 31 | SemaphoreHandle_t* i2c_lock); 32 | 33 | #endif -------------------------------------------------------------------------------- /examples/Modules/BALA2/pid.cpp: -------------------------------------------------------------------------------- 1 | #include "pid.h" 2 | 3 | PID::PID(float point, float kp, float ki, float kd) { 4 | _kp = kp; 5 | _ki = ki; 6 | _kd = kd; 7 | _point = point; 8 | output_max = 10000; 9 | output_min = -10000; 10 | integral_max = 10000; 11 | integral_min = -10000; 12 | error_integral = 0; 13 | _dir = 1; 14 | } 15 | 16 | float PID::Update(float input) { 17 | float output; 18 | float dinput; 19 | error = _point - input; 20 | error_integral += _ki * error + error_integral_offset; 21 | if (error_integral > integral_max) { 22 | error_integral = integral_max; 23 | } 24 | if (error_integral < integral_min) { 25 | error_integral = integral_min; 26 | } 27 | dinput = input - input_last; 28 | output = _kp * error + error_integral - _kd * dinput; 29 | input_last = input; 30 | if (output < output_min) { 31 | output = output_min; 32 | } 33 | if (output > output_max) { 34 | output = output_max; 35 | } 36 | return output; 37 | } 38 | 39 | void PID::SetOutputLimits(float max_out, float min_out) { 40 | output_max = max_out; 41 | output_min = min_out; 42 | } 43 | 44 | void PID::SetIntegralLimits(float max_out, float min_out) { 45 | integral_max = max_out; 46 | integral_min = min_out; 47 | } 48 | 49 | void PID::SetDirection(int8_t dir) { 50 | _dir = dir; 51 | _kp = fabs(_kp) * _dir; 52 | _ki = fabs(_ki) * _dir; 53 | _kd = fabs(_kd) * _dir; 54 | } 55 | 56 | void PID::SetIntegral(float integral) { 57 | error_integral = integral; 58 | } 59 | 60 | void PID::SetIntegralOffset(float offset) { 61 | error_integral_offset = offset; 62 | } 63 | 64 | void PID::UpdateParam(float kp, float ki, float kd) { 65 | _kp = fabs(kp) * _dir; 66 | _ki = fabs(ki) * _dir; 67 | _kd = fabs(kd) * _dir; 68 | } 69 | 70 | void PID::SetPoint(float point) { 71 | _point = point; 72 | } 73 | -------------------------------------------------------------------------------- /examples/Modules/BALA2/pid.h: -------------------------------------------------------------------------------- 1 | #ifndef _PID_H_ 2 | #define _PID_H_ 3 | 4 | #include "Arduino.h" 5 | 6 | class PID { 7 | public: 8 | // commonly used functions 9 | // ************************************************************************** 10 | PID(float point, float kp, float ki, float kd); 11 | 12 | float Update(float input); 13 | void SetOutputLimits(float max_out, float min_out); 14 | void SetIntegralLimits(float max_out, float min_out); 15 | void SetPoint(float point); 16 | void SetDirection(int8_t dir); 17 | void UpdateParam(float kp, float ki, float kd); 18 | void SetIntegral(float integral); 19 | void SetIntegralOffset(float offset); 20 | 21 | float error_integral; 22 | 23 | private: 24 | float _kp, _ki, _kd; 25 | float _point; 26 | float error_integral_offset; 27 | float input_last; 28 | float error; 29 | float output_max, output_min; 30 | float integral_max, integral_min; 31 | int8_t _dir; 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /examples/Modules/BaseX/BaseX.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Sorzn 3 | * @Date: 2019-12-12 14:33:50 4 | * @LastEditTime: 2019-12-13 15:47:59 5 | * @Description: M5Stack project 6 | * @FilePath: /M5Stack/examples/Modules/BaseX/BaseX.h 7 | */ 8 | 9 | #ifndef __BASE_X_H__ 10 | #define __BASE_X_H__ 11 | 12 | #include "Arduino.h" 13 | 14 | #define BASE_X_ADDR (0x22) 15 | 16 | #define BASE_X_SERVO_ANGLE_ADDR (0x00) 17 | #define BASE_X_SERVO_PULSE_ADDR (0x10) 18 | #define BASE_X_PWM_DUTY_ADDR (0x20) 19 | #define BASE_X_ENCODER_ADDR (0x30) 20 | #define BASE_X_SPEED_ADDR (0x40) 21 | 22 | /* 23 | | 0 | 1 | 2 | 3 | 4, 5, 6, 7 | 8 24 | | 9 | 10 | 11 | 12 | | mod | position-p | 25 | position-i | position-d | position-point | position-max-speed | speed-p | 26 | speed-i | speed-d | speed-point | 27 | */ 28 | #define BASE_X_CONFIG_ADDR (0x50) 29 | 30 | #define NORMAL_MODE (0x00) 31 | #define POSITION_MODE (0x01) 32 | #define SPEED_MODE (0x02) 33 | 34 | class BASE_X { 35 | public: 36 | void SetMode(uint8_t pos, uint8_t mode); 37 | 38 | int32_t GetEncoderValue(uint8_t pos); 39 | void SetEncoderValue(uint8_t pos, int32_t encode); 40 | 41 | void SetMotorSpeed(uint8_t pos, int8_t duty); 42 | int8_t GetMotorSpeed(uint8_t pos); 43 | 44 | int8_t GetMotorSpeed20MS(uint8_t pos); 45 | 46 | void SetPositionPID(uint8_t pos, uint8_t kp, uint8_t ki, uint8_t kd); 47 | void SetPositionPoint(uint8_t pos, int32_t position_point); 48 | void SetPositionPIDMaxSpeed(uint8_t pos, uint8_t max_pwm); 49 | 50 | void SetSpeedPID(uint8_t pos, uint8_t kp, uint8_t ki, uint8_t kd); 51 | void SetSpeedPoint(uint8_t pos, int8_t speed_point); 52 | 53 | void SetServoAngle(uint8_t pos, uint8_t angle); 54 | void SetServoPulseWidth(uint8_t pos, uint16_t width); 55 | 56 | private: 57 | uint8_t CheckPos(uint8_t pos); 58 | }; 59 | 60 | #endif -------------------------------------------------------------------------------- /examples/Modules/Base_PoE/RS_485/RS_485.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Base LAN PoE 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | M5.begin(true, false, true, false); // Init M5Core. 初始化 M5Core 18 | M5.Power.begin(); // Init Power module. 初始化电源模块 19 | M5.Lcd.setTextColor(YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 20 | M5.Lcd.setTextSize(2); // Set the font size. 设置字体大小为2 21 | M5.Lcd.drawString("RS485", 130, 10); 22 | M5.Lcd.drawString("Signal", 0, 60); 23 | Serial2.begin(115200, SERIAL_8N1, 5, 15); 24 | } 25 | 26 | void loop() 27 | { 28 | if (M5.BtnA.wasPressed()) { // Press the buttonA to send a 29 | // message.按下按键A发送信息 30 | M5.Lcd.fillCircle(100, 65, 15, 31 | GREEN); // Set the light to Green. 设置灯为绿色 32 | M5.update(); 33 | Serial2.write('a'); 34 | delay(50); 35 | 36 | } else { 37 | M5.Lcd.fillCircle(100, 65, 15, WHITE); 38 | } 39 | if (Serial2.available()) { // If the serial port receives a 40 | // message. 如果串口收到信息 41 | int ch = Serial2.read(); // Read the message. 读取信息 42 | Serial.write(ch); 43 | M5.Lcd.fillCircle(100, 65, 15, GREEN); 44 | M5.update(); 45 | delay(50); 46 | } else { 47 | M5.Lcd.fillCircle(100, 65, 15, WHITE); 48 | } 49 | M5.update(); 50 | } -------------------------------------------------------------------------------- /examples/Modules/COMMU/MCP_CAN_lib.rar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/examples/Modules/COMMU/MCP_CAN_lib.rar -------------------------------------------------------------------------------- /examples/Modules/COM_GSM/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/COM_LTE-DATA/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/COM_LTE/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/COM_LoRaWAN/LoRaWAN_Receive/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/COM_LoRaWAN470/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/COM_LoRaWAN915/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/COM_NB-IoT/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/COM_SigFox/COM_SigFox.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module COMX SigFox 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | // Description: Get device ID,PAC and Send "00FFEE" to Dongle. 16 | 17 | #define rxPin 16 18 | #define txPin 17 19 | 20 | // Set to 0 if you don't need to see the messages in the console 21 | #define DEBUG 1 22 | 23 | // Message buffer 24 | uint8_t msg[12]; 25 | 26 | // the setup function runs once when you press reset or power the board 27 | void setup() 28 | { 29 | M5.begin(); 30 | Serial2.begin(9600, SERIAL_8N1, rxPin, txPin); 31 | 32 | delay(2000); 33 | getID(); 34 | delay(1000); 35 | getPAC(); 36 | delay(1000); 37 | } 38 | 39 | // the loop function runs over and over again forever 40 | void loop() 41 | { 42 | Serial2.write("AT$SF=00FFEE\r\n"); 43 | delay(60000); 44 | } 45 | 46 | // Get Sigfox ID 47 | String getID() 48 | { 49 | String id = ""; 50 | char output; 51 | 52 | Serial2.write("AT$I=10\r\n"); 53 | while (!Serial2.available()) { 54 | } 55 | while (Serial2.available()) { 56 | output = Serial2.read(); 57 | id += output; 58 | delay(10); 59 | } 60 | 61 | if (DEBUG) { 62 | Serial.println("Sigfox Device ID: "); 63 | Serial.println(id); 64 | M5.Lcd.println(id); 65 | } 66 | 67 | return id; 68 | } 69 | 70 | // Get PAC number 71 | String getPAC() 72 | { 73 | String pac = ""; 74 | char output; 75 | 76 | Serial2.write("AT$I=11\r\n"); 77 | while (!Serial2.available()) { 78 | } 79 | 80 | while (Serial2.available()) { 81 | output = Serial2.read(); 82 | pac += output; 83 | delay(10); 84 | } 85 | 86 | if (DEBUG) { 87 | Serial.println("PAC number: "); 88 | Serial.println(pac); 89 | M5.Lcd.println(pac); 90 | } 91 | 92 | return pac; 93 | } 94 | -------------------------------------------------------------------------------- /examples/Modules/COM_Zigbee_CC2630/P2P_TEST/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef _RESOURCE_H_ 2 | #define _RESOURCE_H_ 3 | 4 | extern const unsigned char coordinator_jpeg_120x140[27537]; 5 | extern const unsigned char endDevice_jpeg_120x140[24609]; 6 | extern const unsigned char router_jpeg_120x140[26433]; 7 | extern const unsigned char EndDeviceTitle[17470]; 8 | extern const unsigned char coordinatorTitle[21823]; 9 | extern const unsigned char chatBubblesBottom[11546]; 10 | extern const unsigned char chatBubblesTop[10561]; 11 | 12 | #endif -------------------------------------------------------------------------------- /examples/Modules/COM_Zigbee_CC2630/RSSI_TEST/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef _RESOURCE_H_ 2 | #define _RESOURCE_H_ 3 | 4 | extern const unsigned char coordinator_jpeg_120x140[27537]; 5 | extern const unsigned char endDevice_jpeg_120x140[24609]; 6 | extern const unsigned char router_jpeg_120x140[26433]; 7 | extern const unsigned char EndDeviceTitle[17470]; 8 | extern const unsigned char coordinatorTitle[21823]; 9 | extern const unsigned char chatBubblesBottom[11546]; 10 | extern const unsigned char chatBubblesTop[10561]; 11 | 12 | #endif -------------------------------------------------------------------------------- /examples/Modules/DHT12/DHT12.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | DHT12.cpp - Library for DHT12 sensor. 3 | v0.0.1 Beta 4 | Created by Bobadas, July 30,2016. 5 | Released into the public domain. 6 | */ 7 | #include "DHT12.h" 8 | 9 | DHT12::DHT12(uint8_t scale, uint8_t id) { 10 | if (id == 0 || id > 126) 11 | _id = 0x5c; 12 | else 13 | _id = id; 14 | if (scale == 0 || scale > 3) 15 | _scale = CELSIUS; 16 | else 17 | _scale = scale; 18 | } 19 | 20 | uint8_t DHT12::read() { 21 | Wire.beginTransmission(_id); 22 | Wire.write(0); 23 | if (Wire.endTransmission() != 0) return 1; 24 | Wire.requestFrom(_id, (uint8_t)5); 25 | for (int i = 0; i < 5; i++) { 26 | datos[i] = Wire.read(); 27 | }; 28 | delay(50); 29 | if (Wire.available() != 0) return 2; 30 | if (datos[4] != (datos[0] + datos[1] + datos[2] + datos[3])) return 3; 31 | return 0; 32 | } 33 | 34 | float DHT12::readTemperature(uint8_t scale) { 35 | float resultado = 0; 36 | uint8_t error = read(); 37 | if (error != 0) return (float)error / 100; 38 | 39 | resultado = datos[2] + (float)(datos[3] & 0x7f) / 10; 40 | if (datos[3] & 0x80) { 41 | resultado = -resultado; 42 | } 43 | 44 | if (scale == 0) scale = _scale; 45 | switch (scale) { 46 | case CELSIUS: 47 | break; 48 | case FAHRENHEIT: 49 | resultado = resultado * 1.8 + 32; 50 | break; 51 | case KELVIN: 52 | resultado = resultado + 273.15; 53 | break; 54 | }; 55 | return resultado; 56 | } 57 | 58 | float DHT12::readHumidity() { 59 | float resultado; 60 | uint8_t error = read(); 61 | if (error != 0) return (float)error / 100; 62 | resultado = (datos[0] + (float)datos[1] / 10); 63 | return resultado; 64 | } 65 | -------------------------------------------------------------------------------- /examples/Modules/DHT12/DHT12.h: -------------------------------------------------------------------------------- 1 | /* 2 | DHT12.h - Library for DHT12 sensor. 3 | v0.0.1 Beta 4 | Created by Bobadas, July 30,2016. 5 | Released into the public domain. 6 | */ 7 | #ifndef DHT12_h 8 | #define DHT12_h 9 | #include "Arduino.h" 10 | #include "Wire.h" 11 | 12 | #define CELSIUS 1 13 | #define KELVIN 2 14 | #define FAHRENHEIT 3 15 | 16 | class DHT12 { 17 | public: 18 | DHT12(uint8_t scale = 0, uint8_t id = 0); 19 | float readTemperature(uint8_t scale = 0); 20 | float readHumidity(); 21 | 22 | private: 23 | uint8_t read(); 24 | uint8_t datos[5]; 25 | uint8_t _id; 26 | uint8_t _scale; 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/Modules/DHT12/DHT12.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + DHT12 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | #include //The DHT12 uses I2C comunication. 15 | #include "DHT12.h" 16 | 17 | // Description: Use DHT12 Sensor to read temperature, humidity and display the data on the screen. 18 | 19 | DHT12 dht12; // Preset scale CELSIUS and ID 0x5c. 20 | /* 21 | For configuration library: 22 | DHT12 dht12("Scale temperature","ID device for I2C"); 23 | On "Scale temperature" you can select the preset scale: 24 | CELSIUS, FAHRENHEIT or KELVIN. 25 | And on "ID device", you can put ID sensor, on DHT12 26 | normally is 0x5c. 27 | Examples: 28 | DHT12 dht12; 29 | The preset scale is CELSIUS and ID is 0x5c. 30 | DHT12 dht12(KELVIN); 31 | the preset scale is KELVIN and ID is 0x5c. 32 | DHT12 dht12(FAHRENHEIT,0x53); 33 | The preset scale is FAHRENHEIT and ID is 0x53. 34 | */ 35 | 36 | void setup() 37 | { 38 | M5.begin(); 39 | M5.Power.begin(); 40 | Wire.begin(); 41 | Serial.println("Prueba de libreria DHT12:"); 42 | M5.Lcd.println("Prueba de libreria DHT12:"); 43 | } 44 | 45 | void loop() 46 | { 47 | // Read temperature with preset scale. 48 | Serial.print("Temperatura: "); 49 | M5.Lcd.print("Temperatura: "); 50 | Serial.print(dht12.readTemperature()); 51 | M5.Lcd.print(dht12.readTemperature()); 52 | 53 | // Read humidity. 54 | Serial.print("*C Humedad: "); 55 | M5.Lcd.print("*C Humedad: "); 56 | Serial.print(dht12.readHumidity()); 57 | M5.Lcd.println(dht12.readHumidity()); 58 | 59 | // Read temperature as forced fahrenheit. 60 | Serial.println("%RH"); 61 | Serial.println("%RH"); 62 | Serial.print("Temperatura: "); 63 | Serial.print(dht12.readTemperature(FAHRENHEIT)); 64 | 65 | // Read termperature as forced kelvin. 66 | Serial.println("*F"); 67 | Serial.print("Temperatura: "); 68 | Serial.print(dht12.readTemperature(KELVIN)); 69 | Serial.println("*K"); 70 | 71 | delay(5000); 72 | } 73 | -------------------------------------------------------------------------------- /examples/Modules/GPS_NEO_M8N/GPSRaw/GPSRaw.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module GPS 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | HardwareSerial GPSRaw(2); 16 | 17 | void setup() 18 | { 19 | M5.begin(); 20 | M5.Power.begin(); 21 | GPSRaw.begin(9600); 22 | Serial.println("hello"); 23 | M5.Lcd.setTextFont(4); 24 | M5.Lcd.println(("GPS Raw Example")); 25 | } 26 | 27 | void loop() 28 | { 29 | // put your main code here, to run repeatedly: 30 | if (Serial.available()) { 31 | int ch = Serial.read(); 32 | GPSRaw.write(ch); 33 | } 34 | 35 | if (GPSRaw.available()) { 36 | int ch = GPSRaw.read(); 37 | Serial.write(ch); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/Modules/GSM_M6315/GSM_M6315.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module GSM 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | // Description: Send AT command to get current signal quality. 16 | 17 | void IotWriteCommand(char cmd[], char date[]) 18 | { 19 | char buf[256] = {0}; 20 | 21 | if (cmd == NULL) 22 | sprintf(buf, "AT\r\n"); 23 | else if (date == NULL) 24 | sprintf(buf, "AT+%s\r\n", cmd); 25 | else 26 | sprintf(buf, "AT+%s=%s\r\n", cmd, date); 27 | 28 | Serial2.write(buf); 29 | } 30 | // AT+CSQ=? 31 | void get_time(void) 32 | { 33 | IotWriteCommand("CSQ=?", NULL); 34 | while (Serial2.available()) { 35 | uint8_t ch = Serial2.read(); 36 | Serial.write(ch); 37 | M5.Lcd.write(ch); 38 | } 39 | } 40 | 41 | void setup() 42 | { 43 | M5.begin(); 44 | M5.Power.begin(); 45 | 46 | Serial2.begin(115200, SERIAL_8N1, 16, 17); 47 | pinMode(5, OUTPUT); 48 | digitalWrite(5, 1); 49 | } 50 | 51 | void loop() 52 | { 53 | if (M5.BtnA.wasReleased()) { 54 | M5.Lcd.fillScreen(TFT_BLACK); 55 | M5.Lcd.setCursor(60, 80, 2); 56 | get_time(); 57 | } 58 | M5.update(); 59 | } 60 | -------------------------------------------------------------------------------- /examples/Modules/GoPLUS/GoPlus.h: -------------------------------------------------------------------------------- 1 | #ifndef __GOPLUS_H__ 2 | #define __GOPLUS_H__ 3 | 4 | #include 5 | 6 | #define GOPLUS_ADDR 0x5d 7 | 8 | #define SERVO_ADDR 0x10 9 | #define SERVO_NUM0 0x00 10 | #define SERVO_NUM1 0x01 11 | #define SERVO_NUM2 0x02 12 | #define SERVO_NUM3 0x03 13 | 14 | #define MOTOR_ADDR 0x30 15 | #define MOTOR_NUM0 0x00 16 | #define MOTOR_NUM1 0x02 17 | 18 | #define HUB1_ADDR 0x40 19 | #define HUB2_ADDR 0x50 20 | #define HUB3_ADDR 0x60 21 | #define HUB_NUM0 0x06 22 | #define HUB_NUM1 0x07 23 | 24 | #define HUB_READ 0x00 25 | #define HUB_WIRE 0x80 26 | 27 | #define HUB_DIGITAL 0x00 28 | #define HUB_ANALOG 0x01 29 | 30 | class GoPlus { 31 | public: 32 | GoPlus(); 33 | void begin(); 34 | 35 | void Servo_write_angle(uint8_t number, uint8_t angle); 36 | void Motor_write_speed(uint8_t number, uint8_t trun, uint8_t motor_speed); 37 | uint16_t hub1_a_read_value(uint8_t reg); 38 | uint16_t hub1_d_read_value(uint8_t reg); 39 | uint16_t hub2_d_read_value(uint8_t reg); 40 | uint16_t hub3_d_read_value(uint8_t reg); 41 | uint16_t hub2_a_read_value(uint8_t reg); 42 | uint16_t hub3_a_read_value(uint8_t reg); 43 | void hub1_wire_value(uint8_t reg, uint16_t value); 44 | void hub2_wire_value(uint8_t reg, uint16_t value); 45 | void hub3_wire_value(uint8_t reg, uint16_t value); 46 | 47 | public: 48 | private: 49 | private: 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /examples/Modules/LoRa433_SX1278/LoRaDumpRegisters/LoRaDumpRegisters.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module LoRa433 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * arduino-LoRa:https://github.com/sandeepmistry/arduino-LoRa 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | // LoRa register dump 18 | // This examples shows how to inspect and output the LoRa radio's 19 | // registers on the Serial interface 20 | void header(const char *string, uint16_t color) 21 | { 22 | M5.Lcd.fillScreen(color); 23 | M5.Lcd.setTextSize(1); 24 | M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE); 25 | M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE); 26 | M5.Lcd.setTextDatum(TC_DATUM); 27 | M5.Lcd.drawString(string, 160, 3, 4); 28 | } 29 | 30 | void setup() 31 | { 32 | M5.begin(); 33 | M5.Power.begin(); 34 | while (!Serial); 35 | 36 | header("LoRa Dump Registers", TFT_BLACK); 37 | 38 | M5.Lcd.setTextFont(2); 39 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 40 | M5.Lcd.drawString("Please use serial port to view data.", 0, 80, 2); 41 | 42 | Serial.println("LoRa Dump Registers\n"); 43 | 44 | // override the default CS, reset, and IRQ pins (optional) 45 | // LoRa.setPins(7, 6, 1); // set CS, reset, IRQ pin 46 | 47 | if (!LoRa.begin(433E6)) { // initialize ratio at 915 MHz 48 | Serial.println("LoRa init failed. Check your connections."); 49 | while (true); // if failed, do nothing 50 | } 51 | 52 | LoRa.dumpRegisters(Serial); 53 | } 54 | 55 | void loop() 56 | { 57 | } 58 | -------------------------------------------------------------------------------- /examples/Modules/LoRa433_SX1278/LoRaReceiver/LoRaReceiver.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module LoRa433 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * arduino-LoRa:https://github.com/sandeepmistry/arduino-LoRa 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | void setup() 18 | { 19 | M5.begin(); 20 | M5.Power.begin(); 21 | // override the default CS, reset, and IRQ pins (optional) 22 | LoRa.setPins(); // default set CS, reset, IRQ pin 23 | Serial.println("LoRa Receiver"); 24 | M5.Lcd.println("LoRa Receiver"); 25 | 26 | // frequency in Hz (433E6, 866E6, 915E6) 27 | if (!LoRa.begin(433E6)) { 28 | Serial.println("Starting LoRa failed!"); 29 | M5.Lcd.println("Starting LoRa failed!"); 30 | while (1); 31 | } 32 | 33 | // LoRa.setSyncWord(0x69); 34 | Serial.println("LoRa init succeeded."); 35 | M5.Lcd.println("LoRa init succeeded."); 36 | } 37 | 38 | void loop() 39 | { 40 | // try to parse packet 41 | int packetSize = LoRa.parsePacket(); 42 | if (packetSize) { 43 | // received a packet 44 | Serial.print("Received packet: \""); 45 | M5.Lcd.print("Received packet: \""); 46 | 47 | // read packet 48 | while (LoRa.available()) { 49 | char ch = (char)LoRa.read(); 50 | Serial.print(ch); 51 | M5.Lcd.print(ch); 52 | } 53 | 54 | // print RSSI of packet 55 | Serial.print("\" with RSSI "); 56 | Serial.println(LoRa.packetRssi()); 57 | M5.Lcd.print("\" with RSSI "); 58 | M5.Lcd.println(LoRa.packetRssi()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/Modules/LoRa433_SX1278/LoRaReceiverCallback/LoRaReceiverCallback.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module LoRa433 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * arduino-LoRa:https://github.com/sandeepmistry/arduino-LoRa 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | void header(const char *string, uint16_t color) 18 | { 19 | M5.Lcd.fillScreen(color); 20 | M5.Lcd.setTextSize(1); 21 | M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE); 22 | M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE); 23 | M5.Lcd.setTextDatum(TC_DATUM); 24 | M5.Lcd.drawString(string, 160, 3, 4); 25 | } 26 | 27 | void setup() 28 | { 29 | M5.begin(); 30 | M5.Power.begin(); 31 | // initialize serial 32 | header("LoRa Receiver Callback", TFT_BLACK); 33 | M5.Lcd.setTextFont(2); 34 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 35 | M5.Lcd.drawString("Please use serial port to view data.", 0, 35, 2); 36 | Serial.println("LoRa Receiver Callback"); 37 | 38 | // frequency in Hz (433E6, 866E6, 915E6) 39 | if (!LoRa.begin(433E6)) { 40 | Serial.println("Starting LoRa failed!"); 41 | while (1); 42 | } 43 | 44 | // register the receive callback 45 | LoRa.onReceive(onReceive); 46 | 47 | // put the radio into receive mode 48 | LoRa.receive(); 49 | } 50 | 51 | void loop() 52 | { 53 | // do nothing 54 | LoRa.receive(); 55 | } 56 | 57 | void onReceive(int packetSize) 58 | { 59 | // received a packet 60 | Serial.print("Received packet '"); 61 | 62 | // read packet 63 | for (int i = 0; i < packetSize; i++) { 64 | Serial.print((char)LoRa.read()); 65 | } 66 | 67 | // print RSSI of packet 68 | Serial.print("' with RSSI "); 69 | Serial.println(LoRa.packetRssi()); 70 | } 71 | -------------------------------------------------------------------------------- /examples/Modules/LoRa433_SX1278/LoRaSender/LoRaSender.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module LoRa433 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * arduino-LoRa:https://github.com/sandeepmistry/arduino-LoRa 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | void setup() 18 | { 19 | M5.begin(); 20 | M5.Power.begin(); 21 | // override the default CS, reset, and IRQ pins (optional) 22 | LoRa.setPins(); // default set CS, reset, IRQ pin 23 | Serial.println("LoRa Sender"); 24 | M5.Lcd.println("LoRa Sender"); 25 | 26 | // frequency in Hz (433E6, 866E6, 915E6) 27 | if (!LoRa.begin(433E6)) { 28 | Serial.println("Starting LoRa failed!"); 29 | M5.Lcd.println("Starting LoRa failed!"); 30 | while (1); 31 | } 32 | 33 | // LoRa.setSyncWord(0x69); 34 | Serial.println("LoRa init succeeded."); 35 | M5.Lcd.println("LoRa init succeeded."); 36 | } 37 | 38 | void loop() 39 | { 40 | // try to parse packet 41 | static uint32_t counter; 42 | 43 | Serial.print("Sending packet: "); 44 | Serial.println(counter); 45 | 46 | // send packet 47 | LoRa.beginPacket(); 48 | LoRa.print("hello "); 49 | LoRa.print(counter); 50 | LoRa.endPacket(); 51 | 52 | counter++; 53 | 54 | delay(1000); 55 | } -------------------------------------------------------------------------------- /examples/Modules/PLUS/PLUS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module Plus 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | // This exmpale can display the encoder gear reading of the PLUS Module and the 16 | // state of the keys. 本例可以显示PLUS模块的编码器齿轮读数和按键状态。 17 | 18 | #define IrPin (13) 19 | #define PLUS_ADDR (0x62) 20 | 21 | int32_t number = 0; 22 | uint8_t press = 0; 23 | 24 | void setup() 25 | { 26 | M5.begin(true, false, false); 27 | M5.Power.begin(); 28 | M5.Lcd.setTextFont(6); 29 | M5.Lcd.clear(BLACK); 30 | M5.Lcd.setTextColor(ORANGE, BLACK); 31 | Wire.begin(); 32 | ledcSetup(1, 38000, 10); 33 | ledcAttachPin(IrPin, 1); 34 | } 35 | 36 | void plus_encode() 37 | { 38 | Wire.requestFrom(PLUS_ADDR, 2); 39 | while (Wire.available()) { 40 | int8_t encode = Wire.read(); 41 | uint8_t press_n = Wire.read(); 42 | number += encode; 43 | if (press_n == 0xff) { 44 | press = 0; 45 | } else { 46 | press = 1; 47 | } 48 | } 49 | } 50 | 51 | void loop() 52 | { 53 | char data[20]; 54 | 55 | plus_encode(); 56 | ledcWrite(1, ledcRead(1) ? 0 : 512); 57 | sprintf(data, "%d %d ", number, press); 58 | M5.Lcd.setCursor(100, 100); 59 | M5.Lcd.print(data); 60 | vTaskDelay(200); 61 | } -------------------------------------------------------------------------------- /examples/Modules/PM2.5_PMSA003/DFRobot_SHT20.h: -------------------------------------------------------------------------------- 1 | #ifndef DFRobot_SHT20_h 2 | #define DFRobot_SHT20_h 3 | 4 | #if defined(ARDUINO) && ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | #include 10 | 11 | #define ERROR_I2C_TIMEOUT 998 12 | #define ERROR_BAD_CRC 999 13 | #define SLAVE_ADDRESS 0x40 14 | #define TRIGGER_TEMP_MEASURE_HOLD 0xE3 15 | #define TRIGGER_HUMD_MEASURE_HOLD 0xE5 16 | #define TRIGGER_TEMP_MEASURE_NOHOLD 0xF3 17 | #define TRIGGER_HUMD_MEASURE_NOHOLD 0xF5 18 | #define WRITE_USER_REG 0xE6 19 | #define READ_USER_REG 0xE7 20 | #define SOFT_RESET 0xFE 21 | #define USER_REGISTER_RESOLUTION_MASK 0x81 22 | #define USER_REGISTER_RESOLUTION_RH12_TEMP14 0x00 23 | #define USER_REGISTER_RESOLUTION_RH8_TEMP12 0x01 24 | #define USER_REGISTER_RESOLUTION_RH10_TEMP13 0x80 25 | #define USER_REGISTER_RESOLUTION_RH11_TEMP11 0x81 26 | #define USER_REGISTER_END_OF_BATTERY 0x40 27 | #define USER_REGISTER_HEATER_ENABLED 0x04 28 | #define USER_REGISTER_DISABLE_OTP_RELOAD 0x02 29 | #define MAX_WAIT 100 30 | #define DELAY_INTERVAL 10 31 | #define SHIFTED_DIVISOR 0x988000 32 | #define MAX_COUNTER (MAX_WAIT / DELAY_INTERVAL) 33 | 34 | class DFRobot_SHT20 { 35 | public: 36 | void checkSHT20(void); 37 | void setResolution(byte resBits); 38 | void writeUserRegister(byte val); 39 | void initSHT20(TwoWire &wirePort = Wire); 40 | void showReslut(const char *prefix, int val); 41 | float readHumidity(void); 42 | float readTemperature(void); 43 | byte readUserRegister(void); 44 | 45 | private: 46 | TwoWire *i2cPort; 47 | byte checkCRC(uint16_t message_from_sensor, 48 | uint8_t check_value_from_sensor); 49 | uint16_t readValue(byte cmd); 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /examples/Modules/RS232/RS232.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module13.2 RS232F/M 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | /* Define your pin here */ 16 | /* And should be the same as you module setup */ 17 | #define RX_PIN 16 18 | #define TX_PIN 17 19 | 20 | void setup() 21 | { 22 | M5.begin(); 23 | M5.Power.begin(); 24 | M5.Lcd.setTextSize(1); 25 | M5.Lcd.drawString("Module RS232 test", 75, 3, 4); 26 | Serial2.begin(115200, SERIAL_8N1, RX_PIN, 27 | TX_PIN); // Set the baud rate of serial port 2 to 115200,8 data bits, 28 | // no parity bits, and 1 stop bit, and set RX to 16 and TX 29 | // to 17. 30 | // 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX,TX引脚 31 | } 32 | 33 | void loop() 34 | { 35 | Serial2.write("Hello\n"); 36 | 37 | if (Serial2.available()) { 38 | M5.Lcd.print(char(Serial2.read())); 39 | } 40 | delay(100); 41 | } 42 | -------------------------------------------------------------------------------- /examples/Modules/SERVO/SERVO.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module Servo 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | // Use SERVO Module to control the rotation of 12-channel servo. 18 | // 使用 SERVO 模块控制 12 通道舵机的旋转。 19 | 20 | #define SERVO_ADDR (0x53) 21 | 22 | void setup() 23 | { 24 | M5.begin(true, false, true); 25 | M5.Power.begin(); 26 | M5.Lcd.setTextFont(4); 27 | M5.Lcd.setCursor(70, 100); 28 | M5.Lcd.print("Servo Example"); 29 | 30 | Wire.begin(21, 22, 100000UL); 31 | } 32 | // addr 0x01 mean control the number 1 servo by us 33 | void Servo_write_us(uint8_t number, uint16_t us) 34 | { 35 | Wire.beginTransmission(SERVO_ADDR); 36 | Wire.write(0x00 | number); 37 | Wire.write(us & 0x00ff); 38 | Wire.write(us >> 8 & 0x00ff); 39 | Wire.endTransmission(); 40 | } 41 | 42 | // addr 0x11 mean control the number 1 servo by angle 43 | void Servo_write_angle(uint8_t number, uint8_t angle) 44 | { 45 | Wire.beginTransmission(SERVO_ADDR); 46 | Wire.write(0x10 | number); 47 | Wire.write(angle); 48 | Wire.endTransmission(); 49 | } 50 | 51 | void loop() 52 | { 53 | for (uint8_t i = 0; i < 12; i++) { 54 | Servo_write_us(i, 700); 55 | // Servo_write_angle(i, 0); 56 | } 57 | delay(1000); 58 | for (uint8_t i = 0; i < 12; i++) { 59 | Servo_write_us(i, 2300); 60 | // Servo_write_angle(i, 180); 61 | } 62 | delay(1000); 63 | } -------------------------------------------------------------------------------- /examples/Modules/SIM800L/ATCOM/AT/AT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module SIM800L 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | #define RX_PIN 16 15 | #define TX_PIN 17 16 | #define RESET_PIN 5 17 | 18 | // Description: SIM800L serial transparent transmission debugging program 19 | 20 | void header(const char *string, uint16_t color) 21 | { 22 | M5.Lcd.fillScreen(color); 23 | M5.Lcd.setTextSize(1); 24 | M5.Lcd.setTextColor(TFT_MAGENTA, TFT_BLUE); 25 | M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLUE); 26 | M5.Lcd.setTextDatum(TC_DATUM); 27 | M5.Lcd.drawString(string, 160, 3, 4); 28 | } 29 | 30 | void setup() 31 | { 32 | M5.begin(); 33 | M5.Power.begin(); 34 | header("SIM800L AT command", TFT_BLACK); 35 | M5.Lcd.setTextFont(2); 36 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 37 | M5.Lcd.drawString("Please use serial port to Test AT command.", 0, 35, 2); 38 | // Host serial communication 39 | 40 | // SIM800L serial communication 41 | Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN); 42 | pinMode(RESET_PIN, OUTPUT); 43 | } 44 | 45 | void loop() 46 | { 47 | // AT instruction write 48 | if (Serial.available()) { 49 | Serial2.write(Serial.read()); 50 | } 51 | 52 | // AT instruction result 53 | if (Serial2.available()) { 54 | Serial.write(Serial2.read()); 55 | } 56 | 57 | delay(10); 58 | } 59 | -------------------------------------------------------------------------------- /examples/Modules/SIM800L/HTTP/TFTTerminal.h: -------------------------------------------------------------------------------- 1 | #ifndef _TFTTERMINAL_H_ 2 | #define _TFTTERMINAL_H_ 3 | 4 | #include 5 | #include 6 | 7 | class TFTTerminal : public Print { 8 | private: 9 | TFT_eSprite *disptr; 10 | char discharbuff[60][55]; 11 | uint32_t xpos = 0, ypos = 0, dispos = 0; 12 | TFT_eSprite *_dis_buff_ptr = NULL; 13 | uint16_t _bkcolor = TFT_BLACK; 14 | uint16_t _color = TFT_GREEN; 15 | 16 | uint16_t _win_x_pos = 0, _win_y_pos = 0, _win_w = 320, _win_h = 240; 17 | uint16_t _font_x_size = 6, _font_y_size = 8; 18 | uint8_t _fontSize = 0; 19 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 20 | 21 | public: 22 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 23 | ~TFTTerminal(); 24 | 25 | void setcolor(uint16_t color, uint16_t bk_color); 26 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 27 | void setFontsize(uint8_t size); 28 | 29 | size_t write(uint8_t); 30 | size_t write(const uint8_t *buffer, size_t size); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /examples/Modules/StepmotorGRBL13.2_M035/xyz_control/xyz_control.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Module13.2 GRBL 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * M5Module-GRBL-13.2:https://github.com/m5stack/M5Module-GRBL-13.2 12 | */ 13 | 14 | #include 15 | #include "Module_GRBL_13.2.h" 16 | 17 | // GRBL 13.2 Module TEST Example,use I2C to control stepper motors 18 | // 步进电机模块测试示例,使用I2C控制步进电机 19 | 20 | /* 21 | * The I2C address of GRBL 13.2 Module is 0x70 by default. 22 | * GRBL 13.2 模块的 I2C 地址默认为 0x70。 23 | * You could use the DIP Switch for modify I2C address to 0x71 24 | * 您可以使用拨码开关将 I2C 地址修改为 0x71 25 | */ 26 | 27 | #define STEPMOTOR_I2C_ADDR 0x70 28 | // #define STEPMOTOR_I2C_ADDR 0x71 29 | 30 | Module_GRBL _GRBL(STEPMOTOR_I2C_ADDR); 31 | 32 | void setup() 33 | { 34 | // put your setup code here, to run once: 35 | M5.begin(); 36 | M5.Power.begin(); 37 | Wire.begin(21, 22); 38 | _GRBL.Init(&Wire); 39 | Serial.begin(115200); 40 | m5.Lcd.setTextColor(WHITE, BLACK); 41 | m5.Lcd.setTextSize(3); 42 | m5.lcd.setBrightness(100); 43 | M5.Lcd.setCursor(80, 40); 44 | M5.Lcd.println("GRBL 13.2"); 45 | M5.Lcd.setCursor(50, 80); 46 | M5.Lcd.println("Press Btn A/B"); 47 | M5.Lcd.setCursor(50, 120); 48 | M5.Lcd.println("Control Motor"); 49 | _GRBL.setMode("absolute"); 50 | } 51 | 52 | void loop() 53 | { 54 | // If Button A was pressed,stepmotor will rotate back and forth at a time 55 | // 如果按下按钮 A,步进电机将一次来回旋转 56 | if (M5.BtnA.wasPressed()) // A button 57 | { 58 | Serial.print(_GRBL.readStatus()); 59 | _GRBL.setMotor(5, 5, 5, 200); 60 | _GRBL.setMotor(0, 0, 0, 200); 61 | } 62 | 63 | if (M5.BtnB.wasPressed()) { 64 | // USE Gcode 65 | _GRBL.sendGcode("G1 X5Y5Z5 F200"); 66 | _GRBL.sendGcode("G1 X0Y0Z0 F200"); 67 | } 68 | 69 | if (M5.BtnC.wasReleased()) { 70 | _GRBL.unLock(); 71 | } 72 | M5.update(); 73 | } 74 | -------------------------------------------------------------------------------- /examples/Unit/ANGLE/ANGLE.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Angle 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | int sensorPin = 36; // set the input pin for the potentiometer. 设置角度计的输入引脚 16 | int last_sensorValue = 100; // Stores the value last read by the sensor. 存储传感器上次读取到的值 17 | int cur_sensorValue = 0; // Stores the value currently read by the sensor. 18 | // 存储传感器当前读取到的值 19 | 20 | void setup() 21 | { 22 | M5.begin(); // Init M5Stack. 初始化M5Stack 23 | M5.Power.begin(); // Init power 初始化电源模块 24 | pinMode(sensorPin, INPUT); // Sets the specified pin to input mode. 设置指定引脚为输入模式 25 | dacWrite(25, 0); 26 | M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字体大小为2 27 | M5.Lcd.print("the value of ANGLE: "); 28 | } 29 | 30 | void loop() 31 | { 32 | cur_sensorValue = analogRead(sensorPin); // read the value from the sensor. 读取当前传感器的值 33 | M5.Lcd.setCursor(0, 25); // Place the cursor at (0,25). 将光标固定在(0,25) 34 | if (abs(cur_sensorValue - last_sensorValue) > 10) { // debaunce 35 | M5.Lcd.fillRect(0, 25, 100, 25, BLACK); 36 | M5.Lcd.print(cur_sensorValue); 37 | last_sensorValue = cur_sensorValue; 38 | } 39 | delay(50); 40 | } 41 | -------------------------------------------------------------------------------- /examples/Unit/BPS_QMP6988/BPS_QMP6988.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit BPS v1.1 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5UnitENV: https://github.com/m5stack/M5Unit-ENV 11 | * M5Unifiedd@^0.2.2: https://github.com/m5stack/M5Unified 12 | * M5GFX@^0.2.3: https://github.com/m5stack/M5GFX 13 | */ 14 | 15 | #include 16 | #include "M5UnitENV.h" 17 | 18 | QMP6988 qmp; 19 | 20 | void setup() 21 | { 22 | M5.begin(); 23 | 24 | if (!qmp.begin(&Wire, QMP6988_SLAVE_ADDRESS_L, 32, 33, 400000U)) { 25 | Serial.println("Couldn't find QMP6988"); 26 | while (1) delay(1); 27 | } 28 | } 29 | 30 | void loop() 31 | { 32 | if (qmp.update()) { 33 | Serial.println("-----QMP6988-----"); 34 | Serial.print(F("Temperature: ")); 35 | Serial.print(qmp.cTemp); 36 | Serial.println(" *C"); 37 | Serial.print(F("Pressure: ")); 38 | Serial.print(qmp.pressure); 39 | Serial.println(" Pa"); 40 | Serial.print(F("Approx altitude: ")); 41 | Serial.print(qmp.altitude); 42 | Serial.println(" m"); 43 | Serial.println("-------------\r\n"); 44 | } 45 | delay(1000); 46 | } -------------------------------------------------------------------------------- /examples/Unit/BUTTON/BUTTON.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Button 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | int last_value = 0; 16 | int cur_value = 0; 17 | 18 | void setup() 19 | { 20 | M5.begin(); // Init M5Stack. 初始化M5Stack 21 | M5.Power.begin(); // Init power 初始化电源模块 22 | pinMode(36, INPUT); // set pin mode to input.设置引脚模式为输入模式 23 | M5.Lcd.setTextColor(YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 24 | M5.Lcd.setTextSize(2); // Setting the Font size. 设置字号大小 25 | M5.Lcd.setCursor(80, 0); // Set the cursor position to (80,0). 将光标位置设置为(80,0) 26 | M5.Lcd.println("Button example"); 27 | M5.Lcd.setTextColor(WHITE); 28 | } 29 | 30 | void loop() 31 | { 32 | cur_value = digitalRead(36); // read the value of BUTTON. 读取36号引脚的值 33 | M5.Lcd.setCursor(80, 25); 34 | M5.Lcd.print("Button"); 35 | M5.Lcd.setCursor(0, 45); 36 | M5.Lcd.print("Value: "); 37 | M5.Lcd.setCursor(0, 85); 38 | M5.Lcd.print("State: "); 39 | if (cur_value != last_value) { 40 | M5.Lcd.fillRect(85, 45, 75, 85, 41 | BLACK); // Draw a black rectangle 75 by 85 at (85,45). 42 | // 在(85,45)处绘制宽75,高85的黑色矩形 43 | if (cur_value == 0) { 44 | M5.Lcd.setCursor(95, 45); 45 | M5.Lcd.print("0"); // display the status 46 | M5.Lcd.setCursor(95, 85); 47 | M5.Lcd.print("pre"); 48 | } else { 49 | M5.Lcd.setCursor(95, 45); 50 | M5.Lcd.print("1"); // display the status 51 | M5.Lcd.setCursor(95, 85); 52 | M5.Lcd.print("rel"); 53 | } 54 | last_value = cur_value; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /examples/Unit/CATCH/CATCH.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Catch 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | const int servoPin = 26; 16 | int freq = 50; 17 | int ledChannel = 0; 18 | int resolution = 10; 19 | void setup() 20 | { 21 | // put your setup code here, to run once: 22 | M5.begin(); 23 | M5.Power.begin(); 24 | M5.Lcd.setCursor(100, 50, 4); 25 | M5.Lcd.println("Catch Unit"); 26 | M5.Lcd.setCursor(40, 120, 4); 27 | M5.Lcd.println("Connect to the Port B"); 28 | ledcSetup(ledChannel, freq, resolution); 29 | ledcAttachPin(servoPin, ledChannel); 30 | } 31 | 32 | void loop() 33 | { 34 | // High level 0.5ms is angle 0° 35 | // duty = 0.5/20ms = 0.025, 0.025*1023≈25 36 | ledcWrite(ledChannel, 25); 37 | delay(2000); 38 | // High level 1ms is angle 45° 39 | // duty = 1/20ms = 0.05, 0.05*1023≈50 40 | ledcWrite(ledChannel, 50); 41 | delay(2000); 42 | } 43 | -------------------------------------------------------------------------------- /examples/Unit/CATEAR_SK6812/CATEAR_SK6812.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + SK6812 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * FastLED@^3.9.10: https://github.com/FastLED/FastLED 12 | */ 13 | 14 | #include 15 | #include "FastLED.h" 16 | 17 | #define Neopixel_PIN (21) 18 | #define NUM_LEDS (118) 19 | 20 | CRGB leds[NUM_LEDS]; 21 | uint8_t gHue = 0; 22 | static TaskHandle_t FastLEDshowTaskHandle = 0; 23 | static TaskHandle_t userTaskHandle = 0; 24 | void setup() 25 | { 26 | M5.begin(); 27 | M5.Power.begin(); 28 | 29 | M5.Lcd.clear(BLACK); 30 | M5.Lcd.setTextColor(YELLOW); 31 | M5.Lcd.setTextSize(2); 32 | M5.Lcd.setCursor(60, 160); 33 | M5.Lcd.println("CatEar Example"); 34 | M5.Lcd.setTextColor(WHITE); 35 | // Neopixel initialization 36 | FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); 37 | FastLED.setBrightness(10); 38 | xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2048, NULL, 2, NULL, 1); 39 | } 40 | 41 | void loop() 42 | { 43 | } 44 | 45 | void FastLEDshowESP32() 46 | { 47 | if (userTaskHandle == 0) { 48 | userTaskHandle = xTaskGetCurrentTaskHandle(); 49 | xTaskNotifyGive(FastLEDshowTaskHandle); 50 | const TickType_t xMaxBlockTime = pdMS_TO_TICKS(200); 51 | ulTaskNotifyTake(pdTRUE, xMaxBlockTime); 52 | userTaskHandle = 0; 53 | } 54 | } 55 | 56 | void FastLEDshowTask(void *pvParameters) 57 | { 58 | for (;;) { 59 | fill_rainbow(leds, NUM_LEDS, gHue, 7); // rainbow effect 60 | FastLED.show(); // must be executed for neopixel becoming effective 61 | EVERY_N_MILLISECONDS(20) 62 | { 63 | gHue++; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /examples/Unit/CardKB/CardKB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit CardKB 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define CARDKB_ADDR (0x5F) // Define the I2C address of CardKB. 定义CardKB的I2C地址 16 | 17 | void setup() 18 | { 19 | M5.begin(); // Init M5Stack. 初始化M5Stack 20 | M5.Power.begin(); // Init power 初始化电源模块 21 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 22 | M5.Lcd.printf("CardKB Test\n"); 23 | M5.Lcd.printf(">>"); 24 | } 25 | void loop() 26 | { 27 | Wire.requestFrom(CARDKB_ADDR, 1); // Request 1 byte from the slave device. 向从设备请求1字节 28 | while (Wire.available()) // If received data is detected. 如果检测到收到数据 29 | { 30 | char c = Wire.read(); // Store the received data. 将接收到的数据存储 31 | if (c != 0) { 32 | M5.Lcd.printf("%c", c); 33 | Serial.println(c, HEX); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/Unit/DAC_MCP4725/DAC_MCP4725.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit DAC 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * Adafruit_MCP4725: https://github.com/adafruit/Adafruit_MCP4725 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | #define DAC_ADDR \ 18 | (0x60) // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR 19 | // pin tied to VCC) For MCP4725A0 the address is 0x60 or 0x61 For 20 | // MCP4725A2 the address is 0x64 or 0x65 21 | 22 | Adafruit_MCP4725 dac; 23 | 24 | void setup(void) 25 | { 26 | M5.begin(true, false, false); // Init M5Stack. 初始化M5Stack 27 | M5.Power.begin(); // Init power 初始化电源模块 28 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 29 | M5.Lcd.print(" DAC MCP4725 demo."); 30 | dac.begin(0x60); // Setups the hardware address and checks the DAC was 31 | // found. 设置硬件地址并检查是否找到DAC 32 | dac.setVoltage(2048, false); 33 | } 34 | 35 | void loop(void) 36 | { 37 | M5.Lcd.setCursor(100, 60); 38 | M5.Lcd.print("1.2V"); 39 | dac.setVoltage(1024, false); // Set the voltage to 1.2V and retain the current 40 | // voltage output after power off or reset. 41 | // 设置电压为1.2v,关闭断电或复位后保留当前电压输出 42 | delay(1000); 43 | M5.Lcd.fillRect(100, 60, 120, 40, BLACK); // Draw a black rectangle at (100,60) with a width of 120 and a 44 | // height of 40. 在(100,60)处绘制一个宽为120,高为40的黑色矩形 45 | M5.Lcd.print("2.4V"); 46 | dac.setVoltage(2048, false); // 2.4v 47 | delay(1000); 48 | M5.Lcd.fillRect(100, 60, 120, 40, BLACK); 49 | } -------------------------------------------------------------------------------- /examples/Unit/EARTH/EARTH.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Earth 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | M5.begin(); // Init M5Stack. 初始化M5Stack 18 | M5.Power.begin(); // Init power 初始化电源模块 19 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 20 | M5.Lcd.printf("UNIT_EARTH EXAMPLE\n"); 21 | pinMode(26, INPUT); // Set pin 26 to input mode. 将引脚26设置为输入模式 22 | dacWrite(25, 0); // disable the speak noise. 禁用喇叭 23 | } 24 | 25 | void loop() 26 | { 27 | M5.Lcd.setCursor(0, 80); // Set the cursor at (0,80). 将光标设置在(0,80) 28 | M5.Lcd.printf("AnalogRead:%d\n", analogRead(36)); 29 | M5.Lcd.printf("DigitalRead:%d\n", digitalRead(26)); 30 | delay(1000); 31 | } 32 | -------------------------------------------------------------------------------- /examples/Unit/EXT_IO_PCA9554PW/EXT_IO_PCA9554PW.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit EXT.IO 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * PCA9554: https://github.com/Tinyu-Zhao/PCA9554 12 | */ 13 | 14 | #include 15 | #include "PCA9554.h" 16 | 17 | PCA9554 ioCon1(0x27); // Create an object at this address. 在这个地址上创建一个对象 18 | 19 | uint8_t res; 20 | void setup() 21 | { 22 | M5.begin(); 23 | M5.Power.begin(); 24 | Wire.begin(); 25 | M5.Lcd.setTextSize(2); 26 | M5.Lcd.setTextColor(YELLOW); 27 | M5.Lcd.setCursor(0, 90); 28 | M5.Lcd.print("UNIT_IO EXAMPLE\n"); 29 | 30 | ioCon1.twiWrite(21, 22); // Sets the I2C pin of the connection. 设置连接的I2C引脚 31 | delay(10); 32 | res = 1; 33 | ioCon1.twiRead(res); 34 | Serial.printf("res:%d\r\n", res); 35 | 36 | ioCon1.portMode(ALLOUTPUT); // Set the port as all output. 设置所有引脚为输出模式 37 | } 38 | 39 | void loop() 40 | { 41 | for (int i = 0; i < 8; i++) ioCon1.digitalWrite(i, LOW); 42 | delay(1000); 43 | for (int i = 0; i < 8; i++) ioCon1.digitalWrite(i, HIGH); 44 | delay(1000); 45 | 46 | // write 0-7 HIGH. 设置0~7号引脚为高电平 47 | Serial.println(ioCon1.digitalWritePort(0xff)); 48 | delay(200); 49 | 50 | // write 0-7 LOW. 设置0~7号引脚为低电平 51 | Serial.println(ioCon1.digitalWritePort(0x00)); 52 | delay(200); 53 | 54 | // write Port, the same read 55 | for (byte i = 0; i < 8; i++) { 56 | ioCon1.digitalWritePort((1 << i)); 57 | delay(200); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/Unit/FADER/FADER.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Fader 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * FastLED@^3.9.10: https://github.com/FastLED/FastLED 12 | */ 13 | 14 | #include "FastLED.h" 15 | #include "M5Stack.h" 16 | 17 | // How many leds in your strip? 18 | #define NUM_LEDS (14) 19 | #define INPUT_PINS (36) 20 | #define DATA_PIN (26) 21 | 22 | // Define the array of leds 23 | CRGB leds[NUM_LEDS]; 24 | 25 | uint8_t beginHue = 0; 26 | uint8_t deltaHue = 30; 27 | uint8_t brightness = 100; 28 | uint16_t rawADC = 0; 29 | 30 | void setup() 31 | { 32 | M5.begin(); 33 | M5.Lcd.setTextDatum(MC_DATUM); 34 | M5.Lcd.drawString("FADER UNIT TEST", 160, 60, 4); 35 | FastLED.addLeds(leds, NUM_LEDS); 36 | delay(1000); 37 | pinMode(36, INPUT); 38 | fill_rainbow(leds, NUM_LEDS, beginHue, deltaHue); 39 | } 40 | 41 | void loop() 42 | { 43 | rawADC = analogRead(INPUT_PINS); // Read ADC value 读取ADC数值 44 | brightness = map(rawADC, 0, 4095, 0, 255); // The mapping ADC value is the brightness value 45 | // range 映射ADC值为亮度值范围 46 | FastLED.setBrightness(brightness); // Adjust the brightness of the FADER 47 | // LED 调整FADER LED灯亮度 48 | FastLED.show(); 49 | Serial.printf("%d\r\n", rawADC); 50 | M5.Lcd.fillRect(0, 120, 320, 100, BLACK); 51 | M5.Lcd.drawString("value: " + String(rawADC), 160, 160, 4); 52 | delay(100); 53 | } -------------------------------------------------------------------------------- /examples/Unit/FAN/FAN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Fan 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define motor_pin (26) 16 | 17 | int freq = 10000; 18 | int ledChannel = 0; 19 | int resolution = 10; 20 | void setup() 21 | { 22 | M5.begin(); // Init M5Stack. 初始化M5Stack 23 | M5.Power.begin(); // Init power 初始化电源模块 24 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 25 | M5.Lcd.setCursor(140, 26 | 10); // Set the cursor at (140,10). 将光标设置在(140,10)处 27 | M5.Lcd.println("Fan"); 28 | ledcSetup(ledChannel, freq, resolution); // Sets the frequency and number of counts corresponding 29 | // to the channel. 设置通道对应的频率和计数位数 30 | ledcAttachPin(motor_pin, ledChannel); // Binds the specified channel to the specified I/O port 31 | // for output. 将指定通道绑定到指定 IO 口上以实现输出 32 | } 33 | 34 | void loop() 35 | { 36 | ledcWrite(ledChannel, 512); // Output PWM. 输出PWM 37 | delay(1000); 38 | ledcWrite(ledChannel, 0); 39 | delay(1000); 40 | } 41 | -------------------------------------------------------------------------------- /examples/Unit/GLASS/GLASS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Glass 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * M5Unit-GLASS: https://github.com/m5stack/M5Unit-GLASS 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | UNIT_GLASS Glass; 18 | String string_buffer; 19 | 20 | void setup() 21 | { 22 | M5.begin(1, 0, 1, 0); 23 | M5.Lcd.setTextSize(3); 24 | M5.Lcd.setTextColor(0x867D); 25 | M5.Lcd.printf(" Unit Glass Demo\n\n\n"); 26 | M5.Lcd.printf(" Please connect\n\n your Unit-Glass\n\n"); 27 | M5.Lcd.printf(" to PORT-A\n\n <--"); 28 | 29 | /* Unit-Glass init */ 30 | Glass.begin(&Wire, GLASS_ADDR, 21, 22, 100000UL); 31 | Glass.invert(0); 32 | Glass.color_invert(0); 33 | Glass.clear(); 34 | 35 | /* Draw title on Unit-Glass */ 36 | string_buffer = "M5STACK"; 37 | Glass.set_string_buffer(string_buffer.c_str()); 38 | Glass.draw_string(36, 0, 16, 1); 39 | delay(20); // Ensure complete character display. 保证字符显示完全 40 | string_buffer = "2023-02-24"; 41 | Glass.set_string_buffer(string_buffer.c_str()); 42 | Glass.draw_string(24, 24, 16, 1); 43 | Glass.show(); 44 | } 45 | 46 | void loop() 47 | { 48 | /* When key on Unit-Glass was pressed, update conut and print it out */ 49 | static int count = 0; 50 | if (Glass.getKeyA() == 0) { 51 | Glass.setBuzzer(1500, 128); 52 | Glass.enable_buzz(); 53 | delay(50); 54 | Glass.disable_buzz(); 55 | count++; 56 | } else if (Glass.getKeyB() == 0) { 57 | Glass.setBuzzer(2300, 128); 58 | Glass.enable_buzz(); 59 | delay(50); 60 | Glass.disable_buzz(); 61 | count--; 62 | } 63 | 64 | string_buffer = "Count: "; 65 | string_buffer += count; 66 | string_buffer += " "; 67 | Glass.set_string_buffer(string_buffer.c_str()); 68 | Glass.draw_string(36, 48, 16, 1); 69 | Glass.show(); 70 | delay(20); 71 | } 72 | -------------------------------------------------------------------------------- /examples/Unit/GPS_AT6558/GPSRaw/GPSRaw.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit GPS 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5GFX@^0.2.3: https://github.com/m5stack/M5GFX 11 | * M5Unified@^0.2.2: https://github.com/m5stack/M5Unified 12 | */ 13 | 14 | #include 15 | #include "M5GFX.h" 16 | 17 | HardwareSerial GPSRaw(2); 18 | 19 | M5GFX display; 20 | M5Canvas canvas(&display); 21 | 22 | void setup() 23 | { 24 | M5.begin(); 25 | M5.Power.begin(); 26 | GPSRaw.begin(9600); 27 | 28 | display.begin(); 29 | 30 | canvas.setColorDepth(1); // mono color 31 | canvas.setFont(&fonts::efontCN_14); 32 | canvas.createSprite(display.width(), display.height()); 33 | canvas.setTextSize(2); 34 | canvas.setPaletteColor(1, GREEN); 35 | canvas.setTextScroll(true); 36 | 37 | canvas.println("GPS Raw Example"); 38 | canvas.pushSprite(0, 0); 39 | } 40 | 41 | void loop() 42 | { 43 | // put your main code here, to run repeatedly: 44 | if (Serial.available()) { 45 | int ch = Serial.read(); 46 | GPSRaw.write(ch); 47 | } 48 | 49 | if (GPSRaw.available()) { 50 | int ch = GPSRaw.read(); 51 | Serial.write(ch); 52 | canvas.print(ch); 53 | canvas.pushSprite(0, 0); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /examples/Unit/HALL/HALL.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Hall 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define HALL (36) 16 | 17 | void setup() 18 | { 19 | M5.begin(); // Init M5Stack. 初始化M5Stack 20 | M5.Power.begin(); // Init power 初始化电源模块 21 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 22 | M5.Lcd.print(" HALL Sensor"); 23 | pinMode(HALL, INPUT); // Set the pins to which the Hall sensor is connected to 24 | // the input mode. 将霍尔传感器所连接的引脚设置为输入模式 25 | } 26 | 27 | void loop() 28 | { 29 | bool status = digitalRead(HALL); 30 | M5.Lcd.setCursor(20, 80); 31 | M5.Lcd.printf("Hall status : %d", status); 32 | } 33 | -------------------------------------------------------------------------------- /examples/Unit/HEART_MAX30100/MAX30100_RawData/MAX30100_RawData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Heart 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * Arduino-MAX30100: https://github.com/oxullo/Arduino-MAX30100 12 | */ 13 | 14 | #include 15 | #include "MAX30100.h" 16 | 17 | #define SAMPLING_RATE (MAX30100_SAMPRATE_100HZ) 18 | #define IR_LED_CURRENT (MAX30100_LED_CURR_24MA) 19 | #define RED_LED_CURRENT (MAX30100_LED_CURR_27_1MA) 20 | #define PULSE_WIDTH (MAX30100_SPC_PW_1600US_16BITS) 21 | #define HIGHRES_MODE (true) 22 | 23 | MAX30100 sensor; // Instantiate a MAX30100 sensor class. 实例化一个MAX30100传感器类 24 | 25 | void setup() 26 | { 27 | M5.begin(); // Init M5Stack. 初始化M5Stack 28 | M5.Power.begin(); // Init power 初始化电源模块 29 | Serial.print("Initializing MAX30100.."); 30 | 31 | while (!sensor.begin()) { // Initialize the sensor. 初始化传感器 32 | M5.Lcd.setTextFont(4); 33 | M5.Lcd.setCursor(50, 100, 4); 34 | M5.Lcd.println("Sensor not found"); 35 | delay(1000); 36 | } 37 | M5.Lcd.fillScreen(BLACK); 38 | // Set up the wanted parameters. 设置所需的参数 39 | sensor.setMode(MAX30100_MODE_SPO2_HR); 40 | sensor.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT); 41 | sensor.setLedsPulseWidth(PULSE_WIDTH); 42 | sensor.setSamplingRate(SAMPLING_RATE); 43 | sensor.setHighresModeEnabled(HIGHRES_MODE); 44 | } 45 | 46 | void loop() 47 | { 48 | uint16_t ir, red; 49 | sensor.update(); // 更新传感器读取到的数据 50 | while (sensor.getRawValues(&ir, &red)) { // 如果获取到数据 51 | M5.Lcd.setTextFont(4); 52 | M5.Lcd.setCursor(100, 100, 4); 53 | M5.Lcd.printf("IR:%d ", ir); 54 | M5.Lcd.setCursor(100, 130, 4); 55 | M5.Lcd.printf("RED:%d ", red); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /examples/Unit/HEX_SK6812/HEX_SK6812.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit HEX 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * FastLED@^3.9.10: https://github.com/FastLED/FastLED 12 | */ 13 | 14 | #include 15 | #include "FastLED.h" 16 | 17 | #define Neopixel_PIN (21) 18 | #define NUM_LEDS (37) 19 | 20 | CRGB leds[NUM_LEDS]; 21 | uint8_t gHue = 0; // Initial tone value. 起始色调数值 22 | 23 | void setup() 24 | { 25 | M5.begin(); // Init M5Stack. 初始化M5Stack 26 | M5.Power.begin(); // Init power 初始化电源模块 27 | M5.Lcd.setTextSize(2); // 设置字号大小为2 28 | M5.Lcd.println(" HEX Example"); 29 | M5.Lcd.println("Display rainbow effect"); 30 | 31 | // Neopixel initialization. 初始化灯带 32 | FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); 33 | FastLED.setBrightness(5); // set the LED brightness to 5. 设置灯带的亮度为5 34 | } 35 | 36 | void loop() 37 | { 38 | fill_rainbow(leds, NUM_LEDS, gHue, 39 | 7); // Set the leds from 0 to 37 beads to gradient rainbow color, the 40 | // starting tone value to gHue, and the color difference between 41 | // adjacent beads to 7. 42 | // 将leds灯带的从0~37个灯珠设置为渐变彩虹色,起始色调数值设置为gHue,相邻灯珠色差为7 43 | FastLED.show(); // Updated LED color. 更新LED色彩 44 | EVERY_N_MILLISECONDS(20) 45 | { 46 | gHue++; 47 | } // The program is executed every 20 milliseconds. 48 | // 每20毫秒执行一次其中的程序 49 | } 50 | -------------------------------------------------------------------------------- /examples/Unit/IR/IR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit IR 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | int ir_recv_pin = 36; // set the input pin. 设置引脚 16 | int ir_send_pin = 26; 17 | 18 | int last_recv_value = 0; 19 | int cur_recv_value = 0; 20 | 21 | void setup() 22 | { 23 | M5.begin(); 24 | M5.Power.begin(); 25 | pinMode(ir_recv_pin, INPUT); 26 | pinMode(ir_send_pin, OUTPUT); 27 | // send infrared light. 发送红外线 28 | // now, you can see the infrared light through mobile phone camera. 29 | // 现在,你可以通过手机摄像头看到红外光 30 | digitalWrite(ir_send_pin, 1); 31 | M5.Lcd.setTextSize(2); 32 | M5.Lcd.setCursor(0, 0); 33 | M5.Lcd.print("Test for IR receiver: "); 34 | } 35 | 36 | void loop() 37 | { 38 | // now, once you press the button on a remote controller to send infrared 39 | // light. 现在,一旦你按下遥控器上的按钮发送红外线 the screen will display 40 | // "detected!" 屏幕将显示“检测到!” 41 | cur_recv_value = digitalRead(ir_recv_pin); 42 | if (last_recv_value != cur_recv_value) { 43 | M5.Lcd.setCursor(0, 25); 44 | M5.Lcd.fillRect(0, 25, 150, 25, BLACK); 45 | if (cur_recv_value == 0) { // 0: detected 1: not detected, 0检测到,1没有检测到 46 | M5.Lcd.print("detected!"); 47 | } 48 | last_recv_value = cur_recv_value; 49 | } 50 | Serial.println(cur_recv_value); 51 | } 52 | -------------------------------------------------------------------------------- /examples/Unit/ISO485/ISO485.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit RS485-ISO 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | String str = ""; 16 | 17 | void setup() 18 | { 19 | M5.begin(); 20 | M5.Lcd.drawString("ISO485", 20, 0, 2); 21 | Serial2.begin(115200, SERIAL_8N1, 16, 17); 22 | M5.Lcd.setCursor(0, 20); 23 | } 24 | 25 | void loop() 26 | { 27 | if (M5.BtnA.wasPressed()) { 28 | Serial2.write("Hello World\r\n"); 29 | } 30 | 31 | if (Serial2.available()) { 32 | char ch = Serial2.read(); 33 | str += ch; 34 | if (str.endsWith("\r\n")) { 35 | Serial.print(str); 36 | M5.Lcd.print(str); 37 | str = ""; 38 | } 39 | } 40 | M5.update(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/Unit/JOYSTICK/JOYSTICK.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Joystick v1.1 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define JOY_ADDR (0x52) // define Joystick I2C address. 定义摇杆的I2C地址 16 | 17 | void setup() 18 | { 19 | M5.begin(); 20 | M5.Power.begin(); 21 | M5.Lcd.setCursor(70, 0, 4); 22 | M5.Lcd.println(("Joystick Test")); 23 | dacWrite(25, 0); // disable the speak noise. 禁用语音噪音 24 | Wire.begin(21, 22, 400000UL); 25 | } 26 | 27 | char data[100]; 28 | void loop() 29 | { 30 | static uint8_t x_data, y_data, button_data; 31 | Wire.requestFrom(JOY_ADDR, 32 | 3); // Request 3 bytes from the slave device. 向从设备请求3个字节 33 | if (Wire.available()) { // If data is received. 如果接收到数据 34 | x_data = Wire.read(); 35 | y_data = Wire.read(); 36 | button_data = Wire.read(); 37 | sprintf(data, "x:%d y:%d button:%d\n", x_data, y_data, button_data); 38 | Serial.print(data); 39 | 40 | M5.Lcd.setCursor(100, 50, 4); 41 | M5.Lcd.printf("X:%d ", x_data); 42 | M5.Lcd.setCursor(100, 80, 4); 43 | M5.Lcd.printf("Y:%d ", y_data); 44 | M5.Lcd.setCursor(100, 110, 4); 45 | M5.Lcd.printf("B:%d ", button_data); 46 | } 47 | delay(200); 48 | } 49 | -------------------------------------------------------------------------------- /examples/Unit/KEY/KEY-DEMO1/KEY-DEMO1.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Key 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * FastLED@^3.9.10: https://github.com/FastLED/FastLED 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | uint8_t ledColor = 0; 18 | 19 | #define KEY_PIN 36 20 | #define DATA_PIN 26 21 | 22 | CRGB LED[1]; 23 | 24 | void setup() 25 | { 26 | M5.begin(); 27 | M5.Lcd.setTextSize(3); 28 | M5.Lcd.print("\n UNIT-KEY Example\n\n Key State:"); 29 | /* Init key pin */ 30 | pinMode(KEY_PIN, INPUT_PULLUP); 31 | /* Init RGB led */ 32 | FastLED.addLeds(LED, 1); 33 | LED[0] = CRGB::Blue; 34 | FastLED.setBrightness(0); 35 | } 36 | 37 | void loop() 38 | { 39 | /* If Key was pressed */ 40 | if (!digitalRead(KEY_PIN)) { 41 | M5.Lcd.setCursor(75, 130); 42 | M5.Lcd.print((" Pressed ")); 43 | FastLED.setBrightness(255); 44 | FastLED.show(); 45 | /* Hold until the key released */ 46 | while (!digitalRead(KEY_PIN)); 47 | } else { 48 | M5.Lcd.setCursor(75, 130); 49 | M5.Lcd.println(("Released")); 50 | FastLED.setBrightness(0); 51 | FastLED.show(); 52 | } 53 | delay(100); 54 | } -------------------------------------------------------------------------------- /examples/Unit/LASER/LASER.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Laser R/TX 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | char ch; 16 | // serial 2 write and read 17 | // #define RX 18 | void setup() 19 | { 20 | M5.begin(); 21 | M5.Power.begin(); 22 | Serial.begin(115200); 23 | 24 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 25 | // txPin, bool invert) 26 | Serial2.begin(9600, SERIAL_8N1, 16, 17); 27 | pinMode(5, OUTPUT); 28 | digitalWrite(5, 1); 29 | 30 | M5.Lcd.setTextSize(4); 31 | M5.Lcd.setTextColor(GREEN); 32 | M5.Lcd.setCursor(60, 50); 33 | #ifdef RX 34 | M5.Lcd.print("LASER RX"); 35 | #elif defined TX 36 | M5.Lcd.print("LASER TX"); 37 | #else 38 | M5.Lcd.setCursor(30, 50); 39 | M5.Lcd.print("LASER TX/RX"); 40 | M5.Lcd.setCursor(50, 200); 41 | M5.Lcd.print('A'); 42 | M5.Lcd.setCursor(150, 200); 43 | M5.Lcd.print('B'); 44 | M5.Lcd.setCursor(240, 200); 45 | M5.Lcd.print('C'); 46 | #endif 47 | M5.Lcd.setCursor(0, 100); 48 | } 49 | 50 | void loop() 51 | { 52 | #ifdef RX 53 | M5.update(); 54 | if (Serial2.available()) { 55 | char ch = Serial2.read(); 56 | M5.Lcd.print(ch); 57 | } 58 | 59 | if (M5.BtnA.wasReleased()) { 60 | M5.Lcd.clear(); 61 | M5.Lcd.setCursor(0, 0); 62 | } 63 | #elif defined TX 64 | Serial2.write('A'); 65 | delay(50); 66 | #else 67 | if (M5.BtnA.wasReleased()) { 68 | ch = 'A'; 69 | Serial2.write(ch); 70 | } else if (M5.BtnB.wasReleased()) { 71 | ch = 'B'; 72 | Serial2.write(ch); 73 | } else if (M5.BtnC.wasReleased()) { 74 | ch = 'C'; 75 | Serial2.write(ch); 76 | } 77 | M5.update(); 78 | if (Serial2.available()) { 79 | char ch = Serial2.read(); 80 | M5.Lcd.print(ch); 81 | } 82 | #endif 83 | } 84 | -------------------------------------------------------------------------------- /examples/Unit/LCD_ST7789V2/LCD_ST7789V2.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit LCD 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | M5UnitLCD display; 16 | 17 | M5Canvas canvas(&display); 18 | 19 | static constexpr char text[] = 20 | "Hello world ! こんにちは世界! this is long long string sample. " 21 | "寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う" 22 | "寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、" 23 | "シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長" 24 | "久命の長助"; 25 | static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); 26 | int textpos = 0; 27 | int scrollstep = 2; 28 | 29 | void setup(void) 30 | { 31 | display.init(); // Initialize the display. 初始化显示屏 32 | display.setRotation(3); // Rotating display. 旋转显示屏 33 | canvas.setColorDepth(1); // Set the color depth. 设置色深 34 | canvas.setFont(&fonts::lgfxJapanMinchoP_32); // Set the font. 设置字体 35 | canvas.setTextSize(2); // Set the font size. 设置字号 36 | canvas.createSprite(display.width() + 64, 72); // Create a canvas with a wide display width of +64 and a height 37 | // of 72. 创建一块宽显示屏宽度+64,高72的画布 38 | } 39 | 40 | void loop(void) 41 | { 42 | int32_t cursor_x = canvas.getCursorX() - scrollstep; 43 | if (cursor_x <= 0) { 44 | textpos = 0; 45 | cursor_x = display.width(); 46 | } 47 | 48 | canvas.setCursor(cursor_x, 0); // Set the cursor position. 设置光标的位置 49 | canvas.scroll(-scrollstep, 0); // Set the rolling. 设置滚动 50 | while (textpos < textlen && cursor_x <= display.width()) { 51 | canvas.print(text[textpos++]); 52 | cursor_x = canvas.getCursorX(); 53 | } 54 | display.waitDisplay(); 55 | canvas.pushSprite( 56 | &display, 0, 57 | (display.height() - canvas.height()) >> 1); // Displays the contents of the canvas. 显示画布上的内容 58 | } -------------------------------------------------------------------------------- /examples/Unit/LIGHT/LIGHT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Light 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | TFT_eSprite img = TFT_eSprite(&M5.Lcd); 16 | 17 | void setup() 18 | { 19 | M5.begin(); // Init M5Stack. 初始化M5Stack 20 | M5.Power.begin(); // Init power 初始化电源模块 21 | img.setColorDepth(8); 22 | img.createSprite(320, 240); // 创建一块320x240的画布 23 | img.setTextSize(2); 24 | pinMode(26, INPUT); // Set pin 26 as input mode. 设置引脚26为输入模式 25 | } 26 | 27 | void loop() 28 | { 29 | static uint16_t digitalRead_value = 0, analogRead_value = 0; 30 | analogRead_value = analogRead(36); // Store the analog quantity read from 31 | // pin 36. 将36号引脚读取到的模拟量存储 32 | digitalRead_value = digitalRead(26); // Store the number read from pin 26. 将26号引脚读取到的数字量存储 33 | img.fillRect(0, 0, 320, 240, 0x00); 34 | img.drawString("UNIT_LIGHT EXAMPLE", 40, 0); 35 | img.setCursor(90, 30); 36 | img.printf("Analog:%d\n", analogRead_value); 37 | img.setCursor(90, 50); 38 | img.printf("Digital:%d\n", digitalRead_value); 39 | img.pushSprite(0, 0); // 把画布推送到屏幕(0,0)处 40 | delay(10); 41 | } 42 | -------------------------------------------------------------------------------- /examples/Unit/LIMIT/LIMIT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Limit 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define KEY_PIN 36 // Define Limit Pin. 定义Limit连接引脚 16 | 17 | void setup() 18 | { 19 | M5.begin(); // Init M5Stack 初始化M5Stack 20 | M5.Lcd.setTextSize(4); 21 | M5.Lcd.print(("\n UNIT-LIMIT\n Example")); 22 | pinMode(KEY_PIN, INPUT_PULLUP); // Init Limit pin. 初始化Limit引脚. 23 | } 24 | 25 | void loop() 26 | { 27 | if (!digitalRead(KEY_PIN)) { // If Limit was hit. 如果触碰了Limit. 28 | M5.Lcd.setCursor(0, 130); 29 | M5.Lcd.print((" Hit limit!")); 30 | } else { 31 | M5.Lcd.setCursor(0, 130); 32 | M5.Lcd.println((" ")); 33 | } 34 | delay(100); 35 | } 36 | -------------------------------------------------------------------------------- /examples/Unit/MiniOLED/MiniOLED.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Mini Unit OLED 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * U8g2_Arduino: https://github.com/olikraus/U8g2_Arduino 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #define SDA_PIN (21) 19 | #define SCL_PIN (22) 20 | 21 | U8G2_SSD1306_72X40_ER_F_HW_I2C u8g2(U8G2_R0, /* reset=*/U8X8_PIN_NONE); // EastRising 0.42" OLED 22 | 23 | void setup(void) 24 | { 25 | Wire.begin(SDA_PIN, SCL_PIN); 26 | u8g2.begin(); 27 | } 28 | 29 | void loop(void) 30 | { 31 | u8g2.clearBuffer(); // clear the internal memory 32 | u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font 33 | u8g2.drawStr(10, 20, "Hello"); // write something to the internal memory 34 | u8g2.drawStr(10, 30, "M5Stack!"); 35 | u8g2.sendBuffer(); // transfer internal memory to the display 36 | delay(1000); 37 | } 38 | -------------------------------------------------------------------------------- /examples/Unit/NCIR_MLX90614/NCIR_MLX90614.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit NCIR 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | M5.begin(); 18 | M5.Power.begin(); 19 | M5.Lcd.setTextSize(3); 20 | M5.Lcd.setCursor(120, 0); 21 | M5.Lcd.print("NCIR"); 22 | } 23 | 24 | void loop() 25 | { 26 | static uint16_t result; 27 | static float temperature; 28 | Wire.beginTransmission(0x5A); // Send Initial Signal and I2C Bus Address 29 | // 发送初始信号和I2C总线地址 30 | Wire.write(0x07); // Send data only once and add one address automatically. 31 | // 只发送一次数据,并自动添加一个地址。 32 | Wire.endTransmission(false); // Stop signal 停止信号 33 | Wire.requestFrom(0x5A, 2); // Get 2 consecutive data from 0x5A, and the data is stored 34 | // only. 从0x5A中获取2个连续的数据,并且只存储这些数据。 35 | result = Wire.read(); // Receive DATA 接收数据 36 | result |= Wire.read() << 8; // Receive DATA 接收数据 37 | 38 | temperature = result * 0.02 - 273.15; 39 | M5.Lcd.setCursor(70, 100); 40 | M5.Lcd.printf("Temp:%.3f", temperature); 41 | delay(500); 42 | } 43 | -------------------------------------------------------------------------------- /examples/Unit/NEOFLASH_SK6812_PIR/DisplayCurrentTime.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef __DISPLATCURRENTTIME_H 3 | #define __DISPLATCURRENTTIME_H 4 | #include "FastLED.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define NUM_LEDS 192 11 | extern CRGB leds[NUM_LEDS]; 12 | extern void displayCurrentTime(uint16_t time4Day); 13 | extern void diaplayPoint(); 14 | extern void clearPoint(); 15 | extern void clearLeds(); 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /examples/Unit/OLED_SH1107/OLED_SH1107.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit OLED 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5GFX@^0.2.3: https://github.com/m5stack/M5GFX 11 | */ 12 | #include 13 | 14 | M5UnitOLED display; 15 | 16 | M5Canvas canvas(&display); 17 | 18 | static constexpr char text[] = 19 | "Hello world ! こんにちは世界! this is long long string sample. " 20 | "寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う" 21 | "寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、" 22 | "シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長" 23 | "久命の長助"; 24 | static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); 25 | int textpos = 0; 26 | int scrollstep = 2; 27 | 28 | void setup(void) 29 | { 30 | display.init(); // Initialize the display. 初始化显示屏 31 | display.setRotation(2); // Rotating display. 旋转显示屏 32 | canvas.setColorDepth(1); // Set the color depth. 设置色深 33 | canvas.setFont(&fonts::lgfxJapanMinchoP_32); // Set the font. 设置字体 34 | canvas.setTextWrap(false); 35 | canvas.setTextSize(2); // Set the font size. 设置字号 36 | canvas.createSprite(display.width() + 64, 37 | 72); // Create a canvas with a wide display width of +64 and a height 38 | // of 72. 创建一块宽显示屏宽度+64,高72的画布 39 | } 40 | 41 | void loop(void) 42 | { 43 | int32_t cursor_x = canvas.getCursorX() - scrollstep; 44 | if (cursor_x <= 0) { 45 | textpos = 0; 46 | cursor_x = display.width(); 47 | } 48 | 49 | canvas.setCursor(cursor_x, 0); // Set the cursor position. 设置光标的位置 50 | canvas.scroll(-scrollstep, 0); // Set the rolling. 设置滚动 51 | while (textpos < textlen && cursor_x <= display.width()) { 52 | canvas.print(text[textpos++]); 53 | cursor_x = canvas.getCursorX(); 54 | } 55 | display.waitDisplay(); 56 | canvas.pushSprite( 57 | &display, 0, 58 | (display.height() - canvas.height()) >> 1); // Displays the contents of the canvas. 显示画布上的内容 59 | } -------------------------------------------------------------------------------- /examples/Unit/OP90.180_ITR9606/OP90.180_ITR9606.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit OP90 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | M5.begin(); // Init M5Stack. 初始化M5Stack 18 | M5.Power.begin(); // Init power 初始化电源模块 19 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 20 | M5.Lcd.setCursor(80, 10); // Set the cursor at (80,10). 将光标设置在(80,10)处 21 | M5.Lcd.println("90/180 OPTICAL"); 22 | pinMode(36, INPUT_PULLUP); // Set pin 36 to input pull-up mode. 23 | // 设置36号引脚为输入上拉模式 24 | } 25 | 26 | void loop() 27 | { 28 | M5.Lcd.setCursor(80, 120); 29 | M5.Lcd.printf("IR Receive: %d", digitalRead(36)); // Output the value of pin 36. 输出36号引脚的值 30 | } 31 | -------------------------------------------------------------------------------- /examples/Unit/PIR/PIR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit PIR 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | M5.begin(); // Init M5Stack. 初始化M5Stack 18 | M5.Power.begin(); // Init power 初始化电源模块 19 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 20 | M5.Lcd.println("PIR example"); 21 | M5.Lcd.setCursor(0, 25); // Position the cursor at (0,25). 将光标固定在(0,25) 22 | M5.Lcd.println("Status: \nValue: "); 23 | pinMode(36, INPUT); // Set pin 36 to input mode. 设置36号引脚为输入模式 24 | } 25 | 26 | void loop() 27 | { 28 | M5.Lcd.fillRect(90, 25, 180, 50, BLACK); // Draw a black rectangle 180 by 50 at (90,25). 29 | // 在(90,25)处画一个宽180高50的黑的矩形 30 | if (digitalRead(36) == 1) { // If pin 36 reads a value of 1. 如果36号引脚的读取到的值为1 31 | M5.Lcd.setCursor(95, 25); 32 | M5.Lcd.print("Sensing"); 33 | M5.Lcd.setCursor(95, 45); 34 | M5.Lcd.print("1"); 35 | } else { 36 | M5.Lcd.setCursor(95, 25); 37 | M5.Lcd.print("Not Sensed"); 38 | M5.Lcd.setCursor(95, 45); 39 | M5.Lcd.print("0"); 40 | } 41 | delay(500); 42 | } -------------------------------------------------------------------------------- /examples/Unit/PbHUB/PbHUB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit PbHub 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | #include 15 | 16 | #include "porthub.h" 17 | 18 | #define X_OFFSET 10 19 | #define Y_OFFSET 18 20 | 21 | PortHub porthub; 22 | uint8_t HUB_ADDR[6] = {HUB1_ADDR, HUB2_ADDR, HUB3_ADDR, HUB4_ADDR, HUB5_ADDR, HUB6_ADDR}; 23 | 24 | void setup() 25 | { 26 | M5.begin(true, false, true); 27 | M5.Power.begin(); 28 | porthub.begin(); 29 | M5.Lcd.clear(BLACK); 30 | M5.Lcd.setTextColor(WHITE); 31 | M5.Lcd.setTextSize(4); 32 | } 33 | 34 | void loop() 35 | { 36 | M5.Lcd.clear(BLACK); 37 | for (int i = 0; i < 6; i++) { 38 | M5.Lcd.setCursor(8 * X_OFFSET, (i * 2) * Y_OFFSET); 39 | M5.Lcd.printf("%d:%d", i + 1, porthub.hub_a_read_value(HUB_ADDR[i])); 40 | } 41 | 42 | for (int i = 0; i < 6; i++) { 43 | porthub.hub_wire_setBrightness(HUB_ADDR[i], 1); 44 | porthub.hub_wire_fill_color(HUB_ADDR[i], 0, 15, 250, 250, 250); 45 | } 46 | delay(1000); 47 | } -------------------------------------------------------------------------------- /examples/Unit/PbHUB/porthub.h: -------------------------------------------------------------------------------- 1 | #ifndef __PORTHUB_H__ 2 | #define __PORTHUB_H__ 3 | 4 | #include 5 | 6 | #define IIC_ADDR1 0x61 7 | #define IIC_ADDR2 0x62 8 | #define IIC_ADDR3 0x63 9 | #define IIC_ADDR4 0x64 10 | #define IIC_ADDR5 0x65 11 | #define IIC_ADDR6 0x66 12 | #define IIC_ADDR7 0x67 13 | #define IIC_ADDR8 0x68 14 | #define HUB1_ADDR 0x40 15 | #define HUB2_ADDR 0x50 16 | #define HUB3_ADDR 0x60 17 | #define HUB4_ADDR 0x70 18 | #define HUB5_ADDR 0x80 19 | #define HUB6_ADDR 0xA0 20 | 21 | class PortHub { 22 | public: 23 | PortHub(); 24 | PortHub(uint8_t iic_addr); 25 | void begin(); 26 | 27 | uint16_t hub_a_read_value(uint8_t reg); 28 | 29 | uint8_t hub_d_read_value_A(uint8_t reg); 30 | uint8_t hub_d_read_value_B(uint8_t reg); 31 | 32 | void hub_d_wire_value_A(uint8_t reg, uint16_t level); 33 | void hub_d_wire_value_B(uint8_t reg, uint16_t level); 34 | 35 | void hub_a_wire_value_A(uint8_t reg, uint16_t duty); 36 | void hub_a_wire_value_B(uint8_t reg, uint16_t duty); 37 | 38 | void hub_wire_length(uint8_t reg, uint16_t length); 39 | 40 | void hub_wire_index_color(uint8_t reg, uint16_t num, uint8_t r, int8_t g, 41 | uint8_t b); 42 | 43 | void hub_wire_fill_color(uint8_t reg, uint16_t first, uint16_t count, 44 | uint8_t r, int8_t g, uint8_t b); 45 | 46 | void hub_wire_setBrightness(uint8_t reg, uint8_t brightness); 47 | 48 | public: 49 | private: 50 | uint8_t _iic_addr = IIC_ADDR1; 51 | 52 | private: 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /examples/Unit/RFID_RC522/RFID_RC522.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit RFID 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #include "MFRC522_I2C.h" 16 | 17 | MFRC522 mfrc522(0x28); // Create MFRC522 instance. 创建MFRC522实例 18 | 19 | void setup() 20 | { 21 | M5.begin(); // Init M5Stack. 初始化M5Stack 22 | M5.Power.begin(); // Init power 初始化电源模块 23 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 24 | M5.Lcd.println("MFRC522 Test"); 25 | Wire.begin(); // Wire init, adding the I2C bus. Wire初始化, 加入i2c总线 26 | 27 | mfrc522.PCD_Init(); // Init MFRC522. 初始化 MFRC522 28 | M5.Lcd.println("Please put the card\n\nUID:"); 29 | } 30 | 31 | void loop() 32 | { 33 | M5.Lcd.setCursor(40, 47); 34 | if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) { // 如果没有读取到新的卡片 35 | delay(200); 36 | return; 37 | } 38 | M5.Lcd.fillRect(42, 47, 320, 20, BLACK); 39 | for (byte i = 0; i < mfrc522.uid.size; i++) { // Output the stored UID data. 将存储的UID数据输出 40 | M5.Lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 41 | M5.Lcd.print(mfrc522.uid.uidByte[i], HEX); 42 | } 43 | M5.Lcd.println(""); 44 | } -------------------------------------------------------------------------------- /examples/Unit/RGB_LED_SK6812/display_rainbow/display_rainbow.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit RGB LED 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * FastLED@^3.9.10: https://github.com/FastLED/FastLED 12 | */ 13 | 14 | #include 15 | #include "FastLED.h" 16 | 17 | #define Neopixel_PIN (21) 18 | #define NUM_LEDS (30) 19 | 20 | CRGB leds[NUM_LEDS]; 21 | uint8_t gHue = 0; 22 | static TaskHandle_t FastLEDshowTaskHandle = 0; 23 | static TaskHandle_t userTaskHandle = 0; 24 | 25 | void setup() 26 | { 27 | M5.begin(); 28 | M5.Power.begin(); 29 | 30 | M5.Lcd.clear(BLACK); 31 | M5.Lcd.setTextColor(YELLOW); 32 | M5.Lcd.setTextSize(2); 33 | M5.Lcd.setCursor(40, 0); 34 | M5.Lcd.println("Neopixel Example"); 35 | M5.Lcd.setTextColor(WHITE); 36 | M5.Lcd.setCursor(0, 25); 37 | M5.Lcd.println("Display rainbow effect"); 38 | 39 | // Neopixel initialization 40 | FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); 41 | FastLED.setBrightness(10); 42 | xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2048, NULL, 2, NULL, 1); 43 | } 44 | 45 | void loop() 46 | { 47 | } 48 | 49 | void FastLEDshowESP32() 50 | { 51 | if (userTaskHandle == 0) { 52 | userTaskHandle = xTaskGetCurrentTaskHandle(); 53 | xTaskNotifyGive(FastLEDshowTaskHandle); 54 | const TickType_t xMaxBlockTime = pdMS_TO_TICKS(200); 55 | ulTaskNotifyTake(pdTRUE, xMaxBlockTime); 56 | userTaskHandle = 0; 57 | } 58 | } 59 | 60 | void FastLEDshowTask(void *pvParameters) 61 | { 62 | for (;;) { 63 | fill_rainbow(leds, NUM_LEDS, gHue, 7); // rainbow effect 64 | FastLED.show(); // must be executed for neopixel becoming effective 65 | EVERY_N_MILLISECONDS(20) 66 | { 67 | gHue++; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/Unit/RGB_SK6812/RGB_SK6812.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit RGB 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * Adafruit_NeoPixel: https://github.com/adafruit/Adafruit_NeoPixel 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | #define PIN (26) // 定义NeoPixel的控制引脚 18 | #define NUMPIXELS (3) // 定义NeoPixel控制灯灯数量 19 | 20 | Adafruit_NeoPixel pixels = 21 | Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); // set number of LEDs, pin number, LED type. 22 | // 设置灯的数量,控制引脚编号,灯灯类型 23 | 24 | void setup() 25 | { 26 | M5.begin(); // Init M5Stack. 初始化M5Stack 27 | M5.Power.begin(); // Init power 初始化电源模块 28 | pixels.begin(); // Init the NeoPixel library. 初始化NeoPixel库 29 | M5.Lcd.println(("RGB Example")); 30 | } 31 | 32 | int i = 0, j = 1, k = 2; 33 | 34 | void loop() 35 | { 36 | pixels.setPixelColor(i++, pixels.Color(100, 0, 0)); // Bright red 37 | pixels.setPixelColor(j++, pixels.Color(0, 100, 0)); // Bright green 38 | pixels.setPixelColor(k++, pixels.Color(0, 0, 100)); // Bright blue 39 | pixels.show(); // sends the updated color to the hardware. 40 | // 将更新后的颜色发送到硬件。 41 | delay(100); 42 | if (i == 3) 43 | i = 0; 44 | else if (j == 3) 45 | j = 0; 46 | else if (k == 3) 47 | k = 0; 48 | } 49 | -------------------------------------------------------------------------------- /examples/Unit/RS485_SP485EEN/RS485_SP485EEN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit RS485 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define RX_PIN (16) 16 | #define TX_PIN (17) 17 | #define X_OFF (160) 18 | #define Y_OFF (30) 19 | 20 | int i = 0, s = 0; 21 | 22 | void setup() 23 | { 24 | M5.begin(); 25 | M5.Power.begin(); 26 | M5.Lcd.setTextSize(1); 27 | M5.Lcd.drawString("RS485 Unit test", 75, 3, 4); 28 | Serial2.begin(115200, SERIAL_8N1, RX_PIN, 29 | TX_PIN); // Set the baud rate of serial port 2 to 115200,8 data bits, 30 | // no parity bits, and 1 stop bit, and set RX to 16 and TX 31 | // to 17. 32 | // 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX为16,TX为17 33 | } 34 | 35 | void loop() 36 | { 37 | Serial2.write("Hello\n"); 38 | 39 | if (Serial2.available()) { 40 | M5.Lcd.print(char(Serial2.read())); 41 | } 42 | delay(100); 43 | } 44 | -------------------------------------------------------------------------------- /examples/Unit/RTC_BM8563/RTC_BM8563.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit RTC 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * M5Unit-RTC: https://github.com/m5stack/M5Unit-RTC 12 | */ 13 | 14 | #include "M5Stack.h" 15 | #include "Unit_RTC.h" 16 | 17 | Unit_RTC RTC; 18 | 19 | rtc_time_type RTCtime; 20 | rtc_date_type RTCdate; 21 | 22 | char str_buffer[64]; 23 | 24 | void setup() 25 | { 26 | M5.begin(); // Init M5Stack. 初始化M5Stack 27 | M5.Power.begin(); // Init power 初始化电源模块 28 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 29 | M5.Lcd.print(" RTC"); 30 | RTC.begin(); // Example Initialize the RTC clock. 初始化RTC时钟 31 | RTCtime.Hours = 14; // Set the RTC clock time. 设置RTC时钟时间 32 | RTCtime.Minutes = 40; 33 | RTCtime.Seconds = 5; 34 | 35 | RTCdate.WeekDay = 4; // Set the RTC clock date. 设置RTC时钟日期 36 | RTCdate.Month = 7; 37 | RTCdate.Date = 15; 38 | RTCdate.Year = 2021; 39 | 40 | RTC.setTime(&RTCtime); // Example Synchronize the set time to the RTC. 41 | // 将设置的时间同步至RTC 42 | RTC.setDate(&RTCdate); // Synchronize the set date to the RTC. 43 | // 将设置的日期同步至RTC 44 | } 45 | 46 | void loop() 47 | { 48 | RTC.getTime(&RTCtime); // To get the time. 获取时间 49 | RTC.getDate(&RTCdate); // Get the date. 获取日期 50 | M5.Lcd.setCursor(0, 20); 51 | M5.Lcd.printf("RTC Time Now is \n%02d:%02d:%02d\n", RTCtime.Hours, RTCtime.Minutes, RTCtime.Seconds); 52 | M5.Lcd.printf("RTC Date Now is \n%02d:%02d:%02d WeekDay:%02d\n", RTCdate.Year, RTCdate.Month, RTCdate.Date, 53 | RTCdate.WeekDay); 54 | delay(1000); 55 | M5.Lcd.fillRect(0, 20, 320, 140, BLACK); 56 | } 57 | -------------------------------------------------------------------------------- /examples/Unit/THERMAL_MLX90640/MLX90640_I2C_Driver.h: -------------------------------------------------------------------------------- 1 | /** 2 | @copyright (C) 2017 Melexis N.V. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | */ 17 | #ifndef _MLX90640_I2C_Driver_H_ 18 | #define _MLX90640_I2C_Driver_H_ 19 | 20 | #include 21 | 22 | // Define the size of the I2C buffer based on the platform the user has 23 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 24 | #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) 25 | 26 | // I2C_BUFFER_LENGTH is defined in Wire.H 27 | #define I2C_BUFFER_LENGTH BUFFER_LENGTH 28 | 29 | #elif defined(__SAMD21G18A__) 30 | 31 | // SAMD21 uses RingBuffer.h 32 | #define I2C_BUFFER_LENGTH SERIAL_BUFFER_SIZE 33 | 34 | #elif __MK20DX256__ 35 | // Teensy 36 | 37 | #elif ARDUINO_ARCH_ESP32 38 | // ESP32 based platforms 39 | 40 | #else 41 | 42 | // The catch-all default is 32 43 | #define I2C_BUFFER_LENGTH 32 44 | 45 | #endif 46 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 47 | 48 | void MLX90640_I2CInit(void); 49 | int MLX90640_I2CRead(uint8_t slaveAddr, unsigned int startAddress, 50 | unsigned int nWordsRead, uint16_t *data); 51 | int MLX90640_I2CWrite(uint8_t slaveAddr, unsigned int writeAddress, 52 | uint16_t data); 53 | void MLX90640_I2CFreqSet(int freq); 54 | #endif 55 | -------------------------------------------------------------------------------- /examples/Unit/TRACE/TRACE.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit ? 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | // #define VALUE_SPLIT 16 | 17 | uint8_t value; 18 | int SensorArray[4] = {0}; 19 | 20 | void SensorStatus(void) 21 | { 22 | Wire.beginTransmission(0x5a); // The data transfer to 0x5A begins. 开始向0x5a传输数据 23 | Wire.write(0x00); 24 | Wire.endTransmission(); // End the data transmission.结束数据传输 25 | Wire.requestFrom(0x5a, 1); // Request a byte from 0x5a. 向0x5a请求一个字节 26 | while (Wire.available()) { // If data is received. 如果数据被接收到 27 | value = Wire.read(); 28 | } 29 | M5.Lcd.print(" value = "); 30 | M5.Lcd.println(value, HEX); 31 | #ifdef VALUE_SPLIT 32 | SensorArray[3] = (value & 0x08) >> 3; 33 | SensorArray[2] = (value & 0x04) >> 2; 34 | SensorArray[1] = (value & 0x02) >> 1; 35 | SensorArray[0] = (value & 0x01) >> 0; 36 | M5.Lcd.println(" After splitting... "); 37 | M5.Lcd.print(" SensorArray[0] = "); 38 | M5.Lcd.println(SensorArray[0]); 39 | M5.Lcd.print(" SensorArray[1] = "); 40 | M5.Lcd.println(SensorArray[1]); 41 | M5.Lcd.print(" SensorArray[2] = "); 42 | M5.Lcd.println(SensorArray[2]); 43 | M5.Lcd.print(" SensorArray[3] = "); 44 | M5.Lcd.println(SensorArray[3]); 45 | #endif 46 | } 47 | 48 | void setup() 49 | { 50 | M5.begin(); 51 | M5.Power.begin(); 52 | 53 | Wire.begin(); 54 | M5.Lcd.setTextColor(YELLOW); 55 | M5.Lcd.setTextSize(2); 56 | M5.Lcd.setCursor(80, 0); 57 | M5.Lcd.println("TRACE example"); 58 | M5.Lcd.setTextColor(WHITE); 59 | } 60 | 61 | void loop() 62 | { 63 | M5.Lcd.fillRect(0, 20, 320, 180, BLACK); 64 | M5.Lcd.setCursor(100, 70); 65 | SensorStatus(); 66 | delay(100); 67 | } -------------------------------------------------------------------------------- /examples/Unit/TVOC_SGP30/TVOC_SGP30.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit TVOC/eCO2 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | * Adafruit_SGP30: https://github.com/adafruit/Adafruit_SGP30 12 | */ 13 | 14 | #include 15 | #include "Adafruit_SGP30.h" 16 | 17 | Adafruit_SGP30 sgp; 18 | long last_millis = 0; 19 | 20 | void setup() 21 | { 22 | M5.begin(true, false, true, true); 23 | M5.Lcd.setTextSize(2); 24 | M5.Lcd.setCursor(80, 0); 25 | M5.Lcd.println("TVOC TEST"); 26 | if (!sgp.begin()) { // Init the sensor. 初始化传感器 27 | M5.Lcd.println("Sensor not found"); 28 | while (1); 29 | } 30 | M5.Lcd.setCursor(0, 80); 31 | M5.Lcd.println("\nInitialization..."); 32 | } 33 | 34 | void loop() 35 | { 36 | static int i = 15; 37 | while (i > 0) { 38 | if (millis() - last_millis > 1000) { 39 | last_millis = millis(); 40 | i--; 41 | M5.Lcd.fillRect(20, 120, 60, 30, BLACK); 42 | M5.Lcd.drawNumber(i, 20, 120, 2); 43 | } 44 | } 45 | M5.Lcd.fillRect(0, 80, 90, 100, BLACK); 46 | 47 | if (!sgp.IAQmeasure()) { // Commands the sensor to take a single eCO2/VOC 48 | // measurement. 命令传感器进行一次eCO2/VOC测量 49 | Serial.println("Measurement failed"); 50 | return; 51 | } 52 | M5.Lcd.fillRect(100, 40, 220, 90, TFT_BLACK); 53 | M5.Lcd.setCursor(0, 50); 54 | M5.Lcd.printf("TVOC:%d ppb\n", sgp.TVOC); 55 | M5.Lcd.printf("eCO2:%d ppm\n", sgp.eCO2); 56 | delay(500); 57 | } 58 | -------------------------------------------------------------------------------- /examples/Unit/VIBRATOR/VIBRATOR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Vibrator 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define motor_pin 26 16 | int freq = 10000; 17 | int ledChannel = 0; 18 | int resolution = 10; 19 | void setup() 20 | { 21 | M5.begin(); // Init M5Stack. 初始化M5Stack 22 | M5.Power.begin(); // Init power 初始化电源模块 23 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 24 | M5.Lcd.setCursor(110, 10); // Set the cursor at (110, 10). 将光标设置在(110, 10)处 25 | M5.Lcd.println("Vibrator"); 26 | ledcSetup(ledChannel, freq, 27 | resolution); // Sets the frequency and number of counts corresponding 28 | // to the channel. 设置通道对应的频率和计数位数 29 | ledcAttachPin(motor_pin, 30 | ledChannel); // Binds the specified channel to the specified I/O port 31 | // for output. 将指定通道绑定到指定 IO 口上以实现输出 32 | } 33 | 34 | void loop() 35 | { 36 | ledcWrite(ledChannel, 512); // Output PWM. 输出PWM 37 | delay(1000); 38 | ledcWrite(ledChannel, 0); 39 | delay(1000); 40 | } 41 | -------------------------------------------------------------------------------- /examples/Unit/WATERING/WATERING.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Watering 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5Stack@^0.4.6: https://github.com/m5stack/M5Stack 11 | */ 12 | 13 | #include 14 | 15 | #define INPUT_PIN 36 16 | #define PUMP_PIN 26 17 | 18 | bool flag = true; 19 | int rawADC; 20 | 21 | void setup() 22 | { 23 | M5.begin(); 24 | M5.Lcd.setTextColor(GREEN); 25 | M5.Lcd.setTextSize(3); 26 | M5.Lcd.setTextDatum(TC_DATUM); 27 | M5.Lcd.drawString("Watering TEST", 160, 20, 1); 28 | M5.Lcd.drawString("ON/OFF PUMP", 160, 200, 1); 29 | pinMode(INPUT_PIN, INPUT); 30 | pinMode(PUMP_PIN, OUTPUT); 31 | pinMode(25, OUTPUT); 32 | digitalWrite(25, 0); 33 | } 34 | 35 | char info[30]; 36 | 37 | void loop() 38 | { 39 | rawADC = analogRead(INPUT_PIN); 40 | M5.lcd.fillRect(80, 100, 240, 50, BLACK); 41 | M5.Lcd.setCursor(80, 100); 42 | M5.Lcd.print("ADC: " + String(rawADC)); 43 | Serial.print("Watering ADC value: "); 44 | Serial.println(rawADC); 45 | if (M5.BtnB.wasPressed()) { 46 | digitalWrite(PUMP_PIN, flag); 47 | flag = !flag; 48 | } 49 | M5.update(); 50 | delay(100); 51 | } -------------------------------------------------------------------------------- /examples/Unit/WEIGHT_HX711/WEIGHT_HX711.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 3 | * 4 | * SPDX-License-Identifier: MIT 5 | */ 6 | /* 7 | * @Hardwares: M5Core + Unit Weight 8 | * @Platform Version: Arduino M5Stack Board Manager v2.1.3 9 | * @Dependent Library: 10 | * M5GFX@^0.2.3: https://github.com/m5stack/M5GFX 11 | * M5Unified@^0.2.2: https://github.com/m5stack/M5Unified 12 | * HX711: https://github.com/bogde/HX711 13 | */ 14 | 15 | #include 16 | #include 17 | #include "HX711.h" 18 | 19 | M5GFX display; 20 | M5Canvas canvas(&display); 21 | 22 | // HX711 related pin Settings. HX711 相关引脚设置 23 | #define LOADCELL_DOUT_PIN 36 24 | #define LOADCELL_SCK_PIN 26 25 | 26 | HX711 scale; 27 | 28 | void setup() 29 | { 30 | M5.begin(); // Init M5Stack. 初始化M5Stack 31 | M5.Power.begin(); // Init power 初始化电源模块 32 | display.begin(); 33 | canvas.setColorDepth(1); // mono color 34 | canvas.createSprite(display.width(), display.height()); 35 | canvas.setTextDatum(MC_DATUM); 36 | canvas.setPaletteColor(1, GREEN); 37 | 38 | canvas.drawString("Calibration sensor....", 160, 80); 39 | canvas.pushSprite(0, 0); 40 | scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); 41 | // The scale value is the adc value corresponding to 1g 42 | scale.set_scale(61.2f); // set scale 43 | scale.tare(); // auto set offset 44 | } 45 | 46 | void loop() 47 | { 48 | canvas.fillSprite(BLACK); 49 | canvas.setTextSize(1); 50 | canvas.drawString("Connect the Weight Unit to PortB(G26,G36)", 160, 40); 51 | canvas.drawString("Click Btn A for Calibration", 160, 80); 52 | int weight = scale.get_units(5); 53 | canvas.setTextSize(3); 54 | canvas.drawString("Weight:" + String(weight) + "g", 160, 150); 55 | M5.update(); 56 | if (M5.BtnA.wasPressed()) { 57 | scale.set_scale(61.2f); 58 | scale.tare(); 59 | canvas.drawString("Calibration!", 160, 180); 60 | } 61 | canvas.pushSprite(0, 0); 62 | } -------------------------------------------------------------------------------- /examples/Unit/Zigbee_CC2630/P2P_TEST/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef _RESOURCE_H_ 2 | #define _RESOURCE_H_ 3 | 4 | extern const unsigned char coordinator_jpeg_120x140[27537]; 5 | extern const unsigned char endDevice_jpeg_120x140[24609]; 6 | extern const unsigned char router_jpeg_120x140[26433]; 7 | extern const unsigned char EndDeviceTitle[17470]; 8 | extern const unsigned char coordinatorTitle[21823]; 9 | extern const unsigned char chatBubblesBottom[11546]; 10 | extern const unsigned char chatBubblesTop[10561]; 11 | 12 | #endif -------------------------------------------------------------------------------- /examples/Unit/Zigbee_CC2630/RSSI_TEST/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef _RESOURCE_H_ 2 | #define _RESOURCE_H_ 3 | 4 | extern const unsigned char coordinator_jpeg_120x140[27537]; 5 | extern const unsigned char endDevice_jpeg_120x140[24609]; 6 | extern const unsigned char router_jpeg_120x140[26433]; 7 | extern const unsigned char EndDeviceTitle[17470]; 8 | extern const unsigned char coordinatorTitle[21823]; 9 | extern const unsigned char chatBubblesBottom[11546]; 10 | extern const unsigned char chatBubblesTop[10561]; 11 | 12 | #endif -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For M5Stack 3 | ####################################### 4 | 5 | ####################################### 6 | # Library (KEYWORD3) 7 | ####################################### 8 | 9 | M5Stack KEYWORD3 10 | M5 KEYWORD3 11 | m5 KEYWORD3 12 | 13 | ####################################### 14 | # Datatypes (KEYWORD1) 15 | ####################################### 16 | 17 | Lcd KEYWORD1 18 | Speaker KEYWORD1 19 | BtnA KEYWORD1 20 | BtnB KEYWORD1 21 | BtnC KEYWORD1 22 | 23 | ####################################### 24 | # Methods and Functions (KEYWORD2) 25 | ####################################### 26 | 27 | begin KEYWORD2 28 | update KEYWORD2 29 | Power KEYWORD2 30 | isPressed KEYWORD2 31 | wasPressed KEYWORD2 32 | pressedFor KEYWORD2 33 | 34 | isReleased KEYWORD2 35 | wasReleased KEYWORD2 36 | releasedFor KEYWORD2 37 | wasReleasefor KEYWORD2 38 | 39 | held KEYWORD2 40 | repeat KEYWORD2 41 | timeHeld KEYWORD2 42 | 43 | getBuffer KEYWORD2 44 | setContrast KEYWORD2 45 | clear KEYWORD2 46 | update KEYWORD2 47 | fillScreen KEYWORD2 48 | persistence KEYWORD2 49 | setColor KEYWORD2 50 | drawPixel KEYWORD2 51 | getPixel KEYWORD2 52 | drawLine KEYWORD2 53 | drawFastVLine KEYWORD2 54 | drawFastHLine KEYWORD2 55 | drawRect KEYWORD2 56 | fillRect KEYWORD2 57 | drawRoundRect KEYWORD2 58 | fillRoundRect KEYWORD2 59 | drawCircle KEYWORD2 60 | fillCircle KEYWORD2 61 | drawCircleHelper KEYWORD2 62 | fillCircleHelper KEYWORD2 63 | drawTriangle KEYWORD2 64 | fillTriangle KEYWORD2 65 | drawBitmap KEYWORD2 66 | drawChar KEYWORD2 67 | print KEYWORD2 68 | cursorX KEYWORD2 69 | cursorY KEYWORD2 70 | fontSize KEYWORD2 71 | textWrap KEYWORD2 72 | fontWidth KEYWORD2 73 | fontHeight KEYWORD2 74 | setFont KEYWORD2 75 | setTextColor KEYWORD2 76 | setTextSize KEYWORD2 77 | 78 | WHITE LITERAL1 79 | BLACK LITERAL1 80 | INVERT LITERAL1 81 | GRAY LITERAL1 82 | RED LITERAL1 83 | BLUE LITERAL1 84 | GREEN LITERAL1 85 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "M5Stack", 3 | "description": "Library for M5Stack Core development kit", 4 | "keywords": "M5Stack", 5 | "authors": { 6 | "name": "M5Stack", 7 | "url": "http://www.m5stack.com" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/m5stack/m5stack.git" 12 | }, 13 | "version": "0.4.6", 14 | "frameworks": "arduino", 15 | "platforms": "espressif32", 16 | "headers": "M5Stack.h" 17 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=M5Stack 2 | version=0.4.6 3 | author=M5Stack 4 | maintainer=M5Stack 5 | sentence=Library for M5Stack Core development kit 6 | paragraph=See more on http://M5Stack.com 7 | category=Device Control 8 | url=https://github.com/m5stack/m5stack 9 | architectures=esp32 10 | includes=M5Stack.h 11 | depends=M5Family,M5Module-4Relay,Module_GRBL_13.2,M5_BMM150 -------------------------------------------------------------------------------- /src/Fonts/ASC16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/src/Fonts/ASC16 -------------------------------------------------------------------------------- /src/Fonts/Font16.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f16 96 4 | #define chr_hgt_f16 16 5 | #define baseline_f16 13 6 | #define data_size_f16 8 7 | #define firstchr_f16 32 8 | 9 | extern const unsigned char widtbl_f16[96]; 10 | extern const unsigned char* const chrtbl_f16[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font32rle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f32 96 4 | #define chr_hgt_f32 26 5 | #define baseline_f32 19 6 | #define data_size_f32 8 7 | #define firstchr_f32 32 8 | 9 | extern const unsigned char widtbl_f32[96]; 10 | extern const unsigned char* const chrtbl_f32[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font64rle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f64 96 4 | #define chr_hgt_f64 48 5 | #define baseline_f64 36 6 | #define data_size_f64 8 7 | #define firstchr_f64 32 8 | 9 | extern const unsigned char widtbl_f64[96]; 10 | extern const unsigned char* const chrtbl_f64[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font72rle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f72 96 4 | #define chr_hgt_f72 75 5 | #define baseline_f72 73 6 | #define data_size_f72 8 7 | #define firstchr_f72 32 8 | 9 | extern const unsigned char widtbl_f72[96]; 10 | extern const unsigned char* const chrtbl_f72[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/Font7srle.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define nr_chrs_f7s 96 4 | #define chr_hgt_f7s 48 5 | #define baseline_f7s 47 6 | #define data_size_f7s 8 7 | #define firstchr_f7s 32 8 | 9 | extern const unsigned char widtbl_f7s[96]; 10 | extern const unsigned char* const chrtbl_f7s[96]; 11 | -------------------------------------------------------------------------------- /src/Fonts/GFXFF/gfxfont.h: -------------------------------------------------------------------------------- 1 | // Adopted by Bodmer to support TFT_HX8357_Due library. 2 | 3 | // Font structures for newer Adafruit_GFX (1.1 and later). 4 | // Example fonts are included in 'Fonts' directory. 5 | // To use a font in your Arduino sketch, #include the corresponding .h 6 | // file and pass address of GFXfont struct to setFont(). Pass NULL to 7 | // revert to 'classic' fixed-space bitmap font. 8 | 9 | #ifndef _GFXFONT_H_ 10 | #define _GFXFONT_H_ 11 | 12 | #ifdef LOAD_GFXFF 13 | 14 | typedef struct { // Data stored PER GLYPH 15 | uint32_t bitmapOffset; // Pointer into GFXfont->bitmap 16 | uint8_t width, height; // Bitmap dimensions in pixels 17 | uint8_t xAdvance; // Distance to advance cursor (x axis) 18 | int8_t xOffset, yOffset; // Dist from cursor pos to UL corner 19 | } GFXglyph; 20 | 21 | #ifdef USE_M5_FONT_CREATOR 22 | typedef struct { 23 | uint16_t start; 24 | uint16_t end; 25 | uint16_t base; 26 | } EncodeRange; 27 | #endif 28 | 29 | typedef struct { // Data stored for FONT AS A WHOLE: 30 | uint8_t *bitmap; // Glyph bitmaps, concatenated 31 | GFXglyph *glyph; // Glyph array 32 | uint16_t first, last; // ASCII extents 33 | uint8_t yAdvance; // Newline distance (y axis) 34 | #ifdef USE_M5_FONT_CREATOR 35 | uint16_t range_num; 36 | EncodeRange *range; 37 | #endif 38 | } GFXfont; 39 | 40 | #endif // LOAD_GFXFF 41 | 42 | #endif // _GFXFONT_H_ -------------------------------------------------------------------------------- /src/Fonts/GFXFF/license.txt: -------------------------------------------------------------------------------- 1 | This TFT_eSPI library has been developed from the Adafruit_GFX library: 2 | 3 | https://github.com/adafruit/Adafruit-GFX-Library 4 | 5 | It has been modified extensively to improve rendering speed on 6 | ESP8266 processors. There follows the original library license text. 7 | 8 | 9 | Original text follows: 10 | 11 | Software License Agreement (BSD License) 12 | 13 | Copyright (c) 2012 Adafruit Industries. All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without 16 | modification, are permitted provided that the following conditions are met: 17 | 18 | - Redistributions of source code must retain the above copyright notice, 19 | this list of conditions and the following disclaimer. 20 | - Redistributions in binary form must reproduce the above copyright notice, 21 | this list of conditions and the following disclaimer in the documentation 22 | and/or other materials provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 28 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 31 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 32 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | POSSIBILITY OF SUCH DAMAGE. 35 | -------------------------------------------------------------------------------- /src/Fonts/GFXFF/print.txt: -------------------------------------------------------------------------------- 1 | #define TT1 TomThumb 2 | 3 | #define FF1 FreeMono9pt7b 4 | #define FF2 FreeMono12pt7b 5 | #define FF3 FreeMono18pt7b 6 | #define FF4 FreeMono24pt7b 7 | 8 | #define FF5 FreeMonoBold9pt7b 9 | #define FF6 FreeMonoBold12pt7b 10 | #define FF7 FreeMonoBold18pt7b 11 | #define FF8 FreeMonoBold24pt7b 12 | 13 | #define FF9 FreeMonoBoldOblique9pt7b 14 | #define FF10 FreeMonoBoldOblique12pt7b 15 | #define FF11 FreeMonoBoldOblique18pt7b 16 | #define FF12 FreeMonoBoldOblique24pt7b 17 | 18 | #define FF13 FreeMonoOblique9pt7b 19 | #define FF14 FreeMonoOblique12pt7b 20 | #define FF15 FreeMonoOblique18pt7b 21 | #define FF16 FreeMonoOblique24pt7b 22 | 23 | #define FF17 FreeSans9pt7b 24 | #define FF18 FreeSans12pt7b 25 | #define FF19 FreeSans18pt7b 26 | #define FF20 FreeSans24pt7b 27 | 28 | #define FF21 FreeSansBold9pt7b 29 | #define FF22 FreeSansBold12pt7b 30 | #define FF23 FreeSansBold18pt7b 31 | #define FF24 FreeSansBold24pt7b 32 | 33 | #define FF25 FreeSansBoldOblique9pt7b 34 | #define FF26 FreeSansBoldOblique12pt7b 35 | #define FF27 FreeSansBoldOblique18pt7b 36 | #define FF28 FreeSansBoldOblique24pt7b 37 | 38 | #define FF29 FreeSansOblique9pt7b 39 | #define FF30 FreeSansOblique12pt7b 40 | #define FF31 FreeSansOblique18pt7b 41 | #define FF32 FreeSansOblique24pt7b 42 | 43 | #define FF33 FreeSerif9pt7b 44 | #define FF34 FreeSerif12pt7b 45 | #define FF35 FreeSerif18pt7b 46 | #define FF36 FreeSerif24pt7b 47 | 48 | #define FF37 FreeSerifBold9pt7b 49 | #define FF38 FreeSerifBold12pt7b 50 | #define FF39 FreeSerifBold18pt7b 51 | #define FF40 FreeSerifBold24pt7b 52 | 53 | #define FF41 FreeSerifBoldItalic9pt7b 54 | #define FF42 FreeSerifBoldItalic12pt7b 55 | #define FF43 FreeSerifBoldItalic18pt7b 56 | #define FF44 FreeSerifBoldItalic24pt7b 57 | 58 | #define FF45 FreeSerifItalic9pt7b 59 | #define FF46 FreeSerifItalic12pt7b 60 | #define FF47 FreeSerifItalic18pt7b 61 | #define FF48 FreeSerifItalic24pt7b 62 | -------------------------------------------------------------------------------- /src/Fonts/HZK16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/src/Fonts/HZK16 -------------------------------------------------------------------------------- /src/Fonts/TrueType/Not_yet_supported.txt: -------------------------------------------------------------------------------- 1 | TO DO: Add support for converted True Type fonts in an RLE format. -------------------------------------------------------------------------------- /src/IMU.h: -------------------------------------------------------------------------------- 1 | #ifndef __IMU_H__ 2 | #define __IMU_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include "utility/MahonyAHRS.h" 8 | 9 | class IMU { 10 | public: 11 | enum ImuType { IMU_UNKNOWN = 0, IMU_SH200Q, IMU_MPU6886 }; 12 | 13 | IMU(); 14 | 15 | int Init(void); 16 | 17 | void getGres(); 18 | void getAres(); 19 | 20 | void getAccelAdc(int16_t *ax, int16_t *ay, int16_t *az); 21 | void getGyroAdc(int16_t *gx, int16_t *gy, int16_t *gz); 22 | void getTempAdc(int16_t *t); 23 | 24 | void getAccelData(float *ax, float *ay, float *az); 25 | void getGyroData(float *gx, float *gy, float *gz); 26 | void getTempData(float *t); 27 | 28 | void getAhrsData(float *pitch, float *roll, float *yaw); 29 | 30 | void setFIFOEnable(bool enable_flag); 31 | uint8_t ReadFIFO(); 32 | void ReadFIFOBuff(uint8_t *data_buf, uint16_t length); 33 | uint16_t ReadFIFOCount(); 34 | void RestFIFO(); 35 | 36 | ImuType imuType; 37 | float aRes, gRes; 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/M5Faces.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) M5Stack. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full 3 | // license information. 4 | 5 | #include "M5Faces.h" 6 | 7 | // ================ Faces Keyboard =================== 8 | #define KEYBOARD_I2C_ADDR 0x08 9 | #define KEYBOARD_INT 5 10 | #define READI2CSUBADDR 0 11 | 12 | /*----------------------------------------------------------------------* 13 | * Extentions for Facces * 14 | *----------------------------------------------------------------------*/ 15 | bool M5Faces::canControlFaces() { 16 | return M5.I2C.writeCommand(KEYBOARD_I2C_ADDR, READI2CSUBADDR); 17 | } 18 | 19 | M5Faces::M5Faces() { 20 | pinMode(KEYBOARD_INT, INPUT_PULLUP); 21 | } 22 | 23 | uint8_t M5Faces::getch(void) { 24 | uint8_t data = 0x00; 25 | 26 | if (kbhit()) { 27 | while (data == 0x00) { 28 | if (!M5.I2C.readByte(KEYBOARD_I2C_ADDR, &data)) { 29 | return 0x00; 30 | } 31 | delay(1); 32 | } 33 | return data; 34 | } 35 | return 0x00; 36 | } 37 | 38 | bool M5Faces::kbhit(void) { 39 | return (digitalRead(KEYBOARD_INT) == LOW); 40 | } 41 | -------------------------------------------------------------------------------- /src/M5Faces.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) M5Stack. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full 3 | // license information. 4 | #ifndef M5Faces_h 5 | #define M5Faces_h 6 | 7 | #include "M5Stack.h" 8 | 9 | class M5Faces { 10 | public: 11 | M5Faces(); 12 | bool canControlFaces(); 13 | uint8_t getch(void); 14 | bool kbhit(void); 15 | 16 | private: 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/gitTagVersion.h: -------------------------------------------------------------------------------- 1 | #define M5_LIB_VERSION F("0.2.3-dirty") 2 | -------------------------------------------------------------------------------- /src/utility/CommUtil.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------* 2 | * M5Stack I2C Common Library v1.0 * 3 | * * 4 | * This work is licensed under the GNU Lesser General Public * 5 | * License v2.1 * 6 | * https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html * 7 | *----------------------------------------------------------------------*/ 8 | #ifndef CommUtil_h 9 | #define CommUtil_h 10 | 11 | #include 12 | #include 13 | 14 | class CommUtil { 15 | public: 16 | CommUtil(); 17 | bool writeCommand(uint8_t address, uint8_t subAddress); 18 | bool writeByte(uint8_t address, uint8_t subAddress, uint8_t data); 19 | bool writeBytes(uint8_t address, uint8_t subAddress, uint8_t *data, 20 | uint8_t length); 21 | bool readByte(uint8_t address, uint8_t *result); 22 | bool readByte(uint8_t address, uint8_t subAddress, uint8_t *result); 23 | bool readBytes(uint8_t address, uint8_t count, uint8_t *dest); 24 | bool readBytes(uint8_t address, uint8_t subAddress, uint8_t count, 25 | uint8_t *dest); 26 | void scanID(bool *result); 27 | 28 | private: 29 | }; 30 | #endif 31 | -------------------------------------------------------------------------------- /src/utility/Config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | // Screen 5 | #define TFT_LED_PIN 32 6 | #define TFT_DC_PIN 27 7 | #define TFT_CS_PIN 14 8 | #define TFT_MOSI_PIN 23 9 | #define TFT_CLK_PIN 18 10 | #define TFT_RST_PIN 33 11 | #define TFT_MISO_PIN 19 12 | 13 | // SD card 14 | #define TFCARD_CS_PIN 4 15 | 16 | // Buttons 17 | #define BTN_A 0 18 | #define BTN_B 1 19 | #define BTN_C 2 20 | #define BUTTON_A 0 21 | #define BUTTON_B 1 22 | #define BUTTON_C 2 23 | #define BUTTON_A_PIN 39 24 | #define BUTTON_B_PIN 38 25 | #define BUTTON_C_PIN 37 26 | 27 | // BEEP PIN 28 | #define SPEAKER_PIN 25 29 | #define TONE_PIN_CHANNEL 0 30 | 31 | // LORA 32 | #define LORA_CS_PIN 5 33 | #define LORA_RST_PIN 26 34 | #define LORA_IRQ_PIN 36 35 | 36 | // UART 37 | #define USE_SERIAL Serial 38 | 39 | #endif /* SETTINGS_C */ 40 | -------------------------------------------------------------------------------- /src/utility/MahonyAHRS.h: -------------------------------------------------------------------------------- 1 | //===================================================================================================== 2 | // MahonyAHRS.h 3 | //===================================================================================================== 4 | // 5 | // Madgwick's implementation of Mayhony's AHRS algorithm. 6 | // See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms 7 | // 8 | // Date Author Notes 9 | // 29/09/2011 SOH Madgwick Initial release 10 | // 02/10/2011 SOH Madgwick Optimised for reduced CPU load 11 | // 12 | //===================================================================================================== 13 | #ifndef MahonyAHRS_h 14 | #define MahonyAHRS_h 15 | 16 | //---------------------------------------------------------------------------------------------------- 17 | // Variable declaration 18 | 19 | extern volatile float twoKp; // 2 * proportional gain (Kp) 20 | extern volatile float twoKi; // 2 * integral gain (Ki) 21 | // volatile float q0, q1, q2, q3; // quaternion of sensor frame relative to 22 | // auxiliary frame 23 | 24 | //--------------------------------------------------------------------------------------------------- 25 | // Function declarations 26 | 27 | void MahonyAHRSupdate(float gx, float gy, float gz, float ax, float ay, 28 | float az, float mx, float my, float mz); 29 | // void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, 30 | // float az); 31 | void MahonyAHRSupdateIMU(float gx, float gy, float gz, float ax, float ay, 32 | float az, float *pitch, float *roll, float *yaw); 33 | float invSqrt(float x); 34 | #endif 35 | //===================================================================================================== 36 | // End of file 37 | //===================================================================================================== 38 | -------------------------------------------------------------------------------- /src/utility/SH200Q.h: -------------------------------------------------------------------------------- 1 | #ifndef _SH200Q_H_ 2 | #define _SH200Q_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "MahonyAHRS.h" 8 | 9 | #define SH200I_ADDRESS 0x6C // 7bit i2c address 10 | #define SH200I_WHOAMI 0x30 11 | #define SH200I_ACC_CONFIG 0x0E 12 | #define SH200I_GYRO_CONFIG 0x0F 13 | #define SH200I_GYRO_DLPF 0x11 14 | #define SH200I_FIFO_CONFIG 0x12 15 | #define SH200I_ACC_RANGE 0x16 16 | #define SH200I_GYRO_RANGE 0x2B 17 | #define SH200I_OUTPUT_ACC 0x00 18 | #define SH200I_OUTPUT_GYRO 0x06 19 | #define SH200I_OUTPUT_TEMP 0x0C 20 | #define SH200I_REG_SET1 0xBA 21 | #define SH200I_REG_SET2 0xCA // ADC reset 22 | #define SH200I_ADC_RESET 0xC2 // drive reset 23 | #define SH200I_SOFT_RESET 0x7F 24 | #define SH200I_RESET 0x75 25 | 26 | //#define G (9.8) 27 | #define RtA 57.324841 28 | #define AtR 0.0174533 29 | #define Gyro_Gr 0.0010653 30 | 31 | class SH200Q { 32 | public: 33 | enum Ascale { AFS_4G = 0, AFS_8G, AFS_16G }; 34 | 35 | enum Gscale { 36 | GFS_2000DPS = 0, 37 | GFS_1000DPS, 38 | GFS_500DPS, 39 | GFS_250DPS, 40 | GFS_125DPS, 41 | }; 42 | 43 | public: 44 | SH200Q(); 45 | 46 | int Init(void); 47 | 48 | void getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az); 49 | void getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz); 50 | void getTempAdc(int16_t* t); 51 | 52 | void getAccelData(float* ax, float* ay, float* az); 53 | void getGyroData(float* gx, float* gy, float* gz); 54 | void getTempData(float* t); 55 | void getAhrsData(float* pitch, float* roll, float* yaw); 56 | 57 | void setGyroFsr(Gscale scale); 58 | void setAccelFsr(Ascale scale); 59 | 60 | public: 61 | float aRes, gRes; 62 | uint8_t imuId; 63 | Gscale Gyscale; 64 | Ascale Acscale; 65 | 66 | protected: 67 | void I2C_Read_NBytes(uint8_t driver_Addr, uint8_t start_Addr, 68 | uint8_t number_Bytes, uint8_t* read_Buffer); 69 | void I2C_Write_NBytes(uint8_t driver_Addr, uint8_t start_Addr, 70 | uint8_t number_Bytes, uint8_t* write_Buffer); 71 | void sh200i_ADCReset(void); 72 | void sh200i_Reset(void); 73 | void updateGres(); 74 | void updateAres(); 75 | }; 76 | #endif -------------------------------------------------------------------------------- /src/utility/Speaker.cpp: -------------------------------------------------------------------------------- 1 | #include "Speaker.h" 2 | 3 | SPEAKER::SPEAKER(void) { 4 | _volume = 8; 5 | _begun = false; 6 | } 7 | 8 | void SPEAKER::begin() { 9 | _begun = true; 10 | ledcSetup(TONE_PIN_CHANNEL, 0, 13); 11 | ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL); 12 | setBeep(1000, 100); 13 | } 14 | 15 | void SPEAKER::end() { 16 | mute(); 17 | ledcDetachPin(SPEAKER_PIN); 18 | _begun = false; 19 | } 20 | 21 | void SPEAKER::tone(uint16_t frequency) { 22 | if (!_begun) begin(); 23 | ledcWriteTone(TONE_PIN_CHANNEL, frequency); 24 | ledcWrite(TONE_PIN_CHANNEL, 0x400 >> _volume); 25 | } 26 | 27 | void SPEAKER::tone(uint16_t frequency, uint32_t duration) { 28 | tone(frequency); 29 | _count = millis() + duration; 30 | speaker_on = 1; 31 | } 32 | 33 | void SPEAKER::beep() { 34 | if (!_begun) begin(); 35 | tone(_beep_freq, _beep_duration); 36 | } 37 | 38 | void SPEAKER::setBeep(uint16_t frequency, uint16_t duration) { 39 | _beep_freq = frequency; 40 | _beep_duration = duration; 41 | } 42 | 43 | void SPEAKER::setVolume(uint8_t volume) { 44 | _volume = 11 - volume; 45 | } 46 | 47 | void SPEAKER::mute() { 48 | ledcWriteTone(TONE_PIN_CHANNEL, 0); 49 | digitalWrite(SPEAKER_PIN, 0); 50 | } 51 | 52 | void SPEAKER::update() { 53 | if (speaker_on) { 54 | if (millis() > _count) { 55 | speaker_on = 0; 56 | mute(); 57 | } 58 | } 59 | } 60 | 61 | void SPEAKER::write(uint8_t value) { 62 | dacWrite(SPEAKER_PIN, value); 63 | } 64 | 65 | void SPEAKER::playMusic(const uint8_t* music_data, uint16_t sample_rate) { 66 | uint32_t length = strlen((char*)music_data); 67 | uint16_t delay_interval = ((uint32_t)1000000 / sample_rate); 68 | if (_volume != 11) { 69 | for (int i = 0; i < length; i++) { 70 | dacWrite(SPEAKER_PIN, music_data[i] / _volume); 71 | delayMicroseconds(delay_interval); 72 | } 73 | 74 | for (int t = music_data[length - 1] / _volume; t >= 0; t--) { 75 | dacWrite(SPEAKER_PIN, t); 76 | delay(2); 77 | } 78 | } 79 | // ledcSetup(TONE_PIN_CHANNEL, 0, 13); 80 | ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL); 81 | } 82 | -------------------------------------------------------------------------------- /src/utility/Speaker.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPEAKER_H_ 2 | #define _SPEAKER_H_ 3 | 4 | #include "Arduino.h" 5 | #include "Config.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /* __cplusplus */ 10 | #include "esp32-hal-dac.h" 11 | #ifdef __cplusplus 12 | } 13 | #endif /* __cplusplus */ 14 | 15 | class SPEAKER { 16 | public: 17 | SPEAKER(void); 18 | 19 | void begin(); 20 | void end(); 21 | void mute(); 22 | void tone(uint16_t frequency); 23 | void tone(uint16_t frequency, uint32_t duration); 24 | void beep(); 25 | void setBeep(uint16_t frequency, uint16_t duration); 26 | void update(); 27 | 28 | void write(uint8_t value); 29 | void setVolume(uint8_t volume); 30 | void playMusic(const uint8_t *music_data, uint16_t sample_rate); 31 | 32 | private: 33 | uint32_t _count; 34 | uint8_t _volume; 35 | uint16_t _beep_duration; 36 | uint16_t _beep_freq; 37 | bool _begun; 38 | bool speaker_on; 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /src/utility/quaternionFilters.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUATERNIONFILTERS_H_ 2 | #define _QUATERNIONFILTERS_H_ 3 | 4 | #include 5 | 6 | void MadgwickQuaternionUpdate(float ax, float ay, float az, float gx, float gy, 7 | float gz, float mx, float my, float mz, 8 | float deltat); 9 | void MahonyQuaternionUpdate(float ax, float ay, float az, float gx, float gy, 10 | float gz, float mx, float my, float mz, 11 | float deltat); 12 | const float* getQ(); 13 | 14 | #endif // _QUATERNIONFILTERS_H_ 15 | -------------------------------------------------------------------------------- /tools/bin2code.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | ''' 4 | # Example: 5 | > python bin2code.py m5_logo.jpg 6 | > Out:m5_logo.jpg.c Done! 7 | ''' 8 | 9 | import sys, os 10 | 11 | in_name = sys.argv[1] 12 | out_name = in_name + '.c' 13 | file_size = os.path.getsize(in_name) 14 | 15 | with open(in_name, 'rb') as infile: 16 | with open(out_name, 'wb+') as outfile: 17 | arrary_name = 'const unsigned char ' + out_name[0:out_name.find('.')] + '[' +str(file_size)+'] = {\n' 18 | outfile.write(arrary_name.encode('utf-8')) 19 | while True: 20 | data = infile.read(20) 21 | if len(data) > 0: 22 | # outfile.write('\t'.encode('utf-8')) 23 | for i in range(0, len(data)): 24 | d = "0x%02x," % data[i] 25 | outfile.write(d.encode('utf-8')) 26 | outfile.write('\n'.encode('utf-8')) 27 | else: 28 | outfile.write('};\n'.encode('utf-8')) 29 | break 30 | 31 | print('Out:'+ out_name +' Done!') -------------------------------------------------------------------------------- /tools/m5_logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Stack/60cba67112b70d1a77000f4f8263b667869bdce0/tools/m5_logo.jpg --------------------------------------------------------------------------------