v0.0.1.1
This commit is contained in:
+33
-26
@@ -1,17 +1,17 @@
|
||||
/*************************************
|
||||
* CAN-bus receive
|
||||
* Author: Michel Bats
|
||||
* Website: www.batssoft.nl
|
||||
* Version: 0.0.1
|
||||
* Revision: 20161122
|
||||
*
|
||||
* Used libraries:
|
||||
* Adafruit_SSD1306\Adafruit_SSD1306 by adafruit
|
||||
* https://github.com/adafruit/Adafruit_SSD1306
|
||||
* Adafruit-GFX-Library\Adafruit_GFX by adafruit
|
||||
* https://github.com/adafruit/Adafruit-GFX-Library
|
||||
* CAN Bus Shield - MCP2515&MCP2551\CAN_BUS_Shield by Seeed-Studio
|
||||
* https://github.com/Seeed-Studio/CAN_BUS_Shield
|
||||
CAN-bus receive
|
||||
Author: Michel Bats
|
||||
Website: www.batssoft.nl
|
||||
Version: 0.0.1
|
||||
Revision: 20161122
|
||||
|
||||
Used libraries:
|
||||
Adafruit_SSD1306\Adafruit_SSD1306 by adafruit
|
||||
https://github.com/adafruit/Adafruit_SSD1306
|
||||
Adafruit-GFX-Library\Adafruit_GFX by adafruit
|
||||
https://github.com/adafruit/Adafruit-GFX-Library
|
||||
CAN Bus Shield - MCP2515&MCP2551\CAN_BUS_Shield by Seeed-Studio
|
||||
https://github.com/Seeed-Studio/CAN_BUS_Shield
|
||||
*************************************/
|
||||
#include <SPI.h>
|
||||
#include <mcp_can.h>
|
||||
@@ -33,17 +33,11 @@ unsigned char lenDisp = 0;
|
||||
unsigned char bufDisp[8];
|
||||
int canIdDisp = 0;
|
||||
int tel = 0;
|
||||
int canIdToReadArray[] = {114, 261, 264, 271, 274,
|
||||
279, 281, 520, 761, 773,
|
||||
781, 840, 845, 909, 973,
|
||||
1037, 1042, 1074, 1101, 1128,
|
||||
1160, 1293, 1294, 1295, 1303,
|
||||
1362, 1401, 1416, 1426, 1544,
|
||||
1551, 1554, 1792, 1928, 1933,
|
||||
1935, 1938, 1943, 2034
|
||||
};
|
||||
int canIdToReadArray[] = {16, 24, 32, 54, 162, 182, 223, 225, 230, 237, 246, 267, 272, 277, 288, 294, 296, 301, 308, 318, 332, 347, 353, 359, 360, 382, 396, 400, 417, 419, 424, 446, 460, 464, 471, 479, 535, 543, 545, 551, 588, 597, 608, 609, 652, 672, 673, 694, 725, 789, 791, 822, 853, 865, 935, 950, 1014, 1189, 1203, 1291, 1292, 1298, 1309, 1311, 1317, 1318, 1325, 1331};
|
||||
//int canIdToReadArray[] = {261, 264, 274, 520, 761, 773, 781, 840, 845, 909, 973, 1037, 1042, 1074, 1101, 1128, 1160, 1293, 1294, 1303, 1362, 1401, 1416, 1426, 1544, 1554, 1792, 1928, 1933, 1938, 1943, 2034};
|
||||
int canIdToRead = canIdToReadArray[0];
|
||||
#define CAN_ID_COUNT 38
|
||||
#define CAN_ID_COUNT 68
|
||||
//#define CAN_ID_COUNT 32
|
||||
int canIdCount = 0;
|
||||
int telDisp = 0;
|
||||
|
||||
@@ -53,6 +47,11 @@ Adafruit_SSD1306 display(OLED_RESET);
|
||||
// Initialisatie mcp_can
|
||||
MCP_CAN CAN(MCP_CAN_SPI_CS_PIN);
|
||||
|
||||
// Controleren of de SSD1306-library correct is ingesteld.
|
||||
#if (SSD1306_LCDHEIGHT != 64)
|
||||
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
|
||||
#endif
|
||||
|
||||
// SETUP
|
||||
void setup()
|
||||
{
|
||||
@@ -68,7 +67,8 @@ void setup()
|
||||
display.setTextColor(WHITE);
|
||||
|
||||
// Verbinding met de MCP2515 controleren
|
||||
while (CAN_OK != CAN.begin(CAN_500KBPS))
|
||||
while (CAN_OK != CAN.begin(CAN_125KBPS))
|
||||
//while (CAN_OK != CAN.begin(CAN_500KBPS))
|
||||
{
|
||||
// Cursor verplaatsen naar linkerbovenhoek
|
||||
display.setCursor(0, 0);
|
||||
@@ -103,7 +103,7 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
unsigned char len = 0;
|
||||
unsigned char buf[8];
|
||||
unsigned char buf[12];
|
||||
|
||||
if (CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
|
||||
{
|
||||
@@ -111,7 +111,6 @@ void loop()
|
||||
|
||||
unsigned int canId = CAN.getCanId();
|
||||
|
||||
|
||||
if (canId == canIdToRead)
|
||||
{
|
||||
bufDisp[0] = buf[0];
|
||||
@@ -123,6 +122,10 @@ void loop()
|
||||
bufDisp[6] = buf[6];
|
||||
bufDisp[7] = buf[7];
|
||||
bufDisp[8] = buf[8];
|
||||
bufDisp[9] = buf[9];
|
||||
bufDisp[10] = buf[10];
|
||||
bufDisp[11] = buf[11];
|
||||
bufDisp[12] = buf[12];
|
||||
canIdDisp = canId;
|
||||
lenDisp = len;
|
||||
telDisp++;
|
||||
@@ -176,9 +179,13 @@ void loop()
|
||||
display.display();
|
||||
display.clearDisplay();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void canIdToReadChange() {
|
||||
while (digitalRead(INTERRUPT_PIN) == 0) {
|
||||
delay(250);
|
||||
}
|
||||
canIdCount++;
|
||||
if (canIdCount > CAN_ID_COUNT) {
|
||||
canIdCount = 0;
|
||||
|
||||
Reference in New Issue
Block a user