Skip to content

Commit f769d92

Browse files
authored
Add some example and delete repeat file (#211)
* add some example and delete repeat file
1 parent acdc9de commit f769d92

File tree

13 files changed

+916
-193
lines changed

13 files changed

+916
-193
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
neo pixel test
3+
4+
hardwware: M5StackFire
5+
6+
please install the Adafruit library first!
7+
September 2018, ChrisMicro
8+
*/
9+
10+
#include <Adafruit_NeoPixel.h>
11+
12+
#define M5STACK_FIRE_NEO_NUM_LEDS 10
13+
#define M5STACK_FIRE_NEO_DATA_PIN 15
14+
15+
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN, NEO_GRB + NEO_KHZ800);
16+
17+
void setup()
18+
{
19+
pixels.begin();
20+
}
21+
22+
void loop()
23+
{
24+
25+
static int pixelNumber=0;// = random(0, M5STACK_FIRE_NEO_NUM_LEDS - 1);
26+
pixelNumber++;
27+
if(pixelNumber>9)pixelNumber=0;
28+
int r = 1<<random(0, 7);
29+
int g = 1<<random(0, 7);
30+
int b = 1<<random(0, 7);
31+
32+
pixels.setPixelColor(pixelNumber, pixels.Color(r, g, b));
33+
pixels.show();
34+
35+
delay(100);
36+
37+
}

examples/Modules/GSM/GSM.ino

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <M5Stack.h>
2+
3+
void IotWriteCommand(char cmd[],char date[]){
4+
char buf[256] = {0};
5+
6+
if(cmd == NULL)
7+
sprintf(buf,"AT\r\n");
8+
else if(date == NULL)
9+
sprintf(buf,"AT+%s\r\n",cmd);
10+
else
11+
sprintf(buf,"AT+%s=%s\r\n",cmd,date);
12+
13+
Serial2.write(buf);
14+
}
15+
//AT+CSQ=?
16+
void get_time(void){
17+
IotWriteCommand("CSQ=?",NULL);
18+
while(Serial2.available()){
19+
uint8_t ch = Serial2.read();
20+
Serial.write(ch);
21+
M5.Lcd.write(ch);
22+
}
23+
}
24+
25+
void setup() {
26+
M5.begin();
27+
28+
Serial.begin(115200);
29+
Serial2.begin(115200, SERIAL_8N1, 16, 17);
30+
pinMode(5, OUTPUT);
31+
digitalWrite(5, 1);
32+
}
33+
34+
void loop() {
35+
if(M5.BtnA.wasReleased()){
36+
M5.Lcd.fillScreen(TFT_BLACK);
37+
M5.Lcd.setCursor(60,80,2);
38+
get_time();
39+
}
40+
M5.update();
41+
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
LoRa Duplex communication
3+
4+
Sends a message every half second, and polls continually
5+
for new incoming messages. Implements a one-byte addressing scheme,
6+
with 0xFF as the broadcast address.
7+
8+
Uses readString() from Stream class to read payload. The Stream class'
9+
timeout may affect other functuons, like the radio's callback. For an
10+
11+
created 28 April 2017
12+
by Tom Igoe
13+
*/
14+
#include <M5Stack.h>
15+
#include <M5LoRa.h>
16+
17+
String outgoing; // outgoing message
18+
19+
byte msgCount = 0; // count of outgoing messages
20+
byte localAddress = 0xFF; // address of this device
21+
byte destination = 0xBB; // destination to send to
22+
23+
long lastSendTime = 0; // last send time
24+
int interval = 1000; // interval between sends
25+
26+
void setup() {
27+
M5.begin();
28+
while (!Serial);
29+
30+
Serial.println("LoRa Duplex B");
31+
32+
// override the default CS, reset, and IRQ pins (optional)
33+
LoRa.setPins();// set CS, reset, IRQ pin
34+
35+
if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz
36+
Serial.println("LoRa init failed. Check your connections.");
37+
while (true); // if failed, do nothing
38+
}
39+
40+
Serial.println("LoRa init succeeded.");
41+
}
42+
43+
void loop() {
44+
if (millis() - lastSendTime > interval) {
45+
String message = "HeLoRa World!"; // send a message
46+
sendMessage(message);
47+
Serial.println("Sending " + message);
48+
M5.Lcd.setTextColor(BLUE);
49+
M5.Lcd.println("Sending " + message);
50+
lastSendTime = millis(); // timestamp the message
51+
interval = random(1000) + 500; // 2-3 seconds
52+
}
53+
54+
// parse for a packet, and call onReceive with the result:
55+
onReceive(LoRa.parsePacket());
56+
57+
if(M5.BtnA.wasPressed()){
58+
M5.Lcd.setCursor(0, 0);
59+
M5.Lcd.clear(BLACK);
60+
}
61+
62+
if(M5.BtnB.wasPressed()){
63+
reinit();
64+
}
65+
66+
M5.update();
67+
}
68+
69+
void reinit(){
70+
Serial.println("LoRa Duplex Reinitialization");
71+
72+
// override the default CS, reset, and IRQ pins (optional)
73+
LoRa.setPins();// set CS, reset, IRQ pin
74+
75+
if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz
76+
Serial.println("LoRa init failed. Check your connections.");
77+
M5.Lcd.setCursor(0, 0);
78+
M5.Lcd.setTextColor(RED);
79+
M5.Lcd.println("Init failed!!!");
80+
while (true); // if failed, do nothing
81+
}
82+
83+
Serial.println("LoRa init succeeded.");
84+
}
85+
86+
void sendMessage(String outgoing) {
87+
LoRa.beginPacket(); // start packet
88+
LoRa.write(destination); // add destination address
89+
LoRa.write(localAddress); // add sender address
90+
LoRa.write(msgCount); // add message ID
91+
LoRa.write(outgoing.length()); // add payload length
92+
LoRa.print(outgoing); // add payload
93+
LoRa.endPacket(); // finish packet and send it
94+
msgCount++; // increment message ID
95+
}
96+
97+
void onReceive(int packetSize) {
98+
if (packetSize == 0) return; // if there's no packet, return
99+
100+
// read packet header bytes:
101+
int recipient = LoRa.read(); // recipient address
102+
byte sender = LoRa.read(); // sender address
103+
byte incomingMsgId = LoRa.read(); // incoming msg ID
104+
byte incomingLength = LoRa.read(); // incoming msg length
105+
106+
String incoming = "";
107+
108+
while (LoRa.available()) {
109+
incoming += (char)LoRa.read();
110+
}
111+
112+
if (incomingLength != incoming.length()) { // check length for error
113+
Serial.println("error: message length does not match length");
114+
return; // skip rest of function
115+
}
116+
117+
// if the recipient isn't this device or broadcast,
118+
if (recipient != localAddress && recipient != 0xFF) {
119+
Serial.println("This message is not for me.");
120+
return; // skip rest of function
121+
}
122+
123+
// if message is for this device, or broadcast, print details:
124+
Serial.println("Received from: 0x" + String(sender, HEX));
125+
Serial.println("Sent to: 0x" + String(recipient, HEX));
126+
Serial.println("Message ID: " + String(incomingMsgId));
127+
Serial.println("Message length: " + String(incomingLength));
128+
Serial.println("Message: " + incoming);
129+
Serial.println("RSSI: " + String(LoRa.packetRssi()));
130+
Serial.println("Snr: " + String(LoRa.packetSnr()));
131+
Serial.println();
132+
133+
M5.Lcd.setTextColor(YELLOW);
134+
M5.Lcd.println("Message: " + incoming);
135+
}

0 commit comments

Comments
 (0)