├── src ├── Fonts │ ├── ASC16 │ ├── HZK16 │ ├── TrueType │ │ └── Not_yet_supported.txt │ ├── Font16.h │ ├── Font32rle.h │ ├── Font64rle.h │ ├── Font72rle.h │ ├── Font7srle.h │ └── GFXFF │ │ ├── gfxfont.h │ │ ├── license.txt │ │ └── print.txt ├── utility │ ├── Config.h │ ├── Speaker.h │ ├── MahonyAHRS.h │ ├── ST7789_Rotation.h │ ├── Button.h │ ├── Speaker.cpp │ └── qrcode.h ├── M5StickCPlus.cpp ├── RTC.h └── AXP192.h ├── .gitignore ├── examples ├── Hat │ ├── YUN │ │ ├── yunBoard.h │ │ ├── display.h │ │ ├── SHT20.h │ │ ├── yunBoard.cpp │ │ ├── SHT20.cpp │ │ └── YUN.ino │ ├── PuppyC │ │ ├── IIC_.h │ │ ├── IIC_.cpp │ │ └── PuppyC.ino │ ├── ENVII_SHT30_BMP280 │ │ ├── SHT3X.h │ │ └── SHT3X.cpp │ ├── PIR │ │ └── PIR.ino │ ├── SERVO │ │ └── SERVO.ino │ ├── BUGC │ │ ├── BUGC.ino │ │ ├── bugC.h │ │ └── bugC.cpp │ ├── CardKB │ │ └── CardKB.ino │ ├── C_BACK_DRIVER │ │ ├── CBACK_DRIVER.h │ │ ├── C_BACK_DRIVER.ino │ │ └── CBACK_DRIVER.cpp │ ├── SPEAKER │ │ └── SPEAKER.ino │ ├── RS485_SP485EEN │ │ └── RS485_SP485EEN.ino │ ├── DAC_ADS1100 │ │ ├── Adafruit_MCP4725.h │ │ ├── DAC_ADS1100.ino │ │ └── Adafruit_MCP4725.cpp │ ├── VIBRATOR │ │ └── VIBRATOR.ino │ ├── THERMAL_MLX90640 │ │ ├── MLX90640_I2C_Driver.h │ │ └── MLX90640_API.h │ └── DAC2_GP8413 │ │ └── DAC2_GP8413.ino ├── Unit │ ├── PaHUB │ │ ├── ClosedCube_TCA9548A.h │ │ ├── ClosedCube_TCA9548A.cpp │ │ └── PaHUB.ino │ ├── FAN │ │ └── FAN.ino │ ├── OP90.180_ITR9606 │ │ └── OP90.180_ITR9606.ino │ ├── VIBRATOR │ │ └── VIBRATOR.ino │ ├── CardKB │ │ └── CardKB.ino │ ├── ANGLE │ │ └── ANGLE.ino │ ├── DAC_MCP4725 │ │ └── DAC_MCP4725.ino │ ├── ISO485 │ │ └── ISO485.ino │ ├── HALL │ │ └── HALL.ino │ ├── PbHUB │ │ ├── PbHUB.ino │ │ └── porthub.h │ ├── Joystick │ │ └── Joystick.ino │ ├── Earth │ │ └── Earth.ino │ ├── HEX_SK6812 │ │ └── HEX_SK6812.ino │ ├── LASER │ │ └── LASER.ino │ ├── Light │ │ └── Light.ino │ ├── RS485_SP485EEN │ │ └── RS485_SP485EEN.ino │ ├── IR │ │ └── IR.ino │ ├── WATERING │ │ └── WATERING.ino │ ├── LIMIT │ │ └── LIMIT.ino │ ├── PIR │ │ └── PIR.ino │ ├── EXT_IO │ │ ├── PCA9554.h │ │ └── EXT_IO.ino │ ├── MIC_LM393_MAX4466 │ │ └── MIC_LM393_MAX4466.ino │ ├── BUTTON │ │ └── BUTTON.ino │ ├── IMU_MPU6886 │ │ ├── IMU_MPU6886.ino │ │ └── IMU_6886.h │ ├── THERMAL_MLX90640 │ │ ├── MLX90640_I2C_Driver.h │ │ └── MLX90640_API.h │ ├── RGB_LED │ │ └── display_rainbow │ │ │ └── display_rainbow.ino │ ├── RFID │ │ └── RFID.ino │ ├── Color │ │ └── Color.ino │ ├── HEART │ │ └── MAX30100_RawData │ │ │ └── MAX30100_RawData.ino │ ├── TVOC_SGP30 │ │ ├── TVOC_SGP30.ino │ │ └── Adafruit_SGP30.h │ ├── RGB │ │ └── RGB.ino │ ├── Dual_Button │ │ └── Dual_Button.ino │ ├── ACCEL_ADXL345 │ │ └── ACCEL_ADXL345.ino │ ├── DAC2_GP8413 │ │ └── DAC2_GP8413.ino │ ├── KEY │ │ └── KEY.ino │ └── PDM_SPM1423 │ │ └── fft.h ├── Advanced │ ├── QRCode │ │ └── QRCode.ino │ ├── WIFI │ │ ├── WiFiSetting │ │ │ └── detail │ │ │ │ └── RequestHandler.h │ │ ├── WiFiMulti │ │ │ └── WiFiMulti.ino │ │ ├── OTAUpload │ │ │ └── OTAUpload.ino │ │ ├── BasicHttpClient │ │ │ └── BasicHttpClient.ino │ │ ├── WiFiSmartConfig │ │ │ └── WiFiSmartConfig.ino │ │ └── WiFiScan │ │ │ └── WiFiScan.ino │ ├── MultSerial │ │ └── MultSerial.ino │ ├── Storage │ │ ├── SPIFFS │ │ │ ├── SPIFFS_Delete │ │ │ │ └── SPIFFS_Delete.ino │ │ │ └── SPIFFS_Add │ │ │ │ └── SPIFFS_Add.ino │ │ └── Counter │ │ │ └── Counter.ino │ ├── Time │ │ └── Time.ino │ ├── MultiTask │ │ └── MultiTask.ino │ ├── I2C_Tester │ │ └── I2C_Tester.ino │ ├── EzData │ │ └── EzData.ino │ └── HallSensor │ │ └── HallSensor.ino ├── FactoryTest │ ├── TFTTerminal.h │ └── fft.h ├── Basics │ ├── HelloWorld │ │ └── HelloWorld.ino │ ├── Display │ │ └── Display.ino │ ├── MPU6886 │ │ └── MPU6886.ino │ ├── Button │ │ └── Button.ino │ ├── IMU │ │ └── IMU.ino │ ├── RTC │ │ └── RTC.ino │ ├── Micophone │ │ └── Micophone.ino │ └── AXP192 │ │ └── AXP192.ino └── Games │ └── Dices │ └── Dices.ino ├── .vscode └── extensions.json ├── platformio.ini ├── library.properties ├── .github ├── workflows │ ├── Arduino-Lint-Check.yml │ └── clang-format-check.yml └── ISSUE_TEMPLATE │ └── bug-report.yml ├── library.json ├── CMakeLists.txt ├── LICENSE ├── README_cn.md └── README.md /src/Fonts/ASC16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5StickC-Plus/HEAD/src/Fonts/ASC16 -------------------------------------------------------------------------------- /src/Fonts/HZK16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m5stack/M5StickC-Plus/HEAD/src/Fonts/HZK16 -------------------------------------------------------------------------------- /src/Fonts/TrueType/Not_yet_supported.txt: -------------------------------------------------------------------------------- 1 | TO DO: Add support for converted True Type fonts in an RLE format. -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | .vscode/.browse.c_cpp.db* 3 | .vscode/c_cpp_properties.json 4 | .vscode/launch.json 5 | .vscode/ipch 6 | -------------------------------------------------------------------------------- /examples/Hat/YUN/yunBoard.h: -------------------------------------------------------------------------------- 1 | #ifndef _BOARD__H_ 2 | #define _BOARD__H_ 3 | 4 | #include 5 | 6 | extern void led_set(uint8_t num, uint32_t color_in); 7 | extern void led_set_all(uint32_t color_in); 8 | extern uint16_t light_get(); 9 | 10 | #endif -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "platformio.platformio-ide" 6 | ], 7 | "unwantedRecommendations": [ 8 | "ms-vscode.cpptools-extension-pack" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | 2 | ;PlatformIO Project Configuration File 3 | ;PlatformIO recommended configuration 4 | 5 | [env:M5StickCPlus] 6 | platform = espressif32 7 | board = m5stick-c 8 | lib_ldf_mode = deep 9 | framework = arduino 10 | upload_speed = 1500000 11 | monitor_speed = 115200 12 | lib_deps = 13 | https://github.com/m5stack/M5StickC-Plus.git -------------------------------------------------------------------------------- /examples/Hat/PuppyC/IIC_.h: -------------------------------------------------------------------------------- 1 | #ifndef _IIC_H_ 2 | #define _IIC_H_ 3 | 4 | #include 5 | 6 | #define SERVO_ADDRESS 0X38 7 | void IIC_Init(); // sda 0 scl 26 8 | 9 | void angle_all_set(uint8_t angle1, uint8_t angle2, uint8_t angle3, 10 | uint8_t angle4); 11 | 12 | uint8_t angle_set(uint8_t whitch, uint8_t anglex); 13 | #endif 14 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=M5StickCPlus 2 | version=0.1.1 3 | author=M5Stack 4 | maintainer=M5Stack 5 | sentence=Library for M5StickC Plus development kit 6 | paragraph=See more on http://M5Stack.com 7 | category=Device Control 8 | url=https://github.com/m5stack/M5StickC-Plus.git 9 | architectures=esp32 10 | includes=M5StickCPlus.h 11 | depends=M5Family,M5Hat-8Servos,M5Hat-JoyC,M5-RoverC -------------------------------------------------------------------------------- /examples/Hat/YUN/display.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPLAY_h 2 | #define DISPLAY_h 3 | 4 | #include 5 | void display_light(void); 6 | void display_light0(void); 7 | void display_light1(void); 8 | void display_light2(void); 9 | void display_light3(void); 10 | void display_light4(void); 11 | 12 | void led_breath(void); 13 | void led_off(void); 14 | void display_led(void); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /.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 -------------------------------------------------------------------------------- /src/utility/Config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | #define M5_IR 9 5 | #define M5_LED 10 6 | #define M5_BUTTON_HOME 37 7 | #define M5_BUTTON_RST 39 8 | 9 | #define BUTTON_A_PIN 37 10 | #define BUTTON_B_PIN 39 11 | 12 | #define SPEAKER_PIN 2 13 | #define TONE_PIN_CHANNEL 0 14 | 15 | // UART 16 | #define USE_SERIAL Serial 17 | 18 | #endif /* SETTINGS_C */ 19 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "M5StickCPlus", 3 | "description": "An ESP32 Arduino board", 4 | "keywords": "M5StickCPlus", 5 | "authors": { 6 | "name": "M5Stack", 7 | "url": "http://www.m5stack.com" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/m5stack/M5StickC-Plus.git" 12 | }, 13 | "version": "0.1.1", 14 | "frameworks": "arduino", 15 | "platforms": "espressif32", 16 | "headers": "M5StickCPlus.h" 17 | } -------------------------------------------------------------------------------- /examples/Hat/ENVII_SHT30_BMP280/SHT3X.h: -------------------------------------------------------------------------------- 1 | #ifndef __SHT3X_H 2 | #define __HT3X_H 3 | 4 | #if ARDUINO >= 100 5 | #include "Arduino.h" 6 | #else 7 | #include "WProgram.h" 8 | #endif 9 | 10 | #include "Wire.h" 11 | 12 | class SHT3X { 13 | public: 14 | SHT3X(uint8_t address = 0x44); 15 | byte get(void); 16 | float cTemp = 0; 17 | float fTemp = 0; 18 | float humidity = 0; 19 | 20 | private: 21 | uint8_t _address; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(COMPONENT_SRCDIRS src 2 | src/Fonts 3 | src/utility) 4 | 5 | set(COMPONENT_ADD_INCLUDEDIRS src) 6 | 7 | set(COMPONENT_PRIV_INCLUDEDIRS src/Fonts 8 | src/Fonts/Custom 9 | src/Fonts/GFXFF 10 | src/Fonts/TrueType 11 | src/utility) 12 | 13 | set(COMPONENT_PRIV_REQUIRES arduino) 14 | 15 | register_component() 16 | -------------------------------------------------------------------------------- /examples/Hat/PIR/PIR.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | // put your setup code here, to run once: 5 | M5.begin(); 6 | M5.Lcd.setRotation(3); 7 | M5.Lcd.fillScreen(BLACK); 8 | M5.Lcd.setCursor(0, 0, 4); 9 | M5.Lcd.println("PIR TEST"); 10 | 11 | pinMode(36, INPUT_PULLUP); 12 | } 13 | 14 | void loop() { 15 | // put your main code here, to run repeatedly: 16 | 17 | M5.Lcd.setCursor(110, 55, 6); 18 | M5.Lcd.println(digitalRead(36)); 19 | } 20 | -------------------------------------------------------------------------------- /examples/Hat/SERVO/SERVO.ino: -------------------------------------------------------------------------------- 1 | #define COUNT_LOW 1500 2 | #define COUNT_HIGH 8500 3 | #define TIMER_WIDTH 16 4 | #include "esp32-hal-ledc.h" 5 | #include 6 | 7 | void setup() { 8 | // put your setup code here, to run once: 9 | M5.begin(); 10 | ledcSetup(1, 50, TIMER_WIDTH); 11 | ledcAttachPin(26, 1); 12 | M5.Lcd.setCursor(25, 80, 4); 13 | M5.Lcd.print("SERVO"); 14 | } 15 | 16 | void loop() { 17 | // put your main code here, to run repeatedly: 18 | for (int i = COUNT_LOW; i < COUNT_HIGH; i = i + 100) { 19 | ledcWrite(1, i); 20 | delay(50); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/Unit/PaHUB/ClosedCube_TCA9548A.h: -------------------------------------------------------------------------------- 1 | #ifndef CLOSEDCUBE_TCA9548A_H 2 | #define CLOSEDCUBE_TCA9548A_H 3 | 4 | #include 5 | 6 | #define TCA9548A_MAX_CHANNELS 6 7 | 8 | namespace ClosedCube { 9 | 10 | namespace Wired { 11 | 12 | class TCA9548A { 13 | public: 14 | TCA9548A(); 15 | TCA9548A(uint8_t address); 16 | 17 | void address(uint8_t address); 18 | 19 | uint8_t getChannel(); 20 | 21 | uint8_t selectChannel(uint8_t channel); 22 | uint8_t nextChannel(); 23 | 24 | private: 25 | uint8_t _address; 26 | uint8_t _currentChannel; 27 | }; 28 | 29 | } // namespace Wired 30 | } // namespace ClosedCube 31 | 32 | #endif // CLOSEDCUBE_TCA9548A_H 33 | -------------------------------------------------------------------------------- /examples/Hat/BUGC/BUGC.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "bugC.h" 3 | 4 | BUGC BugC; 5 | 6 | void setup() { 7 | M5.begin(); 8 | BugC.Init(); 9 | M5.Lcd.setTextColor(TFT_GREEN); 10 | M5.Lcd.setRotation(1); 11 | M5.Lcd.drawCentreString("BUGC example", 120, 50, 4); 12 | } 13 | 14 | void loop() { 15 | M5.update(); 16 | 17 | BugC.BugCSetColor(0x100000, 0x000010); 18 | BugC.BugCSetAllSpeed(-100, 100, -100, 100); 19 | delay(1000); 20 | BugC.BugCSetColor(0x000010, 0x100000); 21 | BugC.BugCSetAllSpeed(-100, 100, -100, 100); 22 | delay(1000); 23 | BugC.BugCSetAllSpeed(0, 0, 0, 0); 24 | BugC.BugCSetColor(0x000000, 0x000000); 25 | delay(1000); 26 | } 27 | -------------------------------------------------------------------------------- /examples/Unit/FAN/FAN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: Adjust the speed of FAN Unit through PWM. 3 | */ 4 | 5 | #include 6 | 7 | const int motor_pin = 32; 8 | int freq = 10000; 9 | int ledChannel = 2; 10 | int resolution = 10; 11 | void setup() { 12 | // put your setup code here, to run once: 13 | M5.begin(); 14 | M5.Lcd.setCursor(25, 10, 4); 15 | M5.Lcd.println("MOTOR"); 16 | ledcSetup(ledChannel, freq, resolution); 17 | ledcAttachPin(motor_pin, ledChannel); 18 | } 19 | 20 | void loop() { 21 | // put your main code here, to run repeatedly: 22 | ledcWrite(ledChannel, 512); 23 | delay(1000); 24 | ledcWrite(ledChannel, 0); 25 | delay(1000); 26 | } 27 | -------------------------------------------------------------------------------- /examples/Unit/OP90.180_ITR9606/OP90.180_ITR9606.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: Detect the current OP 90/180 Unit Photoelectric switch status. 3 | */ 4 | 5 | #include 6 | 7 | void setup() { 8 | // put your setup code here, to run once: 9 | M5.begin(); 10 | // Wire.begin(); 11 | M5.Lcd.setCursor(30, 5, 4); 12 | M5.Lcd.println("90/180"); 13 | M5.Lcd.setCursor(20, 30, 4); 14 | M5.Lcd.println("OPTICAL"); 15 | 16 | pinMode(33, INPUT_PULLUP); 17 | } 18 | 19 | void loop() { 20 | // put your main code here, to run repeatedly: 21 | M5.Lcd.setCursor(12, 100, 4); 22 | M5.Lcd.printf("IR receive:"); 23 | M5.Lcd.setCursor(40, 140, 8); 24 | M5.Lcd.printf("%d", digitalRead(33)); 25 | } 26 | -------------------------------------------------------------------------------- /examples/Unit/VIBRATOR/VIBRATOR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: Adjust the speed of VIBRATOR Unit through PWM. 3 | */ 4 | 5 | #include 6 | 7 | const int motor_pin = 32; 8 | int freq = 10000; 9 | int ledChannel = 2; 10 | int resolution = 10; 11 | void setup() { 12 | // put your setup code here, to run once: 13 | M5.begin(); 14 | M5.Lcd.setCursor(25, 10, 4); 15 | M5.Lcd.println("MOTOR"); 16 | ledcSetup(ledChannel, freq, resolution); 17 | ledcAttachPin(motor_pin, ledChannel); 18 | } 19 | 20 | void loop() { 21 | // put your main code here, to run repeatedly: 22 | ledcWrite(ledChannel, 512); 23 | delay(1000); 24 | ledcWrite(ledChannel, 0); 25 | delay(1000); 26 | } 27 | -------------------------------------------------------------------------------- /examples/Hat/CardKB/CardKB.ino: -------------------------------------------------------------------------------- 1 | #include 0 2 | #include 3 | 4 | #define CARDKB_ADDR 0x5F 5 | 6 | void setup() { 7 | M5.begin(); 8 | Wire.begin(0, 26); 9 | M5.Lcd.setRotation(3); 10 | M5.Lcd.fillScreen(BLACK); 11 | M5.Lcd.setCursor(0, 0, 2); 12 | M5.Lcd.setTextColor(YELLOW); 13 | 14 | M5.Lcd.println("IIC Address: 0x5F\n"); 15 | M5.Lcd.println(">>"); 16 | } 17 | void loop() { 18 | Wire.requestFrom(CARDKB_ADDR, 1); 19 | while (Wire.available()) { 20 | char c = Wire.read(); // receive a byte as characterif 21 | if (c != 0) { 22 | M5.Lcd.printf("%c", c); 23 | Serial.println(c, HEX); 24 | Serial.println(char(c)); 25 | } 26 | } 27 | // delay(10); 28 | } 29 | -------------------------------------------------------------------------------- /examples/Unit/CardKB/CardKB.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define CARDKB_ADDR 0x5F 5 | 6 | void setup() { 7 | M5.begin(); 8 | Wire.begin(32, 33); 9 | M5.Lcd.setRotation(3); 10 | M5.Lcd.fillScreen(BLACK); 11 | M5.Lcd.setCursor(1, 10); 12 | M5.Lcd.setTextColor(YELLOW); 13 | M5.Lcd.setTextSize(2); 14 | M5.Lcd.printf("IIC Address: 0x5F\n"); 15 | M5.Lcd.printf(">>"); 16 | } 17 | void loop() { 18 | Wire.requestFrom(CARDKB_ADDR, 1); 19 | while (Wire.available()) { 20 | char c = Wire.read(); // receive a byte as characterif 21 | if (c != 0) { 22 | M5.Lcd.printf("%c", c); 23 | Serial.println(c, HEX); 24 | // M5.Speaker.beep(); 25 | } 26 | } 27 | // delay(10); 28 | } 29 | -------------------------------------------------------------------------------- /examples/Hat/C_BACK_DRIVER/CBACK_DRIVER.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SERVO_ADDRESS 0X38 4 | 5 | class CBACK_DRIVER { 6 | private: 7 | void Write1Byte(uint8_t address, uint8_t Register_address, uint8_t data); 8 | void Write2Byte(uint8_t address, uint8_t Register_address, uint16_t data); 9 | uint8_t ReadBytes(uint8_t address, uint8_t subAddress, uint8_t count, 10 | uint8_t* dest); 11 | 12 | public: 13 | void Init(); // sda 25 scl 21 14 | uint8_t SetServoAngle(uint8_t Servo_CH, uint8_t angle); 15 | uint8_t SetServoPulse(uint8_t Servo_CH, uint16_t width); 16 | uint8_t ReadServoAngle(uint8_t Servo_CH); 17 | uint16_t ReadServoPulse(uint8_t Servo_CH); 18 | uint16_t ReadADC(); 19 | uint8_t SetOutput(uint8_t status); 20 | uint8_t ReadInput(); 21 | }; -------------------------------------------------------------------------------- /.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|RFID|HEART|MahonyAHRS)' # 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 | -------------------------------------------------------------------------------- /examples/Unit/ANGLE/ANGLE.ino: -------------------------------------------------------------------------------- 1 | #include 2 | // select the input pin for the potentiometer 3 | int sensorPin = 33; 4 | // last variable to store the value coming from the sensor 5 | int last_sensorValue = 0; 6 | // current variable to store the value coming from the sensor 7 | int cur_sensorValue = 0; 8 | 9 | void setup() { 10 | M5.begin(); 11 | M5.Lcd.setRotation(3); 12 | pinMode(sensorPin, INPUT); 13 | M5.Lcd.setCursor(0, 10, 2); 14 | M5.Lcd.print("The value of ANGLE: "); 15 | } 16 | 17 | void loop() { 18 | // read the value from the sensor: 19 | cur_sensorValue = analogRead(sensorPin); 20 | M5.Lcd.setCursor(80, 50, 6); 21 | if (abs(cur_sensorValue - last_sensorValue) > 10) { // debaunce 22 | M5.Lcd.fillRect(100, 50, 100, 40, BLACK); 23 | M5.Lcd.print(cur_sensorValue); 24 | last_sensorValue = cur_sensorValue; 25 | } 26 | delay(50); 27 | } 28 | -------------------------------------------------------------------------------- /examples/Hat/PuppyC/IIC_.cpp: -------------------------------------------------------------------------------- 1 | #include "IIC_.h" 2 | 3 | void IIC_Init() // sda 0 scl 26 4 | { 5 | Wire.begin(0, 26, 100000UL); 6 | } 7 | 8 | /*******************************************************************************/ 9 | /* 10 | 11 | 1 2 12 | 3 4 13 | */ 14 | void angle_all_set(uint8_t angle1, uint8_t angle2, uint8_t angle3, 15 | uint8_t angle4) { 16 | Wire.beginTransmission(SERVO_ADDRESS); 17 | Wire.write(0x00); 18 | Wire.write(angle1); 19 | Wire.write(angle2); 20 | Wire.write(angle3); 21 | Wire.write(angle4); 22 | Wire.endTransmission(); 23 | } 24 | uint8_t angle_set(uint8_t whitch, uint8_t anglex) { 25 | if (whitch < 1 || whitch > 5) { 26 | return 0; 27 | } 28 | whitch -= 1; 29 | Wire.beginTransmission(SERVO_ADDRESS); 30 | Wire.write(whitch); 31 | Wire.write(anglex); 32 | Wire.endTransmission(); 33 | return 1; 34 | } 35 | -------------------------------------------------------------------------------- /examples/Unit/DAC_MCP4725/DAC_MCP4725.ino: -------------------------------------------------------------------------------- 1 | /* 2 | hardware : m5stack uint dac 3 | 4 | please install adafruit MCP4725 lib 5 | */ 6 | #include 7 | #include 8 | #include 9 | 10 | #define DAC_ADDR 11 | Adafruit_MCP4725 dac; 12 | 13 | void setup(void) { 14 | M5.begin(); 15 | Serial.println("Hello!"); 16 | 17 | // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin 18 | // tied to VCC) For MCP4725A0 the address is 0x60 or 0x61 For MCP4725A2 the 19 | // address is 0x64 or 0x65 20 | dac.begin(0x60); 21 | 22 | Serial.println("Generating a triangle wave"); 23 | dac.setVoltage(2048, false); 24 | 25 | M5.Lcd.drawString("DAC test", 10, 10, 4); 26 | } 27 | 28 | void loop(void) { 29 | // 12bit value , false mean not write EEPROM 30 | dac.setVoltage(1024, false); 31 | delay(1000); 32 | dac.setVoltage(2048, false); 33 | delay(1000); 34 | } 35 | -------------------------------------------------------------------------------- /examples/Unit/ISO485/ISO485.ino: -------------------------------------------------------------------------------- 1 | /* 2 | neo pixel test 3 | 4 | hardwware: M5StickCPLUS 5 | Pressed ButtonA :send "hello world" 6 | 7 | */ 8 | #include 9 | 10 | String str = ""; 11 | 12 | void setup() { 13 | M5.begin(); 14 | M5.Lcd.drawString("ISO485", 30, 0, 4); 15 | 16 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 17 | // txPin, bool invert) 18 | Serial2.begin(115200, SERIAL_8N1, 33, 32); 19 | 20 | M5.Lcd.setTextFont(2); 21 | M5.Lcd.setCursor(0, 30); 22 | } 23 | 24 | void loop() { 25 | if (M5.BtnA.wasPressed()) { 26 | Serial2.write("Hello World\r\n"); 27 | } 28 | 29 | if (Serial2.available()) { 30 | char ch = Serial2.read(); 31 | str += ch; 32 | if (str.endsWith("\r\n")) { 33 | Serial.print(str); 34 | M5.Lcd.print(str); 35 | str = ""; 36 | } 37 | } 38 | M5.update(); 39 | } 40 | -------------------------------------------------------------------------------- /examples/Unit/HALL/HALL.ino: -------------------------------------------------------------------------------- 1 | // Low-level signal can be generated when the magnet S pole is close to the 2 | // front of the sensor OR the N pole is close to the back, and the internal LED 3 | // indicator will light up, the screen wiil display 0. 4 | 5 | #include 6 | #define HALL 33 7 | 8 | void header() { 9 | M5.Lcd.setTextSize(2); 10 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 11 | M5.Lcd.drawString("HALL", 42, 3, 2); 12 | M5.Lcd.drawString("Sensor", 30, 30, 2); 13 | } 14 | 15 | void setup() { 16 | M5.begin(true, false, true); 17 | header(); 18 | pinMode(HALL, INPUT); 19 | } 20 | 21 | void loop() { 22 | bool status = digitalRead(HALL); 23 | M5.Lcd.setTextSize(2); 24 | M5.Lcd.setCursor(51, 70, 2); 25 | M5.Lcd.printf("Hall"); 26 | M5.Lcd.setCursor(34, 100, 2); 27 | M5.Lcd.printf("status:"); 28 | M5.Lcd.setCursor(45, 150, 6); 29 | M5.Lcd.printf("%d", status); 30 | // delay(100); 31 | } 32 | -------------------------------------------------------------------------------- /src/utility/Speaker.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPEAKER_H_ 2 | #define _SPEAKER_H_ 3 | 4 | #include "Arduino.h" 5 | #include "Config.h" 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /* __cplusplus */ 10 | #include "esp32-hal-dac.h" 11 | #ifdef __cplusplus 12 | } 13 | #endif /* __cplusplus */ 14 | 15 | class SPEAKER { 16 | public: 17 | SPEAKER(void); 18 | 19 | void begin(); 20 | void end(); 21 | void mute(); 22 | void tone(uint16_t frequency); 23 | void tone(uint16_t frequency, uint32_t duration); 24 | void beep(); 25 | void setBeep(uint16_t frequency, uint16_t duration); 26 | void update(); 27 | 28 | void write(uint8_t value); 29 | void setVolume(uint8_t volume); 30 | void playMusic(const uint8_t *music_data, uint16_t sample_rate); 31 | 32 | private: 33 | uint32_t _count; 34 | uint8_t _volume; 35 | uint16_t _beep_duration; 36 | uint16_t _beep_freq; 37 | bool _begun; 38 | bool speaker_on; 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /examples/Unit/PbHUB/PbHUB.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "porthub.h" 4 | 5 | #define X_OFFSET 10 6 | #define Y_OFFSET 9 7 | 8 | PortHub porthub; 9 | uint8_t HUB_ADDR[6] = {HUB1_ADDR, HUB2_ADDR, HUB3_ADDR, 10 | HUB4_ADDR, HUB5_ADDR, HUB6_ADDR}; 11 | 12 | void setup() { 13 | M5.begin(true, false, true); 14 | M5.Lcd.setRotation(3); 15 | porthub.begin(); 16 | M5.Lcd.fillScreen(BLACK); 17 | M5.Lcd.setTextColor(WHITE); 18 | M5.Lcd.setTextSize(2); 19 | } 20 | 21 | void loop() { 22 | M5.Lcd.fillScreen(BLACK); 23 | for (int i = 0; i < 6; i++) { 24 | M5.Lcd.setCursor(8 * X_OFFSET, (i * 2) * Y_OFFSET); 25 | M5.Lcd.printf("%d:%d", i + 1, porthub.hub_a_read_value(HUB_ADDR[i])); 26 | } 27 | 28 | for (int i = 0; i < 6; i++) { 29 | porthub.hub_wire_setBrightness(HUB_ADDR[i], 1); 30 | porthub.hub_wire_fill_color(HUB_ADDR[i], 0, 15, 250, 250, 250); 31 | } 32 | delay(1000); 33 | } 34 | -------------------------------------------------------------------------------- /examples/Advanced/QRCode/QRCode.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: QRcode. 创建二维码 10 | * Date: 2021/9/18 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | void setup() { 16 | M5.begin(); 17 | M5.Lcd.qrcode("http://www.m5stack.com", 0, 0, 18 | 135); // Create a QR code with a width of 135 QR code at (0, 19 | // 0). 在(0,0)处创建一个宽为135二维码 20 | // Please select the appropriate QR code version according to the number of 21 | // characters. 请根据字符数量选择合适的二维码版本 22 | } 23 | 24 | void loop() { 25 | } -------------------------------------------------------------------------------- /examples/Unit/Joystick/Joystick.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Wire.h" 3 | 4 | #define JOY_ADDR 0x52 5 | 6 | void setup() { 7 | M5.begin(); 8 | // M5.Lcd.clear(); 9 | // disable the speak noise 10 | // dacWrite(25, 0); 11 | 12 | Wire.begin(); 13 | M5.Lcd.setRotation(3); 14 | } 15 | 16 | uint8_t x_data; 17 | uint8_t y_data; 18 | uint8_t button_data; 19 | char data[100]; 20 | void loop() { 21 | // put your main code here, to run repeatedly: 22 | Wire.requestFrom(JOY_ADDR, 3); 23 | if (Wire.available()) { 24 | x_data = Wire.read(); 25 | y_data = Wire.read(); 26 | button_data = Wire.read(); 27 | sprintf(data, "x:%d y:%d button:%d\n", x_data, y_data, button_data); 28 | Serial.print(data); 29 | 30 | M5.Lcd.setCursor(1, 30, 4); 31 | M5.Lcd.printf("x:%04d y:%04d\n", x_data, y_data); 32 | M5.Lcd.setCursor(1, 60, 4); 33 | M5.Lcd.printf("button:%d\n", button_data); 34 | } 35 | delay(200); 36 | } 37 | -------------------------------------------------------------------------------- /examples/FactoryTest/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 | uint16_t _line_x_limit = 53, _line_y_limit = 30; 19 | 20 | public: 21 | TFTTerminal(TFT_eSprite *dis_buff_ptr); 22 | ~TFTTerminal(); 23 | 24 | void setcolor(uint16_t color, uint16_t bk_color); 25 | void setGeometry(uint16_t x, uint16_t y, uint16_t w, uint16_t h); 26 | void setFontsize(uint8_t size); 27 | 28 | size_t write(uint8_t); 29 | size_t write(const uint8_t *buffer, size_t size); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /examples/Unit/Earth/Earth.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | M5.begin(); 5 | M5.Lcd.setRotation(3); 6 | M5.Lcd.setTextColor(YELLOW); 7 | M5.Lcd.setCursor(65, 2); 8 | M5.Lcd.printf("UNIT_EARTH EXAMPLE\n"); 9 | pinMode(32, INPUT); 10 | M5.Lcd.setCursor(50, 30); 11 | M5.Lcd.print("GPIO33:"); 12 | M5.Lcd.setCursor(50, 50); 13 | M5.Lcd.print("GPIO32:"); 14 | } 15 | 16 | uint16_t analogRead_value = 0; 17 | uint16_t digitalRead_value = 0; 18 | void loop() { 19 | // put your main code here, to run repeatedly: 20 | M5.Lcd.setCursor(160, 30); 21 | M5.Lcd.setTextColor(BLACK); 22 | M5.Lcd.printf("%d\n", analogRead_value); 23 | M5.Lcd.setCursor(160, 50); 24 | M5.Lcd.printf("%d\n", digitalRead_value); 25 | analogRead_value = analogRead(33); 26 | digitalRead_value = digitalRead(32); 27 | M5.Lcd.setTextColor(YELLOW); 28 | M5.Lcd.setCursor(160, 30); 29 | M5.Lcd.printf("%d\n", analogRead_value); 30 | M5.Lcd.setCursor(160, 50); 31 | M5.Lcd.printf("%d\n", digitalRead_value); 32 | delay(10); 33 | } 34 | -------------------------------------------------------------------------------- /examples/Hat/C_BACK_DRIVER/C_BACK_DRIVER.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "CBACK_DRIVER.h" 3 | 4 | bool flag = true; 5 | 6 | CBACK_DRIVER Driver; 7 | 8 | void setup() { 9 | M5.begin(); 10 | Driver.Init(); 11 | Serial.println("C Back Driver Test..."); 12 | M5.Lcd.setTextColor(TFT_GREEN); 13 | M5.Lcd.setRotation(1); 14 | M5.Lcd.drawCentreString("C BACK Driver", 120, 30, 4); 15 | M5.Lcd.drawCentreString("Click Btn A Start", 120, 65, 4); 16 | } 17 | 18 | void loop() { 19 | if (M5.BtnA.wasPressed()) { 20 | flag = !flag; 21 | } 22 | if (flag) { 23 | for (int i = 1; i <= 4; i++) { 24 | Driver.SetServoAngle(i, 90); 25 | // Driver.ReadServoPulse(i,1500); 26 | } 27 | Driver.SetOutput(1); 28 | } else { 29 | for (int i = 1; i <= 4; i++) { 30 | Driver.SetServoAngle(i, 120); 31 | // Driver.ReadServoPulse(i,2000); 32 | } 33 | Driver.SetOutput(0); 34 | } 35 | Serial.print("PortB ADC: "); 36 | Serial.println(Driver.ReadADC()); 37 | M5.update(); 38 | } 39 | -------------------------------------------------------------------------------- /examples/Unit/HEX_SK6812/HEX_SK6812.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: Control HEX Unit to run rainbow light show 3 | Please install library before compiling: 4 | FastLED: https://github.com/FastLED/FastLED 5 | */ 6 | #include 7 | #include "FastLED.h" 8 | 9 | #define Neopixel_PIN 32 10 | #define NUM_LEDS 37 11 | 12 | CRGB leds[NUM_LEDS]; 13 | uint8_t gHue = 0; 14 | 15 | void setup() { 16 | M5.begin(); 17 | 18 | M5.Lcd.setTextColor(YELLOW); 19 | M5.Lcd.setTextSize(2); 20 | M5.Lcd.setCursor(0, 5); 21 | M5.Lcd.println("HEX Example"); 22 | M5.Lcd.setTextColor(WHITE); 23 | M5.Lcd.setCursor(0, 70); 24 | M5.Lcd.println("Display rainbow effect"); 25 | 26 | // Neopixel initialization 27 | FastLED.addLeds(leds, NUM_LEDS) 28 | .setCorrection(TypicalLEDStrip); 29 | FastLED.setBrightness(10); 30 | } 31 | 32 | void loop() { 33 | fill_rainbow(leds, NUM_LEDS, gHue, 7); 34 | FastLED.show(); // must be executed for neopixel becoming effective 35 | EVERY_N_MILLISECONDS(20) { 36 | gHue++; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /examples/Unit/LASER/LASER.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: LASER Unit wireless UART application: burn the program to two 3 | M5StickCPlus    And connect LASER.TX and LASER.RX to PORT port respectively. 4 | Point LASER.TX to LASER.RX and press the button on the panel to send 5 | characters to the receiver of LASER.RX. 6 | */ 7 | 8 | #include 9 | void setup() { 10 | M5.begin(); 11 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 12 | // txPin, bool invert) 13 | Serial2.begin(9600, SERIAL_8N1, 33, 32); 14 | 15 | M5.Lcd.setTextSize(2); 16 | M5.Lcd.setTextColor(GREEN); 17 | 18 | M5.Lcd.setCursor(40, 5); 19 | M5.Lcd.print("LASER"); 20 | M5.Lcd.setCursor(40, 25); 21 | M5.Lcd.print("TX/RX"); 22 | M5.Lcd.setCursor(0, 50); // RX print set 23 | } 24 | 25 | void loop() { 26 | if (M5.BtnA.wasReleased()) { 27 | Serial2.write("Holle\r\n"); 28 | } 29 | M5.update(); 30 | if (Serial2.available()) { 31 | delay(2); 32 | String ch = Serial2.readString(); 33 | M5.Lcd.print(ch); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /examples/Unit/PaHUB/ClosedCube_TCA9548A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "ClosedCube_TCA9548A.h" 4 | 5 | ClosedCube::Wired::TCA9548A::TCA9548A() { 6 | } 7 | 8 | ClosedCube::Wired::TCA9548A::TCA9548A(uint8_t address) : _address(address) { 9 | } 10 | 11 | void ClosedCube::Wired::TCA9548A::address(uint8_t address) { 12 | _address = address; 13 | } 14 | 15 | uint8_t ClosedCube::Wired::TCA9548A::getChannel() { 16 | return _currentChannel; 17 | } 18 | 19 | uint8_t ClosedCube::Wired::TCA9548A::selectChannel(uint8_t channel) { 20 | uint8_t result = 0xff; 21 | if (channel < TCA9548A_MAX_CHANNELS) { 22 | Wire.beginTransmission(_address); 23 | Wire.write(((uint8_t)1) << (channel)); 24 | 25 | _currentChannel = channel; 26 | result = Wire.endTransmission(); 27 | } 28 | return result; 29 | } 30 | 31 | uint8_t ClosedCube::Wired::TCA9548A::nextChannel() { 32 | uint8_t nextChannel = _currentChannel + 1; 33 | if (nextChannel > (TCA9548A_MAX_CHANNELS - 1)) { 34 | nextChannel = 0; 35 | } 36 | 37 | return selectChannel(nextChannel); 38 | } 39 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /examples/Hat/ENVII_SHT30_BMP280/SHT3X.cpp: -------------------------------------------------------------------------------- 1 | #include "SHT3X.h" 2 | 3 | /* Motor() 4 | 5 | */ 6 | SHT3X::SHT3X(uint8_t address) { 7 | Wire.begin(); 8 | _address = address; 9 | } 10 | 11 | byte SHT3X::get() { 12 | unsigned int data[6]; 13 | 14 | // Start I2C Transmission 15 | Wire.beginTransmission(_address); 16 | // Send measurement command 17 | Wire.write(0x2C); 18 | Wire.write(0x06); 19 | // Stop I2C transmission 20 | if (Wire.endTransmission() != 0) return 1; 21 | 22 | delay(500); 23 | 24 | // Request 6 bytes of data 25 | Wire.requestFrom(_address, 6); 26 | 27 | // Read 6 bytes of data 28 | // cTemp msb, cTemp lsb, cTemp crc, humidity msb, humidity lsb, humidity crc 29 | for (int i = 0; i < 6; i++) { 30 | data[i] = Wire.read(); 31 | }; 32 | 33 | delay(50); 34 | 35 | if (Wire.available() != 0) return 2; 36 | 37 | // Convert the data 38 | cTemp = ((((data[0] * 256.0) + data[1]) * 175) / 65535.0) - 45; 39 | fTemp = (cTemp * 1.8) + 32; 40 | humidity = ((((data[3] * 256.0) + data[4]) * 100) / 65535.0); 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /examples/Hat/SPEAKER/SPEAKER.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int servo_pin = 26; 4 | int freq = 50; 5 | int ledChannel = 0; 6 | int resolution = 10; 7 | extern const unsigned char m5stack_startup_music[]; 8 | void setup() { 9 | // put your setup code here, to run once: 10 | M5.begin(); 11 | M5.Lcd.setRotation(0); 12 | M5.Lcd.setCursor(25, 80, 4); 13 | M5.Lcd.println("speaker"); 14 | ledcSetup(ledChannel, freq, resolution); 15 | ledcAttachPin(servo_pin, ledChannel); 16 | ledcWrite(ledChannel, 256); // 0° 17 | } 18 | void playMusic(const uint8_t* music_data, uint16_t sample_rate) { 19 | uint32_t length = strlen((char*)music_data); 20 | uint16_t delay_interval = ((uint32_t)1000000 / sample_rate); 21 | for (int i = 0; i < length; i++) { 22 | ledcWriteTone(ledChannel, music_data[i] * 50); 23 | delayMicroseconds(delay_interval); 24 | } 25 | } 26 | void loop() { 27 | // put your main code here, to run repeatedly: 28 | ledcWriteTone(ledChannel, 1250); 29 | delay(1000); 30 | ledcWriteTone(ledChannel, 0); 31 | delay(1000); 32 | } 33 | -------------------------------------------------------------------------------- /src/M5StickCPlus.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) M5Stack. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full 3 | // license information. 4 | 5 | #include "M5StickCPlus.h" 6 | 7 | M5StickCPlus::M5StickCPlus() : isInited(0) { 8 | } 9 | 10 | void M5StickCPlus::begin(bool LCDEnable, bool PowerEnable, bool SerialEnable) { 11 | //! Correct init once 12 | if (isInited) 13 | return; 14 | else 15 | isInited = true; 16 | 17 | //! UART 18 | if (SerialEnable) { 19 | Serial.begin(115200); 20 | Serial.flush(); 21 | delay(50); 22 | Serial.print("M5StickCPlus initializing..."); 23 | } 24 | 25 | // Power 26 | if (PowerEnable) { 27 | Axp.begin(); 28 | } 29 | 30 | // LCD INIT 31 | if (LCDEnable) { 32 | Lcd.begin(); 33 | } 34 | 35 | if (SerialEnable) { 36 | Serial.println("OK"); 37 | } 38 | 39 | Beep.begin(); 40 | 41 | Rtc.begin(); 42 | } 43 | 44 | void M5StickCPlus::update() { 45 | M5.BtnA.read(); 46 | M5.BtnB.read(); 47 | M5.Beep.update(); 48 | } 49 | 50 | M5StickCPlus M5; 51 | -------------------------------------------------------------------------------- /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/Unit/Light/Light.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | M5.begin(); 5 | // disable the speak noise 6 | // dacWrite(25, 0); 7 | M5.Lcd.setRotation(3); 8 | M5.Lcd.setTextColor(YELLOW); 9 | M5.Lcd.setTextSize(2); 10 | M5.Lcd.setCursor(10, 2); 11 | M5.Lcd.printf("UNIT_LIGHT EXAMPLE\n"); 12 | pinMode(32, INPUT); 13 | M5.Lcd.setCursor(10, 30); 14 | M5.Lcd.print("GPIO33:"); 15 | M5.Lcd.setCursor(10, 50); 16 | M5.Lcd.print("GPIO32:"); 17 | } 18 | 19 | uint16_t analogRead_value = 0; 20 | uint16_t digitalRead_value = 0; 21 | void loop() { 22 | // put your main code here, to run repeatedly: 23 | M5.Lcd.setCursor(105, 30); 24 | M5.Lcd.setTextColor(BLACK); 25 | M5.Lcd.printf("%d\n", analogRead_value); 26 | M5.Lcd.setCursor(105, 50); 27 | M5.Lcd.printf("%d\n", digitalRead_value); 28 | analogRead_value = analogRead(33); 29 | digitalRead_value = digitalRead(32); 30 | M5.Lcd.setTextColor(YELLOW); 31 | M5.Lcd.setCursor(105, 30); 32 | M5.Lcd.printf("%d\n", analogRead_value); 33 | M5.Lcd.setCursor(105, 50); 34 | M5.Lcd.printf("%d\n", digitalRead_value); 35 | delay(10); 36 | } 37 | -------------------------------------------------------------------------------- /examples/Unit/RS485_SP485EEN/RS485_SP485EEN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: Use RS485 Unit for serial communication, BtnA to send "Hello", 3 | and display the received content on the screen. 4 | */ 5 | #include 6 | #define RX_PIN 33 7 | #define TX_PIN 32 8 | 9 | int i = 0, s = 0; 10 | 11 | void header(const char *string, uint16_t color) { 12 | M5.Lcd.fillScreen(color); 13 | M5.Lcd.setTextSize(2); 14 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 15 | M5.Lcd.fillRect(0, 0, 80, 30, TFT_BLACK); 16 | M5.Lcd.setTextDatum(TC_DATUM); 17 | M5.Lcd.drawString(string, 70, 10); 18 | } 19 | 20 | void setup() { 21 | M5.begin(); 22 | header("RS485 Unit", TFT_BLACK); 23 | M5.Lcd.setTextSize(2); 24 | M5.Lcd.setCursor(0, 40); 25 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 26 | Serial.begin(115200); 27 | Serial2.begin(115200, SERIAL_8N1, RX_PIN, TX_PIN); 28 | delay(10); 29 | Serial2.read(); 30 | } 31 | 32 | void loop() { 33 | if (M5.BtnA.wasPressed()) { 34 | Serial2.write("Hello\n"); 35 | } 36 | if (Serial2.available()) { 37 | M5.Lcd.print(char(Serial2.read())); 38 | } 39 | delay(100); 40 | M5.update(); 41 | } 42 | -------------------------------------------------------------------------------- /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 | uint16_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 | typedef struct { // Data stored for FONT AS A WHOLE: 22 | uint8_t *bitmap; // Glyph bitmaps, concatenated 23 | GFXglyph *glyph; // Glyph array 24 | uint16_t first, last; // ASCII extents 25 | uint8_t yAdvance; // Newline distance (y axis) 26 | } GFXfont; 27 | 28 | #endif // LOAD_GFXFF 29 | 30 | #endif // _GFXFONT_H_ 31 | -------------------------------------------------------------------------------- /examples/Unit/IR/IR.ino: -------------------------------------------------------------------------------- 1 | #include 2 | // select the input pin for the potentiometer 3 | int ir_recv_pin = 33; 4 | int ir_send_pin = 32; 5 | int last_recv_value = 0; 6 | int cur_recv_value = 0; 7 | 8 | void setup() { 9 | M5.begin(); 10 | M5.Lcd.setRotation(3); 11 | pinMode(ir_recv_pin, INPUT); 12 | pinMode(ir_send_pin, OUTPUT); 13 | // send infrared light 14 | // now, you can see the infrared light through mobile phone camera 15 | digitalWrite(ir_send_pin, 1); 16 | // M5.Lcd.setTextSize(2); 17 | M5.Lcd.setCursor(0, 0); 18 | M5.Lcd.print("Test for IR receiver: "); 19 | } 20 | 21 | void loop() { 22 | // now, once you press the button on a remote controller to send infrared 23 | // light the screen will display "detected!" 24 | cur_recv_value = digitalRead(ir_recv_pin); 25 | if (last_recv_value != cur_recv_value) { 26 | M5.Lcd.setCursor(0, 25); 27 | M5.Lcd.fillRect(0, 25, 150, 25, BLACK); 28 | if (cur_recv_value == 0) { // 0: detected 1: not detected 29 | M5.Lcd.print("detected!"); 30 | } 31 | last_recv_value = cur_recv_value; 32 | } 33 | Serial.println(cur_recv_value); 34 | delay(100); 35 | } 36 | -------------------------------------------------------------------------------- /examples/Unit/WATERING/WATERING.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: Read the ADC value measured by the Watering Unit, and the water 3 | pump can be switched on and off through the middle button. 4 | */ 5 | 6 | #include 7 | 8 | #define INPUT_PIN 33 9 | #define PUMP_PIN 32 10 | 11 | bool flag = true; 12 | int rawADC; 13 | 14 | void setup() { 15 | M5.begin(); 16 | M5.Lcd.setTextSize(2); 17 | M5.Lcd.setTextColor(GREEN, BLACK); 18 | M5.Lcd.setTextDatum(TC_DATUM); 19 | M5.Lcd.drawString("Watering", 70, 10); 20 | M5.Lcd.drawString("TEST", 70, 40, 1); 21 | M5.Lcd.drawString("ON/OFF", 70, 190, 1); 22 | M5.Lcd.drawString("PUMP", 70, 210, 1); 23 | pinMode(INPUT_PIN, INPUT); 24 | pinMode(PUMP_PIN, OUTPUT); 25 | pinMode(25, OUTPUT); 26 | digitalWrite(25, 0); 27 | } 28 | 29 | char info[30]; 30 | 31 | void loop() { 32 | rawADC = analogRead(INPUT_PIN); 33 | M5.Lcd.setCursor(20, 100); 34 | M5.Lcd.print("ADC:" + String(rawADC)); 35 | Serial.print("Watering ADC value: "); 36 | Serial.println(rawADC); 37 | if (M5.BtnA.wasPressed()) { 38 | digitalWrite(PUMP_PIN, flag); 39 | flag = !flag; 40 | } 41 | M5.update(); 42 | delay(100); 43 | } 44 | -------------------------------------------------------------------------------- /examples/Hat/RS485_SP485EEN/RS485_SP485EEN.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* This demo is for RS485 Hat uart write and read , 4 | AutoSend Hello M5! AutoReceive and diaplay on screen */ 5 | 6 | void setup() { 7 | M5.begin(true, true, false); 8 | 9 | Serial.begin(115200); 10 | 11 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 12 | // txPin, bool invert) 13 | Serial2.begin(115200, SERIAL_8N1, 26, 0); 14 | // pinMode(5, OUTPUT); 15 | // digitalWrite(5, 1); 16 | M5.Lcd.setRotation(3); 17 | M5.Lcd.setTextSize(3); 18 | M5.Lcd.setTextColor(ORANGE); 19 | M5.Lcd.setCursor(0, 0); 20 | 21 | M5.Lcd.print("RS485 Demo"); 22 | Serial.println("RS485"); 23 | M5.Lcd.setTextSize(2); 24 | M5.Lcd.setCursor(10, 30); 25 | M5.Lcd.print("AutoSend Hello M5!"); 26 | 27 | M5.Lcd.setCursor(10, 50); 28 | M5.Lcd.print("AutoPrint Receive"); 29 | M5.Lcd.setCursor(10, 80); 30 | } 31 | 32 | void loop() { 33 | Serial2.print("Hello M5!"); 34 | Serial.println("RS485"); 35 | delay(500); 36 | 37 | if (Serial2.available()) { 38 | char ch = Serial2.read(); 39 | M5.Lcd.setTextSize(2); 40 | 41 | M5.Lcd.print(ch); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/Unit/LIMIT/LIMIT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2022 by M5Stack 4 | * Equipped with M5StickC Plus sample source code 5 | * 配套 M5StickC Plus 示例源代码 6 | * Visit for more information: 7 | * 获取更多资料请访问: 8 | * 9 | * Product: Limit. 10 | * Date: 2022/6/1 11 | ******************************************************************************* 12 | 如果按键按下,在屏幕上显示输出,否则显示为空白 13 | If the key is pressed, the output is displayed on the screen, otherwise the 14 | display is blank 15 | */ 16 | 17 | #include 18 | 19 | #define KEY_PIN 33 // Define Limit Pin. 定义Limit连接引脚 20 | 21 | void setup() { 22 | M5.begin(); // Init M5Stack 初始化M5Stack 23 | M5.Lcd.setCursor(0, 25, 2); 24 | M5.Lcd.print((" UNIT-LIMIT\n Example\n\n")); 25 | 26 | pinMode(KEY_PIN, INPUT_PULLUP); // Init Limit pin. 初始化Limit引脚. 27 | } 28 | 29 | void loop() { 30 | if (!digitalRead(KEY_PIN)) { // If Limit was hit. 如果触碰了Limit. 31 | M5.Lcd.setCursor(0, 100); 32 | M5.Lcd.print((" Hit limit!")); 33 | } else { 34 | M5.Lcd.setCursor(0, 100); 35 | M5.Lcd.println((" ")); 36 | } 37 | delay(100); 38 | } 39 | -------------------------------------------------------------------------------- /examples/Unit/PIR/PIR.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void setup() { 4 | M5.begin(); 5 | M5.Lcd.setRotation(3); 6 | M5.Lcd.setTextColor(YELLOW); 7 | M5.Lcd.setCursor(50, 0); 8 | M5.Lcd.setTextSize(2); 9 | M5.Lcd.println("PIR example"); 10 | Serial.println("PIR example: "); 11 | M5.Lcd.setCursor(65, 10); 12 | M5.Lcd.setTextColor(WHITE); 13 | pinMode(33, INPUT); 14 | } 15 | 16 | void loop() { 17 | M5.Lcd.setCursor(10, 25); 18 | M5.Lcd.print("Status: "); 19 | M5.Lcd.setCursor(10, 45); 20 | M5.Lcd.print("Value: "); 21 | 22 | M5.Lcd.fillRect(105, 25, 200, 25, BLACK); 23 | M5.Lcd.fillRect(105, 45, 200, 25, BLACK); 24 | 25 | if (digitalRead(33) == 1) { 26 | M5.Lcd.setCursor(105, 25); 27 | M5.Lcd.print("Sensing"); 28 | M5.Lcd.setCursor(105, 45); 29 | M5.Lcd.print("1"); 30 | Serial.println("PIR Status: Sensing"); 31 | Serial.println(" value: 1"); 32 | } else { 33 | M5.Lcd.setCursor(105, 25); 34 | M5.Lcd.print("Not Sensed"); 35 | M5.Lcd.setCursor(105, 45); 36 | M5.Lcd.print("0"); 37 | Serial.println("PIR Status: Not Sensed"); 38 | Serial.println(" value: 0"); 39 | } 40 | delay(500); 41 | M5.update(); 42 | } 43 | -------------------------------------------------------------------------------- /examples/Unit/PbHUB/porthub.h: -------------------------------------------------------------------------------- 1 | #ifndef __PORTHUB_H__ 2 | #define __PORTHUB_H__ 3 | 4 | #include 5 | 6 | #define IIC_ADDR 0x61 7 | #define HUB1_ADDR 0x40 8 | #define HUB2_ADDR 0x50 9 | #define HUB3_ADDR 0x60 10 | #define HUB4_ADDR 0x70 11 | #define HUB5_ADDR 0x80 12 | #define HUB6_ADDR 0xA0 13 | 14 | class PortHub { 15 | public: 16 | PortHub(); 17 | void begin(); 18 | 19 | uint16_t hub_a_read_value(uint8_t reg); 20 | 21 | uint8_t hub_d_read_value_A(uint8_t reg); 22 | uint8_t hub_d_read_value_B(uint8_t reg); 23 | 24 | void hub_d_wire_value_A(uint8_t reg, uint16_t level); 25 | void hub_d_wire_value_B(uint8_t reg, uint16_t level); 26 | 27 | void hub_a_wire_value_A(uint8_t reg, uint16_t duty); 28 | void hub_a_wire_value_B(uint8_t reg, uint16_t duty); 29 | 30 | void hub_wire_length(uint8_t reg, uint16_t length); 31 | 32 | void hub_wire_index_color(uint8_t reg, uint16_t num, uint8_t r, int8_t g, 33 | uint8_t b); 34 | 35 | void hub_wire_fill_color(uint8_t reg, uint16_t first, uint16_t count, 36 | uint8_t r, int8_t g, uint8_t b); 37 | 38 | void hub_wire_setBrightness(uint8_t reg, uint8_t brightness); 39 | 40 | public: 41 | private: 42 | private: 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /examples/Hat/DAC_ADS1100/Adafruit_MCP4725.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************/ 2 | /*! 3 | @file Adafruit_MCP4725.h 4 | @author K. Townsend (Adafruit Industries) 5 | @license BSD (see license.txt) 6 | 7 | This is a library for the Adafruit MCP4725 breakout board 8 | ----> http://www.adafruit.com/products/935 9 | 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | @section HISTORY 15 | 16 | v1.0 - First release 17 | */ 18 | /**************************************************************************/ 19 | 20 | #if ARDUINO >= 100 21 | #include "Arduino.h" 22 | #else 23 | #include "WProgram.h" 24 | #endif 25 | 26 | #include 27 | 28 | #define MCP4726_CMD_WRITEDAC (0x40) // Writes data to the DAC 29 | #define MCP4726_CMD_WRITEDACEEPROM \ 30 | (0x60) // Writes data to the DAC and the EEPROM (persisting the assigned 31 | // value after reset) 32 | 33 | class Adafruit_MCP4725 { 34 | public: 35 | Adafruit_MCP4725(); 36 | void begin(uint8_t a); 37 | void setVoltage(uint16_t output, bool writeEEPROM); 38 | 39 | private: 40 | uint8_t _i2caddr; 41 | }; 42 | -------------------------------------------------------------------------------- /src/RTC.h: -------------------------------------------------------------------------------- 1 | #ifndef __RTC_H__ 2 | #define __RTC_H__ 3 | 4 | #include 5 | 6 | typedef struct { 7 | uint8_t Hours; 8 | uint8_t Minutes; 9 | uint8_t Seconds; 10 | } RTC_TimeTypeDef; 11 | 12 | typedef struct { 13 | uint8_t WeekDay; 14 | uint8_t Month; 15 | uint8_t Date; 16 | uint16_t Year; 17 | } RTC_DateTypeDef; 18 | 19 | class RTC { 20 | public: 21 | RTC(); 22 | 23 | void begin(void); 24 | void GetBm8563Time(void); 25 | 26 | void SetTime(RTC_TimeTypeDef* RTC_TimeStruct); 27 | void SetDate(RTC_DateTypeDef* RTC_DateStruct); 28 | 29 | void GetTime(RTC_TimeTypeDef* RTC_TimeStruct); 30 | void GetDate(RTC_DateTypeDef* RTC_DateStruct); 31 | 32 | public: 33 | uint8_t Second; 34 | uint8_t Minute; 35 | uint8_t Hour; 36 | uint8_t Week; 37 | uint8_t Day; 38 | uint8_t Month; 39 | uint8_t Year; 40 | uint8_t DateString[9]; 41 | uint8_t TimeString[9]; 42 | 43 | uint8_t asc[14]; 44 | 45 | private: 46 | void Bcd2asc(void); 47 | void DataMask(); 48 | void Str2Time(void); 49 | 50 | uint8_t Bcd2ToByte(uint8_t Value); 51 | uint8_t ByteToBcd2(uint8_t Value); 52 | 53 | private: 54 | /*定义数组用来存储读取的时间数据 */ 55 | uint8_t trdata[7]; 56 | /*定义数组用来存储转换的 asc 码时间数据*/ 57 | // uint8_t asc[14]; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /examples/Hat/YUN/SHT20.h: -------------------------------------------------------------------------------- 1 | #ifndef SHT20_h 2 | #define SHT20_h 3 | 4 | #include 5 | #include 6 | 7 | #define SHT20_ADDR 0x40 8 | 9 | #define TRIGGER_TEMP_MEASURE_HOLD 0xE3 10 | #define TRIGGER_HUMD_MEASURE_HOLD 0xE5 11 | #define TRIGGER_TEMP_MEASURE_NOHOLD 0xF3 12 | #define TRIGGER_HUMD_MEASURE_NOHOLD 0xF5 13 | #define WRITE_USER_REG 0xE6 14 | #define READ_USER_REG 0xE7 15 | #define SOFT_RESET 0xFE 16 | #define REG_RESOLUTION_MASK 0x81 17 | #define REG_RESOLUTION_RH12_TEMP14 0x00 18 | #define REG_RESOLUTION_RH8_TEMP12 0x01 19 | #define REG_RESOLUTION_RH10_TEMP13 0x80 20 | #define REG_RESOLUTION_RH11_TEMP11 0x81 21 | #define REG_END_OF_BATTERY 0x40 22 | #define REG_HEATER_ENABLED 0x04 23 | #define REG_DISABLE_OTP_RELOAD 0x02 24 | #define MAX_WAIT 100 25 | #define DELAY_INTERVAL 10 26 | #define SHIFTED_DIVISOR 0x988000 27 | 28 | class SHT20 { 29 | public: 30 | void set_resolution(uint8_t resBits); 31 | float read_humidity(void); 32 | float read_temperature(void); 33 | void write_register(uint8_t val); 34 | uint8_t read_register(void); 35 | 36 | private: 37 | bool check_crc(uint16_t data_in, uint8_t crc); 38 | bool I2C_read_u16(uint8_t reg, uint16_t *val); 39 | }; 40 | 41 | #endif -------------------------------------------------------------------------------- /examples/Unit/EXT_IO/PCA9554.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | Title: PCA9554 3 | by: AD0ND 4 | 5 | This file is free software; you can redistribute it and/or modify 6 | it under the terms of either the GNU General Public License version 2 7 | or the GNU Lesser General Public License version 2.1, both as 8 | published by the Free Software Foundation. 9 | ***************************************************************************/ 10 | 11 | #ifndef PCA9554_h 12 | #define PCA9554_h 13 | 14 | #include 15 | #include 16 | 17 | // PCA9554 Command Byte 18 | #define INPUTPORT0 0x00 19 | #define OUTPUTPORT0 0x01 20 | #define POLINVPORT0 0x02 21 | #define CONFIGPORT0 0x03 22 | 23 | #define ALLOUTPUT 0x00 24 | #define ALLINPUT 0xFF 25 | 26 | class PCA9554 { 27 | public: 28 | PCA9554(byte SlaveAddress); 29 | 30 | bool twiRead(byte ®isterAddress); 31 | bool twiWrite(byte registerAddress, byte dataWrite); 32 | 33 | bool pinMode0(byte pinNumber, bool state); 34 | bool portMode0(byte value); 35 | 36 | bool digitalWrite0(byte pinNumber, bool state); 37 | bool digitalWritePort0(byte value); 38 | 39 | bool digitalRead0(byte &pinNumber); 40 | bool digitalReadPort0(byte &value); 41 | 42 | private: 43 | int _SlaveAddress; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /examples/Unit/MIC_LM393_MAX4466/MIC_LM393_MAX4466.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Free_Fonts.h" 3 | #define MIC_Unit 33 4 | #define MAX_LEN 240 5 | #define X_OFFSET 0 6 | #define Y_OFFSET 75 7 | #define X_SCALE 1 8 | 9 | static void draw_waveform() { 10 | static int16_t val_buf[MAX_LEN] = {0}; 11 | static int16_t pt = MAX_LEN - 1; 12 | int micValue = analogRead(MIC_Unit); 13 | val_buf[pt] = map((int16_t)(micValue * X_SCALE), 1800, 4095, 0, 135); 14 | 15 | if (--pt < 0) { 16 | pt = MAX_LEN - 1; 17 | } 18 | 19 | for (int i = 1; i < (MAX_LEN); i++) { 20 | uint16_t now_pt = (pt + i) % (MAX_LEN); 21 | M5.Lcd.drawLine(i + X_OFFSET, 22 | val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET, 23 | i + 1 + X_OFFSET, 24 | val_buf[(now_pt + 2) % MAX_LEN] + Y_OFFSET, TFT_BLACK); 25 | if (i < MAX_LEN - 1) { 26 | M5.Lcd.drawLine( 27 | i + X_OFFSET, val_buf[now_pt] + Y_OFFSET, i + 1 + X_OFFSET, 28 | val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET, TFT_GREEN); 29 | } 30 | } 31 | } 32 | 33 | void setup() { 34 | M5.begin(); 35 | M5.Lcd.setRotation(3); 36 | 37 | dacWrite(25, 0); 38 | } 39 | 40 | void loop() { 41 | draw_waveform(); 42 | } 43 | -------------------------------------------------------------------------------- /examples/Basics/HelloWorld/HelloWorld.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: Hello World. 10 | * Date: 2021/9/14 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | /* After M5StickC Plus is started or reset 16 | the program in the setUp () function will be run, and this part will only be 17 | run once. 在 M5StickC Plus 18 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 19 | void setup() { 20 | M5.begin(); // Initialize M5StickC Plus. 初始化 M5StickC PLus 21 | M5.Lcd.setTextSize(3); // Set font size. 设置字体大小 22 | M5.Lcd.setRotation(3); // Rotate the screen. 将屏幕旋转 23 | // LCD display. Lcd显示 24 | M5.Lcd.print("Hello World"); 25 | } 26 | 27 | /* After the program in setup() runs, it runs the program in loop() 28 | The loop() function is an infinite loop in which the program runs repeatedly 29 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 30 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 31 | void loop() { 32 | } -------------------------------------------------------------------------------- /examples/Advanced/MultSerial/MultSerial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: MultSerial. 多串口 10 | * Date: 2021/9/18 11 | ****************************************************************************** 12 | */ 13 | #include 14 | 15 | void setup() { 16 | M5.begin(); 17 | // Serial2.begin(unsigned long baud, uint32_t config, int8_t rxPin, int8_t 18 | // txPin, bool invert) 19 | Serial2.begin(115200, SERIAL_8N1, 16, 20 | 17); // Init serial port 2. 初始化串口2 21 | } 22 | 23 | void loop() { 24 | if (Serial 25 | .available()) { // If the serial port reads data. 如果串口读到数据 26 | int ch = Serial.read(); // Copy the data read from the serial port to 27 | // the CH. 把串口读取到的数据复制给ch 28 | Serial2.write( 29 | ch); // Serial port 2 Outputs the CH content. 串口2输出ch的内容 30 | } 31 | 32 | if (Serial2.available()) { 33 | int ch = Serial2.read(); 34 | Serial.write(ch); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/Hat/DAC_ADS1100/DAC_ADS1100.ino: -------------------------------------------------------------------------------- 1 | /* 2 | hardware : m5stack uint dac 3 | 4 | please install adafruit MCP4725 lib 5 | */ 6 | 7 | #include 8 | #include 9 | #include "Adafruit_MCP4725.h" 10 | 11 | #define DAC_ADDR 12 | Adafruit_MCP4725 dac; 13 | 14 | void setup(void) { 15 | M5.begin(true, true, false); 16 | Serial.begin(115200); 17 | Serial.println("Hello!"); 18 | M5.Lcd.fillScreen(BLACK); 19 | M5.Lcd.setTextColor(ORANGE); 20 | M5.Lcd.drawString("DAC Generate.", 25, 10, 2); 21 | // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin 22 | // tied to VCC) For MCP4725A0 the address is 0x60 or 0x61 For MCP4725A2 the 23 | // address is 0x64 or 0x65 24 | dac.begin(0x60); 25 | 26 | Serial.println("Generating a triangle wave"); 27 | dac.setVoltage(2048, false); 28 | } 29 | 30 | void loop(void) { 31 | // 12bit value , false mean not write EEPROM 32 | 33 | dac.setVoltage(1024, false); 34 | M5.Lcd.setTextColor(ORANGE); 35 | M5.Lcd.drawString("2048", 35, 40, 4); 36 | M5.Lcd.setTextColor(WHITE); 37 | M5.Lcd.drawString("1024", 35, 80, 4); 38 | delay(2000); 39 | 40 | dac.setVoltage(2048, false); 41 | M5.Lcd.setTextColor(WHITE); 42 | M5.Lcd.drawString("2048", 35, 40, 4); 43 | M5.Lcd.setTextColor(ORANGE); 44 | M5.Lcd.drawString("1024", 35, 80, 4); 45 | delay(2000); 46 | } 47 | -------------------------------------------------------------------------------- /examples/Unit/BUTTON/BUTTON.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int button = 33; 4 | int last_value = 0; 5 | int cur_value = 0; 6 | 7 | void setup() { 8 | // init lcd 9 | M5.begin(); 10 | M5.Lcd.setRotation(3); 11 | pinMode(button, INPUT); 12 | M5.Lcd.setTextColor(YELLOW); 13 | M5.Lcd.setCursor(60, 0, 2); 14 | M5.Lcd.println("Button example"); 15 | Serial.println("Button example: "); 16 | M5.Lcd.setTextColor(WHITE); 17 | } 18 | 19 | void loop() { 20 | cur_value = digitalRead(button); // read the value of BUTTON 21 | 22 | M5.Lcd.setCursor(40, 25, 2); 23 | M5.Lcd.print("Status: "); 24 | M5.Lcd.setCursor(40, 45, 2); 25 | M5.Lcd.print("Value: "); 26 | if (cur_value != last_value) { 27 | M5.Lcd.fillRect(135, 25, 100, 25, BLACK); 28 | M5.Lcd.fillRect(135, 45, 100, 25, BLACK); 29 | if (cur_value == 0) { 30 | M5.Lcd.setCursor(135, 25, 2); 31 | M5.Lcd.print("pressed"); // display the status 32 | M5.Lcd.setCursor(135, 45, 2); 33 | M5.Lcd.print("0"); 34 | Serial.println("Button Status: pressed"); 35 | Serial.println(" value: 0"); 36 | } else { 37 | M5.Lcd.setCursor(135, 25, 2); 38 | M5.Lcd.print("released"); // display the status 39 | M5.Lcd.setCursor(135, 45, 2); 40 | M5.Lcd.print("1"); 41 | Serial.println("Button Status: released"); 42 | Serial.println(" value: 1"); 43 | } 44 | last_value = cur_value; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/SPIFFS/SPIFFS_Delete/SPIFFS_Delete.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: SPIFFS Delete 10 | * Date: 2021/9/18 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(); 22 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 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/Unit/IMU_MPU6886/IMU_MPU6886.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #include "IMU_6886.h" 6 | } 7 | #endif 8 | 9 | IMU_6886 imu6886; 10 | 11 | float accX = 0; 12 | float accY = 0; 13 | float accZ = 0; 14 | 15 | float gyroX = 0; 16 | float gyroY = 0; 17 | float gyroZ = 0; 18 | 19 | float pitch = 0.0F; 20 | float roll = 0.0F; 21 | float yaw = 0.0F; 22 | 23 | float temp = 0; 24 | 25 | void setup() { 26 | // put your setup code here, to run once: 27 | M5.begin(); 28 | M5.Lcd.setRotation(3); 29 | M5.Lcd.fillScreen(BLACK); 30 | M5.Lcd.setTextSize(2); 31 | M5.Lcd.setCursor(40, 5); 32 | M5.Lcd.println("MPU6886 TEST"); 33 | M5.Lcd.setTextSize(1); 34 | M5.Lcd.setCursor(50, 30); 35 | M5.Lcd.println(" X Y Z"); 36 | M5.Lcd.setCursor(45, 90); 37 | M5.Lcd.println(" Pitch Roll Yaw"); 38 | imu6886.Init(32, 33); 39 | } 40 | 41 | void loop() { 42 | // put your main code here, to run repeatedly: 43 | imu6886.getGyroData(&gyroX, &gyroY, &gyroZ); 44 | imu6886.getAccelData(&accX, &accY, &accZ); 45 | imu6886.getTempData(&temp); 46 | imu6886.getAhrsData(&pitch, &roll, &yaw); 47 | M5.Lcd.setCursor(45, 45); 48 | M5.Lcd.printf("%.2f %.2f %.2f ", gyroX, gyroY, gyroZ); 49 | M5.Lcd.setCursor(185, 45); 50 | M5.Lcd.print("o/s"); 51 | M5.Lcd.setCursor(45, 60); 52 | M5.Lcd.printf("%.2f %.2f %.2f ", accX, accY, accZ); 53 | M5.Lcd.setCursor(185, 60); 54 | M5.Lcd.print("G"); 55 | M5.Lcd.setCursor(45, 75); 56 | M5.Lcd.printf("Temperature : %.2f C", temp); 57 | M5.Lcd.setCursor(45, 105); 58 | M5.Lcd.printf(" %5.2f %5.2f %5.2f ", pitch, roll, yaw); 59 | delay(100); 60 | } 61 | -------------------------------------------------------------------------------- /examples/Unit/PaHUB/PaHUB.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "ClosedCube_TCA9548A.h" 4 | 5 | #define FRONT 1 6 | 7 | //#define X_LOCAL 40 8 | //#define Y_LOCAL 10 9 | //#define X_OFFSET 160 10 | //#define Y_OFFSET 30 11 | 12 | #define X_LOCAL 40 13 | #define Y_LOCAL 10 14 | #define X_OFFSET 160 15 | #define Y_OFFSET 20 16 | 17 | #define PaHub_I2C_ADDRESS 0x70 18 | 19 | ClosedCube::Wired::TCA9548A tca9548a; 20 | 21 | void setup() { 22 | M5.begin(); 23 | Wire.begin(); 24 | M5.Lcd.fillScreen(TFT_BLACK); 25 | M5.Lcd.setRotation(3); 26 | tca9548a.address(PaHub_I2C_ADDRESS); 27 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 28 | M5.Lcd.setTextSize(2); 29 | } 30 | 31 | void PaHUB(void) { 32 | uint8_t returnCode = 0; 33 | uint8_t address; 34 | for (uint8_t channel = 0; channel < TCA9548A_MAX_CHANNELS; channel++) { 35 | M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT); 36 | M5.Lcd.printf( 37 | " "); 38 | M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET * channel, FRONT); 39 | M5.Lcd.printf("CH%d : ", channel); 40 | returnCode = tca9548a.selectChannel(channel); 41 | if (returnCode == 0) { 42 | for (address = 0x01; address < 0x7F; address++) { 43 | Wire.beginTransmission(address); 44 | returnCode = Wire.endTransmission(); 45 | if (returnCode == 0) { 46 | Serial.print("I2C device = "); 47 | M5.Lcd.printf("0X%X ", address); 48 | } 49 | } 50 | } 51 | delay(100); 52 | } 53 | } 54 | 55 | void loop() { 56 | PaHUB(); 57 | } 58 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/Hat/VIBRATOR/VIBRATOR.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define CTRL_PIN 26 4 | 5 | enum Vibrate_mode_t { 6 | stop = 0, 7 | weak, 8 | medium, 9 | strong, 10 | very_strong, 11 | strongest, 12 | }; 13 | static uint8_t mode = stop; 14 | 15 | void Vibrator_hat_update() { 16 | ledcWrite(1, mode * 51); 17 | 18 | M5.Lcd.setRotation(1); 19 | M5.Lcd.setTextSize(3); 20 | M5.Lcd.setTextColor(TFT_ORANGE, TFT_BLACK); 21 | M5.Lcd.setCursor(0, 0); 22 | M5.Lcd.printf(" VIBRATOR HAT\n"); 23 | M5.Lcd.printf(" G%d PWM:%3d%%", CTRL_PIN, ledcRead(1) / 51 * 20); 24 | M5.Lcd.printf("\n\n Press\n ->"); 25 | 26 | M5.Lcd.fillRoundRect(110, 70, 20, 50, 1, 27 | (mode >= weak ? TFT_GREEN : TFT_BLACK)); 28 | M5.Lcd.fillRoundRect(86, 70, 20, 50, 1, 29 | (mode >= medium ? TFT_GREENYELLOW : TFT_BLACK)); 30 | M5.Lcd.fillRoundRect(62, 70, 20, 50, 1, 31 | (mode >= strong ? TFT_YELLOW : TFT_BLACK)); 32 | M5.Lcd.fillRoundRect(38, 70, 20, 50, 1, 33 | (mode >= very_strong ? TFT_ORANGE : TFT_BLACK)); 34 | M5.Lcd.fillRoundRect(14, 70, 20, 50, 1, 35 | (mode >= strongest ? TFT_RED : TFT_BLACK)); 36 | } 37 | 38 | void setup() { 39 | M5.begin(); 40 | 41 | ledcAttachPin(CTRL_PIN, 1); 42 | ledcSetup(1, 10000, 8); 43 | 44 | Vibrator_hat_update(); 45 | } 46 | 47 | void loop() { 48 | if (M5.BtnA.isPressed()) { 49 | mode++; 50 | if (mode > strongest) mode = stop; 51 | while (M5.BtnA.read()) 52 | ; 53 | Vibrator_hat_update(); 54 | } 55 | 56 | delay(50); 57 | M5.update(); 58 | } 59 | -------------------------------------------------------------------------------- /examples/Unit/EXT_IO/EXT_IO.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "PCA9554.h" // Load the PCA9554 Library 3 | 4 | PCA9554 ioCon1(0x27); // Create an object at this address 5 | 6 | uint8_t res; 7 | void setup() { 8 | M5.begin(); 9 | Wire.begin(); 10 | // M5.Lcd.clear(BLACK); 11 | M5.Lcd.setRotation(3); 12 | M5.Lcd.setTextSize(2); 13 | M5.Lcd.setTextColor(YELLOW); 14 | M5.Lcd.setCursor(32, 2); 15 | M5.Lcd.print("UNIT_IO EXAMPLE\n"); 16 | 17 | ioCon1.twiWrite(32, 33); 18 | delay(10); 19 | res = 1; 20 | ioCon1.twiRead(res); 21 | Serial.printf("res:%d\r\n", res); 22 | 23 | ioCon1.portMode0(ALLOUTPUT); // Set the port as all output 24 | } 25 | 26 | void loop() { 27 | // write single, the same read 28 | ioCon1.digitalWrite0(0, LOW); 29 | ioCon1.digitalWrite0(1, LOW); 30 | ioCon1.digitalWrite0(2, LOW); 31 | ioCon1.digitalWrite0(3, LOW); 32 | ioCon1.digitalWrite0(4, LOW); 33 | ioCon1.digitalWrite0(5, LOW); 34 | ioCon1.digitalWrite0(6, LOW); 35 | ioCon1.digitalWrite0(7, LOW); 36 | delay(1000); 37 | ioCon1.digitalWrite0(0, HIGH); 38 | ioCon1.digitalWrite0(1, HIGH); 39 | ioCon1.digitalWrite0(2, HIGH); 40 | ioCon1.digitalWrite0(3, HIGH); 41 | ioCon1.digitalWrite0(4, HIGH); 42 | ioCon1.digitalWrite0(5, HIGH); 43 | ioCon1.digitalWrite0(6, HIGH); 44 | ioCon1.digitalWrite0(7, HIGH); 45 | delay(1000); 46 | 47 | // write 0-7 HIGHT 48 | Serial.println(ioCon1.digitalWritePort0(0xff)); 49 | delay(200); 50 | 51 | // write 0-7 LOW 52 | Serial.println(ioCon1.digitalWritePort0(0x00)); 53 | delay(200); 54 | 55 | //// write Port, the same read 56 | for (byte i = 0; i < 8; i++) { 57 | ioCon1.digitalWritePort0((1 << i)); 58 | delay(200); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /examples/Hat/BUGC/bugC.h: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Sorzn 3 | * @Date: 2019-11-22 13:38:31 4 | * @LastEditTime: 2019-11-22 14:33:56 5 | * @Description: M5Stack Hat BUGC Lib 6 | * @FilePath: /M5StickC/examples/Hat/BUGC/bugC.h 7 | */ 8 | 9 | #ifndef __BUG_C_H 10 | #define __BUG_C_H 11 | 12 | #include "Arduino.h" 13 | 14 | #define BUGC_ADDR 0x38 15 | 16 | #define FRONT_LEFT 0 17 | #define FRONT_RIGHT 1 18 | #define REAR_LEFT 2 19 | #define REAR_RIGHT 3 20 | 21 | class BUGC { 22 | public: 23 | void Init(); 24 | /** 25 | * @description: Set BugC single motor speed 26 | * @param pos: 0 ~ 3 27 | * @param speed: -100 ~ 100 28 | * @return: 29 | */ 30 | void BugCSetSpeed(uint8_t pos, int8_t speed); 31 | 32 | /** 33 | * @description: Set BugC motor speed 34 | * @param speed_0: -100 ~ 100 35 | * @param speed_1: -100 ~ 100 36 | * @param speed_2: -100 ~ 100 37 | * @param speed_3: -100 ~ 100 38 | * @return: 39 | */ 40 | void BugCSetAllSpeed(int8_t speed_0, int8_t speed_1, int8_t speed_2, 41 | int8_t speed_3); 42 | 43 | /** 44 | * @description: Set BugC sk6812 color 45 | * @param color_left: (r << 16) | (g << 8) | b 46 | * @param color_right: (r << 16) | (g << 8) | b 47 | * @return: 48 | */ 49 | void BugCSetColor(uint32_t color_left, uint32_t color_right); 50 | 51 | private: 52 | void Write1Byte(uint8_t address, uint8_t Register_address, uint8_t data); 53 | void Write2Byte(uint8_t address, uint8_t Register_address, uint16_t data); 54 | void WriteBytes(uint8_t address, uint8_t Register_address, uint8_t* data, 55 | size_t size); 56 | uint8_t ReadBytes(uint8_t address, uint8_t subAddress, uint8_t count, 57 | uint8_t* dest); 58 | }; 59 | 60 | #endif -------------------------------------------------------------------------------- /examples/Hat/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/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/Hat/YUN/yunBoard.cpp: -------------------------------------------------------------------------------- 1 | #include "yunBoard.h" 2 | #include "Wire.h" 3 | #define YUN_ADDR 0x38 4 | #define LED_REG_ADDR 0x01 5 | #define LIGHT_REG_ADDR 0x00 6 | 7 | bool I2C_writeBytes(uint8_t address, uint8_t subAddress, uint8_t *data, 8 | uint8_t length) { 9 | bool function_result = false; 10 | 11 | Wire.beginTransmission(address); // Initialize the Tx buffer 12 | Wire.write(subAddress); // Put slave register address in Tx buffer 13 | for (int i = 0; i < length; i++) { 14 | Wire.write(*(data + i)); // Put data in Tx buffer 15 | } 16 | function_result = (Wire.endTransmission() == 0); // Send the Tx buffer 17 | 18 | return (Wire.endTransmission() == 0); // Send the Tx buffer 19 | } 20 | 21 | bool I2C_readBytes(uint8_t address, uint8_t subAddress, uint8_t count, 22 | uint8_t *dest) { 23 | Wire.beginTransmission(address); // Initialize the Tx buffer 24 | Wire.write(subAddress); // Put slave register address in Tx buffer 25 | Wire.endTransmission(true); 26 | 27 | Wire.requestFrom(address, (uint8_t)count); 28 | uint8_t i = 0; 29 | while (Wire.available()) { 30 | dest[i++] = Wire.read(); // Put read results in the Rx buffer 31 | } 32 | return false; 33 | } 34 | 35 | // RGB888 36 | void led_set(uint8_t num, uint32_t color_in) { 37 | uint8_t data_out[4] = {0x00}; 38 | data_out[0] = num; 39 | data_out[1] = color_in >> 16; 40 | data_out[2] = color_in >> 8; 41 | data_out[3] = (uint8_t)color_in; 42 | I2C_writeBytes(YUN_ADDR, LED_REG_ADDR, data_out, 4); 43 | } 44 | 45 | void led_set_all(uint32_t color_in) { 46 | led_set(14, color_in); 47 | } 48 | 49 | uint16_t light_get() { 50 | uint16_t light = 0x00; 51 | I2C_readBytes(YUN_ADDR, LIGHT_REG_ADDR, 2, (uint8_t *)&light); 52 | return light; 53 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/Games/Dices/Dices.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | A couple of dices on a tiny 80x160px TFT display 4 | 5 | Author: Alfonso de Cala 6 | 7 | */ 8 | 9 | #include 10 | 11 | #define DOT_SIZE 6 12 | int dot[6][6][2]{ 13 | {{35, 35}}, 14 | {{15, 15}, {55, 55}}, 15 | {{15, 15}, {35, 35}, {55, 55}}, 16 | {{15, 15}, {15, 55}, {55, 15}, {55, 55}}, 17 | {{15, 15}, {15, 55}, {35, 35}, {55, 15}, {55, 55}}, 18 | {{15, 15}, {15, 35}, {15, 55}, {55, 15}, {55, 35}, {55, 55}}, 19 | }; 20 | 21 | float accX = 0; 22 | float accY = 0; 23 | float accZ = 0; 24 | 25 | void setup(void) { 26 | M5.begin(); 27 | M5.IMU.Init(); 28 | 29 | M5.Lcd.setRotation(1); 30 | 31 | M5.Lcd.fillScreen(TFT_GREEN); 32 | 33 | M5.Lcd.setTextColor(TFT_BLACK); // Adding a background colour erases 34 | // previous text automatically 35 | 36 | M5.Lcd.setCursor(10, 30); 37 | M5.Lcd.setTextSize(3); 38 | M5.Lcd.print("SHAKE ME"); 39 | delay(1000); 40 | } 41 | 42 | void draw_dice(int16_t x, int16_t y, int n) { 43 | M5.Lcd.fillRect(x, y, 70, 70, WHITE); 44 | 45 | for (int d = 0; d < 6; d++) { 46 | if (dot[n][d][0] > 0) { 47 | M5.Lcd.fillCircle(x + dot[n][d][0], y + dot[n][d][1], DOT_SIZE, 48 | TFT_BLACK); 49 | } 50 | } 51 | } 52 | 53 | void loop() { 54 | while (1) { 55 | M5.IMU.getAccelData(&accX, &accY, &accZ); 56 | if (accX > 1.5 || accY > 1.5) { 57 | break; 58 | } 59 | } 60 | 61 | M5.Lcd.fillScreen(TFT_GREEN); 62 | 63 | // Draw first dice 64 | delay(500); // A little delay to increase suspense :-D 65 | int number = random(0, 6); 66 | draw_dice(50, 30, number); 67 | 68 | // Draw second dice 69 | delay(500); 70 | number = random(0, 6); 71 | draw_dice(125, 30, number); 72 | } 73 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/Unit/RGB_LED/display_rainbow/display_rainbow.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Please install FastLED library first. 3 | In arduino library manage search FastLED 4 | */ 5 | #include 6 | #include "FastLED.h" 7 | 8 | #define Neopixel_PIN 32 9 | #define NUM_LEDS 30 10 | 11 | CRGB leds[NUM_LEDS]; 12 | uint8_t gHue = 0; 13 | static TaskHandle_t FastLEDshowTaskHandle = 0; 14 | static TaskHandle_t userTaskHandle = 0; 15 | 16 | void setup() { 17 | M5.begin(); 18 | // M5.Lcd.clear(BLACK); 19 | M5.Lcd.setRotation(3); 20 | M5.Lcd.setTextColor(YELLOW); 21 | M5.Lcd.setTextSize(2); 22 | M5.Lcd.setCursor(20, 2); 23 | M5.Lcd.println("Neopixel Example"); 24 | M5.Lcd.setTextColor(WHITE); 25 | M5.Lcd.setCursor(15, 35); 26 | M5.Lcd.println("Display"); 27 | M5.Lcd.setCursor(30, 55); 28 | M5.Lcd.println("rainbow effect"); 29 | 30 | // Neopixel initialization 31 | FastLED.addLeds(leds, NUM_LEDS) 32 | .setCorrection(TypicalLEDStrip); 33 | FastLED.setBrightness(10); 34 | xTaskCreatePinnedToCore(FastLEDshowTask, "FastLEDshowTask", 2048, NULL, 2, 35 | NULL, 1); 36 | } 37 | 38 | void loop() { 39 | } 40 | 41 | void FastLEDshowESP32() { 42 | if (userTaskHandle == 0) { 43 | userTaskHandle = xTaskGetCurrentTaskHandle(); 44 | xTaskNotifyGive(FastLEDshowTaskHandle); 45 | const TickType_t xMaxBlockTime = pdMS_TO_TICKS(200); 46 | ulTaskNotifyTake(pdTRUE, xMaxBlockTime); 47 | userTaskHandle = 0; 48 | } 49 | } 50 | 51 | void FastLEDshowTask(void *pvParameters) { 52 | for (;;) { 53 | fill_rainbow(leds, NUM_LEDS, gHue, 7); // rainbow effect 54 | FastLED.show(); // must be executed for neopixel becoming effective 55 | EVERY_N_MILLISECONDS(20) { 56 | gHue++; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/utility/ST7789_Rotation.h: -------------------------------------------------------------------------------- 1 | // This is the command sequence that rotates the ST7789 driver coordinate frame 2 | 3 | writecommand(TFT_MADCTL); 4 | rotation = m % 4; 5 | switch (rotation) { 6 | case 0: // Portrait 7 | #ifdef CGRAM_OFFSET 8 | if (_init_width == 135) { 9 | colstart = 52; 10 | rowstart = 40; 11 | } else { 12 | colstart = 0; 13 | rowstart = 0; 14 | } 15 | #endif 16 | writedata(TFT_MAD_COLOR_ORDER); 17 | 18 | _width = _init_width; 19 | _height = _init_height; 20 | break; 21 | 22 | case 1: // Landscape (Portrait + 90) 23 | #ifdef CGRAM_OFFSET 24 | if (_init_width == 135) { 25 | colstart = 40; 26 | rowstart = 53; 27 | } else { 28 | colstart = 0; 29 | rowstart = 0; 30 | } 31 | #endif 32 | writedata(TFT_MAD_MX | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); 33 | 34 | _width = _init_height; 35 | _height = _init_width; 36 | break; 37 | 38 | case 2: // Inverter portrait 39 | #ifdef CGRAM_OFFSET 40 | if (_init_width == 135) { 41 | colstart = 53; 42 | rowstart = 40; 43 | } else { 44 | colstart = 0; 45 | rowstart = 80; 46 | } 47 | #endif 48 | writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); 49 | 50 | _width = _init_width; 51 | _height = _init_height; 52 | break; 53 | case 3: // Inverted landscape 54 | #ifdef CGRAM_OFFSET 55 | if (_init_width == 135) { 56 | colstart = 40; 57 | rowstart = 52; 58 | } else { 59 | colstart = 80; 60 | rowstart = 0; 61 | } 62 | #endif 63 | writedata(TFT_MAD_MV | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); 64 | 65 | _width = _init_height; 66 | _height = _init_width; 67 | break; 68 | } 69 | -------------------------------------------------------------------------------- /examples/Hat/PuppyC/PuppyC.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "IIC_.h" 3 | 4 | void puppy_start() { 5 | angle_all_set(90, 90, 90, 90); // servo 1 2 3 4 => set 90° 6 | delay(100); 7 | } 8 | 9 | void puppy_go() { 10 | angle_all_set(55, 60, 130, 120); // servo 1 2 3 4 11 | delay(100); 12 | angle_all_set(55, 160, 130, 120); // servo 1 2 3 4 13 | delay(100); 14 | angle_all_set(120, 130, 150, 60); // servo 1 2 3 4 15 | delay(100); 16 | angle_all_set(120, 130, 60, 60); // servo 1 2 3 4 17 | delay(100); 18 | angle_all_set(55, 130, 60, 60); // servo 1 2 3 4 19 | delay(100); 20 | angle_all_set(55, 60, 130, 30); 21 | delay(100); 22 | } 23 | 24 | void puppy_back() { 25 | angle_all_set(120, 130, 60, 55); 26 | delay(100); 27 | angle_all_set(120, 130, 160, 55); 28 | delay(100); 29 | angle_all_set(60, 150, 130, 120); 30 | delay(100); 31 | angle_all_set(60, 60, 130, 120); 32 | delay(100); 33 | angle_all_set(60, 60, 130, 55); 34 | delay(100); 35 | angle_all_set(30, 130, 60, 55); 36 | delay(100); 37 | } 38 | 39 | // the setup routine runs once when M5StickC starts up 40 | void setup() { 41 | // Initialize the M5StickC object 42 | M5.begin(); 43 | 44 | // LCD display 45 | M5.Lcd.println(" "); 46 | M5.Lcd.println(" IIC_PUPPY"); 47 | IIC_Init(); // sda 0 scl 26 48 | 49 | /* 50 | 1 2 51 | 3 4 52 | */ 53 | angle_set(1, 90); // servo 1 => set 90° 54 | angle_set(2, 90); 55 | angle_set(3, 90); 56 | angle_set(4, 90); 57 | delay(1000); 58 | } 59 | 60 | // the loop routine runs over and over again forever 61 | /* 62 | 1 2 63 | 3 4 64 | */ 65 | uint8_t cnt = 10; 66 | void loop() { 67 | while (cnt != 0) { 68 | cnt--; 69 | puppy_go(); 70 | } 71 | cnt = 10; 72 | puppy_start(); 73 | while (cnt != 0) { 74 | cnt--; 75 | puppy_back(); 76 | } 77 | cnt = 10; 78 | puppy_start(); 79 | } 80 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/Counter/Counter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: counter. 计数器 10 | * Date: 2021/9/18 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | Preferences preferences; 18 | 19 | void setup() { 20 | M5.begin(); 21 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 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 | -------------------------------------------------------------------------------- /README_cn.md: -------------------------------------------------------------------------------- 1 | # M5StickC-Plus Library 2 | 3 | [![Arduino Compile](https://github.com/m5stack/M5StickC-Plus/actions/workflows/arduino-action-compile.yml/badge.svg)](https://github.com/m5stack/M5StickC-Plus/actions/workflows/arduino-action-compile.yml) 4 | [![Arduino Lint](https://github.com/m5stack/M5StickC-Plus/actions/workflows/Arduino-Lint-Check.yml/badge.svg)](https://github.com/m5stack/M5StickC-Plus/actions/workflows/Arduino-Lint-Check.yml) 5 | [![Clang Format](https://github.com/m5stack/M5StickC-Plus/actions/workflows/clang-format-check.yml/badge.svg)](https://github.com/m5stack/M5StickC-Plus/actions/workflows/clang-format-check.yml) 6 | 7 | English | [中文](README.md) 8 | 9 | M5StickC_01 10 | 11 | * **如果查看 M5StickC Plus 的详细介绍文档,[点击这里](https://docs.m5stack.com/#/zh_CN/core/m5stickc_plus)** 12 | 13 | * **如果想要购买 M5StickC Plus 的话,[点击这里](https://item.taobao.com/item.htm?spm=a1z10.5-c-s.w4002-22404213529.29.5ada1d91KUL15v&id=623449145184)** 14 | 15 | 16 | ## 描述 17 | 18 | **M5StickC PLUS** 是M5StickC的大屏幕版本,主控采用ESP32-PICO-D4模组,具备蓝牙4.2与WIFI功能,小巧的机身内部集成了丰富的硬件资源,如红外、RTC、麦克风、LED、IMU、按键、蜂鸣器、PMU等,在保留原有M5StickC功能的基础上加入了无源蜂鸣器,同时屏幕尺寸升级到1.14寸、135*240分辨率的TFT屏幕,相较之前的0.96寸屏幕增加18.7%的显示面积,电池容量达到120mAh,接口同样支持HAT与Unit系列产品. 19 | 20 | 21 | **开关机操作:** 22 | 23 | * 开机:按复位按键,持续至少 2 秒 24 | 25 | * 关机:按复位按键,持续至少 6 秒 26 | 27 | **注意:** 28 | 29 | * M5StickC Plus支持的波特率: 1200 ~115200, 250K, 500K, 750K, 1500K 30 | 31 | * G36/G25共用同一个端口,当使用其中一个引脚时要将另外一个引脚设置为浮空输入 32 | * 比如要使用G36引脚作为ADC输入,则配置G25引脚为浮空状态 33 | 34 | ## 更多信息 35 | 36 | **UIFlow 快速上手**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/m5stickc_plus/uiflow) 37 | 38 | **MicroPython API**: [点击这里](https://docs.m5stack.com/zh_CN/mpy/display/m5stack_lvgl) 39 | 40 | **Arduino IDE 环境搭建**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/m5stickc_plus/arduino) 41 | 42 | **M5StickC Arduino API**: [点击这里](https://docs.m5stack.com/zh_CN/api/stickc/system_m5stickc) 43 | 44 | **引脚地图**: [点击这里](https://docs.m5stack.com/zh_CN/core/m5stickc_plus) 45 | -------------------------------------------------------------------------------- /src/utility/Button.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------* 2 | * Arduino Button Library v1.0 * 3 | * Jack Christensen Mar 2012 * 4 | * * 5 | * This work is licensed under the Creative Commons Attribution- * 6 | * ShareAlike 3.0 Unported License. To view a copy of this license, * 7 | * visit http://creativecommons.org/licenses/by-sa/3.0/ or send a * 8 | * letter to Creative Commons, 171 Second Street, Suite 300, * 9 | * San Francisco, California, 94105, USA. * 10 | *----------------------------------------------------------------------*/ 11 | #ifndef Button_h 12 | #define Button_h 13 | // #if ARDUINO >= 100 14 | #include 15 | // #else 16 | // #include 17 | // #endif 18 | class Button { 19 | public: 20 | Button(uint8_t pin, uint8_t invert, uint32_t dbTime); 21 | uint8_t read(); 22 | uint8_t isPressed(); 23 | uint8_t isReleased(); 24 | uint8_t wasPressed(); 25 | uint8_t wasReleased(); 26 | uint8_t pressedFor(uint32_t ms); 27 | uint8_t releasedFor(uint32_t ms); 28 | uint8_t wasReleasefor(uint32_t ms); 29 | uint32_t lastChange(); 30 | 31 | private: 32 | uint8_t _pin; // arduino pin number 33 | uint8_t _puEnable; // internal pullup resistor enabled 34 | uint8_t _invert; // if 0, interpret high state as pressed, else interpret 35 | // low state as pressed 36 | uint8_t _state; // current button state 37 | uint8_t _lastState; // previous button state 38 | uint8_t _changed; // state changed since last read 39 | uint32_t _time; // time of current state (all times are in ms) 40 | uint32_t _lastTime; // time of previous state 41 | uint32_t _lastChange; // time of last state change 42 | uint32_t _dbTime; // debounce time 43 | uint32_t _pressTime; // press time 44 | uint32_t _hold_time; // hold time call wasreleasefor 45 | }; 46 | #endif 47 | -------------------------------------------------------------------------------- /examples/Unit/RFID/RFID.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "MFRC522_I2C.h" 4 | // 0x28 is i2c address on SDA. Check your address with i2cscanner if not match. 5 | MFRC522 mfrc522(0x28); // Create MFRC522 instance. 6 | 7 | void setup() { 8 | M5.begin(); 9 | M5.Lcd.setRotation(3); 10 | M5.Lcd.fillScreen(BLACK); 11 | M5.Lcd.setCursor(60, 2); 12 | M5.Lcd.println("M5StackFire MFRC522"); 13 | Wire.begin(); // Initialize I2C 14 | mfrc522.PCD_Init(); // Init MFRC522 15 | ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details 16 | Serial.println(F("Scan PICC to see UID, type, and data blocks...")); 17 | M5.Lcd.println("Scan PICC to see UID, type, and data blocks..."); 18 | } 19 | 20 | void loop() { 21 | // Look for new cards, and select one if present 22 | if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) { 23 | delay(50); 24 | return; 25 | } 26 | 27 | // Now a card is selected. The UID and SAK is in mfrc522.uid. 28 | 29 | // Dump UID 30 | Serial.print(F("Card UID:")); 31 | M5.Lcd.println(" "); 32 | for (byte i = 0; i < mfrc522.uid.size; i++) { 33 | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 34 | Serial.print(mfrc522.uid.uidByte[i], HEX); 35 | M5.Lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 36 | M5.Lcd.print(mfrc522.uid.uidByte[i], HEX); 37 | } 38 | Serial.println(); 39 | } 40 | 41 | void ShowReaderDetails() { 42 | // Get the MFRC522 software version 43 | byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); 44 | Serial.print(F("MFRC522 Software Version: 0x")); 45 | Serial.print(v, HEX); 46 | if (v == 0x91) 47 | Serial.print(F(" = v1.0")); 48 | else if (v == 0x92) 49 | Serial.print(F(" = v2.0")); 50 | else 51 | Serial.print(F(" (unknown)")); 52 | Serial.println(""); 53 | // When 0x00 or 0xFF is returned, communication probably failed 54 | if ((v == 0x00) || (v == 0xFF)) { 55 | Serial.println( 56 | F("WARNING: Communication failure, is the MFRC522 properly " 57 | "connected?")); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/Unit/Color/Color.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Color test 3 | hardware: M5Stack 4 | 5 | please install the Adfruit TCS34725 library first ... 6 | */ 7 | 8 | #include 9 | #include 10 | #include "Adafruit_TCS34725.h" 11 | 12 | // set to false if using a common cathode LED 13 | #define commonAnode true 14 | 15 | // our RGB -> eye-recognized gamma color 16 | byte gammatable[256]; 17 | 18 | static uint16_t color16(uint16_t r, uint16_t g, uint16_t b) { 19 | uint16_t _color; 20 | _color = (uint16_t)(r & 0xF8) << 8; 21 | _color |= (uint16_t)(g & 0xFC) << 3; 22 | _color |= (uint16_t)(b & 0xF8) >> 3; 23 | return _color; 24 | } 25 | 26 | Adafruit_TCS34725 tcs = 27 | Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); 28 | 29 | void setup() { 30 | delay(100); 31 | 32 | M5.begin(true, false, false); 33 | Serial.begin(115200); 34 | Serial.println("Color View Test!"); 35 | 36 | if (tcs.begin()) { 37 | Serial.println("Found sensor"); 38 | } else { 39 | Serial.println("No TCS34725 found ... check your connections"); 40 | while (1) 41 | ; // halt! 42 | } 43 | tcs.setIntegrationTime(TCS34725_INTEGRATIONTIME_154MS); 44 | tcs.setGain(TCS34725_GAIN_4X); 45 | } 46 | 47 | void loop() { 48 | uint16_t clear, red, green, blue; 49 | 50 | delay(60); // takes 50ms to read 51 | 52 | tcs.getRawData(&red, &green, &blue, &clear); 53 | 54 | Serial.print("C:\t"); 55 | Serial.print(clear); 56 | Serial.print("\tR:\t"); 57 | Serial.print(red); 58 | Serial.print("\tG:\t"); 59 | Serial.print(green); 60 | Serial.print("\tB:\t"); 61 | Serial.print(blue); 62 | 63 | // Figure out some basic hex code for visualization 64 | uint32_t sum = clear; 65 | float r, g, b; 66 | r = red; 67 | r /= sum; 68 | g = green; 69 | g /= sum; 70 | b = blue; 71 | b /= sum; 72 | r *= 256; 73 | g *= 256; 74 | b *= 256; 75 | Serial.print("\t"); 76 | Serial.print((int)r, HEX); 77 | Serial.print((int)g, HEX); 78 | Serial.print((int)b, HEX); 79 | Serial.println(); 80 | uint16_t _color = color16((int)r, (int)g, (int)b); 81 | M5.Lcd.fillScreen(_color); 82 | } 83 | -------------------------------------------------------------------------------- /examples/Unit/HEART/MAX30100_RawData/MAX30100_RawData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | pls install MAX30100lib by library manager first 3 | addr: https://github.com/oxullo/Arduino-MAX30100 4 | */ 5 | 6 | #include 7 | #include 8 | #include "MAX30100.h" 9 | 10 | // Sampling is tightly related to the dynamic range of the ADC. 11 | // refer to the datasheet for further info 12 | #define SAMPLING_RATE MAX30100_SAMPRATE_100HZ 13 | 14 | // The LEDs currents must be set to a level that avoids clipping and maximises 15 | // the dynamic range 16 | #define IR_LED_CURRENT MAX30100_LED_CURR_50MA 17 | #define RED_LED_CURRENT MAX30100_LED_CURR_27_1MA 18 | 19 | // The pulse width of the LEDs driving determines the resolution of 20 | // the ADC (which is a Sigma-Delta). 21 | // set HIGHRES_MODE to true only when setting PULSE_WIDTH to 22 | // MAX30100_SPC_PW_1600US_16BITS 23 | #define PULSE_WIDTH MAX30100_SPC_PW_1600US_16BITS 24 | #define HIGHRES_MODE true 25 | 26 | // Instantiate a MAX30100 sensor class 27 | MAX30100 sensor; 28 | 29 | void setup() { 30 | M5.begin(); 31 | M5.Lcd.setRotation(3); 32 | // M5.Lcd.setTextColor(WHITE); 33 | M5.Lcd.setTextSize(3); 34 | M5.Lcd.print("MAX30100"); 35 | // M5.Lcd.clear(BLACK); 36 | M5.Lcd.setCursor(0, 40); 37 | Serial.begin(115200); 38 | 39 | Serial.print("Initializing MAX30100.."); 40 | 41 | // Initialize the sensor 42 | // Failures are generally due to an improper I2C wiring, missing power 43 | // supply or wrong target chip 44 | if (!sensor.begin()) { 45 | Serial.println("FAILED"); 46 | for (;;) 47 | ; 48 | } else { 49 | Serial.println("SUCCESS"); 50 | } 51 | 52 | // Set up the wanted parameters 53 | sensor.setMode(MAX30100_MODE_SPO2_HR); 54 | sensor.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT); 55 | sensor.setLedsPulseWidth(PULSE_WIDTH); 56 | sensor.setSamplingRate(SAMPLING_RATE); 57 | sensor.setHighresModeEnabled(HIGHRES_MODE); 58 | } 59 | 60 | void loop() { 61 | uint16_t ir, red; 62 | 63 | sensor.update(); 64 | 65 | while (sensor.getRawValues(&ir, &red)) { 66 | Serial.print(ir); 67 | Serial.print('\t'); 68 | Serial.println(red); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/Unit/TVOC_SGP30/TVOC_SGP30.ino: -------------------------------------------------------------------------------- 1 | // SGP30 needs 15 seconds to initialize calibration after power on. 2 | // The screen will display TVOC and CO2 3 | 4 | #include 5 | #include "Adafruit_SGP30.h" 6 | 7 | Adafruit_SGP30 sgp; 8 | int i = 15; 9 | long last_millis = 0; 10 | void header(const char *string, uint16_t color) { 11 | M5.Lcd.fillScreen(color); 12 | M5.Lcd.setTextSize(1); 13 | M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); 14 | M5.Lcd.fillRect(0, 0, 120, 20, TFT_BLACK); 15 | M5.Lcd.setTextDatum(TC_DATUM); 16 | M5.Lcd.drawString(string, 120, 2, 4); 17 | } 18 | 19 | void setup() { 20 | M5.begin(true, false, false); 21 | Wire.begin(32, 33); 22 | M5.Lcd.setRotation(3); 23 | header("SGP30 TEST", TFT_BLACK); 24 | Serial.begin(115200); 25 | Serial.println("SGP30 test"); 26 | if (!sgp.begin()) { 27 | Serial.println("Sensor not found :("); 28 | while (1) 29 | ; 30 | } 31 | 32 | M5.Lcd.drawString("TVOC:", 40, 42, 4); 33 | M5.Lcd.drawString("eCO2:", 40, 76, 4); 34 | Serial.print("Found SGP30 serial #"); 35 | Serial.print(sgp.serialnumber[0], HEX); 36 | Serial.print(sgp.serialnumber[1], HEX); 37 | Serial.println(sgp.serialnumber[2], HEX); 38 | M5.Lcd.drawString("Initialization", 150, 110, 4); 39 | } 40 | 41 | void loop() { 42 | while (i > 0) { 43 | if (millis() - last_millis > 1000) { 44 | last_millis = millis(); 45 | i--; 46 | M5.Lcd.fillRect(45, 110, 30, 25, TFT_BLACK); 47 | M5.Lcd.drawNumber(i, 60, 110, 4); 48 | } 49 | } 50 | M5.Lcd.fillRect(45, 110, 180, 25, TFT_BLACK); 51 | 52 | if (!sgp.IAQmeasure()) { 53 | Serial.println("Measurement failed"); 54 | return; 55 | } 56 | M5.Lcd.fillRect(85, 42, 75, 68, TFT_BLACK); 57 | M5.Lcd.drawNumber(sgp.TVOC, 120, 42, 4); 58 | M5.Lcd.drawString("ppb", 200, 42, 4); 59 | M5.Lcd.drawNumber(sgp.eCO2, 120, 76, 4); 60 | M5.Lcd.drawString("ppm", 200, 76, 4); 61 | Serial.print("TVOC "); 62 | Serial.print(sgp.TVOC); 63 | Serial.print(" ppb\t"); 64 | Serial.print("eCO2 "); 65 | Serial.print(sgp.eCO2); 66 | Serial.println(" ppm"); 67 | 68 | delay(1000); 69 | } 70 | -------------------------------------------------------------------------------- /examples/Basics/Display/Display.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: Display. 10 | * Date: 2021/9/14 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | /* After M5StickC Plus is started or reset 16 | the program in the setUp () function will be run, and this part will only be 17 | run once. 在 M5StickC Plus 18 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 19 | void setup() { 20 | M5.begin(); 21 | // Lcd display 22 | M5.Lcd.fillScreen(WHITE); 23 | delay(500); 24 | M5.Lcd.fillScreen(RED); 25 | delay(500); 26 | M5.Lcd.fillScreen(GREEN); 27 | delay(500); 28 | M5.Lcd.fillScreen(BLUE); 29 | delay(500); 30 | M5.Lcd.fillScreen(BLACK); 31 | delay(500); 32 | 33 | // text print. 文字打印 34 | M5.Lcd.fillScreen(BLACK); 35 | M5.Lcd.setCursor(0, 10); 36 | M5.Lcd.setTextColor(WHITE); 37 | M5.Lcd.setTextSize(1); 38 | M5.Lcd.printf("Display Test!"); 39 | 40 | // draw graphic. 绘图🌹 41 | delay(1000); 42 | M5.Lcd.drawRect(15, 55, 50, 50, BLUE); 43 | delay(1000); 44 | M5.Lcd.fillRect(15, 55, 50, 50, BLUE); 45 | delay(1000); 46 | M5.Lcd.drawCircle(40, 80, 30, RED); 47 | delay(1000); 48 | M5.Lcd.fillCircle(40, 80, 30, RED); 49 | delay(1000); 50 | } 51 | 52 | /* After the program in setup() runs, it runs the program in loop() 53 | The loop() function is an infinite loop in which the program runs repeatedly 54 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 55 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 56 | void loop() { 57 | // rand draw 58 | M5.Lcd.fillTriangle(random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1), 59 | random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1), 60 | random(M5.Lcd.width() - 1), random(M5.Lcd.height() - 1), 61 | random(0xfffe)); 62 | } 63 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiMulti/WiFiMulti.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: WIFI Multi. 多wifi择优 10 | * Date: 2021/9/18 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(); 24 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 25 | wifiMulti.addAP("wifi1", "213123"); // Storage wifi configuration 26 | // information 1. 存储wifi配置信息1 27 | wifiMulti.addAP("M5wifi", "213431241234"); 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/Basics/MPU6886/MPU6886.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: MPU6886. 10 | * Date: 2021/9/14 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | float accX = 0; 16 | float accY = 0; 17 | float accZ = 0; 18 | 19 | float gyroX = 0; 20 | float gyroY = 0; 21 | float gyroZ = 0; 22 | 23 | /* After M5StickC Plus is started or reset 24 | the program in the setUp () function will be run, and this part will only be 25 | run once. 在 M5StickC Plus 26 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 27 | void setup() { 28 | M5.begin(); // Init M5StickC Plus. 初始化 M5StickC Plus 29 | M5.Imu.Init(); // Init IMU. 初始化IMU 30 | M5.Lcd.setRotation(3); // Rotate the screen. 将屏幕旋转 31 | M5.Lcd.setCursor(50, 15); // set the cursor location. 设置光标位置 32 | M5.Lcd.println("MPU6886 TEST"); 33 | M5.Lcd.setCursor(30, 30); 34 | M5.Lcd.println(" X Y Z"); 35 | } 36 | 37 | /* After the program in setup() runs, it runs the program in loop() 38 | The loop() function is an infinite loop in which the program runs repeatedly 39 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 40 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 41 | void loop() { 42 | static float temp = 0; 43 | M5.Imu.getGyroData(&gyroX, &gyroY, &gyroZ); 44 | M5.Imu.getAccelData(&accX, &accY, &accZ); 45 | M5.Imu.getTempData(&temp); 46 | 47 | M5.Lcd.setCursor(30, 45); 48 | M5.Lcd.printf("%.2f %.2f %.2f ", gyroX, gyroY, gyroZ); 49 | M5.Lcd.setCursor(170, 45); 50 | M5.Lcd.print("o/s"); 51 | M5.Lcd.setCursor(30, 60); 52 | M5.Lcd.printf("%.2f %.2f %.2f ", accX * 1000, accY * 1000, 53 | accZ * 1000); 54 | M5.Lcd.setCursor(185, 60); 55 | M5.Lcd.print("mg"); 56 | M5.Lcd.setCursor(30, 75); 57 | M5.Lcd.printf("Temperature : %.2f C", temp); 58 | delay(100); 59 | } 60 | -------------------------------------------------------------------------------- /examples/Basics/Button/Button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: Button. 10 | * Date: 2021/11/16 11 | ******************************************************************************* 12 | */ 13 | #include "M5StickCPlus.h" 14 | 15 | /* After M5StickC is started or reset 16 | the program in the setUp () function will be run, and this part will only be 17 | run once. 在 M5StickC 18 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 19 | void setup() { 20 | M5.begin(); // Initialize the M5StickC-Plus object. 初始化 M5StickC-Plus 21 | // 对象 22 | M5.Lcd.setTextColor( 23 | YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 24 | M5.Lcd.setTextSize(2); // Set the font size to 2. 设置字体大小为2 25 | M5.Lcd.setRotation(3); 26 | M5.Lcd.println( 27 | "Button example"); // The screen prints the formatted string and wraps 28 | // the line. 输出格式化字符串并换行 29 | M5.Lcd.println("Press button B for 700ms"); 30 | M5.Lcd.println("to clear screen."); 31 | M5.Lcd.setTextColor(RED); 32 | } 33 | 34 | /* After the program in setup() runs, it runs the program in loop() 35 | The loop() function is an infinite loop in which the program runs repeatedly 36 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 37 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 38 | void loop() { 39 | M5.update(); // Read the press state of the key. 读取按键 A, B, C 的状态 40 | if (M5.BtnA 41 | .wasReleased()) { // If the button A is pressed. 如果按键 A 被按下 42 | M5.Lcd.print('A'); 43 | } else if (M5.BtnB.wasReleased()) { // If the button B is pressed. 如果按键 44 | // B 被按下, 45 | M5.Lcd.print('B'); 46 | } else if (M5.BtnB.wasReleasefor( 47 | 700)) { // The button B is pressed for 700ms. 按键 B 按下 48 | // 700ms,屏幕清空 49 | M5.Lcd.fillScreen( 50 | BLACK); // Set BLACK to the background color. 将黑色设置为底色 51 | M5.Lcd.setCursor(0, 0); 52 | } 53 | } -------------------------------------------------------------------------------- /examples/Advanced/Time/Time.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: NTP TIME. 10 | * Date: 2021/9/18 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(); 41 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 42 | M5.Lcd.printf("\nConnecting to %s", ssid); 43 | WiFi.begin(ssid, password); // Connect wifi and return connection status. 44 | // 连接wifi并返回连接状态 45 | while (WiFi.status() != 46 | WL_CONNECTED) { // If the wifi connection fails. 若wifi未连接成功 47 | delay(500); // delay 0.5s. 延迟0.5s 48 | M5.Lcd.print("."); 49 | } 50 | M5.Lcd.println("\nCONNECTED!"); 51 | configTime(gmtOffset_sec, daylightOffset_sec, 52 | ntpServer); // init and get the time. 初始化并设置NTP 53 | printLocalTime(); 54 | WiFi.disconnect(true); // Disconnect wifi. 断开wifi连接 55 | WiFi.mode(WIFI_OFF); // Set the wifi mode to off. 设置wifi模式为关闭 56 | delay(20); 57 | } 58 | 59 | void loop() { 60 | delay(1000); 61 | M5.Lcd.setCursor(0, 25); // Set cursor to (0,25). 设置光标处于(0,25) 62 | printLocalTime(); 63 | } -------------------------------------------------------------------------------- /src/utility/Speaker.cpp: -------------------------------------------------------------------------------- 1 | #include "Speaker.h" 2 | 3 | SPEAKER::SPEAKER(void) { 4 | _volume = 8; 5 | _begun = false; 6 | } 7 | 8 | void SPEAKER::begin() { 9 | _begun = true; 10 | #if ESP_IDF_VERSION_MAJOR <= 4 11 | ledcSetup(TONE_PIN_CHANNEL, 0, 13); 12 | ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL); 13 | #elif ESP_IDF_VERSION_MAJOR > 4 14 | ledcAttach(SPEAKER_PIN, 0, 13); 15 | #endif 16 | setBeep(4000, 100); 17 | } 18 | 19 | void SPEAKER::end() { 20 | mute(); 21 | #if ESP_IDF_VERSION_MAJOR <= 4 22 | ledcDetachPin(SPEAKER_PIN); 23 | #elif ESP_IDF_VERSION_MAJOR > 4 24 | ledcDetach(SPEAKER_PIN); 25 | #endif 26 | _begun = false; 27 | } 28 | 29 | void SPEAKER::tone(uint16_t frequency) { 30 | if (!_begun) begin(); 31 | ledcWriteTone(TONE_PIN_CHANNEL, frequency); 32 | } 33 | 34 | void SPEAKER::tone(uint16_t frequency, uint32_t duration) { 35 | tone(frequency); 36 | _count = millis() + duration; 37 | speaker_on = 1; 38 | } 39 | 40 | void SPEAKER::beep() { 41 | if (!_begun) begin(); 42 | tone(_beep_freq, _beep_duration); 43 | } 44 | 45 | void SPEAKER::setBeep(uint16_t frequency, uint16_t duration) { 46 | _beep_freq = frequency; 47 | _beep_duration = duration; 48 | } 49 | 50 | void SPEAKER::setVolume(uint8_t volume) { 51 | _volume = 11 - volume; 52 | } 53 | 54 | void SPEAKER::mute() { 55 | ledcWriteTone(TONE_PIN_CHANNEL, 0); 56 | digitalWrite(SPEAKER_PIN, 0); 57 | } 58 | 59 | void SPEAKER::update() { 60 | if (speaker_on) { 61 | if (millis() > _count) { 62 | speaker_on = 0; 63 | mute(); 64 | } 65 | } 66 | } 67 | 68 | void SPEAKER::write(uint8_t value) { 69 | dacWrite(SPEAKER_PIN, value); 70 | } 71 | 72 | void SPEAKER::playMusic(const uint8_t* music_data, uint16_t sample_rate) { 73 | uint32_t length = strlen((char*)music_data); 74 | uint16_t delay_interval = ((uint32_t)1000000 / sample_rate); 75 | if (_volume != 11) { 76 | for (int i = 0; i < length; i++) { 77 | dacWrite(SPEAKER_PIN, music_data[i] / _volume); 78 | delayMicroseconds(delay_interval); 79 | } 80 | 81 | for (int t = music_data[length - 1] / _volume; t >= 0; t--) { 82 | dacWrite(SPEAKER_PIN, t); 83 | delay(2); 84 | } 85 | } 86 | #if ESP_IDF_VERSION_MAJOR <= 4 87 | ledcAttachPin(SPEAKER_PIN, TONE_PIN_CHANNEL); 88 | #elif ESP_IDF_VERSION_MAJOR > 4 89 | ledcAttach(SPEAKER_PIN, 0, 13); 90 | #endif 91 | } 92 | -------------------------------------------------------------------------------- /examples/Advanced/MultiTask/MultiTask.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: MultiTask. 多线程 10 | * Date: 2021/9/18 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | void task1(void* pvParameters) { // Define the tasks to be executed in 16 | // thread 1. 定义线程1内要执行的任务 17 | while (1) { // Keep the thread running. 使线程一直运行 18 | Serial.print("task1 Uptime (ms): "); 19 | Serial.println(millis()); // The running time of the serial port 20 | // printing program. 串口打印程序运行的时间 21 | delay( 22 | 100); // With a delay of 100ms, it can be seen in the serial 23 | // monitor that every 100ms, thread 1 will be executed once. 24 | // 延迟100ms,在串口监视器内可看到每隔100ms,线程1就会被执行一次 25 | } 26 | } 27 | 28 | void task2(void* pvParameters) { 29 | while (1) { 30 | Serial.print("task2 Uptime (ms): "); 31 | Serial.println(millis()); 32 | delay(200); 33 | } 34 | } 35 | 36 | void task3(void* pvParameters) { 37 | while (1) { 38 | Serial.print("task3 Uptime (ms): "); 39 | Serial.println(millis()); 40 | delay(1000); 41 | } 42 | } 43 | 44 | void setup() { 45 | M5.begin(); 46 | // Creat Task1. 创建线程1 47 | xTaskCreatePinnedToCore( 48 | task1, // Function to implement the task. 49 | // 线程对应函数名称(不能有返回值) 50 | "task1", //线程名称 51 | 4096, // The size of the task stack specified as the number of * 52 | // bytes.任务堆栈的大小(字节) 53 | NULL, // Pointer that will be used as the parameter for the task * 54 | // being created. 创建作为任务输入参数的指针 55 | 1, // Priority of the task. 任务的优先级 56 | NULL, // Task handler. 任务句柄 57 | 0); // Core where the task should run. 将任务挂载到指定内核 58 | 59 | // Task 2 60 | xTaskCreatePinnedToCore(task2, "task2", 4096, NULL, 2, NULL, 0); 61 | 62 | // Task 3 63 | xTaskCreatePinnedToCore(task3, "task3", 4096, NULL, 3, NULL, 0); 64 | } 65 | 66 | void loop() { 67 | } -------------------------------------------------------------------------------- /examples/Basics/IMU/IMU.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: IMU. 10 | * Date: 2021/9/14 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | float accX = 0.0F; 16 | float accY = 0.0F; 17 | float accZ = 0.0F; 18 | 19 | float gyroX = 0.0F; 20 | float gyroY = 0.0F; 21 | float gyroZ = 0.0F; 22 | 23 | float pitch = 0.0F; 24 | float roll = 0.0F; 25 | float yaw = 0.0F; 26 | 27 | /* After M5StickC Plus is started or reset 28 | the program in the setUp () function will be run, and this part will only be 29 | run once. 在 M5StickC Plus 30 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 31 | void setup() { 32 | M5.begin(); // Init M5StickC Plus. 初始化 M5StickC Plus 33 | M5.Imu.Init(); // Init IMU. 初始化IMU 34 | M5.Lcd.setRotation(3); // Rotate the screen. 将屏幕旋转 35 | M5.Lcd.fillScreen(BLACK); 36 | M5.Lcd.setTextSize(1); 37 | M5.Lcd.setCursor(80, 15); // set the cursor location. 设置光标位置 38 | M5.Lcd.println("IMU TEST"); 39 | M5.Lcd.setCursor(30, 30); 40 | M5.Lcd.println(" X Y Z"); 41 | M5.Lcd.setCursor(30, 70); 42 | M5.Lcd.println(" Pitch Roll Yaw"); 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 | static float temp = 0; 51 | M5.IMU.getGyroData(&gyroX, &gyroY, &gyroZ); 52 | M5.IMU.getAccelData(&accX, &accY, &accZ); 53 | M5.IMU.getAhrsData(&pitch, &roll, &yaw); 54 | M5.IMU.getTempData(&temp); 55 | M5.Lcd.setCursor(30, 40); 56 | M5.Lcd.printf("%6.2f %6.2f %6.2f ", gyroX, gyroY, gyroZ); 57 | M5.Lcd.setCursor(170, 40); 58 | M5.Lcd.print("o/s"); 59 | M5.Lcd.setCursor(30, 50); 60 | M5.Lcd.printf(" %5.2f %5.2f %5.2f ", accX, accY, accZ); 61 | M5.Lcd.setCursor(170, 50); 62 | M5.Lcd.print("G"); 63 | M5.Lcd.setCursor(30, 80); 64 | M5.Lcd.printf(" %5.2f %5.2f %5.2f ", pitch, roll, yaw); 65 | 66 | M5.Lcd.setCursor(30, 95); 67 | M5.Lcd.printf("Temperature : %.2f C", temp); 68 | delay(100); 69 | } 70 | -------------------------------------------------------------------------------- /examples/Unit/TVOC_SGP30/Adafruit_SGP30.h: -------------------------------------------------------------------------------- 1 | // @file Adafruit_SGP30.h 2 | 3 | #ifndef ADAFRUIT_SGP30_H 4 | #define ADAFRUIT_SGP30_H 5 | 6 | #include "Arduino.h" 7 | #include 8 | 9 | // the i2c address 10 | #define SGP30_I2CADDR_DEFAULT 0x58 ///< SGP30 has only one I2C address 11 | 12 | // commands and constants 13 | #define SGP30_FEATURESET 0x0020 ///< The required set for this library 14 | #define SGP30_CRC8_POLYNOMIAL 0x31 ///< Seed for SGP30's CRC polynomial 15 | #define SGP30_CRC8_INIT 0xFF ///< Init value for CRC 16 | #define SGP30_WORD_LEN 2 ///< 2 bytes per word 17 | 18 | /*! 19 | * @brief Class that stores state and functions for interacting with 20 | * SGP30 Gas Sensor 21 | */ 22 | class Adafruit_SGP30 { 23 | public: 24 | Adafruit_SGP30(); 25 | boolean begin(TwoWire *theWire = &Wire, boolean initSensor = true); 26 | boolean softReset(); 27 | boolean IAQinit(); 28 | boolean IAQmeasure(); 29 | boolean IAQmeasureRaw(); 30 | 31 | boolean getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base); 32 | boolean setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base); 33 | boolean setHumidity(uint32_t absolute_humidity); 34 | 35 | /** The last measurement of the IAQ-calculated Total Volatile Organic 36 | * Compounds in ppb. This value is set when you call {@link IAQmeasure()} 37 | * **/ 38 | uint16_t TVOC; 39 | 40 | /** The last measurement of the IAQ-calculated equivalent CO2 in ppm. This 41 | * value is set when you call {@link IAQmeasure()} **/ 42 | uint16_t eCO2; 43 | 44 | /** The last measurement of the IAQ-calculated equivalent CO2 in ppm. This 45 | * value is set when you call {@link IAQmeasureRaw()} **/ 46 | uint16_t rawH2; 47 | 48 | /** The last measurement of the IAQ-calculated equivalent CO2 in ppm. This 49 | * value is set when you call {@link IAQmeasureRaw()} **/ 50 | uint16_t rawEthanol; 51 | 52 | /** The 48-bit serial number, this value is set when you call {@link 53 | * begin()} 54 | * **/ 55 | uint16_t serialnumber[3]; 56 | 57 | private: 58 | TwoWire *_i2c; 59 | uint8_t _i2caddr; 60 | 61 | void write(uint8_t address, uint8_t *data, uint8_t n); 62 | void read(uint8_t address, uint8_t *data, uint8_t n); 63 | boolean readWordFromCommand(uint8_t command[], uint8_t commandLength, 64 | uint16_t delay, uint16_t *readdata = NULL, 65 | uint8_t readlen = 0); 66 | uint8_t generateCRC(uint8_t data[], uint8_t datalen); 67 | }; 68 | #endif // ndef ADAFRUIT_SGP30_H 69 | -------------------------------------------------------------------------------- /examples/Basics/RTC/RTC.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: RTC. 实时时钟 10 | * Date: 2021/9/14 11 | ******************************************************************************* 12 | */ 13 | #include 14 | 15 | RTC_TimeTypeDef RTC_TimeStruct; 16 | RTC_DateTypeDef RTC_DateStruct; 17 | 18 | /* After M5StickC Plus is started or reset 19 | the program in the setUp () function will be run, and this part will only be 20 | run once. 在 M5StickC Plus 21 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 22 | void setup() { 23 | M5.begin(); // Init M5StickC Plus. 初始化 M5StickC Plus 24 | M5.Lcd.setRotation(3); // Rotate the screen. 将屏幕旋转 25 | M5.Lcd.setCursor(60, 10, 2); // set the cursor location. 设置光标位置 26 | M5.Lcd.println("RTC TEST"); 27 | RTC_TimeTypeDef TimeStruct; 28 | TimeStruct.Hours = 18; // Set the time. 设置时间 29 | TimeStruct.Minutes = 56; 30 | TimeStruct.Seconds = 10; 31 | M5.Rtc.SetTime(&TimeStruct); // writes the set time to the real time clock. 32 | // 将设置的时间写入实时时钟 33 | RTC_DateTypeDef DateStruct; 34 | DateStruct.WeekDay = 3; // Set the date. 设置日期 35 | DateStruct.Month = 3; 36 | DateStruct.Date = 22; 37 | DateStruct.Year = 2019; 38 | M5.Rtc.SetDate(&DateStruct); // writes the set date to the real time clock. 39 | // 将设置的日期写入实时时钟 40 | } 41 | 42 | /* After the program in setup() runs, it runs the program in loop() 43 | The loop() function is an infinite loop in which the program runs repeatedly 44 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 45 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 46 | void loop() { 47 | M5.Rtc.GetTime(&RTC_TimeStruct); // Gets the time in the real-time clock. 48 | // 获取实时时钟内的时间 49 | M5.Rtc.GetDate(&RTC_DateStruct); 50 | M5.Lcd.setCursor(30, 35); 51 | M5.Lcd.printf("Data : %04d-%02d-%02d\n", RTC_DateStruct.Year, 52 | RTC_DateStruct.Month, RTC_DateStruct.Date); 53 | M5.Lcd.setCursor(30, 55); 54 | M5.Lcd.printf("Week : %d\n", RTC_DateStruct.WeekDay); 55 | M5.Lcd.setCursor(30, 75); 56 | M5.Lcd.printf("Time : %02d : %02d : %02d\n", RTC_TimeStruct.Hours, 57 | RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds); 58 | delay(500); 59 | } 60 | -------------------------------------------------------------------------------- /examples/Unit/RGB/RGB.ino: -------------------------------------------------------------------------------- 1 | // NeoPixel Ring simple sketch (c) 2013 Shae Erisson 2 | // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel 3 | // library 4 | 5 | /* 6 | Install the AdaFruit NeoPixel library first 7 | Github: https://github.com/adafruit/Adafruit_NeoPixel 8 | */ 9 | #include 10 | #include 11 | 12 | // Which pin on the Arduino is connected to the NeoPixels? 13 | // On a Trinket or Gemma we suggest changing this to 1 14 | #define PIN 32 15 | // How many NeoPixels are attached to the Arduino? 16 | #define NUMPIXELS 3 17 | 18 | // When we setup the NeoPixel library, we tell it how many pixels, and which pin 19 | // to use to send signals. Note that for older NeoPixel strips you might need to 20 | // change the third parameter--see the strandtest example for more information 21 | // on possible values. 22 | Adafruit_NeoPixel pixels = 23 | Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 24 | 25 | int delayval = 150; // delay for half a second 26 | 27 | void setup() { 28 | M5.begin(); 29 | pixels.begin(); // This initializes the NeoPixel library. 30 | 31 | M5.Lcd.setRotation(3); 32 | M5.Lcd.fillScreen(BLACK); 33 | M5.Lcd.setTextSize(8); 34 | M5.Lcd.setCursor(60, 40); 35 | M5.Lcd.setTextColor(RED); 36 | M5.Lcd.printf("R"); 37 | M5.Lcd.setTextColor(GREEN); 38 | M5.Lcd.printf("G"); 39 | M5.Lcd.setTextColor(BLUE); 40 | M5.Lcd.printf("B"); 41 | } 42 | void loop() { 43 | pixels.setPixelColor( 44 | 0, pixels.Color(100, 0, 0)); // Moderately bright red color. 45 | pixels.setPixelColor( 46 | 1, pixels.Color(0, 100, 0)); // Moderately bright green color. 47 | pixels.setPixelColor( 48 | 2, pixels.Color(0, 0, 100)); // Moderately bright blue color. 49 | 50 | pixels.show(); // This sends the updated pixel color to the hardware. 51 | delay(delayval); // Delay for a period of time (in milliseconds) 52 | 53 | pixels.setPixelColor(0, pixels.Color(0, 100, 0)); 54 | pixels.setPixelColor(1, pixels.Color(0, 0, 100)); 55 | pixels.setPixelColor(2, pixels.Color(100, 0, 0)); 56 | pixels.show(); 57 | delay(delayval); 58 | 59 | pixels.setPixelColor(0, pixels.Color(0, 0, 100)); 60 | pixels.setPixelColor(1, pixels.Color(100, 0, 0)); 61 | pixels.setPixelColor(2, pixels.Color(0, 100, 0)); 62 | pixels.show(); 63 | delay(delayval); 64 | 65 | // pixels.setPixelColor(0, pixels.Color(100,100,100)); 66 | // pixels.setPixelColor(1, pixels.Color(100,100,100)); 67 | // pixels.setPixelColor(2, pixels.Color(100,100,100)); 68 | // pixels.show(); 69 | // delay(delayval); 70 | } 71 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/OTAUpload/OTAUpload.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: OTA Upload. 隔空传输程序 10 | * Date: 2021/9/18 11 | ******************************************************************************* 12 | PC and M5StickCPlus can only be used on the same wifi. 电脑和 13 | M5StickCPlus需在同一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 = "wifi"; 24 | const char* password = "123456123456"; 25 | 26 | void setup() { 27 | M5.begin(); 28 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 29 | WiFi.begin(ssid, 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 | "M5StickC"); // 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/Basics/Micophone/Micophone.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define PIN_CLK 0 5 | #define PIN_DATA 34 6 | #define READ_LEN (2 * 256) 7 | #define GAIN_FACTOR 3 8 | uint8_t BUFFER[READ_LEN] = {0}; 9 | 10 | uint16_t oldy[160]; 11 | int16_t *adcBuffer = NULL; 12 | 13 | void showSignal() { 14 | int y; 15 | for (int n = 0; n < 160; n++) { 16 | y = adcBuffer[n] * GAIN_FACTOR; 17 | y = map(y, INT16_MIN, INT16_MAX, 10, 70); 18 | M5.Lcd.drawPixel(n, oldy[n], WHITE); 19 | M5.Lcd.drawPixel(n, y, BLACK); 20 | oldy[n] = y; 21 | } 22 | } 23 | 24 | void mic_record_task(void *arg) { 25 | size_t bytesread; 26 | while (1) { 27 | i2s_read(I2S_NUM_0, (char *)BUFFER, READ_LEN, &bytesread, 28 | (100 / portTICK_RATE_MS)); 29 | adcBuffer = (int16_t *)BUFFER; 30 | showSignal(); 31 | vTaskDelay(100 / portTICK_RATE_MS); 32 | } 33 | } 34 | 35 | void i2sInit() { 36 | i2s_config_t i2s_config = { 37 | .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM), 38 | .sample_rate = 44100, 39 | .bits_per_sample = 40 | I2S_BITS_PER_SAMPLE_16BIT, // is fixed at 12bit, stereo, MSB 41 | .channel_format = I2S_CHANNEL_FMT_ALL_RIGHT, 42 | #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 1, 0) 43 | .communication_format = I2S_COMM_FORMAT_STAND_I2S, 44 | #else 45 | .communication_format = I2S_COMM_FORMAT_I2S, 46 | #endif 47 | .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, 48 | .dma_buf_count = 2, 49 | .dma_buf_len = 128, 50 | }; 51 | 52 | i2s_pin_config_t pin_config; 53 | 54 | #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) 55 | pin_config.mck_io_num = I2S_PIN_NO_CHANGE; 56 | #endif 57 | 58 | pin_config.bck_io_num = I2S_PIN_NO_CHANGE; 59 | pin_config.ws_io_num = PIN_CLK; 60 | pin_config.data_out_num = I2S_PIN_NO_CHANGE; 61 | pin_config.data_in_num = PIN_DATA; 62 | 63 | i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL); 64 | i2s_set_pin(I2S_NUM_0, &pin_config); 65 | i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); 66 | } 67 | 68 | void setup() { 69 | M5.begin(); 70 | M5.Lcd.setRotation(3); 71 | M5.Lcd.fillScreen(WHITE); 72 | M5.Lcd.setTextColor(BLACK, WHITE); 73 | M5.Lcd.println("mic test"); 74 | 75 | i2sInit(); 76 | xTaskCreate(mic_record_task, "mic_record_task", 2048, NULL, 1, NULL); 77 | } 78 | 79 | void loop() { 80 | printf("loop cycling\n"); 81 | vTaskDelay(1000 / portTICK_RATE_MS); // otherwise the main task wastes half 82 | // of the cpu cycles 83 | } 84 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: BasicHTTPClient. 10 | * Date: 2021/9/18 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(); 24 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 25 | wifiMulti.addAP("M5", "41231243"); // Storage wifi configuration 26 | // information. 存储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 | Serial.printf("[HTTP] GET... code: %d\n", httpCode); 45 | M5.Lcd.print("Please see Serial."); 46 | if (httpCode == 47 | HTTP_CODE_OK) { // file found at server. 在服务器上找到文件 48 | String payload = http.getString(); 49 | Serial.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.fillRect(0, 0, 160, 80, BLACK); // clear the screen. 清除屏幕 62 | } 63 | -------------------------------------------------------------------------------- /examples/Unit/Dual_Button/Dual_Button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | This Unit connects to GRVOE B on M5Core. 3 | */ 4 | #include 5 | 6 | int last_value_red = 0; 7 | int cur_value_red = 0; 8 | int last_value_blue = 0; 9 | int cur_value_blue = 0; 10 | 11 | void setup() { 12 | // init lcd 13 | M5.begin(); 14 | M5.Lcd.setRotation(3); 15 | M5.Lcd.setTextSize(2); // title size 16 | pinMode(32, INPUT); 17 | pinMode(33, INPUT); 18 | M5.Lcd.setTextColor(YELLOW); 19 | M5.Lcd.setCursor(5, 2); 20 | M5.Lcd.println("Dual Button example"); 21 | M5.Lcd.setTextColor(WHITE); 22 | 23 | M5.Lcd.setTextSize(1); // text size 24 | } 25 | 26 | void loop() { 27 | cur_value_red = digitalRead(32); 28 | cur_value_blue = digitalRead(33); 29 | 30 | M5.Lcd.setCursor(40, 25); 31 | M5.Lcd.print("Blue Status: "); 32 | M5.Lcd.setCursor(40, 40); 33 | M5.Lcd.print("Blue Value: "); 34 | M5.Lcd.setCursor(40, 55); 35 | M5.Lcd.print(" Red Status: "); 36 | M5.Lcd.setCursor(40, 70); 37 | M5.Lcd.print(" Red Value: "); 38 | 39 | if (cur_value_blue != last_value_blue) { 40 | M5.Lcd.fillRect(135, 25, 100, 15, BLACK); 41 | M5.Lcd.fillRect(135, 40, 100, 15, BLACK); 42 | if (cur_value_blue == 0) { 43 | M5.Lcd.setCursor(135, 25); 44 | M5.Lcd.print("pressed"); 45 | M5.Lcd.setCursor(135, 40); 46 | M5.Lcd.print("0"); 47 | Serial.println("Button Status: blue pressed"); 48 | Serial.println(" value: 0"); 49 | } else { 50 | M5.Lcd.setCursor(135, 25); 51 | M5.Lcd.print("released"); 52 | M5.Lcd.setCursor(135, 40); 53 | M5.Lcd.print("1"); 54 | Serial.println("Button Status: blue released"); 55 | Serial.println(" value: 1"); 56 | } 57 | last_value_blue = cur_value_blue; 58 | } 59 | 60 | if (cur_value_red != last_value_red) { 61 | M5.Lcd.fillRect(135, 55, 100, 15, BLACK); 62 | M5.Lcd.fillRect(135, 70, 100, 15, BLACK); 63 | if (cur_value_red == 0) { 64 | M5.Lcd.setCursor(135, 55); 65 | M5.Lcd.print("pressed"); 66 | M5.Lcd.setCursor(135, 70); 67 | M5.Lcd.print("0"); 68 | Serial.println("Button Status: red pressed"); 69 | Serial.println(" value: 0"); 70 | } else { 71 | M5.Lcd.setCursor(135, 55); 72 | M5.Lcd.print("released"); 73 | M5.Lcd.setCursor(135, 70); 74 | M5.Lcd.print("1"); 75 | Serial.println("Button Status: red released"); 76 | Serial.println(" value: 1"); 77 | } 78 | last_value_red = cur_value_red; 79 | } 80 | 81 | M5.update(); 82 | } 83 | -------------------------------------------------------------------------------- /examples/Hat/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 | #define SCALEALPHA 0.000001 21 | 22 | typedef struct { 23 | int16_t kVdd; 24 | int16_t vdd25; 25 | float KvPTAT; 26 | float KtPTAT; 27 | uint16_t vPTAT25; 28 | float alphaPTAT; 29 | int16_t gainEE; 30 | float tgc; 31 | float cpKv; 32 | float cpKta; 33 | uint8_t resolutionEE; 34 | uint8_t calibrationModeEE; 35 | float KsTa; 36 | float ksTo[5]; 37 | int16_t ct[5]; 38 | uint16_t alpha[768]; 39 | uint8_t alphaScale; 40 | int16_t offset[768]; 41 | int8_t kta[768]; 42 | uint8_t ktaScale; 43 | int8_t kv[768]; 44 | uint8_t kvScale; 45 | float cpAlpha[2]; 46 | int16_t cpOffset[2]; 47 | float ilChessC[3]; 48 | uint16_t brokenPixels[5]; 49 | uint16_t outlierPixels[5]; 50 | } paramsMLX90640; 51 | 52 | int MLX90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData); 53 | int MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData); 54 | int MLX90640_ExtractParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); 55 | float MLX90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *params); 56 | float MLX90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params); 57 | void MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *params, 58 | float *result); 59 | void MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *params, 60 | float emissivity, float tr, float *result); 61 | int MLX90640_SetResolution(uint8_t slaveAddr, uint8_t resolution); 62 | int MLX90640_GetCurResolution(uint8_t slaveAddr); 63 | int MLX90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate); 64 | int MLX90640_GetRefreshRate(uint8_t slaveAddr); 65 | int MLX90640_GetSubPageNumber(uint16_t *frameData); 66 | int MLX90640_GetCurMode(uint8_t slaveAddr); 67 | int MLX90640_SetInterleavedMode(uint8_t slaveAddr); 68 | int MLX90640_SetChessMode(uint8_t slaveAddr); 69 | void MLX90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, 70 | paramsMLX90640 *params); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /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 | #define SCALEALPHA 0.000001 21 | 22 | typedef struct { 23 | int16_t kVdd; 24 | int16_t vdd25; 25 | float KvPTAT; 26 | float KtPTAT; 27 | uint16_t vPTAT25; 28 | float alphaPTAT; 29 | int16_t gainEE; 30 | float tgc; 31 | float cpKv; 32 | float cpKta; 33 | uint8_t resolutionEE; 34 | uint8_t calibrationModeEE; 35 | float KsTa; 36 | float ksTo[5]; 37 | int16_t ct[5]; 38 | uint16_t alpha[768]; 39 | uint8_t alphaScale; 40 | int16_t offset[768]; 41 | int8_t kta[768]; 42 | uint8_t ktaScale; 43 | int8_t kv[768]; 44 | uint8_t kvScale; 45 | float cpAlpha[2]; 46 | int16_t cpOffset[2]; 47 | float ilChessC[3]; 48 | uint16_t brokenPixels[5]; 49 | uint16_t outlierPixels[5]; 50 | } paramsMLX90640; 51 | 52 | int MLX90640_DumpEE(uint8_t slaveAddr, uint16_t *eeData); 53 | int MLX90640_GetFrameData(uint8_t slaveAddr, uint16_t *frameData); 54 | int MLX90640_ExtractParameters(uint16_t *eeData, paramsMLX90640 *mlx90640); 55 | float MLX90640_GetVdd(uint16_t *frameData, const paramsMLX90640 *params); 56 | float MLX90640_GetTa(uint16_t *frameData, const paramsMLX90640 *params); 57 | void MLX90640_GetImage(uint16_t *frameData, const paramsMLX90640 *params, 58 | float *result); 59 | void MLX90640_CalculateTo(uint16_t *frameData, const paramsMLX90640 *params, 60 | float emissivity, float tr, float *result); 61 | int MLX90640_SetResolution(uint8_t slaveAddr, uint8_t resolution); 62 | int MLX90640_GetCurResolution(uint8_t slaveAddr); 63 | int MLX90640_SetRefreshRate(uint8_t slaveAddr, uint8_t refreshRate); 64 | int MLX90640_GetRefreshRate(uint8_t slaveAddr); 65 | int MLX90640_GetSubPageNumber(uint16_t *frameData); 66 | int MLX90640_GetCurMode(uint8_t slaveAddr); 67 | int MLX90640_SetInterleavedMode(uint8_t slaveAddr); 68 | int MLX90640_SetChessMode(uint8_t slaveAddr); 69 | void MLX90640_BadPixelsCorrection(uint16_t *pixels, float *to, int mode, 70 | paramsMLX90640 *params); 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiSmartConfig/WiFiSmartConfig.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC sample source code 5 | * 配套 M5StickC 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc 8 | * 9 | * Describe: WIFI Smart Config. WIFI智能配网 10 | * Date: 2021/7/30 11 | ******************************************************************************* 12 | * Fill in WIFI configuration information through mobile APP to connect M5StickC 13 | *to relevant WIFI 通过手机APP填写WIFI配置信息使 M5StickC连接至相关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 M5StickC. 初始化 M5StickC 23 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 24 | WiFi.mode(WIFI_AP_STA); // Set the wifi mode to the mode compatible with 25 | // the AP and Station, and start intelligent 26 | // network configuration 27 | WiFi.beginSmartConfig(); // 设置wifi模式为AP 与 Station 28 | // 兼容模式,并开始智能配网 29 | 30 | // Wait for the M5StickC to receive network information from the phone 31 | // 等待M5StickC接收到来自手机的配网信息 32 | M5.Lcd.print( 33 | "\nWaiting for Phone SmartConfig."); // Screen print format string. 34 | // 屏幕打印格式化字符串 35 | while (!WiFi.smartConfigDone()) { // If the smart network is not completed. 36 | // 若智能配网没有完成 37 | delay(500); 38 | M5.Lcd.print("."); 39 | } 40 | M5.Lcd.println("\nSmartConfig received."); 41 | 42 | M5.Lcd.println("Waiting for WiFi"); 43 | while ( 44 | WiFi.status() != 45 | WL_CONNECTED) { // M5StickC will connect automatically upon receipt of 46 | // the configuration information, and return true if 47 | // the connection is successful. 48 | // 收到配网信息后M5StickC将自动连接,若连接成功将返回true 49 | delay(500); 50 | M5.Lcd.print("."); 51 | } 52 | M5.Lcd.fillScreen(BLACK); 53 | M5.lcd.setCursor(0, 0); 54 | M5.Lcd.print("\nWiFi Connect To: "); 55 | M5.Lcd.println(WiFi.SSID()); // Output Network name. 输出网络名称 56 | M5.Lcd.print("IP address: "); 57 | M5.Lcd.println(WiFi.localIP()); // Output IP Address. 输出IP地址 58 | M5.Lcd.print("RSSI: "); 59 | M5.Lcd.println(WiFi.RSSI()); // Output signal strength. 输出信号强度 60 | } 61 | 62 | void loop() { 63 | } -------------------------------------------------------------------------------- /examples/Hat/YUN/SHT20.cpp: -------------------------------------------------------------------------------- 1 | #include "SHT20.h" 2 | 3 | static bool I2C_readBytes(uint8_t address, uint8_t subAddress, uint8_t count, 4 | uint8_t* dest) { 5 | Wire.beginTransmission(address); // Initialize the Tx buffer 6 | Wire.write(subAddress); // Put slave register address in Tx buffer 7 | if (Wire.endTransmission() != 0) { 8 | return false; 9 | } 10 | 11 | uint8_t time_count = 0; 12 | while (Wire.requestFrom(address, (uint8_t)count) != count) { 13 | if (time_count++ > 10) { 14 | return false; 15 | } 16 | delay(10); 17 | } 18 | 19 | uint8_t i = 0; 20 | while (Wire.available()) { 21 | dest[i++] = Wire.read(); // Put read results in the Rx buffer 22 | } 23 | return true; 24 | } 25 | 26 | bool SHT20::check_crc(uint16_t data_in, uint8_t crc) { 27 | uint32_t remainder = data_in << 8; 28 | uint32_t divsor = SHIFTED_DIVISOR; 29 | 30 | remainder |= crc; 31 | for (int i = 0; i < 16; i++) { 32 | if (remainder & (uint32_t)1 << (23 - i)) { 33 | remainder ^= divsor; 34 | } 35 | divsor >>= 1; 36 | } 37 | 38 | return remainder == 0; 39 | } 40 | 41 | bool SHT20::I2C_read_u16(uint8_t reg, uint16_t* val) { 42 | uint8_t buffer[3] = {0x00}; 43 | 44 | if (I2C_readBytes(SHT20_ADDR, reg, 3, buffer) != true) { 45 | return false; 46 | } 47 | 48 | uint16_t rawValue = (buffer[0] << 8) | buffer[1]; 49 | if (check_crc(rawValue, buffer[2]) != true) { 50 | return false; 51 | } 52 | *val = rawValue & 0xFFFC; 53 | return true; 54 | } 55 | 56 | float SHT20::read_humidity(void) { 57 | uint16_t rawHumidity = 0; 58 | 59 | if (I2C_read_u16(TRIGGER_HUMD_MEASURE_NOHOLD, &rawHumidity) != true) { 60 | return 0; 61 | } 62 | 63 | float hum = -6.0 + rawHumidity * (125.0 / 65536.0); 64 | return hum; 65 | } 66 | 67 | float SHT20::read_temperature(void) { 68 | uint16_t rawTemperature = 0; 69 | 70 | if (I2C_read_u16(TRIGGER_TEMP_MEASURE_NOHOLD, &rawTemperature) != true) { 71 | return 0; 72 | } 73 | 74 | float tempTemperature = -46.85 + (float)rawTemperature * (175.72 / 65536.0); 75 | return tempTemperature; 76 | } 77 | 78 | void SHT20::set_resolution(uint8_t resolution) { 79 | byte userRegister = read_register(); 80 | userRegister &= B01111110; 81 | resolution &= B10000001; 82 | userRegister |= resolution; 83 | write_register(userRegister); 84 | } 85 | 86 | uint8_t SHT20::read_register(void) { 87 | uint8_t reg = 0x00; 88 | I2C_readBytes(SHT20_ADDR, READ_USER_REG, 1, ®); 89 | return reg; 90 | } 91 | 92 | void SHT20::write_register(byte val) { 93 | Wire.beginTransmission(SHT20_ADDR); 94 | Wire.write(WRITE_USER_REG); 95 | Wire.write(val); 96 | Wire.endTransmission(); 97 | } 98 | -------------------------------------------------------------------------------- /examples/Unit/ACCEL_ADXL345/ACCEL_ADXL345.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Description: Read ACCEL Unit three-axis acceleration 3 | Please install library before compiling: 4 | Arduino-ADXL345: https://github.com/jakalada/Arduino-ADXL345 5 | */ 6 | #include 7 | #include 8 | ADXL345 accel(ADXL345_ALT); 9 | 10 | void setup() { 11 | // put your setup code here, to run once: 12 | M5.begin(); 13 | Wire.begin(32, 33); 14 | M5.Lcd.setCursor(40, 5, 4); 15 | M5.Lcd.println("ACC"); 16 | 17 | M5.Lcd.setCursor(30, 40); 18 | M5.Lcd.print(" x "); 19 | M5.Lcd.setCursor(30, 80); 20 | M5.Lcd.print(" y "); 21 | M5.Lcd.setCursor(30, 120); 22 | M5.Lcd.print(" z "); 23 | 24 | byte deviceID = accel.readDeviceID(); 25 | if (deviceID != 0) { 26 | Serial.print("0x"); 27 | Serial.print(deviceID, HEX); 28 | Serial.println(""); 29 | } else { 30 | Serial.println("read device id: failed"); 31 | while (1) { 32 | delay(100); 33 | } 34 | } 35 | 36 | // Data Rate 37 | // - ADXL345_RATE_3200HZ: 3200 Hz 38 | // - ADXL345_RATE_1600HZ: 1600 Hz 39 | // - ADXL345_RATE_800HZ: 800 Hz 40 | // - ADXL345_RATE_400HZ: 400 Hz 41 | // - ADXL345_RATE_200HZ: 200 Hz 42 | // - ADXL345_RATE_100HZ: 100 Hz 43 | // - ADXL345_RATE_50HZ: 50 Hz 44 | // - ADXL345_RATE_25HZ: 25 Hz 45 | // - ... 46 | if (!accel.writeRate(ADXL345_RATE_200HZ)) { 47 | Serial.println("write rate: failed"); 48 | while (1) { 49 | delay(100); 50 | } 51 | } 52 | 53 | // Data Range 54 | // - ADXL345_RANGE_2G: +-2 g 55 | // - ADXL345_RANGE_4G: +-4 g 56 | // - ADXL345_RANGE_8G: +-8 g 57 | // - ADXL345_RANGE_16G: +-16 g 58 | if (!accel.writeRange(ADXL345_RANGE_16G)) { 59 | Serial.println("write range: failed"); 60 | while (1) { 61 | delay(100); 62 | } 63 | } 64 | 65 | if (!accel.start()) { 66 | Serial.println("start: failed"); 67 | while (1) { 68 | delay(100); 69 | } 70 | } 71 | } 72 | 73 | void loop() { 74 | // put your main code here, to run repeatedly: 75 | if (accel.update()) { 76 | M5.Lcd.fillRect(60, 40, 80, 20, BLACK); 77 | M5.Lcd.setCursor(60, 40); 78 | M5.Lcd.print((int)(1000 * accel.getX())); 79 | M5.Lcd.fillRect(60, 80, 80, 20, BLACK); 80 | M5.Lcd.setCursor(60, 80); 81 | M5.Lcd.print((int)(1000 * accel.getY())); 82 | M5.Lcd.fillRect(60, 120, 80, 20, BLACK); 83 | M5.Lcd.setCursor(60, 120); 84 | M5.Lcd.print((int)(1000 * accel.getZ())); 85 | // M5.Lcd.setCursor(300, 130); M5.Lcd.print("mg"); 86 | } else { 87 | Serial.println("update failed"); 88 | while (1) { 89 | delay(100); 90 | } 91 | } 92 | delay(100); 93 | } 94 | -------------------------------------------------------------------------------- /examples/Hat/YUN/YUN.ino: -------------------------------------------------------------------------------- 1 | // please install Adafruit_BMP280 lib first 2 | // Adafruit_BMP280 lib in Sketch->Includ Library->Library Manager 3 | 4 | #include 5 | #include 6 | #include "SHT20.h" 7 | #include "yunBoard.h" 8 | #include 9 | #include "display.h" 10 | 11 | SHT20 sht20; 12 | Adafruit_BMP280 bmp; 13 | 14 | uint32_t update_time = 0; 15 | float tmp, hum; 16 | float pressure; 17 | uint16_t light; 18 | extern uint8_t lightR; 19 | extern uint8_t lightG; 20 | 21 | void setup() { 22 | int8_t i, j; 23 | M5.begin(); 24 | Wire.begin(0, 26, 100000UL); 25 | M5.Lcd.setRotation(1); 26 | M5.Lcd.setTextSize(2); 27 | 28 | // RGB888 29 | // led_set(uint8_t 1, 0x080808); 30 | 31 | if (!bmp.begin(0x76)) { 32 | Serial.println( 33 | F("Could not find a valid BMP280 sensor, check wiring!")); 34 | } 35 | 36 | /* Default settings from datasheet. */ 37 | bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode. */ 38 | Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ 39 | Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */ 40 | Adafruit_BMP280::FILTER_X16, /* Filtering. */ 41 | Adafruit_BMP280::STANDBY_MS_1000); /* Standby time. */ 42 | 43 | // put your setup code here, to run once: 44 | display_light4(); 45 | } 46 | 47 | uint8_t light_flag = 0; 48 | 49 | void loop() { 50 | // led_set_all((lightR << 16) | (lightG << 8) | lightB); 51 | if (millis() > update_time) { 52 | update_time = millis() + 1000; 53 | tmp = sht20.read_temperature(); 54 | hum = sht20.read_humidity(); 55 | light = light_get(); 56 | pressure = bmp.readPressure(); 57 | M5.Lcd.setCursor(3, 3); 58 | M5.Lcd.setTextColor(TFT_BLUE, TFT_BLACK); 59 | M5.Lcd.print("YUN"); 60 | M5.Lcd.setCursor(0, 25); 61 | M5.Lcd.setTextColor(TFT_RED, TFT_BLACK); 62 | M5.Lcd.printf("%.2fC\r\n", tmp); 63 | M5.Lcd.setCursor(0, 25 + 20); 64 | M5.Lcd.setTextColor(TFT_RED, TFT_BLACK); 65 | M5.Lcd.printf("%d", int(hum)); 66 | M5.Lcd.print("%\r\n"); 67 | M5.Lcd.setCursor(0, 25 + 20 + 20); 68 | M5.Lcd.setTextColor(TFT_RED, TFT_BLACK); 69 | M5.Lcd.printf("%d Pa\r\n", int(pressure)); 70 | } 71 | M5.update(); 72 | 73 | if (M5.BtnA.wasPressed()) { 74 | esp_restart(); 75 | } 76 | 77 | delay(10); 78 | // put your main code here, to run repeatedly: 79 | 80 | display_light(); 81 | if (light > 1500) { 82 | if (light_flag == 0) { 83 | light_flag = 1; 84 | lightR = 40; 85 | lightG = 40; 86 | } 87 | led_breath(); 88 | } else { 89 | led_off(); 90 | light_flag = 0; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/AXP192.h: -------------------------------------------------------------------------------- 1 | #ifndef __AXP192_H__ 2 | #define __AXP192_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define SLEEP_MSEC(us) (((uint64_t)us) * 1000L) 8 | #define SLEEP_SEC(us) (((uint64_t)us) * 1000000L) 9 | #define SLEEP_MIN(us) (((uint64_t)us) * 60L * 1000000L) 10 | #define SLEEP_HR(us) (((uint64_t)us) * 60L * 60L * 1000000L) 11 | 12 | class AXP192 { 13 | public: 14 | AXP192(); 15 | void begin(void); 16 | void ScreenBreath(int brightness); 17 | void ScreenSwitch(bool state); 18 | 19 | bool GetBatState(); 20 | 21 | void EnableCoulombcounter(void); 22 | void DisableCoulombcounter(void); 23 | void StopCoulombcounter(void); 24 | void ClearCoulombcounter(void); 25 | uint32_t GetCoulombchargeData(void); 26 | uint32_t GetCoulombdischargeData(void); 27 | float GetCoulombData(void); 28 | 29 | uint16_t GetVbatData(void) __attribute__((deprecated)); 30 | uint16_t GetIchargeData(void) __attribute__((deprecated)); 31 | uint16_t GetIdischargeData(void) __attribute__((deprecated)); 32 | uint16_t GetTempData(void) __attribute__((deprecated)); 33 | uint32_t GetPowerbatData(void) __attribute__((deprecated)); 34 | uint16_t GetVinData(void) __attribute__((deprecated)); 35 | uint16_t GetIinData(void) __attribute__((deprecated)); 36 | uint16_t GetVusbinData(void) __attribute__((deprecated)); 37 | uint16_t GetIusbinData(void) __attribute__((deprecated)); 38 | uint16_t GetVapsData(void) __attribute__((deprecated)); 39 | uint8_t GetBtnPress(void); 40 | 41 | // -- sleep 42 | void SetSleep(void); 43 | void WakeUpDisplayAfterLightSleep(void); 44 | void DeepSleep(uint64_t time_in_us = 0); 45 | void LightSleep(uint64_t time_in_us = 0); 46 | uint8_t GetWarningLeve(void); 47 | 48 | public: 49 | // void SetChargeVoltage( uint8_t ); 50 | // void SetChargeCurrent( uint8_t ); 51 | float GetBatVoltage(); 52 | float GetBatCurrent(); 53 | float GetVinVoltage(); 54 | float GetVinCurrent(); 55 | float GetVBusVoltage(); 56 | float GetVBusCurrent(); 57 | float GetTempInAXP192(); 58 | float GetBatPower(); 59 | float GetBatChargeCurrent(); 60 | float GetAPSVoltage(); 61 | float GetBatCoulombInput(); 62 | float GetBatCoulombOut(); 63 | uint8_t GetWarningLevel(void); 64 | void SetCoulombClear(); 65 | void SetLDO2(bool State); 66 | void SetPeripherialsPower(uint8_t state); 67 | 68 | // -- Power Off 69 | void PowerOff(); 70 | 71 | public: 72 | void Write1Byte(uint8_t Addr, uint8_t Data); 73 | uint8_t Read8bit(uint8_t Addr); 74 | uint16_t Read12Bit(uint8_t Addr); 75 | uint16_t Read13Bit(uint8_t Addr); 76 | uint16_t Read16bit(uint8_t Addr); 77 | uint32_t Read24bit(uint8_t Addr); 78 | uint32_t Read32bit(uint8_t Addr); 79 | void ReadBuff(uint8_t Addr, uint8_t Size, uint8_t *Buff); 80 | }; 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /examples/Hat/DAC2_GP8413/DAC2_GP8413.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DAC2_GP8413.ino 3 | * @author SeanKwok (shaoxiang@m5stack.com) 4 | * @brief M5StickCPlus Hat DAC2 Test 5 | * @version 0.1 6 | * @date 2024-01-09 7 | * 8 | * 9 | * @Hardwares: M5StickCPlus + Hat 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(0, 26); 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("BtnA 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.BtnA.wasClicked()) { 82 | output = !output; 83 | if (output) { 84 | AllOutputCtl(3300); 85 | // AllOutputCtl(10000); 86 | } else { 87 | AllOutputCtl(0); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /examples/Unit/DAC2_GP8413/DAC2_GP8413.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * @file DAC2_GP8413.ino 3 | * @author SeanKwok (shaoxiang@m5stack.com) 4 | * @brief M5StickCPlus Unit DAC2 Test 5 | * @version 0.1 6 | * @date 2024-01-09 7 | * 8 | * 9 | * @Hardwares: M5StickCPlus + 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("BtnA 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.BtnA.wasClicked()) { 82 | output = !output; 83 | if (output) { 84 | AllOutputCtl(3300); 85 | // AllOutputCtl(10000); 86 | } else { 87 | AllOutputCtl(0); 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /examples/Hat/DAC_ADS1100/Adafruit_MCP4725.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************************************/ 2 | /*! 3 | @file Adafruit_MCP4725.cpp 4 | @author K.Townsend (Adafruit Industries) 5 | @license BSD (see license.txt) 6 | 7 | I2C Driver for Microchip's MCP4725 I2C DAC 8 | 9 | This is a library for the Adafruit MCP4725 breakout 10 | ----> http://www.adafruit.com/products/935 11 | 12 | Adafruit invests time and resources providing this open source code, 13 | please support Adafruit and open-source hardware by purchasing 14 | products from Adafruit! 15 | 16 | @section HISTORY 17 | 18 | v1.0 - First release 19 | */ 20 | /**************************************************************************/ 21 | #if ARDUINO >= 100 22 | #include "Arduino.h" 23 | #else 24 | #include "WProgram.h" 25 | #endif 26 | 27 | #include 28 | 29 | #include "Adafruit_MCP4725.h" 30 | 31 | /**************************************************************************/ 32 | /*! 33 | @brief Instantiates a new MCP4725 class 34 | */ 35 | /**************************************************************************/ 36 | Adafruit_MCP4725::Adafruit_MCP4725() { 37 | } 38 | 39 | /**************************************************************************/ 40 | /*! 41 | @brief Setups the HW 42 | */ 43 | /**************************************************************************/ 44 | void Adafruit_MCP4725::begin(uint8_t addr) { 45 | _i2caddr = addr; 46 | Wire.begin(0, 26); 47 | } 48 | 49 | /**************************************************************************/ 50 | /*! 51 | @brief Sets the output voltage to a fraction of source vref. (Value 52 | can be 0..4095) 53 | 54 | @param[in] output 55 | The 12-bit value representing the relationship between 56 | the DAC's input voltage and its output voltage. 57 | @param[in] writeEEPROM 58 | If this value is true, 'output' will also be written 59 | to the MCP4725's internal non-volatile memory, meaning 60 | that the DAC will retain the current voltage output 61 | after power-down or reset. 62 | */ 63 | /**************************************************************************/ 64 | void Adafruit_MCP4725::setVoltage(uint16_t output, bool writeEEPROM) { 65 | #ifdef TWBR 66 | uint8_t twbrback = TWBR; 67 | TWBR = ((F_CPU / 400000L) - 16) / 2; // Set I2C frequency to 400kHz 68 | #endif 69 | Wire.beginTransmission(_i2caddr); 70 | if (writeEEPROM) { 71 | Wire.write(MCP4726_CMD_WRITEDACEEPROM); 72 | } else { 73 | Wire.write(MCP4726_CMD_WRITEDAC); 74 | } 75 | Wire.write(output / 16); // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4) 76 | Wire.write((output % 16) << 4); // Lower data bits (D3.D2.D1.D0.x.x.x.x) 77 | Wire.endTransmission(); 78 | #ifdef TWBR 79 | TWBR = twbrback; 80 | #endif 81 | } 82 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/Unit/KEY/KEY.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2022 by M5Stack 4 | * Equipped with M5StickCPlus sample source code 5 | * 配套 M5StickCPlus 示例源代码 6 | * 7 | * Visit for more information: https://docs.m5stack.com/en/unit/key 8 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/key 9 | * 10 | * Product: UNIT-KEY example 11 | * Date: 2022/6/1 12 | ******************************************************************************* 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | uint8_t ledColor = 0; 19 | 20 | #define KEY_PIN 33 // Define Key Pin. 定义Key引脚 21 | #define DATA_PIN 32 // Define LED pin. 定义LED引脚. 22 | CRGB leds[1]; // Define the array of leds. 定义LED阵列. 23 | 24 | void LED(void *parameter); 25 | void changeLedColor(); 26 | 27 | void setup() { 28 | M5.begin(); // Init M5Stack 初始化M5Stack 29 | M5.Lcd.setCursor(0, 25, 2); 30 | M5.Lcd.print((" UNIT-KEY\n Example\n\n Key State:")); 31 | 32 | pinMode(KEY_PIN, INPUT_PULLUP); // Init Key pin. 初始化Key引脚. 33 | 34 | FastLED.addLeds(leds, 35 | 1); // Init FastLED. 初始化FastLED. 36 | 37 | xTaskCreate( 38 | LED, "led", 1000, NULL, 0, 39 | NULL); // Create a thread for breathing LED. 创建一个线程用于LED呼吸灯. 40 | } 41 | 42 | void loop() { 43 | if (!digitalRead(KEY_PIN)) { // If Key was pressed. 如果按键按下. 44 | M5.Lcd.setCursor(0, 100, 2); 45 | M5.Lcd.print((" Pressed ")); 46 | changeLedColor(); // Change LED color. 更换LED呼吸灯颜色. 47 | while (!digitalRead( 48 | KEY_PIN)) // Hold until the key released. 在松开按键前保持状态. 49 | ; 50 | } else { 51 | M5.Lcd.setCursor(0, 100, 2); 52 | M5.Lcd.println((" Released")); 53 | } 54 | delay(100); 55 | } 56 | 57 | void LED(void *parameter) { 58 | leds[0] = CRGB::Red; 59 | for (;;) { 60 | for (int i = 0; i < 255; 61 | i++) { // Set LED brightness from 0 to 255. 设置LED亮度从0到255. 62 | FastLED.setBrightness(i); 63 | FastLED.show(); 64 | delay(5); 65 | } 66 | for (int i = 255; i > 0; 67 | i--) { // Set LED brightness from 255 to 0. 设置LED亮度从255到0. 68 | FastLED.setBrightness(i); 69 | FastLED.show(); 70 | delay(5); 71 | } 72 | } 73 | vTaskDelete(NULL); 74 | } 75 | 76 | void changeLedColor() { 77 | ledColor++; 78 | if (ledColor > 2) ledColor = 0; 79 | switch ( 80 | ledColor) { // Change LED colors between R,G,B. 在红绿蓝中切换LED颜色. 81 | case 0: 82 | leds[0] = CRGB::Red; 83 | break; 84 | case 1: 85 | leds[0] = CRGB::Green; 86 | break; 87 | case 2: 88 | leds[0] = CRGB::Blue; 89 | break; 90 | default: 91 | break; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiScan/WiFiScan.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: Wifi scan. wifi扫描 10 | * Date: 2022/4/3 11 | ******************************************************************************* 12 | http://forum.m5stack.com/topic/58/lesson-3-wi-fi-scanner 13 | Press M5 to start/re-scan wifi, press up to turn down the page 14 | 按下M5键以开始/重新扫描wifi,按下上键向下翻页 15 | */ 16 | 17 | #include 18 | 19 | #include "WiFi.h" 20 | 21 | int n; 22 | int ssidLength = 10; 23 | int thisPage = 0; 24 | const int pageSize = 12; 25 | bool on = false; 26 | 27 | void LCD_Clear() { 28 | M5.Lcd.fillScreen(BLACK); 29 | M5.Lcd.setCursor(0, 0); 30 | M5.Lcd.setTextColor(WHITE); 31 | M5.Lcd.setTextSize(2); 32 | } 33 | 34 | void Show(int nav = 0) // -1 top, 1 bottom 35 | { 36 | if ((nav == 1) && (on == true)) { 37 | if ((thisPage) < ((n - 1) / pageSize)) { 38 | thisPage++; 39 | } else { 40 | thisPage = 0; 41 | } 42 | Show(); 43 | } else { 44 | LCD_Clear(); 45 | M5.Lcd.setTextSize(1); 46 | M5.Lcd.setCursor(30, 5); 47 | M5.Lcd.print("TOTAL: "); 48 | M5.Lcd.print(n); 49 | M5.Lcd.setCursor(0, 16); 50 | for (int i = (thisPage * pageSize); 51 | i < ((thisPage * pageSize) + pageSize); i++) { 52 | if (i >= n) break; 53 | String ssid = (WiFi.SSID(i).length() > ssidLength) 54 | ? (WiFi.SSID(i).substring(0, ssidLength) + "...") 55 | : WiFi.SSID(i); 56 | M5.Lcd.print(" " + String(i + 1)); 57 | M5.Lcd.print(") " + ssid + " (" + WiFi.RSSI(i) + ");\n"); 58 | } 59 | } 60 | } 61 | 62 | void Search() { 63 | on = true; 64 | thisPage = 0; 65 | LCD_Clear(); 66 | M5.Lcd.setTextSize(2); 67 | M5.Lcd.setCursor(50, 20); 68 | M5.Lcd.setTextColor(TFT_YELLOW); 69 | M5.Lcd.printf("Please, wait"); 70 | M5.Lcd.setTextSize(1); 71 | M5.Lcd.setTextColor(TFT_ORANGE); 72 | M5.Lcd.setCursor(80, 50); 73 | M5.Lcd.printf("Searching..."); 74 | n = WiFi.scanNetworks(); 75 | Show(); 76 | } 77 | 78 | void setup() { 79 | M5.begin(); 80 | WiFi.mode(WIFI_STA); 81 | WiFi.disconnect(); 82 | M5.Lcd.setRotation(1); 83 | M5.Lcd.setTextSize(2); 84 | M5.Lcd.setTextColor(GREEN); 85 | M5.Lcd.setCursor(90, 20); 86 | M5.Lcd.printf("Wi-Fi"); 87 | M5.Lcd.setCursor(75, 45); 88 | M5.Lcd.printf("scanner"); 89 | } 90 | 91 | void loop() { 92 | if (M5.BtnA.wasPressed()) Search(); 93 | if (M5.BtnB.wasPressed()) Show(1); 94 | M5.update(); 95 | } -------------------------------------------------------------------------------- /examples/Advanced/I2C_Tester/I2C_Tester.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: I2C Scanner. I2C探测 10 | * Date: 2021/9/18 11 | ******************************************************************************* 12 | This program scans the addresses 1-127 continuosly and shows the devices found 13 | on the TFT. 该程序连续扫描地址 1-127 并显示在外部(内部)I2C发现的设备。 14 | */ 15 | #include 16 | 17 | void setup() { 18 | M5.begin(); 19 | // For HY2.0-4P 20 | Wire.begin(); // Init wire and join the I2C network. 21 | // 初始化wire,并且加入到I2C网络 22 | // For HAT 23 | // Wire1.begin(0,26); 24 | // Wire.begin(21, 22); //Detect internal I2C, if this sentence is not added, 25 | // it will detect external I2C. 检测内部I2C,若不加此句为检测外部I2C 26 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 27 | M5.Lcd.setTextColor( 28 | YELLOW); // Set the font color to yellow. 设置字体颜色为黄色 29 | M5.Lcd.println("M5StickC I2C Tester"); // Print a string on the screen. 30 | // 在屏幕上打印字符串 31 | } 32 | 33 | int textColor = YELLOW; 34 | 35 | void loop() { 36 | int address; 37 | int error; 38 | int error1; 39 | M5.Lcd.setCursor(0, 0); 40 | M5.Lcd.println("scanning Address [HEX]"); 41 | 42 | for (address = 1; address < 127; address++) { 43 | Wire.beginTransmission( 44 | address); // Data transmission to the specified device address 45 | // starts. 开始向指定的设备地址进行传输数据 46 | Wire1.beginTransmission(address); 47 | error = Wire.endTransmission(); /*Stop data transmission with the slave. 48 | 停止与从机的数据传输 0: success. 成功 1: The amount of data 49 | exceeds the transmission buffer capacity limit. 50 | 数据量超过传送缓存容纳限制 return value: 2: 51 | Received NACK when sending address. 传送地址时收到 NACK 3: 52 | Received NACK when transmitting data. 传送数据时收到 NACK 53 | 4: Other errors. 其它错误 */ 54 | error1 = Wire1.endTransmission(); 55 | if ((error == 0) || (error1 == 0)) { 56 | M5.Lcd.print(address, HEX); 57 | M5.Lcd.print(" "); 58 | } else 59 | M5.Lcd.print("."); 60 | 61 | delay(10); 62 | } 63 | 64 | if (textColor == YELLOW) 65 | textColor = GREEN; 66 | else 67 | textColor = YELLOW; 68 | M5.Lcd.setTextColor(textColor, 69 | BLACK); // Set the foreground color of the text to 70 | // textColor and the background color to BLACK. 71 | // 设置文字的前景色为textColor背景色为BLACK 72 | } 73 | -------------------------------------------------------------------------------- /examples/Hat/C_BACK_DRIVER/CBACK_DRIVER.cpp: -------------------------------------------------------------------------------- 1 | #include "CBACK_DRIVER.h" 2 | 3 | void CBACK_DRIVER::Init() { 4 | Wire.begin(0, 26); 5 | } 6 | 7 | void CBACK_DRIVER::Write1Byte(uint8_t address, uint8_t Register_address, 8 | uint8_t data) { 9 | Wire.beginTransmission(address); 10 | Wire.write(Register_address); 11 | Wire.write(data); 12 | Wire.endTransmission(); 13 | } 14 | 15 | void CBACK_DRIVER::Write2Byte(uint8_t address, uint8_t Register_address, 16 | uint16_t data) { 17 | Wire.beginTransmission(address); 18 | Wire.write(Register_address); 19 | Wire.write(data >> 8); // MSB 20 | Wire.write(data & 0xFF); // LSB 21 | 22 | Wire.endTransmission(); 23 | } 24 | 25 | uint8_t CBACK_DRIVER::ReadBytes(uint8_t address, uint8_t subAddress, 26 | uint8_t count, uint8_t* dest) { 27 | Wire.beginTransmission(address); // Initialize the Tx buffer 28 | Wire.write(subAddress); // Put slave register address in Tx buffer 29 | uint8_t i = 0; 30 | if (Wire.endTransmission(false) == 0 && 31 | Wire.requestFrom(address, (uint8_t)count)) { 32 | while (Wire.available()) { 33 | dest[i++] = Wire.read(); 34 | } 35 | return true; 36 | } 37 | return false; 38 | } 39 | 40 | /*******************************************************************************/ 41 | 42 | uint8_t CBACK_DRIVER::SetServoAngle(uint8_t Servo_CH, uint8_t angle) { 43 | uint8_t Register_address = Servo_CH - 1; 44 | if (Register_address > 3) return 0; 45 | Write1Byte(SERVO_ADDRESS, Register_address, angle); 46 | return 0; 47 | } 48 | 49 | uint8_t CBACK_DRIVER::SetServoPulse(uint8_t Servo_CH, 50 | uint16_t width) // 0x10 ->16 51 | { 52 | uint8_t servo_ch = Servo_CH - 1; 53 | uint8_t Register_address = 2 * servo_ch + 16; 54 | if (Register_address % 2 == 1 || Register_address > 32) return 1; 55 | Write2Byte(SERVO_ADDRESS, Register_address, width); 56 | return 0; 57 | } 58 | 59 | uint8_t CBACK_DRIVER::ReadServoAngle(uint8_t Servo_CH) { 60 | uint8_t data = 0; 61 | uint8_t Register_address = Servo_CH - 1; 62 | ReadBytes(SERVO_ADDRESS, Register_address, 1, &data); 63 | return data; 64 | } 65 | 66 | uint16_t CBACK_DRIVER::ReadServoPulse(uint8_t Servo_CH) { 67 | uint8_t data[2]; 68 | uint8_t servo_ch = Servo_CH - 1; 69 | uint8_t Register_address = 2 * servo_ch | 0x10; 70 | ReadBytes(SERVO_ADDRESS, Register_address, 2, data); 71 | return (data[0] << 8) + data[1]; 72 | } 73 | 74 | uint16_t CBACK_DRIVER::ReadADC() { 75 | uint8_t data[2]; 76 | ReadBytes(SERVO_ADDRESS, 0x20, 2, data); 77 | return (data[0] << 8) + data[1]; 78 | } 79 | uint8_t CBACK_DRIVER::SetOutput(uint8_t status) { 80 | Write1Byte(SERVO_ADDRESS, 0x30, status); 81 | return 0; 82 | } 83 | uint8_t CBACK_DRIVER::ReadInput() { 84 | uint8_t data; 85 | ReadBytes(SERVO_ADDRESS, 0x31, 1, &data); 86 | return data; 87 | } 88 | -------------------------------------------------------------------------------- /examples/Hat/BUGC/bugC.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * @Author: Sorzn 3 | * @Date: 2019-11-22 13:38:26 4 | * @LastEditTime: 2019-11-22 14:28:56 5 | * @Description: M5Stack Hat BUGC Lib 6 | * @FilePath: /M5StickC/examples/Hat/BUGC/bugC.cpp 7 | */ 8 | 9 | #include 10 | #include "bugC.h" 11 | 12 | void BUGC::Init() { 13 | Wire.begin(0, 26); 14 | } 15 | 16 | void BUGC::Write1Byte(uint8_t address, uint8_t Register_address, uint8_t data) { 17 | Wire.beginTransmission(address); 18 | Wire.write(Register_address); 19 | Wire.write(data); 20 | Wire.endTransmission(); 21 | } 22 | 23 | void BUGC::Write2Byte(uint8_t address, uint8_t Register_address, 24 | uint16_t data) { 25 | Wire.beginTransmission(address); 26 | Wire.write(Register_address); 27 | Wire.write(data >> 8); // MSB 28 | Wire.write(data & 0xFF); // LSB 29 | 30 | Wire.endTransmission(); 31 | } 32 | 33 | void BUGC::WriteBytes(uint8_t address, uint8_t Register_address, uint8_t *data, 34 | size_t size) { 35 | Wire.beginTransmission(address); 36 | Wire.write(Register_address); 37 | for (int i = 0; i < size; i++) { 38 | Wire.write(*(data + i)); 39 | } 40 | Wire.endTransmission(); 41 | } 42 | 43 | uint8_t BUGC::ReadBytes(uint8_t address, uint8_t subAddress, uint8_t count, 44 | uint8_t *dest) { 45 | Wire.beginTransmission(address); // Initialize the Tx buffer 46 | Wire.write(subAddress); // Put slave register address in Tx buffer 47 | uint8_t i = 0; 48 | if (Wire.endTransmission(false) == 0 && 49 | Wire.requestFrom(address, (uint8_t)count)) { 50 | while (Wire.available()) { 51 | dest[i++] = Wire.read(); 52 | } 53 | return true; 54 | } 55 | return false; 56 | } 57 | 58 | //*******************************************************// 59 | 60 | // if speed > 0; clockwise rotation 61 | void BUGC::BugCSetSpeed(uint8_t pos, int8_t speed) { 62 | speed = (speed > 100) ? 100 : speed; 63 | speed = (speed < -100) ? -100 : speed; 64 | Write1Byte(BUGC_ADDR, pos, speed); 65 | } 66 | 67 | void BUGC::BugCSetAllSpeed(int8_t speed_0, int8_t speed_1, int8_t speed_2, 68 | int8_t speed_3) { 69 | int8_t speed_out[4] = {speed_0, speed_1, speed_2, speed_3}; 70 | for (uint8_t i = 0; i < 4; i++) { 71 | speed_out[i] = (speed_out[i] > 100) ? 100 : speed_out[i]; 72 | speed_out[i] = (speed_out[i] < -100) ? -100 : speed_out[i]; 73 | } 74 | WriteBytes(BUGC_ADDR, 0x00, (uint8_t *)speed_out, 4); 75 | } 76 | 77 | void BUGC::BugCSetColor(uint32_t color_left, uint32_t color_right) { 78 | uint8_t color_out[4]; 79 | color_out[0] = 0; 80 | color_out[1] = (color_left & 0xff0000) >> 16; 81 | color_out[2] = (color_left & 0x00ff00) >> 8; 82 | color_out[3] = (color_left & 0x0000ff); 83 | WriteBytes(BUGC_ADDR, 0x10, color_out, 4); 84 | 85 | color_out[0] = 1; 86 | color_out[1] = (color_right & 0xff0000) >> 16; 87 | color_out[2] = (color_right & 0x00ff00) >> 8; 88 | color_out[3] = (color_right & 0x0000ff); 89 | WriteBytes(BUGC_ADDR, 0x10, color_out, 4); 90 | } 91 | -------------------------------------------------------------------------------- /examples/Advanced/EzData/EzData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: EzData 10 | * Date: 2021/10/23 11 | ******************************************************************************* 12 | */ 13 | #include "M5StickCPlus.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 | M5.Lcd.setRotation(3); 25 | if (setupWifi(ssid, password)) { // Connect to wifi. 连接到wifi 26 | M5.Lcd.printf("Success connecting to %s\n", ssid); 27 | } else { 28 | M5.Lcd.printf("Connecting to %s failed\n", ssid); 29 | } 30 | } 31 | 32 | void loop() { 33 | // Save the data 20 to the top of the testData topic queue. 保存数据20至 34 | // testData 队列首位 35 | if (setData(token, "testData", 20)) { 36 | M5.Lcd.printf("Success sending data to the topic\n"); 37 | } else { 38 | M5.Lcd.print("Fail to save data\n"); 39 | } 40 | delay(5000); 41 | 42 | // Save 3 data in sequence to the first place of testList. 依次保存3个数据至 43 | // testList首位 44 | for (int i = 0; i < 3; i++) { 45 | if (addToList(token, "testList", i)) { 46 | M5.Lcd.printf("Success sending %d to the list\n", i); 47 | } else { 48 | M5.Lcd.print("Fail to save data\n"); 49 | } 50 | delay(100); 51 | } 52 | delay(5000); 53 | 54 | // Get a piece of data from a topic and store the value in result. 从一个 55 | // topic中获取一个数据,并将值存储在 result 56 | int result = 0; 57 | if (getData(token, "testData", result)) { 58 | M5.Lcd.printf("Success get data %d\n", result); 59 | } else { 60 | M5.Lcd.print("Fail to get data\n"); 61 | } 62 | delay(5000); 63 | 64 | // Get a set of data from a list and store the values in the Array array. 65 | // 从一个 list中获取一组数据,并将值存储在 Array数组中 66 | int Array[3] = {}; 67 | if (getData(token, "testList", Array, 0, 3)) { 68 | M5.Lcd.print("Success get list\n"); 69 | for (int i = 0; i < 3; i++) { 70 | M5.Lcd.printf("Array[%d]=%d,", i, Array[i]); 71 | } 72 | M5.Lcd.println(""); 73 | } else { 74 | M5.Lcd.println("Fail to get data"); 75 | } 76 | delay(5000); 77 | 78 | // Remove data 79 | if (removeData(token, "testData")) 80 | M5.Lcd.printf("Success remove data\n"); 81 | else 82 | M5.Lcd.println("Fail to remove data"); 83 | 84 | if (removeData(token, "testList")) 85 | M5.Lcd.printf("Success remove data from the list\n"); 86 | else 87 | M5.Lcd.println("Fail to remove data"); 88 | delay(5000); 89 | M5.Lcd.fillScreen(BLACK); 90 | M5.Lcd.setCursor(0, 0); 91 | } -------------------------------------------------------------------------------- /examples/Basics/AXP192/AXP192.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: APX192. 10 | * Date: 2021/9/14 11 | ******************************************************************************* 12 | */ 13 | #include 14 | #include "AXP192.h" 15 | TFT_eSprite tftSprite = TFT_eSprite(&M5.Lcd); 16 | 17 | /* After M5StickC Plus is started or reset 18 | the program in the setUp () function will be run, and this part will only be 19 | run once. 在 M5StickC Plus 20 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 21 | void setup() { 22 | M5.begin(); // Init M5StickC Plus. 初始化 M5StickC Plus 23 | M5.lcd.setRotation(3); // Rotate the screen. 将屏幕旋转 24 | tftSprite.createSprite( 25 | 240, 135); // Create a 240x135 canvas. 创建一块160x80的画布 26 | tftSprite.setRotation(3); 27 | M5.Axp.EnableCoulombcounter(); // Enable Coulomb counter. 启用库仑计数器 28 | } 29 | 30 | /* After the program in setup() runs, it runs the program in loop() 31 | The loop() function is an infinite loop in which the program runs repeatedly 32 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 33 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 34 | void loop() { 35 | tftSprite.fillSprite(BLACK); // Fill the canvas with black. 36 | // 将画布填充为黑色 37 | tftSprite.setCursor(0, 0, 1); // Set the cursor position and use the 38 | // 1-point font. 设置光标位置并采用1号字体 39 | tftSprite.printf("AXP Temp: %.1fC \r\n", 40 | M5.Axp.GetTempInAXP192()); // Get the temperature of 41 | // AXP192. 获取AXP192的温度 42 | tftSprite.printf("Bat:\r\n V: %.3fv I: %.3fma\r\n", 43 | M5.Axp.GetBatVoltage(), 44 | M5.Axp.GetBatCurrent()); // Output voltage and current of 45 | // Bat. 输出Bat的电压和电流 46 | tftSprite.printf("USB:\r\n V: %.3fv I: %.3fma\r\n", 47 | M5.Axp.GetVBusVoltage(), 48 | M5.Axp.GetVBusCurrent()); // Output current and voltage of 49 | // USB. 输出USB的电流和电压 50 | tftSprite.printf("5V-In:\r\n V: %.3fv I: %.3fma\r\n", 51 | M5.Axp.GetVinVoltage(), M5.Axp.GetVinCurrent()); 52 | tftSprite.printf("Bat power %.3fmw", M5.Axp.GetBatPower()); 53 | tftSprite.pushSprite(40, 20); 54 | 55 | // 0x01 long press(1s), 0x02 press 56 | if (M5.Axp.GetBtnPress() == 0x02) { 57 | esp_restart(); 58 | } 59 | 60 | if (M5.BtnA.wasPressed()) { 61 | // close tft voltage output 62 | M5.Axp.SetLDO2(false); 63 | } else if (M5.BtnB.wasPressed()) { 64 | // close tft voltage output 65 | M5.Axp.SetLDO2(true); 66 | } 67 | M5.update(); // Detect whether the keystroke state has changed. 68 | // 检测按键状态是否发生变化 69 | delay(100); 70 | } 71 | -------------------------------------------------------------------------------- /examples/FactoryTest/fft.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ESP32 FFT 4 | ========= 5 | 6 | This provides a vanilla radix-2 FFT implementation and a test example. 7 | 8 | Author 9 | ------ 10 | 11 | This code was written by [Robin Scheibler](http://www.robinscheibler.org) 12 | during rainy days in October 2017. 13 | 14 | License 15 | ------- 16 | 17 | Copyright (c) 2017 Robin Scheibler 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in all 27 | copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 35 | SOFTWARE. 36 | 37 | */ 38 | #ifndef __FFT_H__ 39 | #define __FFT_H__ 40 | 41 | typedef enum { FFT_REAL, FFT_COMPLEX } fft_type_t; 42 | 43 | typedef enum { FFT_FORWARD, FFT_BACKWARD } fft_direction_t; 44 | 45 | #define FFT_OWN_INPUT_MEM 1 46 | #define FFT_OWN_OUTPUT_MEM 2 47 | 48 | typedef struct { 49 | int size; // FFT size 50 | float *input; // pointer to input buffer 51 | float *output; // pointer to output buffer 52 | float *twiddle_factors; // pointer to buffer holding twiddle factors 53 | fft_type_t type; // real or complex 54 | fft_direction_t direction; // forward or backward 55 | unsigned int flags; // FFT flags 56 | } fft_config_t; 57 | 58 | fft_config_t *fft_init(int size, fft_type_t type, fft_direction_t direction, 59 | float *input, float *output); 60 | void fft_destroy(fft_config_t *config); 61 | void fft_execute(fft_config_t *config); 62 | void fft(float *input, float *output, float *twiddle_factors, int n); 63 | void ifft(float *input, float *output, float *twiddle_factors, int n); 64 | void rfft(float *x, float *y, float *twiddle_factors, int n); 65 | void irfft(float *x, float *y, float *twiddle_factors, int n); 66 | void fft_primitive(float *x, float *y, int n, int stride, 67 | float *twiddle_factors, int tw_stride); 68 | void split_radix_fft(float *x, float *y, int n, int stride, 69 | float *twiddle_factors, int tw_stride); 70 | void ifft_primitive(float *input, float *output, int n, int stride, 71 | float *twiddle_factors, int tw_stride); 72 | void fft8(float *input, int stride_in, float *output, int stride_out); 73 | void fft4(float *input, int stride_in, float *output, int stride_out); 74 | 75 | #endif // __FFT_H__ 76 | -------------------------------------------------------------------------------- /examples/Unit/PDM_SPM1423/fft.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | ESP32 FFT 4 | ========= 5 | 6 | This provides a vanilla radix-2 FFT implementation and a test example. 7 | 8 | Author 9 | ------ 10 | 11 | This code was written by [Robin Scheibler](http://www.robinscheibler.org) 12 | during rainy days in October 2017. 13 | 14 | License 15 | ------- 16 | 17 | Copyright (c) 2017 Robin Scheibler 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in all 27 | copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 35 | SOFTWARE. 36 | 37 | */ 38 | #ifndef __FFT_H__ 39 | #define __FFT_H__ 40 | 41 | typedef enum { FFT_REAL, FFT_COMPLEX } fft_type_t; 42 | 43 | typedef enum { FFT_FORWARD, FFT_BACKWARD } fft_direction_t; 44 | 45 | #define FFT_OWN_INPUT_MEM 1 46 | #define FFT_OWN_OUTPUT_MEM 2 47 | 48 | typedef struct { 49 | int size; // FFT size 50 | float *input; // pointer to input buffer 51 | float *output; // pointer to output buffer 52 | float *twiddle_factors; // pointer to buffer holding twiddle factors 53 | fft_type_t type; // real or complex 54 | fft_direction_t direction; // forward or backward 55 | unsigned int flags; // FFT flags 56 | } fft_config_t; 57 | 58 | fft_config_t *fft_init(int size, fft_type_t type, fft_direction_t direction, 59 | float *input, float *output); 60 | void fft_destroy(fft_config_t *config); 61 | void fft_execute(fft_config_t *config); 62 | void fft(float *input, float *output, float *twiddle_factors, int n); 63 | void ifft(float *input, float *output, float *twiddle_factors, int n); 64 | void rfft(float *x, float *y, float *twiddle_factors, int n); 65 | void irfft(float *x, float *y, float *twiddle_factors, int n); 66 | void fft_primitive(float *x, float *y, int n, int stride, 67 | float *twiddle_factors, int tw_stride); 68 | void split_radix_fft(float *x, float *y, int n, int stride, 69 | float *twiddle_factors, int tw_stride); 70 | void ifft_primitive(float *input, float *output, int n, int stride, 71 | float *twiddle_factors, int tw_stride); 72 | void fft8(float *input, int stride_in, float *output, int stride_out); 73 | void fft4(float *input, int stride_in, float *output, int stride_out); 74 | 75 | #endif // __FFT_H__ 76 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/SPIFFS/SPIFFS_Add/SPIFFS_Add.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: SPIFFS Add(Write is to clean up the contents of the file and write 10 | *it again.). 向SPIFFS中添加信息(write是将文件内容完全清除重新写) Date: 2021/9/18 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 | bool SPIFFS_FORMAT = 21 | true; // Whether to initialize the SPIFFS. 是否初始化SPIFFS 22 | // You don't need to format the flash file system every time you use it. 23 | //无需每次使用闪存都进行格式化 24 | 25 | void setup() { 26 | M5.begin(); 27 | M5.Lcd.setRotation(3); // Rotate the screen. 旋转屏幕 28 | if (SPIFFS_FORMAT) { 29 | M5.Lcd.println( 30 | "\nSPIFFS format start..."); // Screen prints format String. 31 | // 屏幕打印格式化字符串 32 | SPIFFS.format(); // Formatting SPIFFS. 格式化SPIFFS 33 | M5.Lcd.println("SPIFFS format finish"); 34 | } 35 | if (SPIFFS.begin()) { // Start SPIFFS, return 1 on success. 36 | // 启动闪存文件系统,若成功返回1 37 | M5.Lcd.println("\nSPIFFS Started."); 38 | } else { 39 | M5.Lcd.println("SPIFFS Failed to Start."); 40 | } 41 | 42 | if (SPIFFS.exists( 43 | file_name)) { // Check whether the file_name file exists in the 44 | // flash memory. 确认闪存中是否有file_name文件 45 | M5.Lcd.println("FOUND."); 46 | M5.Lcd.println(file_name); 47 | 48 | File dataFile = SPIFFS.open( 49 | file_name, 50 | "a"); // Create a File object dafaFile to add information to 51 | // file_name in the SPIFFS. 52 | // 建立File对象dafaFile用于向SPIFFS中的file_name添加信息 53 | dataFile.println( 54 | "This is Appended Info."); // Adds string information to dataFile. 55 | // 向dataFile添加字符串信息 56 | dataFile.close(); // Close the file when writing is complete. 57 | // 完成写入后关闭文件 58 | M5.Lcd.println("Finished Appending data to SPIFFS"); 59 | } else { 60 | M5.Lcd.println("NOT FOUND."); 61 | M5.Lcd.print(file_name); 62 | M5.Lcd.println("is creating."); 63 | File dataFile = SPIFFS.open( 64 | file_name, 65 | "w"); // Create aFile object dafaFile to write information to 66 | // file_name in the SPIFFS. 67 | // 建立File对象dafaFile用于向SPIFFS中的file_name写入信息 68 | dataFile.close(); // Close the file when writing is complete. 69 | // 完成写入后关闭文件 70 | M5.Lcd.println("Please disable format and Reupload"); 71 | } 72 | } 73 | 74 | void loop() { 75 | } -------------------------------------------------------------------------------- /examples/Advanced/HallSensor/HallSensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with M5StickC-Plus sample source code 5 | * 配套 M5StickC-Plus 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus 8 | * 9 | * Describe: Hall sensor. 霍尔传感器 10 | * Date: 2021/9/18 11 | ******************************************************************************* 12 | The ESP32 MCU has build in Hall sensor. ESP32 MCU内置霍尔传感器 13 | It is not very suscescible but if you bring a magnet close to the 14 | upper screen you will see the influence on the measurement. 15 | In this example we use some low pass filters to get rid of the noise. 16 | */ 17 | #include 18 | 19 | #define HORIZONTAL_RESOLUTION 135 //屏幕水平分辨率 20 | #define VERTICAL_RESOLUTION 240 //屏幕竖直分辨率 21 | #define POSITION_OFFSET_Y 20 22 | 23 | uint16_t oldSignal[HORIZONTAL_RESOLUTION]; 24 | 25 | float ESP32_hallRead() // ESP32 hall value read. ESP32霍尔值读取 26 | { 27 | float value = 0; 28 | int count = 400; 29 | // mean value filter. 数据低通滤波器 30 | for (int n = 0; n < count; n++) value += hallRead(); 31 | return value / count * 10; 32 | } 33 | 34 | float HallOffset = 35 | 0; ////Store the initial value of magnetic force. 存储磁力的初值 36 | 37 | void setup() { 38 | M5.begin(); 39 | M5.Lcd.printf("\nESP32 Hall sensor:"); // Screen printout. 屏幕打印输出 40 | HallOffset = 41 | ESP32_hallRead(); // callibrate the output value to the magnetic field 42 | // at start up. 在启动时将输出值校准到磁场 43 | } 44 | 45 | float LowPassFilteredValue = 0; 46 | void showSignal() { 47 | int n; 48 | 49 | int oldx; 50 | int oldy; 51 | int oldSig; 52 | int x, y; 53 | 54 | for (n = 0; n < HORIZONTAL_RESOLUTION; 55 | n++) //在水平分辨率内,每个像素点根据计算得到的磁力大小绘制 56 | { // Within the horizontal resolution, each pixel is drawn according to the 57 | // calculated magnetic force 58 | x = n; 59 | float value = 60 | ESP32_hallRead() - HallOffset; // Reduce the influence of own 61 | // magnetism. 减少自身磁力的影响 62 | LowPassFilteredValue += (value - LowPassFilteredValue) * 0.05; 63 | M5.Lcd.setCursor(50, 30); 64 | M5.Lcd.print((int)LowPassFilteredValue); 65 | M5.Lcd.print(" "); 66 | M5.Lcd.setCursor(0, 40); 67 | y = map( 68 | value, -127, 127, VERTICAL_RESOLUTION, 69 | POSITION_OFFSET_Y); //将value映射至-30~30的范围内,以免绘制超出屏幕 70 | 71 | if (n > 0) { 72 | // delete old line element. 删除上次画的线 73 | M5.Lcd.drawLine(oldx, oldSig, x, oldSignal[n], BLACK); 74 | 75 | // draw new line element. 画新的线 76 | if (n < HORIZONTAL_RESOLUTION - 77 | 1) // don't draw last element because it would generate 78 | // artifacts. 不能绘制最后一个像素 79 | { 80 | M5.Lcd.drawLine(oldx, oldy, x, y, GREEN); 81 | } 82 | } 83 | oldx = x; 84 | oldy = y; 85 | oldSig = oldSignal[n]; 86 | oldSignal[n] = y; 87 | } 88 | } 89 | 90 | void loop(void) { 91 | showSignal(); 92 | } 93 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🚫 Deprecated — Use M5GFX & M5Unified 2 | 3 | - **M5GFX** 4 | High-performance, lightweight graphics and display driver library for M5 devices. 5 | 6 | 7 | - **M5Unified** 8 | Unified base library for M5 devices (IO/peripherals, power management, audio, etc.). 9 | 10 | 11 | 12 | # M5StickC-Plus Library 13 | 14 | [![Arduino Compile](https://github.com/m5stack/M5StickC-Plus/actions/workflows/arduino-action-compile.yml/badge.svg)](https://github.com/m5stack/M5StickC-Plus/actions/workflows/arduino-action-compile.yml) 15 | [![Arduino Lint](https://github.com/m5stack/M5StickC-Plus/actions/workflows/Arduino-Lint-Check.yml/badge.svg)](https://github.com/m5stack/M5StickC-Plus/actions/workflows/Arduino-Lint-Check.yml) 16 | [![Clang Format](https://github.com/m5stack/M5StickC-Plus/actions/workflows/clang-format-check.yml/badge.svg)](https://github.com/m5stack/M5StickC-Plus/actions/workflows/clang-format-check.yml) 17 | 18 | English | [中文](README_cn.md) 19 | 20 | M5StickC_01 21 | 22 | * **For the Detailed documentation of M5StickC Plus, please [Click here](https://docs.m5stack.com/#/en/core/m5stickc_plus)** 23 | 24 | * **In order to buy M5StickC Plus,please [Click here](https://shop.m5stack.com/collections/m5-controllers/products/m5stickc-plus-esp32-pico-mini-iot-development-kit)** 25 | 26 | ## Description 27 | 28 | **M5StickC PLUS** is powered by **ESP32-PICO-D4** with **Bluetooth 4.2** and **WiFi**.It's an upgrade big screen product of M5StickC.It is a portable, easy-to-use, open source, IoT development board. What it can do? This tiny block is able to realize your idea, enlighten your creativity, and help with your IoT prototying in a very short time. It will take away a lot of pains from the development process. M5stickC Plus is one of the core devices in M5Stack product series. The compact body is integrated with rich hardware resources, such as infrared, **RTC**, **Microphone**, **LED**, **IMU**, **Buttons**, **PMU**,etc. Compared with StickC, a buzzer is added and the big screen is upgraded to a 1.14-inch, **135 * 240** resolution LCD Screen.Compared with the previous display area, the display area is increased by 18.7%, and the battery capacity is **120mAh**.It also supports HAT and Unit family products. 29 | 30 | **Power switch operation:** 31 | 32 | * Power on :Long press power button for 2 seconds 33 | 34 | * Power off :Long press power button for 6 seconds 35 | 36 | **Notice:** 37 | 38 | * Baud rate supported by M5StickC Plus: 1200 ~115200, 250K, 500K, 750K, 1500K 39 | 40 | * G36/G25 share the same port, when one of the pins is used, the other pin should be set as a floating input 41 | * For example, to use the G36 pin as the ADC input, Configuration the G25 pin as FLOATING 42 | 43 | ## More Information 44 | 45 | **UIFlow Quick Start**: [Click Here](https://docs.m5stack.com/en/quick_start/m5stickc_plus/uiflow) 46 | 47 | **MicroPython API**: [Click Here](https://docs.m5stack.com/en/mpy/display/m5stack_lvgl) 48 | 49 | **Arduino IDE Development**: [Click Here](https://docs.m5stack.com/en/quick_start/m5stickc_plus/arduino) 50 | 51 | **M5StickC Arduino API**: [Click Here](https://docs.m5stack.com/en/api/stickc/system_m5stickc) 52 | 53 | **PinMap**: [Click Here](https://docs.m5stack.com/en/core/m5stickc_plus) 54 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | # Source: 2 | # https://github.com/Tinyu-Zhao/M5-Depends/blob/main/.github/ISSUE_TEMPLATE/bug-report.yml 3 | # See: 4 | # https://docs.github.com/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms 5 | 6 | name: Bug report 7 | description: Report a problem with the code in this repository. 8 | labels: 9 | - "type: bug" 10 | body: 11 | - type: markdown 12 | attributes: 13 | value: "Thank you for opening an issue on an M5Stack Arduino library repository.\n\ 14 | To improve the speed of resolution please review the following guidelines and common troubleshooting steps below before creating the issue:\n\ 15 | Do not use GitHub issues for troubleshooting projects and issues. Instead use the forums at https://community.m5stack.com to ask questions and troubleshoot why something isn't working as expected. In many cases the problem is a common issue that you will more quickly receive help from the forum community. GitHub issues are meant for known defects in the code. If you don't know if there is a defect in the code then start with troubleshooting on the forum first." 16 | - type: textarea 17 | id: description 18 | attributes: 19 | label: Describe the bug 20 | description: A clear and concise description of what the bug is. 21 | validations: 22 | required: true 23 | - type: textarea 24 | id: reproduce 25 | attributes: 26 | label: To reproduce 27 | description: Provide the specific set of steps we can follow to reproduce the problem. 28 | placeholder: | 29 | 1. In this environment... 30 | 2. With this config... 31 | 3. Run '...' 32 | 4. See error... 33 | validations: 34 | required: true 35 | - type: textarea 36 | id: expected 37 | attributes: 38 | label: Expected behavior 39 | description: What would you expect to happen after following those instructions? 40 | validations: 41 | required: true 42 | - type: textarea 43 | id: screenshots 44 | attributes: 45 | label: Screenshots 46 | description: If applicable, add screenshots to help explain your problem. 47 | validations: 48 | required: false 49 | - type: textarea 50 | id: information 51 | attributes: 52 | label: Environment 53 | description: | 54 | If applicable, add screenshots to help explain your problem. 55 | examples: 56 | - **OS**: Ubuntu 20.04 57 | - **IDE & IDE Version**: Arduino 1.8.19 Or Platform IO v2.5.0 58 | - **Repository Version**: 0.4.0 59 | value: | 60 | - OS: 61 | - IDE &IDE Version: 62 | - Repository Version: 63 | validations: 64 | required: false 65 | - type: textarea 66 | id: additional 67 | attributes: 68 | label: Additional context 69 | description: Add any additional information here. 70 | validations: 71 | required: false 72 | - type: checkboxes 73 | id: checklist 74 | attributes: 75 | label: Issue checklist 76 | description: Please double-check that you have done each of the following things before submitting the issue. 77 | options: 78 | - label: I searched for previous reports in [the issue tracker](https://github.com/m5stack/M5StickC-Plus/issues?q=) 79 | required: true 80 | - label: My report contains all necessary details 81 | required: true 82 | -------------------------------------------------------------------------------- /examples/Unit/IMU_MPU6886/IMU_6886.h: -------------------------------------------------------------------------------- 1 | /* 2 | Note: The IMU_6886 is an I2C sensor and uses the Arduino Wire library. 3 | Because the sensor is not 5V tolerant, we are using a 3.3 V 8 MHz Pro Mini or 4 | a 3.3 V Teensy 3.1. We have disabled the internal pull-ups used by the Wire 5 | library in the Wire.h/twi.c utility file. We are also using the 400 kHz fast 6 | I2C mode by setting the TWI_FREQ to 400000L /twi.h utility file. 7 | */ 8 | #ifndef __IMU_6886_H__ 9 | #define __IMU_6886_H__ 10 | 11 | #include 12 | #include 13 | 14 | #define IMU_6886_ADDRESS 0x68 15 | #define IMU_6886_WHOAMI 0x75 16 | #define IMU_6886_ACCEL_INTEL_CTRL 0x69 17 | #define IMU_6886_SMPLRT_DIV 0x19 18 | #define IMU_6886_INT_PIN_CFG 0x37 19 | #define IMU_6886_INT_ENABLE 0x38 20 | #define IMU_6886_ACCEL_XOUT_H 0x3B 21 | #define IMU_6886_ACCEL_XOUT_L 0x3C 22 | #define IMU_6886_ACCEL_YOUT_H 0x3D 23 | #define IMU_6886_ACCEL_YOUT_L 0x3E 24 | #define IMU_6886_ACCEL_ZOUT_H 0x3F 25 | #define IMU_6886_ACCEL_ZOUT_L 0x40 26 | 27 | #define IMU_6886_TEMP_OUT_H 0x41 28 | #define IMU_6886_TEMP_OUT_L 0x42 29 | 30 | #define IMU_6886_GYRO_XOUT_H 0x43 31 | #define IMU_6886_GYRO_XOUT_L 0x44 32 | #define IMU_6886_GYRO_YOUT_H 0x45 33 | #define IMU_6886_GYRO_YOUT_L 0x46 34 | #define IMU_6886_GYRO_ZOUT_H 0x47 35 | #define IMU_6886_GYRO_ZOUT_L 0x48 36 | 37 | #define IMU_6886_USER_CTRL 0x6A 38 | #define IMU_6886_PWR_MGMT_1 0x6B 39 | #define IMU_6886_PWR_MGMT_2 0x6C 40 | #define IMU_6886_CONFIG 0x1A 41 | #define IMU_6886_GYRO_CONFIG 0x1B 42 | #define IMU_6886_ACCEL_CONFIG 0x1C 43 | #define IMU_6886_ACCEL_CONFIG2 0x1D 44 | #define IMU_6886_FIFO_EN 0x23 45 | 46 | #define IMU_6886_FIFO_ENABLE 0x23 47 | #define IMU_6886_FIFO_COUNT 0x72 48 | #define IMU_6886_FIFO_R_W 0x74 49 | #define IMU_6886_GYRO_OFFSET 0x13 50 | //#define G (9.8) 51 | #define RtA 57.324841 52 | #define AtR 0.0174533 53 | #define Gyro_Gr 0.0010653 54 | 55 | class IMU_6886 { 56 | public: 57 | enum Ascale { AFS_2G = 0, AFS_4G, AFS_8G, AFS_16G }; 58 | 59 | enum Gscale { GFS_250DPS = 0, GFS_500DPS, GFS_1000DPS, GFS_2000DPS }; 60 | 61 | public: 62 | IMU_6886(); 63 | int Init(uint8_t sda, uint8_t scl); 64 | void getAccelAdc(int16_t* ax, int16_t* ay, int16_t* az); 65 | void getGyroAdc(int16_t* gx, int16_t* gy, int16_t* gz); 66 | void getTempAdc(int16_t* t); 67 | 68 | void getAccelData(float* ax, float* ay, float* az); 69 | void getGyroData(float* gx, float* gy, float* gz); 70 | void getTempData(float* t); 71 | 72 | void setGyroFsr(Gscale scale); 73 | void setAccelFsr(Ascale scale); 74 | 75 | void getAhrsData(float* pitch, float* roll, float* yaw); 76 | void setFIFOEnable(bool enableflag); 77 | uint8_t ReadFIFO(); 78 | void ReadFIFOBuff(uint8_t* DataBuff, uint16_t Length); 79 | uint16_t ReadFIFOCount(); 80 | void RestFIFO(); 81 | void setGyroOffset(uint16_t x, uint16_t y, uint16_t z); 82 | 83 | public: 84 | float aRes, gRes, imuId; 85 | Gscale Gyscale; 86 | Ascale Acscale; 87 | 88 | private: 89 | private: 90 | void I2C_Read_NBytes(uint8_t driver_Addr, uint8_t start_Addr, 91 | uint8_t number_Bytes, uint8_t* read_Buffer); 92 | void I2C_Write_NBytes(uint8_t driver_Addr, uint8_t start_Addr, 93 | uint8_t number_Bytes, uint8_t* write_Buffer); 94 | void updateGres(); 95 | void updateAres(); 96 | }; 97 | #endif 98 | --------------------------------------------------------------------------------