Skip to content

Commit 7bd882a

Browse files
authored
Merge pull request #2 from m5stack/master
pull origin
2 parents ae44fbf + 3727ac9 commit 7bd882a

File tree

96 files changed

+64887
-47
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+64887
-47
lines changed

docs/M-BUS.jpg

58.7 KB
Loading
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* You only need to format SPIFFS the first time you run a
3+
test or else use the SPIFFS plugin to create a partition
4+
https://github.com/me-no-dev/arduino-esp32fs-plugin
5+
* put jpg or bmp file in (<project directory>/data)
6+
* Select Tools > ESP32 Sketch Data Upload menu item. This should start uploading the files into ESP32 flash file system.
7+
*/
8+
9+
#include "FS.h"
10+
#include "SPIFFS.h"
11+
#include "M5Stack.h"
12+
13+
void setup(){
14+
M5.begin(true, false, false, false);
15+
Serial.begin(115200);
16+
if(!SPIFFS.begin(true)){
17+
Serial.println("SPIFFS Mount Failed");
18+
return;
19+
}
20+
M5.Lcd.drawJpgFile(SPIFFS, "/m5_logo.jpg", 0, 0);
21+
}
22+
23+
void loop(){
24+
M5.update();
25+
if(M5.BtnA.wasPressed()) {
26+
M5.Lcd.drawBmpFile(SPIFFS, "/pcd.bmp", 0, 0);
27+
}
28+
if(M5.BtnB.wasPressed()) {
29+
M5.Lcd.drawJpgFile(SPIFFS, "/m5_logo.jpg", 0, 0);
30+
}
31+
}
22.2 KB
Loading
Binary file not shown.

examples/Basics/PowerOFF/PowerOFF.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ void setup(){
99
// Lcd display
1010
M5.Lcd.println("This is software power off demo");
1111
M5.Lcd.println("Press the button A to power off.");
12-
13-
// Set the wakeup button
14-
M5.setWakeupButton(BUTTON_A_PIN);
1512
}
1613

1714
// the loop routine runs over and over again forever
1815
void loop() {
1916

2017
if(M5.BtnA.wasPressed()) {
21-
M5.powerOFF();
18+
M5.Power.powerOFF();
2219
}
2320

2421
M5.update();
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
Please add MCP_CAN_LIB to your library first........
3+
MCP_CAN_LIB file in M5stack lib examples -> modules -> COMMU -> MCP_CAN_lib.rar
4+
*/
5+
6+
#include <M5Stack.h>
7+
#include <mcp_can.h>
8+
#include "m5_logo.h"
9+
10+
/**
11+
* variable for loop
12+
*/
13+
14+
byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
15+
16+
17+
/**
18+
* variable for CAN
19+
*/
20+
long unsigned int rxId;
21+
unsigned char len = 0;
22+
unsigned char rxBuf[8];
23+
char msgString[128]; // Array to store serial string
24+
25+
#define CAN0_INT 15 // Set INT to pin 2
26+
MCP_CAN CAN0(12); // Set CS to pin 10
27+
28+
void init_can();
29+
void test_can();
30+
31+
void setup() {
32+
M5.begin();
33+
Serial.begin(9600);
34+
Serial2.begin(9600, SERIAL_8N1, 16, 17);
35+
36+
M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
37+
delay(500);
38+
M5.Lcd.setTextColor(BLACK);
39+
// M5.Lcd.setTextSize(1);
40+
41+
init_can();
42+
Serial.println("Test CAN...");
43+
}
44+
45+
void loop() {
46+
if(M5.BtnA.wasPressed())
47+
{
48+
M5.Lcd.clear();
49+
M5.Lcd.printf("CAN Test A!\n");
50+
M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
51+
init_can();
52+
Serial.println("Test CAN...");
53+
}
54+
test_can();
55+
M5.update();
56+
}
57+
58+
void init_can(){
59+
M5.Lcd.setTextSize(1);
60+
M5.Lcd.setCursor(0, 10);
61+
M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
62+
delay(500);
63+
64+
M5.Lcd.printf("CAN Test A!\n");
65+
M5.Lcd.printf("Receive first, then testing for sending function!\n");
66+
67+
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
68+
if(CAN0.begin(MCP_ANY, CAN_1000KBPS, MCP_8MHZ) == CAN_OK)
69+
Serial.println("MCP2515 Initialized Successfully!");
70+
else
71+
Serial.println("Error Initializing MCP2515...");
72+
73+
CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the MCP2515 sends acks to received data.
74+
75+
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
76+
77+
Serial.println("MCP2515 Library Receive Example...");
78+
}
79+
80+
void test_can(){
81+
if(!digitalRead(CAN0_INT)) // If CAN0_INT pin is low, read receive buffer
82+
{
83+
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
84+
85+
if((rxId & 0x80000000) == 0x80000000) // Determine if ID is standard (11 bits) or extended (29 bits)
86+
sprintf(msgString, "Extended ID: 0x%.8lX DLC: %1d Data:", (rxId & 0x1FFFFFFF), len);
87+
else
88+
sprintf(msgString, "Standard ID: 0x%.3lX DLC: %1d Data:", rxId, len);
89+
90+
Serial.print(msgString);
91+
M5.Lcd.printf(msgString);
92+
if((rxId & 0x40000000) == 0x40000000){ // Determine if message is a remote request frame.
93+
sprintf(msgString, " REMOTE REQUEST FRAME");
94+
Serial.print(msgString);
95+
} else {
96+
for(byte i = 0; i<len; i++){
97+
sprintf(msgString, " 0x%.2X", rxBuf[i]);
98+
Serial.print(msgString);
99+
M5.Lcd.printf(msgString);
100+
}
101+
}
102+
M5.Lcd.printf("\n");
103+
Serial.println();
104+
}
105+
}

examples/Modules/COMMU/CAN/commu_can_receiver/m5_logo.h

Lines changed: 9603 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
please add MCP_CAN_LIB to your library first........
3+
MCP_CAN_LIB file in M5stack lib examples -> modules -> COMMU -> MCP_CAN_lib.rar
4+
*/
5+
6+
#include <M5Stack.h>
7+
#include <mcp_can.h>
8+
#include "m5_logo.h"
9+
10+
/**
11+
* variable for loop
12+
*/
13+
14+
byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
15+
16+
/**
17+
* variable for CAN
18+
*/
19+
long unsigned int rxId;
20+
unsigned char len = 0;
21+
unsigned char rxBuf[8];
22+
char msgString[128];
23+
24+
#define CAN0_INT 15 // Set INT to pin 2
25+
MCP_CAN CAN0(12); // Set CS to pin 10
26+
27+
void init_can();
28+
void test_can();
29+
30+
31+
void setup() {
32+
M5.begin();
33+
Serial.begin(9600);
34+
Serial2.begin(9600, SERIAL_8N1, 16, 17);
35+
36+
M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
37+
delay(500);
38+
M5.Lcd.setTextColor(BLACK);
39+
// M5.Lcd.setTextSize(1);
40+
41+
init_can();
42+
Serial.println("Test CAN...");
43+
}
44+
45+
void loop() {
46+
if(M5.BtnA.wasPressed())
47+
{
48+
M5.Lcd.clear();
49+
M5.Lcd.printf("CAN Test B!\n");
50+
M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
51+
init_can();
52+
}
53+
test_can();
54+
M5.update();
55+
}
56+
57+
void init_can(){
58+
M5.Lcd.setTextSize(1);
59+
M5.Lcd.setCursor(0, 10);
60+
M5.Lcd.pushImage(0, 0, 320, 240, (uint16_t *)gImage_logoM5);
61+
M5.Lcd.printf("CAN Test B!\n");
62+
63+
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
64+
if(CAN0.begin(MCP_ANY, CAN_1000KBPS, MCP_8MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!");
65+
else Serial.println("Error Initializing MCP2515...");
66+
67+
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
68+
}
69+
70+
void test_can(){
71+
// send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
72+
byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
73+
if(sndStat == CAN_OK){
74+
Serial.println("Message Sent Successfully!");
75+
M5.Lcd.printf("Message Sent Successfully!\n");
76+
} else {
77+
Serial.println("Error Sending Message...");
78+
M5.Lcd.printf("Error Sending Message...\n");
79+
}
80+
delay(200); // send data per 200ms
81+
}

0 commit comments

Comments
 (0)