| Author |
Message |
zndpp
Joined: 03/03/2017 Posts: 1 Karma: +0 / -0
Free account, no CAN development support
|
28-07-2017, 18:15 Subject: Arduino - CAN Bus Shield |
Quote |
|
Hello everyone,
Here's a brief introduction about me: My name is Michael, I am 22 years old, and I am studying mechanical engineering. I'm a hobby electronics enthusiast and I need your help.
Regarding my project: I have an Audi A3 8P (manufactured in 2011). I want to install a car PC in it. I've already given some thought to the concept. However, the problem I'm facing is that I want to retain the functionality of my steering wheel controls (i.e., the multifunction steering wheel). I have already done some research in the past on how the radio is controlled, and subsequently, I acquired an Arduino along with the CAN Bus Shield from Seeed. 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
// loovee, 2014-6-13
#include <SPI>
#include "mcp_can.h"
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
while (CAN_OK != CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init fail");
Serial.println(" Init CAN BUS Shield again");
delay(100);
}
Serial.println("CAN BUS Shield init ok!");
}
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
unsigned int canId = CAN.getCanId();
Serial.println("-----------------------------");
Serial.print("Get data from ID: ");
Serial.println(canId, HEX);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i], HEX);
Serial.print("\t");
}
Serial.println();
}
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/ |
My project was planned in the following way: First, I would analyze the CAN bus and write a program (for the Arduino) that would filter out the important values (louder, quieter, previous track, next track, etc.) and then send these "values" to my PC via USB. Then, I would write a small program on my PC to process these "values" and control the volume internally within Windows. Once everything was ready on the software side, I wanted to buy the hardware (monitor and PC), assemble everything, and have some fun.
Okay, so here's my problem: I simply can't get the CAN codes to display. I have to mention that I'm definitely not a programming expert, and my creations are based on trial and error. To read the data, I've been using a sample code from Seeed, just to have something to work with. I've attached the code below. Unfortunately, I can't say whether this code is generally suitable. I've ruled out any wiring errors. I tapped into the "Can High" and "Can Low" signals from the radio connector, and I'm also getting a signal with the oscilloscope.
I would be very grateful if someone could take a look at it to help me identify any potential issues, as I'm having a hard time spotting a mistake in the code myself.
Best regards,
Michael.
[/url]http://wiki.seeed.cc/CAN-BUS_Shield_V1.2/
|
|
| Back to top |
Profile PM |
 |
postmann CAN-Profi

Joined: 05/23/2013 Posts: 142 Karma: +63 / -0
CAN Support
|
28-07-2017, 21:10 Subject: Arduino - CAN Bus Shield |
Quote |
|
Incorrect baud rate. You have configured a CAN bus with a speed of 500 kBd, but as far as I know, the comfort CAN bus on the 8P model runs at 200 kBd.
|
|
| Back to top |
Profile PM |
 |
Ulli13
Joined: 10/08/2012 Posts: 27 Karma: +19 / -0 Location: Senden 2018 Audi A4 Avant CAN Support
CAN-Diagnose likes this. |
29-08-2017, 23:11 Subject: Comfort can |
Quote |
|
Hello Michael,
My Audi A4 8K's comfort module is running at 100 kbit/s.
I have successfully connected an Arduino to the Motor CAN bus (500kBit/s) of my Audi A4.
It can read data, switch relays based on signals, send diagnostic requests to the motor, and evaluate the responses.
It is important to configure the Canshield masks correctly and only allow the IDs that are necessary to pass through. The Arduino is otherwise completely overwhelmed.
When using diagnostic IDs 7E0 and 7E8, the IDs never reached the Arduino due to their low priority. After the masks are put on, everything runs smoothly and reliably.
Oh yes, my Canshield only had an 8MHz quartz, but it worked when configured that way. My ACC (Adaptive Cruise Control) lever is located at 0x10B, and I can use it to switch relays.
if (rxId == 0x10B) { // Check if the ACC switch is pressed.
text
{
if (bitRead(rxBuf[2], 1) == 1) // 2. Bit set. Set ACC.
{digitalWrite(Relais3, LOW);} else {digitalWrite(Relais3, HIGH);}
if (bitRead(rxBuf[2], 2) == 1) // 3. Set bit to accelerate.
if (condition) {
digitalWrite(Relais4, LOW);
} else {
digitalWrite(Relais4, HIGH);
}
} // End if rx 0x10B
Here's an example of my filters: I allow IDs with the following values to pass through: 0x10B, 3C0, 640, 6B4, 6B7, 7E8.
// Initialize MCP2515 running at 8MHz with a baud rate of 500kb/s and with masks and filters enabled.
if (CAN0.begin(MCP_STD, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
text
Serial.println("MCP2515 Initialized Successfully!");
text
lcd1.setCursor(0, 0); lcd1.print("Motor 500kB Ok"); delay(1000);
else
Serial.println("Error initializing MCP2515...");
CAN0.init_Mask(0, 0, 0x07FF0000); // Initialize the first mask to block all entries...
text
CAN0.init_Filt(0, 0, 0x06400000); // Initialize the first filter for sensors with ID 0x640.
CAN0.init_Filt(1, 0, 0x06B70000); // Initialize second filter 0x6B7, Tank.
text
CAN0.init_Mask(1, 0, 0x07FF0000); // Initialize the second mask...
CAN0.init_Filt(2, 0, 0x07E80000); // Initialize the third filter for MR Diag rx.
CAN0.init_Filt(3, 0, 0x06B40000); // Initialize the fourth filter. FIN
CAN0.init_Filt(4, 0, 0x010B0000); // Initialize fifth filter for ACC lever.
CAN0.init_Filt(5, 0, 0x03C00000); // Initialize fifth filter. Key Status 0x16: 1 = Key on, 7 = Ignition on.
The steering wheel buttons on the 8k model use address 0x66A, the steering angle uses 0x525, and the stalks use 0x3C2.
Best regards,
Ulli
Audi A4 B9 Bj 2018 |
|
| Back to top |
Profile PM Email Garage |
 |
|