Skip to content

Commit

Permalink
Merge pull request #260 from Tinyu-Zhao/master
Browse files Browse the repository at this point in the history
Add some examples
  • Loading branch information
Tinyu-Zhao authored Sep 3, 2021
2 parents 3dd0200 + 0465519 commit b402122
Show file tree
Hide file tree
Showing 61 changed files with 1,985 additions and 4,426 deletions.
2 changes: 1 addition & 1 deletion examples/Advanced/WIFI/WiFiSetting/WiFiSetting.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void setup() {
void loop() {
if (settingMode) {
}
webServer.handleClient(); //检查有没有设备通过网络向M5Stack网络服务器发送请求
webServer.handleClient(); //Check that there is no facility to send requests to the M5StickC Web server over the network. 检查有没有设备通过网络向M5Stack网络服务器发送请求
}

boolean restoreConfig() { /* Check whether there is wifi configuration information storage, if there is 1 return, if no return 0.
Expand Down
13 changes: 12 additions & 1 deletion examples/Modules/AC-SOCKET/AC-SOCKET.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
/*
Description:Click button B to turn on the power. Click button A to turn off the power.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/products
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products
*
* describe: AC Socket.
* date:2021/9/1
*******************************************************************************
Click button B to turn on the power. Click button A to turn off the power.
单击按钮 B 打开电源。 单击按钮 A 关闭电源。
*/
#include <Arduino.h>
#include <M5Stack.h>
Expand Down
15 changes: 12 additions & 3 deletions examples/Modules/COM_GPS/COM_GPS.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/*
Description: Use COM.GPS Module to get the coordinate data and time of the current location.
Please install library before compiling:
TinyGPSPlus: file in M5stack lib examples -> modules -> GPS -> TinyGPSPlus-1.0.2.zip (unzip the lib zip file to the Arduino Lib path)
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core2示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/module/comx_gps
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/comx_gps
*
* describe: comx_gps.
* date:2021/9/2
*******************************************************************************
Use COM.GPS Module to get the coordinate data and time of the current location.
使用 COM.GPS 模块获取当前位置的坐标数据和时间。
*/

#include <M5Stack.h>
Expand Down
18 changes: 15 additions & 3 deletions examples/Modules/COM_GSM/COM_GSM.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/*
Description: screen will display the signal strength and network access status
Note: Set the DIP switch to 5 and 13.
*/
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/module/comx_gsm
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/comx_gsm
*
* describe: comx_gsm.
* date:2021/9/2
*******************************************************************************
Set the DIP switch to 5 and 13
and the screen will display the signal strength and network access status
将 DIP 开关设置为 5 和 13
并且屏幕会显示信号强度和网络访问状态
*/

#include <M5Stack.h>
#include <stdint.h>
Expand Down
17 changes: 14 additions & 3 deletions examples/Modules/COM_LTE-DATA/COM_LTE-DATA.ino
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
/*
Description: screen will display the signal strength and network access status
Note: Set the DIP switch to 5 and 13.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/module/comx_lte-data
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/comx_lte-data
*
* describe: comx_lte-data.
* date:2021/9/2
*******************************************************************************
Set the DIP switch to 5 and 13 and the screen will display the signal strength and network access status
press buttonA to dial phonenumber, ATD00000000000 is phone number, you can change
将 DIP 开关设置为 5 和 13 并且屏幕会显示信号强度和网络访问状态
按按钮A拨打电话号码,ATD00000000000 是电话号码,您可以更改
*/

#include <M5Stack.h>
#include <stdint.h>
#include <vector>
Expand Down
19 changes: 14 additions & 5 deletions examples/Modules/COM_LTE/COM_LTE.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
/*
Description: screen will display the signal strength and network access status
press buttonA to dial phonenumber.
ATD13800088888 is phone number, you can change
Note: Set the DIP switch to 5 and 13.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/module/comx_lte
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/comx_lte
*
* describe: comx_lte.
* date:2021/9/2
*******************************************************************************
Set the DIP switch to 5 and 13 and the screen will display the signal strength and network access status
press buttonA to dial phonenumber, ATD00000000000 is phone number, you can change
将 DIP 开关设置为 5 和 13 并且屏幕会显示信号强度和网络访问状态
按按钮A拨打电话号码,ATD00000000000 是电话号码,您可以更改
*/


#include <M5Stack.h>
#include <stdint.h>
#include <vector>
Expand Down
5 changes: 3 additions & 2 deletions examples/Modules/GRBL13.2/multi_control/multi_control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Power.begin();
_GRBL_A.Init();
_GRBL_B.Init();
Wire.begin(21, 22);
_GRBL_A.Init(&Wire);
_GRBL_B.Init(&Wire);
Serial.begin(115200);
m5.Lcd.setTextColor(WHITE, BLACK);
m5.Lcd.setTextSize(3);
Expand Down
3 changes: 2 additions & 1 deletion examples/Modules/GRBL13.2/xyz_control/xyz_control.ino
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ void setup() {
// put your setup code here, to run once:
M5.begin();
M5.Power.begin();
_GRBL.Init();
Wire.begin(21, 22);
_GRBL.Init(&Wire);
Serial.begin(115200);
m5.Lcd.setTextColor(WHITE, BLACK);
m5.Lcd.setTextSize(3);
Expand Down
85 changes: 49 additions & 36 deletions examples/Modules/LORA868_SX1276/LoRa868Duplex/LoRa868Duplex.ino
Original file line number Diff line number Diff line change
@@ -1,48 +1,61 @@
/*
Description: LoRa868 Duplex communication.Send messages regularly "HeLoRa World!"
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/module/comx_lorawan
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/comx_lorawan
*
* describe: comx_lorawan.
* date:2021/9/2
*******************************************************************************
LoRa868 Duplex communication.Send messages regularly "HeLoRa World!"
LoRa868 双工通讯。定期发送消息“HeLoRa World!”
*/
#include <M5Stack.h>
#include <M5LoRa.h>

String outgoing; // outgoing message
String outgoing; // outgoing message. 传出讯息

byte msgCount = 0; // count of outgoing messages
byte localAddress = 0xFF; // address of this device
byte destination = 0xBB; // destination to send to
byte msgCount = 0; // count of outgoing messages. 传出消息的计数
byte localAddress = 0xFF; // address of this device. 此设备的地址
byte destination = 0xBB; // destination to send to. 发送目的地

long lastSendTime = 0; // last send time
int interval = 1000; // interval between sends
long lastSendTime = 0; // last send time. 上次发送时间
int interval = 1000; // interval between sends. 发送间隔

void setup() {
M5.begin();
M5.Power.begin();

while (!Serial);

Serial.println("LoRa Duplex B");

// override the default CS, reset, and IRQ pins (optional)
LoRa.setPins();// set CS, reset, IRQ pin
// override the default CS, reset, and IRQ pins (optional). 覆盖默认的 CS、复位和 IRQ 引脚(可选)
LoRa.setPins();// set CS, reset, IRQ pin. 设置 CS、复位、IRQ 引脚

if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz
if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz. 868 MHz 时的初始化比率
Serial.println("LoRa init failed. Check your connections.");
while (true); // if failed, do nothing
while (true); // if failed, do nothing. 如果失败,什么都不做
}

Serial.println("LoRa init succeeded.");
}

void loop() {
if (millis() - lastSendTime > interval) {
String message = "HeLoRa World!"; // send a message
String message = "HeLoRa World!"; // send a message. 发送消息
sendMessage(message);
Serial.println("Sending " + message);
M5.Lcd.setTextColor(BLUE);
M5.Lcd.println("Sending " + message);
lastSendTime = millis(); // timestamp the message
lastSendTime = millis(); // timestamp the message. 给消息加时间戳
interval = random(1000) + 500;
}

// parse for a packet, and call onReceive with the result:
// parse for a packet, and call onReceive with the result:. 解析数据包,并使用结果调用 onReceive:
onReceive(LoRa.parsePacket());

if(M5.BtnA.wasPressed()){
Expand All @@ -60,58 +73,58 @@ void loop() {
void reinit(){
Serial.println("LoRa Duplex Reinitialization");

// override the default CS, reset, and IRQ pins (optional)
LoRa.setPins();// set CS, reset, IRQ pin
// override the default CS, reset, and IRQ pins (optional). 覆盖默认的 CS、复位和 IRQ 引脚(可选)
LoRa.setPins();// set CS, reset, IRQ pin. 设置 CS、复位、IRQ 引脚

if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz
if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz. 868 MHz 时的初始化比率
Serial.println("LoRa init failed. Check your connections.");
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(RED);
M5.Lcd.println("Init failed!!!");
while (true); // if failed, do nothing
while (true); // if failed, do nothing. 如果失败,什么都不做
}

Serial.println("LoRa init succeeded.");
}

void sendMessage(String outgoing) {
LoRa.beginPacket(); // start packet
LoRa.write(destination); // add destination address
LoRa.write(localAddress); // add sender address
LoRa.write(msgCount); // add message ID
LoRa.write(outgoing.length()); // add payload length
LoRa.print(outgoing); // add payload
LoRa.endPacket(); // finish packet and send it
msgCount++; // increment message ID
LoRa.beginPacket(); // start packet. 开始包
LoRa.write(destination); // add destination address. 添加目标地址
LoRa.write(localAddress); // add sender address. 添加发件人地址
LoRa.write(msgCount); // add message ID. 添加消息标识
LoRa.write(outgoing.length()); // add payload length. 添加有效载荷长度
LoRa.print(outgoing); // add payload. 添加有效载荷
LoRa.endPacket(); // finish packet and send it. 完成数据包并发送
msgCount++; // increment message ID. 增加消息 ID
}

void onReceive(int packetSize) {
if (packetSize == 0) return; // if there's no packet, return
if (packetSize == 0) return; // if there's no packet, return. 如果没有包,返回。

// read packet header bytes:
int recipient = LoRa.read(); // recipient address
byte sender = LoRa.read(); // sender address
byte incomingMsgId = LoRa.read(); // incoming msg ID
byte incomingLength = LoRa.read(); // incoming msg length
int recipient = LoRa.read(); // recipient address. 收件人地址。
byte sender = LoRa.read(); // sender address. 发件人地址。
byte incomingMsgId = LoRa.read(); // incoming msg ID. 传入的消息 ID。
byte incomingLength = LoRa.read(); // incoming msg length. 传入消息长度。

String incoming = "";

while (LoRa.available()) {
incoming += (char)LoRa.read();
}

if (incomingLength != incoming.length()) { // check length for error
if (incomingLength != incoming.length()) { // check length for error. 检查错误长度
Serial.println("error: message length does not match length");
return; // skip rest of function
return; // skip rest of function. 跳过其余功能
}

// if the recipient isn't this device or broadcast,
// if the recipient isn't this device or broadcast,. 如果收件人不是此设备或广播,
if (recipient != localAddress && recipient != 0xFF) {
Serial.println("This message is not for me.");
return; // skip rest of function
return; // skip rest of function. 跳过其余功能
}

// if message is for this device, or broadcast, print details:
// if message is for this device, or broadcast, print details:. 如果消息是针对此设备或广播的,则打印详细信息:
Serial.println("Received from: 0x" + String(sender, HEX));
Serial.println("Sent to: 0x" + String(recipient, HEX));
Serial.println("Message ID: " + String(incomingMsgId));
Expand Down
14 changes: 13 additions & 1 deletion examples/Modules/NB-IoT_M5311LV/NB-IoT_M5311LV.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
/*
Description: Use NB-IoT Module to send data to MQTT server.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/module/nb-iot
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/nb-iot
*
* describe: NB-IoT.
* date:2021/9/1
*******************************************************************************
Use NB-IoT Module to send data to MQTT server.
使用 NB-IoT 模块将数据发送到 MQTT 服务器。
*/

#include <M5Stack.h>
#include <stdint.h>
#include <vector>
Expand Down
13 changes: 12 additions & 1 deletion examples/Modules/PLUS/PLUS.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
/*
Description: This exmpale can display the encoder gear reading of the PLUS Module and the state of the keys.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core sample source code
* 配套 M5Core 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/module/plus
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/module/plus
*
* describe: PLUS.
* date:2021/9/2
*******************************************************************************
This exmpale can display the encoder gear reading of the PLUS Module and the state of the keys.
本例可以显示PLUS模块的编码器齿轮读数和按键状态。
*/
#include <Arduino.h>
#include <M5Stack.h>
Expand Down
Loading

0 comments on commit b402122

Please sign in to comment.