├── .clang-format ├── .github ├── ISSUE_TEMPLATE │ └── bug-report.yml ├── actions │ ├── action.yml │ └── arduino-test-compile.sh └── workflows │ ├── Arduino-Lint-Check.yml │ ├── arduino-action-compile.yml │ └── clang-format-check.yml ├── .gitignore ├── LICENSE ├── README.md ├── README_cn.md ├── examples ├── Advanced │ ├── Display │ │ ├── Display_Unicode │ │ │ ├── CUF_24px.h │ │ │ ├── Display_Unicode.ino │ │ │ └── README.md │ │ ├── HZK16 │ │ │ ├── HZK16.ino │ │ │ ├── README.md │ │ │ ├── display_ch.cpp │ │ │ ├── display_ch.h │ │ │ └── str.h │ │ └── TFT_Ellipse │ │ │ └── TFT_Ellipse.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 │ │ └── SPIFFS_Add │ │ │ └── SPIFFS_Add.ino │ ├── Time │ │ └── Time.ino │ └── WIFI │ │ ├── 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 │ ├── helloworld │ │ └── helloworld.ino │ ├── mpu6886 │ │ └── mpu6886.ino │ ├── record │ │ └── record.ino │ ├── rtc │ │ ├── rtc_date_time │ │ │ └── rtc_date_time.ino │ │ └── rtc_wakeup │ │ │ └── rtc_wakeup.ino │ ├── sleep │ │ └── sleep.ino │ ├── speak │ │ ├── data.c │ │ └── speak.ino │ ├── speak_sd │ │ └── speak_sd.ino │ ├── tfcard │ │ └── tfcard.ino │ └── vibrate │ │ └── vibrate.ino ├── FactoryTest │ └── FactoryTest │ │ ├── Core2Cover.c │ │ ├── Core2Main.c │ │ ├── FactoryTest.ino │ │ ├── Number8x7.c │ │ ├── SettingAppImage.c │ │ ├── TimerAppImage.c │ │ ├── WifiSacn.c │ │ ├── batPower.c │ │ ├── batRect.c │ │ ├── bibisig.c │ │ ├── clockImage.c │ │ ├── digNumber.c │ │ ├── digNumber_35px.c │ │ ├── fft.cpp │ │ ├── fft.h │ │ ├── image.c │ │ ├── imageMenu.c │ │ ├── initImage.c │ │ ├── line3D.cpp │ │ ├── line3D.h │ │ ├── main.cpp.old │ │ ├── platformio.ini │ │ ├── power.c │ │ ├── preview_R.c │ │ ├── rect_320_20.c │ │ ├── sdCardImage.c │ │ ├── touchFish.c │ │ └── touchImage.c ├── KIT │ └── SCALES_KIT │ │ └── SCALES_KIT.ino ├── Module │ ├── 4EncoderMotor │ │ └── 4EncoderMotor.ino │ ├── AC-SOCKET │ │ ├── AC-SOCKET.ino │ │ ├── modbus.c │ │ ├── modbus.h │ │ ├── protocol.cpp │ │ └── protocol.h │ ├── COMMU │ │ ├── CAN │ │ │ ├── commu_can_receiver │ │ │ │ ├── commu_can_receiver.ino │ │ │ │ └── m5_logo.h │ │ │ └── commu_can_transmitter │ │ │ │ ├── commu_can_transmitter.ino │ │ │ │ └── m5_logo.h │ │ ├── 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 │ ├── COMX_GPS │ │ └── COMX_GPS.ino │ ├── COMX_GSM │ │ ├── COMX_GSM.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COMX_LTE-DATA │ │ ├── COMX_LTE-DATA.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COMX_LTE │ │ ├── COMX_LTE.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COMX_NB-IoT │ │ ├── COMX_NB-IoT.ino │ │ ├── TFTTerminal.cpp │ │ └── TFTTerminal.h │ ├── COM_CAT1_SIM7680 │ │ └── COM_CAT1_SIM7680.ino │ ├── LORA868_SX1276 │ │ └── LoRa868Duplex │ │ │ ├── LoRa868Duplex.ino │ │ │ ├── M5LoRa.cpp │ │ │ └── M5LoRa.h │ ├── NB-IoT_M5311LV │ │ └── NB-IoT_M5311LV.ino │ ├── PLUS │ │ └── PLUS.ino │ ├── PM2.5_PMSA003 │ │ ├── DFRobot_SHT20.cpp │ │ ├── DFRobot_SHT20.h │ │ ├── Free_Fonts.h │ │ └── PM2.5_PMSA003.ino │ ├── SERVO │ │ └── SERVO.ino │ ├── SERVO2_PCA9685 │ │ ├── .vscode │ │ │ └── arduino.json │ │ ├── Adafruit_PWMServoDriver.cpp │ │ ├── Adafruit_PWMServoDriver.h │ │ └── SERVO2_PCA9685.ino │ ├── STEPMOTOR │ │ └── STEPMOTOR.ino │ └── USB_MAX3421E │ │ └── usb_mouse │ │ ├── M5Mouse.h │ │ └── usb_mouse.ino ├── Touch │ ├── TouchGoal │ │ ├── Goals.cpp │ │ ├── Goals.h │ │ └── TouchGoal.ino │ ├── TouchView │ │ └── TouchView.ino │ ├── circles │ │ └── circles.ino │ └── events_buttons_gestures_rotation │ │ └── events_buttons_gestures_rotation.ino ├── Unit │ ├── ACCEL_ADXL345 │ │ └── ACCEL_ADXL345.ino │ ├── ADC_ADS1100 │ │ └── ADC_ADS1100.ino │ ├── ANGLE │ │ └── ANGLE.ino │ ├── BPS_BMP280 │ │ └── BPS_BMP280.ino │ ├── BPS_QMP6988 │ │ └── BPS_QMP6988.ino │ ├── BUTTON │ │ └── BUTTON.ino │ ├── CAN │ │ ├── CAN.c │ │ ├── CAN.h │ │ ├── CAN.ino │ │ ├── CAN_config.h │ │ ├── ESP32CAN.cpp │ │ ├── ESP32CAN.h │ │ └── can_regdef.h │ ├── 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 │ ├── GPS_AT6558 │ │ └── FullExample │ │ │ └── FullExample.ino │ ├── HALL │ │ └── HALL.ino │ ├── HEART_MAX30100 │ │ ├── MAX30100_RawData │ │ │ └── MAX30100_RawData.ino │ │ └── ScreenShow │ │ │ └── ScreenShow.ino │ ├── IR │ │ └── IR.ino │ ├── ISO485 │ │ └── ISO485.ino │ ├── JOYSTICK │ │ └── JOYSTICK.ino │ ├── KEY │ │ └── KEY.ino │ ├── LASER │ │ └── LASER.ino │ ├── LCD_ST7789V2 │ │ └── LCD_ST7789V2.ino │ ├── LIGHT │ │ └── LIGHT.ino │ ├── LIMIT │ │ └── LIMIT.ino │ ├── NCIR_MLX90614 │ │ └── NCIR_MLX90614.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 │ │ │ ├── PbHUB.ino │ │ │ ├── porthub.cpp │ │ │ └── porthub.h │ ├── RFID_RC522 │ │ ├── MFRC522_I2C.cpp │ │ ├── MFRC522_I2C.h │ │ └── RFID_RC522.ino │ ├── RGB_SK6812 │ │ └── RGB_SK6812.ino │ ├── RS485_SP485EEN │ │ └── RS485_SP485EEN.ino │ ├── THERMAL_MLX90640 │ │ ├── MLX90640_API.cpp │ │ ├── MLX90640_API.h │ │ ├── MLX90640_I2C_Driver.cpp │ │ ├── MLX90640_I2C_Driver.h │ │ ├── THERMAL_MLX90640.ino │ │ └── interpolation.cpp │ ├── TOF │ │ └── TOF_VL53L0X │ │ │ └── TOF_VL53L0X.ino │ ├── TRACE │ │ └── TRACE.ino │ ├── TVOC │ │ └── TVOC.ino │ ├── ULTRA │ │ └── ULTRA.ino │ ├── VIBRATOR │ │ └── VIBRATOR.ino │ ├── VMeter_ADS1115 │ │ ├── VMeter_ADS1115.ino │ │ ├── voltmeter.cpp │ │ └── voltmeter.h │ └── WEIGHT_HX711 │ │ └── WEIGHT_HX711.ino └── games │ └── floppybird │ └── floppybird.ino ├── keywords.txt ├── library.json ├── library.properties └── src ├── AXP.cpp ├── AXP.h ├── AXP192.cpp ├── AXP192.h ├── AXP2101.cpp ├── AXP2101.h ├── Fonts ├── ASC16 ├── ASC16.h ├── CUF_24px.h ├── Custom │ ├── Orbitron_Light_24.h │ ├── Orbitron_Light_32.h │ ├── Roboto_Thin_24.h │ ├── Satisfy_24.h │ └── Yellowtail_32.h ├── EVA_10px.h ├── EVA_11px.h ├── EVA_20px.h ├── EVA_24px.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 ├── INA3221.cpp ├── INA3221.h ├── M5Core2.cpp ├── M5Core2.h ├── M5Display.cpp ├── M5Display.h ├── M5Touch.cpp ├── M5Touch.h ├── RTC.cpp ├── RTC.h ├── Speaker.cpp ├── Speaker.h └── utility ├── CommUtil.cpp ├── CommUtil.h ├── Config.h ├── ILI9341_Defines.h ├── ILI9341_Init.h ├── ILI9341_Rotation.h ├── In_eSPI.cpp ├── In_eSPI.h ├── In_eSPI_Setup.h ├── M5Button.cpp ├── M5Button.h ├── M5Timer.cpp ├── M5Timer.h ├── MPU6886.cpp ├── MPU6886.h ├── MahonyAHRS.cpp ├── MahonyAHRS.h ├── PointAndZone.cpp ├── PointAndZone.h ├── Sprite.cpp ├── Sprite.h ├── pngle.c ├── pngle.h ├── qrcode.c ├── qrcode.h ├── quaternionFilters.cpp └── quaternionFilters.h /.github/workflows/Arduino-Lint-Check.yml: -------------------------------------------------------------------------------- 1 | name: Arduino Lint 2 | on: 3 | push: 4 | pull_request: 5 | jobs: 6 | lint: 7 | name: Lint Check 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - uses: arduino/arduino-lint-action@v1 12 | with: 13 | library-manager: update 14 | compliance: strict 15 | project-type: all -------------------------------------------------------------------------------- /.github/workflows/clang-format-check.yml: -------------------------------------------------------------------------------- 1 | name: clang-format Check 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|MahonyAHRS|utility)' # 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 | ~/.DS_Store 2 | */.DS_Store 3 | examples/Basics/.DS_Store 4 | .development 5 | examples/Touch/.DS_Store 6 | *.svd 7 | debug_custom.json 8 | .vscode 9 | .vscode/* 10 | # Prerequisites 11 | *.d 12 | 13 | # Compiled Object files 14 | *.slo 15 | *.lo 16 | *.o 17 | *.obj 18 | 19 | # Precompiled Headers 20 | *.gch 21 | *.pch 22 | 23 | # Compiled Dynamic libraries 24 | *.so 25 | *.dylib 26 | *.dll 27 | 28 | # Fortran module files 29 | *.mod 30 | *.smod 31 | 32 | # Compiled Static libraries 33 | *.lai 34 | *.la 35 | *.a 36 | *.lib 37 | 38 | # Executables 39 | *.exe 40 | *.out 41 | *.app 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # M5Core2 Library 2 | 3 | [![Arduino Compile](https://github.com/m5stack/M5Core2/actions/workflows/arduino-action-compile.yml/badge.svg)](https://github.com/m5stack/M5Core2/actions/workflows/arduino-action-compile.yml) 4 | [![Arduino Lint](https://github.com/m5stack/M5Core2/actions/workflows/Arduino-Lint-Check.yml/badge.svg)](https://github.com/m5stack/M5Core2/actions/workflows/Arduino-Lint-Check.yml) 5 | [![Clang Format](https://github.com/m5stack/M5Core2/actions/workflows/clang-format-check.yml/badge.svg)](https://github.com/m5stack/M5Core2/actions/workflows/clang-format-check.yml) 6 | 7 | English | [中文](README_cn.md) 8 | 9 | M5Core2_P1 10 | 11 | **For the Detailed documentation of M5Core2, Please [Click here](https://docs.m5stack.com/en/core/core2)** 12 | 13 | **In order to buy M5Core2, Please [Click here](https://shop.m5stack.com/collections/m5-controllers/products/m5stack-core2-esp32-iot-development-kit)** 14 | 15 | ## Description 16 | 17 | **M5Core2** is the second generation core device in the M5Stack development kit series, which further enhances the functions of the original generation of cores. 18 | 19 | The MCU is an ESP32 model D0WDQ6-V3 and has dual core Xtensa® 32-bit 240Mhz LX6 processors that can be controlled separately. WiFi and Bluetooth are supported as standard and it includes an on board 16MB Flash and 8MB PSRAM, USB TYPE-C interface for charging, downloading of programs and serial communication, a 2.0-inch integrated capacitive touch screen, and a built-in vibration motor. 20 | 21 | M5Core2 also features a built-in RTC module which can provide accurate timing. The power supply is managed by an AXP192 power management chip, which can effectively control the power consumption of the base and a built-in green LED power indicator helps to notify the user of battery level. The battery capacity has been upgraded to 390mAh, which can power the core for much longer than the previous model. 22 | 23 | The M5Core2 retains the SD card slot and speakers. However, in order to ensure higher quality sound output, the I2S digital audio interface power amplifier chip is used to effectively prevent signal distortion. There are independent power and reset buttons on the left side and bottom of the base. 24 | 25 | The 3 icons on the front of the screen are capacitive buttons which are programmable. There is a small expansion board on the back of the base with a 6-axis IMU sensor and microphone. 26 | 27 | ## M5Core2 M-BUS Schematic diagram 28 | 29 | 30 | 31 | ## More Information 32 | 33 | **UIFlow Quick Start**: [Click Here](https://docs.m5stack.com/en/quick_start/core2/uiflow) 34 | 35 | **MicroPython API**: [Click Here](https://docs.m5stack.com/en/quick_start/core2/mpy) 36 | 37 | **Arduino IDE Development**: [Click Here](https://docs.m5stack.com/en/quick_start/core2/arduino) 38 | 39 | **M5Core2 Arduino API**: [Click Here](https://docs.m5stack.com/en/api/core2/axp192_core2) 40 | 41 | **PinMap**: [Click Here](https://docs.m5stack.com/en/core/core2) 42 | -------------------------------------------------------------------------------- /README_cn.md: -------------------------------------------------------------------------------- 1 | # M5Core2 Library 2 | 3 | [![Arduino Compile](https://github.com/m5stack/M5Core2/actions/workflows/arduino-action-compile.yml/badge.svg)](https://github.com/m5stack/M5Core2/actions/workflows/arduino-action-compile.yml) 4 | [![Arduino Lint](https://github.com/m5stack/M5Core2/actions/workflows/Arduino-Lint-Check.yml/badge.svg)](https://github.com/m5stack/M5Core2/actions/workflows/Arduino-Lint-Check.yml) 5 | [![Clang Format](https://github.com/m5stack/M5Core2/actions/workflows/clang-format-check.yml/badge.svg)](https://github.com/m5stack/M5Core2/actions/workflows/clang-format-check.yml) 6 | 7 | 中文 | [English](README_cn.md) 8 | 9 | M5Core2_P1 10 | 11 | * **如果查看 M5Core2 的详细介绍文档,[点击这里](https://docs.m5stack.com/zh_CN/core/core2)** 12 | 13 | * **如果想要购买 M5Core2 的话,[点击这里](https://item.taobao.com/item.htm?spm=a1z10.5-c-s.w4002-22404213529.31.5ada1d91KUL15v&id=625561056791)** 14 | 15 | ## 描述 16 | 17 | **M5Core2** 是M5Stack开发套件系列中第二代主机,在原有一代主机基础上对功能进一步加强,硬件功能更加齐全。主控ESP32型号为D0WDQ6-V3,具有两个可以单独控制的 Xtensa® 32-bit LX6 处理器,主频高达240Mhz,支持WiFi与蓝牙功能,板载16MB Flash与8MB PSRAM,可通过TYPE-C接口下载程序,强劲的配置满足复杂应用的资源开销。正面搭载一块2.0寸一体化电容式触摸屏,为用户带来更流畅的人机交互体验。机身内置震动马达,可提供触觉回馈和震动提醒功能。内建的RTC模块可提供精准计时功能。电源部分搭载AXP192电源管理芯片可有效控制机身功耗,内置绿色电源指示灯,配备390mAh电池,续航时间更持久。同时机身内配备了SD卡槽与扬声器,为了保证获得更高质量的声音效果,采用I2S数字音频接口的功放芯片,能有效防止信号失真。在机身的左侧和底部配有独立的电源按键与重启(RST)按键,屏幕正面的3个圆点属于触摸屏的一部分,可通过编写程序设置热区映射为3个虚拟按键。机身背部有一块扩展小板,板上带有6轴IMU传感器与麦克风。 18 | 19 | ## M5Core2 M-BUS示意图 20 | 21 | 22 | 23 | 24 | ## 更多信息 25 | 26 | **UIFlow 快速上手**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/core2/uiflow) 27 | 28 | **MicroPython API**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/core2/mpy) 29 | 30 | **Arduino IDE 环境搭建**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/core2/arduino) 31 | 32 | **M5Core2 Arduino API**: [点击这里](https://docs.m5stack.com/zh_CN/api/core2/axp192_core2) 33 | 34 | **引脚地图**: [点击这里](https://docs.m5stack.com/zh_CN/core/core2) 35 | -------------------------------------------------------------------------------- /examples/Advanced/Display/Display_Unicode/Display_Unicode.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: Display_Unicode. Unicode显示 10 | * Date: 2021/7/23 11 | ******************************************************************************* 12 | */ 13 | 14 | /*---PLEASE SEE THE README---- 15 | ------请在使用前看README文件----*/ 16 | #include 17 | #include "CUF_24px.h" 18 | 19 | void setup() { 20 | M5.begin(); // Init M5Stack. 初始化M5Core2 21 | M5.Lcd.setFreeFont( 22 | &unicode_24px); // Set the GFX font to use. 设置要使用的GFX字体 23 | M5.Lcd.setTextDatum(TC_DATUM); // Set text alignment to center-up 24 | // alignment. 设置文本对齐方式为居中向上对齐 25 | } 26 | 27 | void loop() { 28 | M5.Lcd.fillScreen(0); 29 | M5.Lcd.drawString("Hello world", 160, 60, 30 | 1); // Hello world is displayed in font 1 on (1600.60). 31 | M5.Lcd.drawString("你好 世界", 160, 90, 32 | 1); // 在(160,60)处以字体1显示hello world 33 | M5.Lcd.drawString("Здравствуй мир", 160, 120, 1); 34 | M5.Lcd.drawString("こんにちは せかい", 160, 150, 1); 35 | delay(3000); 36 | 37 | M5.Lcd.fillScreen( 38 | 0); // Fill the screen with black (used to clear the screen) is 39 | // equivalent to clear (). 使屏幕充满黑色(用来清屏)等同于clear() 40 | M5.Lcd.setCursor( 41 | 0, 30); // Set the text cursor 0,30 position. 设置文本光标在(0,30)处 42 | M5.Lcd.printf( 43 | "☀☁☂☃☄★☆☇☈☉☊☋☌☍☎☏☐☑☒☓☔☕☖☗☘☙☚☛☜☝☞☟☠☡☢☣☤☥☦☧☨☩☪☫☬☭☮☯☸☹☺☻☼☽☾☿♀♁♂♃♄♅♆♇♈♉" 44 | "♊♋♌♍♎♏" 45 | "♐♑♒♓♔♕♖♗♘♙♚♛♜♝♞♟♠♡♢♣♤♥♦♧♨♩♪♫♬♭♮♯♰♱♲♳♴♵♶♷♸♹♺♻♼♽♾♿⚀⚁⚂⚃⚄⚅⚆⚇⚈⚉⚊⚋⚌⚍⚎⚏⚐" 46 | "⚑⚒⚓⚔⚕⚖⚗" 47 | "⚘⚙⚚⚛⚜⚝⚞⚟A⚠⚡⚢⚣⚤⚥⚦⚧⚨⚩⚪⚫⚬⚭⚮⚯B⚰⚱⚲⚳⚴⚵⚶⚷⚸⚹⚺⚻⚼⚽⚾⚿C⛀⛁⛂⛃⛄⛅⛆⛇⛈⛉⛊⛋⛌⛍⛎⛏D⛐⛑" 48 | "⛒⛓⛔⛕⛖⛗⛘⛙⛚⛛" 49 | "⛜⛝⛞⛟E⛠⛡⛢"); 50 | delay(3000); 51 | 52 | M5.Lcd.fillScreen(0); 53 | M5.Lcd.setCursor(0, 30); 54 | M5.Lcd.printf( 55 | "⛣⛤⛥⛦⛧⛨⛩⛪⛫⛬⛭⛮⛯F⛰⛱⛲⛳⛴⛵⛶⛷⛸⛹⛺⛻⛼⛽⛾⛿✀✁✂✃✄✅✆✇✈✉✊✋✌✍✎✏✐✑✒✓✔✕✖✗✘✙✚✛✜✝✞" 56 | "✟✠✡✢✣✤✥" 57 | "✦" 58 | "✧" 59 | "✨✩✪✫✬✭✮✯✰✱✲✳✴✵✶✷✸✹✺✻✼✽✾✿❀❁❂❃❄❅❆❇❈❉❊❋❌❍❎❏❐❑❒❓❔❕❖❗❘❙❚❛❜❝❞❟❠❡❢❣❤❥❦" 60 | "❧❨❩❪❫❬❭❮❯" 61 | "❰❱❲❳❴❵❶❷❸❹❺❻❼❽❾❿➀➁➂➃➄➅➆➇➈➉➊➋➌➍➎➏➐➑➒➓➔➕➖➗➘➙➚➛➜➝➞➟A➠➡➢➣➤➥➦➧➨➩➪➫➬➭➮➯B" 62 | "➰➱➲➳➴➵" 63 | "➶➷➸➹➺➻➼➽➾➿"); 64 | delay(3000); 65 | } 66 | -------------------------------------------------------------------------------- /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/HZK16.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: Character library. 字库 10 | * Date: 2021/7/28 11 | ******************************************************************************* 12 | 13 | -----PLEASE SEE THE README---- 14 | ------请在使用前看README文件----*/ 15 | 16 | #include 17 | #include "display_ch.h" 18 | #include "str.h" 19 | 20 | DisplayCh displaych; 21 | void setup() { 22 | M5.begin(); // Init M5Stack. 初始化M5Stack 23 | displaych.loadHzk16(); // Load the Chinese character library (be sure to 24 | // load before using the Chinese character library). 25 | // 加载汉字库(务必在使用汉字库前加载) 26 | displaych.setTextColor( 27 | WHITE, 28 | BLACK); // Set the text color to white and the text background color to 29 | // black (mandatory). 30 | // 设置文字颜色为白色,文字背景颜色为黑色(必加) 31 | // Set text with red highlight color 32 | displaych.setHighlightColor( 33 | RED); // Set the text highlight color to red. 设置文字高亮颜色为红色 34 | displaych.setTextSize( 35 | 1); // Set text size to 1. 设置字号大小为1 Set text size to 1(必加) 36 | } 37 | 38 | void loop() { 39 | displaych.setCursor( 40 | 0, 0, 41 | 1); // Set the cursor at (0,0) and the size to 1(mandatory). 42 | // 将光标设置在(0,0)处,并设置字号为1(必加) 43 | displaych.writeHzk( 44 | AscStr); // Display the contents of AscStr here (which can be changed 45 | // in str.h). 在此处显示AscStr中的内容(可在str.h中更改) 46 | delay(1000); // delay 1000ms. 延迟1000ms 47 | displaych.setCursor(0, 45); 48 | displaych.writeHzk( 49 | GbkStr); // Display the contents of GbkStr here (which can be changed 50 | // in str.h). 在此处显示GbkStr中的内容(可在str.h中更改) 51 | delay(1000); 52 | // Highlight the text. 高亮显示文本 53 | displaych.highlight(true); // Turn on highlight. 开启高亮显示 54 | displaych.setCursor(0, 65); 55 | displaych.writeHzk(GbkStr); 56 | delay(1000); 57 | displaych.fillScreen( 58 | BLACK); // Fill the screen with black color, equivalent to empty the 59 | // screen. 填充屏幕颜色为黑色,等效于清空屏幕 60 | displaych.highlight(false); // Turn off highlight. 关闭高亮显示 61 | delay(500); 62 | } -------------------------------------------------------------------------------- /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/display_ch.h: -------------------------------------------------------------------------------- 1 | #ifndef __DISPLAY_CH_H_ 2 | #define __DISPLAY_CH_H_ 3 | #include 4 | #include "Fonts/HZK16.h" 5 | #include "Fonts/ASC16.h" 6 | 7 | typedef enum { DontUsedHzk16, InternalHzk16, ExternalHzk16 } Hzk16Types; 8 | 9 | class DisplayCh { 10 | public: 11 | DisplayCh(); 12 | /************************************************************************** 13 | ** 14 | ** GBK character support 15 | ** 16 | **************************************************************************/ 17 | void loadHzk16(Hzk16Types hzkTypes = InternalHzk16, 18 | const char* HZK16Path = "/HZK16", 19 | const char* ASC16Path = "/ASC16"); 20 | void disableHzk16(); 21 | 22 | void setTextColor(uint16_t c); 23 | void setTextColor(uint16_t c, uint16_t b); 24 | void setCursor(int16_t x, int16_t y); 25 | void setCursor(int16_t x, int16_t y, uint8_t font); 26 | void setTextSize(uint8_t size); 27 | void fillScreen(uint32_t color); 28 | 29 | // Highlight the text (Once set to be true, the text background will not be 30 | // transparent any more) 31 | inline void highlight(bool isHighlight) { 32 | highlighted = isHighlight; 33 | } 34 | // Set highlight color 35 | inline void setHighlightColor(uint16_t color) { 36 | highlightcolor = color; 37 | istransparent = false; 38 | } 39 | 40 | void writeHzk(char* c); 41 | 42 | private: 43 | inline void setTransparentBgColor(bool isTransparent) { 44 | istransparent = isTransparent; 45 | } 46 | inline bool isTransparentBg() { 47 | return istransparent; 48 | } 49 | bool initHzk16(boolean use, const char* HZK16Path = nullptr, 50 | const char* ASC16Path = nullptr); 51 | inline bool isHzk16Used() { 52 | return hzk16Used; 53 | } 54 | void setTextWrap(boolean wrap); 55 | void writeHzkAsc(const char c); 56 | void writeHzkGbk(const char* c); 57 | 58 | private: 59 | uint8_t hzkBufCount, hzkBuf[2]; 60 | boolean hzk16Used, istransparent, highlighted; 61 | Hzk16Types hzk16Type; // Use of HZK16 and ASC16 font. 62 | File Asc16File, Hzk16File, // Font file 63 | *pAsc16File, *pHzk16File; // Font file pointer 64 | 65 | uint8_t *pAscCharMatrix, *pGbkCharMatrix; 66 | uint16_t highlightcolor, ascCharWidth, ascCharHeigth, gbkCharWidth, 67 | gbkCharHeight; 68 | uint32_t textcolor, textbgcolor; 69 | int32_t cursor_x, cursor_y; 70 | uint8_t textfont, textsize; 71 | uint32_t _width, _height; // Display w/h as modified by current rotation 72 | boolean textwrap; // If set, 'wrap' text at right edge of display 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /examples/Advanced/Display/HZK16/str.h: -------------------------------------------------------------------------------- 1 | #ifndef _STR_H_ 2 | #define _STR_H_ 3 | 4 | char* AscStr = "ASCII: ABCDEFG1234567"; 5 | char* GbkStr = "Tao yuanming:�ɾն����� ����ˤ���"; 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /examples/Advanced/Display/TFT_Ellipse/TFT_Ellipse.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: Ellipse drawing. 椭圆绘制 10 | * Date: 2021/7/26 11 | *******************************************************************************/ 12 | 13 | #include 14 | 15 | void setup(void) { 16 | M5.begin(); // Init M5Core2. 初始化M5Core2 17 | } 18 | 19 | void loop() { 20 | // Draw some random ellipses. 绘制一些随机形状的椭圆 21 | for (int i = 0; i < 40; i++) { 22 | int rx = random(60); 23 | int ry = random(60); 24 | int x = rx + random(320 - rx - rx); 25 | int y = ry + random(240 - ry - ry); 26 | M5.Lcd.fillEllipse( 27 | x, y, rx, ry, 28 | random( 29 | 0xFFFF)); // At (x, y), draw a filled ellipse with random width 30 | // and height of rx, ry with random color random 31 | // (0xFFFF). 32 | // 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的填充椭圆 33 | } 34 | 35 | delay(2000); 36 | M5.Lcd.clear(); // 清空屏幕 37 | 38 | for (int i = 0; i < 40; i++) { 39 | int rx = random(60); 40 | int ry = random(60); 41 | int x = rx + random(320 - rx - rx); 42 | int y = ry + random(240 - ry - ry); 43 | M5.Lcd.drawEllipse( 44 | x, y, rx, ry, 45 | random( 46 | 0xFFFF)); // At (x, y), draw an elliptical wire frame with a 47 | // random width and height of rx, ry in a random 48 | // color (0xFFFF). 49 | // 在(x,y)处以随机颜色random(0xFFFF),绘制一个随机宽高为rx,ry的椭圆线框 50 | } 51 | 52 | delay(2000); 53 | } 54 | -------------------------------------------------------------------------------- /examples/Advanced/EzData/EzData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: EzData. 10 | * Date: 2021/10/23 11 | ******************************************************************************* 12 | */ 13 | #include "M5Core2.h" 14 | #include "M5_EzData.h" 15 | 16 | // Configure the name and password of the connected wifi and your token. 17 | // 配置所连接wifi的名称、密码以及你的token 18 | const char* ssid = "Explore-F"; 19 | const char* password = "xingchentansuo123"; 20 | const char* token = ""; 21 | 22 | void setup() { 23 | M5.begin(); // Initialize M5Stack 24 | if (setupWifi(ssid, password)) { // Connect to wifi. 连接到wifi 25 | M5.Lcd.printf("Success connecting to %s\n", ssid); 26 | } else { 27 | M5.Lcd.printf("Connecting to %s failed\n", ssid); 28 | } 29 | } 30 | 31 | void loop() { 32 | // Save the data 20 to the top of the testData topic queue. 保存数据20至 33 | // testData 队列首位 34 | if (setData(token, "testData", 20)) { 35 | M5.Lcd.printf("Success sending data to the topic\n"); 36 | } else { 37 | M5.Lcd.print("Fail to save data\n"); 38 | } 39 | delay(5000); 40 | 41 | // Save 3 data in sequence to the first place of testList. 依次保存3个数据至 42 | // testList首位 43 | for (int i = 0; i < 3; i++) { 44 | if (addToList(token, "testList", i)) { 45 | M5.Lcd.printf("Success sending %d to the list\n", i); 46 | } else { 47 | M5.Lcd.print("Fail to save data\n"); 48 | } 49 | delay(100); 50 | } 51 | delay(5000); 52 | 53 | // Get a piece of data from a topic and store the value in result. 从一个 54 | // topic中获取一个数据,并将值存储在 result 55 | int result = 0; 56 | if (getData(token, "testData", result)) { 57 | M5.Lcd.printf("Success get data %d\n", result); 58 | } else { 59 | M5.Lcd.print("Fail to get data\n"); 60 | } 61 | delay(5000); 62 | 63 | // Get a set of data from a list and store the values in the Array array. 64 | // 从一个 list中获取一组数据,并将值存储在 Array数组中 65 | int Array[3] = {}; 66 | if (getData(token, "testList", Array, 0, 3)) { 67 | M5.Lcd.print("Success get list\n"); 68 | for (int i = 0; i < 3; i++) { 69 | M5.Lcd.printf("Array[%d]=%d,", i, Array[i]); 70 | } 71 | M5.Lcd.println(""); 72 | } else { 73 | M5.Lcd.println("Fail to get data"); 74 | } 75 | delay(5000); 76 | 77 | // Remove data 78 | if (removeData(token, "testData")) 79 | M5.Lcd.printf("Success remove data\n"); 80 | else 81 | M5.Lcd.println("Fail to remove data"); 82 | 83 | if (removeData(token, "testList")) 84 | M5.Lcd.printf("Success remove data from the list\n"); 85 | else 86 | M5.Lcd.println("Fail to remove data"); 87 | delay(5000); 88 | M5.Lcd.fillScreen(BLACK); 89 | M5.Lcd.setCursor(0, 0); 90 | } -------------------------------------------------------------------------------- /examples/Advanced/I2C_Tester/I2C_Tester.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: I2C Scanner. I2C探测 10 | * Date: 2021/7/26 11 | ******************************************************************************* 12 | */ 13 | /* 14 | This program scans the addresses 1-127 continuosly and shows the devices found 15 | on the TFT. 该程序连续扫描地址 1-127 并显示在外部(内部)I2C发现的设备。 16 | */ 17 | #include 18 | 19 | void setup() { 20 | M5.begin(true, true, true, 21 | true); // Init M5Core2(Initialization of external I2C is also 22 | // included). 初始化M5Core2(初始化外部I2C也包含在内) 23 | // Wire.begin(21, 22); //Detect internal I2C, if this sentence is not added, 24 | // it will detect external I2C. 检测内部I2C,若不加此句为检测外部I2C 25 | M5.Lcd.setTextColor( 26 | YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 27 | M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字体大小为2 28 | M5.Lcd.println("M5Core2 I2C Tester"); // Print a string on the screen. 29 | // 在屏幕上打印字符串 30 | delay(3000); 31 | M5.Lcd.fillScreen( 32 | BLACK); // Make the screen full of black (equivalent to clear() to 33 | // clear the screen). 使屏幕充满黑色(等效clear()清屏) 34 | } 35 | 36 | int textColor = YELLOW; 37 | 38 | void loop() { 39 | int address; 40 | int error; 41 | M5.Lcd.setCursor(0, 0); 42 | M5.Lcd.println("scanning Address [HEX]"); 43 | for (address = 1; address < 127; address++) { 44 | Wire.beginTransmission( 45 | address); // Data transmission to the specified device address 46 | // starts. 开始向指定的设备地址进行传输数据 47 | error = Wire.endTransmission(); /*Stop data transmission with the slave. 48 | 停止与从机的数据传输 0: success. 成功 1: The amount of 49 | data exceeds the transmission buffer capacity limit. 50 | 数据量超过传送缓存容纳限制 return value: 2: 51 | Received NACK when sending address. 传送地址时收到 NACK 52 | 3: Received NACK when transmitting data. 传送数据时收到 53 | NACK 4: Other errors. 其它错误 */ 54 | if (error == 0) { 55 | M5.Lcd.print(address, HEX); 56 | M5.Lcd.print(" "); 57 | } else 58 | M5.Lcd.print("."); 59 | 60 | delay(10); 61 | } 62 | 63 | if (textColor == YELLOW) { 64 | textColor = CYAN; 65 | } else 66 | textColor = YELLOW; 67 | M5.Lcd.setTextColor(textColor, 68 | BLACK); // Set the foreground color of the text to 69 | // textColor and the background color to BLACK. 70 | // 设置文字的前景色为textColor背景色为BLACK 71 | } 72 | -------------------------------------------------------------------------------- /examples/Advanced/MultSerial/MultSerial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: MultSerial. 多串口 10 | * Date: 2021/8/5 11 | ****************************************************************************** 12 | */ 13 | #include 14 | 15 | void setup() { 16 | M5.begin(); // Init M5Core2. 初始化 M5Core2 17 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 18 | // txPin, bool invert) 19 | Serial2.begin(115200, SERIAL_8N1, 13, 20 | 14); // 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/MultiTask/MultiTask.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: MultiTask. 多线程 10 | * Date: 2021/7/26 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | 16 | void task1(void* pvParameters) { // Define the tasks to be executed in 17 | // thread 1. 定义线程1内要执行的任务 18 | while (1) { // Keep the thread running. 使线程一直运行 19 | Serial.print("task1 Uptime (ms): "); 20 | Serial.println(millis()); // The running time of the serial port 21 | // printing program. 串口打印程序运行的时间 22 | delay( 23 | 100); // With a delay of 100ms, it can be seen in the serial 24 | // monitor that every 100ms, thread 1 will be executed once. 25 | // 延迟100ms,在串口监视器内可看到每隔100ms,线程1就会被执行一次 26 | } 27 | } 28 | 29 | void task2(void* pvParameters) { 30 | while (1) { 31 | Serial.print("task2 Uptime (ms): "); 32 | Serial.println(millis()); 33 | delay(200); 34 | } 35 | } 36 | 37 | void task3(void* pvParameters) { 38 | while (1) { 39 | Serial.print("task3 Uptime (ms): "); 40 | Serial.println(millis()); 41 | delay(1000); 42 | } 43 | } 44 | 45 | void setup() { 46 | M5.begin(); // Init M5Core2. 初始化M5Core2 47 | // Creat Task1. 创建线程1 48 | xTaskCreatePinnedToCore( 49 | task1, // Function to implement the task. 50 | // 线程对应函数名称(不能有返回值) 51 | "task1", // 线程名称 52 | 4096, // The size of the task stack specified as the number of * 53 | // bytes.任务堆栈的大小(字节) 54 | NULL, // Pointer that will be used as the parameter for the task * 55 | // being created. 创建作为任务输入参数的指针 56 | 1, // Priority of the task. 任务的优先级 57 | NULL, // Task handler. 任务句柄 58 | 0); // Core where the task should run. 将任务挂载到指定内核 59 | 60 | // Task 2 61 | xTaskCreatePinnedToCore(task2, "task2", 4096, NULL, 2, NULL, 0); 62 | 63 | // Task 3 64 | xTaskCreatePinnedToCore(task3, "task3", 4096, NULL, 3, NULL, 0); 65 | } 66 | 67 | void loop() { 68 | } -------------------------------------------------------------------------------- /examples/Advanced/QRCode/QRCode.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: QRcode. 创建二维码 10 | * Date: 2021/7/26 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | 16 | void setup() { 17 | M5.begin(); // Init M5Core2. 初始化M5Core2 18 | M5.Lcd.qrcode( 19 | "http://www.m5stack.com", 0, 0, 150, 20 | 6); // Create a QR code with a width of 150 QR code with version 6 at 21 | // (0, 0). 在(0,0)处创建一个宽为150二维码版本为6的二维码 22 | // Please select the appropriate QR code version according to the number of 23 | // characters. 请根据字符数量选择合适的二维码版本 24 | } 25 | 26 | void loop() { 27 | } 28 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/Counter/Counter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 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 M5Core2. 初始化 M5Core2 21 | M5.Lcd.setTextSize(2); 22 | preferences.begin( 23 | "my-app", 24 | false); // We will open storage in RW-mode (second parameter has to be 25 | // false). 26 | // 在perferences中创建叫my-app的空间,并以rw模式打开存储(第二个参数必须为false) 27 | 28 | // preferences.clear(); // Remove all preferences under the opened 29 | // namespace.清除preferences中所有的空间 30 | 31 | // preferences.remove("counter"); // Or remove the counter key only. 32 | // 只清除counter中的值 33 | 34 | unsigned int counter = preferences.getUInt( 35 | "counter", 36 | 0); // Get the counter value in current sapce, if the key does not 37 | // exist, return a default value of 0. 38 | // 在当前空间中读取counter的值(若不存在为0),并赋值给counter 39 | counter++; // Increase counter by 1. 使计数器的值加一 40 | M5.Lcd.printf( 41 | "Current counter value: %u\n", 42 | counter); // Print the counter to Serial Monitor. 串口输出计数器的值 43 | preferences.putUInt( 44 | "counter", 45 | counter); // Store the counter to the Preferences. 存储计数器的值 46 | preferences.end(); // Close the Preferences. 关闭Preferences 47 | M5.Lcd.println("Restarting in 10 seconds.."); 48 | delay(10000); // delay 10. 延迟10s 49 | ESP.restart(); // Restart. 重启 50 | } 51 | void loop() { 52 | } 53 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/SPIFFS/SPIFFS_Delete/SPIFFS_Delete.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 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 M5Core2. 初始化 M5Core2 22 | M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字号大小为2 23 | if (SPIFFS.begin()) { // Start SPIFFS, return 1 on success. 24 | // 启动闪存文件系统,若成功返回1 25 | M5.Lcd.println("\nSPIFFS Started."); // Screen prints format String. 26 | // 屏幕打印格式化字符串 27 | } else { 28 | M5.Lcd.println("SPIFFS Failed to Start."); 29 | } 30 | 31 | if (SPIFFS.remove( 32 | file_name)) { // Delete file_name file from flash, return 1 on 33 | // success. 从闪存中删除file_name文件,如果成功返回1 34 | M5.Lcd.print(file_name); 35 | M5.Lcd.println(" Remove sucess"); 36 | } else { 37 | M5.Lcd.print(file_name); 38 | M5.Lcd.println(" Remove fail"); 39 | } 40 | } 41 | 42 | void loop() { 43 | } -------------------------------------------------------------------------------- /examples/Advanced/Time/Time.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: NTP TIME. 10 | * Date: 2021/8/3 11 | *******************************************************************************/ 12 | 13 | #include 14 | #include 15 | #include "time.h" 16 | 17 | // Set the name and password of the wifi to be connected. 18 | // 配置所连接wifi的名称和密码 19 | const char* ssid = "M5"; 20 | const char* password = "123456"; 21 | 22 | const char* ntpServer = 23 | "time1.aliyun.com"; // Set the connect NTP server. 设置连接的NTP服务器 24 | const long gmtOffset_sec = 0; 25 | const int daylightOffset_sec = 3600; 26 | 27 | void printLocalTime() { // Output current time. 输出当前时间 28 | struct tm timeinfo; 29 | if (!getLocalTime(&timeinfo)) { // Return 1 when the time is successfully 30 | // obtained. 成功获取到时间返回1 31 | M5.Lcd.println("Failed to obtain time"); 32 | return; 33 | } 34 | M5.Lcd.println(&timeinfo, 35 | "%A, %B %d \n%Y %H:%M:%S"); // Screen prints date and time. 36 | // 屏幕打印日期和时间 37 | } 38 | 39 | void setup() { 40 | M5.begin(); // Init M5Core2. 初始化 M5Core2 41 | M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字号大小为2 42 | M5.Lcd.printf("\nConnecting to %s", ssid); 43 | WiFi.begin(ssid, 44 | password); // Connect wifi and return connection status. 45 | // 连接wifi并返回连接状态 46 | while (WiFi.status() != 47 | WL_CONNECTED) { // If the wifi connection fails. 若wifi未连接成功 48 | delay(500); // delay 0.5s. 延迟0.5s 49 | M5.Lcd.print("."); 50 | } 51 | M5.Lcd.println("\nCONNECTED!"); 52 | configTime(gmtOffset_sec, daylightOffset_sec, 53 | ntpServer); // init and get the time. 初始化并设置NTP 54 | printLocalTime(); 55 | WiFi.disconnect(true); // Disconnect wifi. 断开wifi连接 56 | WiFi.mode(WIFI_OFF); // Set the wifi mode to off. 设置wifi模式为关闭 57 | delay(20); 58 | } 59 | 60 | void loop() { 61 | delay(1000); 62 | M5.Lcd.setCursor(0, 47); // Set the cursor at (0,0). 设置光标位于(0,0)处 63 | printLocalTime(); 64 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: BasicHTTPClient. 10 | * Date: 2021/8/4 11 | ****************************************************************************** 12 | */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | WiFiMulti wifiMulti; 20 | HTTPClient http; 21 | 22 | void setup() { 23 | M5.begin(); // Init M5Core2. 初始化 M5Core2 24 | wifiMulti.addAP("WIFINAME", 25 | "WIFIPASSWORD"); // Storage wifi configuration information. 26 | // 存储wifi配置信息 27 | M5.Lcd.print("\nConnecting Wifi...\n"); // print format output string on 28 | // lcd. 串口格式化输出字符串 29 | } 30 | 31 | void loop() { 32 | M5.Lcd.setCursor(0, 0); // Set the cursor at (0,0). 设置光标位于(0,0)处 33 | if ((wifiMulti.run() == 34 | WL_CONNECTED)) { // wait for WiFi connection. 等待连接至wifi 35 | M5.Lcd.print("[HTTP] begin...\n"); 36 | http.begin( 37 | "http://example.com/index.html"); // configure traged server and 38 | // url. 配置被跟踪的服务器和URL 39 | M5.Lcd.print("[HTTP] GET...\n"); 40 | int httpCode = http.GET(); // start connection and send HTTP header. 41 | // 开始连接服务器并发送HTTP的标头 42 | if (httpCode > 43 | 0) { // httpCode will be negative on error. 出错时httpCode将为负值 44 | M5.Lcd.printf("[HTTP] GET... code: %d\n", httpCode); 45 | 46 | if (httpCode == 47 | HTTP_CODE_OK) { // file found at server. 在服务器上找到文件 48 | String payload = http.getString(); 49 | M5.Lcd.println(payload); // 打印在服务器上读取的文件. Print 50 | // files read on the server 51 | } 52 | } else { 53 | M5.Lcd.printf("[HTTP] GET... failed, error: %s\n", 54 | http.errorToString(httpCode).c_str()); 55 | } 56 | http.end(); 57 | } else { 58 | M5.Lcd.print("connect failed"); 59 | } 60 | delay(5000); 61 | M5.Lcd.clear(); // clear the screen. 清除屏幕 62 | } 63 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/OTAUpload/OTAUpload.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: OTA Upload. 隔空传输程序 10 | * Date: 2021/7/30 11 | ******************************************************************************* 12 | PC and M5Core2 can only be used on the same wifi. 13 | 电脑和M5Core2需在同一wifi下才可使用 When the OTA is ready, restart the Arduino 14 | client from Tools > Ports > Network ports to instantly transmit the program 15 | wirelessly. OTA 准备好后重启Arduino客户端在工具->端口->网络端口,即刻无线传输程序 16 | */ 17 | #include 18 | #include 19 | #include 20 | 21 | // Set the name and password of the wifi to be connected. 22 | // 配置所连接wifi的名称和密码 23 | const char* ssid = "M5wifi"; 24 | const char* password = "21213123"; 25 | 26 | void setup() { 27 | M5.begin(); // Init M5Core2. 初始化 M5Core2 28 | WiFi.begin(ssid, 29 | password); // Connect wifi and return connection status. 30 | // 连接wifi并返回连接状态 31 | M5.lcd.print("Waiting Wifi Connect"); 32 | while (WiFi.status() != 33 | WL_CONNECTED) { // If the wifi connection fails. 若wifi未连接成功 34 | delay(1000); 35 | M5.lcd.print("."); 36 | } 37 | M5.lcd.println("\nWiFi Connected!"); 38 | M5.lcd.print("WiFi Connect To: "); 39 | M5.lcd.println(WiFi.SSID()); // Output Network name. 输出网络名称 40 | M5.lcd.print("IP address: "); 41 | M5.lcd.println(WiFi.localIP()); // Output IP Address. 输出IP地址 42 | 43 | ArduinoOTA.setHostname( 44 | "M5Core2"); // Set the network port name. 设置网络端口名称 45 | ArduinoOTA.setPassword("666666"); // Set the network port connection 46 | // password. 设置网络端口连接的密码 47 | ArduinoOTA.begin(); // Initialize the OTA. 初始化OTA 48 | M5.lcd.println("OTA ready!"); // M5.lcd port output format string. 49 | // 串口输出格式化字符串 50 | } 51 | 52 | void loop() { 53 | ArduinoOTA.handle(); // Continuously check for update requests. 54 | // 持续检测是否有更新请求 55 | M5.update(); 56 | if (M5.BtnA.isPressed()) { // if BtnA is Pressed. 如果按键A按下 57 | ArduinoOTA.end(); // Ends the ArduinoOTA service. 结束OTA服务 58 | M5.lcd.println("OTA End!"); 59 | delay(200); 60 | } 61 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiMulti/WiFiMulti.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 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 M5Core2. 初始化 M5Core2 24 | wifiMulti.addAP("wifi1", 25 | "12345566"); // Storage wifi configuration information 1. 26 | // 存储wifi配置信息1 27 | wifiMulti.addAP("wifi2", "12345566"); 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/WiFiScan/WiFiScan.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: Wifi scan. wifi扫描 10 | * Date: 2021/7/28 11 | ******************************************************************************* 12 | */ 13 | #include 14 | #include "WiFi.h" 15 | 16 | void setup() { 17 | M5.begin(); // Init M5Stack. 初始化M5Stack 18 | WiFi.mode(WIFI_STA); // Set WiFi to station mode and disconnect from an AP 19 | // if it was previously connected. 20 | // 将WiFi设置为站模式,如果之前连接过AP,则断开连接 21 | WiFi.disconnect(); // Turn off all wifi connections. 关闭所有wifi连接 22 | delay(100); // 100 ms delay. 延迟100ms 23 | M5.Lcd.print("WIFI SCAN"); // Screen print string. 屏幕打印字符串 24 | } 25 | 26 | void loop() { 27 | M5.Lcd.setCursor(0, 0); // Set the cursor at (0,0). 将光标设置在(0,0)处 28 | M5.Lcd.println("Please press Btn.A to (re)scan"); 29 | M5.update(); // Check the status of the key. 检测按键的状态 30 | if (M5.BtnA.isPressed()) { // If button A is pressed. 如果按键A按下 31 | M5.Lcd.clear(); // Clear the screen. 清空屏幕 32 | M5.Lcd.println("scan start"); 33 | int n = WiFi.scanNetworks(); // return the number of networks found. 34 | // 返回发现的网络数 35 | if (n == 0) { // If no network is found. 如果没有找到网络 36 | M5.Lcd.println("no networks found"); 37 | } else { // If have network is found. 找到网络 38 | M5.Lcd.printf("networks found:%d\n\n", n); 39 | for (int i = 0; i < n; 40 | ++i) { // Print SSID and RSSI for each network found. 41 | // 打印每个找到的网络的SSID和信号强度 42 | M5.Lcd.printf("%d:", i + 1); 43 | M5.Lcd.print(WiFi.SSID(i)); 44 | M5.Lcd.printf("(%d)", WiFi.RSSI(i)); 45 | M5.Lcd.println( 46 | (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*"); 47 | delay(10); 48 | } 49 | } 50 | delay(1000); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /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/Advanced/WIFI/WiFiSmartConfig/WiFiSmartConfig.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: WIFI Smart Config. WIFI智能配网 10 | * Date: 2021/7/30 11 | ******************************************************************************* 12 | * Fill in WIFI configuration information through mobile APP to connect M5Core2 13 | *to relevant WIFI 通过手机APP填写WIFI配置信息使 M5Core2连接至相关WIFI APP 14 | *Download Address: 15 | *https://www.espressif.com/en/products/software/esp-touch/resources APP下载地址: 16 | *https://www.espressif.com/zh-hans/products/software/esp-touch/resources 17 | */ 18 | #include 19 | #include "WiFi.h" 20 | 21 | void setup() { 22 | M5.begin(); // Init M5Core2. 初始化 M5Core2 23 | WiFi.mode(WIFI_AP_STA); // Set the wifi mode to the mode compatible with 24 | // the AP and Station, and start intelligent 25 | // network configuration 26 | WiFi.beginSmartConfig(); // 设置wifi模式为AP 与 Station 27 | // 兼容模式,并开始智能配网 28 | 29 | // Wait for the M5Core2 to receive network information from the phone 30 | // 等待M5Core2接收到来自手机的配网信息 31 | M5.Lcd.println( 32 | "\nWaiting for Phone SmartConfig."); // Screen print format string. 33 | // 屏幕打印格式化字符串 34 | while (!WiFi.smartConfigDone()) { // If the smart network is not completed. 35 | // 若智能配网没有完成 36 | delay(500); 37 | M5.Lcd.print("."); 38 | } 39 | M5.Lcd.println("\nSmartConfig received."); 40 | 41 | M5.Lcd.println("Waiting for WiFi"); 42 | while ( 43 | WiFi.status() != 44 | WL_CONNECTED) { // M5Core2 will connect automatically upon receipt of 45 | // the configuration information, and return true if 46 | // the connection is successful. 47 | // 收到配网信息后M5Core2将自动连接,若连接成功将返回true 48 | delay(500); 49 | M5.Lcd.print("."); 50 | } 51 | M5.Lcd.print("\nWiFi Connect To: "); 52 | M5.Lcd.println(WiFi.SSID()); // Output Network name. 输出网络名称 53 | M5.Lcd.print("IP address: "); 54 | M5.Lcd.println(WiFi.localIP()); // Output IP Address. 输出IP地址 55 | M5.Lcd.print("RSSI: "); 56 | M5.Lcd.println(WiFi.RSSI()); // Output signal strength. 输出信号强度 57 | } 58 | 59 | void loop() { 60 | } -------------------------------------------------------------------------------- /examples/Basics/button/button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: Button example. 按键示例 10 | * Date: 2021/7/21 11 | ******************************************************************************* 12 | */ 13 | #include 14 | /* After M5Core2 is started or reset 15 | the program in the setUp () function will be run, and this part will only be 16 | run once. 在 M5Core2 17 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 18 | void setup() { 19 | M5.begin(); // Init M5Core. 初始化 M5Core2 20 | M5.Lcd.setTextColor( 21 | YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 22 | M5.Lcd.setTextSize(2); // Set the font size. 设置字体大小为2 23 | M5.Lcd.setCursor( 24 | 65, 25 | 10); // Move the cursor position to (x, y). 移动光标位置到 (x, y)处 26 | M5.Lcd.println( 27 | "Button example"); // The screen prints the formatted string and wraps 28 | // the line. 输出格式化字符串并换行 29 | M5.Lcd.setCursor(3, 35); 30 | M5.Lcd.println("Press button B for 700ms"); 31 | M5.Lcd.println("to clear screen."); 32 | M5.Lcd.setTextColor(RED); 33 | } 34 | 35 | /* After the program in setup() runs, it runs the program in loop() 36 | The loop() function is an infinite loop in which the program runs repeatedly 37 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 38 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 39 | void loop() { 40 | M5.update(); // Read the press state of the key. 读取按键 A, B, C 的状态 41 | if (M5.BtnA.wasReleased() || M5.BtnA.pressedFor(1000, 200)) { 42 | M5.Lcd.print('A'); 43 | } else if (M5.BtnB.wasReleased() || M5.BtnB.pressedFor(1000, 200)) { 44 | M5.Lcd.print('B'); 45 | } else if (M5.BtnC.wasReleased() || M5.BtnC.pressedFor(1000, 200)) { 46 | M5.Lcd.print('C'); 47 | } else if (M5.BtnB.wasReleasefor(700)) { 48 | M5.Lcd.clear(WHITE); // Clear the screen and set white to the 49 | // background color. 清空屏幕并将白色设置为底色 50 | M5.Lcd.setCursor(0, 0); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/Basics/helloworld/helloworld.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: Hello World 10 | * Date: 2021/7/21 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | /* After M5Core2 is started or reset 16 | the program in the setUp () function will be run, and this part will only be run 17 | once. 在 M5Core2 18 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 19 | void setup() { 20 | M5.begin(); // Init M5Core2. 初始化 M5Core2 21 | /* Power chip connected to gpio21, gpio22, I2C device 22 | Set battery charging voltage and current 23 | If used battery, please call this function in your project */ 24 | M5.Lcd.print("Hello World"); // Print text on the screen (string) 25 | // 在屏幕上打印文本(字符串) 26 | } 27 | 28 | /* After the program in setup() runs, it runs the program in loop() 29 | The loop() function is an infinite loop in which the program runs repeatedly 30 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 31 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 32 | void loop() { 33 | } -------------------------------------------------------------------------------- /examples/Basics/rtc/rtc_date_time/rtc_date_time.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: RTC--实时时钟示例 10 | * Date: 2022/1/9 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | RTC_TimeTypeDef RTCtime; 16 | RTC_DateTypeDef RTCDate; 17 | 18 | char timeStrbuff[64]; 19 | 20 | void flushTime() { 21 | M5.Rtc.GetTime(&RTCtime); // Gets the time in the real-time clock. 22 | // 获取实时时钟内的时间 23 | M5.Rtc.GetDate(&RTCDate); 24 | sprintf(timeStrbuff, "%d/%02d/%02d %02d:%02d:%02d", RTCDate.Year, 25 | RTCDate.Month, RTCDate.Date, RTCtime.Hours, RTCtime.Minutes, 26 | RTCtime.Seconds); 27 | // Stores real-time time and date data 28 | // to timeStrbuff. 29 | // 将实时时间、日期数据存储至timeStrbuff 30 | M5.lcd.setCursor(10, 100); 31 | // Move the cursor position to (x,y). 移动光标位置到(x,y)处 32 | M5.Lcd.println(timeStrbuff); 33 | // Output the contents of. 输出timeStrbuff中的内容 34 | } 35 | 36 | void setupTime() { 37 | RTCtime.Hours = 16; // Set the time. 设置时间 38 | RTCtime.Minutes = 51; 39 | RTCtime.Seconds = 20; 40 | if (!M5.Rtc.SetTime(&RTCtime)) Serial.println("wrong time set!"); 41 | // and writes the set time to the real 42 | // time clock. 并将设置的时间写入实时时钟 43 | RTCDate.Year = 2022; // Set the date. 设置日期 44 | RTCDate.Month = 1; 45 | RTCDate.Date = 9; 46 | if (!M5.Rtc.SetDate(&RTCDate)) Serial.println("wrong date set!"); 47 | } 48 | /* After M5Core2 is started or reset 49 | the program in the setUp () function will be run, and this part will only be run 50 | once. 在 M5Core2 51 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 52 | void setup() { 53 | M5.begin(); // Init M5Core2. 初始化 M5Core2 54 | delay(1000); 55 | setupTime(); 56 | M5.Lcd.setTextSize(2); // Set the text size. 设置文本大小 57 | } 58 | 59 | /* After the program in setup() runs, it runs the program in loop() 60 | The loop() function is an infinite loop in which the program runs repeatedly 61 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 62 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 63 | void loop() { 64 | flushTime(); 65 | delay(1000); 66 | } -------------------------------------------------------------------------------- /examples/Basics/rtc/rtc_wakeup/rtc_wakeup.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: RTC--时间管理示例 10 | * Date: 2023/7/14 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | RTC_TimeTypeDef RTCtime; 16 | RTC_TimeTypeDef RTCtime_Now; 17 | 18 | char timeStrbuff[64]; 19 | 20 | /* After M5Core2 is started or reset 21 | the program in the setUp () function will be run, and this part will only be run 22 | once. 在 M5Core2 23 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 24 | void setup() { 25 | M5.begin(); // Init M5Core2. 初始化 M5Stack 26 | 27 | RTCtime.Hours = 12; // Set the time. 设置时间 28 | RTCtime.Minutes = 31; 29 | RTCtime.Seconds = 00; 30 | 31 | RTCtime_Now.Hours = 12; 32 | RTCtime_Now.Minutes = 30; 33 | RTCtime_Now.Seconds = 00; 34 | 35 | M5.Rtc.SetTime(&RTCtime_Now); 36 | 37 | // The screen prints the formatted string and wraps it. 38 | // 屏幕打印格式化字符串并换行 39 | M5.Lcd.println("BtnA: shutdown, use power button to turn back on"); 40 | M5.Lcd.println("BtnB: shutdown, wake up after 5 seconds"); 41 | M5.Lcd.printf("BtnC: shutdown, wake up at RTC Time %d:%d", RTCtime.Hours, 42 | RTCtime.Minutes); 43 | } 44 | 45 | /* After the program in setup() runs, it runs the program in loop() 46 | The loop() function is an infinite loop in which the program runs repeatedly 47 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 48 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 49 | void loop() { 50 | M5.update(); // Read the status of keys A, B, and C. 读取按键 A, B, C 51 | // 的状态 52 | 53 | if (M5.BtnA.wasPressed()) { // Constantly check the status of keys A, B, 54 | // and C, if A press..... 55 | // 不断检测按键A、B、C的状态,如果A按下.... 56 | M5.shutdown(); // Turn off the power. 关闭电源 57 | } else if (M5.BtnB.wasPressed()) { 58 | M5.shutdown(5); // Turn off the power and wake up again after 5 59 | // seconds. 关闭电源,5秒后再次唤醒 60 | } else if (M5.BtnC.wasPressed()) { 61 | M5.shutdown(RTCtime); 62 | // Turn off the power and wake up at the specified time. 63 | // 关闭电源,在指定时间唤醒 64 | // Note: Wakeups are only accurate to the minute. 65 | // 注意:唤醒只能精确到分钟 66 | } 67 | 68 | M5.Lcd.setCursor(0, 140); 69 | M5.Rtc.GetTime(&RTCtime_Now); // Gets the current time. 获取当前时间 70 | sprintf(timeStrbuff, 71 | "RTC Time Now is %02d:%02d:%02d", // Stores real-time time data to 72 | // timeStrbuff. 73 | // 将实时时间数据存储至timeStrbuff 74 | RTCtime_Now.Hours, RTCtime_Now.Minutes, RTCtime_Now.Seconds); 75 | M5.Lcd.println( 76 | timeStrbuff); // Screen printing output timeStrbuff. 输出timeStrbuff 77 | } 78 | -------------------------------------------------------------------------------- /examples/Basics/sleep/sleep.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: Sleep--Axp电源休眠 10 | * Date: 2022/3/12 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | /* After M5Core2 is started or reset 16 | the program in the setUp () function will be run, and this part will only be run 17 | once. 在 M5Core2 18 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 19 | void setup() { 20 | M5.begin(); // Init M5Core2. 初始化 M5Core2 21 | 22 | M5.Lcd.setTextFont(2); // Set font size to 2. 设置字体大小为2 23 | 24 | Serial.println( 25 | "Light / Deep Sleep Test."); // The serial port prints the formatted 26 | // string with a newline. 27 | // 串口输出格式化字符串并换行 28 | M5.Lcd.println( 29 | "Light / Deep Sleep Test."); // The screen prints the formatted string 30 | // and wraps it. 31 | // 屏幕打印格式化字符串并换行 32 | 33 | Serial.println("Going to light sleep for 5 seconds."); 34 | M5.Lcd.println("Going to light sleep for 5 seconds."); 35 | delay(2500); // delay 2500ms. 延迟2500ms 36 | 37 | M5.Axp.LightSleep( 38 | SLEEP_SEC(5)); // Wake up after 5 seconds of light sleep, the CPU will 39 | // reboot and the program will start from the beginning. 40 | // 轻度睡眠10秒后重新启动,程序从下一行继续执行 41 | 42 | Serial.println("Wakeup from light sleep."); 43 | M5.Lcd.println("Wakeup from light sleep."); 44 | delay(1000); 45 | 46 | Serial.println("Going to deep sleep for 5 seconds."); 47 | M5.Lcd.println("Going to deep sleep for 5 seconds."); 48 | delay(2500); 49 | 50 | M5.Axp.DeepSleep( 51 | SLEEP_SEC(5)); // Wake up after 5 seconds of deep sleep, the CPU will 52 | // reboot and the program will start from the beginning. 53 | // 深度睡眠5秒后唤醒,CPU将重新启动,程序将从头开始执行 54 | } 55 | 56 | void loop() { 57 | } 58 | -------------------------------------------------------------------------------- /examples/Basics/tfcard/tfcard.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: TF Card. TF卡 10 | * Date: 2022/3/25 11 | ******************************************************************************* 12 | In this example, we will detect the existence of a file and perform read and 13 | write operations on it 14 | 在这个示例中,我们将会检测某文件是否存在,并进行读写文件操作 15 | */ 16 | 17 | #include 18 | 19 | void setup() { 20 | M5.begin(); 21 | if (!SD.begin()) { // Initialize the SD card. 初始化SD卡 22 | M5.Lcd.println( 23 | "Card failed, or not present"); // Print a message if the SD card 24 | // initialization fails or if the 25 | // SD card does not exist 26 | // 如果SD卡初始化失败或者SD卡不存在,则打印消息 27 | while (1) 28 | ; 29 | } 30 | M5.Lcd.println("TF card initialized."); 31 | if (SD.exists("/hello.txt")) { // Check if the "/hello.txt" file 32 | // exists.查看是否存在"/hello.txt"文件 33 | M5.Lcd.println("hello.txt exists."); 34 | } else { 35 | M5.Lcd.println("hello.txt doesn't exist."); 36 | } 37 | M5.Lcd.println("Creating hello.txt"); 38 | File myFile = SD.open("/hello.txt", 39 | FILE_WRITE); // Create a new file "/hello.txt". 40 | // 创建一个新文件"/hello.txt" 41 | if (myFile) { // If the file is open, then write to it. 42 | // 如果文件打开,则进行写入操作 43 | M5.Lcd.println("Writing to test.txt..."); 44 | myFile.println("SD test."); 45 | myFile.close(); // Close the file. 关闭文件 46 | M5.Lcd.println("done."); 47 | } else { 48 | M5.Lcd.println("error opening test.txt"); 49 | } 50 | delay(500); 51 | myFile = SD.open("/hello.txt", 52 | FILE_READ); // Open the file "/hello.txt" in read mode. 53 | // 以读取模式打开文件"/hello.txt" 54 | if (myFile) { 55 | M5.Lcd.println("/hello.txt Content:"); 56 | // Read the data from the file and print it until the reading is 57 | // complete. 从文件里读取数据并打印到串口,直到读取完成. 58 | while (myFile.available()) { 59 | M5.Lcd.write(myFile.read()); 60 | } 61 | myFile.close(); 62 | } else { 63 | M5.Lcd.println("error opening /hello.txt"); // If the file is not open. 64 | // 如果文件没有打开 65 | } 66 | } 67 | 68 | void loop() { 69 | } -------------------------------------------------------------------------------- /examples/Basics/vibrate/vibrate.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2023 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2 8 | * 9 | * Describe: vibrate example. 震动电机示例 10 | * Date: 2023/11/17 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | /* After M5Core2 is started or reset 16 | the program in the setUp () function will be run, and this part will only be 17 | run once. 在 M5Core2 18 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 19 | void setup() { 20 | M5.begin(); // Init M5Core2. 初始化 M5Core2 21 | } 22 | 23 | /* After the program in setup() runs, it runs the program in loop() 24 | The loop() function is an infinite loop in which the program runs repeatedly 25 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 26 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 27 | void loop() { 28 | M5.Axp.SetVibration(true); // Open the vibration. 开启震动马达 29 | delay(1000); 30 | M5.Axp.SetVibration(false); // Open the vibration. 关闭震动马达 31 | delay(1000); 32 | } 33 | -------------------------------------------------------------------------------- /examples/FactoryTest/FactoryTest/line3D.cpp: -------------------------------------------------------------------------------- 1 | #include "line3D.h" 2 | 3 | line3D::line3D(/* args */) { 4 | } 5 | 6 | line3D::~line3D() { 7 | } 8 | 9 | bool line3D::point3Dto2D(point_3d_t *source, point_2d_t *point) { 10 | point->x = (source->x * cos_gamma) - (source->y * sin_gamma); 11 | point->y = -(source->x * sin_gamma * sin_alpha) - 12 | (source->y * cos_gamma * sin_alpha) + (source->z * cos_alpha); 13 | return true; 14 | } 15 | 16 | bool line3D::point2DToDisPoint(point_2d_t *point, uint8_t *x, uint8_t *y) { 17 | *x = point->x + _zeroXoffset; 18 | *y = _zeroYOffset - point->y; 19 | return true; 20 | } 21 | 22 | bool line3D::printLine3D(TFT_eSprite *display, line_3d_t *line, 23 | uint32_t color) { 24 | uint8_t start_x, start_y, end_x, end_y; 25 | point_2d_t point; 26 | point3Dto2D(&line->start_point, &point); 27 | point2DToDisPoint(&point, &start_x, &start_y); 28 | point3Dto2D(&line->end_point, &point); 29 | point2DToDisPoint(&point, &end_x, &end_y); 30 | 31 | display->drawLine(start_x, start_y, end_x, end_y, color); 32 | 33 | return true; 34 | } 35 | 36 | void line3D::RotatePoint(point_3d_t *point, double x, double y, double z) { 37 | if (x != 0) { 38 | point->y = point->y * cos(x * r_rand) - point->z * sin(x * r_rand); 39 | point->z = point->y * sin(x * r_rand) + point->z * cos(x * r_rand); 40 | } 41 | 42 | if (y != 0) { 43 | point->x = point->z * sin(y * r_rand) + point->x * cos(y * r_rand); 44 | point->z = point->z * cos(y * r_rand) - point->x * sin(y * r_rand); 45 | } 46 | 47 | if (z != 0) { 48 | point->x = point->x * cos(z * r_rand) - point->y * sin(z * r_rand); 49 | point->y = point->x * sin(z * r_rand) + point->y * cos(z * r_rand); 50 | } 51 | } 52 | 53 | void line3D::RotatePoint(point_3d_t *point, point_3d_t *point_new, double x, 54 | double y, double z) { 55 | if (x != 0) { 56 | point_new->y = point->y * cos(x * r_rand) - point->z * sin(x * r_rand); 57 | point_new->z = point->y * sin(x * r_rand) + point->z * cos(x * r_rand); 58 | } 59 | 60 | if (y != 0) { 61 | point_new->x = point->z * sin(y * r_rand) + point->x * cos(y * r_rand); 62 | point_new->z = point->z * cos(y * r_rand) - point->x * sin(y * r_rand); 63 | } 64 | 65 | if (z != 0) { 66 | point_new->x = point->x * cos(z * r_rand) - point->y * sin(z * r_rand); 67 | point_new->y = point->x * sin(z * r_rand) + point->y * cos(z * r_rand); 68 | } 69 | } -------------------------------------------------------------------------------- /examples/FactoryTest/FactoryTest/line3D.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINE3D_H__ 2 | #define __LINE3D_H__ 3 | 4 | #include 5 | #include "utility/Sprite.h" 6 | 7 | typedef struct { 8 | double x; 9 | double y; 10 | double z; 11 | } point_3d_t; 12 | 13 | typedef struct { 14 | point_3d_t start_point; 15 | point_3d_t end_point; 16 | } line_3d_t; 17 | 18 | typedef struct { 19 | double x; 20 | double y; 21 | } point_2d_t; 22 | 23 | class line3D { 24 | private: 25 | double r_rand = PI / 180; 26 | 27 | double r_alpha = 19.47 * PI / 180; 28 | double r_gamma = 20.7 * PI / 180; 29 | 30 | double sin_alpha = sin(19.47 * PI / 180); 31 | double cos_alpha = cos(19.47 * PI / 180); 32 | double sin_gamma = sin(20.7 * PI / 180); 33 | double cos_gamma = cos(20.7 * PI / 180); 34 | 35 | int _zeroXoffset = 0; 36 | int _zeroYOffset = 0; 37 | 38 | public: 39 | line3D(/* args */); 40 | ~line3D(); 41 | 42 | void setZeroOffset(int offsetX, int offsetY) { 43 | _zeroXoffset = offsetX; 44 | _zeroYOffset = offsetY; 45 | } 46 | bool point3Dto2D(point_3d_t *source, point_2d_t *point); 47 | bool point2DToDisPoint(point_2d_t *point, uint8_t *x, uint8_t *y); 48 | bool printLine3D(TFT_eSprite *display, line_3d_t *line, uint32_t color); 49 | void RotatePoint(point_3d_t *point, double x, double y, double z); 50 | void RotatePoint(point_3d_t *point, point_3d_t *point_new, double x, 51 | double y, double z); 52 | }; 53 | 54 | #endif -------------------------------------------------------------------------------- /examples/FactoryTest/FactoryTest/main.cpp.old: -------------------------------------------------------------------------------- 1 | #include "M5Core2.h" 2 | #include "FastLED.h" 3 | #include 4 | 5 | #define LEDS_PIN 25 6 | #define LEDS_NUM 10 7 | CRGB ledsBuff[LEDS_NUM]; 8 | 9 | ECCX08Class myECCX08(Wire1, 0x35); 10 | //ECCX08 Serial Number = 0123AB2500FF230C01 11 | //ECCX08 Serial Number = 012358FF897FCDDB01 12 | 13 | void setup() 14 | { 15 | M5.begin(); 16 | // put your setup code here, to run once: 17 | FastLED.addLeds(ledsBuff, LEDS_NUM); 18 | for (int i = 0; i < LEDS_NUM; i++) 19 | { 20 | ledsBuff[i].setRGB(100, 0, 0); 21 | } 22 | FastLED.show(); 23 | 24 | Wire1.begin(21, 22, 100000UL); 25 | for (int i = 0; i < 128; i++) 26 | { 27 | Wire1.beginTransmission(i); 28 | if (Wire1.endTransmission() == ESP_OK) 29 | { 30 | Serial.printf("Device %02x \r\n", i); 31 | } 32 | } 33 | 34 | if (!myECCX08.begin()) 35 | { 36 | Serial.println("No ECCX08 present!"); 37 | while (1) 38 | ; 39 | } 40 | 41 | String serialNumber = myECCX08.serialNumber(); 42 | 43 | Serial.print("ECCX08 Serial Number = "); 44 | Serial.println(serialNumber); 45 | Serial.println(); 46 | 47 | 48 | } 49 | 50 | void loop() 51 | { 52 | // put your main code here, to run repeatedly: 53 | FastLED.show(); 54 | delay(100); 55 | M5.update(); 56 | } 57 | -------------------------------------------------------------------------------- /examples/FactoryTest/FactoryTest/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter 4 | ; Upload options: custom upload port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; Advanced options: extra scripting 7 | ; 8 | ; Please visit documentation for the other options and examples 9 | ; https://docs.platformio.org/page/projectconf.html 10 | 11 | [platformio] 12 | src_dir = . 13 | 14 | [common_env_data] 15 | framework = arduino 16 | upload_speed = 1500000 17 | monitor_speed = 115200 18 | lib_deps = 19 | https://github.com/m5stack/M5Core2 20 | fastled/FastLED @ ^3.4.0 21 | arduino-libraries/ArduinoECCX08 @ ^1.3.6 22 | arduino-libraries/ArduinoBearSSL @ ^1.5.0 23 | 24 | build_flags = 25 | -DBOARD_HAS_PSRAM 26 | 27 | [env:esp32dev] 28 | platform = espressif32 29 | board = esp32dev 30 | framework = ${common_env_data.framework} 31 | upload_speed = ${common_env_data.upload_speed} 32 | monitor_speed = ${common_env_data.monitor_speed} 33 | lib_deps = ${common_env_data.lib_deps} 34 | build_flags = ${common_env_data.build_flags} 35 | 36 | board_build.partitions = min_spiffs.csv 37 | -------------------------------------------------------------------------------- /examples/Module/AC-SOCKET/AC-SOCKET.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/products 8 | * 9 | * Product: AC Socket. 10 | * Date: 2021/9/1 11 | ******************************************************************************* 12 | Click button B to turn on the power. Click button A to turn off the power. 13 | 单击按钮 B 打开电源。 单击按钮 A 关闭电源。 14 | */ 15 | #include 16 | #include 17 | #include "protocol.h" 18 | #include "modbus.h" 19 | volatile uint32_t tim = 0; 20 | 21 | uint32_t time_now = 0; 22 | uint8_t ucTestFlag = 0; 23 | bool ubCoilState = false; 24 | 25 | void setup() { 26 | M5.begin(true, false, true, false, kMBusModeOutput); 27 | mb_init(0xac, 9600, &tim); 28 | Serial1.begin(9600, SERIAL_8N1, 13, 14); 29 | time_now = millis(); 30 | // put your setup code here, to run once: 31 | } 32 | 33 | void loop() { 34 | M5.update(); 35 | 36 | if (millis() - time_now > 60000UL) { 37 | time_now = millis(); 38 | if (ucTestFlag) { 39 | if (ubCoilState) { 40 | char data_str[] = {0xAA, 5, 0x00, 0x00, 0x00, 0x00}; 41 | mb_send_frame((uint8_t *)data_str, 6); 42 | } else { 43 | char data_str[] = {0xAA, 5, 0x00, 0x00, 0xff, 0x00}; 44 | mb_send_frame((uint8_t *)data_str, 6); 45 | } 46 | ubCoilState = 1 - ubCoilState; 47 | } 48 | } 49 | 50 | if (M5.BtnA.wasPressed()) { 51 | char data_str[] = {0xAA, 5, 0x00, 0x00, 0x00, 0x00}; 52 | mb_send_frame((uint8_t *)data_str, 6); 53 | } 54 | 55 | if (M5.BtnB.wasPressed()) { 56 | char data_str[] = {0xAA, 5, 0x00, 0x00, 0xff, 0x00}; 57 | mb_send_frame((uint8_t *)data_str, 6); 58 | } 59 | 60 | if (M5.BtnC.wasPressed()) { 61 | ucTestFlag = 1 - ucTestFlag; 62 | } 63 | 64 | vTaskDelay(pdMS_TO_TICKS(10)); 65 | 66 | // while(Serial1.available()) { 67 | // protocol_rec_put(Serial1.read()); 68 | // micros(); 69 | // } 70 | // put your main code here, to run repeatedly: 71 | } 72 | 73 | void mb_send_one_byte(uint8_t data) { 74 | Serial1.write(data); 75 | } 76 | 77 | void protocol_callback(CmdData cmd) { 78 | Serial.printf("got ... \r\n"); 79 | } 80 | -------------------------------------------------------------------------------- /examples/Module/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/Module/COMMU/CAN/commu_can_transmitter/commu_can_transmitter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | please add MCP_CAN_LIB to your library first........ 3 | MCP_CAN_LIB file in M5stack lib examples -> modules -> COMMU -> 4 | MCP_CAN_lib.rar 5 | */ 6 | 7 | #include 8 | #include 9 | #include "m5_logo.h" 10 | 11 | /** 12 | * variable for loop 13 | */ 14 | 15 | byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}; 16 | 17 | /** 18 | * variable for CAN 19 | */ 20 | long unsigned int rxId; 21 | unsigned char len = 0; 22 | unsigned char rxBuf[8]; 23 | char msgString[128]; 24 | 25 | #define CAN0_INT 2 // Set INT to pin 2 26 | MCP_CAN CAN0(27); // Set CS to pin 27 27 | 28 | void init_can(); 29 | void test_can(); 30 | 31 | void setup() { 32 | M5.begin(true, true, false, true, kMBusModeOutput); 33 | // kMBusModeOutput,powered by USB or Battery 34 | // kMBusModeInput,powered by outside input 35 | 36 | Serial.begin(9600); 37 | Serial2.begin(9600, SERIAL_8N1, 13, 14); 38 | // The 13(RX), 14(TX) pins of the CORE2 correspond to the 16(RX), 17(TX) 39 | // pins of the COMX 40 | // Please make sure that the dialing switch of COMX is set to 16(RX), 41 | // 17(TX). 42 | 43 | M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5); 44 | delay(500); 45 | M5.Lcd.setTextColor(BLACK); 46 | // M5.Lcd.setTextSize(1); 47 | 48 | init_can(); 49 | Serial.println("Test CAN..."); 50 | } 51 | 52 | void loop() { 53 | if (M5.BtnA.wasPressed()) { 54 | M5.Lcd.clear(); 55 | M5.Lcd.printf("CAN Test B!\n"); 56 | M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5); 57 | init_can(); 58 | } 59 | test_can(); 60 | M5.update(); 61 | } 62 | 63 | void init_can() { 64 | M5.Lcd.setTextSize(1); 65 | M5.Lcd.setCursor(0, 10); 66 | M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5); 67 | M5.Lcd.printf("CAN Test B!\n"); 68 | 69 | // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the 70 | // masks and filters disabled. 71 | if (CAN0.begin(MCP_ANY, CAN_1000KBPS, MCP_8MHZ) == CAN_OK) 72 | Serial.println("MCP2515 Initialized Successfully!"); 73 | else 74 | Serial.println("Error Initializing MCP2515..."); 75 | 76 | CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be 77 | // transmitted 78 | } 79 | 80 | void test_can() { 81 | // send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' 82 | // = array of data bytes to send 83 | byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data); 84 | if (sndStat == CAN_OK) { 85 | Serial.println("Message Sent Successfully!"); 86 | M5.Lcd.printf("Message Sent Successfully!\n"); 87 | } else { 88 | Serial.println("Error Sending Message..."); 89 | M5.Lcd.printf("Error Sending Message...\n"); 90 | } 91 | delay(200); // send data per 200ms 92 | } 93 | -------------------------------------------------------------------------------- /examples/Module/COMX_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/Module/COMX_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/Module/COMX_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/Module/COMX_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/Module/LORA868_SX1276/LoRa868Duplex/M5LoRa.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Sandeep Mistry. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full 3 | // license information. 4 | 5 | // 23FEB18 gojimmypi reversed LORA_DEFAULT_RESET_PIN and LORA_DEFAULT_DIO0_PIN 6 | // pin numbers reset on pin 36; irq on pin 26 7 | 8 | #ifndef M5LORA_H 9 | #define M5LORA_H 10 | 11 | #include 12 | #include 13 | 14 | #define LORA_DEFAULT_SS_PIN 33 15 | #define LORA_DEFAULT_RESET_PIN 36 16 | #define LORA_DEFAULT_DIO0_PIN 26 17 | 18 | #define PA_OUTPUT_RFO_PIN 0 19 | #define PA_OUTPUT_PA_BOOST_PIN 1 20 | 21 | class LoRaClass : public Stream { 22 | public: 23 | LoRaClass(); 24 | 25 | int begin(long frequency); 26 | void end(); 27 | 28 | int beginPacket(int implicitHeader = false); 29 | int endPacket(); 30 | 31 | int parsePacket(int size = 0); 32 | int packetRssi(); 33 | float packetSnr(); 34 | 35 | // from Print 36 | virtual size_t write(uint8_t byte); 37 | virtual size_t write(const uint8_t* buffer, size_t size); 38 | 39 | // from Stream 40 | virtual int available(); 41 | virtual int read(); 42 | virtual int peek(); 43 | virtual void flush(); 44 | 45 | void onReceive(void (*callback)(int)); 46 | 47 | void receive(int size = 0); 48 | void idle(); 49 | void sleep(); 50 | 51 | void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN); 52 | void setFrequency(long frequency); 53 | void setSpreadingFactor(int sf); 54 | void setSignalBandwidth(long sbw); 55 | void setCodingRate4(int denominator); 56 | void setPreambleLength(long length); 57 | void setSyncWord(int sw); 58 | void enableCrc(); 59 | void disableCrc(); 60 | 61 | // deprecated 62 | void crc() { 63 | enableCrc(); 64 | } 65 | void noCrc() { 66 | disableCrc(); 67 | } 68 | 69 | byte random(); 70 | 71 | void setPins(int ss = LORA_DEFAULT_SS_PIN, 72 | int reset = LORA_DEFAULT_RESET_PIN, 73 | int dio0 = LORA_DEFAULT_DIO0_PIN); 74 | void setSPIFrequency(uint32_t frequency); 75 | 76 | void dumpRegisters(Stream& out); 77 | 78 | private: 79 | void explicitHeaderMode(); 80 | void implicitHeaderMode(); 81 | 82 | void handleDio0Rise(); 83 | 84 | uint8_t readRegister(uint8_t address); 85 | void writeRegister(uint8_t address, uint8_t value); 86 | uint8_t singleTransfer(uint8_t address, uint8_t value); 87 | 88 | static void onDio0Rise(); 89 | 90 | private: 91 | SPISettings _spiSettings; 92 | int _ss; 93 | int _reset; 94 | int _dio0; 95 | int _frequency; 96 | int _packetIndex; 97 | int _implicitHeaderMode; 98 | void (*_onReceive)(int); 99 | }; 100 | 101 | extern LoRaClass LoRa; 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /examples/Module/PLUS/PLUS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/module/plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/module/plus 8 | * 9 | * Product: PLUS. 10 | * Date: 2021/9/2 11 | ******************************************************************************* 12 | This exmpale can display the encoder gear reading of the PLUS Module and the 13 | state of the keys. 本例可以显示PLUS模块的编码器齿轮读数和按键状态。 14 | */ 15 | #include 16 | #include 17 | 18 | #define IrPin \ 19 | 33 //-------------------------------------------------------------------- 20 | #define PLUS_ADDR 0x62 21 | 22 | int32_t number = 0; 23 | uint8_t press = 0; 24 | 25 | void setup() { 26 | M5.begin(true, true, true, false, kMBusModeOutput); 27 | /* kMBusModeOutput,powered by USB or Battery 28 | kMBusModeInput,powered by outside input need to fill in this Otherwise 29 | M5Core2 will not work properly 30 | 由外部供电时此项必填,否则M5Core2将无法正常工作 */ 31 | 32 | M5.Lcd.setTextFont(6); 33 | M5.Lcd.clear(BLACK); 34 | M5.Lcd.setTextColor(ORANGE, BLACK); 35 | Wire1.begin(21, 22); 36 | ledcSetup(1, 38000, 10); 37 | ledcAttachPin(IrPin, 1); 38 | } 39 | 40 | void plus_encode() { 41 | Wire1.requestFrom(PLUS_ADDR, 2); 42 | while (Wire1.available()) { 43 | int8_t encode = Wire1.read(); 44 | uint8_t press_n = Wire1.read(); 45 | number += encode; 46 | if (press_n == 0xff) { 47 | press = 0; 48 | } else { 49 | press = 1; 50 | } 51 | } 52 | } 53 | 54 | void loop() { 55 | char data[20]; 56 | 57 | plus_encode(); 58 | ledcWrite(1, ledcRead(1) ? 0 : 512); 59 | sprintf(data, "%d %d ", number, press); 60 | M5.Lcd.setCursor(100, 100); 61 | M5.Lcd.print(data); 62 | vTaskDelay(200); 63 | } 64 | -------------------------------------------------------------------------------- /examples/Module/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/Module/SERVO/SERVO.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/module/servo 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/module/servo 8 | * 9 | * Product: SERVO. 10 | * Date: 2021/9/2 11 | ******************************************************************************* 12 | Use SERVO Module to control the rotation of 12-channel servo. 13 | 使用 SERVO 模块控制 12 通道舵机的旋转。 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #define SERVO_ADDR 0x53 21 | void setup() { 22 | M5.begin(true, false, true, true, kMBusModeInput); 23 | /* kMBusModeOutput,powered by USB or Battery 24 | kMBusModeInput,powered by outside input need to fill in this Otherwise 25 | M5Core2 will not work properly 26 | 由外部供电时此项必填,否则M5Core2将无法正常工作 */ 27 | M5.Lcd.setTextFont(4); 28 | M5.Lcd.setCursor(70, 100); 29 | M5.Lcd.print("Servo Example"); 30 | 31 | Wire.begin(32, 33, 100000UL); 32 | } 33 | 34 | // addr 0x01 mean control the number 1 servo by us 35 | void Servo_write_us(uint8_t number, uint16_t us) { 36 | Wire.beginTransmission(SERVO_ADDR); 37 | Wire.write(0x00 | number); 38 | Wire.write(us & 0x00ff); 39 | Wire.write(us >> 8 & 0x00ff); 40 | Wire.endTransmission(); 41 | } 42 | 43 | // addr 0x11 mean control the number 1 servo by angle 44 | void Servo_write_angle(uint8_t number, uint8_t angle) { 45 | Wire.beginTransmission(SERVO_ADDR); 46 | Wire.write(0x10 | number); 47 | Wire.write(angle); 48 | Wire.endTransmission(); 49 | } 50 | 51 | void loop() { 52 | for (uint8_t i = 0; i < 12; i++) { 53 | Servo_write_us(i, 700); 54 | // Servo_write_angle(i, 0); 55 | } 56 | delay(1000); 57 | for (uint8_t i = 0; i < 12; i++) { 58 | Servo_write_us(i, 2300); 59 | // Servo_write_angle(i, 180); 60 | } 61 | delay(1000); 62 | } -------------------------------------------------------------------------------- /examples/Module/SERVO2_PCA9685/.vscode/arduino.json: -------------------------------------------------------------------------------- 1 | { 2 | "port": "COM1" 3 | } -------------------------------------------------------------------------------- /examples/Module/SERVO2_PCA9685/SERVO2_PCA9685.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/module/servo2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/module/servo2 8 | * 9 | * Product: servo2. 10 | * Date: 2021/9/2 11 | ******************************************************************************* 12 | Use SERVO2 Module to control the rotation of 16-channel servo. 13 | 使用 SERVO2 模块控制 16 通道舵机的旋转。 14 | */ 15 | 16 | #include 17 | #include 18 | #include "Adafruit_PWMServoDriver.h" 19 | 20 | Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40, Wire1); 21 | 22 | #define SERVOMIN \ 23 | 102 // This is the 'minimum' pulse length count (out of 4096) 24 | // 这是“最小”脉冲长度计数(共 4096 个) 25 | #define SERVOMAX \ 26 | 512 // This is the 'maximum' pulse length count (out of 4096) 27 | // 这是“最大”脉冲长度计数(共 4096 个) 28 | #define USMIN \ 29 | 500 // This is the rounded 'minimum' microsecond length based on the 30 | // minimum pulse of 102 这是基于 102 的最小脉冲的舍入“最小”微秒长度 31 | #define USMAX \ 32 | 2500 // This is the rounded 'maximum' microsecond length based on the 33 | // maximum pulse of 512 这是基于 512 的最大脉冲的舍入“最大”微秒长度 34 | #define SERVO_FREQ \ 35 | 50 // Analog servos run at ~50 Hz updates 模拟伺服以 ~50 Hz 更新运行 36 | 37 | void setup() { 38 | M5.begin(true, true, true, true, kMBusModeInput); 39 | /* kMBusModeOutput,powered by USB or Battery 40 | kMBusModeInput,powered by outside input need to fill in this Otherwise 41 | M5Core2 will not work properly 42 | 由外部供电时此项必填,否则M5Core2将无法正常工作 */ 43 | Wire1.begin(21, 22); 44 | pwm.begin(); 45 | pwm.setPWMFreq(50); 46 | M5.Lcd.setCursor(115, 0, 4); 47 | M5.Lcd.setTextColor(TFT_GREEN, TFT_BLACK); 48 | M5.Lcd.print("Servo2"); 49 | } 50 | 51 | void setServoPulse(uint8_t n, double pulse) { 52 | double pulselength; 53 | pulselength = 1000000; // 1,000,000 us per second 54 | pulselength /= 50; // 50 Hz 55 | Serial.print(pulselength); 56 | Serial.println(" us per period"); 57 | pulselength /= 4096; // 12 bits of resolution 58 | Serial.print(pulselength); 59 | Serial.println(" us per bit"); 60 | pulse *= 1000; 61 | pulse /= pulselength; 62 | Serial.println(pulse); 63 | pwm.setPWM(n, 0, pulse); 64 | } 65 | 66 | void servo_angle_write(uint8_t n, int Angle) { 67 | double pulse = Angle; 68 | pulse = pulse / 90 + 0.5; 69 | setServoPulse(n, pulse); 70 | } 71 | 72 | void loop() { 73 | for (int i = 0; i < 16; i++) { 74 | setServoPulse(i, 0.5); 75 | } 76 | delay(500); 77 | for (int i = 0; i < 16; i++) { 78 | setServoPulse(i, 2.5); 79 | } 80 | delay(500); 81 | } 82 | -------------------------------------------------------------------------------- /examples/Module/USB_MAX3421E/usb_mouse/M5Mouse.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int mou_px, mou_py, mou_button; 4 | 5 | class MouseRptParser : public MouseReportParser { 6 | protected: 7 | void OnMouseMove(MOUSEINFO *mi); 8 | void OnLeftButtonUp(MOUSEINFO *mi); 9 | void OnLeftButtonDown(MOUSEINFO *mi); 10 | void OnRightButtonUp(MOUSEINFO *mi); 11 | void OnRightButtonDown(MOUSEINFO *mi); 12 | void OnMiddleButtonUp(MOUSEINFO *mi); 13 | void OnMiddleButtonDown(MOUSEINFO *mi); 14 | }; 15 | void SendToBT(MOUSEINFO *mi) { 16 | byte Button = 0; 17 | 18 | if (mi->bmLeftButton) 19 | Button |= BIT0; 20 | else 21 | Button & !BIT0; 22 | 23 | if (mi->bmRightButton) 24 | Button |= BIT1; 25 | else 26 | Button & !BIT1; 27 | 28 | if (mi->bmMiddleButton) 29 | Button |= BIT2; 30 | else 31 | Button & !BIT2; 32 | 33 | mou_px = mi->dX; 34 | mou_py = mi->dY; 35 | mou_button = Button; 36 | // /* 37 | Serial.println("L Mouse Move"); 38 | Serial.print("dx="); 39 | Serial.print(mi->dX, DEC); 40 | Serial.print(" dy="); 41 | Serial.println(mi->dY, DEC); 42 | Serial.println(Button, DEC); 43 | // */ 44 | 45 | /* 46 | Serial.write(0x08); //BYTE1 47 | Serial.write(0x00); //BYTE2 48 | Serial.write(0xA1); //BYTE3 49 | Serial.write(0x02); //BYTE4 50 | Serial.write(Button); //BYTE5 51 | Serial.write(mi->dX); //BYTE6 52 | Serial.write(mi->dY); //BYTE7 53 | Serial.write(0); //BYTE8 54 | */ 55 | } 56 | void MouseRptParser::OnMouseMove(MOUSEINFO *mi) { 57 | SendToBT(mi); 58 | }; 59 | void MouseRptParser::OnLeftButtonUp(MOUSEINFO *mi) { 60 | // Serial.println("L Butt Up"); 61 | SendToBT(mi); 62 | }; 63 | void MouseRptParser::OnLeftButtonDown(MOUSEINFO *mi) { 64 | // Serial.println("L Butt Dn"); 65 | SendToBT(mi); 66 | }; 67 | void MouseRptParser::OnRightButtonUp(MOUSEINFO *mi) { 68 | // Serial.println("R Butt Up"); 69 | SendToBT(mi); 70 | }; 71 | void MouseRptParser::OnRightButtonDown(MOUSEINFO *mi) { 72 | // Serial.println("R Butt Dn"); 73 | SendToBT(mi); 74 | }; 75 | void MouseRptParser::OnMiddleButtonUp(MOUSEINFO *mi) { 76 | // Serial.println("M Butt Up"); 77 | SendToBT(mi); 78 | }; 79 | void MouseRptParser::OnMiddleButtonDown(MOUSEINFO *mi) { 80 | // Serial.println("M Butt Dn"); 81 | SendToBT(mi); 82 | }; 83 | -------------------------------------------------------------------------------- /examples/Touch/TouchGoal/Goals.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define TEXT_TOP 25 4 | #define TEXT_CENTER 160 5 | #define TEXT_HEIGHT 32 6 | #define TEXT_FONT 4 7 | 8 | #define TEST_DURRATION 8000 9 | 10 | class Goal { 11 | public: 12 | Goal(); 13 | bool test(); 14 | bool passed(); 15 | const char* getName(); 16 | virtual void event_handler(Event& evt) = 0; 17 | 18 | protected: 19 | String name; 20 | uint32_t start_time; 21 | bool success; 22 | }; 23 | 24 | class TapAGoal : public Goal { 25 | public: 26 | TapAGoal(); 27 | void event_handler(Event& e); 28 | }; 29 | class TapBGoal : public Goal { 30 | public: 31 | TapBGoal(); 32 | void event_handler(Event& e); 33 | }; 34 | class LongPressAGoal : public Goal { 35 | public: 36 | LongPressAGoal(); 37 | void event_handler(Event& e); 38 | }; 39 | class LongPressBGoal : public Goal { 40 | public: 41 | LongPressBGoal(); 42 | void event_handler(Event& e); 43 | }; 44 | class LongPressBackgroundGoal : public Goal { 45 | public: 46 | LongPressBackgroundGoal(); 47 | void event_handler(Event& e); 48 | }; 49 | class DoubleTapAGoal : public Goal { 50 | public: 51 | DoubleTapAGoal(); 52 | void event_handler(Event& e); 53 | }; 54 | class DoubleTapBGoal : public Goal { 55 | public: 56 | DoubleTapBGoal(); 57 | void event_handler(Event& e); 58 | }; 59 | class TapBackgroundGoal : public Goal { 60 | public: 61 | TapBackgroundGoal(); 62 | void event_handler(Event& e); 63 | }; 64 | class DoubleTapBackgroundGoal : public Goal { 65 | public: 66 | DoubleTapBackgroundGoal(); 67 | void event_handler(Event& e); 68 | }; 69 | class DragFromAtoBGoal : public Goal { 70 | public: 71 | DragFromAtoBGoal(); 72 | void event_handler(Event& e); 73 | }; 74 | class DragFromBtoAGoal : public Goal { 75 | public: 76 | DragFromBtoAGoal(); 77 | void event_handler(Event& e); 78 | }; 79 | class DragFromAtoBackgroundGoal : public Goal { 80 | public: 81 | DragFromAtoBackgroundGoal(); 82 | void event_handler(Event& e); 83 | }; 84 | class DragFromBtoBackgroundGoal : public Goal { 85 | public: 86 | DragFromBtoBackgroundGoal(); 87 | void event_handler(Event& e); 88 | }; 89 | class DragFromBackgroundtoAGoal : public Goal { 90 | public: 91 | DragFromBackgroundtoAGoal(); 92 | void event_handler(Event& e); 93 | 94 | private: 95 | bool can_succeed; 96 | }; 97 | class DragFromBackgroundtoBGoal : public Goal { 98 | public: 99 | DragFromBackgroundtoBGoal(); 100 | void event_handler(Event& e); 101 | 102 | private: 103 | bool can_succeed; 104 | }; 105 | class SwipeUpGoal : public Goal { 106 | public: 107 | SwipeUpGoal(); 108 | void event_handler(Event& e); 109 | }; 110 | class SwipeDownGoal : public Goal { 111 | public: 112 | SwipeDownGoal(); 113 | void event_handler(Event& e); 114 | }; 115 | class SwipeLeftGoal : public Goal { 116 | public: 117 | SwipeLeftGoal(); 118 | void event_handler(Event& e); 119 | }; 120 | class SwipeRightGoal : public Goal { 121 | public: 122 | SwipeRightGoal(); 123 | void event_handler(Event& e); 124 | }; 125 | -------------------------------------------------------------------------------- /examples/Touch/circles/circles.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | M5.begin(); 5 | M5.Lcd.fillScreen(WHITE); 6 | } 7 | 8 | void loop() { 9 | M5.update(); 10 | Event& e = M5.Buttons.event; 11 | if (e & (E_MOVE | E_RELEASE)) circle(e & E_MOVE ? e.from : e.to, WHITE); 12 | if (e & (E_TOUCH | E_MOVE)) circle(e.to, e.finger ? BLUE : RED); 13 | } 14 | 15 | void circle(Point p, uint16_t c) { 16 | M5.Lcd.drawCircle(p.x, p.y, 50, c); 17 | M5.Lcd.drawCircle(p.x, p.y, 52, c); 18 | } 19 | -------------------------------------------------------------------------------- /examples/Unit/ADC_ADS1100/ADC_ADS1100.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/adc 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/adc 8 | * 9 | * Product: ADC. A/D转换器 10 | * Date: 2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port A,Use ADC Unit to convert 0 ~ 12V analog voltage into 13 | 16-bit data and display it on the screen. 请连接端口A,利用ADC单元将0 ~ 14 | 12V模拟电压转换成16位数据显示在屏幕上。 15 | */ 16 | 17 | #include 18 | #include "M5_ADS1100.h" 19 | 20 | ADS1100 ads; 21 | 22 | void setup(void) { 23 | M5.begin(); // Init M5Core2. 初始化M5Core2 24 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 25 | 26 | // The address can be changed making the option of connecting multiple 27 | // devices 地址可以改变,以连接多个设备 28 | ads.getAddr_ADS1100( 29 | ADS1100_DEFAULT_ADDRESS); // 0x48, 1001 000 (ADDR = GND) 30 | 31 | // The ADC gain (PGA). ADC增益(PGA) 32 | ads.setGain(GAIN_ONE); // 1x gain(default) 33 | // ads.setGain(GAIN_TWO); // 2x gain 34 | // ads.setGain(GAIN_FOUR); // 4x gain 35 | // ads.setGain(GAIN_EIGHT); // 8x gain 36 | 37 | // Device operating mode. 设备工作模式 38 | ads.setMode(MODE_CONTIN); // Continuous conversion mode (default) 39 | // ads.setMode(MODE_SINGLE); // Single-conversion mode 40 | 41 | // Data rate. 数据速率 42 | ads.setRate(RATE_8); // 8SPS (default) 43 | // ads.setRate(RATE_16); // 16SPS 44 | // ads.setRate(RATE_32); // 32SPS 45 | // ads.setRate(RATE_128); // 128SPS 46 | 47 | ads.setOSMode( 48 | OSMODE_SINGLE); // Set to start a single-conversion. 设置开始一次转换 49 | 50 | ads.begin(); // Sets up the Hardware. 设置硬件 51 | } 52 | 53 | void loop(void) { 54 | byte error; 55 | int8_t address; 56 | 57 | address = ads.ads_i2cAddress; 58 | Wire.beginTransmission(address); 59 | error = Wire.endTransmission(); 60 | if (error == 0) // If the device is connected. 如果连接上设备 61 | { 62 | int16_t result; 63 | result = ads.Measure_Differential(); 64 | M5.Lcd.fillScreen(BLACK); 65 | char data[20] = {0}; 66 | sprintf(data, "%d", result); 67 | M5.Lcd.drawCentreString(data, 160, 100, 4); 68 | } else { 69 | M5.Lcd.drawString("No Found ADC sensor.", 20, 100, 2); 70 | } 71 | delay(1000); 72 | } -------------------------------------------------------------------------------- /examples/Unit/ANGLE/ANGLE.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/angle 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/angle 8 | * 9 | * Product: Angle. 角度计 10 | * Date: 2021/8/9 11 | ******************************************************************************* 12 | Description:Connect to Port B, Read the Angle of the angometer and convert it 13 | to digital display 连接至Port B,读取角度计的角度,并转换为数字量显示 14 | */ 15 | 16 | #include 17 | int sensorPin = 18 | 36; // set the input pin for the potentiometer. 设置角度计的输入引脚 19 | 20 | int last_sensorValue = 21 | 100; // Stores the value last read by the sensor. 存储传感器上次读取到的值 22 | int cur_sensorValue = 0; // Stores the value currently read by the sensor. 23 | // 存储传感器当前读取到的值 24 | 25 | void setup() { 26 | M5.begin(); // Init M5Core2. 初始化 M5Core2 27 | pinMode( 28 | sensorPin, 29 | INPUT); // Sets the specified pin to input mode. 设置指定引脚为输入模式 30 | dacWrite(25, 0); 31 | M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字体大小为2 32 | M5.Lcd.print("the value of ANGLE: "); 33 | } 34 | 35 | void loop() { 36 | cur_sensorValue = analogRead( 37 | sensorPin); // read the value from the sensor. 读取当前传感器的值 38 | M5.Lcd.setCursor(0, 25); // Place the cursor at (0,25). 将光标固定在(0,25) 39 | if (abs(cur_sensorValue - last_sensorValue) > 40 | 10) { // If the difference is more than 10. 如果差值超过10 41 | M5.Lcd.fillRect(0, 25, 100, 25, BLACK); 42 | M5.Lcd.print(cur_sensorValue); 43 | last_sensorValue = cur_sensorValue; 44 | } 45 | delay(50); 46 | } 47 | -------------------------------------------------------------------------------- /examples/Unit/BPS_BMP280/BPS_BMP280.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/bps 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/bps 8 | * 9 | * Product: BPS_BMP280. 压力传感器 10 | * Date: 2021/8/10 11 | ******************************************** *********************************** 12 | Please connect to Port A,Read atmospheric pressure and temperature and display 13 | them on the display screen 请连接端口A,读取大气压强和温度并在显示屏上显示 14 | */ 15 | #include 16 | #include //The BPS uses I2C comunication. 17 | #include "Adafruit_Sensor.h" 18 | #include 19 | 20 | Adafruit_BMP280 bme; 21 | 22 | void setup() { 23 | M5.begin(); // Init M5Core2. 初始化 M5Core2 24 | Wire.begin(); // Wire init, adding the I2C bus. Wire初始化, 加入i2c总线 25 | while (!bme.begin( 26 | 0x76)) { // Init this sensor,True if the init was successful, otherwise 27 | // false. 初始化传感器,如果初始化成功返回1 28 | M5.Lcd.println("Could not find a valid BMP280 sensor, check wiring!"); 29 | } 30 | M5.Lcd.clear(); // Clear the screen. 清屏 31 | } 32 | 33 | float pressure, 34 | Temp; // Store the vuale of pressure and Temperature. 存储压力和温度() 35 | 36 | void loop() { 37 | pressure = bme.readPressure(); 38 | Temp = bme.readTemperature(); 39 | M5.Lcd.setCursor(0, 0); // 将光标设置在(0 ,0). Set the cursor to (0,0) 40 | M5.Lcd.setTextSize(3); // 设置字体大小为3. Set the font size to 3 41 | M5.Lcd.printf("Pressure:%2.0fPa\nTemperature:%2.0f^C", pressure, Temp); 42 | delay(100); 43 | } 44 | -------------------------------------------------------------------------------- /examples/Unit/BPS_QMP6988/BPS_QMP6988.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/core2 8 | * 9 | * Product: BPS_QMP6988. 压力传感器 10 | * Date: 2021/8/10 11 | ****************************************************************************** 12 | Please connect to Port A,Read atmospheric pressure and display them on the 13 | display screen 请连接端口A,读取大气压强并在显示屏上显示 14 | */ 15 | #include 16 | #include "Wire.h" //The BPS uses I2C comunication. 17 | #include "M5_ENV.h" 18 | 19 | QMP6988 qmp6988; 20 | 21 | void setup() { 22 | M5.begin(true, false, true, 23 | true); // Init M5Core2 And the I2C port(21,22). 初始化 24 | // M5Core2和I2C端口(21,22) 25 | } 26 | 27 | void loop() { 28 | while ( 29 | !qmp6988 30 | .init()) { // Init qmp6988.True if the init was successful, 31 | // otherwise false. 初始化qmp6988,如果初始化成功返回1 32 | M5.lcd.setTextSize(1); // Set the text size to 1. 设置文字大小为1 33 | M5.Lcd.println( 34 | "\nCould not find a valid qmp6988 sensor, check wiring!"); 35 | } 36 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 37 | M5.lcd.setCursor(0, 30); // Set the cursor at (0,30). 设置光标在(0,30)处 38 | M5.lcd.fillScreen(BLACK); // Fill the screen with black (to clear the 39 | // screen). 将屏幕填充满黑色(用来清屏) 40 | M5.Lcd.printf("Pressure:%0.2f", 41 | qmp6988.calcPressure()); // Screen print format string. 42 | // 屏幕打印格式化字符串 43 | delay(2000); // Delay 2s. 延迟2s 44 | } -------------------------------------------------------------------------------- /examples/Unit/BUTTON/BUTTON.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/button 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/button 8 | * 9 | * Product: Button. 按键 10 | * Date: 2021/7/26 11 | ******************************************************************************* 12 | Please connect to Port B,Read the button status of BUTTON Unit and display it 13 | on the screen 请连接端口B,读取按键的状态并在显示屏上显示 if you don't have M5GO 14 | BOTTOM, you need change the pinMode and the digitalRead to 33, But you will not 15 | be able to use any I2C operations. 如果你没有M5GO 16 | BOTTOM,你需要改变pinMode和digitalRead到33,但是你将不能使用任何I2C操作. 17 | */ 18 | #include 19 | 20 | int last_value = 0; 21 | int cur_value = 0; 22 | 23 | void setup() { 24 | M5.begin(); // Init M5Core2. 初始化 M5Core2 25 | pinMode(36, INPUT); // set pin mode to input.设置引脚模式为输入模式 26 | M5.Lcd.setTextColor( 27 | YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 28 | M5.Lcd.setTextSize(2); // Setting the Font size. 设置字号大小 29 | M5.Lcd.setCursor( 30 | 80, 0); // Set the cursor position to (80,0). 将光标位置设置为(80,0) 31 | M5.Lcd.println("Button example"); 32 | M5.Lcd.setTextColor(WHITE); 33 | } 34 | 35 | void loop() { 36 | cur_value = digitalRead(36); // read the value of BUTTON. 读取22号引脚的值 37 | M5.Lcd.setCursor(80, 25); 38 | M5.Lcd.print("Button"); 39 | M5.Lcd.setCursor(0, 45); 40 | M5.Lcd.print("Value: "); 41 | M5.Lcd.setCursor(0, 85); 42 | M5.Lcd.print("State: "); 43 | if (cur_value != last_value) { 44 | M5.Lcd.fillRect(85, 45, 75, 85, 45 | BLACK); // Draw a black rectangle 75 by 85 at (85,45). 46 | // 在(85,45)处绘制宽75,高85的黑色矩形 47 | if (cur_value == 0) { 48 | M5.Lcd.setCursor(95, 45); 49 | M5.Lcd.print("0"); // display the status 50 | M5.Lcd.setCursor(95, 85); 51 | M5.Lcd.print("pre"); 52 | } else { 53 | M5.Lcd.setCursor(95, 45); 54 | M5.Lcd.print("1"); // display the status 55 | M5.Lcd.setCursor(95, 85); 56 | M5.Lcd.print("rel"); 57 | } 58 | last_value = cur_value; 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/Unit/CAN/CAN_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @section License 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2017, Thomas Barth, barth-dev.de 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, copy, 12 | * modify, merge, publish, distribute, sublicense, and/or sell copies 13 | * of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be 17 | * included in all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | */ 28 | 29 | #ifndef __DRIVERS_CAN_CFG_H__ 30 | #define __DRIVERS_CAN_CFG_H__ 31 | 32 | #include "freertos/FreeRTOS.h" 33 | #include "freertos/queue.h" 34 | #include "freertos/task.h" 35 | #include "driver/gpio.h" 36 | #include "freertos/semphr.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** \brief CAN Node Bus speed */ 43 | typedef enum { 44 | CAN_SPEED_100KBPS = 100, /**< \brief CAN Node runs at 100kBit/s. */ 45 | CAN_SPEED_125KBPS = 125, /**< \brief CAN Node runs at 125kBit/s. */ 46 | CAN_SPEED_200KBPS = 200, /**< \brief CAN Node runs at 250kBit/s. */ 47 | CAN_SPEED_250KBPS = 250, /**< \brief CAN Node runs at 250kBit/s. */ 48 | CAN_SPEED_500KBPS = 500, /**< \brief CAN Node runs at 500kBit/s. */ 49 | CAN_SPEED_800KBPS = 800, /**< \brief CAN Node runs at 800kBit/s. */ 50 | CAN_SPEED_1000KBPS = 1000 /**< \brief CAN Node runs at 1000kBit/s. */ 51 | } CAN_speed_t; 52 | 53 | /** \brief CAN configuration structure */ 54 | typedef struct { 55 | CAN_speed_t speed; /**< \brief CAN speed. */ 56 | gpio_num_t tx_pin_id; /**< \brief TX pin. */ 57 | gpio_num_t rx_pin_id; /**< \brief RX pin. */ 58 | QueueHandle_t rx_queue; /**< \brief Handler to FreeRTOS RX queue. */ 59 | QueueHandle_t tx_queue; /**< \brief Handler to FreeRTOS TX queue. */ 60 | TaskHandle_t tx_handle; /**< \brief Handler to FreeRTOS TX task. */ 61 | TaskHandle_t rx_handle; /**< \brief Handler to FreeRTOS RX task. */ 62 | } CAN_device_t; 63 | 64 | /** \brief CAN configuration reference */ 65 | extern CAN_device_t CAN_cfg; 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __DRIVERS_CAN_CFG_H__ */ 72 | -------------------------------------------------------------------------------- /examples/Unit/CAN/ESP32CAN.cpp: -------------------------------------------------------------------------------- 1 | #include "ESP32CAN.h" 2 | 3 | int ESP32CAN::CANInit() { 4 | return CAN_init(); 5 | } 6 | int ESP32CAN::CANWriteFrame(const CAN_frame_t* p_frame) { 7 | return CAN_write_frame(p_frame); 8 | } 9 | int ESP32CAN::CANStop() { 10 | return CAN_stop(); 11 | } 12 | int ESP32CAN::CANConfigFilter(const CAN_filter_t* p_filter) { 13 | return CAN_config_filter(p_filter); 14 | } 15 | 16 | ESP32CAN ESP32Can; 17 | -------------------------------------------------------------------------------- /examples/Unit/CAN/ESP32CAN.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP32CAN_H 2 | #define ESP32CAN_H 3 | 4 | #include "CAN_config.h" 5 | #include "CAN.h" 6 | 7 | class ESP32CAN { 8 | public: 9 | int CANInit(); 10 | int CANConfigFilter(const CAN_filter_t* p_filter); 11 | int CANWriteFrame(const CAN_frame_t* p_frame); 12 | int CANStop(); 13 | }; 14 | 15 | extern ESP32CAN ESP32Can; 16 | #endif 17 | -------------------------------------------------------------------------------- /examples/Unit/CardKB/CardKB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/core2 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/core2 8 | * 9 | * Product: CardKB. 键盘 10 | * Date: 2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port A,Read the characters entered by CardKB Unit and 13 | display them on the screen. 请连接端口A,读取CardKB 14 | Unit输入的字符并显示在屏幕上。 15 | */ 16 | 17 | #include 18 | 19 | #define CARDKB_ADDR \ 20 | 0x5F // Define the I2C address of CardKB. 定义CardKB的I2C地址 21 | 22 | void setup() { 23 | M5.begin(); // Init M5Core2. 初始化 M5Core2 24 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 25 | M5.Lcd.printf("IIC Address: 0x5F\n"); 26 | M5.Lcd.printf(">>"); 27 | Wire.begin(); 28 | } 29 | 30 | void loop() { 31 | Wire.requestFrom( 32 | CARDKB_ADDR, 33 | 1); // Request 1 byte from the slave device. 向从设备请求1字节 34 | while ( 35 | Wire.available()) // If received data is detected. 如果检测到收到数据 36 | { 37 | char c = Wire.read(); // Store the received data. 将接收到的数据存储 38 | if (c != 0) { 39 | M5.Lcd.printf("%c", c); 40 | Serial.println(c, HEX); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/Unit/DAC2_GP8413/DAC2_GP8413.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DAC2_GP8413.ino 3 | * @author SeanKwok (shaoxiang@m5stack.com) 4 | * @brief Core2 Unit DAC2 Test 5 | * @version 0.1 6 | * @date 2024-01-09 7 | * 8 | * 9 | * @Hardwares: Core2 + Unit DAC2(GP8413) 10 | * @Platform Version: Arduino M5Stack Board Manager v2.0.9 11 | * @Dependent Library: 12 | * M5GFX: https://github.com/m5stack/M5GFX 13 | * M5Unified: https://github.com/m5stack/M5Unified 14 | * DFRobot_GP8XXX: https://github.com/DFRobot/DFRobot_GP8XXX 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | DFRobot_GP8XXX_IIC GP8413(RESOLUTION_15_BIT, 0x59, &Wire); 22 | 23 | // range is 0~10000mv 24 | void setDacVoltage(uint16_t vol, uint8_t ch) { 25 | uint16_t setting_vol = 0; 26 | if (vol > 10000) { 27 | vol = 10000; 28 | } 29 | if (ch > 1) ch = 1; 30 | setting_vol = (int16_t)((float)vol / 10000.0f * 32767.0f); 31 | if (setting_vol > 32767) { 32 | setting_vol = 32767; 33 | } 34 | GP8413.setDACOutVoltage(setting_vol, ch); 35 | } 36 | 37 | void AllOutputCtl(uint16_t vol) { 38 | M5.Display.fillRect(0, 0, M5.Display.width(), 30, vol > 0 ? GREEN : ORANGE); 39 | M5.Display.drawString("OUTPUT " + String(vol) + "mv", 40 | M5.Display.width() / 2, 0); 41 | // set channel0 42 | setDacVoltage(vol, 0); 43 | // set channel1 44 | setDacVoltage(vol, 1); 45 | } 46 | 47 | void setup(void) { 48 | auto cfg = M5.config(); 49 | 50 | M5.begin(cfg); 51 | M5.Display.setRotation(1); 52 | M5.Display.setTextDatum(top_center); 53 | M5.Display.setTextColor(WHITE); 54 | M5.Display.setFont(&fonts::FreeSansBoldOblique12pt7b); 55 | M5.Display.setTextSize(1); 56 | M5.Display.drawString("DAC2", M5.Display.width() / 2, 57 | M5.Display.height() / 2 - 20); 58 | Wire.end(); 59 | Wire.begin(32, 33); 60 | 61 | while (GP8413.begin() != 0) { 62 | Serial.println("Init Fail!"); 63 | M5.Display.drawString("Init Fail!", M5.Display.width() / 2, 64 | M5.Display.height() / 2); 65 | delay(1000); 66 | } 67 | M5.Display.clear(); 68 | M5.Display.drawString("DAC2", M5.Display.width() / 2, 69 | M5.Display.height() / 2 - 20); 70 | GP8413.setDACOutRange(GP8413.eOutputRange10V); 71 | M5.Display.drawString("Touch En/Dis Output", M5.Display.width() / 2, 72 | M5.Display.height() / 2 + 20); 73 | 74 | AllOutputCtl(0); 75 | } 76 | 77 | bool output = false; 78 | 79 | void loop(void) { 80 | M5.update(); 81 | if (M5.Touch.getCount() && M5.Touch.getDetail().wasPressed()) { 82 | output = !output; 83 | if (output) { 84 | AllOutputCtl(3300); 85 | // AllOutputCtl(10000); 86 | } else { 87 | AllOutputCtl(0); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /examples/Unit/DAC_MCP4725/DAC_MCP4725.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/dac 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/dac 8 | * 9 | * Product: DAC_MCP4725. 数模转换 10 | * Date: 2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port A,Use DAC Unit to output 0 ~ 3.3V voltage with an 13 | accuracy of 12 bits. 请连接端口A,使用DAC Unit 输出12位精度的0 ~ 3.3V电压。 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #define DAC_ADDR \ 20 | 0x60 // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC) \ 21 | // For MCP4725A0 the address is 0x60 or 0x61 \ 22 | // For MCP4725A2 the address is 0x64 or 0x65 23 | 24 | Adafruit_MCP4725 dac; 25 | 26 | void setup(void) { 27 | M5.begin(true, false, false); // Init M5Core2. 初始化 M5Core2 28 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 29 | M5.Lcd.print(" DAC MCP4725 demo."); 30 | 31 | dac.begin(0x60); // Setups the hardware address and checks the DAC was 32 | // found. 设置硬件地址并检查是否找到DAC 33 | dac.setVoltage(2048, false); 34 | } 35 | 36 | void loop(void) { 37 | M5.Lcd.setCursor(100, 60); 38 | M5.Lcd.print("1.2V"); 39 | dac.setVoltage(1024, 40 | false); // Set the voltage to 1.2V and retain the current 41 | // voltage output after power off or reset. 42 | // 设置电压为1.2v,关闭断电或复位后保留当前电压输出 43 | delay(1000); 44 | M5.Lcd.fillRect( 45 | 100, 60, 120, 40, 46 | BLACK); // Draw a black rectangle at (100,60) with a width of 120 and a 47 | // height of 40. 在(100,60)处绘制一个宽为120,高为40的黑色矩形 48 | M5.Lcd.print("2.4V"); 49 | dac.setVoltage(2048, false); // 2.4v 50 | delay(1000); 51 | M5.Lcd.fillRect(100, 60, 120, 40, BLACK); 52 | } -------------------------------------------------------------------------------- /examples/Unit/DUAL_BUTTON/DUAL_BUTTON.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/dual_button 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/dual_button 8 | * 9 | * Product: Button_Two. 双按键 10 | * Date: 2021/8/9 11 | ******************************************************************************* 12 | Please connect to Port B,Read the button status of BUTTON Unit and display it 13 | on the screen 请连接端口B,读取按键的状态并在显示屏上显示 if you don't have M5GO 14 | BOTTOM, you need change the pinMode and the digitalRead to 33、32, But you will 15 | not be able to use any I2C operations. 如果你没有M5GO 16 | BOTTOM,你需要改变pinMode和digitalRead到 33,32,但是你将不能使用任何I2C操作. 17 | */ 18 | #include 19 | 20 | int last_value1 = 0, last_value2 = 0; 21 | int cur_value1 = 0, cur_value2 = 0; 22 | 23 | void setup() { 24 | M5.begin(); // Init M5Core2. 初始化 M5Core2 25 | pinMode(36, INPUT); // set pin mode to input.设置引脚模式为输入模式 26 | pinMode(26, INPUT); 27 | M5.Lcd.setTextColor( 28 | YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 29 | M5.Lcd.setTextSize(2); // Setting the Font size. 设置字号大小 30 | M5.Lcd.setCursor( 31 | 80, 0); // Set the cursor position to (80,0). 将光标位置设置为(80,0) 32 | M5.Lcd.println("Button example"); 33 | M5.Lcd.setTextColor(WHITE); 34 | } 35 | 36 | void loop() { 37 | cur_value1 = digitalRead(36); // read the value of BUTTON. 读取22号引脚的值 38 | cur_value2 = digitalRead(26); 39 | M5.Lcd.setCursor(90, 25); 40 | M5.Lcd.print("Btn.1 Btn.2"); 41 | M5.Lcd.setCursor(0, 45); 42 | M5.Lcd.print("Value: "); 43 | M5.Lcd.setCursor(0, 85); 44 | M5.Lcd.print("State: "); 45 | if (cur_value1 != last_value1) { 46 | M5.Lcd.fillRect(85, 45, 75, 85, 47 | BLACK); // Draw a black rectangle 75 by 85 at (85,45). 48 | // 在(85,45)处绘制宽75,高85的黑色矩形 49 | if (cur_value1 == 0) { 50 | M5.Lcd.setCursor(95, 45); 51 | M5.Lcd.print("0"); // display the status 52 | M5.Lcd.setCursor(95, 85); 53 | M5.Lcd.print("pre"); 54 | } else { 55 | M5.Lcd.setCursor(95, 45); 56 | M5.Lcd.print("1"); // display the status 57 | M5.Lcd.setCursor(95, 85); 58 | M5.Lcd.print("rel"); 59 | } 60 | last_value1 = cur_value1; 61 | } 62 | if (cur_value2 != last_value2) { 63 | M5.Lcd.fillRect(170, 45, 75, 85, BLACK); 64 | if (cur_value2 == 0) { 65 | M5.Lcd.setCursor(185, 45); 66 | M5.Lcd.print("0"); // display the status 67 | M5.Lcd.setCursor(185, 85); 68 | M5.Lcd.print("pre"); 69 | } else { 70 | M5.Lcd.setCursor(185, 45); 71 | M5.Lcd.print("1"); // display the status 72 | M5.Lcd.setCursor(185, 85); 73 | M5.Lcd.print("rel"); 74 | } 75 | last_value2 = cur_value2; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /examples/Unit/EARTH/EARTH.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/earth 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/earth 8 | * 9 | * Product: EARTH. 土壤湿度 10 | * Date: 2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port B,Read the analog quantity and digital quantity 13 | returned by the EARTH unit, and convert the analog quantity into 12-bit data and 14 | display it on the screen. 请连接端口B,读取EARTH Unit 15 | 返回的模拟量和数字量,并将模拟量转换为12位数据显示在屏幕上。 16 | */ 17 | 18 | #include 19 | 20 | void setup() { 21 | M5.begin(); // Init M5Stack. 初始化M5Stack 22 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 23 | M5.Lcd.printf("UNIT_EARTH EXAMPLE\n"); 24 | pinMode(26, INPUT); 25 | dacWrite(25, 0); // disable the speak noise. 禁用喇叭 26 | } 27 | 28 | void loop() { 29 | M5.Lcd.setCursor(0, 80); // Set the cursor at (0,80). 将光标设置在(0,80) 30 | M5.Lcd.printf("AnalogRead:%d\n", analogRead(36)); 31 | M5.Lcd.printf("DigitalRead:%d\n", digitalRead(26)); 32 | delay(1000); 33 | } 34 | -------------------------------------------------------------------------------- /examples/Unit/EXT_IO_PCA9554PW/EXT_IO_PCA9554PW.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/extio 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/extio 8 | * 9 | * Product: extio. 10 | * Date: 2021/8/30 11 | ******************************************************************************* 12 | Please connect to Port A,Control the 8 extended IOs on the EXT.IO Unit to 13 | cycle high and low level changes. 请连接端口 A,在EXT.IO 14 | Unit上控制8个扩展的IO来循环高电平和低电平的变化。 15 | */ 16 | #include 17 | #include "PCA9554.h" 18 | 19 | PCA9554 ioCon1( 20 | 0x27); // Create an object at this address. 在这个地址上创建一个对象 21 | 22 | uint8_t res; 23 | void setup() { 24 | M5.begin(); 25 | Wire.begin(); 26 | M5.Lcd.setTextSize(2); 27 | M5.Lcd.setTextColor(YELLOW); 28 | M5.Lcd.setCursor(70, 0); 29 | M5.Lcd.print("UNIT_IO EXAMPLE\n"); 30 | 31 | ioCon1.twiWrite( 32 | 21, 33 | 22); // Sets the I2C pin of the connection. 设置连接的I2C引脚 34 | delay(10); 35 | res = 1; 36 | ioCon1.twiRead(res); 37 | Serial.printf("res:%d\r\n", res); 38 | 39 | ioCon1.portMode( 40 | ALLOUTPUT); // Set the port as all output. 设置所有引脚为输出模式 41 | } 42 | 43 | void loop() { 44 | for (int i = 0; i < 8; i++) ioCon1.digitalWrite(i, LOW); 45 | delay(1000); 46 | for (int i = 0; i < 8; i++) ioCon1.digitalWrite(i, HIGH); 47 | delay(1000); 48 | 49 | // write 0-7 HIGH. 设置0~7号引脚为高电平 50 | Serial.println(ioCon1.digitalWritePort(0xff)); 51 | delay(200); 52 | 53 | // write 0-7 LOW. 设置0~7号引脚为低电平 54 | Serial.println(ioCon1.digitalWritePort(0x00)); 55 | delay(200); 56 | 57 | // write Port, the same read 58 | for (byte i = 0; i < 8; i++) { 59 | ioCon1.digitalWritePort((1 << i)); 60 | delay(200); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /examples/Unit/FADER/FADER.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * 7 | * Visit for more information: https://docs.m5stack.com/en/unit/fader 8 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/fader 9 | * 10 | * Product: UNIT FADER. 滑动电位器/推子 11 | * Date: 2021/8/20 12 | ******************************************************************************* 13 | Connect UNIT FADER to port B and push the FADER slider to adjust the input 14 | value and light brightness 将UNIT FADER连接到B端口, 15 | 推动FADER滑杆即可实现调整输入数值大小与灯光亮度 16 | */ 17 | 18 | #include "M5Core2.h" 19 | #include "FastLED.h" 20 | 21 | // How many leds in your strip? 22 | #define NUM_LEDS 14 23 | #define INPUT_PINS 36 24 | 25 | #define DATA_PIN 26 26 | 27 | // Define the array of leds 28 | CRGB leds[NUM_LEDS]; 29 | 30 | uint8_t beginHue = 0; 31 | uint8_t deltaHue = 30; 32 | uint8_t brightness = 100; 33 | uint16_t rawADC = 0; 34 | 35 | void setup() { 36 | M5.begin(); 37 | M5.Lcd.setTextDatum(MC_DATUM); 38 | M5.Lcd.drawString("FADER UNIT TEST", 160, 60, 4); 39 | FastLED.addLeds(leds, NUM_LEDS); 40 | delay(1000); 41 | pinMode(36, INPUT); 42 | fill_rainbow(leds, NUM_LEDS, beginHue, deltaHue); 43 | } 44 | 45 | void loop() { 46 | rawADC = analogRead(INPUT_PINS); // Read ADC value 读取ADC数值 47 | brightness = map(rawADC, 0, 4095, 0, 48 | 255); // The mapping ADC value is the brightness value 49 | // range 映射ADC值为亮度值范围 50 | FastLED.setBrightness(brightness); // Adjust the brightness of the FADER 51 | // LED 调整FADER LED灯亮度 52 | FastLED.show(); 53 | Serial.printf("%d\r\n", rawADC); 54 | M5.Lcd.fillRect(0, 120, 320, 100, BLACK); 55 | M5.Lcd.drawString("value: " + String(rawADC), 160, 160, 4); 56 | delay(100); 57 | } -------------------------------------------------------------------------------- /examples/Unit/FAN/FAN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/unit_fan 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/unit_fan 8 | * 9 | * Product: Fan. 风扇 10 | * Date: 2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port B, Adjust the speed of FAN Unit through PWM. 13 | 请连接端口B,通过PWM调节风扇单元的转速。 14 | */ 15 | #include 16 | 17 | #define motor_pin 26 18 | 19 | int freq = 10000; 20 | int ledChannel = 0; 21 | int resolution = 10; 22 | void setup() { 23 | M5.begin(); // Init M5Core2. 初始化M5Core2 24 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 25 | M5.Lcd.setCursor(80, 26 | 10); // Set the cursor at (80,10). 将光标设置在(80,10)处 27 | M5.Lcd.println("Fan"); 28 | ledcSetup( 29 | ledChannel, freq, 30 | resolution); // Sets the frequency and number of counts corresponding 31 | // to the channel. 设置通道对应的频率和计数位数 32 | ledcAttachPin( 33 | motor_pin, 34 | ledChannel); // Binds the specified channel to the specified I/O port 35 | // for output. 将指定通道绑定到指定 IO 口上以实现输出 36 | } 37 | 38 | void loop() { 39 | ledcWrite(ledChannel, 1024); // Output PWM. 输出PWM 40 | delay(1000); 41 | ledcWrite(ledChannel, 0); 42 | delay(1000); 43 | } 44 | -------------------------------------------------------------------------------- /examples/Unit/HALL/HALL.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/hall 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/hall 8 | * 9 | * Product: Hall. 霍尔传感器 10 | * Date: 2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port B,Displays a string on the screen. 13 | 请连接端口B,在屏幕上显示字符串。 14 | Low-level signal can be generated when the magnet S pole is close to the front 15 | of the sensor 当磁体S极靠近传感器前端时,会产生低电平信号 OR the N pole is close 16 | to the back, and the internal LED indicator will light up, the screen wiil 17 | display 0. 或N极靠近背面,内部LED指示灯亮起,屏幕显示0。 18 | */ 19 | 20 | #include 21 | 22 | #define HALL 36 23 | 24 | void setup() { 25 | M5.begin(); // Init M5Core2. 初始化M5Core2 26 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 27 | M5.Lcd.print(" HALL Sensor"); 28 | pinMode(HALL, 29 | INPUT); // Set the pins to which the Hall sensor is connected to 30 | // the input mode. 将霍尔传感器所连接的引脚设置为输入模式 31 | } 32 | 33 | void loop() { 34 | bool status = digitalRead(HALL); 35 | M5.Lcd.setCursor(20, 80); 36 | M5.Lcd.printf("Hall status : %d", status); 37 | } 38 | -------------------------------------------------------------------------------- /examples/Unit/HEART_MAX30100/MAX30100_RawData/MAX30100_RawData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/heart 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/heart 8 | * 9 | * Product: Heart Rate. 心率 10 | * Date: 2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port A, HEART Unit obtains the original value of the heart 13 | rate detection and displays it on the screen. The user can also use the Arduino 14 | IDE Serial Plotter to view the line graph output. 请连接端口A,HEART 15 | Unit获取心率检测的原始值并显示在屏幕上。用户还可以使用Arduino IDE Serial 16 | Plotter查看线图输出。 17 | */ 18 | 19 | #include 20 | #include "MAX30100.h" 21 | 22 | #define SAMPLING_RATE MAX30100_SAMPRATE_100HZ 23 | #define IR_LED_CURRENT MAX30100_LED_CURR_24MA 24 | #define RED_LED_CURRENT MAX30100_LED_CURR_27_1MA 25 | #define PULSE_WIDTH MAX30100_SPC_PW_1600US_16BITS 26 | #define HIGHRES_MODE true 27 | 28 | MAX30100 29 | sensor; // Instantiate a MAX30100 sensor class. 实例化一个MAX30100传感器类 30 | 31 | void setup() { 32 | M5.begin(); // Init M5Core2. 初始化M5Core2 33 | Serial.print("Initializing MAX30100.."); 34 | 35 | while (!sensor.begin()) { // Initialize the sensor. 初始化传感器 36 | M5.Lcd.setTextFont(4); 37 | M5.Lcd.setCursor(50, 100, 4); 38 | M5.Lcd.println("Sensor not found"); 39 | delay(1000); 40 | } 41 | M5.Lcd.fillScreen(BLACK); 42 | // Set up the wanted parameters. 设置所需的参数 43 | sensor.setMode(MAX30100_MODE_SPO2_HR); 44 | sensor.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT); 45 | sensor.setLedsPulseWidth(PULSE_WIDTH); 46 | sensor.setSamplingRate(SAMPLING_RATE); 47 | sensor.setHighresModeEnabled(HIGHRES_MODE); 48 | } 49 | 50 | void loop() { 51 | uint16_t ir, red; 52 | sensor.update(); // 更新传感器读取到的数据 53 | while (sensor.getRawValues(&ir, &red)) { // 如果获取到数据 54 | M5.Lcd.setTextFont(4); 55 | M5.Lcd.setCursor(100, 100, 4); 56 | M5.Lcd.printf("IR:%d ", ir); 57 | M5.Lcd.setCursor(100, 130, 4); 58 | M5.Lcd.printf("RED:%d ", red); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/Unit/IR/IR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/ir 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/ir 8 | * 9 | * Product: ir. 10 | * Date: 2021/8/27 11 | ******************************************************************************* 12 | Please connect to Port B,Use IR Unit to receive and test infrared receiving 13 | and transmitting 请连接端口B,使用红外单元接收和测试红外接收和发射. 14 | */ 15 | 16 | #include 17 | 18 | int ir_recv_pin = 36; // set the input pin. 设置引脚 19 | int ir_send_pin = 26; 20 | 21 | int last_recv_value = 0; 22 | int cur_recv_value = 0; 23 | 24 | void setup() { 25 | M5.begin(); 26 | pinMode(ir_recv_pin, INPUT); 27 | pinMode(ir_send_pin, OUTPUT); 28 | // send infrared light. 发送红外线 29 | // now, you can see the infrared light through mobile phone camera. 30 | // 现在,你可以通过手机摄像头看到红外光 31 | digitalWrite(ir_send_pin, 1); 32 | M5.Lcd.setTextSize(2); 33 | M5.Lcd.setCursor(0, 0); 34 | M5.Lcd.print("Test for IR receiver: "); 35 | } 36 | 37 | void loop() { 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 == 46 | 0) { // 0: detected 1: not detected, 0检测到,1没有检测到 47 | M5.Lcd.print("detected!"); 48 | } 49 | last_recv_value = cur_recv_value; 50 | } 51 | Serial.println(cur_recv_value); 52 | } 53 | -------------------------------------------------------------------------------- /examples/Unit/ISO485/ISO485.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/iso485 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/iso485 8 | * 9 | * Product: iso485. 10 | * Date: 2021/8/30 11 | ******************************************************************************* 12 | Please connect to PortC,Pressed ButtonA :send "hello world" 13 | 请连接端口C,Pressed ButtonA :send "hello world" 14 | */ 15 | 16 | #include 17 | 18 | String str = ""; 19 | 20 | void setup() { 21 | M5.begin(true, false, true, false); 22 | M5.Lcd.drawString("ISO485", 20, 0, 2); 23 | Serial2.begin(115200, SERIAL_8N1, 14, 13); 24 | M5.Lcd.setCursor(0, 20); 25 | } 26 | 27 | void loop() { 28 | if (M5.BtnA.wasPressed()) { 29 | Serial2.write("Hello World\r\n"); 30 | Serial.println("1"); 31 | } 32 | if (Serial2.available()) { 33 | char ch = Serial2.read(); 34 | str += ch; 35 | Serial.println("2"); 36 | 37 | if (str.endsWith("\r\n")) { 38 | Serial.print(str); 39 | M5.Lcd.print(str); 40 | str = ""; 41 | } 42 | } 43 | M5.update(); 44 | } 45 | -------------------------------------------------------------------------------- /examples/Unit/JOYSTICK/JOYSTICK.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/joystick 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/joystick 8 | * 9 | * Product: JOYSTICK. 10 | * Date: 2021/8/30 11 | ******************************************************************************* 12 | Please connect to PortA,Read JOYSTICK Unit X, Y axis offset data and button 13 | status 请连接端口A,读取操纵杆单位X, Y轴偏移数据和按钮状态 14 | */ 15 | 16 | #include 17 | 18 | #define JOY_ADDR 0x52 // define Joystick I2C address. 定义摇杆的I2C地址 19 | 20 | void setup() { 21 | M5.begin(); 22 | M5.Lcd.setCursor(70, 0, 4); 23 | M5.Lcd.println(("Joystick Test")); 24 | dacWrite(25, 0); // disable the speak noise. 禁用语音噪音 25 | Wire.begin(32, 33, 400000UL); 26 | } 27 | 28 | char data[100]; 29 | void loop() { 30 | static uint8_t x_data, y_data, button_data; 31 | M5.Lcd.setCursor(100, 50, 4); 32 | M5.Lcd.printf("X:%d ", x_data); 33 | M5.Lcd.setCursor(100, 80, 4); 34 | M5.Lcd.printf("Y:%d ", y_data); 35 | M5.Lcd.setCursor(100, 110, 4); 36 | M5.Lcd.printf("B:%d ", button_data); 37 | Wire.requestFrom( 38 | JOY_ADDR, 39 | 3); // Request 3 bytes from the slave device. 向从设备请求3个字节 40 | if (Wire.available()) { // If data is received. 如果接收到数据 41 | x_data = Wire.read(); 42 | y_data = Wire.read(); 43 | button_data = Wire.read(); 44 | sprintf(data, "x:%d y:%d button:%d\n", x_data, y_data, button_data); 45 | Serial.print(data); 46 | } 47 | delay(200); 48 | } 49 | -------------------------------------------------------------------------------- /examples/Unit/KEY/KEY.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2022 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/key 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/key 8 | * 9 | * Product: Key. 按键 10 | * Date: 2022/6/1 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | uint8_t ledColor = 0; 18 | 19 | #define KEY_PIN 33 // Define Key Pin. 定义Key引脚 20 | #define DATA_PIN 32 // Define LED pin. 定义LED引脚. 21 | CRGB leds[1]; // Define the array of leds. 定义LED阵列. 22 | 23 | void LED(void *parameter); 24 | void changeLedColor(); 25 | 26 | void setup() { 27 | M5.begin(); // Init M5Stack 初始化M5Stack 28 | M5.Lcd.setTextSize(3); 29 | M5.Lcd.print(("\n UNIT-KEY Example\n\n Key State:")); 30 | 31 | pinMode(KEY_PIN, INPUT_PULLUP); // Init Key pin. 初始化Key引脚. 32 | 33 | FastLED.addLeds(leds, 34 | 1); // Init FastLED. 初始化FastLED. 35 | 36 | xTaskCreate( 37 | LED, "led", 1000, NULL, 0, 38 | NULL); // Create a thread for breathing LED. 创建一个线程用于LED呼吸灯. 39 | } 40 | 41 | void loop() { 42 | if (!digitalRead(KEY_PIN)) { // If Key was pressed. 如果按键按下. 43 | M5.Lcd.setCursor(75, 130); 44 | M5.Lcd.print(("Pressed ")); 45 | changeLedColor(); // Change LED color. 更换LED呼吸灯颜色. 46 | while (!digitalRead( 47 | KEY_PIN)) // Hold until the key released. 在松开按键前保持状态. 48 | ; 49 | } else { 50 | M5.Lcd.setCursor(75, 130); 51 | M5.Lcd.println(("Released")); 52 | } 53 | delay(100); 54 | } 55 | 56 | void LED(void *parameter) { 57 | leds[0] = CRGB::Red; 58 | for (;;) { 59 | for (int i = 0; i < 255; 60 | i++) { // Set LED brightness from 0 to 255. 设置LED亮度从0到255. 61 | FastLED.setBrightness(i); 62 | FastLED.show(); 63 | delay(5); 64 | } 65 | for (int i = 255; i > 0; 66 | i--) { // Set LED brightness from 255 to 0. 设置LED亮度从255到0. 67 | FastLED.setBrightness(i); 68 | FastLED.show(); 69 | delay(5); 70 | } 71 | } 72 | vTaskDelete(NULL); 73 | } 74 | 75 | void changeLedColor() { 76 | ledColor++; 77 | if (ledColor > 2) ledColor = 0; 78 | switch ( 79 | ledColor) { // Change LED colors between R,G,B. 在红绿蓝中切换LED颜色. 80 | case 0: 81 | leds[0] = CRGB::Red; 82 | break; 83 | case 1: 84 | leds[0] = CRGB::Green; 85 | break; 86 | case 2: 87 | leds[0] = CRGB::Blue; 88 | break; 89 | default: 90 | break; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /examples/Unit/LASER/LASER.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/laser-rx 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/laser-rx 8 | * 9 | * Product: laser-rx/laser-tx. 10 | * Date: 2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port B,LASER Unit wireless UART application: burn the 13 | program to two M5Core2 And connect LASER.TX and LASER.RX Point LASER.TX to 14 | LASER.RX and press the button on the panel to send characters to the receiver of 15 | LASER.RX. 请连接端口B,在屏幕上显示字符串。LASER 16 | Unit无线UART应用:刻录程序到两个M5Core2 并分别连接 LASER RX 和 LASER TX 17 | 然后按下LASER TX面板上的按钮,将字符发送到LASER.RX接收器。 18 | */ 19 | 20 | #include 21 | 22 | char ch; 23 | #define RX 24 | void setup() { 25 | M5.begin(); // Init M5Core2. 初始化M5Core2 26 | 27 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 28 | // txPin, bool invert) 29 | Serial2.begin(9600, SERIAL_8N1, 13, 14); 30 | pinMode(5, OUTPUT); 31 | digitalWrite(5, 1); 32 | 33 | M5.Lcd.setTextSize(4); 34 | M5.Lcd.setTextColor(GREEN); 35 | M5.Lcd.setCursor(60, 50); 36 | #ifdef RX 37 | M5.Lcd.print("LASER RX"); 38 | #elif defined TX 39 | M5.Lcd.print("LASER TX"); 40 | #else 41 | M5.Lcd.setCursor(30, 50); 42 | M5.Lcd.print("LASER TX/RX"); 43 | M5.Lcd.setCursor(50, 200); 44 | M5.Lcd.print('A'); 45 | M5.Lcd.setCursor(150, 200); 46 | M5.Lcd.print('B'); 47 | M5.Lcd.setCursor(240, 200); 48 | M5.Lcd.print('C'); 49 | #endif 50 | M5.Lcd.setCursor(0, 100); 51 | } 52 | 53 | void loop() { 54 | #ifdef RX 55 | M5.update(); 56 | if (Serial2.available()) { 57 | char ch = Serial2.read(); 58 | M5.Lcd.print(ch); 59 | } 60 | 61 | if (M5.BtnA.wasReleased()) { 62 | M5.Lcd.clear(); 63 | M5.Lcd.setCursor(0, 0); 64 | } 65 | #elif defined TX 66 | Serial2.write('A'); 67 | delay(50); 68 | #else 69 | if (M5.BtnA.wasReleased()) { 70 | ch = 'A'; 71 | Serial2.write(ch); 72 | } else if (M5.BtnB.wasReleased()) { 73 | ch = 'B'; 74 | Serial2.write(ch); 75 | } else if (M5.BtnC.wasReleased()) { 76 | ch = 'C'; 77 | Serial2.write(ch); 78 | } 79 | M5.update(); 80 | if (Serial2.available()) { 81 | char ch = Serial2.read(); 82 | M5.Lcd.print(ch); 83 | } 84 | #endif 85 | } 86 | -------------------------------------------------------------------------------- /examples/Unit/LCD_ST7789V2/LCD_ST7789V2.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/unit/lcd 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/lcd 8 | * 9 | * Product: LCD. 显示屏 10 | * Date: 2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port A,Displays a string on the screen. 13 | 请连接端口A,在屏幕上显示字符串。 14 | */ 15 | #include 16 | #include 17 | 18 | M5UnitLCD display; 19 | 20 | M5Canvas canvas(&display); 21 | 22 | static constexpr char text[] = 23 | "Hello world ! こんにちは世界! this is long long string sample. " 24 | "寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う" 25 | "寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、" 26 | "シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長" 27 | "久命の長助"; 28 | static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); 29 | int textpos = 0; 30 | int scrollstep = 2; 31 | 32 | void setup(void) { 33 | M5.begin(); 34 | display.init(); // Initialize the display. 初始化显示屏 35 | display.setRotation(3); // Rotating display. 旋转显示屏 36 | canvas.setColorDepth(1); // Set the color depth. 设置色深 37 | canvas.setFont(&fonts::lgfxJapanMinchoP_32); // Set the font. 设置字体 38 | canvas.setTextSize(2); // Set the font size. 设置字号 39 | canvas.createSprite( 40 | display.width() + 64, 41 | 72); // Create a canvas with a wide display width of +64 and a height 42 | // of 72. 创建一块宽显示屏宽度+64,高72的画布 43 | } 44 | 45 | void loop(void) { 46 | int32_t cursor_x = canvas.getCursorX() - scrollstep; 47 | if (cursor_x <= 0) { 48 | textpos = 0; 49 | cursor_x = display.width(); 50 | } 51 | 52 | canvas.setCursor(cursor_x, 0); // Set the cursor position. 设置光标的位置 53 | canvas.scroll(-scrollstep, 0); // Set the rolling. 设置滚动 54 | while (textpos < textlen && cursor_x <= display.width()) { 55 | canvas.print(text[textpos++]); 56 | cursor_x = canvas.getCursorX(); 57 | } 58 | display.waitDisplay(); 59 | canvas.pushSprite( 60 | &display, 0, 61 | (display.height() - canvas.height()) >> 62 | 1); // Displays the contents of the canvas. 显示画布上的内容 63 | } -------------------------------------------------------------------------------- /examples/Unit/LIGHT/LIGHT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/light 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/light 8 | * 9 | * Product: Light. 环境光传感器 10 | * Date: 2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port B,Use the Light Unit screen to display the current 13 | ambient lighting value 请连接端口 B ,使用Light Unit 屏幕显示当前环境光照值。 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Core2. 初始化M5Core2 20 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 21 | M5.Lcd.printf("UNIT_LIGHT EXAMPLE\n\n"); 22 | M5.Lcd.println("Analog:"); 23 | M5.Lcd.println("Digital:"); 24 | pinMode(26, INPUT); // Set pin 26 as input mode. 设置引脚26为输入模式 25 | } 26 | 27 | void loop() { 28 | static uint16_t digitalRead_value = 0, analogRead_value = 0; 29 | analogRead_value = analogRead(36); // Store the analog quantity read from 30 | // pin 36. 将36号引脚读取到的模拟量存储 31 | digitalRead_value = digitalRead( 32 | 26); // Store the number read from pin 26. 将26号引脚读取到的数字量存储 33 | M5.Lcd.setCursor(90, 30); 34 | M5.Lcd.printf("%d\n", analogRead_value); 35 | M5.Lcd.setCursor(90, 50); 36 | M5.Lcd.printf("%d\n", digitalRead_value); 37 | delay(10); 38 | } 39 | -------------------------------------------------------------------------------- /examples/Unit/LIMIT/LIMIT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2022 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/limit 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/limit 8 | * 9 | * Product: Limit. 10 | * Date: 2022/6/1 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | 16 | #define KEY_PIN 36 // Define Limit Pin. 定义Limit连接引脚 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Stack 初始化M5Stack 20 | M5.Lcd.setTextSize(4); 21 | M5.Lcd.print(("\n UNIT-LIMIT\n Example")); 22 | 23 | pinMode(KEY_PIN, INPUT_PULLUP); // Init Limit pin. 初始化Limit引脚. 24 | } 25 | 26 | void loop() { 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/NCIR_MLX90614/NCIR_MLX90614.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/ncir 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/ncir 8 | * 9 | * Product: ncir. 单点红外测温传感器 10 | * Date: 2021/8/27 11 | ******************************************************************************* 12 | Please connect to Port A,Use NCIR Unit to measure the temperature without 13 | contact and display the value on the screen. 14 | 请连接端口A,使用NCIR单元无接触测量温度,并在屏幕上显示。 15 | */ 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); 20 | Wire.begin(); 21 | M5.Lcd.setTextSize(3); 22 | M5.Lcd.setCursor(120, 0); 23 | M5.Lcd.print("NCIR"); 24 | } 25 | 26 | void loop() { 27 | static uint16_t result; 28 | static float temperature; 29 | Wire.beginTransmission(0x5A); // Send Initial Signal and I2C Bus Address 30 | // 发送初始信号和I2C总线地址 31 | Wire.write(0x07); // Send data only once and add one address automatically. 32 | // 只发送一次数据,并自动添加一个地址。 33 | Wire.endTransmission(false); // Stop signal 停止信号 34 | Wire.requestFrom( 35 | 0x5A, 36 | 2); // Get 2 consecutive data from 0x5A, and the data is stored only. 37 | // 从0x5A中获取2个连续的数据,并且只存储这些数据。 38 | result = Wire.read(); // Receive DATA 接收数据 39 | result |= Wire.read() << 8; // Receive DATA 接收数据 40 | 41 | temperature = result * 0.02 - 273.15; 42 | M5.Lcd.setCursor(70, 100); 43 | M5.Lcd.printf("Temp:%.3f", temperature); 44 | delay(500); 45 | } 46 | -------------------------------------------------------------------------------- /examples/Unit/OLED_SH1107/OLED_SH1107.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/oled 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/oled 8 | * 9 | * Product: OLED. 显示屏 10 | * Date: 2021/8/31 11 | ******************************************************************************* 12 | Please connect to Port A,Displays a string on the screen. 13 | 请连接端口A,在屏幕上显示字符串。 14 | */ 15 | #include 16 | 17 | M5UnitOLED display; 18 | 19 | M5Canvas canvas(&display); 20 | 21 | static constexpr char text[] = 22 | "Hello world ! こんにちは世界! this is long long string sample. " 23 | "寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う" 24 | "寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、" 25 | "シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長" 26 | "久命の長助"; 27 | static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); 28 | int textpos = 0; 29 | int scrollstep = 2; 30 | 31 | void setup(void) { 32 | display.init(); // Initialize the display. 初始化显示屏 33 | display.setRotation(2); // Rotating display. 旋转显示屏 34 | canvas.setColorDepth(1); // Set the color depth. 设置色深 35 | canvas.setFont(&fonts::lgfxJapanMinchoP_32); // Set the font. 设置字体 36 | canvas.setTextWrap(false); 37 | canvas.setTextSize(2); // Set the font size. 设置字号 38 | canvas.createSprite( 39 | display.width() + 64, 40 | 72); // Create a canvas with a wide display width of +64 and a height 41 | // of 72. 创建一块宽显示屏宽度+64,高72的画布 42 | } 43 | 44 | void loop(void) { 45 | int32_t cursor_x = canvas.getCursorX() - scrollstep; 46 | if (cursor_x <= 0) { 47 | textpos = 0; 48 | cursor_x = display.width(); 49 | } 50 | 51 | canvas.setCursor(cursor_x, 0); // Set the cursor position. 设置光标的位置 52 | canvas.scroll(-scrollstep, 0); // Set the rolling. 设置滚动 53 | while (textpos < textlen && cursor_x <= display.width()) { 54 | canvas.print(text[textpos++]); 55 | cursor_x = canvas.getCursorX(); 56 | } 57 | display.waitDisplay(); 58 | canvas.pushSprite( 59 | &display, 0, 60 | (display.height() - canvas.height()) >> 61 | 1); // Displays the contents of the canvas. 显示画布上的内容 62 | } -------------------------------------------------------------------------------- /examples/Unit/OP90.180_ITR9606/OP90.180_ITR9606.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/op90 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/op90 8 | * 9 | * Product: OP 180/90. 非接触式光电限位开关 10 | * Date: 2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port B,Detect the current OP 90/180 Unit Photoelectric 13 | switch status. 请连接端口B,检测当前OP 90/180单元光电开关状态。 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Core2. 初始化M5Core2 20 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 21 | M5.Lcd.setCursor(80, 22 | 10); // Set the cursor at (80,10). 将光标设置在(80,10)处 23 | M5.Lcd.println("90/180 OPTICAL"); 24 | pinMode(36, 25 | INPUT_PULLUP); // Set pin 36 to input pull-up mode. 26 | // 设置36号引脚为输入上拉模式 27 | } 28 | 29 | void loop() { 30 | M5.Lcd.setCursor(80, 120); 31 | M5.Lcd.printf( 32 | "IR Receive: %d", 33 | digitalRead(36)); // Output the value of pin 36. 输出36号引脚的值 34 | } 35 | -------------------------------------------------------------------------------- /examples/Unit/PIR/PIR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/pir 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/pir 8 | * 9 | * Product: PIR. 人体红外 10 | * Date: 2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port B,Human body detection using PIR Unit. 13 | 请连接端口B,使用PIR Unit进行人体检测。 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Core2. 初始化 M5Core2 20 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 21 | M5.Lcd.println("PIR example"); 22 | M5.Lcd.setCursor(0, 23 | 25); // Position the cursor at (0,25). 将光标固定在(0,25) 24 | M5.Lcd.println("Status: \nValue: "); 25 | pinMode(36, INPUT); // Set pin 36 to input mode. 设置36号引脚为输入模式 26 | } 27 | 28 | void loop() { 29 | M5.Lcd.fillRect(90, 25, 180, 50, 30 | BLACK); // Draw a black rectangle 180 by 50 at (90,25). 31 | // 在(90,25)处画一个宽180高50的黑的矩形 32 | if (digitalRead(36) == 33 | 1) { // If pin 36 reads a value of 1. 如果36号引脚的读取到的值为1 34 | M5.Lcd.setCursor(95, 25); 35 | M5.Lcd.print("Sensing"); 36 | M5.Lcd.setCursor(95, 45); 37 | M5.Lcd.print("1"); 38 | } else { 39 | M5.Lcd.setCursor(95, 25); 40 | M5.Lcd.print("Not Sensed"); 41 | M5.Lcd.setCursor(95, 45); 42 | M5.Lcd.print("0"); 43 | } 44 | delay(500); 45 | } -------------------------------------------------------------------------------- /examples/Unit/PaHUB_TCA9548A/PaHUB_TCA9548A.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/pahub 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/pahub 8 | * 9 | * Product: PaHUB. 10 | * Date: 2021/8/31 11 | ******************************************************************************* 12 | Please connect to Port A, Use PaHUB Unit to expand multiple I2C devices and 13 | scan the I2C addresses of the slave devices in order. 请连接端口A, 使用PaHUB 14 | Unit扩展多个I2C设备,并依次扫描从设备的I2C地址。 15 | */ 16 | 17 | #include 18 | #include "ClosedCube_TCA9548A.h" 19 | 20 | #define FRONT 2 21 | 22 | #define X_LOCAL 100 23 | #define Y_LOCAL 35 24 | #define X_OFFSET 160 25 | #define Y_OFFSET 34 26 | 27 | #define PaHub_I2C_ADDRESS 0x70 28 | 29 | ClosedCube::Wired::TCA9548A tca9548a; 30 | 31 | void setup() { 32 | M5.begin(); 33 | Wire.begin(); 34 | tca9548a.address(PaHub_I2C_ADDRESS); // Set the I2C address. 设置I2C地址 35 | M5.Lcd.setTextFont(4); 36 | M5.Lcd.setCursor(70, 0, 4); 37 | M5.Lcd.setTextColor(YELLOW, TFT_BLACK); 38 | M5.Lcd.println(("PaHUB Example")); 39 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 40 | } 41 | 42 | void loop() { 43 | uint8_t returnCode = 0; 44 | uint8_t address; 45 | for (uint8_t channel = 0; channel < TCA9548A_MAX_CHANNELS; channel++) { 46 | M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT); 47 | M5.Lcd.printf( 48 | " "); 49 | M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT); 50 | M5.Lcd.printf("CH%d : ", channel); 51 | returnCode = tca9548a.selectChannel(channel); 52 | if (returnCode == 0) { 53 | for (address = 0x01; address < 0x7F; address++) { 54 | Wire.beginTransmission(address); 55 | returnCode = Wire.endTransmission(); 56 | if (returnCode == 0) { 57 | Serial.print("I2C device = "); 58 | M5.Lcd.printf("0X%X ", address); 59 | } 60 | } 61 | } 62 | delay(200); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /examples/Unit/PbHUB/PbHUB/PbHUB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/pbhub 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/pbhub 8 | * 9 | * Product: PbHub. 10 | * Date: 2021/8/16 11 | ******************************************************************************* 12 | Use Pbhub to read the analog input value of the slave device, or drive 13 | multiple sets of RGB LEDs. 使用Pbhub来读取从属设备的模拟输入值,或驱动多组RGB 14 | LED。 15 | */ 16 | 17 | #include 18 | #include "porthub.h" 19 | 20 | #define X_OFFSET 10 21 | #define Y_OFFSET 18 22 | 23 | PortHub porthub; 24 | uint8_t HUB_ADDR[6] = {HUB1_ADDR, HUB2_ADDR, HUB3_ADDR, 25 | HUB4_ADDR, HUB5_ADDR, HUB6_ADDR}; 26 | 27 | void setup() { 28 | M5.begin(true, false, true); 29 | porthub.begin(); 30 | M5.Lcd.clear(BLACK); 31 | M5.Lcd.setTextColor(WHITE); 32 | M5.Lcd.setTextSize(4); 33 | } 34 | 35 | void loop() { 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 | } 48 | -------------------------------------------------------------------------------- /examples/Unit/PbHUB/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 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/rfid 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rfid 8 | * 9 | * Product: RFID. 10 | * Date: 2021/8/19 11 | ******************************************************************************* 12 | Please connect to Port A,Use the RFID Unit to read the Fudan card ID and 13 | display the ID on the screen. 请连接端口A,使用RFID Unit 读取ID卡并在屏幕上显示。 14 | */ 15 | 16 | #include 17 | #include "MFRC522_I2C.h" 18 | 19 | MFRC522 mfrc522(0x28); // Create MFRC522 instance. 创建MFRC522实例 20 | 21 | void setup() { 22 | M5.begin(); // Init M5Core2. 初始化M5Core2 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 | M5.Lcd.setCursor(40, 47); 33 | if (!mfrc522.PICC_IsNewCardPresent() || 34 | !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++) { 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_SK6812/RGB_SK6812.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/rgb 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rgb 8 | * 9 | * Product: RGB. 多彩灯 10 | * Date: 2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port B,Control RGB Unit to scroll through three colors of 13 | red, green and blue 请连接端口B,控制RGB单元滚动红、绿、蓝三种颜色. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #define PIN 26 // 定义NeoPixel的控制引脚 20 | #define NUMPIXELS 3 // 定义NeoPixel控制灯灯数量 21 | 22 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel( 23 | NUMPIXELS, PIN, 24 | NEO_GRB + NEO_KHZ800); // set number of LEDs, pin number, LED type. 25 | // 设置灯的数量,控制引脚编号,灯灯类型 26 | 27 | void setup() { 28 | M5.begin(); // Init M5Core2. 初始化 M5Core2 29 | pixels.begin(); // Init the NeoPixel library. 初始化NeoPixel库 30 | M5.Lcd.println(("RGB Example")); 31 | } 32 | 33 | int i = 0, j = 1, k = 2; 34 | 35 | void loop() { 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 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/rs485 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rs485 8 | * 9 | * Product: rs485. 10 | * Date: 2021/8/30 11 | ******************************************************************************* 12 | Please connect to Port C,Use RS485 Unit for serial communication, continuously 13 | send "Hello", and display the received content on the screen. 请连接端口 14 | C,采用RS485单元串行通信,连续发送“Hello”,接收到的内容显示在屏幕上。 15 | */ 16 | 17 | #include 18 | #define RX_PIN 13 19 | #define TX_PIN 14 20 | 21 | #define X_OFF 160 22 | #define Y_OFF 30 23 | 24 | int i = 0, s = 0; 25 | 26 | void setup() { 27 | M5.begin(); 28 | M5.Lcd.setTextSize(1); 29 | M5.Lcd.drawString("RS485 Unit test", 75, 3, 4); 30 | Serial2.begin( 31 | 115200, SERIAL_8N1, RX_PIN, 32 | TX_PIN); // Set the baud rate of serial port 2 to 115200,8 data bits, 33 | // no parity bits, and 1 stop bit, and set RX to 13 and TX 34 | // to 14. 35 | // 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX为13,TX为14 36 | } 37 | 38 | void loop() { 39 | Serial2.write("Hello\n"); 40 | 41 | if (Serial2.available()) { 42 | M5.Lcd.print(char(Serial2.read())); 43 | } 44 | delay(100); 45 | } 46 | -------------------------------------------------------------------------------- /examples/Unit/THERMAL_MLX90640/MLX90640_API.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 _MLX640_API_H_ 18 | #define _MLX640_API_H_ 19 | 20 | #include 21 | 22 | #define SCALEALPHA 0.000001 23 | 24 | typedef struct { 25 | int16_t kVdd; 26 | int16_t vdd25; 27 | float KvPTAT; 28 | float KtPTAT; 29 | uint16_t vPTAT25; 30 | float alphaPTAT; 31 | int16_t gainEE; 32 | float tgc; 33 | float cpKv; 34 | float cpKta; 35 | uint8_t resolutionEE; 36 | uint8_t calibrationModeEE; 37 | float KsTa; 38 | float ksTo[5]; 39 | int16_t ct[5]; 40 | uint16_t alpha[768]; 41 | uint8_t alphaScale; 42 | int16_t offset[768]; 43 | int8_t kta[768]; 44 | uint8_t ktaScale; 45 | int8_t kv[768]; 46 | uint8_t kvScale; 47 | float cpAlpha[2]; 48 | int16_t cpOffset[2]; 49 | float ilChessC[3]; 50 | uint16_t brokenPixels[5]; 51 | uint16_t outlierPixels[5]; 52 | } paramsMLX90640; 53 | 54 | int MLX90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData); 55 | int MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData); 56 | int MLX90640_ExtractParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); 57 | float MLX90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *params); 58 | float MLX90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params); 59 | void MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *params, 60 | float *result); 61 | void MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *params, 62 | float emissivity, float tr, float *result); 63 | int MLX90640_SetResolution(uint8_t slaveAddr, uint8_t resolution); 64 | int MLX90640_GetCurResolution(uint8_t slaveAddr); 65 | int MLX90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate); 66 | int MLX90640_GetRefreshRate(uint8_t slaveAddr); 67 | int MLX90640_GetSubPageNumber(uint16_t *frameData); 68 | int MLX90640_GetCurMode(uint8_t slaveAddr); 69 | int MLX90640_SetInterleavedMode(uint8_t slaveAddr); 70 | int MLX90640_SetChessMode(uint8_t slaveAddr); 71 | void MLX90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, 72 | paramsMLX90640 *params); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /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 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/trace 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/trace 8 | * 9 | * Product: TRACE. 10 | * Date: 2021/9/1 11 | ******************************************************************************* 12 | Please connect to PORT-A, Read the status of the four line-tracking sensors of 13 | TRACE Unit and output them through UART. 请连接端口A,读取TRACE 14 | Unit四个线跟踪传感器的状态,并通过UART输出。 15 | */ 16 | 17 | #include 18 | 19 | // #define VALUE_SPLIT 20 | 21 | uint8_t value; 22 | int SensorArray[4] = {0}; 23 | 24 | void SensorStatus(void) { 25 | Wire.beginTransmission( 26 | 0x5a); // The data transfer to 0x5A begins. 开始向0x5a传输数据 27 | Wire.write(0x00); 28 | Wire.endTransmission(); // End the data transmission.结束数据传输 29 | Wire.requestFrom(0x5a, 1); // Request a byte from 0x5a. 向0x5a请求一个字节 30 | while (Wire.available()) { // If data is received. 如果数据被接收到 31 | value = Wire.read(); 32 | } 33 | M5.Lcd.print(" value = "); 34 | M5.Lcd.println(value, HEX); 35 | #ifdef VALUE_SPLIT 36 | SensorArray[3] = (value & 0x08) >> 3; 37 | SensorArray[2] = (value & 0x04) >> 2; 38 | SensorArray[1] = (value & 0x02) >> 1; 39 | SensorArray[0] = (value & 0x01) >> 0; 40 | M5.Lcd.println(" After splitting... "); 41 | M5.Lcd.print(" SensorArray[0] = "); 42 | M5.Lcd.println(SensorArray[0]); 43 | M5.Lcd.print(" SensorArray[1] = "); 44 | M5.Lcd.println(SensorArray[1]); 45 | M5.Lcd.print(" SensorArray[2] = "); 46 | M5.Lcd.println(SensorArray[2]); 47 | M5.Lcd.print(" SensorArray[3] = "); 48 | M5.Lcd.println(SensorArray[3]); 49 | #endif 50 | } 51 | 52 | void setup() { 53 | M5.begin(); 54 | 55 | Wire.begin(); 56 | M5.Lcd.setTextColor(YELLOW); 57 | M5.Lcd.setTextSize(2); 58 | M5.Lcd.setCursor(80, 0); 59 | M5.Lcd.println("TRACE example"); 60 | M5.Lcd.setTextColor(WHITE); 61 | } 62 | 63 | void loop() { 64 | M5.Lcd.fillRect(0, 20, 320, 180, BLACK); 65 | M5.Lcd.setCursor(100, 70); 66 | SensorStatus(); 67 | delay(100); 68 | } -------------------------------------------------------------------------------- /examples/Unit/TVOC/TVOC.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/tvoc 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/tvoc 8 | * 9 | * Product: TVOC/eCO2. 10 | * Date: 2021/8/26 11 | ******************************************************************************* 12 | Description: The screen will display TVOC and CO2. 屏幕将显示TVOC和CO2。 13 | Note: SGP30 needs 15 seconds to initialize calibration after power on. 14 | SGP30开机后需要15秒进行初始校准。 15 | */ 16 | 17 | #include 18 | #include "Adafruit_SGP30.h" 19 | 20 | Adafruit_SGP30 sgp; 21 | long last_millis = 0; 22 | 23 | void setup() { 24 | M5.begin(true, false, true, true); 25 | M5.Lcd.setTextSize(2); 26 | M5.Lcd.setCursor(80, 0); 27 | M5.Lcd.println("TVOC TEST"); 28 | if (!sgp.begin()) { // Init the sensor. 初始化传感器 29 | M5.Lcd.println("Sensor not found"); 30 | while (1) 31 | ; 32 | } 33 | M5.Lcd.setCursor(0, 80); 34 | M5.Lcd.println("\nInitialization..."); 35 | } 36 | 37 | void loop() { 38 | static int i = 15; 39 | while (i > 0) { 40 | if (millis() - last_millis > 1000) { 41 | last_millis = millis(); 42 | i--; 43 | M5.Lcd.fillRect(20, 120, 60, 30, BLACK); 44 | M5.Lcd.drawNumber(i, 20, 120, 2); 45 | } 46 | } 47 | M5.Lcd.fillRect(0, 80, 90, 100, BLACK); 48 | 49 | if (!sgp.IAQmeasure()) { // Commands the sensor to take a single eCO2/VOC 50 | // measurement. 命令传感器进行一次eCO2/VOC测量 51 | Serial.println("Measurement failed"); 52 | return; 53 | } 54 | M5.Lcd.fillRect(100, 40, 220, 90, TFT_BLACK); 55 | M5.Lcd.setCursor(0, 50); 56 | M5.Lcd.printf("TVOC:%d ppb\n", sgp.TVOC); 57 | M5.Lcd.printf("eCO2:%d ppm\n", sgp.eCO2); 58 | delay(500); 59 | } 60 | -------------------------------------------------------------------------------- /examples/Unit/ULTRA/ULTRA.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | TFT_eSprite Terminalbuff = TFT_eSprite(&M5.Lcd); 4 | 5 | void setup() { 6 | // put your setup code here, to run once: 7 | M5.begin(); 8 | 9 | Wire.begin(32, 33); 10 | 11 | Terminalbuff.createSprite(160, 80); 12 | Terminalbuff.fillRect(80, 20, 160, 80, BLACK); 13 | 14 | Terminalbuff.pushSprite(80, 20); 15 | Terminalbuff.setTextFont(4); 16 | M5.Lcd.setCursor(105, 0, 4); 17 | 18 | M5.Lcd.print("Ultrasonic"); 19 | } 20 | 21 | float readEUS() { 22 | uint32_t data; 23 | Wire.beginTransmission(0x57); 24 | Wire.write(0x01); 25 | Wire.endTransmission(); 26 | delay(120); 27 | Wire.requestFrom(0x57, 3); 28 | data = Wire.read(); 29 | data <<= 8; 30 | data |= Wire.read(); 31 | data <<= 8; 32 | data |= Wire.read(); 33 | return float(data) / 1000; 34 | } 35 | 36 | void loop() { 37 | float newvalue = 0; 38 | 39 | while (1) { 40 | newvalue = readEUS(); 41 | 42 | Terminalbuff.fillRect(80, 20, 160, 80, BLACK); 43 | Terminalbuff.setCursor(30, 50); 44 | 45 | if ((newvalue < 1500) && (newvalue > 20)) { 46 | Terminalbuff.printf("%.2fmm", newvalue); 47 | Terminalbuff.pushSprite(80, 20); 48 | } 49 | delay(100); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/Unit/VIBRATOR/VIBRATOR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/vibrator 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/vibrator 8 | * 9 | * Product: Vibrator. 震动电机 10 | * Date: 2021/8/19 11 | ******************************************************************************* 12 | Please connect to Port B,Adjust the speed of VIBRATOR Unit through PWM. 13 | 请连接端口B,通过PWM调节Vibrator Unit的速度。 14 | */ 15 | 16 | #include 17 | 18 | #define motor_pin 26 19 | int freq = 10000; 20 | int ledChannel = 0; 21 | int resolution = 10; 22 | void setup() { 23 | M5.begin(); // Init M5Core2. 初始化M5Core2 24 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 25 | M5.Lcd.setCursor(110, 26 | 10); // Set the cursor at (110,10). 将光标设置在(110,10)处 27 | M5.Lcd.println("Vibrator"); 28 | ledcSetup( 29 | ledChannel, freq, 30 | resolution); // Sets the frequency and number of counts corresponding 31 | // to the channel. 设置通道对应的频率和计数位数 32 | ledcAttachPin( 33 | motor_pin, 34 | ledChannel); // Binds the specified channel to the specified I/O port 35 | // for output. 将指定通道绑定到指定 IO 口上以实现输出 36 | } 37 | 38 | void loop() { 39 | ledcWrite(ledChannel, 512); // Output PWM. 输出PWM 40 | delay(1000); 41 | ledcWrite(ledChannel, 0); 42 | delay(1000); 43 | } 44 | -------------------------------------------------------------------------------- /examples/Unit/WEIGHT_HX711/WEIGHT_HX711.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5Core2 sample source code 5 | * 配套 M5Core2 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/weight 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/weight 8 | * 9 | * Product: Weight. 10 | * Date: 2021/8/20 11 | ******************************************************************************* 12 | Please connect to Port B,Use WEIGHT Unit to read the analog value returned by 13 | the pressure sensor, convert it into intuitive weight data and send it to 14 | M5Core,Press ButtonA to calibrate 请连接端口B,使用WEIGHT 15 | Unit读取压力传感器返回的模拟值,将其转换为直观的重量数据,发送到M5Core,按下按钮A进行校准 16 | */ 17 | 18 | #include 19 | #include "HX711.h" 20 | 21 | // HX711 related pin Settings. HX711 相关引脚设置 22 | #define LOADCELL_DOUT_PIN 36 23 | #define LOADCELL_SCK_PIN 26 24 | 25 | HX711 scale; 26 | const long LOADCELL_OFFSET = 50682624; 27 | const long LOADCELL_DIVIDER = 5895655; 28 | 29 | void setup() { 30 | M5.begin(); // Init M5Core2. 初始化M5Core2 31 | M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 32 | 33 | scale.begin( 34 | LOADCELL_DOUT_PIN, 35 | LOADCELL_SCK_PIN); // Initialize library with data output pin, clock 36 | // input pin and gain factor. 37 | // 初始化库的数据输出引脚,时钟输入引脚和增益因子。 38 | scale.set_scale( 39 | LOADCELL_DIVIDER); // set the SCALE value this value is used to convert 40 | // the raw data to measure units. 41 | // 设置SCALE值,该值用于将原始数据转换为度量单位 42 | scale.set_offset(LOADCELL_OFFSET); // Set the tare weight. 设置皮重 43 | scale.set_scale(61.2f); // this value is obtained by calibrating the scale 44 | // with known weights; see the README for details. 45 | // 这个值是通过校正已知权重的刻度而得到的 46 | scale.tare(); // reset the scale to 0. 将比例重置为0 47 | M5.Lcd.print(" Weight Unit\nConnect the Weight Unit to PortB"); 48 | M5.Lcd.setCursor(20, 210, 1); 49 | M5.Lcd.print("Calibration"); 50 | } 51 | 52 | void loop() { 53 | M5.update(); 54 | if (M5.BtnA.wasPressed()) { // If button A is pressed. 如果按键A按下 55 | scale.set_offset(LOADCELL_OFFSET + scale.read()); 56 | scale.set_scale(61.2f); 57 | scale.tare(); 58 | } 59 | int weight = scale.get_units(5); 60 | M5.Lcd.fillRect(75, 80, 320, 80, BLACK); 61 | M5.Lcd.setCursor(75, 80); 62 | M5.Lcd.printf("Weight:%1d g", weight); 63 | } -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "M5Core2", 3 | "description": "An ESP32 Arduino board", 4 | "keywords": "M5Stack Core M5Core2", 5 | "authors": { 6 | "name": "M5Stack", 7 | "url": "http://www.m5stack.com" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/m5stack/M5Core2.git" 12 | }, 13 | "version": "0.2.0", 14 | "frameworks": "arduino", 15 | "platforms": "espressif32", 16 | "headers": "M5Core2.h" 17 | } 18 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=M5Core2 2 | version=0.2.0 3 | author=M5Stack 4 | maintainer=M5Stack 5 | sentence=Library for M5Stack Core2 development kit 6 | paragraph=See more on https://docs.m5stack.com/en/core/core2 7 | category=Device Control 8 | url=https://github.com/m5stack/M5Core2.git 9 | architectures=esp32 10 | includes=M5Core2.h 11 | depends=M5Family,M5Module-4Relay,Module_GRBL_13.2,Ethernet2 12 | -------------------------------------------------------------------------------- /src/AXP192.h: -------------------------------------------------------------------------------- 1 | #ifndef __AXP192_H__ 2 | #define __AXP192_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define AXP192_ADDR 0X34 8 | 9 | class AXP192 { 10 | public: 11 | enum CHGCurrent { 12 | kCHG_100mA = 0, 13 | kCHG_190mA, 14 | kCHG_280mA, 15 | kCHG_360mA, 16 | kCHG_450mA, 17 | kCHG_550mA, 18 | kCHG_630mA, 19 | kCHG_700mA, 20 | kCHG_780mA, 21 | kCHG_880mA, 22 | kCHG_960mA, 23 | kCHG_1000mA, 24 | kCHG_1080mA, 25 | kCHG_1160mA, 26 | kCHG_1240mA, 27 | kCHG_1320mA, 28 | }; 29 | 30 | AXP192(); 31 | void begin(); 32 | // Will be deprecated 33 | void ScreenBreath(int brightness); 34 | bool GetBatState(); 35 | 36 | void EnableCoulombcounter(void); 37 | void DisableCoulombcounter(void); 38 | void StopCoulombcounter(void); 39 | void ClearCoulombcounter(void); 40 | uint32_t GetCoulombchargeData(void); 41 | uint32_t GetCoulombdischargeData(void); 42 | float GetCoulombData(void); 43 | float GetBatteryLevel(void); 44 | void PowerOff(void); 45 | void SetAdcState(bool state); 46 | // -- sleep 47 | void PrepareToSleep(void); 48 | void RestoreFromLightSleep(void); 49 | void DeepSleep(uint64_t time_in_us = 0); 50 | void LightSleep(uint64_t time_in_us = 0); 51 | uint8_t GetWarningLeve(void); 52 | 53 | // void SetChargeVoltage( uint8_t ); 54 | // void SetChargeCurrent( uint8_t ); 55 | float GetBatVoltage(); 56 | float GetBatCurrent(); 57 | float GetVinVoltage(); 58 | float GetVinCurrent(); 59 | float GetVBusVoltage(); 60 | float GetVBusCurrent(); 61 | float GetTempInAXP192(); 62 | float GetBatPower(); 63 | float GetBatChargeCurrent(); 64 | float GetAPSVoltage(); 65 | float GetBatCoulombInput(); 66 | float GetBatCoulombOut(); 67 | uint8_t GetWarningLevel(void); 68 | void SetCoulombClear(); 69 | void SetLDO2(bool State); 70 | void SetDCDC3(bool State); 71 | 72 | uint8_t AXPInState(); 73 | bool isACIN(); 74 | bool isCharging(); 75 | bool isVBUS(); 76 | 77 | void SetLDOVoltage(uint8_t number, uint16_t voltage); 78 | void SetDCVoltage(uint8_t number, uint16_t voltage); 79 | void SetESPVoltage(uint16_t voltage); 80 | void SetLcdVoltage(uint16_t voltage); 81 | void SetLDOEnable(uint8_t number, bool state); 82 | void SetLCDRSet(bool state); 83 | void SetBusPowerMode(uint8_t state); 84 | void SetLed(uint8_t state); 85 | void SetSpkEnable(uint8_t state); 86 | void SetCHGCurrent(uint8_t state); 87 | void SetPeripherialsPower(uint8_t state); 88 | 89 | /// set battery charge enable. 90 | /// @param enable true=enable / false=disable 91 | void SetBatteryCharge(bool enable); 92 | }; 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /src/Fonts/ASC16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5Core2/0134dd3a38cfd335a1ec39da2c149f88baf54326/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 | uint8_t smooth_bpp; 38 | #endif 39 | } GFXfont; 40 | 41 | #endif // LOAD_GFXFF 42 | 43 | #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/M5Core2/0134dd3a38cfd335a1ec39da2c149f88baf54326/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/M5Core2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) M5Core2. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full 3 | // license information. 4 | 5 | #include "M5Core2.h" 6 | 7 | M5Core2::M5Core2() : isInited(0) { 8 | } 9 | 10 | void M5Core2::begin(bool LCDEnable, bool SDEnable, bool SerialEnable, 11 | bool I2CEnable, mbus_mode_t mode, bool SpeakerEnable) { 12 | // Correct init once 13 | if (isInited == true) { 14 | return; 15 | } else { 16 | isInited = true; 17 | } 18 | 19 | // UART 20 | if (SerialEnable == true) { 21 | Serial.begin(115200); 22 | Serial.flush(); 23 | delay(50); 24 | Serial.print("M5Core2 initializing..."); 25 | } 26 | 27 | // I2C init 28 | if (I2CEnable == true) { 29 | Wire.begin(32, 33); 30 | } 31 | 32 | Axp.begin(mode); 33 | 34 | // LCD INIT 35 | if (LCDEnable == true) { 36 | Lcd.begin(); 37 | } 38 | 39 | // Touch init 40 | Touch.begin(); // Touch begin after AXP begin. (Reset at the start of AXP) 41 | 42 | // TF Card 43 | if (SDEnable == true) { 44 | SD.begin(TFCARD_CS_PIN, SPI, 40000000); 45 | } 46 | 47 | // TONE 48 | 49 | if (SpeakerEnable == true) { 50 | Spk.begin(); 51 | } 52 | 53 | if (SerialEnable == true) { 54 | Serial.println("OK"); 55 | } 56 | 57 | Rtc.begin(); 58 | } 59 | 60 | void M5Core2::update() { 61 | Touch.update(); 62 | Buttons.update(); 63 | yield(); 64 | } 65 | 66 | void M5Core2::shutdown() { 67 | Axp.PowerOff(); 68 | } 69 | 70 | int M5Core2::shutdown(int seconds) { 71 | Rtc.clearIRQ(); 72 | Rtc.SetAlarmIRQ(seconds); 73 | delay(10); 74 | Axp.PowerOff(); 75 | return 0; 76 | } 77 | 78 | int M5Core2::shutdown(const RTC_TimeTypeDef &RTC_TimeStruct) { 79 | Rtc.clearIRQ(); 80 | Rtc.SetAlarmIRQ(RTC_TimeStruct); 81 | delay(10); 82 | Axp.PowerOff(); 83 | return 0; 84 | } 85 | 86 | int M5Core2::shutdown(const RTC_DateTypeDef &RTC_DateStruct, 87 | const RTC_TimeTypeDef &RTC_TimeStruct) { 88 | Rtc.clearIRQ(); 89 | Rtc.SetAlarmIRQ(RTC_DateStruct, RTC_TimeStruct); 90 | delay(10); 91 | Axp.PowerOff(); 92 | return 0; 93 | } 94 | 95 | M5Core2 M5; 96 | -------------------------------------------------------------------------------- /src/M5Core2.h: -------------------------------------------------------------------------------- 1 | #ifndef _M5Core2_H_ 2 | #define _M5Core2_H_ 3 | 4 | #if defined(ESP32) 5 | 6 | #include 7 | #include 8 | #include 9 | #include "FS.h" 10 | #include "SD.h" 11 | 12 | #include "M5Display.h" 13 | #include "M5Touch.h" // M5Touch 14 | #include "utility/M5Button.h" // M5Buttons, M5Events, Button, Gesture 15 | #include "utility/Config.h" 16 | #include "utility/CommUtil.h" 17 | #include "utility/MPU6886.h" 18 | #include "Speaker.h" 19 | #include "AXP.h" 20 | #include "RTC.h" 21 | 22 | class M5Core2 { 23 | public: 24 | M5Core2(); 25 | [[deprecated("It is recommended to use M5Unified Lib")]] 26 | 27 | void begin(bool LCDEnable = true, bool SDEnable = true, 28 | bool SerialEnable = true, bool I2CEnable = false, 29 | mbus_mode_t mode = kMBusModeOutput, bool SpeakerEnable = false); 30 | void update(); 31 | 32 | void shutdown(); 33 | int shutdown(int seconds); 34 | int shutdown(const RTC_TimeTypeDef &RTC_TimeStruct); 35 | int shutdown(const RTC_DateTypeDef &RTC_DateStruct, 36 | const RTC_TimeTypeDef &RTC_TimeStruct); 37 | 38 | // LCD 39 | M5Display Lcd; 40 | 41 | // Power 42 | AXP Axp; 43 | 44 | // Touch 45 | M5Touch Touch; 46 | 47 | // Buttons (global button and gesture functions) 48 | M5Buttons Buttons; 49 | 50 | // Default "button" that gets events where there is no button. 51 | Button background = Button(0, 0, TOUCH_W, TOUCH_H, true, "background"); 52 | 53 | // Touch version of the buttons on older M5stack cores, below screen 54 | Button BtnA = Button(10, 240, 110, 40, true, "BtnA"); 55 | Button BtnB = Button(130, 240, 70, 40, true, "BtnB"); 56 | Button BtnC = Button(230, 240, 80, 40, true, "BtnC"); 57 | 58 | MPU6886 IMU; 59 | 60 | // I2C 61 | CommUtil I2C; 62 | 63 | RTC Rtc; 64 | 65 | Speaker Spk; 66 | 67 | /** 68 | * Functions have been moved to Power class for compatibility. 69 | * These will be removed in a future release. 70 | */ 71 | void setPowerBoostKeepOn(bool en) __attribute__((deprecated)); 72 | void setWakeupButton(uint8_t button) __attribute__((deprecated)); 73 | void powerOFF() __attribute__((deprecated)); 74 | 75 | private: 76 | bool isInited; 77 | }; 78 | 79 | extern M5Core2 M5; 80 | #define m5 M5 81 | #define lcd Lcd 82 | #else 83 | #error "This library only supports boards with ESP32 processor." 84 | #endif 85 | #endif 86 | -------------------------------------------------------------------------------- /src/RTC.h: -------------------------------------------------------------------------------- 1 | #ifndef __RTC_H__ 2 | #define __RTC_H__ 3 | 4 | #include 5 | 6 | typedef struct { 7 | int8_t Hours; 8 | int8_t Minutes; 9 | int8_t Seconds; 10 | } RTC_TimeTypeDef; 11 | 12 | typedef struct { 13 | int8_t WeekDay; 14 | int8_t Month; 15 | int8_t Date; 16 | int16_t Year; 17 | } RTC_DateTypeDef; 18 | 19 | class RTC { 20 | public: 21 | RTC(); 22 | 23 | void begin(void); 24 | void GetBm8563Time(void); 25 | 26 | int SetTime(RTC_TimeTypeDef* RTC_TimeStruct); 27 | int SetDate(RTC_DateTypeDef* RTC_DateStruct); 28 | 29 | void GetTime(RTC_TimeTypeDef* RTC_TimeStruct); 30 | void GetDate(RTC_DateTypeDef* RTC_DateStruct); 31 | 32 | int SetAlarmIRQ(int afterSeconds); 33 | int SetAlarmIRQ(const RTC_TimeTypeDef& RTC_TimeStruct); 34 | int SetAlarmIRQ(const RTC_DateTypeDef& RTC_DateStruct, 35 | const RTC_TimeTypeDef& RTC_TimeStruct); 36 | 37 | void clearIRQ(); 38 | void disableIRQ(); 39 | 40 | bool getVoltLow(void); 41 | 42 | public: 43 | uint8_t Second; 44 | uint8_t Minute; 45 | uint8_t Hour; 46 | uint8_t Week; 47 | uint8_t Day; 48 | uint8_t Month; 49 | uint8_t Year; 50 | uint8_t DateString[9]; 51 | uint8_t TimeString[9]; 52 | 53 | uint8_t asc[14]; 54 | 55 | private: 56 | void Bcd2asc(void); 57 | void DataMask(); 58 | void Str2Time(void); 59 | void WriteReg(uint8_t reg, uint8_t data); 60 | uint8_t ReadReg(uint8_t reg); 61 | uint8_t Bcd2ToByte(uint8_t Value); 62 | uint8_t ByteToBcd2(uint8_t Value); 63 | 64 | private: 65 | /*定义数组用来存储读取的时间数据 */ 66 | uint8_t trdata[7]; 67 | /*定义数组用来存储转换的 asc 码时间数据*/ 68 | // uint8_t asc[14]; 69 | }; 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /src/Speaker.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPEAKER_H_ 2 | #define _SPEAKER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "AXP.h" 9 | #include "Arduino.h" 10 | 11 | #define CONFIG_I2S_BCK_PIN 12 // 定义I2S相关端口 12 | #define CONFIG_I2S_LRCK_PIN 0 13 | #define CONFIG_I2S_DATA_PIN 2 14 | #define CONFIG_I2S_DATA_IN_PIN 34 15 | 16 | #define Speak_I2S_NUMBER I2S_NUM_0 // 定义扬声器端口 17 | 18 | #define MODE_MIC 0 // 定义工作模式 19 | #define MODE_SPK 1 20 | #define DATA_SIZE 1024 21 | 22 | enum pmic_t { pmic_unknown = 0, pmic_axp192, pmic_axp2101 }; 23 | 24 | class Speaker { 25 | public: 26 | void begin(void); 27 | bool InitI2SSpeakOrMic(int mode); 28 | // Plays the given amount of bytes from the given data array and returns the 29 | // amount of bytes, that were actually played by the speaker. 30 | size_t PlaySound(const unsigned char* data, const size_t& amount_of_bytes); 31 | 32 | private: 33 | pmic_t _pmic; 34 | }; 35 | #endif 36 | -------------------------------------------------------------------------------- /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 | #define TFT M5Display::instance 5 | #define BUTTONS M5Buttons::instance 6 | 7 | // Screen 8 | #define TFT_LED_PIN 32 9 | #define TFT_DC_PIN 27 10 | #define TFT_CS_PIN 14 11 | #define TFT_MOSI_PIN 23 12 | #define TFT_CLK_PIN 18 13 | #define TFT_RST_PIN 33 14 | #define TFT_MISO_PIN 19 15 | 16 | // SD card 17 | #define TFCARD_CS_PIN 4 18 | 19 | // UART 20 | #define USE_SERIAL Serial 21 | 22 | // Core2 defines 23 | #define M5Stack_M5Core2 24 | #define TFT_eSPI_TOUCH_EMULATION 25 | #define TOUCH M5Touch::instance 26 | 27 | #endif /* CONFIG_H */ 28 | -------------------------------------------------------------------------------- /src/utility/ILI9341_Init.h: -------------------------------------------------------------------------------- 1 | 2 | // // This is the command sequence that initialises the ILI9341 driver 3 | // // 4 | // // This setup information uses simple 8 bit SPI writecommand() and 5 | // writedata() functions 6 | // // 7 | // // See ST7735_Setup.h file for an alternative format 8 | 9 | { 10 | writecommand(0xC8); 11 | writedata(0xFF); 12 | writedata(0x93); 13 | writedata(0x42); 14 | 15 | writecommand(ILI9341_PWCTR1); 16 | writedata(0x12); 17 | writedata(0x12); 18 | 19 | writecommand(ILI9341_PWCTR2); 20 | writedata(0x03); 21 | 22 | writecommand(0xB0); 23 | writedata(0xE0); 24 | 25 | writecommand(0xF6); 26 | writedata(0x00); 27 | writedata(0x01); 28 | writedata(0x01); 29 | 30 | writecommand(ILI9341_MADCTL); // Memory Access Control 31 | #ifdef M5STACK 32 | writedata(TFT_MAD_MY | TFT_MAD_MV | 33 | TFT_MAD_COLOR_ORDER); // Rotation 0 (portrait mode) 34 | #else 35 | writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER); // Rotation 0 (portrait mode) 36 | #endif 37 | 38 | writecommand(ILI9341_PIXFMT); 39 | writedata(0x55); 40 | 41 | writecommand(ILI9341_DFUNCTR); // Display Function Control 42 | writedata(0x08); 43 | writedata(0x82); 44 | writedata(0x27); 45 | 46 | writecommand(ILI9341_GMCTRP1); // Set Gamma 47 | writedata(0x00); 48 | writedata(0x0C); 49 | writedata(0x11); 50 | writedata(0x04); 51 | writedata(0x11); 52 | writedata(0x08); 53 | writedata(0x37); 54 | writedata(0x89); 55 | writedata(0x4C); 56 | writedata(0x06); 57 | writedata(0x0C); 58 | writedata(0x0A); 59 | writedata(0x2E); 60 | writedata(0x34); 61 | writedata(0x0F); 62 | 63 | writecommand(ILI9341_GMCTRN1); // Set Gamma 64 | writedata(0x00); 65 | writedata(0x0B); 66 | writedata(0x11); 67 | writedata(0x05); 68 | writedata(0x13); 69 | writedata(0x09); 70 | writedata(0x33); 71 | writedata(0x67); 72 | writedata(0x48); 73 | writedata(0x07); 74 | writedata(0x0E); 75 | writedata(0x0B); 76 | writedata(0x2E); 77 | writedata(0x33); 78 | writedata(0x0F); 79 | 80 | writecommand(ILI9341_SLPOUT); // Exit Sleep 81 | 82 | spi_end(); 83 | delay(120); 84 | spi_begin(); 85 | 86 | writecommand(ILI9341_DISPON); // Display on 87 | } -------------------------------------------------------------------------------- /src/utility/ILI9341_Rotation.h: -------------------------------------------------------------------------------- 1 | 2 | // This is the command sequence that rotates the ILI9341 driver coordinate frame 3 | 4 | rotation = m % 8; // Limit the range of values to 0-7 5 | 6 | writecommand(TFT_MADCTL); 7 | switch (rotation) { 8 | case 0: 9 | #ifdef M5STACK 10 | writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); 11 | #else 12 | writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER); 13 | #endif 14 | _width = _init_width; 15 | _height = _init_height; 16 | break; 17 | case 1: 18 | #ifdef M5STACK 19 | writedata(TFT_MAD_COLOR_ORDER); 20 | #else 21 | writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER); 22 | #endif 23 | _width = _init_height; 24 | _height = _init_width; 25 | break; 26 | case 2: 27 | #ifdef M5STACK 28 | writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_COLOR_ORDER); 29 | #else 30 | writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER); 31 | #endif 32 | _width = _init_width; 33 | _height = _init_height; 34 | break; 35 | case 3: 36 | #ifdef M5STACK 37 | writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); 38 | #else 39 | writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); 40 | #endif 41 | _width = _init_height; 42 | _height = _init_width; 43 | break; 44 | // These next rotations are for bottom up BMP drawing 45 | case 4: 46 | #ifdef M5STACK 47 | writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); 48 | #else 49 | writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); 50 | #endif 51 | _width = _init_width; 52 | _height = _init_height; 53 | break; 54 | case 5: 55 | #ifdef M5STACK 56 | writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER); 57 | #else 58 | writedata(TFT_MAD_MV | TFT_MAD_MX | TFT_MAD_COLOR_ORDER); 59 | #endif 60 | _width = _init_height; 61 | _height = _init_width; 62 | break; 63 | case 6: 64 | #ifdef M5STACK 65 | writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER); 66 | #else 67 | writedata(TFT_MAD_COLOR_ORDER); 68 | #endif 69 | _width = _init_width; 70 | _height = _init_height; 71 | break; 72 | case 7: 73 | #ifdef M5STACK 74 | writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER); 75 | #else 76 | writedata(TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); 77 | #endif 78 | _width = _init_height; 79 | _height = _init_width; 80 | break; 81 | } 82 | -------------------------------------------------------------------------------- /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/qrcode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * The MIT License (MIT) 3 | * 4 | * Copyright (c) 2017 Richard Moore 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | /** 26 | * Special thanks to Nayuki (https://www.nayuki.io/) from which this library 27 | * was heavily inspired and compared against. 28 | * 29 | * See: https://github.com/nayuki/QR-Code-generator/tree/master/cpp 30 | */ 31 | 32 | #ifndef __QRCODE_H_ 33 | #define __QRCODE_H_ 34 | 35 | #ifndef __cplusplus 36 | typedef unsigned char bool; 37 | static const bool false = 0; 38 | static const bool true = 1; 39 | #endif 40 | 41 | #include 42 | 43 | // QR Code Format Encoding 44 | #define MODE_NUMERIC 0 45 | #define MODE_ALPHANUMERIC 1 46 | #define MODE_BYTE 2 47 | 48 | // Error Correction Code Levels 49 | #define ECC_LOW 0 50 | #define ECC_MEDIUM 1 51 | #define ECC_QUARTILE 2 52 | #define ECC_HIGH 3 53 | 54 | // If set to non-zero, this library can ONLY produce QR codes at that version 55 | // This saves a lot of dynamic memory, as the codeword tables are skipped 56 | #ifndef LOCK_VERSION 57 | #define LOCK_VERSION 0 58 | #endif 59 | 60 | typedef struct QRCode { 61 | uint8_t version; 62 | uint8_t size; 63 | uint8_t ecc; 64 | uint8_t mode; 65 | uint8_t mask; 66 | uint8_t *modules; 67 | } QRCode; 68 | 69 | #ifdef __cplusplus 70 | extern "C" { 71 | #endif /* __cplusplus */ 72 | 73 | uint16_t qrcode_getBufferSize(uint8_t version); 74 | 75 | int8_t qrcode_initText(QRCode *qrcode, uint8_t *modules, uint8_t version, 76 | uint8_t ecc, const char *data); 77 | int8_t qrcode_initBytes(QRCode *qrcode, uint8_t *modules, uint8_t version, 78 | uint8_t ecc, uint8_t *data, uint16_t length); 79 | 80 | bool qrcode_getModule(QRCode *qrcode, uint8_t x, uint8_t y); 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif /* __cplusplus */ 85 | 86 | #endif /* __QRCODE_H_ */ 87 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------