Hi, installed a arduino uno with a mcp 2512 in my car. Using it to control extra functions the canbus line. Now I want to control my aftermarket stereo from the steering wheel buttons, using a kenwood stereo. I had successful write the code so a button push get registered in arduino ide terminal log, but I now want to take it longer and send the commands to my stereo.
Analysed the signals from my old SWC interface with a oscilloscope, verified the signals I snapped up with from a website I found and build a separately test arduino with basic "volume up" code. Using a uno and a n24401 transistor to this. But no success and when compared the signals from my test unit with the right signals something get corrupt.
Test code
void setup() {
// put your setup code here, to run once:
pinMode(3, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(3, HIGH);
delay(9);
digitalWrite(3, LOW);
delay(4.5);
//1
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
//1
//2
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
//2
//3
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
//3
//4
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delayMicroseconds(562.5);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(1.6875);
//4
digitalWrite(3, HIGH);
delayMicroseconds(562.5);
digitalWrite(3, LOW);
delay(2000);
}
Many hours I had spent to reading, reading, more reading and some tests but im stuck. Some one who can help me fix this. My old SWC interface is crap and why don't make a better version with arduino, it already installed and all I need is a extra cable and some extra code.
Past in my originally code I already using below here, the code I want to put this function in to. Hope I write this right and in right category, im not good neither to write code or english.
Thanks
Setup part code
/////////////
//Taklucka
////////////
////////////
//I-Bus
///////////
#include <mcp_can.h>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
//SID - BEEP//
//const byte Pattern5[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //
//const byte Pattern6[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; //
const byte Pattern7[] = { 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; //Sid High Beep
//SPA//
const byte Pattern1[] = { 0x80, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern2[] = { 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern3[] = { 0x80, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern4[] = { 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern8[] = { 0x80, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern9[] = { 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern10[] = { 0x80, 0x00, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern11[] = { 0x00, 0x00, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern12[] = { 0x80, 0x00, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern13[] = { 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern14[] = { 0x80, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern15[] = { 0x00, 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern16[] = { 0x80, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern17[] = { 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
const byte Pattern18[] = { 0x00, 0x00, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00 }; //SPA Dist
//STEREO - NORMAL MODE//
const byte Pattern19[] = { 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00 }; //vol down
const byte Pattern20[] = { 0x80, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00 }; //vol up
const byte Pattern21[] = { 0x80, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00 }; //src
const byte Pattern22[] = { 0x80, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00 }; //track back
const byte Pattern23[] = { 0x80, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00 }; //track next
const byte Pattern24[] = { 0x80, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00 }; //nxt
//STEREO - NORMAL MODE//
const byte Pattern25[] = { 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 }; //LONG vol down
const byte Pattern26[] = { 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 }; //LONG vol up
const byte Pattern27[] = { 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 }; //LONG src
const byte Pattern28[] = { 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 }; //LONG track back
const byte Pattern29[] = { 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 }; //LONG track next
const byte Pattern30[] = { 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 }; //LONG nxt
//STEREO - STANDBY MODE//
const byte Pattern31[] = { 0xB0, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x00 }; //vol down
const byte Pattern32[] = { 0xB0, 0x00, 0x40, 0x00, 0x40, 0x00, 0x00, 0x00 }; //vol up
const byte Pattern33[] = { 0xB0, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00 }; //src
const byte Pattern34[] = { 0xB0, 0x00, 0x08, 0x00, 0x08, 0x00, 0x00, 0x00 }; //track back
const byte Pattern35[] = { 0xB0, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00 }; //track next
const byte Pattern36[] = { 0xB0, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00 }; //nxt
//STEREO - STANDBY MODE//
const byte Pattern37[] = { 0x30, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 }; //LONG vol down
const byte Pattern38[] = { 0x30, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 }; //LONG vol up
const byte Pattern39[] = { 0x30, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00 }; //LONG src
const byte Pattern40[] = { 0x30, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 }; //LONG track back
const byte Pattern41[] = { 0x30, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00 }; //LONG track next
const byte Pattern42[] = { 0x30, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00 }; //LONG nxt
MCP_CAN CAN0(10); // Set CS to pin 10
////////////
//Blinkers
///////////
////////////
//Oljevarnare
///////////
////////////
//Backvarnare
///////////
int beep = 8;
////////////
//Stereo
///////////
void setup() {
/////////////
//Taklucka
////////////
Serial.println("Push Button Counter");
pinMode(lock, INPUT);
pinMode(alock, INPUT);
pinMode(unlock, INPUT);
pinMode(aunlock, INPUT);
pinMode(unlock_output, OUTPUT);
pinMode(lock_output, OUTPUT);
pinMode(fuel_in, INPUT);
pinMode(fuel_out, OUTPUT);
pinMode(relay_fuel, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
////////////
//I-Bus
///////////
Serial.begin(115200);
if (CAN0.begin(MCP_STDEXT, CAN_47KBPS, MCP_8MHZ) == CAN_OK) Serial.print("MCP2515 Init Okay!!\r\n");
else Serial.print("MCP2515 Init Failed!!\r\n");
pinMode(2, INPUT); // Setting pin 2 for /INT input
CAN0.init_Mask(4, 0, 0x07FFFF00);
CAN0.init_Filt(4, 0, 0x02908000);
CAN0.init_Mask(5, 0, 0x07FFFF00);
CAN0.init_Filt(5, 0, 0x02908000);
CAN0.init_Mask(2, 0, 0x07FFFF00);
CAN0.init_Filt(2, 0, 0x04390000);
CAN0.init_Mask(3, 0, 0x07FFFF00);
CAN0.init_Filt(3, 0, 0x04390000);
CAN0.init_Mask(0, 0, 0x07F00000);
CAN0.init_Filt(0, 0, 0x04330000);
CAN0.init_Mask(1, 0, 0x07F00000);
CAN0.init_Filt(1, 0, 0x04330000);
Serial.println("MCP2515 Library Mask & Filter Example...");
CAN0.setMode(MCP_NORMAL);
////////////
//Blinkers
///////////
////////////
//Oljevarnare
///////////
////////////
//Backvarnare
///////////
pinMode(beep, OUTPUT);
////////////
//Stereo
///////////
}
void loop() {
// loop_blinkers();
loop_taklucka();
loop_stereo();
//loop_ibus();
//loop_oljevarnare();
loop_backvarnare();
loop_bensinvarmare();
}
Stereo SWC part code
void loop_stereo() {
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern19 && memcmp(Pattern19, rxBuf, len) == 0) {
// Matches patern
Serial.print("vol down");
Serial.print(" ");
Serial.println();
digitalWrite(5, 50);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern20 && memcmp(Pattern20, rxBuf, len) == 0) {
// Matches patern
Serial.print("Vol up");
Serial.print(" ");
Serial.println();
digitalWrite(5, 100);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern21 && memcmp(Pattern21, rxBuf, len) == 0) {
// Matches patern
Serial.print("src");
Serial.print(" ");
Serial.println();
digitalWrite(5, 125);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern22 && memcmp(Pattern22, rxBuf, len) == 0) {
// Matches patern
Serial.print("track back");
Serial.print(" ");
Serial.println();
digitalWrite(5, 150);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern23 && memcmp(Pattern23, rxBuf, len) == 0) {
// Matches patern
Serial.print("track next");
Serial.print(" ");
Serial.println();
digitalWrite(5, 175);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern24 && memcmp(Pattern24, rxBuf, len) == 0) {
// Matches patern
Serial.print("nxt");
Serial.print(" ");
Serial.println();
digitalWrite(5, 200);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern25 && memcmp(Pattern25, rxBuf, len) == 0) {
// Matches patern
Serial.print("vol down_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern26 && memcmp(Pattern26, rxBuf, len) == 0) {
// Matches patern
Serial.print("Vol up_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern27 && memcmp(Pattern27, rxBuf, len) == 0) {
// Matches patern
Serial.print("src_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern28 && memcmp(Pattern28, rxBuf, len) == 0) {
// Matches patern
Serial.print("track back_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern29 && memcmp(Pattern29, rxBuf, len) == 0) {
// Matches patern
Serial.print("track next_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern30 && memcmp(Pattern30, rxBuf, len) == 0) {
// Matches patern
Serial.print("nxt_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern31 && memcmp(Pattern31, rxBuf, len) == 0) {
// Matches patern
Serial.print("vol down");
Serial.print(" ");
Serial.println();
digitalWrite(5, 50);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern32 && memcmp(Pattern32, rxBuf, len) == 0) {
// Matches patern
Serial.print("Vol up");
Serial.print(" ");
Serial.println();
digitalWrite(5, 100);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern33 && memcmp(Pattern33, rxBuf, len) == 0) {
// Matches patern
Serial.print("src");
Serial.print(" ");
Serial.println();
digitalWrite(5, 125);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern34 && memcmp(Pattern34, rxBuf, len) == 0) {
// Matches patern
Serial.print("track back");
Serial.print(" ");
Serial.println();
digitalWrite(5, 150);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern35 && memcmp(Pattern35, rxBuf, len) == 0) {
// Matches patern
Serial.print("track next");
Serial.print(" ");
Serial.println();
digitalWrite(5, 175);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern36 && memcmp(Pattern36, rxBuf, len) == 0) {
// Matches patern
Serial.print("nxt");
Serial.print(" ");
Serial.println();
digitalWrite(5, 200);
delay(50);
digitalWrite(5, 0);
delay(250);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern37 && memcmp(Pattern37, rxBuf, len) == 0) {
// Matches patern
Serial.print("vol down_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern37 && memcmp(Pattern37, rxBuf, len) == 0) {
// Matches patern
Serial.print("Vol up_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern38 && memcmp(Pattern38, rxBuf, len) == 0) {
// Matches patern
Serial.print("src_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern39 && memcmp(Pattern39, rxBuf, len) == 0) {
// Matches patern
Serial.print("track back_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern40 && memcmp(Pattern40, rxBuf, len) == 0) {
// Matches patern
Serial.print("track next_long");
Serial.print(" ");
Serial.println();
delay(100);
}
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if (len == sizeof Pattern41 && memcmp(Pattern41, rxBuf, len) == 0) {
// Matches patern
Serial.print("nxt_long");
Serial.print(" ");
Serial.println();
delay(100);
}
}