├── .gitignore ├── .vscode └── settings.json ├── library.properties ├── examples ├── Unit │ ├── CAN │ │ ├── ESP32CAN.h │ │ ├── ESP32CAN.cpp │ │ ├── CAN_config.h │ │ ├── CAN.ino │ │ └── CAN.h │ ├── LIMIT │ │ └── LIMIT.ino │ ├── Relay │ │ └── Relay.ino │ ├── OP90.180_ITR9606 │ │ └── OP90.180_ITR9606.ino │ ├── EARTH │ │ └── EARTH.ino │ ├── PIR │ │ └── PIR.ino │ ├── GPS │ │ └── GPSRaw │ │ │ └── GPSRaw.ino │ ├── ISO485 │ │ └── ISO485.ino │ ├── HALL │ │ └── HALL.ino │ ├── LIGHT │ │ └── LIGHT.ino │ ├── BUTTON │ │ └── BUTTON.ino │ ├── FAN │ │ └── FAN.ino │ ├── CardKB │ │ └── CardKB.ino │ ├── VIBRATOR │ │ └── VIBRATOR.ino │ ├── JOYSTICK │ │ └── JOYSTICK.ino │ ├── BPS_QMP6988 │ │ └── BPS_QMP6988.ino │ ├── RS485_SP485EEN │ │ └── RS485_SP485EEN.ino │ ├── RFID_RC522 │ │ └── RFID_RC522.ino │ ├── BPS_BMP280 │ │ └── BPS_BMP280.ino │ ├── ANGLE │ │ └── ANGLE.ino │ ├── NCIR_MLX90614 │ │ └── NCIR_MLX90614.ino │ ├── ULTRA_SONIC │ │ └── ULTRA_SONIC.ino │ ├── IR │ │ └── IR.ino │ ├── RGB_SK6812 │ │ └── RGB_SK6812.ino │ ├── TVOC_SGP30 │ │ └── TVOC_SGP30.ino │ ├── FINGER_FPC1020A │ │ └── FINGER_FPC1020A.ino │ ├── FADER │ │ └── FADER.ino │ ├── HEX_SK6812 │ │ └── HEX_SK6812.ino │ ├── ENVIII_SHT30_QMP6988 │ │ └── ENVIII_SHT30_QMP6988.ino │ ├── THERMAL_MLX90640 │ │ ├── MLX90640_I2C_Driver.h │ │ ├── MLX90640_API.h │ │ ├── MLX90640_I2C_Driver.cpp │ │ └── interpolation.cpp │ ├── ENV_DHT12_BMP280 │ │ └── ENV_DHT12_BMP280.ino │ ├── DAC_MCP4725 │ │ └── DAC_MCP4725.ino │ ├── PaHUB │ │ └── PaHUB.ino │ ├── Dual_Button │ │ └── Dual_Button.ino │ ├── EXT_IO │ │ └── EXT_IO.ino │ ├── ENVII_SHT30_BMP280 │ │ └── ENVII_SHT30_BMP280.ino │ ├── RTC_BM8563 │ │ └── RTC_BM8563.ino │ ├── TRACE │ │ └── TRACE.ino │ ├── HEART_MAX30100 │ │ └── MAX30100_RawData.ino │ ├── LCD_ST7789V2 │ │ └── LCD_ST7789V2.ino │ ├── WEIGHT_HX711 │ │ └── WEIGHT_HX711.ino │ ├── OLED_SH1107 │ │ └── OLED_SH1107.ino │ ├── KEY │ │ └── KEY.ino │ ├── ADC_ADS1100 │ │ └── ADC_ADS1100.ino │ ├── 4-RELAY │ │ └── 4-RELAY.ino │ ├── COLOR_TCS3472 │ │ └── COLOR_TCS3472.ino │ ├── AMeter_ADS1115 │ │ └── AMeter_ADS1115.ino │ ├── VMeter_ADS1115 │ │ └── VMeter_ADS1115.ino │ ├── TOF_VL53L0X │ │ └── TOF_VL53L0X.ino │ ├── LoRaWAN470 │ │ └── LoRaWAN470.ino │ ├── LoRaWAN868 │ │ └── LoRaWAN868.ino │ ├── UHF_RFID_JRD4035 │ │ └── UHF_RFID_JRD4035.ino │ └── PDM_SPM1423 │ │ └── PDM_SPM1423.ino ├── Advanced │ ├── WIFI │ │ ├── WiFiSetting │ │ │ └── detail │ │ │ │ ├── RequestHandler.h │ │ │ │ └── RequestHandlersImpl.h │ │ ├── WiFiScan │ │ │ └── WiFiScan.ino │ │ ├── WiFiMulti │ │ │ └── WiFiMulti.ino │ │ ├── BasicHttpClient │ │ │ └── BasicHttpClient.ino │ │ ├── OTAUpload │ │ │ └── OTAUpload.ino │ │ ├── WiFiSmartConfig │ │ │ └── WiFiSmartConfig.ino │ │ ├── mDNS_Find │ │ │ └── mDNS_Find.ino │ │ ├── WiFiTCP │ │ │ └── WiFiTCP.ino │ │ └── WiFiAccessPoint │ │ │ └── WiFiAccessPoint.ino │ ├── MultSerial │ │ └── MultSerial.ino │ ├── Storage │ │ ├── SPIFFS │ │ │ ├── SPIFFS_Delete │ │ │ │ └── SPIFFS_Delete.ino │ │ │ ├── SPIFFS_Add │ │ │ │ └── SPIFFS_Add.ino │ │ │ └── SPIFFS │ │ │ │ └── SPIFFS.ino │ │ ├── Counter │ │ │ └── Counter.ino │ │ └── EEPROM │ │ │ └── EEPROM.ino │ ├── I2C_Tester │ │ └── I2C_Tester.ino │ ├── EzData │ │ └── EzData.ino │ ├── HallSensor │ │ └── HallSensor.ino │ ├── Time │ │ └── Time.ino │ └── MultiTask │ │ └── MultiTask.ino ├── Audio │ └── STT │ │ ├── BaiduRest.h │ │ └── STT.ino └── Basics │ ├── LEDSet │ └── LEDSet.ino │ └── Button │ └── Button.ino ├── library.json ├── LICENSE ├── README_cn.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "initializer_list": "cpp", 4 | "list": "cpp", 5 | "vector": "cpp", 6 | "xhash": "cpp", 7 | "xstring": "cpp", 8 | "xutility": "cpp" 9 | } 10 | } -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=M5AtomU 2 | version=0.0.2 3 | author=M5Stack 4 | maintainer=M5Stack 5 | sentence=Library for M5AtomU Core development kit 6 | paragraph=See more on http://M5Stack.com 7 | category=Device Control 8 | url=https://github.com/m5stack/M5AtomU 9 | architectures=esp32 10 | depends=M5Family 11 | -------------------------------------------------------------------------------- /examples/Unit/CAN/ESP32CAN.h: -------------------------------------------------------------------------------- 1 | #ifndef ESP32CAN_H 2 | #define ESP32CAN_H 3 | 4 | #include "CAN_config.h" 5 | #include "CAN.h" 6 | 7 | class ESP32CAN { 8 | public: 9 | int CANInit(); 10 | int CANConfigFilter(const CAN_filter_t* p_filter); 11 | int CANWriteFrame(const CAN_frame_t* p_frame); 12 | int CANStop(); 13 | }; 14 | 15 | extern ESP32CAN ESP32Can; 16 | #endif 17 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "M5AtomU", 3 | "description": "An ESP32 Arduino board", 4 | "keywords": "M5AtomU", 5 | "authors": { 6 | "name": "M5Stack", 7 | "url": "http://www.m5stack.com" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/m5stack/M5AtomU.git" 12 | }, 13 | "version": "0.0.2", 14 | "frameworks": "arduino", 15 | "platforms": "espressif32" 16 | } 17 | -------------------------------------------------------------------------------- /examples/Unit/CAN/ESP32CAN.cpp: -------------------------------------------------------------------------------- 1 | #include "ESP32CAN.h" 2 | 3 | int ESP32CAN::CANInit() { 4 | return CAN_init(); 5 | } 6 | int ESP32CAN::CANWriteFrame(const CAN_frame_t* p_frame) { 7 | return CAN_write_frame(p_frame); 8 | } 9 | int ESP32CAN::CANStop() { 10 | return CAN_stop(); 11 | } 12 | int ESP32CAN::CANConfigFilter(const CAN_filter_t* p_filter) { 13 | return CAN_config_filter(p_filter); 14 | } 15 | 16 | ESP32CAN ESP32Can; 17 | -------------------------------------------------------------------------------- /examples/Unit/LIMIT/LIMIT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2022 by M5Stack 4 | * Equipped with M5Stack ATOM sample source code 5 | * 配套 M5Stack ATOM 示例源代码 6 | * Visit the website for more information: 7 | * 获取更多资料请访问: 8 | * 9 | * describe: Limit. 10 | * date: 2022/6/1 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | 16 | #define KEY_PIN 32 // Define Limit Pin. 定义Limit连接引脚 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Stack 初始化M5Stack 20 | 21 | pinMode(KEY_PIN, INPUT_PULLUP); // Init Limit pin. 初始化Limit引脚. 22 | } 23 | 24 | void loop() { 25 | if (!digitalRead(KEY_PIN)) { // If Limit was hit. 如果触碰了Limit. 26 | Serial.println("Hit limit!"); 27 | } 28 | delay(100); 29 | } 30 | -------------------------------------------------------------------------------- /examples/Unit/Relay/Relay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Relay. 继电器 10 | * date:2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port ,Use RELAY to switch on and off the circuit. 13 | 请连接端口,使用继电器开关电路。 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Atom. 初始化 M5Atom 20 | Serial.println(("Relay Example")); 21 | dacWrite(25, 0); // disable the speak noise 22 | pinMode(26, OUTPUT); 23 | } 24 | 25 | void loop(void) { 26 | Serial.println("ON"); 27 | digitalWrite(26, HIGH); 28 | delay(1000); 29 | Serial.println("OFF"); 30 | digitalWrite(26, LOW); 31 | delay(1000); 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 M5Stack 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /examples/Unit/OP90.180_ITR9606/OP90.180_ITR9606.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:OP 180/90. 非接触式光电限位开关 10 | * date:2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port ,Detect the current OP 90/180 Unit Photoelectric switch 13 | status. 请连接端口,检测当前OP 90/180单元光电开关状态。 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Atom. 初始化M5Atom 20 | Serial.println("90/180 OPTICAL"); 21 | pinMode(32, INPUT_PULLUP); // Set pin 32 to input pull-up mode. 22 | // 设置32号引脚为输入上拉模式 23 | } 24 | 25 | void loop() { 26 | Serial.printf( 27 | "IR Receive: %d\n", 28 | digitalRead(32)); // Output the value of pin 32. 输出32号引脚的值 29 | } 30 | -------------------------------------------------------------------------------- /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/EARTH/EARTH.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:EARTH. 土壤湿度 10 | * date:2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port ,Read the analog quantity and digital quantity returned 13 | by the EARTH unit, and convert the analog quantity into 12-bit data and display 14 | it on the Serial. 请连接端口,读取EARTH Unit 15 | 返回的模拟量和数字量,并将模拟量转换为12位数据显示在串口上。 16 | */ 17 | 18 | #include 19 | 20 | void setup() { 21 | M5.begin(); // Init M5Atom. 初始化 M5Atom 22 | Serial.printf("UNIT_EARTH EXAMPLE\n"); 23 | pinMode(26, INPUT); // Set pin 26 to input mode. 将引脚26设置为输入模式 24 | } 25 | 26 | void loop() { 27 | Serial.printf("AnalogRead:%d\n", analogRead(32)); 28 | Serial.printf("DigitalRead:%d\n", digitalRead(26)); 29 | delay(1000); 30 | } 31 | -------------------------------------------------------------------------------- /examples/Unit/PIR/PIR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:PIR. 人体红外 10 | * date:2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port ,Human body detection using PIR Unit. 13 | 请连接端口,使用PIR Unit进行人体检测。 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Atom. 初始化 M5Atom 20 | Serial.println("PIR example"); 21 | pinMode(32, INPUT); // Set pin 36 to input mode. 设置36号引脚为输入模式 22 | } 23 | 24 | void loop() { 25 | if (digitalRead(32) == 26 | 1) { // If pin 32 reads a value of 1. 如果32号引脚的读取到的值为1 27 | Serial.println("Status: Sensing"); 28 | Serial.println("Value: 1\n"); 29 | } else { 30 | Serial.println("Status: Not Sensed"); 31 | Serial.println("Value: 0\n"); 32 | } 33 | delay(500); 34 | } -------------------------------------------------------------------------------- /examples/Unit/GPS/GPSRaw/GPSRaw.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/gps 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/gps 8 | * 9 | * describe:GPS. 10 | * date:2021/8/26 11 | ******************************************************************************* 12 | /* 13 | Description: The command data of the USB UART is forwarded to the GPS Unit 14 | for debugging and functional verification. 将USB UART的命令数据转发给GPS 15 | Unit进行调试和功能验证。 16 | */ 17 | #include 18 | 19 | HardwareSerial GPSRaw(2); 20 | 21 | void setup() { 22 | M5.begin(); 23 | 24 | Serial.printf("\n\nGPS Unit\n\n"); 25 | GPSRaw.begin(9600, SERIAL_8N1, 32, 26); 26 | 27 | Serial.println("hello"); 28 | } 29 | 30 | void loop() { 31 | if (Serial.available()) { 32 | int ch = Serial.read(); 33 | GPSRaw.write(ch); 34 | } 35 | 36 | if (GPSRaw.available()) { 37 | int ch = GPSRaw.read(); 38 | Serial.write(ch); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/Unit/ISO485/ISO485.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | information:https://docs.m5stack.com/en/unit/iso485 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/iso485 9 | * 10 | * describe: iso485. 11 | * date:2021/8/30 12 | ******************************************************************************* 13 | Please connect to Port ,Pressed ButtonA :send "hello world" 14 | 请连接端口 ,Pressed ButtonA :send "hello world" 15 | */ 16 | 17 | #include 18 | 19 | String str = ""; 20 | 21 | void setup() { 22 | M5.begin(); 23 | Serial.println("ISO485"); 24 | Serial2.begin(115200, SERIAL_8N1, 26, 32); 25 | } 26 | 27 | void loop() { 28 | if (M5.Btn.wasPressed()) { 29 | Serial2.write("HELLO World\r\n"); 30 | } 31 | 32 | if (Serial2.available()) { 33 | char ch = Serial2.read(); 34 | str += ch; 35 | if (str.endsWith("\r\n")) { 36 | Serial.print(str); 37 | str = ""; 38 | } 39 | } 40 | M5.update(); 41 | } 42 | -------------------------------------------------------------------------------- /examples/Advanced/MultSerial/MultSerial.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:MultSerial. 多串口 10 | * date:2021/8/5 11 | ****************************************************************************** 12 | */ 13 | #include 14 | 15 | void setup() { 16 | M5.begin(); // Init M5Atom. 初始化 M5Atom 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/Unit/HALL/HALL.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: Hall. 霍尔传感器 10 | * date:2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port ,Displays a string on the Serial. 13 | 请连接端口,在串口上显示字符串。 14 | Low-level signal can be generated when the magnet S pole is close to the front 15 | of the sensor 当磁体S极靠近传感器前端时,会产生低电平信号 OR the N pole is close 16 | to the back, and the internal LED indicator will light up, the Serial wiil 17 | display 0. 或N极靠近背面,内部LED指示灯亮起,串口显示0。 18 | */ 19 | 20 | #include 21 | 22 | #define HALL 32 23 | 24 | void setup() { 25 | M5.begin(); // Init M5Atom. 初始化M5Atom 26 | Serial.print("\n\nHALL Sensor"); 27 | pinMode(HALL, 28 | INPUT); // Set the pins to which the Hall sensor is connected to 29 | // the input mode. 将霍尔传感器所连接的引脚设置为输入模式 30 | } 31 | 32 | void loop() { 33 | bool status = digitalRead(HALL); 34 | Serial.printf("Hall status : %d\n", status); 35 | delay(200); 36 | } 37 | -------------------------------------------------------------------------------- /examples/Unit/LIGHT/LIGHT.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: Light. 环境光传感器 10 | * date:2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port,Use the Light Unit Serial to display the current 13 | ambient lighting value 请连接端口 ,使用Light Unit 串口显示当前环境光照值。 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Atom. 初始化M5Atom 20 | Serial.printf("\n\nUNIT_LIGHT EXAMPLE"); 21 | pinMode(26, INPUT); // Set pin 26 as input mode. 设置引脚26为输入模式 22 | } 23 | 24 | void loop() { 25 | static uint16_t digitalRead_value = 0, analogRead_value = 0; 26 | analogRead_value = analogRead(32); // Store the analog quantity read from 27 | // pin 32. 将32号引脚读取到的模拟量存储 28 | digitalRead_value = digitalRead( 29 | 26); // Store the number read from pin 26. 将26号引脚读取到的数字量存储 30 | Serial.printf("Analog:%d\n", analogRead_value); 31 | Serial.printf("Digital:%d\n----\n", digitalRead_value); 32 | delay(200); 33 | } 34 | -------------------------------------------------------------------------------- /examples/Unit/BUTTON/BUTTON.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Button. 按键 10 | * date:2021/8/9 11 | ******************************************************************************* 12 | Please connect to Port,Read the button status of BUTTON Unit and display it on 13 | the Serial 14 | 15 | 请连接端口,读取按键的状态并在显示屏上显示 16 | */ 17 | #include 18 | 19 | int last_value; 20 | int cur_value; 21 | 22 | void setup() { 23 | M5.begin(); // Init Atom. 初始化Atom 24 | pinMode(32, INPUT); // set pin mode to input.设置引脚模式为输入模式 25 | Serial.println("Button example: "); 26 | } 27 | 28 | void loop() { 29 | cur_value = digitalRead(32); // read the value of BUTTON. 读取22号引脚的值 30 | if (cur_value != last_value) { 31 | if (cur_value == 0) { 32 | Serial.println("Button1 Status: pressed"); 33 | Serial.println(" value: 0"); 34 | } else { 35 | Serial.println("Button1 Status: released"); 36 | Serial.println(" value: 1"); 37 | } 38 | last_value = cur_value; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /examples/Unit/FAN/FAN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Fan. 风扇 10 | * date:2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port , Adjust the speed of FAN Unit through PWM. 13 | 请连接端口,通过PWM调节风扇单元的转速。 14 | */ 15 | #include 16 | 17 | #define motor_pin 26 18 | 19 | int freq = 10000; 20 | int ledChannel = 0; 21 | int resolution = 10; 22 | void setup() { 23 | M5.begin(); // Init M5Atom. 初始化M5Atom 24 | Serial.println("MOTOR"); 25 | ledcSetup( 26 | ledChannel, freq, 27 | resolution); // Sets the frequency and number of counts corresponding 28 | // to the channel. 设置通道对应的频率和计数位数 29 | ledcAttachPin( 30 | motor_pin, 31 | ledChannel); // Binds the specified channel to the specified I/O port 32 | // for output. 将指定通道绑定到指定 IO 口上以实现输出 33 | } 34 | 35 | void loop() { 36 | ledcWrite(ledChannel, 1024); // Output PWM. 输出PWM 37 | delay(1000); 38 | ledcWrite(ledChannel, 0); 39 | delay(1000); 40 | } 41 | -------------------------------------------------------------------------------- /examples/Unit/CardKB/CardKB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:CardKB. 键盘 10 | * date:2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port,Read the characters entered by CardKB Unit and display 13 | them on the Serial. 请连接端口,读取CardKB Unit输入的字符并显示在串口上。 14 | */ 15 | 16 | #include 17 | #define CARDKB_ADDR \ 18 | 0x5F // Define the I2C address of CardKB. 定义CardKB的I2C地址 19 | 20 | void setup() { 21 | M5.begin(); // Init M5Atom. 初始化 M5Atom 22 | Serial.printf("IIC Address: 0x5F\n"); 23 | Serial.printf(">>"); 24 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 25 | } 26 | 27 | void loop() { 28 | Wire.requestFrom( 29 | CARDKB_ADDR, 30 | 1); // Request 1 byte from the slave device. 向从设备请求1字节 31 | while ( 32 | Wire.available()) // If received data is detected. 如果检测到收到数据 33 | { 34 | char c = Wire.read(); // Store the received data. 将接收到的数据存储 35 | if (c != 0) { 36 | Serial.printf("%c", c); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/Audio/STT/BaiduRest.h: -------------------------------------------------------------------------------- 1 | #ifndef _BAIDUREST_H_ 2 | #define _BAIDUREST_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define TOKEN_GET_URL "flow.m5stack.com:5003/token_get" 9 | #define REST_URL "flow.m5stack.com:5003/pcm" 10 | #define REST_URL_T2A "flow.m5stack.com:5003/text2audio" 11 | 12 | #define JSON_DOCSIZE 512 13 | 14 | #define DEV_PID_MANDARIN "1537" // 普通话(纯中文识别) 15 | #define DEV_PID_M_AND_E "1536" // 普通话(支持简单的英文识别) 16 | #define DEV_PID_ENGLISH "1737" // 英语 17 | #define DEV_PID_CANTONESE "1637" // 粤语 18 | 19 | struct pcmPack { 20 | uint8_t* packData; 21 | uint32_t packsize; 22 | }; 23 | 24 | class BaiduRest { 25 | private: 26 | String api_token_str; 27 | StaticJsonDocument rest_json_doc; 28 | char ascii2hex_buff[17] = "0123456789abcdef"; 29 | 30 | public: 31 | QueueHandle_t xQ_i2sSteam = NULL; 32 | 33 | public: 34 | BaiduRest(); 35 | ~BaiduRest(); 36 | int gettoken(void); 37 | int creattoken(void); 38 | void settoken(String token_str); 39 | 40 | int Pcm2String(uint8_t* pcm_buff, uint32_t pcm_lan, String dev_pid, 41 | String* results_str); 42 | int String2Pcm(String str, int spd, int pit, int vol, int per, 43 | uint8_t* pcm_buff, size_t* len); 44 | int String2Pcm(String str, int spd, int pit, int vol, int per); 45 | String Str2UrlEncode(String str); 46 | }; 47 | 48 | #endif -------------------------------------------------------------------------------- /examples/Unit/VIBRATOR/VIBRATOR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: Vibrator. 震动电机 10 | * date:2021/8/19 11 | ******************************************************************************* 12 | Please connect to Port,Adjust the speed of VIBRATOR Unit through PWM. 13 | 请连接端口,通过PWM调节Vibrator Unit的速度。 14 | */ 15 | 16 | #include 17 | 18 | #define motor_pin 26 19 | int freq = 10000; 20 | int ledChannel = 0; 21 | int resolution = 10; 22 | void setup() { 23 | M5.begin(); // Init M5Atom. 初始化M5Atom 24 | ledcSetup( 25 | ledChannel, freq, 26 | resolution); // Sets the frequency and number of counts corresponding 27 | // to the channel. 设置通道对应的频率和计数位数 28 | ledcAttachPin( 29 | motor_pin, 30 | ledChannel); // Binds the specified channel to the specified I/O port 31 | // for output. 将指定通道绑定到指定 IO 口上以实现输出 32 | } 33 | 34 | void loop() { 35 | Serial.println("Vibrator"); 36 | ledcWrite(ledChannel, 512); // Output PWM. 输出PWM 37 | delay(1000); 38 | ledcWrite(ledChannel, 0); 39 | delay(1000); 40 | } 41 | -------------------------------------------------------------------------------- /examples/Unit/JOYSTICK/JOYSTICK.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | information:https://docs.m5stack.com/en/unit/joystick 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/joystick 9 | * 10 | * describe: JOYSTICK. 11 | * date:2021/8/30 12 | ******************************************************************************* 13 | Please connect to Port,Read JOYSTICK Unit X, Y axis offset data and button 14 | status 请连接端口,读取操纵杆单位X, Y轴偏移数据和按钮状态 15 | */ 16 | 17 | #include 18 | 19 | #define JOY_ADDR 0x52 // define Joystick I2C address. 定义摇杆的I2C地址 20 | 21 | void setup() { 22 | M5.begin(); 23 | Wire.begin(26, 32); 24 | } 25 | 26 | char data[100]; 27 | void loop() { 28 | static uint8_t x_data, y_data, button_data; 29 | Wire.requestFrom( 30 | JOY_ADDR, 31 | 3); // Request 3 bytes from the slave device. 向从设备请求3个字节 32 | if (Wire.available()) { // If data is received. 如果接收到数据 33 | x_data = Wire.read(); 34 | y_data = Wire.read(); 35 | button_data = Wire.read(); 36 | sprintf(data, "x:%d y:%d button:%d\n", x_data, y_data, button_data); 37 | Serial.print(data); 38 | 39 | Serial.printf("x:%04d y:%04d button:%d\n", x_data, y_data, button_data); 40 | } 41 | delay(200); 42 | } 43 | -------------------------------------------------------------------------------- /examples/Unit/BPS_QMP6988/BPS_QMP6988.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:BPS_QMP6988. 压力传感器 10 | * date:2021/8/10 11 | ****************************************************************************** 12 | Please connect to Port,Read atmospheric pressure and display them on the 13 | display Serial 请连接端口,读取大气压强并在显示屏上显示 14 | */ 15 | #include 16 | #include "Wire.h" //The BPS uses I2C comunication. 17 | #include "M5_ENV.h" 18 | 19 | QMP6988 qmp6988; 20 | 21 | void setup() { 22 | M5.begin(); // Init M5Atom. 初始化 M5Atom 23 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 24 | } 25 | 26 | void loop() { 27 | while ( 28 | !qmp6988 29 | .init()) { // Init qmp6988.True if the init was successful, 30 | // otherwise false. 初始化qmp6988,如果初始化成功返回1 31 | Serial.println( 32 | "\nCould not find a valid qmp6988 sensor, check wiring!"); 33 | } 34 | Serial.printf("Pressure:%0.2f\n", 35 | qmp6988.calcPressure()); // Serial print format string. 36 | // 串口打印格式化字符串 37 | delay(2000); // Delay 2s. 延迟2s 38 | } 39 | -------------------------------------------------------------------------------- /examples/Unit/RS485_SP485EEN/RS485_SP485EEN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/rs485 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/rs485 8 | * 9 | * describe: rs485. 10 | * date:2021/8/30 11 | ******************************************************************************* 12 | Please connect to Port,Use RS485 Unit for serial communication, continuously 13 | send "Hello", and display the received content on the serial. 14 | 请连接端口,在EXT.IO 15 | 采用RS485单元串行通信,连续发送“Hello”,接收到的内容显示在串口上。 16 | */ 17 | #include 18 | #define RX_PIN 32 19 | #define TX_PIN 26 20 | 21 | int i = 0, s = 0; 22 | 23 | void setup() { 24 | M5.begin(); 25 | Serial.println("RS485 Unit test"); 26 | Serial.begin(115200); 27 | Serial2.begin( 28 | 115200, SERIAL_8N1, RX_PIN, 29 | TX_PIN); // Set the baud rate of serial port 2 to 115200,8 data bits, 30 | // no parity bits, and 1 stop bit, and set RX to 16 and TX 31 | // to 17. 32 | // 设置串口二的波特率为115200,8位数据位,没有校验位,1位停止位,并设置RX为16,TX为17 33 | delay(10); 34 | Serial2.read(); 35 | } 36 | 37 | void loop() { 38 | Serial2.write("Hello\n"); 39 | 40 | if (Serial2.available()) { 41 | Serial.print(char(Serial2.read())); 42 | } 43 | delay(100); 44 | } 45 | -------------------------------------------------------------------------------- /examples/Unit/RFID_RC522/RFID_RC522.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: RFID. 10 | * date:2021/8/19 11 | ******************************************************************************* 12 | Please connect to Port,Use the RFID Unit to read the Fudan card ID and display 13 | the ID on the Serial. 请连接端口,使用RFID Unit 读取ID卡并在串口上显示。 14 | */ 15 | 16 | #include 17 | #include "MFRC522_I2C.h" 18 | 19 | MFRC522 mfrc522(0x28); // Create MFRC522 instance. 创建MFRC522实例 20 | 21 | void setup() { 22 | M5.begin(); // Init M5Atom. 初始化M5Atom 23 | Serial.println("\n\nMFRC522 Test"); 24 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 25 | 26 | mfrc522.PCD_Init(); // Init MFRC522. 初始化 MFRC522 27 | Serial.println("Please put the card"); 28 | } 29 | 30 | void loop() { 31 | if (!mfrc522.PICC_IsNewCardPresent() || 32 | !mfrc522.PICC_ReadCardSerial()) { // 如果没有读取到新的卡片 33 | delay(200); 34 | return; 35 | } 36 | Serial.print("UID:"); 37 | for (byte i = 0; i < mfrc522.uid.size; i++) { 38 | Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); 39 | Serial.print(mfrc522.uid.uidByte[i], HEX); 40 | } 41 | Serial.println(""); 42 | } -------------------------------------------------------------------------------- /examples/Unit/BPS_BMP280/BPS_BMP280.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:BPS_BMP280. 压力传感器 10 | * date:2021/8/10 11 | ******************************************** *********************************** 12 | Please connect to Port,Read atmospheric pressure and temperature and display 13 | them on the display Serial 请连接,读取大气压强和温度并在显示屏上显示 14 | */ 15 | #include 16 | #include //The BPS uses I2C comunication. 17 | #include "Adafruit_Sensor.h" 18 | #include 19 | 20 | Adafruit_BMP280 bme; 21 | 22 | void setup() { 23 | M5.begin(); // Init M5Atom. 初始化 M5Atom 24 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 25 | while (!bme.begin( 26 | 0x76)) { // Init this sensor,True if the init was successful, otherwise 27 | // false. 初始化传感器,如果初始化成功返回1 28 | Serial.println("Could not find a valid BMP280 sensor, check wiring!"); 29 | } 30 | } 31 | 32 | float pressure, 33 | Temp; // Store the vuale of pressure and Temperature. 存储压力和温度() 34 | 35 | void loop() { 36 | pressure = bme.readPressure(); 37 | Temp = bme.readTemperature(); 38 | Serial.printf("Pre:%2.0fPa\nTem:%2.0f^C\n\n", pressure, Temp); 39 | delay(100); 40 | } 41 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/SPIFFS/SPIFFS_Delete/SPIFFS_Delete.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:SPIFFS Delete 10 | * date:2021/8/4 11 | ****************************************************************************** 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | String file_name = 18 | "/M5Stack/notes.txt"; // Sets the location and name of the file to be 19 | // operated on. 设置被操作的文件位置和名称 20 | void setup() { 21 | M5.begin(); // Init M5Atom. 初始化 M5ATOM 22 | 23 | if (SPIFFS.begin()) { // Start SPIFFS, return 1 on success. 24 | // 启动闪存文件系统,若成功返回1 25 | Serial.println("\nSPIFFS Started."); // Serial port output format 26 | // String. 串口输出格式化字符串 27 | } else { 28 | Serial.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 | Serial.print(file_name); 35 | Serial.println(" Remove sucess"); 36 | } else { 37 | Serial.print(file_name); 38 | Serial.println(" Remove fail"); 39 | } 40 | } 41 | 42 | void loop() { 43 | } -------------------------------------------------------------------------------- /examples/Unit/ANGLE/ANGLE.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Angle. 角度计 10 | * date:2021/8/9 11 | ******************************************************************************* 12 | Description: Read the Angle of the angometer and convert it to digital display 13 | 读取角度计的角度,并转换为数字量显示 14 | */ 15 | 16 | #include 17 | int sensorPin = 18 | 32; // set the input pin for the potentiometer. 设置角度计的输入引脚 19 | 20 | int last_sensorValue = 21 | 100; // Stores the value last read by the sensor. 存储传感器上次读取到的值 22 | int cur_sensorValue = 0; // Stores the value currently read by the sensor. 23 | // 存储传感器当前读取到的值 24 | 25 | void setup() { 26 | M5.begin(); // Init M5Atom. 初始化 M5Atom 27 | pinMode( 28 | sensorPin, 29 | INPUT); // Sets the specified pin to input mode. 设置指定引脚为输入模式 30 | dacWrite(25, 0); 31 | } 32 | 33 | void loop() { 34 | cur_sensorValue = analogRead( 35 | sensorPin); // read the value from the sensor. 读取当前传感器的值 36 | if (abs(cur_sensorValue - last_sensorValue) > 37 | 10) { // If the difference is more than 10. 如果差值超过10 38 | Serial.print("the value of ANGLE: "); 39 | Serial.println(cur_sensorValue); 40 | last_sensorValue = cur_sensorValue; 41 | } 42 | delay(200); 43 | } 44 | -------------------------------------------------------------------------------- /examples/Unit/NCIR_MLX90614/NCIR_MLX90614.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/ncir 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/ncir 8 | * 9 | * describe: ncir. 单点红外测温传感器 10 | * date:2021/8/27 11 | ******************************************************************************* 12 | Please connect to Port,Use NCIR Unit to measure the temperature without 13 | contact and display the value on the Serial. 14 | 请连接端口,使用NCIR单元无接触测量温度,并在串口上显示。 15 | */ 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); 20 | Wire.begin(26, 32); 21 | Serial.print("NCIR"); 22 | } 23 | 24 | void loop() { 25 | static uint16_t result; 26 | static float temperature; 27 | Wire.beginTransmission(0x5A); // Send Initial Signal and I2C Bus Address 28 | // 发送初始信号和I2C总线地址 29 | Wire.write(0x07); // Send data only once and add one address automatically. 30 | // 只发送一次数据,并自动添加一个地址。 31 | Wire.endTransmission(false); // Stop signal 停止信号 32 | Wire.requestFrom( 33 | 0x5A, 2); // Get 2 consecutive data from 0x5A, and the data is stored 34 | // only. 从0x5A中获取2个连续的数据,并且只存储这些数据。 35 | result = Wire.read(); // Receive DATA 接收数据 36 | result |= Wire.read() << 8; // Receive DATA 接收数据 37 | 38 | temperature = result * 0.02 - 273.15; 39 | Serial.printf("Temp:%.3f\n", temperature); 40 | delay(500); 41 | } -------------------------------------------------------------------------------- /examples/Unit/ULTRA_SONIC/ULTRA_SONIC.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: Ultrasonic. 超声波测距传感器 10 | * date:2021/8/19 11 | ******************************************************************************* 12 | Please connect to Port,Display the distance measured by ultrasonic 13 | 请连接端口,显示超声波测量的距离 14 | */ 15 | 16 | #include 17 | 18 | void setup() { 19 | M5.begin(); // Init M5Atom. 初始化M5Atom 20 | Wire.begin(26, 32); 21 | Serial.print("Ultrasonic"); 22 | } 23 | 24 | float readEUS() { 25 | uint32_t data; 26 | Wire.beginTransmission(0x57); // Transfer data to 0x57. 将数据传输到0x57 27 | Wire.write(0x01); 28 | Wire.endTransmission(); // Stop data transmission with the Ultrasonic Unit. 29 | // 停止与Ultrasonic Unit的数据传输 30 | delay(120); 31 | Wire.requestFrom(0x57, 3); // Request 3 bytes from Ultrasonic Unit. 32 | // 向Ultrasonic Unit请求3个字节。 33 | data = Wire.read(); 34 | data <<= 8; 35 | data |= Wire.read(); 36 | data <<= 8; 37 | data |= Wire.read(); 38 | return float(data) / 1000; 39 | } 40 | 41 | void loop() { 42 | static float newvalue = 0; 43 | newvalue = readEUS(); 44 | if ((newvalue < 1500) && (newvalue > 20)) { 45 | Serial.printf("Distance:%.2fmm\n", newvalue); 46 | } 47 | delay(100); 48 | } -------------------------------------------------------------------------------- /examples/Unit/IR/IR.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/ir 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/ir 8 | * 9 | * describe: ir. 10 | * date:2021/8/27 11 | ******************************************************************************* 12 | Please connect to Port B,Use IR Unit to receive and test infrared receiving 13 | and transmitting 请连接端口B,使用红外单元接收和测试红外接收和发射. 14 | */ 15 | 16 | #include 17 | 18 | int ir_recv_pin = 32; // set the input pin. 设置引脚 19 | int ir_send_pin = 26; 20 | 21 | int last_recv_value = 0; 22 | int cur_recv_value = 0; 23 | 24 | void setup() { 25 | M5.begin(); 26 | Serial.begin(115200); 27 | pinMode(ir_recv_pin, INPUT); 28 | pinMode(ir_send_pin, OUTPUT); 29 | // send infrared light. 发送红外线 30 | // now, you can see the infrared light through mobile phone camera. 31 | // 现在,你可以通过手机摄像头看到红外光 32 | digitalWrite(ir_send_pin, 1); 33 | Serial.println("Test for IR receiver: "); 34 | } 35 | 36 | void loop() { 37 | // now, once you press the button on a remote controller to send infrared 38 | // light. 现在,一旦你按下遥控器上的按钮发送红外线 the Serial will display 39 | // "detected!" 串口将显示“检测到!” 40 | cur_recv_value = digitalRead(ir_recv_pin); 41 | if (last_recv_value != cur_recv_value) { 42 | if (cur_recv_value == 43 | 0) { // 0: detected 1: not detected, 0检测到,1没有检测到 44 | Serial.println("detected!"); 45 | } 46 | last_recv_value = cur_recv_value; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /examples/Unit/RGB_SK6812/RGB_SK6812.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:RGB. 多彩灯 10 | * date:2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port ,Control RGB Unit to scroll through three colors of 13 | red, green and blue 请连接端口,控制RGB单元滚动红、绿、蓝三种颜色. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #define PIN 26 // 定义NeoPixel的控制引脚 20 | #define NUMPIXELS 3 // 定义NeoPixel控制灯灯数量 21 | 22 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel( 23 | NUMPIXELS, PIN, 24 | NEO_GRB + NEO_KHZ800); // set number of LEDs, pin number, LED type. 25 | // 设置灯的数量,控制引脚编号,灯灯类型 26 | 27 | void setup() { 28 | M5.begin(); // Init M5Atom. 初始化 M5Atom 29 | pixels.begin(); // Init the NeoPixel library. 初始化NeoPixel库 30 | } 31 | 32 | int i = 0, j = 1, k = 2; 33 | 34 | void loop() { 35 | pixels.setPixelColor(i++, pixels.Color(100, 0, 0)); // Bright red 36 | pixels.setPixelColor(j++, pixels.Color(0, 100, 0)); // Bright green 37 | pixels.setPixelColor(k++, pixels.Color(0, 0, 100)); // Bright blue 38 | pixels.show(); // sends the updated color to the hardware. 39 | // 将更新后的颜色发送到硬件。 40 | delay(100); 41 | if (i == 3) 42 | i = 0; 43 | else if (j == 3) 44 | j = 0; 45 | else if (k == 3) 46 | k = 0; 47 | } 48 | -------------------------------------------------------------------------------- /examples/Unit/TVOC_SGP30/TVOC_SGP30.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/tvoc 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/tvoc 8 | * 9 | * describe: TVOC/eCO2. 10 | * date:2021/8/26 11 | ******************************************************************************* 12 | Description: The Serial will display TVOC and CO2. 串口将显示TVOC和CO2。 13 | Note: SGP30 needs 15 seconds to initialize calibration after power on. 14 | SGP30开机后需要15秒进行初始校准。 15 | */ 16 | 17 | #include 18 | #include "Adafruit_SGP30.h" 19 | 20 | Adafruit_SGP30 sgp; 21 | long last_millis = 0; 22 | 23 | void setup() { 24 | M5.begin(true, true, true); 25 | Wire.begin(26, 32); 26 | Serial.println("TVOC TEST"); 27 | if (!sgp.begin()) { // Init the sensor. 初始化传感器 28 | Serial.println("Sensor not found"); 29 | while (1) 30 | ; 31 | } 32 | Serial.println("\nInitialization..."); 33 | } 34 | 35 | void loop() { 36 | static int i = 15; 37 | while (i > 0) { 38 | if (millis() - last_millis > 1000) { 39 | last_millis = millis(); 40 | i--; 41 | } 42 | } 43 | 44 | if (!sgp.IAQmeasure()) { // Commands the sensor to take a single eCO2/VOC 45 | // measurement. 命令传感器进行一次eCO2/VOC测量 46 | Serial.println("Measurement failed"); 47 | return; 48 | } 49 | Serial.printf("TVOC:%d ppb\n", sgp.TVOC); 50 | Serial.printf("eCO2:%d ppm\n", sgp.eCO2); 51 | delay(500); 52 | } 53 | -------------------------------------------------------------------------------- /examples/Unit/FINGER_FPC1020A/FINGER_FPC1020A.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | *information:https://docs.m5stack.com/en/unit/finger 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/finger 9 | * 10 | * describe: Finger. 11 | * date:2021/8/26 12 | ******************************************************************************* 13 | */ 14 | 15 | #include 16 | #include "M5_FPC1020A.h" 17 | 18 | uint8_t userNum; // User number 19 | FingerPrint FP_M; 20 | 21 | void CleanSerial() { 22 | userNum = FP_M.fpm_getUserNum(); // Get users Numbers. 获取用户数量 23 | Serial.print("userNum:"); 24 | Serial.println(userNum); 25 | } 26 | 27 | void setup() { 28 | M5.begin(); 29 | Serial2.begin(19200, SERIAL_8N1, 32, 26); 30 | Serial.println("Finger example"); 31 | userNum = FP_M.fpm_getUserNum(); 32 | Serial.print("userNum:"); 33 | Serial.println(userNum); 34 | } 35 | 36 | void loop() { 37 | M5.update(); 38 | uint8_t res1; 39 | // ButtonA: Add user. 添加用户 40 | if (M5.Btn.wasPressed()) { 41 | CleanSerial(); 42 | Serial.println("Fingerprint Typing"); 43 | 44 | res1 = FP_M.fpm_addUser(userNum, 1); 45 | if (res1 == ACK_SUCCESS) { 46 | Serial.println("Success"); 47 | } else if (res1 == ACK_FAIL) { 48 | Serial.println("Fail"); 49 | } else if (res1 == ACK_FULL) { 50 | Serial.println("Full"); 51 | } else { 52 | Serial.println("Timeout"); 53 | } 54 | userNum++; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /examples/Unit/FADER/FADER.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/fader 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/fader 8 | * 9 | * describe:UNIT FADER. 滑动电位器/推子 10 | * date:2021/8/20 11 | ******************************************************************************* 12 | Connect UNIT FADER to port and push the FADER slider to adjust the input value 13 | and light brightness 将UNIT FADER连接到端口, 14 | 推动FADER滑杆即可实现调整输入数值大小与灯光亮度 15 | */ 16 | 17 | #include "M5Atom.h" 18 | #include "FastLED.h" 19 | 20 | // How many leds in your strip? 21 | #define NUM_LEDS 14 22 | #define INPUT_PINS 36 23 | 24 | #define DATA_PIN 26 25 | 26 | // Define the array of leds 27 | CRGB leds[NUM_LEDS]; 28 | 29 | uint8_t beginHue = 0; 30 | uint8_t deltaHue = 30; 31 | uint8_t brightness = 100; 32 | uint16_t rawADC = 0; 33 | 34 | void setup() { 35 | M5.begin(); 36 | FastLED.addLeds(leds, NUM_LEDS); 37 | delay(1000); 38 | pinMode(36, INPUT); 39 | fill_rainbow(leds, NUM_LEDS, beginHue, deltaHue); 40 | } 41 | 42 | void loop() { 43 | rawADC = analogRead(INPUT_PINS); // Read ADC value 读取ADC数值 44 | brightness = map(rawADC, 0, 4095, 0, 45 | 255); // The mapping ADC value is the brightness value 46 | // range 映射ADC值为亮度值范围 47 | FastLED.setBrightness(brightness); // Adjust the brightness of the FADER 48 | // LED 调整FADER LED灯亮度 49 | FastLED.show(); 50 | Serial.printf("%d\r\n", rawADC); 51 | delay(100); 52 | } -------------------------------------------------------------------------------- /examples/Unit/HEX_SK6812/HEX_SK6812.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:HEX. 灯板 10 | * date:2021/8/17 11 | ******************************************************************************* 12 | Please connect to Port , Control HEX Unit to run rainbow light show. 13 | 请连接端口,控制HEX Unit 彩虹灯显示。 14 | */ 15 | 16 | #include 17 | #include "FastLED.h" 18 | 19 | #define Neopixel_PIN 26 20 | #define NUM_LEDS 37 21 | 22 | CRGB leds[NUM_LEDS]; 23 | uint8_t gHue = 0; // Initial tone value. 起始色调数值 24 | 25 | void setup() { 26 | M5.begin(); // Init M5Atom. 初始化M5Atom 27 | Serial.println("HEX Example"); 28 | Serial.println("Display rainbow effect"); 29 | 30 | // Neopixel initialization. 初始化灯带 31 | FastLED.addLeds(leds, NUM_LEDS) 32 | .setCorrection(TypicalLEDStrip); 33 | FastLED.setBrightness(5); // set the LED brightness to 5. 设置灯带的亮度为5 34 | } 35 | 36 | void loop() { 37 | fill_rainbow( 38 | leds, NUM_LEDS, gHue, 39 | 7); // Set the leds from 0 to 37 beads to gradient rainbow color, the 40 | // starting tone value to gHue, and the color difference between 41 | // adjacent beads to 7. 42 | // 将leds灯带的从0~37个灯珠设置为渐变彩虹色,起始色调数值设置为gHue,相邻灯珠色差为7 43 | FastLED.show(); // Updated LED color. 更新LED色彩 44 | EVERY_N_MILLISECONDS(20) { 45 | gHue++; 46 | } // The program is executed every 20 milliseconds. 47 | // 每20毫秒执行一次其中的程序 48 | } 49 | -------------------------------------------------------------------------------- /examples/Unit/ENVIII_SHT30_QMP6988/ENVIII_SHT30_QMP6988.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:ENVIII_SHT30_QMP6988. 环境传感器 10 | * date:2021/8/17 11 | ******************************************************************************* 12 | Please connect to Port,Read temperature, humidity and atmospheric pressure and 13 | display them on the display Serial 14 | 请连接端口,读取温度、湿度和大气压强并在显示屏上显示 15 | */ 16 | #include 17 | #include "Adafruit_Sensor.h" 18 | #include 19 | #include "M5_ENV.h" 20 | 21 | SHT3X sht30; 22 | QMP6988 qmp6988; 23 | 24 | float tmp = 0.0; 25 | float hum = 0.0; 26 | float pressure = 0.0; 27 | 28 | void setup() { 29 | M5.begin(); // Init M5Atom. 初始化M5Atom 30 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 31 | qmp6988.init(); 32 | Serial.println(F("ENV Unit III test")); 33 | } 34 | 35 | void loop() { 36 | pressure = qmp6988.calcPressure(); 37 | if (sht30.get() == 0) { // Obtain the data of shT30. 获取sht30的数据 38 | tmp = sht30.cTemp; // Store the temperature obtained from shT30. 39 | // 将sht30获取到的温度存储 40 | hum = sht30.humidity; // Store the humidity obtained from the SHT30. 41 | // 将sht30获取到的湿度存储 42 | } else { 43 | tmp = 0, hum = 0; 44 | } 45 | Serial.printf( 46 | "Temp: %2.1f \r\nHumi: %2.0f%% \r\nPressure:%2.0fPa\r\n---\n", tmp, 47 | hum, pressure); 48 | delay(2000); 49 | } 50 | -------------------------------------------------------------------------------- /examples/Unit/THERMAL_MLX90640/MLX90640_I2C_Driver.h: -------------------------------------------------------------------------------- 1 | /** 2 | @copyright (C) 2017 Melexis N.V. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | */ 17 | #ifndef _MLX90640_I2C_Driver_H_ 18 | #define _MLX90640_I2C_Driver_H_ 19 | 20 | #include 21 | 22 | // Define the size of the I2C buffer based on the platform the user has 23 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 24 | #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) 25 | 26 | // I2C_BUFFER_LENGTH is defined in Wire.H 27 | #define I2C_BUFFER_LENGTH BUFFER_LENGTH 28 | 29 | #elif defined(__SAMD21G18A__) 30 | 31 | // SAMD21 uses RingBuffer.h 32 | #define I2C_BUFFER_LENGTH SERIAL_BUFFER_SIZE 33 | 34 | #elif __MK20DX256__ 35 | // Teensy 36 | 37 | #elif ARDUINO_ARCH_ESP32 38 | // ESP32 based platforms 39 | 40 | #else 41 | 42 | // The catch-all default is 32 43 | #define I2C_BUFFER_LENGTH 32 44 | 45 | #endif 46 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 47 | 48 | void MLX90640_I2CInit(void); 49 | int MLX90640_I2CRead(uint8_t slaveAddr, unsigned int startAddress, 50 | unsigned int nWordsRead, uint16_t *data); 51 | int MLX90640_I2CWrite(uint8_t slaveAddr, unsigned int writeAddress, 52 | uint16_t data); 53 | void MLX90640_I2CFreqSet(int freq); 54 | #endif 55 | -------------------------------------------------------------------------------- /examples/Unit/ENV_DHT12_BMP280/ENV_DHT12_BMP280.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:ENVII_DH12_BMP280. 环境传感器 10 | * date:2021/8/17 11 | ******************************************************************************* 12 | Please connect to Port A,Read temperature, humidity and atmospheric pressure 13 | and display them on the display Serial 14 | 请连接端口A,读取温度、湿度和大气压强并在显示屏上显示 15 | */ 16 | 17 | #include 18 | #include "Adafruit_Sensor.h" 19 | #include 20 | #include "M5_ENV.h" 21 | 22 | DHT12 dht12; 23 | Adafruit_BMP280 bme; 24 | 25 | void setup() { 26 | M5.begin(); // Init M5Atom. 初始化M5Atom 27 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 28 | Serial.println(F("ENV Unit(DHT12 and BMP280) test")); 29 | } 30 | 31 | void loop() { 32 | while (!bme.begin(0x76)) { 33 | Serial.println("Could not find a valid BMP280 sensor, check wiring!"); 34 | } 35 | float tmp = dht12.readTemperature(); // Store the temperature obtained from 36 | // dht12. 将dht12获取到的温度存储 37 | float hum = dht12.readHumidity(); // Store the humidity obtained from the 38 | // dht12. 将dht12获取到的湿度存储 39 | float pressure = bme.readPressure(); // Stores the pressure gained by BMP. 40 | // 存储bmp获取到的压强 41 | Serial.printf( 42 | "Temp: %2.1f \r\nHumi: %2.0f%% \r\nPressure:%2.0fPa\r\n------\n", tmp, 43 | hum, pressure); 44 | 45 | delay(2000); 46 | } 47 | -------------------------------------------------------------------------------- /examples/Unit/DAC_MCP4725/DAC_MCP4725.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:DAC_MCP4725. 数模转换 10 | * date:2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port ,Use DAC Unit to output 0 ~ 3.3V voltage with an 13 | accuracy of 12 bits. 请连接端口,使用DAC Unit 输出12位精度的0 ~ 3.3V电压。 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | #define DAC_ADDR \ 20 | 0x60 // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR 21 | // pin tied to VCC) For MCP4725A0 the address is 0x60 or 0x61 For 22 | // MCP4725A2 the address is 0x64 or 0x65 23 | 24 | Adafruit_MCP4725 dac; 25 | 26 | void setup(void) { 27 | M5.begin(true, false, true); // Init M5Atom(Init serial and display). 28 | // 初始化 M5Atom(初始化串口和串口) 29 | Serial.print("\nDAC MCP4725 demo."); 30 | 31 | dac.begin(0x60); // Setups the hardware address and checks the DAC was 32 | // found. 设置硬件地址并检查是否找到DAC 33 | dac.setVoltage(2048, false); 34 | M5.dis.fillpix(0x00FFFF); 35 | } 36 | 37 | void loop(void) { 38 | Serial.println("Voltage:1.2V"); 39 | dac.setVoltage(1024, 40 | false); // Set the voltage to 1.2V and retain the current 41 | // voltage output after power off or reset. 42 | // 设置电压为1.2v,关闭断电或复位后保留当前电压输出 43 | delay(1000); 44 | Serial.println("Voltage:2.4V"); 45 | dac.setVoltage(2048, false); // 2.4v 46 | delay(1000); 47 | } -------------------------------------------------------------------------------- /examples/Unit/PaHUB/PaHUB.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/pahub 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/pahub 8 | * 9 | * describe: PaHUB. 10 | * date:2021/8/31 11 | ******************************************************************************* 12 | Please connect to Port , Use PaHUB Unit to expand multiple I2C devices and 13 | scan the I2C addresses of the slave devices in order. 请连接端口, 使用PaHUB 14 | Unit扩展多个I2C设备,并依次扫描从设备的I2C地址。 15 | */ 16 | 17 | #include 18 | #include "ClosedCube_TCA9548A.h" 19 | 20 | #define FRONT 1 21 | 22 | #define X_LOCAL 40 23 | #define Y_LOCAL 10 24 | #define X_OFFSET 160 25 | #define Y_OFFSET 12 26 | 27 | #define PaHub_I2C_ADDRESS 0x70 28 | 29 | ClosedCube::Wired::TCA9548A tca9548a; 30 | 31 | void setup() { 32 | M5.begin(); 33 | Wire.begin(26, 32); 34 | tca9548a.address(PaHub_I2C_ADDRESS); 35 | } 36 | 37 | void loop() { 38 | uint8_t returnCode = 0; 39 | uint8_t address; 40 | for (uint8_t channel = 0; channel < TCA9548A_MAX_CHANNELS; channel++) { 41 | Serial.printf("CH%d : ", channel); 42 | returnCode = tca9548a.selectChannel(channel); 43 | if (returnCode == 0) { 44 | for (address = 0x01; address < 0x7F; address++) { 45 | Wire.beginTransmission(address); 46 | returnCode = Wire.endTransmission(); 47 | if (returnCode == 0) { 48 | Serial.print("I2C device = "); 49 | Serial.printf("0X%X \n", address); 50 | } 51 | } 52 | } 53 | delay(100); 54 | } 55 | Serial.print("===================\n"); 56 | } 57 | -------------------------------------------------------------------------------- /examples/Unit/Dual_Button/Dual_Button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Button_Two. 双按键 10 | * date:2021/8/9 11 | ******************************************************************************* 12 | Please connect to Port,Read the button status of BUTTON Unit and display it on 13 | the Serial 14 | 15 | 请连接端口,读取按键的状态并在显示屏上显示 16 | */ 17 | #include 18 | 19 | int last_value1 = 0, last_value2 = 0; 20 | int cur_value1 = 0, cur_value2 = 0; 21 | 22 | void setup() { 23 | M5.begin(); // Init Atom. 初始化 Atom 24 | pinMode(32, INPUT); // set pin mode to input.设置引脚模式为输入模式 25 | pinMode(26, INPUT); 26 | Serial.println("Button example: "); 27 | } 28 | 29 | void loop() { 30 | cur_value1 = digitalRead(32); // read the value of BUTTON. 读取22号引脚的值 31 | cur_value2 = digitalRead(26); 32 | if (cur_value1 != last_value1) { 33 | if (cur_value1 == 0) { 34 | Serial.println("Button1 Status: pressed"); 35 | Serial.println(" value: 0"); 36 | } else { 37 | Serial.println("Button1 Status: released"); 38 | Serial.println(" value: 1"); 39 | } 40 | last_value1 = cur_value1; 41 | } 42 | if (cur_value2 != last_value2) { 43 | if (cur_value2 == 0) { 44 | Serial.println("Button2 Status: pressed"); 45 | Serial.println(" value: 0"); 46 | } else { 47 | Serial.println("Button2 Status: released"); 48 | Serial.println(" value: 1"); 49 | } 50 | last_value2 = cur_value2; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/Unit/EXT_IO/EXT_IO.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/extio 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/extio 8 | * 9 | * describe: extio. 10 | * date:2021/8/30 11 | ******************************************************************************* 12 | Please connect to Port ,Control the 8 extended IOs on the EXT.IO Unit to cycle 13 | high and low level changes. 请连接端口 ,在EXT.IO 14 | Unit上控制8个扩展的IO来循环高电平和低电平的变化。 15 | */ 16 | #include 17 | #include "PCA9554.h" // Load the PCA9554 Library 18 | 19 | PCA9554 ioCon1( 20 | 0x27); // Create an object at this address. 在这个地址上创建一个对象 21 | 22 | uint8_t res; 23 | void setup() { 24 | M5.begin(); 25 | Wire.begin(); 26 | Serial.print("UNIT_IO EXAMPLE\n"); 27 | 28 | ioCon1.twiWrite( 29 | 26, 32); // Sets the I2C pin of the connection. 设置连接的I2C引脚 30 | delay(10); 31 | res = 1; 32 | ioCon1.twiRead(res); 33 | Serial.printf("res:%d\r\n", res); 34 | 35 | ioCon1.portMode( 36 | ALLOUTPUT); // Set the port as all output. 设置所有引脚为输出模式 37 | } 38 | 39 | void loop() { 40 | for (int i = 0; i < 8; i++) ioCon1.digitalWrite(i, LOW); 41 | delay(1000); 42 | for (int i = 0; i < 8; i++) ioCon1.digitalWrite(i, HIGH); 43 | delay(1000); 44 | 45 | // write 0-7 HIGH. 设置0~7号引脚为高电平 46 | Serial.println(ioCon1.digitalWritePort(0xff)); 47 | delay(200); 48 | 49 | // write 0-7 LOW. 设置0~7号引脚为低电平 50 | Serial.println(ioCon1.digitalWritePort(0x00)); 51 | delay(200); 52 | 53 | //// write Port, the same read 54 | for (byte i = 0; i < 8; i++) { 55 | ioCon1.digitalWritePort((1 << i)); 56 | delay(200); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /examples/Unit/ENVII_SHT30_BMP280/ENVII_SHT30_BMP280.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:ENVII_SHT30_BMP280. 环境传感器 10 | * date:2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port,Read temperature, humidity and atmospheric pressure and 13 | display them on the display Serial 14 | 请连接端口,读取温度、湿度和大气压强并在显示屏上显示 15 | */ 16 | 17 | #include 18 | #include "Adafruit_Sensor.h" 19 | #include 20 | #include "M5_ENV.h" 21 | SHT3X sht30; 22 | Adafruit_BMP280 bme; 23 | 24 | float tmp = 0.0; 25 | float hum = 0.0; 26 | float pressure = 0.0; 27 | 28 | void setup() { 29 | M5.begin(); // Init M5Atom. 初始化 M5Atom 30 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 31 | Serial.println(F("ENV Unit(SHT30 and BMP280) test...\n")); 32 | } 33 | 34 | void loop() { 35 | while (!bme.begin(0x76)) { // 初始化bme传感器. Init the sensor of bme 36 | Serial.println("Could not find a valid BMP280 sensor, check wiring!"); 37 | } 38 | pressure = bme.readPressure(); // Stores the pressure gained by BMP. 39 | // 存储bmp获取到的压强 40 | sht30.get(); // Obtain the data of shT30. 获取sht30的数据 41 | tmp = sht30.cTemp; // Store the temperature obtained from shT30. 42 | // 将sht30获取到的温度存储 43 | hum = sht30.humidity; // Store the humidity obtained from the SHT30. 44 | // 将sht30获取到的湿度存储 45 | Serial.printf("Temp: %2.1f\nHumi: %2.0f%%\nPressure:%2.0fPa\n\n", tmp, hum, 46 | pressure); 47 | delay(2000); 48 | } 49 | -------------------------------------------------------------------------------- /examples/Unit/RTC_BM8563/RTC_BM8563.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2022 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/rtc 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rtc 8 | * 9 | * Product: RTC. 实时时钟 10 | * Date: 2022/7/29 11 | ******************************************************************************* 12 | Please connect to Port A,The time is displayed on the screen. 13 | 请连接端口A,屏幕上显示时间。 14 | */ 15 | 16 | #include "M5Atom.h" 17 | #include "Unit_RTC.h" 18 | 19 | Unit_RTC RTC; 20 | 21 | rtc_time_type RTCtime; 22 | rtc_date_type RTCdate; 23 | 24 | char str_buffer[64]; 25 | 26 | void setup() { 27 | M5.begin(true, false, true); // Init M5Atom. 初始化M5Atom 28 | Serial.print("RTC"); 29 | RTC.begin(); // Example Initialize the RTC clock. 初始化RTC时钟 30 | RTCtime.Hours = 14; // Set the RTC clock time. 设置RTC时钟时间 31 | RTCtime.Minutes = 40; 32 | RTCtime.Seconds = 5; 33 | 34 | RTCdate.WeekDay = 4; // Set the RTC clock date. 设置RTC时钟日期 35 | RTCdate.Month = 7; 36 | RTCdate.Date = 15; 37 | RTCdate.Year = 2021; 38 | 39 | RTC.setTime(&RTCtime); // Example Synchronize the set time to the RTC. 40 | // 将设置的时间同步至RTC 41 | RTC.setDate(&RTCdate); // Synchronize the set date to the RTC. 42 | // 将设置的日期同步至RTC 43 | M5.dis.fillpix(0x00ff00); 44 | } 45 | 46 | void loop() { 47 | RTC.getTime(&RTCtime); // To get the time. 获取时间 48 | RTC.getDate(&RTCdate); // Get the date. 获取日期 49 | Serial.printf("RTC Time Now is \n%02d:%02d:%02d\n", RTCtime.Hours, 50 | RTCtime.Minutes, RTCtime.Seconds); 51 | Serial.printf("RTC Date Now is \n%02d:%02d:%02d WeekDay:%02d\n", 52 | RTCdate.Year, RTCdate.Month, RTCdate.Date, RTCdate.WeekDay); 53 | delay(1000); 54 | } -------------------------------------------------------------------------------- /README_cn.md: -------------------------------------------------------------------------------- 1 | # ATOM Library 2 | 3 | 中文 | [English](README_cn.md) 4 | 5 | M5Atom U 6 | 7 | ## 描述 8 | 9 | **ATOM U** 是一款非常小巧灵活的物联网语音识别开发板, 采用乐鑫`ESP32`主控芯片,搭载2个低功耗 `Xtensa® 32-bit LX6` 微处理器,主频高达`240MHz`。集成USB-A接口,IR发射管, 可编程LED灯等外设,即插即用,便于程序上传下载调试。集成`Wi-Fi`和`蓝牙`模块, 搭配内置的数字麦克风SPM1423(I2S), 可实现清晰音频录制, 适用于各种物联网人机交互,语音输入识别场景(STT)。 10 | 11 | - `低代码开发`: 12 | - 支持UIFlow图形化编程平台、脚本化、免编译、云推送 13 | - 全面兼容Arduino、ESP32-IDF等主流开发平台 14 | - `高集成度`: 15 | - USB-A编程/供电接口,IR发射管,可编程RGB灯x1、按键x1 16 | - 经过专业调制的射频电路, 提供稳定可靠的无线通信质量。 17 | - `强拓展性`: 18 | - 轻松接入M5Stack的软硬件体系 19 | 20 | ## 产品特性 21 | 22 | - ESP32-PICO-D4(2.4GHz Wi-Fi 和蓝牙双模) 23 | - 集成可编程RGB LED与按键 24 | - 机身小巧 25 | - 内置红外发射器 26 | - 可扩展的引脚与GROVE接口 27 | - 开发平台: 28 | - [UIFlow](http://flow.m5stack.com) 29 | - [MicroPython](http://micropython.org/) 30 | - [Arduino](http://www.arduino.cc) 31 | 32 | ## 应用 33 | 34 | - 物联网控制器 35 | - 语音录制、云端STT识别 36 | 37 | ## 驱动安装 38 | 39 | 将设备连接至PC,打开设备管理器为设备安装[FTDI驱动](https://ftdichip.com/drivers/vcp-drivers/)。以win10环境为例,下载匹配操作系统的驱动文件, 并解压,通过设备管理器进行安装。(注:某些系统环境下,需要安装两次,驱动才会生效,未识别的设备名通常为`M5Stack`或`USB Serial`, Windows推荐使用驱动文件在设备管理器直接进行安装(自定义更新), 可执行文件安装方式可能无法正常工作)。[点击此处,前往下载FTDI驱动](https://ftdichip.com/drivers/vcp-drivers/) 40 | 41 | ## 管脚映射 42 | 43 | - SPM1423 - I2S 44 | 45 | | M5Core | G5 | G19 | 3.3V | GND | 46 | | ------- | ------- | -------- | ---- | --- | 47 | | SPM1423 | MIC_CLK | MIC_DATA | VCC | GND | 48 | 49 | - IR & SK6812 & BUTTON 50 | 51 | | M5Core | G12 | G27 | G39 | 52 | | ------ | --- | --- | --- | 53 | | IR | TX | / | / | 54 | | SK6812 | / | DIN | / | 55 | | BUTTON | / | / | SW | 56 | 57 | ## 更多信息 58 | 59 | **UIFlow 快速上手**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/atom_u/uiflow) 60 | 61 | **MicroPython API**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/atom_u/mpy) 62 | 63 | **Arduino IDE 环境搭建**: [点击这里](https://docs.m5stack.com/zh_CN/quick_start/atom_u/arduino) -------------------------------------------------------------------------------- /examples/Advanced/Storage/Counter/Counter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:counter. 计数器 10 | * date:2021/8/3 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | Preferences preferences; 18 | 19 | void setup() { 20 | M5.begin(); // Init Atom. 初始化 ATOM 21 | preferences.begin( 22 | "my-app", 23 | false); // We will open storage in RW-mode (second parameter has to be 24 | // false). 25 | // 在perferences中创建叫my-app的空间,并以rw模式打开存储(第二个参数必须为false) 26 | 27 | // preferences.clear(); // Remove all preferences under the opened 28 | // namespace.清除preferences中所有的空间 29 | 30 | // preferences.remove("counter"); // Or remove the counter key only. 31 | // 只清除counter中的值 32 | 33 | unsigned int counter = preferences.getUInt( 34 | "counter", 35 | 0); // Get the counter value in current sapce, if the key does not 36 | // exist, return a default value of 0. 37 | // 在当前空间中读取counter的值(若不存在为0),并赋值给counter 38 | counter++; // Increase counter by 1. 使计数器的值加一 39 | Serial.printf( 40 | "Current counter value: %u\n", 41 | counter); // Print the counter to Serial Monitor. 串口输出计数器的值 42 | preferences.putUInt( 43 | "counter", 44 | counter); // Store the counter to the Preferences. 存储计数器的值 45 | preferences.end(); // Close the Preferences. 关闭Preferences 46 | Serial.println("Restarting in 10 seconds..."); 47 | delay(10000); // delay 10. 延迟10s 48 | ESP.restart(); // Restart. 重启 49 | } 50 | void loop() { 51 | } 52 | -------------------------------------------------------------------------------- /examples/Unit/TRACE/TRACE.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/trace 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/trace 8 | * 9 | * describe: TRACE. 10 | * date:2021/9/1 11 | ******************************************************************************* 12 | Please connect to PORT, Read the status of the four line-tracking sensors of 13 | TRACE Unit and output them through UART. 请连接端口,读取TRACE 14 | Unit四个线跟踪传感器的状态,并通过UART输出。 15 | */ 16 | 17 | #include 18 | 19 | // #define VALUE_SPLIT 20 | 21 | uint8_t value; 22 | int SensorArray[4] = {0}; 23 | 24 | void SensorStatus(void) { 25 | Wire.beginTransmission( 26 | 0x5a); // The data transfer to 0x5A begins. 开始向0x5a传输数据 27 | Wire.write(0x00); 28 | Wire.endTransmission(); // End the data transmission.结束数据传输 29 | Wire.requestFrom(0x5a, 1); // Request a byte from 0x5a. 向0x5a请求一个字节 30 | while (Wire.available()) { // If data is received. 如果数据被接收到 31 | value = Wire.read(); 32 | } 33 | Serial.print(" value = "); 34 | Serial.println(value, HEX); 35 | #ifdef VALUE_SPLIT 36 | SensorArray[3] = (value & 0x08) >> 3; 37 | SensorArray[2] = (value & 0x04) >> 2; 38 | SensorArray[1] = (value & 0x02) >> 1; 39 | SensorArray[0] = (value & 0x01) >> 0; 40 | Serial.println(" After splitting... "); 41 | Serial.print(" SensorArray[0] = "); 42 | Serial.println(SensorArray[0]); 43 | Serial.print(" SensorArray[1] = "); 44 | Serial.println(SensorArray[1]); 45 | Serial.print(" SensorArray[2] = "); 46 | Serial.println(SensorArray[2]); 47 | Serial.print(" SensorArray[3] = "); 48 | Serial.println(SensorArray[3]); 49 | #endif 50 | } 51 | 52 | void setup() { 53 | M5.begin(); 54 | 55 | Wire.begin(); 56 | Serial.println("TRACE example"); 57 | } 58 | 59 | void loop() { 60 | SensorStatus(); 61 | delay(100); 62 | } -------------------------------------------------------------------------------- /examples/Unit/HEART_MAX30100/MAX30100_RawData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Heart Rate. 心率 10 | * date:2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port , HEART Unit obtains the original value of the heart 13 | rate detection and displays it on the Serial. The user can also use the Arduino 14 | IDE Serial Plotter to view the line graph output. 请连接端口,HEART 15 | Unit获取心率检测的原始值并显示在串口上。用户还可以使用Arduino IDE Serial 16 | Plotter查看线图输出。 17 | */ 18 | 19 | #include 20 | #include "MAX30100.h" 21 | 22 | #define SAMPLING_RATE MAX30100_SAMPRATE_100HZ 23 | #define IR_LED_CURRENT MAX30100_LED_CURR_24MA 24 | #define RED_LED_CURRENT MAX30100_LED_CURR_27_1MA 25 | #define PULSE_WIDTH MAX30100_SPC_PW_1600US_16BITS 26 | #define HIGHRES_MODE true 27 | 28 | MAX30100 29 | sensor; // Instantiate a MAX30100 sensor class. 实例化一个MAX30100传感器类 30 | 31 | void setup() { 32 | M5.begin(); // Init M5Atom. 初始化M5Atom 33 | Wire.begin(26, 32); 34 | Serial.print("Initializing MAX30100.."); 35 | 36 | while (!sensor.begin()) { // Initialize the sensor. 初始化传感器 37 | Serial.println("Sensor not found"); 38 | delay(1000); 39 | } 40 | // Set up the wanted parameters. 设置所需的参数 41 | sensor.setMode(MAX30100_MODE_SPO2_HR); 42 | sensor.setLedsCurrent(IR_LED_CURRENT, RED_LED_CURRENT); 43 | sensor.setLedsPulseWidth(PULSE_WIDTH); 44 | sensor.setSamplingRate(SAMPLING_RATE); 45 | sensor.setHighresModeEnabled(HIGHRES_MODE); 46 | } 47 | 48 | void loop() { 49 | uint16_t ir, red; 50 | sensor.update(); // 更新传感器读取到的数据 51 | while (sensor.getRawValues(&ir, &red)) { // 如果获取到数据 52 | Serial.printf("IR: %d\n", ir); 53 | Serial.printf("RED: %d\n", red); 54 | } 55 | delay(500); 56 | } 57 | -------------------------------------------------------------------------------- /examples/Advanced/I2C_Tester/I2C_Tester.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:I2C Scanner. I2C探测 10 | * date:2021/7/27 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(true, true, 19 | true); // Init M5Atom(Initialization of external I2C is also 20 | // included). M5Atom(初始化外部I2C也包含在内) 21 | // Wire.begin(21, 22); //Detect internal I2C, if this sentence is not added, 22 | // it will detect external I2C. 检测内部I2C,若不加此句为检测外部I2C 23 | Wire.begin(26, 32); 24 | Serial.println("M5Atom I2C Tester"); // Print a string on the screen. 25 | // 在屏幕上打印字符串 26 | delay(3000); 27 | } 28 | 29 | void loop() { 30 | int address; 31 | int error; 32 | Serial.printf("\nscanning Address [HEX]\n"); 33 | for (address = 1; address < 127; address++) { 34 | Wire.beginTransmission( 35 | address); // Data transmission to the specified device address 36 | // starts. 开始向指定的设备地址进行传输数据 37 | error = Wire.endTransmission(); /*Stop data transmission with the slave. 38 | 停止与从机的数据传输 0: success. 成功 1: The amount of data 39 | exceeds the transmission buffer capacity limit. 40 | 数据量超过传送缓存容纳限制 return value: 2: 41 | Received NACK when sending address. 传送地址时收到 NACK 3: 42 | Received NACK when transmitting data. 传送数据时收到 NACK 43 | 4: Other errors. 其它错误 */ 44 | if (error == 0) { 45 | Serial.print(address, HEX); 46 | Serial.print(" "); 47 | } else 48 | Serial.print("."); 49 | 50 | delay(10); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiScan/WiFiScan.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Wifi scan. wifi扫描 10 | * date:2021/7/28 11 | ******************************************************************************* 12 | */ 13 | #include 14 | #include "WiFi.h" 15 | 16 | void setup() { 17 | M5.begin(true, true, true); // Init M5Stack. 初始化M5Stack 18 | WiFi.mode(WIFI_STA); // Set WiFi to station mode and disconnect from an AP 19 | // if it was previously connected. 20 | // 将WiFi设置为站模式,如果之前连接过AP,则断开连接 21 | WiFi.disconnect(); // Turn off all wifi connections. 关闭所有wifi连接 22 | delay(100); // 100 ms delay. 延迟100ms 23 | M5.dis.drawpix(0, 0xfff000); // Light yellow. 点亮黄色 24 | Serial.println("\nPlease press Btn to scan"); 25 | } 26 | 27 | void loop() { 28 | M5.update(); // Check the status of the key. 检测按键的状态 29 | if (M5.Btn.isPressed()) { // If button A is pressed. 如果按键A按下 30 | Serial.println("scan start"); 31 | int n = WiFi.scanNetworks(); // return the number of networks found. 32 | // 返回发现的网络数 33 | if (n == 0) { // If no network is found. 如果没有找到网络 34 | Serial.println("no networks found"); 35 | M5.dis.fillpix(0xff0000); 36 | } else { // If have network is found. 找到网络 37 | M5.dis.fillpix(0x00ff00); 38 | Serial.printf("networks found:%d\n\n", n); 39 | for (int i = 0; i < n; 40 | ++i) { // Print SSID and RSSI for each network found. 41 | // 打印每个找到的网络的SSID和信号强度 42 | Serial.printf("%d:", i + 1); 43 | Serial.print(WiFi.SSID(i)); 44 | Serial.printf("(%d)", WiFi.RSSI(i)); 45 | Serial.println( 46 | (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*"); 47 | delay(10); 48 | } 49 | } 50 | delay(1000); 51 | Serial.println("\nPlease press Btn to rescan"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /examples/Unit/LCD_ST7789V2/LCD_ST7789V2.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: LCD. 显示屏 10 | * date:2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port,Displays a string on the Serial. 13 | 请连接端口,在串口上显示字符串。 14 | */ 15 | #include 16 | 17 | M5UnitLCD display; 18 | 19 | M5Canvas canvas(&display); 20 | 21 | static constexpr char text[] = 22 | "Hello world ! こんにちは世界! this is long long string sample. " 23 | "寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う" 24 | "寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、" 25 | "シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長" 26 | "久命の長助"; 27 | static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); 28 | int textpos = 0; 29 | int scrollstep = 2; 30 | 31 | void setup(void) { 32 | display.init(); // Initialize the display. 初始化显示屏 33 | display.setRotation(3); // Rotating display. 旋转显示屏 34 | canvas.setColorDepth(1); // Set the color depth. 设置色深 35 | canvas.setFont(&fonts::lgfxJapanMinchoP_32); // Set the font. 设置字体 36 | canvas.setTextSize(2); // Set the font size. 设置字号 37 | canvas.createSprite( 38 | display.width() + 64, 39 | 72); // Create a canvas with a wide display width of +64 and a height 40 | // of 72. 创建一块宽显示屏宽度+64,高72的画布 41 | } 42 | 43 | void loop(void) { 44 | int32_t cursor_x = canvas.getCursorX() - scrollstep; 45 | if (cursor_x <= 0) { 46 | textpos = 0; 47 | cursor_x = display.width(); 48 | } 49 | 50 | canvas.setCursor(cursor_x, 0); // Set the cursor position. 设置光标的位置 51 | canvas.scroll(-scrollstep, 0); // Set the rolling. 设置滚动 52 | while (textpos < textlen && cursor_x <= display.width()) { 53 | canvas.print(text[textpos++]); 54 | cursor_x = canvas.getCursorX(); 55 | } 56 | display.waitDisplay(); 57 | canvas.pushSprite( 58 | &display, 0, 59 | (display.height() - canvas.height()) >> 60 | 1); // Displays the contents of the canvas. 显示画布上的内容 61 | } -------------------------------------------------------------------------------- /examples/Basics/LEDSet/LEDSet.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | *information:https://docs.m5stack.com/en/core/atom_matrix 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/atom_matrix 9 | * 10 | * describe:RGB LED. 点阵示例 11 | * date:2021/7/21 12 | ******************************************************************************* 13 | */ 14 | #include "M5Atom.h" 15 | 16 | /* After Atom-Matrix is started or reset 17 | the program in the setUp () function will be run, and this part will only be run 18 | once. 在 ATOM-Matrix 19 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 20 | void setup() { 21 | M5.begin(true, false, 22 | true); // Init Atom-Matrix(Initialize serial port, LED). 初始化 23 | // ATOM-Matrix(初始化串口、LED点阵) 24 | delay(50); // delay 50ms. 延迟50ms 25 | M5.dis.drawpix(0, 0x00ff00); // Light the LED with the specified RGB color 26 | // 00ff00(Atom-Matrix has only one light). 27 | // 以指定RGB颜色0x00ff00点亮第0个LED 28 | } 29 | 30 | uint8_t FSM = 0; // Store the number of key presses. 存储按键按下次数 31 | 32 | /* After the program in setup() runs, it runs the program in loop() 33 | The loop() function is an infinite loop in which the program runs repeatedly 34 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 35 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 36 | void loop() { 37 | if (M5.Btn 38 | .wasPressed()) { // Check if the key is pressed. 检测按键是否被按下 39 | switch (FSM) { 40 | case 0: 41 | M5.dis.drawpix(0, 0xfff000); // YELLOW 黄色 42 | break; 43 | case 1: 44 | M5.dis.drawpix(0, 0xff0000); // RED 红色 45 | break; 46 | case 2: 47 | M5.dis.drawpix(0, 0x0000f0); // BLUE 蓝色 48 | break; 49 | case 3: 50 | M5.dis.drawpix(0, 0x00ff00); // GREEN 绿色 51 | break; 52 | default: 53 | break; 54 | } 55 | FSM++; 56 | if (FSM >= 4) { 57 | FSM = 0; 58 | } 59 | } 60 | 61 | delay(50); 62 | M5.update(); // Read the press state of the key. 读取按键按下状态 63 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiMulti/WiFiMulti.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:WIFI Multi. 多wifi择优 10 | * date:2021/7/29 11 | ******************************************************************************* 12 | * Connect to the best AP based on a given wifi list 13 | * 根据给定wifi的列表连接到最好的AP 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | WiFiMulti wifiMulti; 21 | 22 | void setup() { 23 | M5.begin(true, false, true); // Init Atom(Initialize serial port, LED). 24 | // 初始化 ATOM(初始化串口、LED) 25 | wifiMulti.addAP( 26 | "cam", 27 | "6767"); // Storage wifi configuration information 1. 存储wifi配置信息1 28 | wifiMulti.addAP("wifi1", "12345566"); 29 | wifiMulti.addAP("aaa", "sadf"); 30 | M5.dis.fillpix(0xfff000); // Light LED with the specified RGB color 31 | // 0xfff000(Atom-Matrix has only one light). 32 | // 以指定RGB颜色fff000点亮所有LED 33 | Serial.println("\n\nConnecting Wifi..."); // Serial port format output 34 | // string. 串口格式化输出字符串 35 | if (wifiMulti.run() == 36 | WL_CONNECTED) { // If the connection to wifi is established 37 | // successfully. 如果与wifi成功建立连接 38 | Serial.print("WiFi connected\n\nSSID:"); 39 | Serial.println(WiFi.SSID()); // Output Network name. 输出网络名称 40 | Serial.print("RSSI: "); 41 | Serial.println(WiFi.RSSI()); // Output signal strength. 输出信号强度 42 | Serial.print("IP address: "); 43 | Serial.println(WiFi.localIP()); // Output IP Address. 输出IP地址 44 | } 45 | } 46 | 47 | void loop() { 48 | if (wifiMulti.run() != 49 | WL_CONNECTED) { // If the connection to wifi is not established 50 | // successfully. 如果没有与wifi成功建立连接 51 | Serial.println("WiFi not connected!"); 52 | M5.dis.fillpix(0xff0000); 53 | delay(1000); 54 | } else { 55 | M5.dis.fillpix(0x00ff00); 56 | delay(1000); 57 | } 58 | } -------------------------------------------------------------------------------- /examples/Unit/WEIGHT_HX711/WEIGHT_HX711.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: Weight. 10 | * date:2021/8/20 11 | ******************************************************************************* 12 | Please connect to Port,Use WEIGHT Unit to read the analog value returned by 13 | the pressure sensor, convert it into intuitive weight data and send it to 14 | M5Core,Press ButtonA to calibrate 请连接端口,使用WEIGHT 15 | Unit读取压力传感器返回的模拟值,将其转换为直观的重量数据,发送到M5Core,按下按钮A进行校准 16 | */ 17 | 18 | #include 19 | #include "HX711.h" 20 | 21 | // HX711 related pin Settings. HX711 相关引脚设置 22 | #define LOADCELL_DOUT_PIN 32 23 | #define LOADCELL_SCK_PIN 26 24 | 25 | HX711 scale; 26 | const long LOADCELL_OFFSET = 50682624; 27 | const long LOADCELL_DIVIDER = 5895655; 28 | 29 | void setup() { 30 | M5.begin(); // Init M5Atom. 初始化M5Atom 31 | 32 | scale.begin( 33 | LOADCELL_DOUT_PIN, 34 | LOADCELL_SCK_PIN); // Initialize library with data output pin, clock 35 | // input pin and gain factor. 36 | // 初始化库的数据输出引脚,时钟输入引脚和增益因子。 37 | scale.set_scale( 38 | LOADCELL_DIVIDER); // set the SCALE value this value is used to convert 39 | // the raw data to measure units. 40 | // 设置SCALE值,该值用于将原始数据转换为度量单位 41 | scale.set_offset(LOADCELL_OFFSET); // Set the tare weight. 设置皮重 42 | scale.set_scale(61.2f); // this value is obtained by calibrating the scale 43 | // with known weights; see the README for details. 44 | // 这个值是通过校正已知权重的刻度而得到的 45 | scale.tare(); // reset the scale to 0. 将比例重置为0 46 | Serial.print("\nWeight Unit\nConnect the Weight Unit to PortB"); 47 | } 48 | 49 | void loop() { 50 | M5.update(); 51 | if (M5.Btn.wasPressed()) { // If button A is pressed. 如果按键A按下 52 | scale.set_offset(LOADCELL_OFFSET + scale.read()); 53 | scale.set_scale(61.2f); 54 | scale.tare(); 55 | } 56 | int weight = scale.get_units(5); 57 | Serial.printf("Weight:%1d g\n", weight); 58 | } -------------------------------------------------------------------------------- /examples/Advanced/EzData/EzData.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:EzData. 10 | * date:2021/10/23 11 | ******************************************************************************* 12 | */ 13 | 14 | #include "M5Atom.h" 15 | #include "M5_EzData.h" 16 | 17 | // Configure the name and password of the connected wifi and your token. 18 | // 配置所连接wifi的名称、密码以及你的token 19 | const char* ssid = "Explore-F"; 20 | const char* password = "xingchentansuo123"; 21 | const char* token = ""; 22 | 23 | void setup() { 24 | M5.begin(); // Initialize M5Stack 25 | if (setupWifi(ssid, password)) { // Connect to wifi. 连接到wifi 26 | Serial.printf("Success connecting to %s\n", ssid); 27 | } else { 28 | Serial.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 | setData(token, "testData", 20); 36 | delay(5000); 37 | 38 | // Save 3 data in sequence to the first place of testList. 依次保存3个数据至 39 | // testList首位 40 | for (int i = 0; i < 3; i++) { 41 | addToList(token, "testList", i); 42 | delay(100); 43 | } 44 | delay(5000); 45 | 46 | // Get a piece of data from a topic and store the value in result. 从一个 47 | // topic中获取一个数据,并将值存储在 result 48 | int result = 0; 49 | if (getData(token, "testData", result)) 50 | ; 51 | delay(5000); 52 | 53 | // Get a set of data from a list and store the values in the Array array. 54 | // 从一个 list中获取一组数据,并将值存储在 Array数组中 55 | int Array[3] = {}; 56 | if (getData(token, "testList", Array, 0, 3)) { 57 | Serial.print("Success get list\n"); 58 | for (int i = 0; i < 3; i++) { 59 | Serial.printf("Array[%d]=%d,", i, Array[i]); 60 | } 61 | Serial.println(""); 62 | } else { 63 | Serial.println("Fail to get data"); 64 | } 65 | delay(5000); 66 | 67 | // Remove data 68 | removeData(token, "testData"); 69 | removeData(token, "testList"); 70 | delay(5000); 71 | } -------------------------------------------------------------------------------- /examples/Advanced/HallSensor/HallSensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:Hall sensor. 霍尔传感器 10 | * date:2021/7/28 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 RANGE 320 20 | 21 | float HallOffset = 22 | 0; // Store the initial value of magnetic force. 存储磁力的初值 23 | float LowPassFilteredValue = 0; 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 | void setup() { 35 | M5.begin(); // Init M5Atom. 初始化M5Atom 36 | Serial.println("ESP32 Hall sensor:"); // Serial printout. 串口打印输出 37 | HallOffset = 38 | ESP32_hallRead(); // callibrate the output value to the magnetic field 39 | // at start up. 在启动时将输出值校准到磁场 40 | } 41 | 42 | void showSignal() { 43 | int n; 44 | for (n = 0; n < RANGE; 45 | n++) // Within the horizontal resolution, each pixel is drawn 46 | // according to the calculated magnetic force 47 | { // 在此范围内,根据计算得到的磁力大小 48 | float value = 49 | ESP32_hallRead() - HallOffset; // Reduce the influence of own 50 | // magnetism. 减少自身磁力的影响 51 | LowPassFilteredValue += (value - LowPassFilteredValue) * 0.05; 52 | Serial.printf("Low Pass Filtered Value:%d\n", 53 | (int)LowPassFilteredValue); 54 | if (n > 0) { 55 | Serial.printf("Magnetic value:%.2f\n\n", value); 56 | } 57 | } 58 | } 59 | 60 | void loop(void) { 61 | showSignal(); 62 | delay(200); 63 | } 64 | -------------------------------------------------------------------------------- /examples/Unit/OLED_SH1107/OLED_SH1107.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/oled 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/oled 8 | * 9 | * describe: OLED. 显示屏 10 | * date:2021/8/31 11 | ******************************************************************************* 12 | Please connect to Port A,Displays a string on the Serial. 13 | 请连接端口,在串口上显示字符串。 14 | */ 15 | #include 16 | 17 | M5UnitOLED display; 18 | 19 | M5Canvas canvas(&display); 20 | 21 | static constexpr char text[] = 22 | "Hello world ! こんにちは世界! this is long long string sample. " 23 | "寿限無、寿限無、五劫の擦り切れ、海砂利水魚の、水行末・雲来末・風来末、喰う" 24 | "寝る処に住む処、藪ら柑子の藪柑子、パイポ・パイポ・パイポのシューリンガン、" 25 | "シューリンガンのグーリンダイ、グーリンダイのポンポコピーのポンポコナの、長" 26 | "久命の長助"; 27 | static constexpr size_t textlen = sizeof(text) / sizeof(text[0]); 28 | int textpos = 0; 29 | int scrollstep = 2; 30 | 31 | void setup(void) { 32 | display.init(); // Initialize the display. 初始化显示屏 33 | display.setRotation(2); // Rotating display. 旋转显示屏 34 | canvas.setColorDepth(1); // Set the color depth. 设置色深 35 | canvas.setFont(&fonts::lgfxJapanMinchoP_32); // Set the font. 设置字体 36 | canvas.setTextWrap(false); 37 | canvas.setTextSize(2); // Set the font size. 设置字号 38 | canvas.createSprite( 39 | display.width() + 64, 40 | 72); // Create a canvas with a wide display width of +64 and a height 41 | // of 72. 创建一块宽显示屏宽度+64,高72的画布 42 | } 43 | 44 | void loop(void) { 45 | int32_t cursor_x = canvas.getCursorX() - scrollstep; 46 | if (cursor_x <= 0) { 47 | textpos = 0; 48 | cursor_x = display.width(); 49 | } 50 | 51 | canvas.setCursor(cursor_x, 0); // Set the cursor position. 设置光标的位置 52 | canvas.scroll(-scrollstep, 0); // Set the rolling. 设置滚动 53 | while (textpos < textlen && cursor_x <= display.width()) { 54 | canvas.print(text[textpos++]); 55 | cursor_x = canvas.getCursorX(); 56 | } 57 | display.waitDisplay(); 58 | canvas.pushSprite( 59 | &display, 0, 60 | (display.height() - canvas.height()) >> 61 | 1); // Displays the contents of the canvas. 显示画布上的内容 62 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/BasicHttpClient/BasicHttpClient.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:BasicHTTPClient. 10 | * date:2021/8/4 11 | ****************************************************************************** 12 | */ 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | WiFiMulti wifiMulti; 20 | HTTPClient http; 21 | 22 | void setup() { 23 | M5.begin(); // Init M5Atom. 初始化 M5Atom 24 | wifiMulti.addAP("M5-2.4G", 25 | "Office@888888"); // Storage wifi configuration 26 | // information. 存储wifi配置信息 27 | Serial.print("\nConnecting Wifi...\n"); // Serial port format output 28 | // string. 串口格式化输出字符串 29 | } 30 | 31 | void loop() { 32 | if ((wifiMulti.run() == 33 | WL_CONNECTED)) { // wait for WiFi connection. 等待连接至wifi 34 | Serial.print("[HTTP] begin...\n"); 35 | http.begin( 36 | "http://example.com/index.html"); // configure traged server and 37 | // url. 配置被跟踪的服务器和URL 38 | Serial.print("[HTTP] GET...\n"); 39 | int httpCode = http.GET(); // start connection and send HTTP header. 40 | // 开始连接服务器并发送HTTP的标头 41 | if (httpCode > 42 | 0) { // httpCode will be negative on error. 出错时httpCode将为负值 43 | Serial.printf("[HTTP] GET... code: %d\n", httpCode); 44 | 45 | if (httpCode == 46 | HTTP_CODE_OK) { // file found at server. 在服务器上找到文件 47 | String payload = http.getString(); 48 | Serial.println(payload); // 打印在服务器上读取的文件. Print 49 | // files read on the server 50 | } 51 | } else { 52 | Serial.printf("[HTTP] GET... failed, error: %s\n", 53 | http.errorToString(httpCode).c_str()); 54 | } 55 | 56 | http.end(); 57 | } else { 58 | Serial.print("connect failed"); 59 | } 60 | delay(5000); 61 | } 62 | -------------------------------------------------------------------------------- /examples/Advanced/Time/Time.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:NTP TIME. 10 | * date:2021/8/3 11 | *******************************************************************************/ 12 | #include 13 | #include 14 | #include "time.h" 15 | 16 | // Set the name and password of the wifi to be connected. 17 | // 配置所连接wifi的名称和密码 18 | const char* ssid = "M5"; 19 | const char* password = "123456"; 20 | 21 | const char* ntpServer = 22 | "time1.aliyun.com"; // Set the connect NTP server. 设置连接的NTP服务器 23 | const long gmtOffset_sec = 0; 24 | const int daylightOffset_sec = 3600; 25 | 26 | void printLocalTime() { // Output current time. 输出当前时间 27 | struct tm timeinfo; 28 | if (!getLocalTime(&timeinfo)) { // Return 1 when the time is successfully 29 | // obtained. 成功获取到时间返回1 30 | Serial.println("Failed to obtain time"); 31 | return; 32 | } 33 | Serial.println(&timeinfo, 34 | "%A, %B %d \n%Y %H:%M:%S"); // Serial port output date and 35 | // time. 串口输出日期和时间 36 | } 37 | 38 | void setup() { 39 | M5.begin(true, false, true); // Init Atom(Initialize serial port, LED). 40 | // 初始化 ATOM(初始化串口、LED) 41 | Serial.printf("\nConnecting to %s ", ssid); 42 | WiFi.begin(ssid, password); // Connect wifi and return connection status. 43 | // 连接wifi并返回连接状态 44 | M5.dis.fillpix(0xff0000); // Make the LED light show red. 使led灯显示红色 45 | while (WiFi.status() != 46 | WL_CONNECTED) { // If the wifi connection fails. 若wifi未连接成功 47 | delay(500); // delay 0.5s. 延迟0.5s 48 | Serial.print("."); 49 | } 50 | Serial.println(" CONNECTED"); 51 | configTime(gmtOffset_sec, daylightOffset_sec, 52 | ntpServer); // init and get the time. 初始化并设置NTP 53 | printLocalTime(); 54 | M5.dis.fillpix(0x00ff00); // Make the LED light green. 使led灯显示绿色 55 | WiFi.disconnect(true); // Disconnect wifi. 断开wifi连接 56 | WiFi.mode(WIFI_OFF); // Set the wifi mode to off. 设置wifi模式为关闭 57 | delay(20); 58 | } 59 | 60 | void loop() { 61 | delay(1000); 62 | printLocalTime(); 63 | } -------------------------------------------------------------------------------- /examples/Advanced/MultiTask/MultiTask.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:MultiTask. 多线程 10 | * date:2021/7/27 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | 16 | void task1(void* pvParameters) { // Define the tasks to be executed in 17 | // thread 1. 定义线程1内要执行的任务 18 | while (1) { // Keep the thread running. 使线程一直运行 19 | Serial.print("task1 Uptime (ms): "); 20 | Serial.println(millis()); // The running time of the serial port 21 | // printing program. 串口打印程序运行的时间 22 | delay( 23 | 100); // With a delay of 100ms, it can be seen in the serial 24 | // monitor that every 100ms, thread 1 will be executed once. 25 | // 延迟100ms,在串口监视器内可看到每隔100ms,线程1就会被执行一次 26 | } 27 | } 28 | 29 | void task2(void* pvParameters) { 30 | while (1) { 31 | Serial.print("task2 Uptime (ms): "); 32 | Serial.println(millis()); 33 | delay(200); 34 | } 35 | } 36 | 37 | void task3(void* pvParameters) { 38 | while (1) { 39 | Serial.print("task3 Uptime (ms): "); 40 | Serial.println(millis()); 41 | delay(1000); 42 | } 43 | } 44 | 45 | void setup() { 46 | M5.begin(true, false, true); // Init Atom(Initialize serial port, LED). 47 | // 初始化 ATOM(初始化串口、LED点阵) 48 | // Creat Task1. 创建线程1 49 | xTaskCreatePinnedToCore( 50 | task1, // Function to implement the task. 51 | // 线程对应函数名称(不能有返回值) 52 | "task1", // 线程名称 53 | 4096, // The size of the task stack specified as the number of * 54 | // bytes.任务堆栈的大小(字节) 55 | NULL, // Pointer that will be used as the parameter for the task * 56 | // being created. 创建作为任务输入参数的指针 57 | 1, // Priority of the task. 任务的优先级 58 | NULL, // Task handler. 任务句柄 59 | 0); // Core where the task should run. 将任务挂载到指定内核 60 | 61 | // Task 2 62 | xTaskCreatePinnedToCore(task2, "task2", 4096, NULL, 2, NULL, 0); 63 | 64 | // Task 3 65 | xTaskCreatePinnedToCore(task3, "task3", 4096, NULL, 3, NULL, 0); 66 | } 67 | 68 | void loop() { 69 | M5.dis.fillpix(0xFFA500); 70 | } -------------------------------------------------------------------------------- /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/OTAUpload/OTAUpload.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:OTA Upload. 隔空传输程序 10 | * date:2021/7/30 11 | ******************************************************************************* 12 | PC and M5Atom can only be used on the same wifi. 13 | 电脑和M5Atom需在同一wifi下才可使用 When the OTA is ready, restart the Arduino 14 | client from Tools > Ports > Network ports to instantly transmit the program 15 | wirelessly. OTA 准备好后重启Arduino客户端在工具->端口->网络端口,即刻无线传输程序 16 | */ 17 | #include 18 | #include 19 | #include 20 | 21 | // Set the name and password of the wifi to be connected. 22 | // 配置所连接wifi的名称和密码 23 | const char* ssid = "M5wifi"; 24 | const char* password = "2134123"; 25 | 26 | void setup() { 27 | M5.begin(true, false, true); // Init Atom(Initialize serial port, LED). 28 | // 初始化 ATOM(初始化串口、LED) 29 | M5.dis.fillpix( 30 | 0x00ff00); // Light LED with the specified RGB color F00000(Atom-Matrix 31 | // has only one light). 以指定RGB颜色00ff00点亮所有LED 32 | WiFi.begin(ssid, password); // Connect wifi and return connection status. 33 | // 连接wifi并返回连接状态 34 | while (WiFi.status() != 35 | WL_CONNECTED) { // If the wifi connection fails. 若wifi未连接成功 36 | delay(1000); 37 | Serial.print("."); 38 | } 39 | Serial.println("\nWiFi Connected!"); 40 | Serial.print("WiFi Connect To: "); 41 | Serial.println(WiFi.SSID()); // Output Network name. 输出网络名称 42 | Serial.print("IP address: "); 43 | Serial.println(WiFi.localIP()); // Output IP Address. 输出IP地址 44 | 45 | ArduinoOTA.setHostname( 46 | "M5Atom"); // Set the network port name. 设置网络端口名称 47 | ArduinoOTA.setPassword("666666"); // Set the network port connection 48 | // password. 设置网络端口连接的密码 49 | ArduinoOTA.begin(); // Initialize the OTA. 初始化OTA 50 | Serial.println("OTA ready!"); // Serial port output format string. 51 | // 串口输出格式化字符串 52 | } 53 | 54 | void loop() { 55 | ArduinoOTA.handle(); // Continuously check for update requests. 56 | // 持续检测是否有更新请求 57 | M5.update(); 58 | if (M5.Btn.isPressed()) { // if BtnA is Pressed. 如果按键A按下 59 | ArduinoOTA.end(); // Ends the ArduinoOTA service. 结束OTA服务 60 | Serial.println("OTA End!"); 61 | delay(200); 62 | } 63 | } -------------------------------------------------------------------------------- /examples/Basics/Button/Button.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | *information:https://docs.m5stack.com/en/core/atom_matrix 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/atom_matrix 9 | * 10 | * describe:Button example. 按键示例 11 | * date:2021/7/21 12 | ******************************************************************************* 13 | */ 14 | #include "M5Atom.h" 15 | 16 | uint8_t 17 | DisBuff[2 + 5 * 5 * 3]; // Used to store RBG color values. 用来存储RBG色值 18 | 19 | void setBuff(uint8_t Rdata, uint8_t Gdata, 20 | uint8_t Bdata) { // Set the colors of LED, and save the relevant 21 | // data to DisBuff[]. 设置RGB灯的颜色 22 | DisBuff[0] = 0x05; 23 | DisBuff[1] = 0x05; 24 | for (int i = 0; i < 25; i++) { 25 | DisBuff[2 + i * 3 + 0] = Rdata; 26 | DisBuff[2 + i * 3 + 1] = Gdata; 27 | DisBuff[2 + i * 3 + 2] = Bdata; 28 | } 29 | } 30 | /* After Atom-Matrix is started or reset 31 | the program in the setUp () function will be run, and this part will only be run 32 | once. 在 ATOM-Matrix 33 | 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */ 34 | void setup() { 35 | M5.begin(true, false, 36 | true); // Init Atom-Matrix(Initialize serial port, LED). 初始化 37 | // ATOM-Matrix(初始化串口、LED点阵) 38 | delay(10); // delay10ms. 延迟10ms 39 | setBuff(0xff, 0x00, 0x00); 40 | M5.dis.displaybuff( 41 | DisBuff); // Display the DisBuff color on the LED. 同步所设置的颜色 42 | } 43 | 44 | uint8_t FSM = 0; // Store the number of key presses. 存储按键按下次数 45 | 46 | /* After the program in setup() runs, it runs the program in loop() 47 | The loop() function is an infinite loop in which the program runs repeatedly 48 | 在setup()函数中的程序执行完后,会接着执行loop()函数中的程序 49 | loop()函数是一个死循环,其中的程序会不断的重复运行 */ 50 | void loop() { 51 | if (M5.Btn 52 | .wasPressed()) { // Check if the key is pressed. 检测按键是否被按下 53 | switch (FSM) { 54 | case 0: 55 | setBuff(0x40, 0x00, 0x00); 56 | break; 57 | case 1: 58 | setBuff(0x00, 0x40, 0x00); 59 | break; 60 | case 2: 61 | setBuff(0x00, 0x00, 0x40); 62 | break; 63 | case 3: 64 | setBuff(0x20, 0x20, 0x20); 65 | break; 66 | default: 67 | break; 68 | } 69 | M5.dis.displaybuff(DisBuff); 70 | 71 | FSM++; 72 | if (FSM >= 4) { 73 | FSM = 0; 74 | } 75 | } 76 | delay(50); 77 | M5.update(); // Read the press state of the key. 读取按键按下状态 78 | } -------------------------------------------------------------------------------- /examples/Unit/KEY/KEY.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2022 by M5Stack 4 | * Equipped with M5Stack ATOM sample source code 5 | * 配套 M5Stack ATOM 示例源代码 6 | * Visit the website for more information: 7 | * 获取更多资料请访问: 8 | * 9 | * Please follow the steps below to add FastLED library: 10 | * - Arduino menu --> Manage Libraries... --> FastLED --> install 11 | * 在烧录前请按以下步骤添加 FastLED 库: 12 | * - Arduino menu --> Manage Libraries... --> FastLED --> install 13 | * 14 | * describe: UNIT-KEY example 15 | * date: 2022/6/1 16 | ******************************************************************************* 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | uint8_t ledColor = 0; 23 | 24 | #define KEY_PIN 32 // Define Key Pin. 定义Key引脚 25 | #define DATA_PIN 26 // Define LED pin. 定义LED引脚. 26 | CRGB leds[1]; // Define the array of leds. 定义LED阵列. 27 | 28 | void LED(void *parameter); 29 | void changeLedColor(); 30 | 31 | void setup() { 32 | M5.begin(); // Init M5Stack 初始化M5Stack 33 | 34 | pinMode(KEY_PIN, INPUT_PULLUP); // Init Key pin. 初始化Key引脚. 35 | 36 | FastLED.addLeds(leds, 37 | 1); // Init FastLED. 初始化FastLED. 38 | 39 | xTaskCreate( 40 | LED, "led", 1000, NULL, 0, 41 | NULL); // Create a thread for breathing LED. 创建一个线程用于LED呼吸灯. 42 | } 43 | 44 | void loop() { 45 | if (!digitalRead(KEY_PIN)) { // If Key was pressed. 如果按键按下. 46 | changeLedColor(); // Change LED color. 更换LED呼吸灯颜色. 47 | while (!digitalRead( 48 | KEY_PIN)) // Hold until the key released. 在松开按键前保持状态. 49 | ; 50 | } 51 | delay(100); 52 | } 53 | 54 | void LED(void *parameter) { 55 | leds[0] = CRGB::Red; 56 | for (;;) { 57 | for (int i = 0; i < 255; 58 | i++) { // Set LED brightness from 0 to 255. 设置LED亮度从0到255. 59 | FastLED.setBrightness(i); 60 | FastLED.show(); 61 | delay(5); 62 | } 63 | for (int i = 255; i > 0; 64 | i--) { // Set LED brightness from 255 to 0. 设置LED亮度从255到0. 65 | FastLED.setBrightness(i); 66 | FastLED.show(); 67 | delay(5); 68 | } 69 | } 70 | vTaskDelete(NULL); 71 | } 72 | 73 | void changeLedColor() { 74 | ledColor++; 75 | if (ledColor > 2) ledColor = 0; 76 | switch ( 77 | ledColor) { // Change LED colors between R,G,B. 在红绿蓝中切换LED颜色. 78 | case 0: 79 | leds[0] = CRGB::Red; 80 | break; 81 | case 1: 82 | leds[0] = CRGB::Green; 83 | break; 84 | case 2: 85 | leds[0] = CRGB::Blue; 86 | break; 87 | default: 88 | break; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /examples/Unit/ADC_ADS1100/ADC_ADS1100.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe: ADC. A/D转换器 10 | * date:2021/8/18 11 | ******************************************************************************* 12 | Please connect to Port A,Use ADC Unit to convert 0 ~ 12V analog voltage into 13 | 16-bit data and display it on the Serial. 请连接端口,利用ADC单元将0 ~ 14 | 12V模拟电压转换成16位数据显示在串口上。 15 | */ 16 | 17 | #include 18 | #include "M5_ADS1100.h" 19 | 20 | ADS1100 ads; 21 | 22 | void setup(void) { 23 | M5.begin(); // Init M5Atom. 初始化M5Atom 24 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 25 | 26 | // The address can be changed making the option of connecting multiple 27 | // devices 地址可以改变,以连接多个设备 28 | ads.getAddr_ADS1100( 29 | ADS1100_DEFAULT_ADDRESS); // 0x48, 1001 000 (ADDR = GND) 30 | 31 | // The ADC gain (PGA). ADC增益(PGA) 32 | ads.setGain(GAIN_ONE); // 1x gain(default) 33 | // ads.setGain(GAIN_TWO); // 2x gain 34 | // ads.setGain(GAIN_FOUR); // 4x gain 35 | // ads.setGain(GAIN_EIGHT); // 8x gain 36 | 37 | // Device operating mode. 设备工作模式 38 | ads.setMode(MODE_CONTIN); // Continuous conversion mode (default) 39 | // ads.setMode(MODE_SINGLE); // Single-conversion mode 40 | 41 | // Data rate. 数据速率 42 | ads.setRate(RATE_8); // 8SPS (default) 43 | // ads.setRate(RATE_16); // 16SPS 44 | // ads.setRate(RATE_32); // 32SPS 45 | // ads.setRate(RATE_128); // 128SPS 46 | 47 | ads.setOSMode( 48 | OSMODE_SINGLE); // Set to start a single-conversion. 设置开始一次转换 49 | 50 | ads.begin(); // Sets up the Hardware. 设置硬件 51 | } 52 | 53 | void loop(void) { 54 | byte error; 55 | int8_t address; 56 | 57 | address = ads.ads_i2cAddress; 58 | 59 | Wire.beginTransmission(address); 60 | error = Wire.endTransmission(); 61 | if (error == 0) // If the device is connected. 如果连接上设备 62 | { 63 | int16_t result; 64 | 65 | Serial.println("Getting Differential Reading from ADS1100"); 66 | Serial.println(" "); 67 | result = ads.Measure_Differential(); 68 | Serial.print("Digital Value of Analog Input between Channel 0 and 1: "); 69 | Serial.println(result); 70 | char data[20] = {0}; 71 | sprintf(data, "%d", result); 72 | Serial.println("-----------"); 73 | } else { 74 | Serial.println("ADS1100 Disconnected!"); 75 | Serial.println("-----------"); 76 | } 77 | 78 | delay(1000); 79 | } -------------------------------------------------------------------------------- /examples/Unit/4-RELAY/4-RELAY.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/4relay 7 | * 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/4relay 8 | * 9 | * Product: Unit 4RELAY. 10 | * Date: 2022/7/22 11 | ******************************************************************************* 12 | Please connect to port ,Control 4 relays and demonstrate the asynchronous 13 | control relay LED 请连接端口,控制4继电器,并演示异步控制继电器LED 14 | ------------------------------------------------------------------------------- 15 | RELAY control reg | 0x10 16 | ----------------------------------------------------------------------------- 17 | Relay_ctrl_mode_reg[0] | R/W | System control 18 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 19 | | R | R | R | R | R | R | R | Sync Mode | 20 | | -Sync Mode:0 LED&Relay Async 21 | | -Sync Mode:1 LED&Relay Sync 22 | --------------------------------------------------------------------------------- 23 | Relay_ctrl_mode_reg[1] | R/W | Relay & LED control 24 | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 25 | | LED1| LED2| LED3| LED4| RLY1| RLY2| RLY3| RLY4| 26 | -------------------------------------------------------------------------------*/ 27 | // Note: The relay can only be controlled in synchronous mode, if the relay is 28 | // controlled in asynchronous mode, it will be invalid. 29 | // 注意:只能在同步模式下控制继电器,如果在异步模式下对继电器进行控制将无效,. 30 | 31 | #include 32 | #include "Unit_4RELAY.h" 33 | 34 | UNIT_4RELAY relay; 35 | 36 | void setup() { 37 | M5.begin(); // Init M5Atom. 初始化 M5Atom 38 | Serial.print(relay.begin(&Wire, 26, 32)); 39 | relay.Init(1); // Set the lamp and relay to synchronous mode(Async = 40 | // 0,Sync = 1). 将灯和继电器设为同步模式 41 | Serial.printf("Please pressed Btn. \n"); 42 | relay.relayAll(0); 43 | } 44 | 45 | char count_i = 0; 46 | 47 | void loop() { 48 | relay.relayAll(1); 49 | delay(1000); 50 | relay.relayAll(0); 51 | delay(1000); 52 | 53 | if (M5.Btn.wasPressed()) { // If button A is pressed. 如果按键A按下 54 | if ((count_i < 4)) { // Control relays turn on/off in sequence. 55 | // 控制继电器依次接通/断开 56 | Serial.printf("%d ON\n", count_i); 57 | relay.relayWrite(count_i, 1); 58 | } else if ((count_i >= 4)) { 59 | Serial.printf("%d OFF\n", (count_i - 4)); 60 | relay.relayWrite((count_i - 4), 0); 61 | } 62 | count_i++; 63 | if (count_i >= 8) count_i = 0; 64 | } 65 | M5.update(); 66 | } -------------------------------------------------------------------------------- /examples/Unit/CAN/CAN_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @section License 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2017, Thomas Barth, barth-dev.de 7 | * 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, copy, 12 | * modify, merge, publish, distribute, sublicense, and/or sell copies 13 | * of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be 17 | * included in all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | */ 28 | 29 | #ifndef __DRIVERS_CAN_CFG_H__ 30 | #define __DRIVERS_CAN_CFG_H__ 31 | 32 | #include "freertos/FreeRTOS.h" 33 | #include "freertos/queue.h" 34 | #include "freertos/task.h" 35 | #include "driver/gpio.h" 36 | #include "freertos/semphr.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** \brief CAN Node Bus speed */ 43 | typedef enum { 44 | CAN_SPEED_100KBPS = 100, /**< \brief CAN Node runs at 100kBit/s. */ 45 | CAN_SPEED_125KBPS = 125, /**< \brief CAN Node runs at 125kBit/s. */ 46 | CAN_SPEED_200KBPS = 200, /**< \brief CAN Node runs at 250kBit/s. */ 47 | CAN_SPEED_250KBPS = 250, /**< \brief CAN Node runs at 250kBit/s. */ 48 | CAN_SPEED_500KBPS = 500, /**< \brief CAN Node runs at 500kBit/s. */ 49 | CAN_SPEED_800KBPS = 800, /**< \brief CAN Node runs at 800kBit/s. */ 50 | CAN_SPEED_1000KBPS = 1000 /**< \brief CAN Node runs at 1000kBit/s. */ 51 | } CAN_speed_t; 52 | 53 | /** \brief CAN configuration structure */ 54 | typedef struct { 55 | CAN_speed_t speed; /**< \brief CAN speed. */ 56 | gpio_num_t tx_pin_id; /**< \brief TX pin. */ 57 | gpio_num_t rx_pin_id; /**< \brief RX pin. */ 58 | QueueHandle_t rx_queue; /**< \brief Handler to FreeRTOS RX queue. */ 59 | QueueHandle_t tx_queue; /**< \brief Handler to FreeRTOS TX queue. */ 60 | TaskHandle_t tx_handle; /**< \brief Handler to FreeRTOS TX task. */ 61 | TaskHandle_t rx_handle; /**< \brief Handler to FreeRTOS RX task. */ 62 | } CAN_device_t; 63 | 64 | /** \brief CAN configuration reference */ 65 | extern CAN_device_t CAN_cfg; 66 | 67 | #ifdef __cplusplus 68 | } 69 | #endif 70 | 71 | #endif /* __DRIVERS_CAN_CFG_H__ */ 72 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiSmartConfig/WiFiSmartConfig.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:WIFI Smart Config. WIFI智能配网 10 | * date:2021/7/30 11 | ******************************************************************************* 12 | * Fill in WIFI configuration information through mobile APP to connect M5Atom 13 | *to relevant WIFI 通过手机APP填写WIFI配置信息使 M5Atom连接至相关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(true, false, true); // Init Atom(Initialize serial port, LED). 23 | // 初始化 ATOM(初始化串口、LED) 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 | M5.dis.fillpix( 30 | 0xfff000); // Light LED with the specified RGB color F00000(Atom-Matrix 31 | // has only one light). 以指定RGB颜色fff000点亮所有LED 32 | // Wait for the M5Atom to receive network information from the phone 33 | // 等待M5Atom接收到来自手机的配网信息 34 | Serial.print( 35 | "\nWaiting for Phone SmartConfig."); // Serial port format output 36 | // string. 串口格式化输出字符串 37 | while (!WiFi.smartConfigDone()) { // If the smart network is not completed. 38 | // 若智能配网没有完成 39 | delay(500); 40 | Serial.print("."); 41 | } 42 | Serial.println("\nSmartConfig received."); 43 | 44 | Serial.println("Waiting for WiFi\n"); 45 | while ( 46 | WiFi.status() != 47 | WL_CONNECTED) { // M5Atom will connect automatically upon receipt of 48 | // the configuration information, and return true if 49 | // the connection is successful. 50 | // 收到配网信息后M5Atom将自动连接,若连接成功将返回true 51 | delay(500); 52 | Serial.print("."); 53 | } 54 | M5.dis.fillpix(0x00ff00); 55 | Serial.print("WiFi Connect To: "); 56 | Serial.println(WiFi.SSID()); // Output Network name. 输出网络名称 57 | Serial.print("IP address: "); 58 | Serial.println(WiFi.localIP()); // Output IP Address. 输出IP地址 59 | Serial.print("RSSI: "); 60 | Serial.println(WiFi.RSSI()); // Output signal strength. 输出信号强度 61 | } 62 | 63 | void loop() { 64 | } -------------------------------------------------------------------------------- /examples/Unit/COLOR_TCS3472/COLOR_TCS3472.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:COLOR_TCS3472. 颜色识别 10 | * date:2021/8/11 11 | ******************************************************************************* 12 | Please connect to Port ,Use COLOR Unit to read C, R, G, B values 13 | 请连接端口,使用COLOR Unit读取C, R, G, B值 14 | */ 15 | 16 | #include 17 | #include "Adafruit_TCS34725.h" 18 | 19 | #define commonAnode \ 20 | true // set to false if using a common cathode LED. 21 | // //如果使用普通阴极LED,则设置为false 22 | 23 | byte gammatable[256]; // our RGB -> eye-recognized gamma color 24 | 25 | static uint16_t color16(uint16_t r, uint16_t g, uint16_t b) { 26 | uint16_t _color; 27 | _color = (uint16_t)(r & 0xF8) << 8; 28 | _color |= (uint16_t)(g & 0xFC) << 3; 29 | _color |= (uint16_t)(b & 0xF8) >> 3; 30 | return _color; 31 | } 32 | 33 | Adafruit_TCS34725 tcs = 34 | Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X); 35 | 36 | void setup() { 37 | M5.begin(); // Init M5Atom. 初始化 M5Atom 38 | Wire.begin(26, 32); // Initialize pin 26,32. 初始化26,32引脚 39 | Serial.println("Color View Test!"); 40 | while (!tcs.begin()) { // 如果color unit未能初始化 41 | Serial.println("No TCS34725 found ... check your connections"); 42 | delay(1000); 43 | } 44 | tcs.setIntegrationTime( 45 | TCS34725_INTEGRATIONTIME_154MS); // Sets the integration time for the 46 | // TC34725. 设置TC34725的集成时间 47 | tcs.setGain(TCS34725_GAIN_4X); // Adjusts the gain on the TCS34725. 48 | // 调整TCS34725上的增益 49 | } 50 | 51 | void loop() { 52 | uint16_t clear, red, green, blue; 53 | tcs.getRawData(&red, &green, &blue, 54 | &clear); // Reads the raw red, green, blue and clear channel 55 | // values. 读取原始的红、绿、蓝和清晰的通道值 56 | 57 | // Figure out some basic hex code for visualization. 生成对应的十六进制代码 58 | uint32_t sum = clear; 59 | float r, g, b; 60 | r = red; 61 | r /= sum; 62 | g = green; 63 | g /= sum; 64 | b = blue; 65 | b /= sum; 66 | r *= 256; 67 | g *= 256; 68 | b *= 256; 69 | uint16_t _color = color16((int)r, (int)g, (int)b); 70 | 71 | Serial.print("C:"); 72 | Serial.println(clear); 73 | Serial.print("R:"); 74 | Serial.println(red); 75 | Serial.print("G:"); 76 | Serial.println(green); 77 | Serial.print("B:"); 78 | Serial.println(blue); 79 | Serial.print("0x"); 80 | Serial.print((int)r, HEX); 81 | Serial.print((int)g, HEX); 82 | Serial.println((int)b, HEX); 83 | Serial.println(""); 84 | delay(1000); 85 | } 86 | -------------------------------------------------------------------------------- /examples/Advanced/Storage/SPIFFS/SPIFFS_Add/SPIFFS_Add.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:SPIFFS Add(Write is to clean up the contents of the file and write 10 | *it again.). 向SPIFFS中添加信息(write是将文件内容完全清除重新写) date:2021/8/4 11 | ****************************************************************************** 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | String file_name = 18 | "/M5Stack/notes.txt"; // Sets the location and name of the file to be 19 | // operated on. 设置被操作的文件位置和名称 20 | 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(); // Init M5Atom. 初始化 M5ATOM 27 | if (SPIFFS_FORMAT) { 28 | Serial.println( 29 | "\nSPIFFS format start..."); // Serial port output format String. 30 | // 串口输出格式化字符串 31 | SPIFFS.format(); // Formatting SPIFFS. 格式化SPIFFS 32 | Serial.println("SPIFFS format finish"); 33 | } 34 | if (SPIFFS.begin()) { // Start SPIFFS, return 1 on success. 35 | // 启动闪存文件系统,若成功返回1 36 | Serial.println("\nSPIFFS Started."); 37 | } else { 38 | Serial.println("SPIFFS Failed to Start."); 39 | } 40 | 41 | if (SPIFFS.exists( 42 | file_name)) { // Check whether the file_name file exists in the 43 | // flash memory. 确认闪存中是否有file_name文件 44 | Serial.println("FOUND."); 45 | Serial.println(file_name); 46 | 47 | File dataFile = SPIFFS.open( 48 | file_name, 49 | "a"); // Create a File object dafaFile to add information to 50 | // file_name in the SPIFFS. 51 | // 建立File对象dafaFile用于向SPIFFS中的file_name添加信息 52 | dataFile.println( 53 | "This is Appended Info."); // Adds string information to dataFile. 54 | // 向dataFile添加字符串信息 55 | dataFile.close(); // Close the file when writing is complete. 56 | // 完成写入后关闭文件 57 | Serial.println("Finished Appending data to SPIFFS"); 58 | } else { 59 | Serial.println("NOT FOUND."); 60 | Serial.print(file_name); 61 | Serial.println("is creating."); 62 | File dataFile = SPIFFS.open( 63 | file_name, 64 | "w"); // Create aFile object dafaFile to write information to 65 | // file_name in the SPIFFS. 66 | // 建立File对象dafaFile用于向SPIFFS中的file_name写入信息 67 | dataFile.close(); // Close the file when writing is complete. 68 | // 完成写入后关闭文件 69 | Serial.println("Please disable format and Reupload"); 70 | } 71 | } 72 | 73 | void loop() { 74 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ATOM Library 2 | 3 | English | [中文](README_cn.md) 4 | 5 | M5Atom U 6 | 7 | ## Description 8 | 9 | **ATOM U** is a compact low-power consumption speech recognition IoT development kit. It adopts an ESP32 chipset, equipped with 2 low-power Xtensa 32-bit LX6 microprocessors with the main frequency of up to 240MHz. Built-in USB-A interface, IR emitter, programmable RGB LED. Plug-and-play, easy to upload and download programs. Integrated `Wi-Fi` and `Bluetooth` modes and digital microphone SPM1423(I2S) for the clear sound record. suitable for HMI, Speech-to-Text (STT). 10 | 11 | - LOW-CODE DEVELOPMENT: 12 | - ATOM U supports UIFlow graphical programming platform, scripting-free, cloud push; 13 | Fully compatible with Arduino, MicroPython, ESP32-IDF, and other mainstream development platforms, to quickly build various applications. 14 | 15 | - HIGH INTEGRATION: 16 | - ATOM U contains a USB-A port for programming/power supply, IR emitter, programmable RGB LED x1, button x1; 17 | Finely tuned RF circuit, providing stable and reliable wireless communication. 18 | 19 | - STRONG EXPANDABILITY: 20 | - ATOM U is easy access to M5Stack's hardware and software system 21 | 22 | ## Product Features 23 | 24 | - ESP32-PICO-D4 (2.4GHz Wi-Fi and Bluetooth dual mode) 25 | - Integrated programmable RGB LED and button 26 | - Compact design 27 | - Built-in IR emitter 28 | - Expandable pinout and GROVE port 29 | - Development platform: 30 | - [UIFlow](http://flow.m5stack.com) 31 | - [MicroPython](http://micropython.org/) 32 | - [Arduino](http://www.arduino.cc) 33 | 34 | ## Application 35 | 36 | - IoT controller 37 | - Voice recording, Speech-to-Text services 38 | 39 | ## Driver Installation 40 | 41 | Connect the device to the PC, open the device manager to install [FTDI driver](https://ftdichip.com/drivers/vcp-drivers/) for the device. Take the win10 environment as an example, download the driver file that matches the operating system, unzip it, and install it through the device manager. (Note: In some system environments, the driver needs to be installed twice for the driver to take effect. The unrecognized device name is usually `M5Stack` or `USB Serial`. Windows recommends using the driver file to install directly in the device manager (custom Update), the executable file installation method may not work properly). [Click here to download FTDI driver](https://ftdichip.com/drivers/vcp-drivers/) 42 | 43 | ## PinMap 44 | 45 | - SPM1423 - I2S 46 | 47 | | M5Core | G5 | G19 | 3.3V | GND | 48 | | ------- | ------- | -------- | ---- | --- | 49 | | SPM1423 | MIC_CLK | MIC_DATA | VCC | GND | 50 | 51 | - IR & SK6812 & BUTTON 52 | 53 | | M5Core | G12 | G27 | G39 | 54 | | ------ | --- | --- | --- | 55 | | IR | TX | / | / | 56 | | SK6812 | / | DIN | / | 57 | | BUTTON | / | / | SW | 58 | 59 | ## More Inoformation 60 | 61 | **UIFlow Quick Start**: [Click Here](https://docs.m5stack.com/en/quick_start/atom_u/uiflow) 62 | 63 | **MicroPython API**: [Click Here](https://docs.m5stack.com/en/quick_start/atom_u/mpy) 64 | 65 | **Arduino IDE Development**: [Click Here](https://docs.m5stack.com/en/quick_start/atom_u/arduino) 66 | -------------------------------------------------------------------------------- /examples/Unit/AMeter_ADS1115/AMeter_ADS1115.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit for more information:https://docs.m5stack.com/en/unit/ameter 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/ameter 8 | * 9 | * Product: Ameter_ADS1115. 电流计 10 | * Date: 2022/7/11 11 | ******************************************************************************* 12 | This example can be used to calibrate a device. 13 | 此示例可用来校准设备. 14 | Please connect to Port ,Measure current and display. 15 | 请连接端口,测量电流并显示到串口上 16 | Pay attention: EEPROM (0x51) has built-in calibration parameters when leaving 17 | the factory. Please do not write to the EEPROM, otherwise the calibration data 18 | will be overwritten and the measurement results will be inaccurate. 注意: EEPROM 19 | (0x51)在出厂时具有内置的校准参数。请不要写入EEPROM,否则校准数据会被覆盖,测量结果会不准确。 20 | */ 21 | 22 | #include 23 | #include "M5_ADS1115.h" 24 | 25 | ADS1115 Ammeter(AMETER, AMETER_ADDR, AMETER_EEPROM_ADDR); 26 | 27 | float pgae512_volt = 2000.0F; 28 | 29 | int16_t volt_raw_list[10]; 30 | uint8_t raw_now_ptr = 0; 31 | int16_t adc_raw = 0; 32 | 33 | int16_t hope = 0.0; 34 | 35 | ADS1115Gain_t now_gain = PGA_512; 36 | 37 | void setup(void) { 38 | M5.begin(); // Init M5Atom. 初始化M5Atom 39 | Wire.begin(); 40 | 41 | Ammeter.setMode(SINGLESHOT); 42 | Ammeter.setRate(RATE_8); 43 | Ammeter.setGain(PGA_512); 44 | hope = pgae512_volt / Ammeter.resolution; 45 | // | PGA | Max Input Voltage(V) | 46 | // | PGA_6144 | 128 | 47 | // | PGA_4096 | 64 | 48 | // | PGA_2048 | 32 | 49 | // | PGA_512 | 16 | 50 | // | PGA_256 | 8 | 51 | 52 | Serial.printf("2A"); 53 | } 54 | 55 | void loop(void) { 56 | M5.update(); // Check the status of the key. 检测按键的状态 57 | if (M5.Btn.wasPressed()) { 58 | Ammeter.setMode(SINGLESHOT); // Set the mode. 设置模式 59 | Ammeter.setRate(RATE_8); // Set the rate. 设置速率 60 | Ammeter.setGain(PGA_512); 61 | now_gain = PGA_512; 62 | hope = pgae512_volt / Ammeter.resolution; 63 | 64 | for (uint8_t i = 0; i < 10; i++) { 65 | volt_raw_list[i] = 0; 66 | } 67 | } 68 | 69 | float current = Ammeter.getValue(); 70 | 71 | volt_raw_list[raw_now_ptr] = Ammeter.adc_raw; 72 | raw_now_ptr = (raw_now_ptr == 9) ? 0 : (raw_now_ptr + 1); 73 | 74 | int count = 0; 75 | int total = 0; 76 | 77 | for (uint8_t i = 0; i < 10; i++) { 78 | if (volt_raw_list[i] == 0) { 79 | continue; 80 | } 81 | total += volt_raw_list[i]; 82 | count += 1; 83 | } 84 | 85 | if (count == 0) { 86 | adc_raw = 0; 87 | } else { 88 | adc_raw = total / count; 89 | } 90 | 91 | Serial.printf("Hope volt:%.2f mAn\n", pgae512_volt); 92 | 93 | Serial.printf("Cal volt:%.2f mA\n", current); 94 | 95 | Serial.printf("Cal ADC:%.0f\n", adc_raw * Ammeter.calibration_factor); 96 | 97 | Serial.printf("RAW ADC:%d\n\n", adc_raw); 98 | } -------------------------------------------------------------------------------- /examples/Unit/VMeter_ADS1115/VMeter_ADS1115.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit for more information: https://docs.m5stack.com/en/unit/vmeter 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/vmeter 8 | * 9 | * Product: Vmeter_ADS1115. 10 | * Date: 2022/7/11 11 | ******************************************************************************* 12 | Please connect to Port,Measure voltage and display in the serial. 13 | 请连接端口,测量电压并显示到串口 14 | Pay attention: EEPROM (0x53) has built-in calibration parameters when leaving 15 | the factory. Please do not write to the EEPROM, otherwise the calibration data 16 | will be overwritten and the measurement results will be inaccurate. 17 | 注意:EEPROM在出厂时具有内置的校准参数。请不要写入EEPROM,否则校准数据会被覆盖,测量结果会不准确。 18 | */ 19 | 20 | #include "M5Atom.h" 21 | #include 22 | #include "M5_ADS1115.h" 23 | #include "title.h" 24 | #include "shut.h" 25 | 26 | ADS1115 voltmeter; 27 | 28 | float pgae512_volt = 5000.0F; 29 | float pgae4096_volt = 60000.0F; 30 | 31 | int16_t volt_raw_list[10]; 32 | uint8_t raw_now_ptr = 0; 33 | int16_t adc_raw = 0; 34 | 35 | int16_t hope = 0.0; 36 | uint8_t voltage_change = 0; 37 | 38 | ADS1115Gain_t now_gain = PGA_512; 39 | 40 | int x = 0; 41 | int xt = 0; 42 | int value = 0; 43 | 44 | int bright[4] = {30, 60, 100, 200}; 45 | int b = 1; 46 | bool d = 0; 47 | 48 | void setup() { 49 | M5.begin(); 50 | Wire.begin(26, 32); 51 | 52 | voltmeter.setMode(SINGLESHOT); 53 | voltmeter.setRate(RATE_128); 54 | voltmeter.setGain(PGA_512); 55 | } 56 | 57 | void loop(void) { 58 | M5.update(); 59 | 60 | voltmeter.getValue(); 61 | 62 | volt_raw_list[raw_now_ptr] = voltmeter.adc_raw; 63 | raw_now_ptr = (raw_now_ptr == 9) ? 0 : (raw_now_ptr + 1); 64 | 65 | int count = 0; 66 | int total = 0; 67 | 68 | for (uint8_t i = 0; i < 10; i++) { 69 | if (volt_raw_list[i] == 0) { 70 | continue; 71 | } 72 | total += volt_raw_list[i]; 73 | count += 1; 74 | } 75 | 76 | if (count == 0) { 77 | adc_raw = 0; 78 | } else { 79 | adc_raw = total / count; 80 | } 81 | 82 | value = adc_raw * voltmeter.resolution * voltmeter.calibration_factor; 83 | 84 | if (d == 0) 85 | Serial.printf("%.2f \r\n", ( 86 | 87 | adc_raw * voltmeter.resolution * 88 | voltmeter.calibration_factor) / 89 | 1000); 90 | if (d == 1) 91 | Serial.printf("%.3f \r\n", (adc_raw * voltmeter.resolution * 92 | voltmeter.calibration_factor) / 93 | 1000); 94 | 95 | Serial.print( 96 | String(adc_raw * voltmeter.resolution * voltmeter.calibration_factor)); 97 | Serial.printf("ADC:%s", String(adc_raw)); 98 | 99 | if (value < 0) value = value * -1; 100 | 101 | x = map(value, 0, 32000, 16, 304); 102 | 103 | if (M5.Btn.wasPressed()) d = !d; 104 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/mDNS_Find/mDNS_Find.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:announcing & finding services. 广播&查找服务 10 | * date:2021/8/3 11 | ******************************************************************************* 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | // Set the name and password of the wifi to be connected. 19 | // 配置所连接wifi的名称和密码 20 | const char* ssid = "M5"; 21 | const char* password = "213@123"; 22 | 23 | void browseService(const char* service, 24 | const char* proto) { // find devices. 查找设备 25 | Serial.printf("Browsing for service _%s._%s.local. ... ", service, proto); 26 | int n = 27 | MDNS.queryService(service, proto); // Store the number of devices found 28 | // in n. 将找到的设备数存储在n中 29 | if (n == 0) { // if don't have any devices. 如果没有任何设备 30 | Serial.println("no services found"); 31 | } else { 32 | Serial.printf("%d service(s) found\n", n); 33 | for (int i = 0; i < n; 34 | ++i) { // Print details for each service found. 打印每个找到的设备 35 | Serial.printf(" %d: ", i + 1); 36 | Serial.print( 37 | MDNS.hostname(i)); // output the devies name. 输出设备名称 38 | Serial.print(" "); 39 | Serial.print( 40 | MDNS.IP(i)); // Output the devices IP Address. 输出设备的IP地址 41 | Serial.printf( 42 | ":%d\n", 43 | MDNS.port(i)); // output the devices port. 输出设备的端口号 44 | } 45 | } 46 | Serial.println(); 47 | } 48 | 49 | void setup() { 50 | M5.begin(); // Init Atom. 初始化 ATOM 51 | WiFi.begin(ssid, password); // Connect wifi and return connection status. 52 | // 连接wifi并返回连接状态 53 | Serial.print("Connected to "); 54 | Serial.println(ssid); // Output Network name. 输出网络名称 55 | while (WiFi.status() != 56 | WL_CONNECTED) { // If the wifi connection fails. 若wifi未连接成功 57 | delay(500); // delay 0.5s. 延迟0.5s 58 | Serial.print("."); 59 | } 60 | Serial.print("Success!\nIP address: "); 61 | Serial.println(WiFi.localIP()); // Output IP Address. 输出IP地址 62 | 63 | if (!MDNS.begin("ESP32_Browser")) { // if init error. 如果初始化错误 64 | Serial.println("Error setting up MDNS responder!"); 65 | while (1) { 66 | delay(1000); 67 | } 68 | } 69 | } 70 | 71 | void loop() { 72 | browseService("http", "tcp"); 73 | delay(1000); 74 | browseService("arduino", "tcp"); 75 | delay(1000); 76 | browseService("workstation", "tcp"); 77 | delay(1000); 78 | browseService("smb", "tcp"); 79 | delay(1000); 80 | browseService("afpovertcp", "tcp"); 81 | delay(1000); 82 | browseService("ftp", "tcp"); 83 | delay(1000); 84 | browseService("ipp", "tcp"); 85 | delay(1000); 86 | browseService("printer", "tcp"); 87 | delay(10000); 88 | } -------------------------------------------------------------------------------- /examples/Advanced/Storage/EEPROM/EEPROM.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:EEPROM Read & Write. 10 | * date:2021/7/30 11 | ******************************************************************************* 12 | The values stored in the EEPROM will remain in the EEPROM even after the 13 | M5Atom is disconnected. When a new program is uploaded to the M5Atom, the values 14 | stored in the EEPROM can still be called or modified by the new program. 15 | 储存于EEPROM的数值即使在断开 M5Atom电源后仍会保存在EEPROM中 16 | 当新程序上传到 M5Atom后,储存于EEPROM中的数值仍然可以被新的程序调用或者修改 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | int addr = 0; // EEPROM Start number of an ADDRESS. EEPROM地址起始编号 23 | #define SIZE 32 // define the size of EEPROM(Byte). 定义EEPROM的大小(字节) 24 | 25 | void setup() { 26 | M5.begin(); // Init Atom. 初始化Atom 27 | if (!EEPROM.begin(SIZE)) { // Request storage of SIZE size(success return 28 | // 1). 申请SIZE大小的存储(成功返回1) 29 | Serial.println( 30 | "\nFailed to initialise EEPROM!"); // 串口输出格式化字符串. Serial 31 | // output format string 32 | delay(1000000); 33 | } 34 | Serial.println("\nRead data from EEPROM. Values are:"); 35 | for (int i = 0; i < SIZE; i++) { 36 | Serial.printf("%d ", 37 | EEPROM.read(i)); // Reads data from 0 to SIZE in EEPROM. 38 | // 读取EEPROM中从0到SIZE中的数据 39 | } 40 | Serial.println("\n\nPress Btn to Write EEPROM"); 41 | } 42 | 43 | void loop() { 44 | M5.update(); // Check button down state. 检测按键按下状态 45 | if (M5.Btn.isPressed()) { // if the button is Pressed. 如果按键按下 46 | Serial.printf("\n%d Bytes datas written on EEPROM.\nValues are:\n", 47 | SIZE); 48 | for (int i = 0; i < SIZE; i++) { 49 | int val = random( 50 | 256); // Integer values to be stored in the EEPROM (EEPROM can 51 | // store one byte per memory address, and can only store 52 | // numbers from 0 to 255. Therefore, if you want to use 53 | // EEPROM to store the numeric value read by the analog 54 | // input pin, divide the numeric value by 4. 55 | // 将要存储于EEPROM的整数数值(EEPROM每一个存储地址可以储存一个字节,只能存储0-255的数.故如果要使用EEPROM存储模拟输入引脚所读取到的数值需要将该数值除以4) 56 | EEPROM.write(addr, 57 | val); // Writes the specified data to the specified 58 | // address. 向指定地址写入指定数据 59 | Serial.printf("%d ", val); 60 | addr += 1; // Go to the next storage address. 转入下一存储地址 61 | } 62 | // When the storage address sequence number reaches the end of the 63 | // storage space of the EEPROM, return to. 64 | // 当存储地址序列号达到EEPROM的存储空间结尾,返回到EEPROM开始地址 65 | addr = 0; 66 | Serial.println("\n\nRead form EEPROM. Values are:"); 67 | for (int i = 0; i < SIZE; i++) { 68 | Serial.printf("%d ", EEPROM.read(i)); 69 | } 70 | Serial.println("\n-------------------------------------\n"); 71 | } 72 | delay(150); 73 | } -------------------------------------------------------------------------------- /examples/Advanced/Storage/SPIFFS/SPIFFS/SPIFFS.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:SPIFFS write & read. 闪存文件读写 10 | * date:2021/8/4 11 | ****************************************************************************** 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | String file_name = 18 | "/M5Stack/notes.txt"; // Sets the location and name of the file to be 19 | // operated on. 设置被操作的文件位置和名称 20 | bool SPIFFS_FORMAT = 21 | false; // 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(); // Init M5Atom. 初始化 M5ATOM 27 | if (SPIFFS_FORMAT) { 28 | Serial.println( 29 | "\nSPIFFS format start..."); // Serial port output format String. 30 | // 串口输出格式化字符串 31 | SPIFFS.format(); // Formatting SPIFFS. 格式化SPIFFS 32 | Serial.println("SPIFFS format finish"); 33 | } 34 | 35 | if (SPIFFS.begin()) { // Start SPIFFS, return 1 on success. 36 | // 启动闪存文件系统,若成功返回1 37 | Serial.println("SPIFFS Begin."); 38 | // Write operation 39 | File dataFile = SPIFFS.open( 40 | file_name, 41 | "w"); // Create aFile object dafaFile to write information to 42 | // file_name in the SPIFFS. 43 | // 建立File对象dafaFile用于向SPIFFS中的file_name写入信息 44 | dataFile.println("Hello IOT World."); // Writes string information and 45 | // newlines to the dataFile. 46 | // 向dataFile写入字符串信息并换行 47 | dataFile.close(); // Close the file when writing is complete. 48 | // 完成写入后关闭文件 49 | Serial.println("Finished Writing data to SPIFFS"); 50 | } else { 51 | Serial.println( 52 | "SPIFFS Failed to Begin.\nYou need to Run SPIFFS_Add.ino first"); 53 | } 54 | } 55 | 56 | void loop() { 57 | M5.update(); // Check whether the key is pressed. 检测按键是否按下 58 | if (M5.Btn.isPressed()) { // If the button is pressed. 如果按键按下 59 | if (SPIFFS.exists( 60 | file_name)) { // Check whether the file_name file exists in the 61 | // flash memory. 确认闪存中是否有file_name文件 62 | Serial.println("FOUND."); 63 | Serial.println(file_name); 64 | } else { 65 | Serial.println("NOT FOUND."); 66 | Serial.println(file_name); 67 | } 68 | File dataFile = SPIFFS.open( 69 | file_name, 70 | "r"); // Create a File object dafaFile to read information to 71 | // file_name in the SPIFFS. 72 | // 建立File对象dafaFile用于向SPIFFS中的file_name读取信息 73 | for (int i = 0; i < dataFile.size(); 74 | i++) { // Reads file contents and outputs file information through 75 | // the serial port monitor. 76 | // 读取文件内容并且通过串口监视器输出文件信息 77 | Serial.print((char)dataFile.read()); 78 | } 79 | dataFile.close(); // Close the file after reading the file. 80 | // 完成文件读取后关闭文件 81 | delay(200); 82 | } 83 | } -------------------------------------------------------------------------------- /examples/Unit/THERMAL_MLX90640/MLX90640_I2C_Driver.cpp: -------------------------------------------------------------------------------- 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 | #include 18 | #include 19 | 20 | #include "MLX90640_I2C_Driver.h" 21 | 22 | void MLX90640_I2CInit() { 23 | } 24 | 25 | // Read a number of words from startAddress. Store into Data array. 26 | // Returns 0 if successful, -1 if error 27 | int MLX90640_I2CRead(uint8_t _deviceAddress, unsigned int startAddress, 28 | unsigned int nWordsRead, uint16_t *data) { 29 | // Caller passes number of 'unsigned ints to read', increase this to 'bytes 30 | // to read' 31 | uint16_t bytesRemaining = nWordsRead * 2; 32 | 33 | // It doesn't look like sequential read works. Do we need to re-issue the 34 | // address command each time? 35 | 36 | uint16_t dataSpot = 0; // Start at beginning of array 37 | 38 | // Setup a series of chunked I2C_BUFFER_LENGTH byte reads 39 | while (bytesRemaining > 0) { 40 | Wire.beginTransmission(_deviceAddress); 41 | Wire.write(startAddress >> 8); // MSB 42 | Wire.write(startAddress & 0xFF); // LSB 43 | if (Wire.endTransmission(false) != 0) // Do not release bus 44 | { 45 | Serial.println("No ack read"); 46 | return (0); // Sensor did not ACK 47 | } 48 | 49 | uint16_t numberOfBytesToRead = bytesRemaining; 50 | if (numberOfBytesToRead > I2C_BUFFER_LENGTH) 51 | numberOfBytesToRead = I2C_BUFFER_LENGTH; 52 | 53 | Wire.requestFrom((uint8_t)_deviceAddress, numberOfBytesToRead); 54 | if (Wire.available()) { 55 | for (uint16_t x = 0; x < numberOfBytesToRead / 2; x++) { 56 | // Store data into array 57 | data[dataSpot] = Wire.read() << 8; // MSB 58 | data[dataSpot] |= Wire.read(); // LSB 59 | 60 | dataSpot++; 61 | } 62 | } 63 | 64 | bytesRemaining -= numberOfBytesToRead; 65 | 66 | startAddress += numberOfBytesToRead / 2; 67 | } 68 | 69 | return (0); // Success 70 | } 71 | 72 | // Set I2C Freq, in kHz 73 | // MLX90640_I2CFreqSet(1000) sets frequency to 1MHz 74 | void MLX90640_I2CFreqSet(int freq) { 75 | // i2c.frequency(1000 * freq); 76 | Wire.setClock((long)1000 * freq); 77 | } 78 | 79 | // Write two bytes to a two byte address 80 | int MLX90640_I2CWrite(uint8_t _deviceAddress, unsigned int writeAddress, 81 | uint16_t data) { 82 | Wire.beginTransmission((uint8_t)_deviceAddress); 83 | Wire.write(writeAddress >> 8); // MSB 84 | Wire.write(writeAddress & 0xFF); // LSB 85 | Wire.write(data >> 8); // MSB 86 | Wire.write(data & 0xFF); // LSB 87 | if (Wire.endTransmission() != 0) { 88 | // Sensor did not ACK 89 | Serial.println("Error: Sensor did not ack"); 90 | return (-1); 91 | } 92 | 93 | uint16_t dataCheck; 94 | MLX90640_I2CRead(_deviceAddress, writeAddress, 1, &dataCheck); 95 | if (dataCheck != data) { 96 | // Serial.println("The write request didn't stick"); 97 | return -2; 98 | } 99 | 100 | return (0); // Success 101 | } 102 | -------------------------------------------------------------------------------- /examples/Unit/CAN/CAN.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/can 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/can 8 | * 9 | * describe: can. 10 | * date:2021/9/1 11 | ******************************************************************************* 12 | Please connect to PORT-,Press buttonA to Send message if received message, 13 | Serial will display 请连接端口,按钮A发送消息,如果收到消息,串口将显示 14 | */ 15 | 16 | #include 17 | #include "ESP32CAN.h" 18 | #include "CAN_config.h" 19 | 20 | #define TX GPIO_NUM_26 21 | #define RX GPIO_NUM_32 22 | 23 | CAN_device_t CAN_cfg; // CAN Config 24 | 25 | int i = 0; 26 | 27 | void setup() { 28 | M5.begin(true, true, true); 29 | Serial.println("CAN Unit Send&Received"); 30 | 31 | CAN_cfg.speed = CAN_SPEED_125KBPS; // Set the Can speed. 设置Can速度 32 | CAN_cfg.tx_pin_id = TX; // Set the Pin foot. 设置引脚 33 | CAN_cfg.rx_pin_id = RX; 34 | 35 | CAN_cfg.rx_queue = xQueueCreate(10, sizeof(CAN_frame_t)); 36 | 37 | ESP32Can.CANInit(); // Init CAN Module. 初始化Can 38 | } 39 | 40 | void loop() { 41 | CAN_frame_t rx_frame; 42 | 43 | if (M5.Btn.wasPressed()) { 44 | rx_frame.FIR.B.FF = CAN_frame_std; 45 | rx_frame.MsgID = 1; 46 | rx_frame.FIR.B.DLC = 8; 47 | rx_frame.data.u8[0] = 'H'; 48 | rx_frame.data.u8[1] = 'e'; 49 | rx_frame.data.u8[2] = 'l'; 50 | rx_frame.data.u8[3] = 'l'; 51 | rx_frame.data.u8[4] = 'o'; 52 | rx_frame.data.u8[5] = 'C'; 53 | rx_frame.data.u8[6] = 'A'; 54 | rx_frame.data.u8[7] = 'N'; 55 | 56 | ESP32Can.CANWriteFrame(&rx_frame); 57 | Serial.println("Send Message1"); 58 | } 59 | if (M5.Btn.pressedFor(2000)) { 60 | rx_frame.FIR.B.FF = CAN_frame_std; 61 | rx_frame.MsgID = 1; 62 | rx_frame.FIR.B.DLC = 8; 63 | rx_frame.data.u8[0] = 'M'; 64 | rx_frame.data.u8[1] = '5'; 65 | rx_frame.data.u8[2] = 'S'; 66 | rx_frame.data.u8[3] = 'T'; 67 | rx_frame.data.u8[4] = 'A'; 68 | rx_frame.data.u8[5] = 'C'; 69 | rx_frame.data.u8[6] = 'K'; 70 | rx_frame.data.u8[7] = ' '; 71 | ESP32Can.CANWriteFrame(&rx_frame); 72 | Serial.println("Send Message2"); 73 | Serial.println("B"); 74 | } 75 | 76 | if (xQueueReceive(CAN_cfg.rx_queue, &rx_frame, 3 * portTICK_PERIOD_MS) == 77 | pdTRUE) { 78 | // do stuff! 79 | if (rx_frame.FIR.B.FF == CAN_frame_std) { 80 | printf("New standard frame"); 81 | Serial.printf("New standard frame"); 82 | } else { 83 | printf("New extended frame"); 84 | Serial.printf("New extended frame"); 85 | } 86 | if (rx_frame.FIR.B.RTR == CAN_RTR) { 87 | printf(" RTR from 0x%08x, DLC %d\r\n", rx_frame.MsgID, 88 | rx_frame.FIR.B.DLC); 89 | Serial.printf(" RTR from 0x%08x, DLC %d\r\n", rx_frame.MsgID, 90 | rx_frame.FIR.B.DLC); 91 | } else { 92 | printf(" from 0x%08x, DLC %d\n", rx_frame.MsgID, 93 | rx_frame.FIR.B.DLC); 94 | Serial.printf(" from 0x%08x, DLC %d\r\n", rx_frame.MsgID, 95 | rx_frame.FIR.B.DLC); 96 | for (int i = 0; i < 8; i++) { 97 | printf("%c\t", (char)rx_frame.data.u8[i]); 98 | Serial.printf("%c\t", (char)rx_frame.data.u8[i]); 99 | } 100 | printf("\n"); 101 | } 102 | } 103 | 104 | M5.update(); 105 | delay(200); 106 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiTCP/WiFiTCP.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:WIFI TCP. 10 | * date:2021/7/29 11 | ******************************************************************************* 12 | M5Atom will sends a message to a TCP server 13 | M5Atom 将向TCP服务器发送一条数据 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | // Set the name and password of the wifi to be connected. 21 | // 配置所连接wifi的名称和密码 22 | const char *ssid = "cam"; 23 | const char *password = "12345678"; 24 | WiFiMulti WiFiMulti; 25 | 26 | void setup() { 27 | M5.begin(true, false, true); // Init Atom(Initialize serial port, LED). 28 | // 初始化 ATOM(初始化串口、LED) 29 | WiFiMulti.addAP( 30 | ssid, 31 | password); // Add wifi configuration information. 添加wifi配置信息 32 | Serial.print( 33 | "\nWaiting connect to WiFi..."); // Serial port output format string. 34 | // 串口输出格式化字符串 35 | M5.dis.fillpix(0xff0000); // Make the LED light show red. 使led灯显示红色 36 | while (WiFiMulti.run() != 37 | WL_CONNECTED) { // If the connection to wifi is not established 38 | // successfully. 如果没有与wifi成功建立连接 39 | Serial.print("."); 40 | delay(300); 41 | } 42 | M5.dis.fillpix(0x00ff00); // Make the LED light green. 使led灯显示绿色 43 | Serial.println("\nWiFi connected"); 44 | Serial.print("IP address: "); 45 | Serial.println(WiFi.localIP()); // The serial port outputs the IP address 46 | // of the M5Atom. 串口输出M5Atom的IP地址 47 | delay(500); 48 | } 49 | 50 | void loop() { 51 | const char *host = "www.baidu.com"; // Set the IP address or DNS of the TCP 52 | // server. 设置TCP服务器的ip或dns 53 | const uint16_t port = 54 | 80; // The port of the TCP server is specified. 设置TCP服务器的端口 55 | Serial.print("Connecting to: "); 56 | Serial.println(host); 57 | 58 | WiFiClient client; 59 | if (!client.connect( 60 | host, 61 | port)) { // Connect to the server. 0 is returned if the 62 | // connection fails. 连接服务器,若连接失败返回0 63 | Serial.println("Connection failed."); 64 | Serial.println("Waiting 5 seconds before retrying..."); 65 | delay(5000); 66 | return; 67 | } 68 | 69 | // send an arbitrary string to the server. 发送一个字符串到上边连接的服务器 70 | client.print("Send this data to the server"); 71 | // send a basic document request to the server. 72 | // 向服务器发送一个基本的文档请求. 73 | client.print("GET /index.html HTTP/1.1\n\n"); 74 | int maxloops = 0; 75 | 76 | // wait for the server's reply to become available 77 | // 等待服务器的回复 78 | while (!client.available() && maxloops < 1000) { 79 | maxloops++; 80 | delay(1); // delay 1 msec 81 | } 82 | if (client.available() > 83 | 0) { // Detects whether data is received. 检测是否接收到数据 84 | String line = client.readStringUntil( 85 | '\r'); // Read information from data received by the device until 86 | // \r is read. 从设备接收到的数据中读取信息,直至读取到\r时 87 | Serial.println(line); // String received by serial port output. 88 | // 串口输出接收到的字符串 89 | } else { 90 | Serial.println("client.available() timed out "); 91 | } 92 | Serial.println("Closing connection."); 93 | client.stop(); 94 | Serial.println("Waiting 5 seconds before restarting..."); 95 | delay(5000); 96 | } 97 | -------------------------------------------------------------------------------- /examples/Unit/TOF_VL53L0X/TOF_VL53L0X.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:ToF. 激光测距 10 | * date:2021/8/16 11 | ******************************************************************************* 12 | Please connect to Port ,Use ToF Unit to detect distance and display distance 13 | data on the Serial in real time. 请连接端口,使用ToF 14 | Unit检测距离,并在串口上实时显示距离数据。 15 | */ 16 | 17 | #include 18 | 19 | #define VL53L0X_REG_IDENTIFICATION_MODEL_ID 0xc0 20 | #define VL53L0X_REG_IDENTIFICATION_REVISION_ID 0xc2 21 | #define VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD 0x50 22 | #define VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD 0x70 23 | #define VL53L0X_REG_SYSRANGE_START 0x00 24 | #define VL53L0X_REG_RESULT_INTERRUPT_STATUS 0x13 25 | #define VL53L0X_REG_RESULT_RANGE_STATUS 0x14 26 | #define address 0x29 // I2C address 27 | 28 | byte gbuf[16]; 29 | 30 | uint16_t bswap(byte b[]) { 31 | // Big Endian unsigned short to little endian unsigned short 32 | uint16_t val = ((b[0] << 8) & b[1]); 33 | return val; 34 | } 35 | 36 | uint16_t makeuint16(int lsb, int msb) { 37 | return ((msb & 0xFF) << 8) | (lsb & 0xFF); 38 | } 39 | 40 | void write_byte_data(byte data) { 41 | Wire.beginTransmission(address); 42 | Wire.write(data); 43 | Wire.endTransmission(); 44 | } 45 | 46 | void write_byte_data_at(byte reg, byte data) { 47 | // write data word at address and register 48 | Wire.beginTransmission(address); 49 | Wire.write(reg); 50 | Wire.write(data); 51 | Wire.endTransmission(); 52 | } 53 | 54 | void write_word_data_at(byte reg, uint16_t data) { 55 | // write data word at address and register 56 | byte b0 = (data & 0xFF); 57 | byte b1 = ((data >> 8) && 0xFF); 58 | 59 | Wire.beginTransmission(address); 60 | Wire.write(reg); 61 | Wire.write(b0); 62 | Wire.write(b1); 63 | Wire.endTransmission(); 64 | } 65 | 66 | byte read_byte_data() { 67 | Wire.requestFrom(address, 1); 68 | while (Wire.available() < 1) delay(1); 69 | byte b = Wire.read(); 70 | return b; 71 | } 72 | 73 | byte read_byte_data_at(byte reg) { 74 | // write_byte_data((byte)0x00); 75 | write_byte_data(reg); 76 | Wire.requestFrom(address, 1); 77 | while (Wire.available() < 1) delay(1); 78 | byte b = Wire.read(); 79 | return b; 80 | } 81 | 82 | uint16_t read_word_data_at(byte reg) { 83 | write_byte_data(reg); 84 | Wire.requestFrom(address, 2); 85 | while (Wire.available() < 2) delay(1); 86 | gbuf[0] = Wire.read(); 87 | gbuf[1] = Wire.read(); 88 | return bswap(gbuf); 89 | } 90 | 91 | void read_block_data_at(byte reg, int sz) { 92 | int i = 0; 93 | write_byte_data(reg); 94 | Wire.requestFrom(address, sz); 95 | for (i = 0; i < sz; i++) { 96 | while (Wire.available() < 1) delay(1); 97 | gbuf[i] = Wire.read(); 98 | } 99 | } 100 | 101 | uint16_t VL53L0X_decode_vcsel_period(short vcsel_period_reg) { 102 | // Converts the encoded VCSEL period register value into the real 103 | // period in PLL clocks 104 | uint16_t vcsel_period_pclks = (vcsel_period_reg + 1) << 1; 105 | return vcsel_period_pclks; 106 | } 107 | 108 | void setup() { 109 | //---osmar 110 | M5.begin(); 111 | Wire.begin(26, 32); // join i2c bus (address optional for master) 112 | Serial.println(("VLX53LOX Example")); 113 | //---osmar 114 | } 115 | 116 | void loop() { 117 | write_byte_data_at(VL53L0X_REG_SYSRANGE_START, 0x01); 118 | 119 | byte val = 0; 120 | int cnt = 0; 121 | while (cnt < 100) { // 1 second waiting time max 122 | delay(10); 123 | val = read_byte_data_at(VL53L0X_REG_RESULT_RANGE_STATUS); 124 | if (val & 0x01) break; 125 | cnt++; 126 | } 127 | if (val & 0x01) 128 | Serial.println("ready"); 129 | else 130 | Serial.println("not ready"); 131 | 132 | read_block_data_at(0x14, 12); 133 | uint16_t acnt = makeuint16(gbuf[7], gbuf[6]); 134 | uint16_t scnt = makeuint16(gbuf[9], gbuf[8]); 135 | uint16_t dist = makeuint16(gbuf[11], gbuf[10]); 136 | byte DeviceRangeStatusInternal = ((gbuf[0] & 0x78) >> 3); 137 | 138 | Serial.print("-------\nambient count: "); 139 | Serial.println(acnt); 140 | Serial.print("signal count: "); 141 | Serial.println(scnt); 142 | Serial.print("distance "); 143 | Serial.println(dist); 144 | Serial.print("status: "); 145 | Serial.println(DeviceRangeStatusInternal); 146 | delay(500); 147 | } -------------------------------------------------------------------------------- /examples/Unit/CAN/CAN.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @section License 3 | * 4 | * The MIT License (MIT) 5 | * 6 | * Copyright (c) 2017, Thomas Barth, barth-dev.de 7 | * 2018, Michael Wagner, mw@iot-make.de 8 | * Permission is hereby granted, free of charge, to any person 9 | * obtaining a copy of this software and associated documentation 10 | * files (the "Software"), to deal in the Software without 11 | * restriction, including without limitation the rights to use, copy, 12 | * modify, merge, publish, distribute, sublicense, and/or sell copies 13 | * of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be 17 | * included in all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 26 | * SOFTWARE. 27 | */ 28 | 29 | #ifndef __DRIVERS_CAN_H__ 30 | #define __DRIVERS_CAN_H__ 31 | 32 | #include 33 | #include "CAN_config.h" 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | /** 40 | * \brief CAN frame type (standard/extended) 41 | */ 42 | typedef enum { 43 | CAN_frame_std = 0, /**< Standard frame, using 11 bit identifer. */ 44 | CAN_frame_ext = 1 /**< Extended frame, using 29 bit identifer. */ 45 | } CAN_frame_format_t; 46 | 47 | /** 48 | * \brief CAN RTR 49 | */ 50 | typedef enum { 51 | CAN_no_RTR = 0, /**< No RTR frame. */ 52 | CAN_RTR = 1 /**< RTR frame. */ 53 | } CAN_RTR_t; 54 | 55 | /** \brief Frame information record type */ 56 | typedef union { 57 | uint32_t U; /**< \brief Unsigned access */ 58 | struct { 59 | uint8_t DLC : 4; /**< \brief [3:0] DLC, Data length container */ 60 | unsigned int unknown_2 : 2; /**< \brief \internal unknown */ 61 | CAN_RTR_t RTR : 1; /**< \brief [6:6] RTR, Remote Transmission Request */ 62 | CAN_frame_format_t 63 | FF : 1; /**< \brief [7:7] Frame Format, see# CAN_frame_format_t*/ 64 | unsigned int reserved_24 : 24; /**< \brief \internal Reserved */ 65 | } B; 66 | } CAN_FIR_t; 67 | 68 | /** \brief CAN Frame structure */ 69 | typedef struct { 70 | CAN_FIR_t FIR; /**< \brief Frame information record*/ 71 | uint32_t MsgID; /**< \brief Message ID */ 72 | union { 73 | uint8_t u8[8]; /**< \brief Payload byte access*/ 74 | uint32_t u32[2]; /**< \brief Payload u32 access*/ 75 | uint64_t u64; /**< \brief Payload u64 access*/ 76 | } data; 77 | } CAN_frame_t; 78 | 79 | typedef enum { 80 | Dual_Mode = 0, /**< \brief The dual acceptance filter option is enabled (two 81 | filters, each with the length of 16 bit are active) */ 82 | Single_Mode = 1 /**< \brief The single acceptance filter option is enabled 83 | (one filter with the length of 32 bit is active) */ 84 | } CAN_filter_mode_t; 85 | 86 | /** \brief CAN Filter structure */ 87 | typedef struct { 88 | CAN_filter_mode_t FM : 1; /**< \brief [0:0] Filter Mode */ 89 | uint8_t ACR0; /**< \brief Acceptance Code Register ACR0 */ 90 | uint8_t ACR1; /**< \brief Acceptance Code Register ACR1 */ 91 | uint8_t ACR2; /**< \brief Acceptance Code Register ACR2 */ 92 | uint8_t ACR3; /**< \brief Acceptance Code Register ACR3 */ 93 | uint8_t AMR0; /**< \brief Acceptance Mask Register AMR0 */ 94 | uint8_t AMR1; /**< \brief Acceptance Mask Register AMR1 */ 95 | uint8_t AMR2; /**< \brief Acceptance Mask Register AMR2 */ 96 | uint8_t AMR3; /**< \brief Acceptance Mask Register AMR3 */ 97 | } CAN_filter_t; 98 | 99 | /** 100 | * \brief Initialize the CAN Module 101 | * 102 | * \return 0 CAN Module had been initialized 103 | */ 104 | int CAN_init(void); 105 | 106 | /** 107 | * \brief Send a can frame 108 | * 109 | * \param p_frame Pointer to the frame to be send, see #CAN_frame_t 110 | * \return 0 Frame has been written to the module 111 | */ 112 | int CAN_write_frame(const CAN_frame_t* p_frame); 113 | 114 | /** 115 | * \brief Stops the CAN Module 116 | * 117 | * \return 0 CAN Module was stopped 118 | */ 119 | int CAN_stop(void); 120 | 121 | /** 122 | * \brief Config CAN Filter, must call before CANInit() 123 | * 124 | * \param p_filter Pointer to the filter, see #CAN_filter_t 125 | * \return 0 CAN Filter had been initialized 126 | */ 127 | int CAN_config_filter(const CAN_filter_t* p_filter); 128 | 129 | #ifdef __cplusplus 130 | } 131 | #endif 132 | 133 | #endif 134 | -------------------------------------------------------------------------------- /examples/Unit/LoRaWAN470/LoRaWAN470.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | *information:https://docs.m5stack.com/en/unit/lorawan470 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/lorawan470 9 | * 10 | * describe: LoRaWAN470. 11 | * date:2021/8/31 12 | ******************************************************************************* 13 | */ 14 | #include "M5Atom.h" 15 | #include "freertos/queue.h" 16 | 17 | String waitRevice() { 18 | String recvStr; 19 | do { 20 | recvStr = Serial2.readStringUntil('\n'); 21 | } while (recvStr.length() == 0); 22 | Serial.println(recvStr); 23 | return recvStr; 24 | } 25 | 26 | void sendATCMD(String cmdStr) { 27 | Serial2.print(cmdStr); 28 | delay(100); 29 | } 30 | 31 | int sendATCMDAndRevice(String cmdStr) { 32 | Serial2.print(cmdStr); 33 | delay(100); 34 | waitRevice(); 35 | String recvStr = waitRevice(); 36 | if (recvStr.indexOf("OK") != -1) { 37 | return 0; 38 | } else { 39 | return -1; 40 | } 41 | } 42 | 43 | void setup() { 44 | M5.begin(true, false, true); 45 | Serial2.begin(115200, SERIAL_8N1, 32, 26); 46 | Serial2.flush(); 47 | delay(100); 48 | 49 | sendATCMD("AT?\r\n"); 50 | delay(100); 51 | Serial2.flush(); 52 | sendATCMDAndRevice("AT+ILOGLVL=0\r\n"); 53 | sendATCMDAndRevice("AT+CSAVE\r\n"); 54 | sendATCMDAndRevice("AT+IREBOOT=0\r\n"); 55 | Serial.println("LoraWan Rebooting"); 56 | delay(2000); 57 | Serial.println("LoraWan config"); 58 | // Set Join Mode OTAA. 59 | sendATCMDAndRevice("AT+CJOINMODE=0\r\n"); 60 | sendATCMDAndRevice("AT+CDEVEUI=0037CAE1FC3542B9\r\n"); 61 | sendATCMDAndRevice("AT+CAPPEUI=70B3D57ED003E04E\r\n"); 62 | sendATCMDAndRevice("AT+CAPPKEY=67FA4ED1075A20573BCDD7594C458698\r\n"); 63 | sendATCMDAndRevice("AT+CULDLMODE=2\r\n"); 64 | // Set ClassC mode 65 | sendATCMDAndRevice("AT+CCLASS=2\r\n"); 66 | sendATCMDAndRevice("AT+CWORKMODE=2\r\n"); 67 | 68 | sendATCMDAndRevice("AT+CRXP=0,0,505300000\r\n"); 69 | 70 | // TX Freq 71 | // 486.3 72 | // 486.5 73 | // 486.7 74 | // 486.9 75 | // 487.1 76 | // 487.3 77 | // 487.5 78 | // 487.7 79 | // MARK 0000 0100 0000 0000 | 0x0400 80 | 81 | sendATCMDAndRevice("AT+CFREQBANDMASK=0400\r"); 82 | 83 | // RX Freq 84 | // 506.7 (RX1) 85 | // 506.9 (RX1) 86 | // 507.1 (RX1) 87 | // 507.3 (RX1) 88 | // 507.5 (RX1) 89 | // 507.7 (RX1) 90 | // 507.9 (RX1) 91 | // 508.1 (RX1) 92 | // 505.3 (RX2)| 505300000 93 | sendATCMDAndRevice("AT+CJOIN=1,0,10,8\r\n"); 94 | } 95 | 96 | enum systemstate { 97 | kIdel = 0, 98 | kJoined, 99 | kSending, 100 | kWaitSend, 101 | kEnd, 102 | }; 103 | int system_fsm = kIdel; 104 | 105 | int loraWanSendNUM = -1; 106 | int loraWanSendCNT = -1; 107 | 108 | void loop() { 109 | String recvStr = waitRevice(); 110 | if (recvStr.indexOf("+CJOIN:") != -1) { 111 | if (recvStr.indexOf("OK") != -1) { 112 | Serial.println("[ INFO ] JOIN IN SUCCESSFUL"); 113 | Serial.printf("LoraWan JOIN"); 114 | system_fsm = kJoined; 115 | M5.dis.fillpix(0x00ff00); // GREEN 绿色 116 | } else { 117 | Serial.println("[ INFO ] JOIN IN FAIL"); 118 | Serial.printf("LoraWan JOIN FAIL"); 119 | system_fsm = kIdel; 120 | M5.dis.drawpix(0, 0xff0000); // RED 红色 121 | } 122 | } else if (recvStr.indexOf("OK+RECV") != -1) { 123 | if (system_fsm == kJoined) { 124 | system_fsm = kSending; 125 | } else if (system_fsm == kWaitSend) { 126 | system_fsm = kSending; 127 | char strbuff[128]; 128 | if ((loraWanSendCNT < 5) && (loraWanSendNUM == 8)) { 129 | sprintf(strbuff, "TSET OK CNT: %d", loraWanSendCNT); 130 | Serial.print(strbuff); 131 | } else { 132 | sprintf(strbuff, "FAILD NUM:%d CNT:%d", loraWanSendNUM, 133 | loraWanSendCNT); 134 | Serial.print(strbuff); 135 | } 136 | } 137 | } else if (recvStr.indexOf("OK+SEND") != -1) { 138 | String snednum = recvStr.substring(8); 139 | Serial.printf(" [ INFO ] SEND NUM %s \r\n", snednum.c_str()); 140 | loraWanSendNUM = snednum.toInt(); 141 | } else if (recvStr.indexOf("OK+SENT") != -1) { 142 | String snedcnt = recvStr.substring(8); 143 | Serial.printf(" [ INFO ] SEND CNT %s \r\n", snedcnt.c_str()); 144 | loraWanSendCNT = snedcnt.toInt(); 145 | } 146 | 147 | if (system_fsm == kSending) { 148 | Serial.println("LoraWan Sending"); 149 | sendATCMD("AT+DTRX=1,8,8,4655434b20535443\r\n"); 150 | system_fsm = kWaitSend; 151 | } 152 | delay(10); 153 | } -------------------------------------------------------------------------------- /examples/Audio/STT/STT.ino: -------------------------------------------------------------------------------- 1 | /**************************************************************** 2 | * 3 | * This Example only for M5AtomU 4 | * 5 | * 1. press btn and speak 6 | * 2. serial get the stt result 7 | * 8 | ****************************************************************/ 9 | #include 10 | #include 11 | #include 12 | 13 | #include "BaiduRest.h" 14 | #include "M5Atom.h" 15 | 16 | const char *WifiSSID = "ssid"; 17 | const char *WifiPWD = "password"; 18 | 19 | #define CONFIG_I2S_BCK_PIN -1 20 | #define CONFIG_I2S_LRCK_PIN 5 21 | #define CONFIG_I2S_DATA_PIN -1 22 | #define CONFIG_I2S_DATA_IN_PIN 19 23 | 24 | #define SPEAK_I2S_NUMBER I2S_NUM_0 25 | 26 | #define MODE_MIC 0 27 | #define MODE_SPK 1 28 | 29 | // String LANGUAGE_MODE = DEV_PID_MANDARIN; 30 | String LANGUAGE_MODE = DEV_PID_ENGLISH; 31 | 32 | bool InitI2SSpeakOrMic(int mode) { 33 | esp_err_t err = ESP_OK; 34 | 35 | i2s_driver_uninstall(SPEAK_I2S_NUMBER); 36 | i2s_config_t i2s_config = { 37 | .mode = (i2s_mode_t)(I2S_MODE_MASTER), 38 | .sample_rate = 16000, 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 = 44 | I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication. 45 | #else // 设置通讯格式 46 | .communication_format = I2S_COMM_FORMAT_I2S, 47 | #endif 48 | .intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, 49 | .dma_buf_count = 6, 50 | .dma_buf_len = 60, 51 | }; 52 | if (mode == MODE_MIC) { 53 | i2s_config.mode = 54 | (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); 55 | } else { 56 | i2s_config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX); 57 | i2s_config.use_apll = false; 58 | i2s_config.tx_desc_auto_clear = true; 59 | } 60 | 61 | Serial.println("Init i2s_driver_install"); 62 | 63 | err += i2s_driver_install(SPEAK_I2S_NUMBER, &i2s_config, 0, NULL); 64 | i2s_pin_config_t tx_pin_config; 65 | 66 | #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) 67 | tx_pin_config.mck_io_num = I2S_PIN_NO_CHANGE; 68 | #endif 69 | 70 | tx_pin_config.bck_io_num = CONFIG_I2S_BCK_PIN; 71 | tx_pin_config.ws_io_num = CONFIG_I2S_LRCK_PIN; 72 | tx_pin_config.data_out_num = CONFIG_I2S_DATA_PIN; 73 | tx_pin_config.data_in_num = CONFIG_I2S_DATA_IN_PIN; 74 | 75 | Serial.println("Init i2s_set_pin"); 76 | err += i2s_set_pin(SPEAK_I2S_NUMBER, &tx_pin_config); 77 | Serial.println("Init i2s_set_clk"); 78 | err += i2s_set_clk(SPEAK_I2S_NUMBER, 16000, I2S_BITS_PER_SAMPLE_16BIT, 79 | I2S_CHANNEL_MONO); 80 | 81 | return true; 82 | } 83 | 84 | BaiduRest rest; 85 | uint8_t microphonedata0[1024 * 80]; 86 | size_t byte_read = 0; 87 | int16_t *buffptr; 88 | uint32_t data_offset = 0; 89 | 90 | void setup() { 91 | M5.begin(true, false, true); 92 | M5.dis.clear(); 93 | 94 | Serial.println("Init Spaker"); 95 | InitI2SSpeakOrMic(MODE_SPK); 96 | delay(100); 97 | 98 | Serial.println("Connecting Wifi"); 99 | WiFi.mode(WIFI_STA); 100 | WiFi.setSleep(false); 101 | 102 | WiFi.begin(WifiSSID, WifiPWD); 103 | 104 | M5.dis.drawpix(0, CRGB(0, 128, 0)); 105 | size_t bytes_written; 106 | 107 | while (WiFi.status() != WL_CONNECTED) { 108 | delay(500); 109 | Serial.print('.'); 110 | } 111 | 112 | M5.dis.drawpix(0, CRGB(128, 0, 0)); 113 | 114 | Serial.println("Connected."); 115 | 116 | rest.settoken("500291857fbc58d4336dbe4e30d49797"); 117 | } 118 | 119 | #define DATA_SIZE 1024 120 | 121 | String SpakeStr; 122 | bool Spakeflag = false; 123 | 124 | void loop() { 125 | if (M5.Btn.isPressed()) { 126 | data_offset = 0; 127 | Spakeflag = false; 128 | InitI2SSpeakOrMic(MODE_MIC); 129 | M5.dis.drawpix(0, CRGB(128, 128, 0)); 130 | while (1) { 131 | i2s_read(SPEAK_I2S_NUMBER, (char *)(microphonedata0 + data_offset), 132 | DATA_SIZE, &byte_read, (100 / portTICK_RATE_MS)); 133 | data_offset += 1024; 134 | M5.update(); 135 | if (M5.Btn.isReleased() || data_offset >= 81919) break; 136 | // delay(60); 137 | } 138 | Serial.println("end"); 139 | 140 | if (rest.Pcm2String(microphonedata0, data_offset, LANGUAGE_MODE, 141 | &SpakeStr) != -1) { 142 | Serial.println(SpakeStr); 143 | Spakeflag = true; 144 | M5.dis.drawpix(0, CRGB(128, 0, 128)); 145 | } else { 146 | M5.dis.drawpix(0, CRGB(0, 128, 0)); 147 | } 148 | } 149 | 150 | if (WiFi.status() != WL_CONNECTED) { 151 | Serial.println("Wifi reconnect"); 152 | WiFi.reconnect(); 153 | while (WiFi.status() != WL_CONNECTED) { 154 | delay(100); 155 | } 156 | } 157 | M5.update(); 158 | delay(100); 159 | } 160 | -------------------------------------------------------------------------------- /examples/Unit/THERMAL_MLX90640/interpolation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | float get_point(float *p, uint8_t rows, uint8_t cols, int8_t x, int8_t y); 4 | void set_point(float *p, uint8_t rows, uint8_t cols, int8_t x, int8_t y, 5 | float f); 6 | void get_adjacents_1d(float *src, float *dest, uint8_t rows, uint8_t cols, 7 | int8_t x, int8_t y); 8 | void get_adjacents_2d(float *src, float *dest, uint8_t rows, uint8_t cols, 9 | int8_t x, int8_t y); 10 | float cubicInterpolate(float p[], float x); 11 | float bicubicInterpolate(float p[], float x, float y); 12 | void interpolate_image(float *src, uint8_t src_rows, uint8_t src_cols, 13 | float *dest, uint8_t dest_rows, uint8_t dest_cols); 14 | 15 | float get_point(float *p, uint8_t rows, uint8_t cols, int8_t x, int8_t y) { 16 | if (x < 0) x = 0; 17 | if (y < 0) y = 0; 18 | if (x >= cols) x = cols - 1; 19 | if (y >= rows) y = rows - 1; 20 | return p[y * cols + x]; 21 | } 22 | 23 | void set_point(float *p, uint8_t rows, uint8_t cols, int8_t x, int8_t y, 24 | float f) { 25 | if ((x < 0) || (x >= cols)) return; 26 | if ((y < 0) || (y >= rows)) return; 27 | p[y * cols + x] = f; 28 | } 29 | 30 | // src is a grid src_rows * src_cols 31 | // dest is a pre-allocated grid, dest_rows*dest_cols 32 | void interpolate_image(float *src, uint8_t src_rows, uint8_t src_cols, 33 | float *dest, uint8_t dest_rows, uint8_t dest_cols) { 34 | float mu_x = (src_cols - 1.0) / (dest_cols - 1.0); 35 | float mu_y = (src_rows - 1.0) / (dest_rows - 1.0); 36 | 37 | float adj_2d[16]; // matrix for storing adjacents 38 | 39 | for (uint8_t y_idx = 0; y_idx < dest_rows; y_idx++) { 40 | for (uint8_t x_idx = 0; x_idx < dest_cols; x_idx++) { 41 | float x = x_idx * mu_x; 42 | float y = y_idx * mu_y; 43 | // Serial.print("("); Serial.print(y_idx); Serial.print(", "); 44 | // Serial.print(x_idx); Serial.print(") = "); Serial.print("("); 45 | // Serial.print(y); Serial.print(", "); Serial.print(x); 46 | // Serial.print(") = "); 47 | get_adjacents_2d(src, adj_2d, src_rows, src_cols, x, y); 48 | /* 49 | Serial.print("["); 50 | for (uint8_t i=0; i<16; i++) { 51 | Serial.print(adj_2d[i]); Serial.print(", "); 52 | } 53 | Serial.println("]"); 54 | */ 55 | float frac_x = 56 | x - (int)x; // we only need the ~delta~ between the points 57 | float frac_y = 58 | y - (int)y; // we only need the ~delta~ between the points 59 | float out = bicubicInterpolate(adj_2d, frac_x, frac_y); 60 | // Serial.print("\tInterp: "); Serial.println(out); 61 | set_point(dest, dest_rows, dest_cols, x_idx, y_idx, out); 62 | } 63 | } 64 | } 65 | 66 | // p is a list of 4 points, 2 to the left, 2 to the right 67 | float cubicInterpolate(float p[], float x) { 68 | float r = p[1] + (0.5 * x * 69 | (p[2] - p[0] + 70 | x * (2.0 * p[0] - 5.0 * p[1] + 4.0 * p[2] - p[3] + 71 | x * (3.0 * (p[1] - p[2]) + p[3] - p[0])))); 72 | /* 73 | Serial.print("interpolating: ["); 74 | Serial.print(p[0],2); Serial.print(", "); 75 | Serial.print(p[1],2); Serial.print(", "); 76 | Serial.print(p[2],2); Serial.print(", "); 77 | Serial.print(p[3],2); Serial.print("] w/"); Serial.print(x); 78 | Serial.print(" = "); Serial.println(r); 79 | */ 80 | return r; 81 | } 82 | 83 | // p is a 16-point 4x4 array of the 2 rows & columns left/right/above/below 84 | float bicubicInterpolate(float p[], float x, float y) { 85 | float arr[4] = {0, 0, 0, 0}; 86 | arr[0] = cubicInterpolate(p + 0, x); 87 | arr[1] = cubicInterpolate(p + 4, x); 88 | arr[2] = cubicInterpolate(p + 8, x); 89 | arr[3] = cubicInterpolate(p + 12, x); 90 | return cubicInterpolate(arr, y); 91 | } 92 | 93 | // src is rows*cols and dest is a 4-point array passed in already allocated! 94 | void get_adjacents_1d(float *src, float *dest, uint8_t rows, uint8_t cols, 95 | int8_t x, int8_t y) { 96 | // Serial.print("("); Serial.print(x); Serial.print(", "); Serial.print(y); 97 | // Serial.println(")"); 98 | // pick two items to the left 99 | dest[0] = get_point(src, rows, cols, x - 1, y); 100 | dest[1] = get_point(src, rows, cols, x, y); 101 | // pick two items to the right 102 | dest[2] = get_point(src, rows, cols, x + 1, y); 103 | dest[3] = get_point(src, rows, cols, x + 2, y); 104 | } 105 | 106 | // src is rows*cols and dest is a 16-point array passed in already allocated! 107 | void get_adjacents_2d(float *src, float *dest, uint8_t rows, uint8_t cols, 108 | int8_t x, int8_t y) { 109 | // Serial.print("("); Serial.print(x); Serial.print(", "); Serial.print(y); 110 | // Serial.println(")"); 111 | float arr[4]; 112 | for (int8_t delta_y = -1; delta_y < 3; delta_y++) { // -1, 0, 1, 2 113 | float *row = dest + 4 * (delta_y + 1); // index into each chunk of 4 114 | for (int8_t delta_x = -1; delta_x < 3; delta_x++) { // -1, 0, 1, 2 115 | row[delta_x + 1] = 116 | get_point(src, rows, cols, x + delta_x, y + delta_y); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiAccessPoint/WiFiAccessPoint.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/products 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products 8 | * 9 | * describe:WIFI AP. wifi热点 10 | * date:2021/7/29 11 | ******************************************************************************* 12 | WiFiAccessPoint.ino creates a WiFi access point and provides a web server on 13 | it. 创建一个WiFi接入点,并在其上提供一个网络服务器 And can send requests to 14 | M5Atom through the web page 并可通过网页向M5Atom发送请求 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | // Set these to your desired credentials. 设置你的热点名称和密码 23 | const char *ssid = "M5Stack_Ap"; 24 | const char *password = "66666666"; 25 | 26 | WiFiServer server(80); 27 | 28 | void setup() { 29 | M5.begin(); // Init M5Atom. 初始化M5Atom 30 | Serial.println( 31 | "\nWIFI ACCESS POINT"); // Screen print string. 屏幕打印字符串 32 | Serial.printf("Please connect:%s \nThen access to:", ssid); 33 | WiFi.softAP( 34 | ssid, 35 | password); // You can remove the password parameter if you want the AP 36 | // to be open. 如果你想建立开放式热点,可以删除密码 37 | IPAddress myIP = WiFi.softAPIP(); // Get the softAP interface IP address. 38 | // 获取AP接口IP地址 39 | Serial.println(myIP); 40 | server.begin(); // Start the established Internet of Things network server. 41 | // 启动建立的物联网网络服务器 42 | } 43 | 44 | void loop() { 45 | WiFiClient client = 46 | server 47 | .available(); // listen for incoming clients. 48 | // 检查有没有设备通过网络向M5Stack网络服务器发送请求 49 | 50 | if (client) { // if you get a client. 如果收到请求 51 | Serial.print("New Client:"); 52 | String currentLine = 53 | ""; // make a String to hold incoming data from the client. 54 | // 创建一个String来保存来自客户端的传入数据 55 | while (client.connected()) { // loop while the client's 56 | // connected,continuously receiving data. 57 | // 在客户端连接时进行循环,不断接收数据 58 | if (client.available()) { // if there's bytes to read from the 59 | // client. 如果有数据可读取 60 | char c = 61 | client.read(); // store the read a byte. 存储读取到的数据 62 | Serial.write(c); 63 | if (c == '\n') { // if the byte is a newline character. 64 | // 如果读取到的字节为换行符 65 | // \n is the end of the client'S HTTP request, indicating 66 | // that the client has sent a new request \n 67 | // 是客户端HTTP请求的结尾,说明客户端发来新请求: 68 | if (currentLine.length() == 0) { 69 | // Here are the instructions to create a page. 70 | // 下面是创建一个页面的指令 71 | 72 | // HTTP headers always start with a response code (e.g. 73 | // HTTP/1.1 200 OK) HTTP的开头总是以响应代码开始(例如 74 | // HTTP/1.1 200 OK) and a content-type so the client 75 | // knows what's coming, then a blank line: 76 | // 然后是content-type,这样客户端就知道接下来会发生什么,然后是空行: 77 | client.println("HTTP/1.1 200 OK"); 78 | client.println("Content-type:text/html"); 79 | client.println(); 80 | 81 | // the content of the HTTP response follows the header: 82 | // HTTP页面显示的内容跟在开头后面: 83 | // /High and /Low are the data received when clicking 84 | // the corresponding connection, which can be replaced. 85 | // /High和/Low 为点击对应连接时接收到的数据,可更换 86 | client.print( 87 | "Click here to turn ON the " 88 | "LED.
"); 89 | client.print( 90 | "Click here to turn OFF the " 91 | "LED.
"); 92 | 93 | // The HTTP response ends with another blank line: 94 | // HTTP响应以空行结束: 95 | client.println(); 96 | // break out of the while loop:退出循环 97 | break; 98 | } else { // if you got a newline, then clear 99 | // currentLine:如果得到新的一行,那么清除当前行 100 | currentLine = ""; 101 | } 102 | } else if (c != 103 | '\r') { // if you got anything else but a carriage 104 | // return character. 105 | // 如果你得到了除了回车符以外的其他字符, 106 | currentLine += c; // add it to the end of the currentLine. 107 | // 将它添加到currentLine的末尾 108 | } 109 | 110 | // Check to see if the client request was "GET /H" or "GET /L": 111 | // 检查客户端请求是“GET /High”还是“GET /Low”: 112 | if (currentLine.endsWith("GET /High")) { 113 | Serial.print("ON\n"); 114 | } else if (currentLine.endsWith("GET /Low")) { 115 | Serial.print("OFF\n"); 116 | } 117 | } 118 | } 119 | client.stop(); // close the connection. 关闭连接 120 | } 121 | } -------------------------------------------------------------------------------- /examples/Advanced/WIFI/WiFiSetting/detail/RequestHandlersImpl.h: -------------------------------------------------------------------------------- 1 | #ifndef REQUESTHANDLERSIMPL_H 2 | #define REQUESTHANDLERSIMPL_H 3 | 4 | #include "RequestHandler.h" 5 | 6 | class FunctionRequestHandler : public RequestHandler { 7 | public: 8 | FunctionRequestHandler(WebServer::THandlerFunction fn, 9 | WebServer::THandlerFunction ufn, const String& uri, 10 | HTTPMethod method) 11 | : _fn(fn), _ufn(ufn), _uri(uri), _method(method) { 12 | } 13 | 14 | bool canHandle(HTTPMethod requestMethod, String requestUri) override { 15 | if (_method != HTTP_ANY && _method != requestMethod) return false; 16 | 17 | if (requestUri != _uri) return false; 18 | 19 | return true; 20 | } 21 | 22 | bool canUpload(String requestUri) override { 23 | if (!_ufn || !canHandle(HTTP_POST, requestUri)) return false; 24 | 25 | return true; 26 | } 27 | 28 | bool handle(WebServer& server, HTTPMethod requestMethod, 29 | String requestUri) override { 30 | (void)server; 31 | if (!canHandle(requestMethod, requestUri)) return false; 32 | 33 | _fn(); 34 | return true; 35 | } 36 | 37 | void upload(WebServer& server, String requestUri, 38 | HTTPUpload& upload) override { 39 | (void)server; 40 | (void)upload; 41 | if (canUpload(requestUri)) _ufn(); 42 | } 43 | 44 | protected: 45 | WebServer::THandlerFunction _fn; 46 | WebServer::THandlerFunction _ufn; 47 | String _uri; 48 | HTTPMethod _method; 49 | }; 50 | 51 | class StaticRequestHandler : public RequestHandler { 52 | public: 53 | StaticRequestHandler(FS& fs, const char* path, const char* uri, 54 | const char* cache_header) 55 | : _fs(fs), _uri(uri), _path(path), _cache_header(cache_header) { 56 | _isFile = fs.exists(path); 57 | // DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, 58 | // cache_header=%s\r\n", path, uri, _isFile, cache_header); 59 | _baseUriLength = _uri.length(); 60 | } 61 | 62 | bool canHandle(HTTPMethod requestMethod, String requestUri) override { 63 | if (requestMethod != HTTP_GET) return false; 64 | 65 | if ((_isFile && requestUri != _uri) || !requestUri.startsWith(_uri)) 66 | return false; 67 | 68 | return true; 69 | } 70 | 71 | bool handle(WebServer& server, HTTPMethod requestMethod, 72 | String requestUri) override { 73 | if (!canHandle(requestMethod, requestUri)) return false; 74 | 75 | // DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", 76 | // requestUri.c_str(), _uri.c_str()); 77 | 78 | String path(_path); 79 | 80 | if (!_isFile) { 81 | // Base URI doesn't point to a file. 82 | // If a directory is requested, look for index file. 83 | if (requestUri.endsWith("/")) requestUri += "index.htm"; 84 | 85 | // Append whatever follows this URI in request to get the file path. 86 | path += requestUri.substring(_baseUriLength); 87 | } 88 | // DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", 89 | // path.c_str(), _isFile); 90 | 91 | String contentType = getContentType(path); 92 | 93 | // look for gz file, only if the original specified path is not a gz. So 94 | // part only works to send gzip via content encoding when a non 95 | // compressed is asked for if you point the the path to gzip you will 96 | // serve the gzip as content type "application/x-gzip", not text or 97 | // javascript etc... 98 | if (!path.endsWith(".gz") && !_fs.exists(path)) { 99 | String pathWithGz = path + ".gz"; 100 | if (_fs.exists(pathWithGz)) path += ".gz"; 101 | } 102 | 103 | File f = _fs.open(path, "r"); 104 | if (!f) return false; 105 | 106 | if (_cache_header.length() != 0) 107 | server.sendHeader("Cache-Control", _cache_header); 108 | 109 | server.streamFile(f, contentType); 110 | return true; 111 | } 112 | 113 | static String getContentType(const String& path) { 114 | if (path.endsWith(".html")) 115 | return "text/html"; 116 | else if (path.endsWith(".htm")) 117 | return "text/html"; 118 | else if (path.endsWith(".css")) 119 | return "text/css"; 120 | else if (path.endsWith(".txt")) 121 | return "text/plain"; 122 | else if (path.endsWith(".js")) 123 | return "application/javascript"; 124 | else if (path.endsWith(".png")) 125 | return "image/png"; 126 | else if (path.endsWith(".gif")) 127 | return "image/gif"; 128 | else if (path.endsWith(".jpg")) 129 | return "image/jpeg"; 130 | else if (path.endsWith(".ico")) 131 | return "image/x-icon"; 132 | else if (path.endsWith(".svg")) 133 | return "image/svg+xml"; 134 | else if (path.endsWith(".ttf")) 135 | return "application/x-font-ttf"; 136 | else if (path.endsWith(".otf")) 137 | return "application/x-font-opentype"; 138 | else if (path.endsWith(".woff")) 139 | return "application/font-woff"; 140 | else if (path.endsWith(".woff2")) 141 | return "application/font-woff2"; 142 | else if (path.endsWith(".eot")) 143 | return "application/vnd.ms-fontobject"; 144 | else if (path.endsWith(".sfnt")) 145 | return "application/font-sfnt"; 146 | else if (path.endsWith(".xml")) 147 | return "text/xml"; 148 | else if (path.endsWith(".pdf")) 149 | return "application/pdf"; 150 | else if (path.endsWith(".zip")) 151 | return "application/zip"; 152 | else if (path.endsWith(".gz")) 153 | return "application/x-gzip"; 154 | else if (path.endsWith(".appcache")) 155 | return "text/cache-manifest"; 156 | return "application/octet-stream"; 157 | } 158 | 159 | protected: 160 | FS _fs; 161 | String _uri; 162 | String _path; 163 | String _cache_header; 164 | bool _isFile; 165 | size_t _baseUriLength; 166 | }; 167 | 168 | #endif // REQUESTHANDLERSIMPL_H 169 | -------------------------------------------------------------------------------- /examples/Unit/LoRaWAN868/LoRaWAN868.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | information:https://docs.m5stack.com/en/unit/lorawan868 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/lorawan868 9 | * 10 | * describe: LoRaWAN868. 11 | * date:2021/8/31 12 | ******************************************************************************* 13 | Please connect to Port,请连接端口 14 | */ 15 | #include "M5Atom.h" 16 | #include "freertos/queue.h" 17 | 18 | String waitRevice() { 19 | String recvStr; 20 | do { 21 | recvStr = Serial2.readStringUntil('\n'); 22 | } while (recvStr.length() == 0); 23 | Serial.println(recvStr); 24 | return recvStr; 25 | } 26 | 27 | void sendATCMD(String cmdStr) { 28 | Serial2.print(cmdStr); 29 | delay(100); 30 | } 31 | 32 | int sendATCMDAndRevice(String cmdStr) { 33 | Serial2.print(cmdStr); 34 | delay(10); 35 | waitRevice(); 36 | String recvStr = waitRevice(); 37 | if (recvStr.indexOf("OK") != -1) { 38 | return 0; 39 | } else { 40 | return -1; 41 | } 42 | } 43 | 44 | void setup() { 45 | M5.begin(); 46 | Serial2.begin(115200, SERIAL_8N1, 32, 26); 47 | Serial2.flush(); 48 | delay(100); 49 | Serial.println("LoRaWAN868"); 50 | 51 | sendATCMD("AT?\r"); 52 | delay(100); 53 | Serial2.flush(); 54 | sendATCMDAndRevice("AT+ILOGLVL=0\r"); 55 | sendATCMDAndRevice("AT+CSAVE\r"); 56 | sendATCMDAndRevice("AT+IREBOOT=0\r"); 57 | Serial.println("LoraWan Rebooting"); 58 | delay(2000); 59 | Serial.println("LoraWan config"); 60 | sendATCMDAndRevice("AT+CJOINMODE=0\r"); 61 | sendATCMDAndRevice("AT+CDEVEUI=00bb9da5b97addf1\r"); 62 | sendATCMDAndRevice("AT+CAPPEUI=70B3D57ED004247E\r"); // 70B3D57ED003B699 63 | sendATCMDAndRevice("AT+CAPPKEY=27DFE264CA33AC1957C005EB48BA4721\r"); 64 | sendATCMDAndRevice("AT+CULDLMODE=2\r"); 65 | sendATCMDAndRevice("AT+CCLASS=2\r"); 66 | sendATCMDAndRevice("AT+CWORKMODE=2\r"); 67 | sendATCMDAndRevice("AT+CNBTRIALS=0,5\r"); 68 | sendATCMDAndRevice("AT+CNBTRIALS=1,5\r"); 69 | 70 | // TX Freq 71 | // 868.1 - SF7BW125 to SF12BW125 72 | // 868.3 - SF7BW125 to SF12BW125 and SF7BW250 73 | // 868.5 - SF7BW125 to SF12BW125 74 | // 867.1 - SF7BW125 to SF12BW125 75 | // 867.3 - SF7BW125 to SF12BW125 76 | // 867.5 - SF7BW125 to SF12BW125 77 | // 867.7 - SF7BW125 to SF12BW125 78 | // 867.9 - SF7BW125 to SF12BW125 79 | // 868.8 - FSK 80 | 81 | sendATCMDAndRevice("AT+CFREQBANDMASK=0001\r"); 82 | 83 | // 869.525 - SF9BW125 (RX2) | 869525000 84 | // sendATCMDAndRevice("AT+CRXP=0,0,869525000\r"); 85 | 86 | sendATCMDAndRevice("AT+CSAVE\r"); 87 | 88 | sendATCMDAndRevice("AT+CJOIN=1,0,10,8\r"); 89 | } 90 | 91 | enum systemstate { 92 | kIdel = 0, 93 | kJoined, 94 | kSending, 95 | kWaitSend, 96 | kEnd, 97 | }; 98 | int system_fsm = kIdel; 99 | 100 | int loraWanSendNUM = -1; 101 | int loraWanSendCNT = -1; 102 | int loraWanupLinkCNT = 0; 103 | int loraWanupLinkReviceCNT = 0; 104 | 105 | void loop() { 106 | String recvStr = waitRevice(); 107 | if (recvStr.indexOf("+CJOIN:") != -1) { 108 | if (recvStr.indexOf("OK") != -1) { 109 | Serial.println("[ INFO ] JOIN IN SUCCESSFUL"); 110 | system_fsm = kJoined; 111 | } else { 112 | Serial.println("[ INFO ] JOIN IN FAIL"); 113 | system_fsm = kIdel; 114 | } 115 | } else if (recvStr.indexOf("OK+RECV") != -1) { 116 | if (system_fsm == kJoined) { 117 | system_fsm = kSending; 118 | } else if (system_fsm == kWaitSend) { 119 | system_fsm = kEnd; 120 | char strbuff[128]; 121 | loraWanupLinkReviceCNT++; 122 | 123 | // if(( loraWanSendCNT < 5 )&&( loraWanSendNUM == 8 )) 124 | //{ 125 | // loraWanupLinkReviceCNT ++; 126 | // sprintf(strbuff,"SEND CNT: %d 127 | // (%d/%d)",loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT); 128 | // M5.Lcd.fillRect(0,183,320,32,TFT_BLACK); 129 | // M5.Lcd.setTextColor(TFT_GREEN); 130 | // M5.Lcd.drawString(strbuff, 10, 183, 4); 131 | // //drawLineStr(strbuff, TFT_GREEN); 132 | // 133 | //} 134 | // else 135 | //{ 136 | // sprintf(strbuff,"FAILD NUM:%d CNT:%d 137 | // (%d/%d)",loraWanSendNUM,loraWanSendCNT,loraWanupLinkReviceCNT,loraWanupLinkCNT); 138 | // M5.Lcd.fillRect(0,183,320,32,TFT_BLACK); 139 | // M5.Lcd.setTextColor(TFT_RED); 140 | // M5.Lcd.drawString(strbuff, 10, 183, 4); 141 | // drawLineStr(strbuff, TFT_RED); 142 | //} 143 | delay(500); 144 | system_fsm = kSending; 145 | } 146 | } else if (recvStr.indexOf("OK+SEND") != -1) { 147 | String snednum = recvStr.substring(8); 148 | Serial.printf(" [ INFO ] SEND NUM %s \r\n", snednum.c_str()); 149 | loraWanSendNUM = snednum.toInt(); 150 | } else if (recvStr.indexOf("OK+SENT") != -1) { 151 | String snedcnt = recvStr.substring(8); 152 | Serial.printf(" [ INFO ] SEND CNT %s \r\n", snedcnt.c_str()); 153 | loraWanSendCNT = snedcnt.toInt(); 154 | } else if (recvStr.indexOf("ERR+SENT") != -1) { 155 | char strbuff[128]; 156 | String ErrorCodeStr = recvStr.substring(9); 157 | sprintf(strbuff, "ERROR Code:%d (%d/%d)", ErrorCodeStr.toInt(), 158 | loraWanupLinkReviceCNT, loraWanupLinkCNT); 159 | Serial.println(strbuff); 160 | delay(500); 161 | 162 | system_fsm = kSending; 163 | } else if (recvStr.indexOf("+CLINKCHECK:") != -1) { 164 | String checkStr = recvStr.substring(String("+CLINKCHECK:").length()); 165 | 166 | char strbuff[128]; 167 | sprintf(strbuff, "%s (%d/%d)", checkStr.c_str(), loraWanupLinkReviceCNT, 168 | loraWanupLinkCNT); 169 | Serial.println(strbuff); 170 | } 171 | 172 | if (system_fsm == kSending) { 173 | Serial.println("LoraWan Sending"); 174 | sendATCMD("AT+CLINKCHECK=1\r"); 175 | loraWanupLinkCNT++; 176 | system_fsm = kWaitSend; 177 | } 178 | delay(10); 179 | } -------------------------------------------------------------------------------- /examples/Unit/UHF_RFID_JRD4035/UHF_RFID_JRD4035.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more 7 | *information:https://docs.m5stack.com/en/unit/uhf_rfid 8 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/uhf_rfid 9 | * 10 | * describe: uhf_rfid. 11 | * date:2021/9/1 12 | ******************************************************************************* 13 | */ 14 | #include 15 | #include "RFID_command.h" 16 | 17 | UHF_RFID RFID; 18 | 19 | String comd = " "; 20 | CardpropertiesInfo card; 21 | ManyInfo cards; 22 | SelectInfo Select; 23 | CardInformationInfo Cardinformation; 24 | QueryInfo Query; 25 | ReadInfo Read; 26 | TestInfo Test; 27 | 28 | void setup() { 29 | M5.begin(); 30 | 31 | RFID._debug = 0; 32 | Serial2.begin(115200, SERIAL_8N1, 32, 26); 33 | if (RFID._debug == 1) Serial.begin(115200, SERIAL_8N1, 21, 22); 34 | 35 | // UHF_RFID set UHF_RFID设置 36 | RFID.Set_transmission_Power(2600); 37 | RFID.Set_the_Select_mode(); 38 | RFID.Delay(100); 39 | RFID.Readcallback(); 40 | RFID.clean_data(); 41 | 42 | // Prompted to connect to UHF_RFID 提示连接UHF_RFID 43 | Serial.println("Please connect UHF_RFID to Port C"); 44 | 45 | // Determined whether to connect to UHF_RFID 判断是否连接UHF_RFID 46 | String soft_version; 47 | soft_version = RFID.Query_software_version(); 48 | while (soft_version.indexOf("V2.3.5") == -1) { 49 | RFID.clean_data(); 50 | RFID.Delay(150); 51 | RFID.Delay(150); 52 | soft_version = RFID.Query_software_version(); 53 | } 54 | 55 | // The prompt will be RFID card close 提示将RFID卡靠近 56 | Serial.println("Please approach the RFID card you need to use"); 57 | } 58 | 59 | void loop() { 60 | // A read/write operation specifies a particular card 61 | // 读写操作需指定某一张卡 comd = 62 | // RFID.Set_the_select_parameter_directive("30751FEB705C5904E3D50D70"); 63 | // Serial.println(comd); 64 | // RFID.clean_data(); 65 | 66 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 67 | Query the card information once 查询一次卡的信息例子 68 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ 69 | card = RFID.A_single_poll_of_instructions(); 70 | if (card._ERROR.length() != 0) { 71 | Serial.println(card._ERROR); 72 | } else { 73 | if (card._EPC.length() == 24) { 74 | Serial.println("RSSI :" + card._RSSI); 75 | Serial.println("PC :" + card._PC); 76 | Serial.println("EPC :" + card._EPC); 77 | Serial.println("CRC :" + card._CRC); 78 | Serial.println(" "); 79 | } 80 | } 81 | RFID.clean_data(); // Empty the data after using it 82 | // 使用完数据后要将数据清空 83 | 84 | /*Other feature usage examples 其他功能使用例子*/ 85 | 86 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 87 | Read multiple RFID cards at once 一次读取多张RFID卡 88 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ 89 | /* cards = RFID.Multiple_polling_instructions(6); 90 | for (size_t i = 0; i < cards.len; i++) 91 | { 92 | if(cards.card[i]._EPC.length() == 24) 93 | { 94 | Serial.println("RSSI :" + cards.card[i]._RSSI); 95 | Serial.println("PC :" + cards.card[i]._PC); 96 | Serial.println("EPC :" + cards.card[i]._EPC); 97 | Serial.println("CRC :" + cards.card[i]._CRC); 98 | } 99 | } 100 | Serial.println(" "); 101 | RFID.clean_data(); 102 | */ 103 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 104 | Used to get the SELECT parameter 用于获取Select参数 105 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ 106 | // Select = RFID.Get_the_select_parameter(); 107 | // if(Select.Mask.length() != 0) 108 | // { 109 | // Serial.println("Mask :" + Select.Mask); 110 | // Serial.println("SelParam :" + Select.SelParam); 111 | // Serial.println("Ptr :" + Select.Ptr); 112 | // Serial.println("MaskLen :" + Select.MaskLen); 113 | // Serial.println("Truncate :" + Select.Truncate); 114 | // Serial.println(" "); 115 | // } 116 | // RFID.clean_data(); 117 | 118 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 119 | Used to change the PSF bit of the NXP G2X label 用于改变 NXP G2X 标签的 120 | PSF 位 121 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ 122 | // Cardinformation = RFID.NXP_Change_EAS(0x00000000); 123 | // if(Cardinformation._UL.length() != 0) 124 | // { 125 | // Serial.println("UL :" + Cardinformation._UL); 126 | // Serial.println("PC :" + Cardinformation._PC); 127 | // Serial.println("EPC :" + Cardinformation._EPC); 128 | // Serial.println("Parameter :" + Cardinformation._Parameter); 129 | // Serial.println("ErrorCode :" + Cardinformation._ErrorCode); 130 | // Serial.println("Error :" + Cardinformation._Error); 131 | // Serial.println("Data :" + Cardinformation._Data); 132 | // Serial.println("Successful :" + Cardinformation._Successful); 133 | // Serial.println(" "); 134 | // } 135 | // RFID.clean_data(); 136 | 137 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 138 | Used to get the Query parameters 用于获取Query参数 139 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ 140 | // Query = RFID.Get_the_Query_parameter(); 141 | // if(Query.QueryParameter.length() != 0) 142 | // { 143 | // Serial.println("QueryParameter :" + Query.QueryParameter); 144 | // Serial.println("DR :" + Query.DR); 145 | // Serial.println("M :" + Query.M); 146 | // Serial.println("TRext :" + Query.TRext); 147 | // Serial.println("Sel :" + Query.Sel); 148 | // Serial.println("Session :" + Query.Session); 149 | // Serial.println("Targetta :" + Query.Target); 150 | // Serial.println("Q :" + Query.Q); 151 | // Serial.println(" "); 152 | // } 153 | // RFID.clean_data(); 154 | 155 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 156 | Used to get the Query parameters 用于读取接收解调器参数 157 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ 158 | // Read = RFID.Read_receive_demodulator_parameters(); 159 | // if(Read.Mixer_G.length()!= 0) 160 | // { 161 | // Serial.println("Mixer_G :" + Read.Mixer_G); 162 | // Serial.println("IF_G :" + Read.IF_G); 163 | // Serial.println("Thrd :" + Read.Thrd); 164 | // Serial.println(" "); 165 | // } 166 | // RFID.clean_data(); 167 | } 168 | -------------------------------------------------------------------------------- /examples/Unit/PDM_SPM1423/PDM_SPM1423.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * Copyright (c) 2021 by M5Stack 4 | * Equipped with Atom-Lite/Matrix sample source code 5 | * 配套 Atom-Lite/Matrix 示例源代码 6 | * Visit the website for more information:https://docs.m5stack.com/en/unit/pdm 7 | * 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/pdm 8 | * 9 | * describe: pdm. 麦克风 10 | * date:2022/2/22 11 | ******************************************************************************* 12 | Please connect to Port,Read the microphone data of the PDM Unit and display 13 | the audio loudness. 请连接端口,读取PDM Unit的麦克风数据,显示响度。 Note: Remove 14 | the M5GO base when using this example, otherwise it will not work properly 15 | 注意:在使用本示例时删除M5GO base,否则它将无法正常工作 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | #include "fft.h" 22 | 23 | #define PIN_CLK 32 24 | #define PIN_DATA 26 25 | 26 | #define MODE_MIC 0 27 | 28 | static QueueHandle_t fftvalueQueue = nullptr; 29 | static QueueHandle_t i2sstateQueue = nullptr; 30 | 31 | typedef struct { 32 | uint8_t state; 33 | void* audioPtr; 34 | uint32_t audioSize; 35 | } i2sQueueMsg_t; 36 | 37 | bool InitI2SSpakerOrMic(int mode) { 38 | i2s_config_t i2s_config = { 39 | .mode = (i2s_mode_t)(I2S_MODE_MASTER), // Set the I2S operating mode. 40 | // 设置I2S工作模式 41 | .sample_rate = 44100, // Set the I2S sampling rate. 设置I2S采样率 42 | .bits_per_sample = 43 | I2S_BITS_PER_SAMPLE_16BIT, // Fixed 12-bit stereo MSB. 44 | // 固定为12位立体声MSB 45 | .channel_format = 46 | I2S_CHANNEL_FMT_ONLY_RIGHT, // Set the channel format. 设置频道格式 47 | #if ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 1, 0) 48 | .communication_format = 49 | I2S_COMM_FORMAT_STAND_I2S, // Set the format of the communication. 50 | #else // 设置通讯格式 51 | .communication_format = I2S_COMM_FORMAT_I2S, 52 | #endif 53 | .intr_alloc_flags = 54 | ESP_INTR_FLAG_LEVEL1, // Set the interrupt flag. 设置中断的标志 55 | .dma_buf_count = 2, // DMA buffer count. DMA缓冲区计数 56 | .dma_buf_len = 128, // DMA buffer length. DMA缓冲区长度 57 | }; 58 | if (mode == MODE_MIC) { 59 | i2s_config.mode = 60 | (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM); 61 | } 62 | 63 | i2s_driver_install(I2S_NUM_0, &i2s_config, 0, 64 | NULL); // Install and drive I2S. 安装并驱动I2S 65 | 66 | i2s_pin_config_t pin_config; 67 | 68 | #if (ESP_IDF_VERSION > ESP_IDF_VERSION_VAL(4, 3, 0)) 69 | pin_config.mck_io_num = I2S_PIN_NO_CHANGE; 70 | #endif 71 | 72 | pin_config.bck_io_num = I2S_PIN_NO_CHANGE; 73 | pin_config.ws_io_num = PIN_CLK; 74 | pin_config.data_out_num = I2S_PIN_NO_CHANGE; 75 | pin_config.data_in_num = PIN_DATA; 76 | 77 | i2s_set_pin(I2S_NUM_0, &pin_config); 78 | i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO); 79 | 80 | return true; 81 | } 82 | 83 | static void i2sMicroFFTtask(void* arg) { 84 | uint8_t FFTDataBuff[128]; 85 | uint8_t FFTValueBuff[24]; 86 | uint8_t* microRawData = (uint8_t*)calloc(2048, sizeof(uint8_t)); 87 | size_t bytesread; 88 | int16_t* buffptr; 89 | double data = 0; 90 | float adc_data; 91 | uint16_t ydata; 92 | uint32_t subData; 93 | 94 | uint8_t state = MODE_MIC; 95 | i2sQueueMsg_t QueueMsg; 96 | while (1) { 97 | if (xQueueReceive(i2sstateQueue, &QueueMsg, (TickType_t)0) == pdTRUE) { 98 | // Serial.println("Queue Now"); 99 | if (QueueMsg.state == MODE_MIC) { 100 | InitI2SSpakerOrMic(MODE_MIC); 101 | state = MODE_MIC; 102 | } 103 | } else if (state == MODE_MIC) { 104 | fft_config_t* real_fft_plan = 105 | fft_init(1024, FFT_REAL, FFT_FORWARD, NULL, NULL); 106 | i2s_read(I2S_NUM_0, (char*)microRawData, 2048, &bytesread, 107 | (100 / portTICK_RATE_MS)); 108 | buffptr = (int16_t*)microRawData; 109 | 110 | for (int count_n = 0; count_n < real_fft_plan->size; count_n++) { 111 | adc_data = (float)map(buffptr[count_n], INT16_MIN, INT16_MAX, 112 | -2000, 2000); 113 | real_fft_plan->input[count_n] = adc_data; 114 | } 115 | fft_execute(real_fft_plan); 116 | 117 | for (int count_n = 1; count_n < real_fft_plan->size / 4; 118 | count_n++) { 119 | data = sqrt(real_fft_plan->output[2 * count_n] * 120 | real_fft_plan->output[2 * count_n] + 121 | real_fft_plan->output[2 * count_n + 1] * 122 | real_fft_plan->output[2 * count_n + 1]); 123 | if ((count_n - 1) < 128) { 124 | data = (data > 2000) ? 2000 : data; 125 | ydata = map(data, 0, 2000, 0, 255); 126 | FFTDataBuff[128 - count_n] = ydata; 127 | } 128 | } 129 | 130 | for (int count = 0; count < 24; count++) { 131 | subData = 0; 132 | for (int count_i = 0; count_i < 5; count_i++) { 133 | subData += FFTDataBuff[count * 5 + count_i]; 134 | } 135 | subData /= 5; 136 | FFTValueBuff[count] = map(subData, 0, 255, 0, 8); 137 | } 138 | xQueueSend(fftvalueQueue, (void*)&FFTValueBuff, 0); 139 | fft_destroy(real_fft_plan); 140 | } else { 141 | delay(10); 142 | } 143 | } 144 | } 145 | 146 | void microPhoneSetup() { 147 | fftvalueQueue = xQueueCreate(5, 24 * sizeof(uint8_t)); 148 | if (fftvalueQueue == 0) { 149 | return; 150 | } 151 | 152 | i2sstateQueue = xQueueCreate(5, sizeof(i2sQueueMsg_t)); 153 | if (i2sstateQueue == 0) { 154 | return; 155 | } 156 | 157 | InitI2SSpakerOrMic(MODE_MIC); 158 | xTaskCreatePinnedToCore(i2sMicroFFTtask, "microPhoneTask", 4096, NULL, 3, 159 | NULL, 0); 160 | } 161 | 162 | void MicroPhoneFFT() { 163 | uint8_t FFTValueBuff[24]; 164 | xQueueReceive(fftvalueQueue, (void*)&FFTValueBuff, portMAX_DELAY); 165 | for (int y = 0; y < 9; y++) { 166 | Serial.printf("loudness:%d\n", FFTValueBuff[y]); 167 | } 168 | } 169 | 170 | void setup() { 171 | M5.begin(true, true, false); 172 | Serial.printf("PDM Unit"); 173 | microPhoneSetup(); 174 | } 175 | 176 | void loop() { 177 | MicroPhoneFFT(); 178 | } 179 | --------------------------------------------------------------------------------