I'm starting this project that involves sending one CAN message to the car's canbus at specific frequency:
Car's canbus baudrate: 100kbaud
Message repeat speed: every 1 second
It's been a very long time since I tried to program something. So please assume that I am a newbie on arduino and programming.
I have bought Arduino Uno R3 + Sparkfun Canbus Shield.
Right now, all I have done is stacked up the canbus shield on top of arduino so that all the writings on the arduino and canbus shield matches up.
Is this all the connection that is needed to put arduino and canbus shield together? or do I need jumper wires to connect something else too?
Also, how would I go about programming this? I have looked at some sketches like Canbus V3, V4, but they only have the baud rate for 125k, 250k, and 500k and not 100kbaud.
unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
// send data: id = 0x00, standrad flame, data len = 8, stmp: data buf
CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(1000); // send data per 1000ms
}
How would I go about changing the bit rate from 500k to 100k?
With this code, I don't think I'm getting any message sent to the CANH & CANL ports.
I only see constant ~2.5V on CANH & CANL ports.
If there was a message being sent every second, I should see something like 2.5V to 5V to 2.5V and so on, right?
Yes, I'm using the library from the seeedstudio canbus shield site. Is there something that I need to change so that the code will work with the sparkfun's canbus shield?
I'm using a multimeter to measure the voltage. I have one probe at the canh/canl and the other probe at ground of the dsub9 port. Does my code need anything else? I know I'm using a sample code from seeedstudio. Do I have to change anything to make it work with sparkfuns canbus shield?
kpxnsfcxkp:
I'm using a multimeter to measure the voltage.
A multimeter is not going to work. The voltage will change for a tiny fraction of a second. Neither a multimeter nor your eyeballs are fast enough to see the change.
Does my code need anything else?
It will be far easier to troubleshoot if you first try to receive rather than try to transmit.
Is the bus in question fairly active?
What are you trying to control?
Do I have to change anything to make it work with sparkfuns canbus shield?
As far as I can tell, it's the same CAN controller (MCP2515) at the same clock speed (16 MHz) so, assuming the library is fairly bug-free, the library and your code should be fine.
It will be far easier to troubleshoot if you first try to receive rather than try to transmit.
Is the bus in question fairly active?
What are you trying to control?
Yes, the bus is fairly active as I will be connecting to a CANBUS in a car.
I will first try to receive the data like you have advised.
I'm trying to disable the daytime running light on my car.
The Sparkfun Shield works great with the sending example, also with extended messages. But I can't receive anything and I don't know why...
I want to receive extended messages at a J1939 CAN-bus (250k), do I have to change something? I think the attachInterrupt 0 should be ok (pin D2), but I don't get an interrupt. I have a CAN-analyzer, so I'm sure that there are some active messages. Can anyone help me?
// demo: CAN-BUS Shield, receive data
#include "mcp_can.h"
#include <SPI.h>
#include <stdio.h>
#define INT8U unsigned char
INT8U Flag_Recv = 0;
INT8U len = 0;
INT8U buf[8];
char str[20];
void setup()
{
CAN.begin(CAN_250KBPS); // init can bus : baudrate = 250k
attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
Serial.begin(115200);
Serial.println("rdy");
}
void MCP2515_ISR()
{
Flag_Recv = 1;
Serial.println("Interrupt");
}
void loop()
{
if(Flag_Recv) // check if get data
{
Flag_Recv = 0; // clear flag
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
Serial.println("CAN_BUS GET DATA!");
Serial.print("data len = ")
Serial.println(len);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]); Serial.print("\t");
}
Serial.println();
}
}
Edit:
I have sended via a CAN-analyzer messages in standard format and I can receive them correctly! So it seems that only extended messages will be ignored...
@kpxnsfcxkp
I don't have changed anything at the send example, only the baudrate and it works with the Sparkfun shield. Do you have connected it at the correct contacts, 3 and 5?
Hello, I'm actually new on arduino and I'm doing a similar project discussed in this thread. Does anyone know how to data log can bus data into a sd card with the can bus shield? Thanks for the help
Hi guys! You can assume me a newbie on arduino and all these programming stuff. I desperately need your help right now. For my final project i'm trying to do that project. I've got uno r3, canbus shield, serial LCD and gps module. As programme i was using skpang demo code, but it didn't work out. When i connect obd 2 cable to my vehicle the programme is working but as result i didn't see anything. Just " can init ok" after that nothing happened. Thanks for your help.
Hi guys! You can assume me a newbie on arduino and all these programming stuff. I desperately need your help right now. For my final project i'm trying to do that project. I've got uno r3, canbus shield, serial LCD and gps module. As programme i was using sparkfun demo code, but it didn't work out. When i connect obd 2 cable to my vehicle the programme is working but as result i didn't see anything. Just " can init ok" after that nothing happened. Thanks for your help.
Hi all
I am new to Arduino and i try to use it to check dashes of car and ecu on bench for repairing, if i run exampale for recive i can get the messages, but every time i am try to copy some other codes to run to transmit message i get this error "Arduino: 1.6.7 (Windows 7), Board: "Arduino/Genuino Uno"
C:\Users\User\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino: In function 'void setup()':
sketch_dec23a:14: error: redefinition of 'void setup()'
void setup()
^
sketch_dec23a:1: error: 'void setup()' previously defined here
void setup() {
^
C:\Users\User\Documents\Arduino\sketch_dec23a\sketch_dec23a.ino: In function 'void loop()':
sketch_dec23a:22: error: redefinition of 'void loop()'
void loop()
^
sketch_dec23a:6: error: 'void loop()' previously defined here
void loop() {
^
Multiple libraries were found for "mcp_can.h"
Used: D:\Program Files\Arduino\libraries\CAN_BUS_Shield1
Not used: D:\Program Files\Arduino\libraries\CAN_BUS_Shield
exit status 1
redefinition of 'void setup()'
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
"