From c11356b4e52202ef0ed572fc5e82f59dda4e2bef Mon Sep 17 00:00:00 2001 From: Anson He Date: Thu, 10 Dec 2020 16:52:16 +0800 Subject: [PATCH] Clear up Arduino examples for all Arduino boards --- examples/OBDII_PIDs/OBDII_PIDs.ino | 16 +++++++++++++--- examples/gpioRead/gpioRead.ino | 18 ++++++++++++++++-- examples/gpioWrite/gpioWrite.ino | 19 +++++++++++++++++-- examples/receive_Blink/receive_Blink.ino | 16 +++++++++++++--- examples/receive_check/receive_check.ino | 18 ++++++++++++++---- .../receive_interrupt/receive_interrupt.ino | 15 ++++++++++++--- .../receive_interruptFD.ino | 4 ++-- examples/recv_sd/recv_sd.ino | 17 +++++++++++++---- examples/send/send.ino | 17 +++++++++++++---- examples/sendFD/sendFD.ino | 16 ++++++++-------- examples/send_Blink/send_Blink.ino | 18 ++++++++++++++---- .../set_mask_filter_recv.ino | 14 ++++++++++++-- .../set_mask_filter_send.ino | 19 +++++++++++++++---- 13 files changed, 162 insertions(+), 45 deletions(-) diff --git a/examples/OBDII_PIDs/OBDII_PIDs.ino b/examples/OBDII_PIDs/OBDII_PIDs.ino index 1623f04..011ea3c 100644 --- a/examples/OBDII_PIDs/OBDII_PIDs.ino +++ b/examples/OBDII_PIDs/OBDII_PIDs.ino @@ -23,15 +23,25 @@ #define SERIAL Serial #endif -#define CAN_2518FD -//#define CAN_2515 +#define CAN_2515 +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; +const int SPI_CS_PIN = 9; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/gpioRead/gpioRead.ino b/examples/gpioRead/gpioRead.ino index 7e54ae1..123233a 100644 --- a/examples/gpioRead/gpioRead.ino +++ b/examples/gpioRead/gpioRead.ino @@ -4,8 +4,22 @@ #include "mcp2515_can.h" #include "mcp2518fd_can.h" -#define CAN_2518FD -#define SPI_CS_PIN BCM8 +#define CAN_2515 +// #define CAN_2518FD + +// the cs pin of the version after v1.1 is default to D9 +// v0.9b and v1.0 is default D10 + +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + +#define SPI_CS_PIN 9 /*SAMD core*/ #ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE diff --git a/examples/gpioWrite/gpioWrite.ino b/examples/gpioWrite/gpioWrite.ino index 5d613b1..10bf7f9 100644 --- a/examples/gpioWrite/gpioWrite.ino +++ b/examples/gpioWrite/gpioWrite.ino @@ -11,8 +11,23 @@ #define SERIAL Serial #endif -#define CAN_2518FD -#define SPI_CS_PIN BCM8 + +#define CAN_2515 +// #define CAN_2518FD + +// the cs pin of the version after v1.1 is default to D9 +// v0.9b and v1.0 is default D10 + +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + +#define SPI_CS_PIN 9 #ifdef CAN_2518FD mcp2518fd CAN(SPI_CS_PIN); // Set CS pin diff --git a/examples/receive_Blink/receive_Blink.ino b/examples/receive_Blink/receive_Blink.ino index 3823e68..457c21c 100644 --- a/examples/receive_Blink/receive_Blink.ino +++ b/examples/receive_Blink/receive_Blink.ino @@ -12,14 +12,24 @@ #endif #define CAN_2515 -//#define CAN_2518FD +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; -const int CAN_INT_PIN = BCM25; +const int SPI_CS_PIN = 9; +const int CAN_INT_PIN = 2; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/receive_check/receive_check.ino b/examples/receive_check/receive_check.ino index dd9c8ba..2a00eca 100644 --- a/examples/receive_check/receive_check.ino +++ b/examples/receive_check/receive_check.ino @@ -11,15 +11,25 @@ #define SERIAL Serial #endif -//#define CAN_2515 -#define CAN_2518FD +#define CAN_2515 +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; -const int CAN_INT_PIN = BCM25; +const int SPI_CS_PIN = 9; +const int CAN_INT_PIN = 2; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/receive_interrupt/receive_interrupt.ino b/examples/receive_interrupt/receive_interrupt.ino index 8864beb..59e02b2 100644 --- a/examples/receive_interrupt/receive_interrupt.ino +++ b/examples/receive_interrupt/receive_interrupt.ino @@ -12,15 +12,24 @@ #endif #define CAN_2515 -//#define CAN_2518FD +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; -const int CAN_INT_PIN = BCM25; +const int SPI_CS_PIN = 9; +const int CAN_INT_PIN = 2; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/receive_interruptFD/receive_interruptFD.ino b/examples/receive_interruptFD/receive_interruptFD.ino index fb4db75..266b2f8 100644 --- a/examples/receive_interruptFD/receive_interruptFD.ino +++ b/examples/receive_interruptFD/receive_interruptFD.ino @@ -16,8 +16,8 @@ // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 -const int SPI_CS_PIN = BCM8; -const int CAN_INT_PIN = BCM25; +const int SPI_CS_PIN = 9; +const int CAN_INT_PIN = 2; #ifdef CAN_2518FD mcp2518fd CAN(SPI_CS_PIN); // Set CS pin diff --git a/examples/recv_sd/recv_sd.ino b/examples/recv_sd/recv_sd.ino index 00054f7..25c8a94 100644 --- a/examples/recv_sd/recv_sd.ino +++ b/examples/recv_sd/recv_sd.ino @@ -15,16 +15,25 @@ File myFile; -//#define CAN_2515 -#define CAN_2518FD +#define CAN_2515 +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; -const int CAN_INT_PIN = BCM25; +const int SPI_CS_PIN = 9; +const int CAN_INT_PIN = 2; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/send/send.ino b/examples/send/send.ino index 3709fea..7efefeb 100644 --- a/examples/send/send.ino +++ b/examples/send/send.ino @@ -12,16 +12,25 @@ #endif -//#define CAN_2515 -#define CAN_2518FD +#define CAN_2515 +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; -const int CAN_INT_PIN = BCM25; +const int SPI_CS_PIN = 9; +const int CAN_INT_PIN = 2; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/sendFD/sendFD.ino b/examples/sendFD/sendFD.ino index f592228..fd25200 100644 --- a/examples/sendFD/sendFD.ino +++ b/examples/sendFD/sendFD.ino @@ -12,11 +12,10 @@ #define SERIAL Serial #endif - #define CAN_2518FD // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 -const int SPI_CS_PIN = BCM8; +const int SPI_CS_PIN = 9; #ifdef CAN_2518FD mcp2518fd CAN(SPI_CS_PIN); // Set CS pin @@ -25,14 +24,15 @@ mcp2518fd CAN(SPI_CS_PIN); // Set CS pin void setup() { SERIAL.begin(115200); while(!Serial){}; - CAN.setMode(0); + CAN.setMode(0); // Set FD Mode while (0 != CAN.begin((byte)CAN_500K_1M)) { // init can bus : baudrate = 500k SERIAL.println("CAN BUS Shield init fail"); SERIAL.println(" Init CAN BUS Shield again"); delay(100); } byte mode = CAN.getMode(); - SERIAL.printf("CAN BUS get mode = %d\n\r",mode); + SERIAL.print("CAN BUS get mode = "); + SERIAL.println(mode); SERIAL.println("CAN BUS Shield init ok!"); } @@ -42,11 +42,11 @@ void loop() { stmp[63] = stmp[63] + 1; if (stmp[63] == 100) { stmp[63] = 0; - stmp[63] = stmp[63] + 1; + stmp[62] = stmp[62] + 1; - if (stmp[6] == 100) { - stmp[6] = 0; - stmp[5] = stmp[6] + 1; + if (stmp[62] == 100) { + stmp[62] = 0; + stmp[61] = stmp[62] + 1; } } diff --git a/examples/send_Blink/send_Blink.ino b/examples/send_Blink/send_Blink.ino index 6d95c2a..b5f13c7 100644 --- a/examples/send_Blink/send_Blink.ino +++ b/examples/send_Blink/send_Blink.ino @@ -8,15 +8,25 @@ #define SERIAL Serial #endif -//#define CAN_2515 -#define CAN_2518FD +#define CAN_2515 +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; -const int CAN_INT_PIN = BCM25; +const int SPI_CS_PIN = 9; +const int CAN_INT_PIN = 2; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/set_mask_filter_recv/set_mask_filter_recv.ino b/examples/set_mask_filter_recv/set_mask_filter_recv.ino index b52db36..b5bf063 100644 --- a/examples/set_mask_filter_recv/set_mask_filter_recv.ino +++ b/examples/set_mask_filter_recv/set_mask_filter_recv.ino @@ -12,14 +12,24 @@ #define SERIAL Serial #endif -//#define CAN_2518FD #define CAN_2515 +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; +const int SPI_CS_PIN = 9; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif diff --git a/examples/set_mask_filter_send/set_mask_filter_send.ino b/examples/set_mask_filter_send/set_mask_filter_send.ino index 796744f..848d925 100644 --- a/examples/set_mask_filter_send/set_mask_filter_send.ino +++ b/examples/set_mask_filter_send/set_mask_filter_send.ino @@ -2,8 +2,6 @@ // this demo will show you how to use mask and filter #include -#define CAN_2518FD -//#define CAN_2515 /*SAMD core*/ #ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE #define SERIAL SerialUSB @@ -11,11 +9,24 @@ #define SERIAL Serial #endif +#define CAN_2515 +// #define CAN_2518FD + // the cs pin of the version after v1.1 is default to D9 // v0.9b and v1.0 is default D10 + +// Set SPI CS Pin according to your hardware +// For Wio Terminal w/ MCP2518FD RPi Hat: +// Channel 0 SPI_CS Pin: BCM 8 +// Channel 1 SPI_CS Pin: BCM 7 +// Interupt Pin: BCM25 +// ***************************************** +// For Arduino MCP2515 Hat: +// SPI_CS Pin: D9 + #ifdef CAN_2518FD #include "mcp2518fd_can.h" -const int SPI_CS_PIN = BCM8; +const int SPI_CS_PIN = 9; mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #endif @@ -23,7 +34,7 @@ mcp2518fd CAN(SPI_CS_PIN); // Set CS pin #include "mcp2515_can.h" const int SPI_CS_PIN = 9; mcp2515_can CAN(SPI_CS_PIN); // Set CS pin -#endif +#endif void setup() {