Hello again, I'm tinkering with another new project, my first go round with canbus or can bus didn't go so well, I was stubborn and didn't want to ask for help and gave up. Now, more hours of searching, youtubing and another round of canbus boards, I've got part 1 checked as a success.
Part one, just be able to read the canbus data
Youtube video that got my part 1 checked
library's he said to use (2 of them)
sketch from
#include <can.h>
#include <mcp2515.h>
#include <CanHacker.h>
#include <CanHackerLineReader.h>
#include <lib.h>
#include <SPI.h>
#include <SoftwareSerial.h>
const int SPI_CS_PIN = 10;
const int INT_PIN = 2;
const int SS_RX_PIN = 3;
const int SS_TX_PIN = 4;
CanHackerLineReader *lineReader = NULL;
CanHacker *canHacker = NULL;
SoftwareSerial softwareSerial(SS_RX_PIN, SS_TX_PIN);
void setup() {
Serial.begin(115200);
while (!Serial);
SPI.begin();
softwareSerial.begin(115200);
Stream *interfaceStream = &Serial;
Stream *debugStream = &softwareSerial;
canHacker = new CanHacker(interfaceStream, debugStream, SPI_CS_PIN);
//canHacker->enableLoopback(); // uncomment this for loopback
lineReader = new CanHackerLineReader(canHacker);
pinMode(INT_PIN, INPUT);
}
void loop() {
CanHacker::ERROR error;
if (digitalRead(INT_PIN) == LOW) {
error = canHacker->processInterrupt();
handleError(error);
}
error = lineReader->process();
handleError(error);
}
void handleError(const CanHacker::ERROR error) {
switch (error) {
case CanHacker::ERROR_OK:
case CanHacker::ERROR_UNKNOWN_COMMAND:
case CanHacker::ERROR_NOT_CONNECTED:
case CanHacker::ERROR_MCP2515_ERRIF:
case CanHacker::ERROR_INVALID_COMMAND:
return;
default:
break;
}
softwareSerial.print("Failure (code ");
softwareSerial.print((int)error);
softwareSerial.println(")");
digitalWrite(SPI_CS_PIN, HIGH);
pinMode(LED_BUILTIN, OUTPUT);
while (1) {
int c = (int)error;
for (int i=0; i<c; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}
delay(2000);
} ;
}
hardware:
nano clone, updated from old bootloader to regular
(didn't want to chance damaging the 1 genuine until i know it works)
HiLetgo 2pcs MCP2515 CAN Bus Module TJA1050 Receiver SPI Module for Arduino AVR from Amazon
software:
canhacker 2.0 from https://www.mictronics.de/
So I was able to wire it up per the schematic from
I've connected it to the car, configured it per the video, and got tons of "ID's" even though I only have an 2 can bus modules plus the nano combo.
Engine Control Unit and the Transmission Control Unit
At this point super excited!!! I started doing checks, seeing what changes, what doesn't when performing specific operations. I found 2 so far, maybe the easiest:
ECU: Accelerator throttle pedal %
TCU: transmission Park and reverse.
and this is now where I cannot google the answer. Some of the searching is super confusing and all of their threads are closed.
Question.. well one of many, what can bus library have you had experience with to
read a message and turn on a output pin? - link to thread if its available?
I think when I first tried, I had quite a few folders in arduino/library folder, each folder had different names but some had same file names within it like can.h (for example) some googling said that can be a problem .. maybe that messed me up the first time.
Currently, this time, I only have those 2 previously mentioned Librarys /folders in my Library folder.
this is the beginning of the can bus data I've maybe identified as Throttle Pedal and Gear position
ID DLC DATA COMMENT
01 02 03 04 05 06 07 08
0AA 8 - - - - - - - 00 0% THROTTLE PEDAL
0AA 8 - - - - - - - FF 100% THROTTLE PEDAL
0F9 8 00 00 40 00 00 00 00 05 Transmission in Park & neutral
0F9 8 7A 12 40 00 00 00 00 05 Transmission in Reverse
0F9 8 07 CB 40 00 00 00 00 05 Transmission in Drive
This is copied from my excel file I started, so this is not extracted from a screen shot or anything.
If anyone has a link that will help point me in the right direction on the next step in this project,
Step2: I want to take message
0F9 8 7A 12 40 00 00 00 00 05 Transmission in Reverse
to turn digital pin on, else off type of sketch.
Then with that I hope I can expand on more messages and outputs.
This post has been crazy long and I want to take little steps and don't want to annoy the active members who are so willing to help with too many questions too fast.
Really appreciate everyone help on the past projects, and look forward to making progress on this one and sharing code as I go
Clint