Skip to content

Commit 0aff06c

Browse files
committed
Add some head
1 parent 0eeeef6 commit 0aff06c

4 files changed

Lines changed: 107 additions & 106 deletions

File tree

examples/Unit/CAN/CAN.ino

Lines changed: 74 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
/*
2-
Description: insert CAN Unit to PORT-B,Press buttonA or buttonB to Send message
3-
if received message, screen will display
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core sample source code
5+
* 配套 M5Core 示例源代码
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/8/30
11+
*******************************************************************************
12+
Please connect to PORT-B,Press buttonA or buttonB to Send message if received message, screen will display
13+
请连接端口B,按钮A或按钮B发送消息,如果收到消息,屏幕将显示
414
*/
515

616
#include <M5Stack.h>
@@ -14,100 +24,82 @@ CAN_device_t CAN_cfg; // CAN Config
1424

1525
int i = 0;
1626

17-
void header(const char *string, uint16_t color)
18-
{
19-
M5.Lcd.fillScreen(color);
20-
M5.Lcd.setTextSize(1);
21-
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
22-
M5.Lcd.fillRect(0, 0, 320, 30, TFT_BLACK);
23-
M5.Lcd.setTextDatum(TC_DATUM);
24-
M5.Lcd.drawString(string, 160, 3, 4);
25-
}
26-
2727
void setup() {
2828
M5.begin(true, false, true);
2929
M5.Power.begin();
30-
Serial.println("CAN Unit Send&Received");
31-
header("CAN-Bus Send&Received", BLACK);
30+
M5.Lcd.drawString("CAN Unit Send&Received", 40, 3, 4);
3231
M5.Lcd.setCursor(0, 60, 4);
33-
34-
CAN_cfg.speed = CAN_SPEED_125KBPS;
35-
CAN_cfg.tx_pin_id = TX;
32+
33+
CAN_cfg.speed = CAN_SPEED_125KBPS; //Set the Can speed
34+
CAN_cfg.tx_pin_id = TX; //Set the Pin foot
3635
CAN_cfg.rx_pin_id = RX;
3736

3837
CAN_cfg.rx_queue = xQueueCreate(10,sizeof(CAN_frame_t));
39-
40-
// Init CAN Module
41-
ESP32Can.CANInit();
38+
39+
ESP32Can.CANInit(); // Init CAN Module. 初始化Can
4240
}
4341

4442
void loop() {
43+
CAN_frame_t rx_frame;
4544

46-
CAN_frame_t rx_frame;
47-
48-
if(M5.BtnA.wasPressed()){
49-
rx_frame.FIR.B.FF = CAN_frame_std;
50-
rx_frame.MsgID = 1;
51-
rx_frame.FIR.B.DLC = 8;
52-
rx_frame.data.u8[0] = 'H';
53-
rx_frame.data.u8[1] = 'e';
54-
rx_frame.data.u8[2] = 'l';
55-
rx_frame.data.u8[3] = 'l';
56-
rx_frame.data.u8[4] = 'o';
57-
rx_frame.data.u8[5] = 'C';
58-
rx_frame.data.u8[6] = 'A';
59-
rx_frame.data.u8[7] = 'N';
60-
61-
ESP32Can.CANWriteFrame(&rx_frame);
62-
M5.Lcd.println("Send Message");
63-
}
64-
if(M5.BtnB.wasPressed()){
65-
rx_frame.FIR.B.FF = CAN_frame_std;
66-
rx_frame.MsgID = 1;
67-
rx_frame.FIR.B.DLC = 8;
68-
rx_frame.data.u8[0] = 'M';
69-
rx_frame.data.u8[1] = '5';
70-
rx_frame.data.u8[2] = 'S';
71-
rx_frame.data.u8[3] = 'T';
72-
rx_frame.data.u8[4] = 'A';
73-
rx_frame.data.u8[5] = 'C';
74-
rx_frame.data.u8[6] = 'K';
75-
rx_frame.data.u8[7] = ' ';
76-
77-
ESP32Can.CANWriteFrame(&rx_frame);
78-
M5.Lcd.println("Send Message");
79-
Serial.println("B");
80-
}
45+
if(M5.BtnA.wasPressed()){
46+
rx_frame.FIR.B.FF = CAN_frame_std;
47+
rx_frame.MsgID = 1;
48+
rx_frame.FIR.B.DLC = 8;
49+
rx_frame.data.u8[0] = 'H';
50+
rx_frame.data.u8[1] = 'e';
51+
rx_frame.data.u8[2] = 'l';
52+
rx_frame.data.u8[3] = 'l';
53+
rx_frame.data.u8[4] = 'o';
54+
rx_frame.data.u8[5] = 'C';
55+
rx_frame.data.u8[6] = 'A';
56+
rx_frame.data.u8[7] = 'N';
8157

82-
83-
if(xQueueReceive(CAN_cfg.rx_queue,&rx_frame, 3*portTICK_PERIOD_MS)==pdTRUE){
58+
ESP32Can.CANWriteFrame(&rx_frame);
59+
M5.Lcd.println("Send Message1");
60+
}
61+
if(M5.BtnB.wasPressed()){
62+
rx_frame.FIR.B.FF = CAN_frame_std;
63+
rx_frame.MsgID = 1;
64+
rx_frame.FIR.B.DLC = 8;
65+
rx_frame.data.u8[0] = 'M';
66+
rx_frame.data.u8[1] = '5';
67+
rx_frame.data.u8[2] = 'S';
68+
rx_frame.data.u8[3] = 'T';
69+
rx_frame.data.u8[4] = 'A';
70+
rx_frame.data.u8[5] = 'C';
71+
rx_frame.data.u8[6] = 'K';
72+
rx_frame.data.u8[7] = ' ';
73+
ESP32Can.CANWriteFrame(&rx_frame);
74+
M5.Lcd.println("Send Message2");
75+
Serial.println("B");
76+
}
8477

85-
M5.Lcd.fillRect(0, 60, 320, 180, BLACK);
86-
M5.Lcd.setCursor(0, 60, 4);
87-
//do stuff!
88-
if(rx_frame.FIR.B.FF==CAN_frame_std){
89-
printf("New standard frame");
90-
M5.Lcd.printf("New standard frame");
91-
} else{
92-
printf("New extended frame");
93-
M5.Lcd.printf("New extended frame");
94-
}
95-
if(rx_frame.FIR.B.RTR==CAN_RTR){
96-
printf(" RTR from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
97-
M5.Lcd.printf(" RTR from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
98-
} else{
99-
printf(" from 0x%08x, DLC %d\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
100-
M5.Lcd.printf(" from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
101-
for(int i = 0; i < 8; i++){
102-
printf("%c\t", (char)rx_frame.data.u8[i]);
103-
M5.Lcd.printf("%c\t", (char)rx_frame.data.u8[i]);
104-
}
105-
printf("\n");
78+
if(xQueueReceive(CAN_cfg.rx_queue,&rx_frame, 3*portTICK_PERIOD_MS)==pdTRUE){
79+
M5.Lcd.fillRect(0, 60, 320, 180, BLACK);
80+
M5.Lcd.setCursor(0, 60, 4);
81+
//do stuff!
82+
if(rx_frame.FIR.B.FF==CAN_frame_std){
83+
printf("New standard frame");
84+
M5.Lcd.printf("New standard frame");
85+
} else{
86+
printf("New extended frame");
87+
M5.Lcd.printf("New extended frame");
88+
}
89+
if(rx_frame.FIR.B.RTR==CAN_RTR){
90+
printf(" RTR from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
91+
M5.Lcd.printf(" RTR from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
92+
} else{
93+
printf(" from 0x%08x, DLC %d\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
94+
M5.Lcd.printf(" from 0x%08x, DLC %d\r\n",rx_frame.MsgID, rx_frame.FIR.B.DLC);
95+
for(int i = 0; i < 8; i++){
96+
printf("%c\t", (char)rx_frame.data.u8[i]);
97+
M5.Lcd.printf("%c\t", (char)rx_frame.data.u8[i]);
10698
}
99+
printf("\n");
107100
}
101+
}
108102

109-
110-
M5.update();
111-
delay(200);
112-
103+
M5.update();
104+
delay(200);
113105
}

examples/Unit/PaHUB_TCA9548A/PaHUB_TCA9548A.ino

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,36 @@ void setup()
2121
{
2222
M5.begin();
2323
M5.Power.begin();
24-
25-
Wire.begin();
26-
M5.Lcd.fillScreen(TFT_BLACK);
27-
tca9548a.address(PaHub_I2C_ADDRESS);
24+
tca9548a.address(PaHub_I2C_ADDRESS);
2825
M5.Lcd.setTextFont(4);
2926
M5.Lcd.setCursor(70, 0, 4);
3027
M5.Lcd.setTextColor(YELLOW,TFT_BLACK);
3128
M5.Lcd.println(("PaHUB Example"));
3229
M5.Lcd.setTextColor(TFT_WHITE,TFT_BLACK);
33-
3430
}
3531

3632
void PaHUB(void){
3733

3834
uint8_t returnCode = 0;
3935
uint8_t address;
40-
for( uint8_t channel=0; channel<TCA9548A_MAX_CHANNELS; channel++ ) {
41-
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET*channel , FRONT);
42-
M5.Lcd.printf(" ");
43-
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET*channel , FRONT);
44-
M5.Lcd.printf("CH%d : ",channel);
45-
returnCode = tca9548a.selectChannel(channel);
46-
if( returnCode == 0 ) {
47-
for(address = 0x01; address < 0x7F; address++ ) {
48-
Wire.beginTransmission(address);
49-
returnCode = Wire.endTransmission();
50-
if (returnCode == 0) {
51-
Serial.print("I2C device = ");
52-
M5.Lcd.printf("0X%X ",address);
53-
}
54-
}
55-
}
56-
delay(200);
57-
36+
for( uint8_t channel=0; channel<TCA9548A_MAX_CHANNELS; channel++ ) {
37+
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET*channel , FRONT);
38+
M5.Lcd.printf(" ");
39+
M5.Lcd.setCursor(X_LOCAL, Y_LOCAL + Y_OFFSET*channel , FRONT);
40+
M5.Lcd.printf("CH%d : ",channel);
41+
returnCode = tca9548a.selectChannel(channel);
42+
if( returnCode == 0 ) {
43+
for(address = 0x01; address < 0x7F; address++ ) {
44+
Wire.beginTransmission(address);
45+
returnCode = Wire.endTransmission();
46+
if (returnCode == 0) {
47+
Serial.print("I2C device = ");
48+
M5.Lcd.printf("0X%X ",address);
49+
}
50+
}
5851
}
52+
delay(200);
53+
}
5954
}
6055

6156
void loop()

examples/Unit/UHF_RFID_JRD4035/UHF_RFID_JRD4035.ino

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core sample source code
5+
* 配套 M5Core 示例源代码
6+
* Visit the website for more information:https://docs.m5stack.com/en/unit/uhf_rfid
7+
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/unit/uhf_rfid
8+
*
9+
* describe: uhf_rfid.
10+
* date:2021/8/30
11+
*******************************************************************************
12+
Please connect to PORT-B,Press buttonA or buttonB to Send message if received message, screen will display
13+
请连接端口B,按钮A或按钮B发送消息,如果收到消息,屏幕将显示
14+
*/
115
#include <M5Stack.h>
216
#include "RFID_command.h"
317

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Device Control
88
url=https://github.com/m5stack/m5stack
99
architectures=esp32
1010
includes=M5Stack.h
11-
depends=M5GFX,UNIT_ENV,UNIT_4RELAY,ADXL345,FastLED,MODULE_GRBL13.2,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,MAX30100lib,MFRC522_I2C,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_Finger,HX711 Arduino Library,PCA9554,TinyGPSPlus,Adafruit SGP30 Sensor,FFT,TFTTerminal
11+
depends=M5GFX,UNIT_ENV,UNIT_4RELAY,ADXL345,FastLED,MODULE_GRBL13.2,Adafruit MCP4725,Adafruit TCS34725,Adafruit NeoPixel,MAX30100lib,MFRC522_I2C,M5_BM8563,M5_ADS1100,M5_ADS1115,M5_Finger,HX711 Arduino Library,PCA9554,TinyGPSPlus,Adafruit SGP30 Sensor,FFT,TFTTerminal,ClosedCube TCA9548A

0 commit comments

Comments
 (0)