CAN BUS Shield for Arduino (แท้จาก DFRobot)

CAN BUS Shield for Arduino (แท้จาก DFRobot)
CAN BUS Shield for Arduino (แท้จาก DFRobot)CAN BUS Shield for Arduino (แท้จาก DFRobot)CAN BUS Shield for Arduino (แท้จาก DFRobot)CAN BUS Shield for Arduino (แท้จาก DFRobot)CAN BUS Shield for Arduino (แท้จาก DFRobot)CAN BUS Shield for Arduino (แท้จาก DFRobot)CAN BUS Shield for Arduino (แท้จาก DFRobot)CAN BUS Shield for Arduino (แท้จาก DFRobot)
รหัสสินค้า SA00162
หมวดหมู่ CAN Bus / LIN Bus / OBD
ราคา 1,250.00 บาท
สถานะสินค้า พร้อมส่ง
จำนวน
ชิ้น
หยิบลงตะกร้า
หนังสือรับรองบริษัท
บุ๊คแบ๊งค์
คุ้มครองโดย LnwPay
ดูรายละเอียดการใช้งานได้ที่ Click

This is an Arduino CAN Bus shield.  It is compatible with the Arduino standard interface and can be stacked on an Arduino UNO, Leonardo or MEGA board.

The shield integrates an MCP2515 CANBUS chip on the shield and has a CAN-BUS transceiver function. With an on-board DB9 and CAN-BUS connector you can choose a suitable port according to your host device.

There is also an integrated MicroSD socket for data storage - a perfect solution for data logging applications.

What is CAN BUS ? Controller Area Network (CAN) BUS is a vehicle bus standard designed to allow microcontrollers and devices to communicate with each other in applications without a host computer. It is a message-based protocol, designed originally for multiplex electrical wiring within automobiles, but is also used in many other contexts.

FEATURES

  • Supports standard frame, extended frame transmitting and receiving
  • Supports two reception methods: Rotational and interrupt detection
  • Supports UART, i2C and DB9 terminal interfaces
  • Supports SD card data storage
  • Supports Arduino mainboard power supply or DB9 power supply (Switch)

SPECIFICATION

  • Chip: MCP2515
  • Power supply: 3.3 ~ 5V Arduino board power supply or DB9 interface power supply
  • Dimension: 76x54x19 (mm)/ 2.99x2.12x0.75 inches
  • Weight: 40g

DOCUMENTS

SHIPPING LIST

  • CAN-BUS Shield V2.0 x1
  • 8-Pin header x1



Tutorial

Requirements

Basic CAN BUS Receiving and sending function (receiving: polling mode)

In this section we will demonstrate basic CAN BUS receiving and sending functions. Receiving uses polling mode. You can accept any ID standard data frame or extended frame. The transmitting node sends a standard data frame which ID is 0x06 per 100ms.

Connection Diagram

DFR0370-TWO.png

Sample Code

Receiver Code
/******************************************************************************
* demo: CAN-BUS Shield, receive data with check mode
* send data coming to fast, such as less than 10ms, you can use this way
* Jansion, 2015.5.27
******************************************************************************/
#include <SPI.h>
#include "df_can.h"
const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
do {
CAN.init(); //must initialize the Can interface here!
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

}
void loop()
{
unsigned char len = 0;
unsigned char buf[8];

if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf

for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);
Serial.print("\t");
}
Serial.println();
}
}
Sender code
 // demo: CAN-BUS Shield, send data
#include <df_can.h>
#include <SPI.h>

const int SPI_CS_PIN = 10;

MCPCAN CAN(SPI_CS_PIN); // Set CS pin

void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
do {
CAN.init(); //must initialize the Can interface here!
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

}

unsigned char data[8] = {'D', 'F', 'R', 'O', 'B', 'O', 'T', '!'};
void loop()
{
// send data: id = 0x06, standrad flame, data len = 8, data: data buf
CAN.sendMsgBuf(0x06, 0, 8, data);
delay(100); // send data per 100ms
}

Result

Receiver: output in the serial port

Blune M3

Basic CAN BUS Receiving and sending function(receive:interrupt mode)

In this section we will test basic CAN BUS receiving and sending functions in this experiment, but will only receive data by interrupt mode.

Connection Diagram

DFR0370-TWO.png

Sample Code

Receiver Code
/***********************************************************
*demo: CAN-BUS Shield, receive data with interrupt mode
* when in interrupt mode, the data coming can't be too fast, must >20ms, or else you can use check mode
* Jansion, 2015-5-27
***********************************************************/
#include <SPI.h>
#include "df_can.h"

const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin


unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];

void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
do {
CAN.init(); //must initialize the Can interface here!
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);


attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
}

void MCP2515_ISR()
{
flagRecv = 1;
}

void loop()
{
if(flagRecv)
{ // check if get data

flagRecv = 0; // clear flag

// iterate over all pending messages
// If either the bus is saturated or the MCU is busy,
// both RX buffers may be in use and after having read a single
// message, MCU does clear the corresponding IRQ conditon.
while (CAN_MSGAVAIL == CAN.checkReceive())
{
// read data, len: data length, buf: data buf
CAN.readMsgBuf(&len, buf);

// print the data
for(int i = 0; i<len; i++)
{
Serial.print(buf[i]);Serial.print("\t");
}
Serial.println();
}
}
}
Sender code
 // demo: CAN-BUS Shield, send data
#include <df_can.h>
#include <SPI.h>

const int SPI_CS_PIN = 10;

MCPCAN CAN(SPI_CS_PIN); // Set CS pin

void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
do {
CAN.init(); //must initialize the Can interface here!
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

}

unsigned char data[8] = {'D', 'F', 'R', 'O', 'B', 'O', 'T', '!'};
void loop()
{
// send data: id = 0x06, standrad flame, data len = 8, data: data buf
CAN.sendMsgBuf(0x06, 0, 8, data);
delay(100); // send data per 100ms
}

Result

Receiver: output in the serial port
5-1

Accecpted to specify the data frame of the ID(receive:interrupt mode)

This test is to specify the data frame of the ID when the CAN module is initialized. Data is received using interrupt mode.

Connection Diagram

DFR0370-TWO.png]

Sample Code

Receiver Code
/**************************************************************************************************************
*demo: CAN-BUS Shield, receive data with interrupt mode, and set mask and filter
* when in interrupt mode, the data coming can't be too fast, must >20ms, or else you can use check mode
* Jansion, 2015-5-27
****************************************************************************************************************/
#include <SPI.h>
#include "df_can.h"
const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin
unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.

do {
CAN.init(); //must initialize the Can interface here!
CAN.init_Mask(MCP_RXM0, 0, 0x3ff); // there are 2 mask in mcp2515, you need to set both of them
CAN.init_Mask(MCP_RXM1, 0, 0x3ff);
/*
* set filter, we can receive id from 0x04 ~ 0x09 except for 0x06
* // there are 6 filter in mcp2515,so it can filter six id,i.e.0x04~0x09.
*/
CAN.init_Filter(MCP_RXF0, 0, 0x04); // filter 0 for id = 0x04
CAN.init_Filter(MCP_RXF1, 0, 0x05); // filter 1 for id = 0x05
// CAN.init_Filter(MCP_RXF2, 0, 0x06); // filter 2 for id = 0x06
CAN.init_Filter(MCP_RXF3, 0, 0x07); // filter 3 for id = 0x07
CAN.init_Filter(MCP_RXF4, 0, 0x08); // filter 4 for id = 0x08
CAN.init_Filter(MCP_RXF5, 0, 0x09); // filter 5 for id = 0x09
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt


/*
* set mask, set both the mask to 0x3ff
*/

}

void MCP2515_ISR()
{
flagRecv = 1;
}

void loop()
{
if(flagRecv) // check if get data
{

flagRecv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf

Serial.println("\r\n------------------------------------------------------------------");
Serial.print("Get Data From id: ");
Serial.println(CAN.getCanId());
for(int i = 0; i<len; i++) // print the data
{
Serial.print("0x");
Serial.print(buf[i], HEX);
Serial.print("\t");
}
Serial.println();

}
}
Sender code
 /***************************************************************
* demo: set_mask_filter_send
* this demo will show you how to use mask and filter
* Jansion, 2015-5-27
*****************************************************************/
#include <df_can.h>
#include <SPI.h>
const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
do {
CAN.init(); //must initialize the Can interface here!
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);
}

unsigned char data[8] = {'D', 'F', 'R', 'O', 'B', 'O', 'T', '!'};

void loop()
{
for(int id=0; id<10; id++)
{
memset(data, id, sizeof(data)); // set id to send data buff, id is arranged form 0x00 to 0x09.
CAN.sendMsgBuf(id, 0, sizeof(data), data);
delay(100);
}
}

Result

Receiver: output in the serial port
CAN-BUS Shield V2.0
The received data frame has no data from ID 0x06,0x00,0x01 or 0x02 which not matched with the ID which is set by Data acceptance filter. This shows that the filter can be a single job, or a few filters working at the same time, or all of the filters working at the same time. When all filters are not in use then can receive any data.
Three modules of the network
This tests all three modules on the network and the data transceiver situation. Each module of the three modules can be used as a receiver, and can also be used as a sender. 3 node devices are used in this experiment; node 1, node 2, node 3. Node 1 is used only as a receiving node, which can receive data frame which ID is 0x04, 0x05,0x07,0x08 and 0x09. Node 2 is used only to receive data frames form ID 0x09 and only send data form ID 0x08 which data frame is “node 2”. Node 3 only receives data frames form ID 0x08 and only send data form ID 0x09 which data frame is “node 3”.
Connection Diagram

DFR0370-THREE.png

Sample Code

Node 1 Code
/**************************************************************************************************************
*demo: CAN-BUS Shield, receive data with interrupt mode, and set mask and filter
* when in interrupt mode, the data coming can't be too fast, must >20ms, or else you can use check mode
* Jansion, 2015-5-27
****************************************************************************************************************/
#include <SPI.h>
#include "df_can.h"

const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin
unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.

do {
CAN.init(); //must initialize the Can interface here!
CAN.init_Mask(MCP_RXM0, 0, 0x3ff); // there are 2 mask in mcp2515, you need to set both of them
CAN.init_Mask(MCP_RXM1, 0, 0x3ff);
/*
* set filter, we can receive id from 0x04 ~ 0x09 except for 0x06
* // there are 6 filter in mcp2515,so it can filter six id,i.e.0x04~0x09.
*/
CAN.init_Filter(MCP_RXF0, 0, 0x04); // filter 0 for id = 0x04
CAN.init_Filter(MCP_RXF1, 0, 0x05); // filter 1 for id = 0x05
// CAN.init_Filter(MCP_RXF2, 0, 0x06); // filter 2 for id = 0x06
CAN.init_Filter(MCP_RXF3, 0, 0x07); // filter 3 for id = 0x07
CAN.init_Filter(MCP_RXF4, 0, 0x08); // filter 4 for id = 0x08
CAN.init_Filter(MCP_RXF5, 0, 0x09); // filter 5 for id = 0x09
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt


/*
* set mask, set both the mask to 0x3ff
*/

}

void MCP2515_ISR()
{
flagRecv = 1;
}

void loop()
{
if(flagRecv) // check if get data
{

flagRecv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf

Serial.println("\r\n------------------------------------------------------------------");
Serial.print("Get Data From id: ");
Serial.println(CAN.getCanId());
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);
Serial.print("\t");
}
Serial.println();

}
}
Node 2 code
#include <SPI.h>
#include "df_can.h"

const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin
unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.

do {
CAN.init(); //must initialize the Can interface here!
CAN.init_Mask(MCP_RXM0, 0, 0x3ff); // there are 2 mask in mcp2515, you need to set both of them
CAN.init_Mask(MCP_RXM1, 0, 0x3ff);
/*
* set filter, we can receive id from 0x04 ~ 0x09 except for 0x06
* // there are 6 filter in mcp2515,so it can filter six id,i.e.0x04~0x09.
*/
CAN.init_Filter(MCP_RXF5, 0, 0x09); // filter 5 for id = 0x09
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt


/*
* set mask, set both the mask to 0x3ff
*/

}

void MCP2515_ISR()
{
flagRecv = 1;
}


unsigned char data[] = "node 2";
void loop()
{
if(flagRecv) // check if get data
{
flagRecv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf

Serial.println("\r\n------------------------------------------------------------------");
Serial.print("Get Data From id: ");
Serial.println(CAN.getCanId());
for(int i = 0; i<len; i++) // print the data
{

Serial.print(buf[i]);
Serial.print("\t");
}
Serial.println();
}

// send data: id = 0x08, standrad flame, data len = 8, data: data buf
CAN.sendMsgBuf(0x08, 0, sizeof(data), data);
delay(1000); // send data per 100ms

}
Node 3 code
 #include <SPI.h>
#include "df_can.h"

const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin
unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.

do {
CAN.init(); //must initialize the Can interface here!
CAN.init_Mask(MCP_RXM0, 0, 0x3ff); // there are 2 mask in mcp2515, you need to set both of them
CAN.init_Mask(MCP_RXM1, 0, 0x3ff);
/*
* set filter, we can receive id from 0x04 ~ 0x09 except for 0x06
* // there are 6 filter in mcp2515,so it can filter six id,i.e.0x04~0x09.
*/
CAN.init_Filter(MCP_RXF5, 0, 0x08); // filter 5 for id = 0x09
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt


/*
* set mask, set both the mask to 0x3ff
*/

}

void MCP2515_ISR()
{
flagRecv = 1;
}


unsigned char data[] = "node 3";
void loop()
{
if(flagRecv) // check if get data
{
flagRecv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf

Serial.println("\r\n------------------------------------------------------------------");
Serial.print("Get Data From id: ");
Serial.println(CAN.getCanId());
for(int i = 0; i<len; i++) // print the data
{

Serial.print(buf[i]);
Serial.print("\t");
}
Serial.println();
}

// send data: id = 0x08, standrad flame, data len = 8, data: data buf
CAN.sendMsgBuf(0x09, 0, sizeof(data), data);
delay(1000); // send data per 100ms

}

Result

Output in the each serial port CAN-BUS Shield V2.0 COM10 is running Node 3 code, which only receives the ID 0x08 data frame. COM12 is running Node 2 code, which only receives the ID 0x09 data frame. COM21 is running Node 1 code, which receives the ID 0x09 and 0x08 data frame.

SD CARD Read and Write

The purpose of this experimental is receiving node receives the ten data from the sending node.And then put it into the SD card.Finally read it from SD card out and print it out through the serial port.

Connection Diagram

DFR0370-TWO.png

Sample Code

Receiver Code
 /**************************************************************************************************************
*demo: CAN-BUS Shield, receive data with interrupt mode, and set mask and filter
* when in interrupt mode, the data coming can't be too fast, must >20ms, or else you can use check mode
* Jansion, 2015-5-27
****************************************************************************************************************/
#include <SPI.h>
#include "df_can.h"
#include <SD.h>

const int SPI_CS_PIN = 10;
MCPCAN CAN(SPI_CS_PIN); // Set CS pin
unsigned char flagRecv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
char sd_cspin = 4; //pin 4 as spi_cs pin
File myFile;

void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
Serial.print("Initializing can controlor...");
do {
CAN.init(); //must initialize the Can interface here!
CAN.init_Mask(MCP_RXM0, 0, 0x3ff); // there are 2 mask in mcp2515, you need to set both of them
CAN.init_Mask(MCP_RXM1, 0, 0x3ff);
/*
* set filter, we can receive id from 0x04 ~ 0x09 except for 0x06
* // there are 6 filter in mcp2515,so it can filter six id,i.e.0x04~0x09.
*/
CAN.init_Filter(MCP_RXF0, 0, 0x04); // filter 0 for id = 0x04
CAN.init_Filter(MCP_RXF1, 0, 0x05); // filter 1 for id = 0x05
CAN.init_Filter(MCP_RXF2, 0, 0x60); // filter 2 for id = 0x60
CAN.init_Filter(MCP_RXF3, 0, 0x07); // filter 3 for id = 0x07
CAN.init_Filter(MCP_RXF4, 0, 0x08); // filter 4 for id = 0x08
CAN.init_Filter(MCP_RXF5, 0, 0x09); // filter 5 for id = 0x09
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt

Serial.print("Initializing SD card...");

if (!SD.begin(sd_cspin)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization success!");
myFile = SD.open("Node0x60.txt", FILE_WRITE); //the file named Node0x60.txt use to save the data
// with the frame id equeling 0x06.
if (!myFile)
{
Serial.println("open Node0x60.text failed!");


}
else
{
Serial.println("open Node0x60.text success!");
}
/*
* set mask, set both the mask to 0x3ff
*/

}

void MCP2515_ISR()
{
flagRecv = 1;
}
char filewrite = 1, fileread = 0;
int i = 0, j = 0;
void loop()
{

if(flagRecv) // check if get data
{
flagRecv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
if (filewrite)
{
if (i++ < 1) //only recieve one frame
{
myFile.write(buf, len);
}
else
{
myFile.close();
filewrite = 0;
myFile = SD.open("Node0x60.txt", FILE_WRITE);
if (SD.exists("Node0x60.txt")) {
Serial.println("example.txt exists.");
fileread = 1;
}
else {
Serial.println("example.txt doesn't exist.");
}
}
}
if (fileread)
{
Serial.println("printf the data that myFile has saved! ");
myFile.read(buf, len);
Serial.println((char *)buf);
Serial.println("");
myFile.close();

Serial.println("myFile closed!!!!");
fileread = 0;
}

}
}
Sender Code
 // demo: CAN-BUS Shield, send data
#include <df_can.h>
#include <SPI.h>

const int SPI_CS_PIN = 10;

MCPCAN CAN(SPI_CS_PIN); // Set CS pin

void setup()
{
Serial.begin(115200);
int count = 50; // the max numbers of initializint the CAN-BUS, if initialize failed first!.
do {
CAN.init(); //must initialize the Can interface here!
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("DFROBOT's CAN BUS Shield init ok!");
break;
}
else
{
Serial.println("DFROBOT's CAN BUS Shield init fail");
Serial.println("Please Init CAN BUS Shield again");

delay(100);
if (count <= 1)
Serial.println("Please give up trying!, trying is useless!");
}

}while(count--);

}

unsigned char data[8] = {'D', 'F', 'R', 'O', 'B', 'O', 'T', '!'};
void loop()
{
// send data: id = 0x60, standrad flame, data len = 8, data: data buf
CAN.sendMsgBuf(0x60, 0, 8, data);
delay(1000); // send data per 100ms
}

Result

Receiver: output in the serial port
CAN-BUS Shield V2.0 Experimental phenomenon analysis: the receiving node receives the data frame from ID 0x60, and deposits it in a file named Node0x60.text file. Then it closes the file. Finally, it opens the file, and reads the data and prints it through the serial port.

Protocol/Library Explanation

CAN BUS WIKIPEDIA

วิธีการชำระเงิน

ชำระเงินค่าสินค้าโดยการโอนเงินเข้าบัญชีธนาคาร KBANK, SCB, BBL,TMB

กรุณาเก็บหลักฐานการโอนเงินของท่านไว้เพื่อแจ้งการชำระเงินด้วยค่ะ

 

ท่านสามารถแจ้งการชำระเงินผ่านระบบอัตโนมัติได้โดย Click Link ข้างล่างค่ะ

https://www.arduitronics.com/informpayment

 

บมจ. ธนาคารกสิกรไทย สาขาเซ็นทรัล แจ้งวัฒนะ ออมทรัพย์
ธนาคารไทยพาณิชย์ จำกัด (มหาชน) สาขาเซ็นทรัล แจ้งวัฒนะ ออมทรัพย์
ธนาคารกรุงเทพ จำกัด (มหาชน) สาขาเซนทรัล พระราม 3 สะสมทรัพย์
ธนาคารทหารไทยธนชาต จำกัด (มหาชน) สาขาเซนทรัล พระราม 3 กระแสรายวัน

เพิ่มเพื่อน

@rfm0967y

ติดต่อสอบถาม

เพิ่มเพื่อน

CATEGORY

Sensors / Modules [1702]

CONTACT US

มือถือ 0887823467 แฟกซ์ 02-0153201

Join เป็นสมาชิกร้านค้า

ร้านArduitronics
ร้านArduitronics
/www.arduitronics.com/
Join เป็นสมาชิกร้าน
2132
สมัครสมาชิกร้านนี้ เพื่อรับสิทธิพิเศษ

STATISTICS

หน้าที่เข้าชม15,396,274 ครั้ง
ผู้ชมทั้งหมด5,899,352 ครั้ง
เปิดร้าน21 พ.ค. 2556
ร้านค้าอัพเดท18 ก.ย. 2568

MEMBER

พูดคุย-สอบถาม