/* * Adafruit MCP2515 FeatherWing CAN Receiver Example */ #include #define CS_PIN 21 // Set CAN bus baud rate #define CAN_BAUDRATE (125000) Adafruit_MCP2515 mcp(CS_PIN); //affichage #include "SSD1306Wire.h" //pour OLEDSSD3306 SSD1306Wire display(0x3c, SDA, SCL);//instancier un objet display I2C adresse = $78 (soit $3c sur 7bits) void setup() { Serial.begin(115200); while(!Serial) delay(10); //init du oled LCD display.init(); Serial.println("MCP2515 Receiver test!"); if (!mcp.begin(CAN_BAUDRATE)) { Serial.println("Error initializing MCP2515."); while(1) delay(10); } Serial.println("MCP2515 chip found"); } void loop() { //LCD display.setFont(ArialMT_Plain_16);//font pour oled display.setTextAlignment(TEXT_ALIGN_CENTER); //aligne le texte display.drawString(40, 0, "BUS CAN RX\n\r"); //ecrit la phrase dans le buffer display.display(); //affiche sur l'écran le buffer // try to parse packet int packetSize = mcp.parsePacket(); if (packetSize) { // received a packet Serial.print("Received "); if (mcp.packetExtended()) { Serial.print("extended "); } if (mcp.packetRtr()) { // Remote transmission request, packet contains no data Serial.print("RTR "); } Serial.print("packet with id 0x"); Serial.print(mcp.packetId(), HEX); if (mcp.packetRtr()) { Serial.print(" and requested length "); Serial.println(mcp.packetDlc()); } else { Serial.print(" and length "); Serial.println(packetSize); // only print packet data for non-RTR packets while (mcp.available()) { //Serial.print((char)mcp.read()); Serial.print(mcp.read()); } Serial.println(); } Serial.println(); } }