From Wikipedia, the Controller Area Network (CAN) bus is a 'vehicle bus standard designed to allow microcontrollers and devices to communicate with each other within a vehicle without a host computer.' These devices can also be referred to as electronic control units (ECUs).
Jul 01, 2014 I have a question. I am trying to connect 2 Arduino Uno with serial connection in Simulink. In the 1st Arduino board I read a sensor information and drive 1st servo. I want to transmit this information to the second Arduino board by serial connection. Based on the transmitted data, the 2nd Arduino board is supposed to drive 2nd servo. I have a question. I am trying to connect 2 Arduino Uno with serial connection in Simulink. In the 1st Arduino board I read a sensor information and drive 1st servo. I want to transmit this information to the second Arduino board by serial connection. Based on the transmitted data, the 2nd Arduino board is supposed to drive 2nd servo.
Essentially the CAN bus is a bunch of linked ECUs within the vehicle that communicate with each based on a broadcast. Every ECU intercepts every broadcast, but individually decide whether or not to react to it. Here's an example: Let's imagine there's one ECU that controls the brake lights, one ECU that controls the car horn, and one ECU that controls the braking system. Whenever you blow the horn, the horn ECU sends a broadcast message out on the CAN bus network to every ECU it is connected to, including the brake light ECU and the braking system ECU. The brake light ECU intercepts that broadcast message, but chooses to ignore it because it has no relevance. The brake light ECU is really only waiting on the message from the brake system ECU. Also, the horn ECU doesn't react to the braking system ECU.
This broadcast system is broken down into different components; the two most important are message ID and message data. For now, think of the message ID as an ECU address. The message data is the content. It is typically larger than the ID at around 8 bytes long. Here's an example: message ID: 620 data: 10 80 FF FF 80 20 00 80 The ECUs communicate with each other over a twisted wire pair holding CAN-high (CAN+) and CAN-low (CAN-). CAN-high and CAN-low are accessible through the OBD-II port under the steering wheel. This is how we'll get in!
Pro-tip: Use a wire tracer/tone generator to backtrace to other CAN Bus access points within your car. Volkswagon has a good guide to how the CAN Bus network works. Components: 1- Arduino UNO R3 2- Sparkfun (or other) CAN Bus Shield: Note: Also available at SK Pang: (SK Pang also supplies the needed CAN Bus library). Note2: At the time of this writing, there were only 6 in stock at Sparkfun. Note3: Sparkfun's CAN Bus shield also has a joystick (up, down, left, right, center), a micro SD slot, and support for GPS and LCD modules. Note4: If you're feeling up to it, you can order the parts from Digikey and make your own using Sparkfun's provided EAGLE CAD drawing.
3- Wire pair or Sparkfun's OBD-II to DB9 cable: Note: I found some old speaker wire that worked great. 4- breakable header pins - the CAN Bus shield doesn't include them: Assembly: 1- Break headers into 2x8 pin, 2x6 pin, and (optional - 1x4 pin sections) 2- Solder the headers to the CAN Bus shield. The attached file, CANreadsample, is for simply reading all messages. I commented out filtering, so you should be able to modify it easily to include filtering of message ID and data. I also attached a file, CANwritesample, for writing a message.
You have two options for connecting the Arduino to vehicle's CAN-high and CAN-low lines: 1- Hack up some speaker wire (or any wire pair) and connect the CAN-H and CAN-L through-holes on the shield to the OBD-II port. CAN-H (shield) CAN-high (OBD-II) CAN-L (shield) CAN-low (OBD-II) 2- Buy Sparkfun's OBD-II to DB9 Cable. This also powers the Arduino through the car's 12v line. I haven't used it, but let me know how it works out. YMMV Connect the Arduino to your car and computer, load the code, open the serial monitor, and watch the magic.
Attachments. As you begin to read CAN bus messages, start manipulating your car.
Unlock and lock the vehicle. Pop the trunk.
Roll up and down windows. Sounding the alarm.
Blow your horn. Turn on and off your flashers. Turn on and off your signal lights. Turn of and off your lights and high beams. Etc. Remember that filtering is your friend! See if you can find messages related to the above.
Once you do, write the same messages back out through your Arduino using Step 2. See if you can unlock or lock your vehicle, pop the trunk, or blow your horn!
I hope to share my findings in the future! Thanks for reading!
Hi, I tried this on my 2003 VW Golf mk4. I had to hookup my shield directly on the bus wires, located behind the dashboard to be able to read messages. Took me quite a while to find the right wires. You have to look for a pair of orange twisted cables connected to the green plug behind the dashboard. There are three orange pairs.
Two of which are Orange/black and orange/brown. You have to use the light coloured pair. Orange/black is Can H and orange/brown is Can L (at 500kbps). Currently im collecting data and try to understand it. My goal is to implement cruise control and an active rev matching system, controlled by a windows 10 pc in the trunk, which is connected to a touchscreen in the front, replacing the radio and navigation system. I need to transmit and receive specific CAN messages for a project.
I have to use a laptop with Busmaster on one end and the Arduino with the CAN shield on the other. When I send messages from the Busmaster to the Arduino I get an error. A CAN message isn't transmitted by busmaster.
Is there anything else I need to add to the code? The setup is a laptop with busmaster sending CAN signals to the shield-arduino through a USB-DB9 connector. The Arduino is connected via USB to another laptop on whose serial monitor I wish to read the messages being transmitted by the first laptop. Also do I need to worry about adding 120 ohm resistors anywhere in this setup? I need an Analog 0-5V to CAN converter at work and the cheapest one I can find is about £400. So I am thinking of going the Arduino route and developing our own. I have a joystick that outputs in CAN but I cannot use it for reasons, and it is connected in a forklift truck (which uses CAN to communicate of course) I have a joystick that outputs in 0-5V which I can use, but of course, I need to translate the 0-5V to CAN exactly as the OEM.
I am kind of struggling to figure out how to do this. Any help would be appreciated. Hello, Basically, I wanted to establish can communication between two arduino boards. For that, I have two sparkfun can-shields.
I wanted to know, 1.Can I connect them directly by using CANH and CANL pins provided on shield?(I tried direct connection, but I'm not able to receive can frame at the receiving arduino board) 2. Whether do i need to connect terminating resistors of 10 ohm at both ends? 3.is there any API, where can we configure baudrate and can fram id etc? Thanks in advance. My mail id is: [email protected].
Hello, i bought the 'SparkFun CAN-BUS Shield' and hooked up on a Arduino Uno. After that, I uploaded the sketch 'CANReadDemo'. I connected it to my car, but there was no data displayed on the serial monitor.
Then I uploaded the sketch 'SparkFunCANDemo' to test the board. The serial monitor shows: CAN-Bus Demo CAN Init ok Please choose a menu option 1.Speed 2.RPM 3.Throttle 4.Coolant Temperature 5.O2 Voltage 6.MAF Sensor But when I enter a option (e.g. 1 for Speed) it shows following error: Vehicle Speed: Not a valid input. Please enter a valid option. Is the shield broken or did I something wrong? I just went through this, your CAN Bus shield is most likely configured for the incorrect 'CS', chip select pin compared to your sketch/library. More than likely your CAN Bus shield is an aftermarket one.
Fastest way to rectify this is to either correct the CS pin (it'll either be 9 or 10) in the code/library or physically jump the gold soldering dot on the back of the CAN Bus shield shorting the center dot to pin 10 dot AND use a blade or knife to cut the PCB print from the center dot to the pin 9 dot. I'm sure this is confusing as heck but flip JUST the CAN Bus shield onto its bottom and you'll see four different rows of soldering gold contacts labeled 'CS, MOSI, MISO, SCK' from top row to bottom. The CS row is what you're interested in and you need to sever the TINNNNY wire going from the very left (9) gold contact to the center contact using a blade and physically solder the center contact to the very right contact dot (10). Note, none of this will apply to you if you have an original CAN Bus shield, its for aftermarket shields only.
![Communication Communication](/uploads/1/2/5/4/125427603/482236102.jpg)
Hi, I'm trying to figure out how use Matlab to program my Arduino. I'm trying to control 3 stepper motors, as I'm trying to built an alignment device. I need Matlab to do my image processing for me, and saw that you can control an Arduino with Matlab. When I run my code uisng the Arduino software, everything runs smoothly, but when I try programming with Matlab, the motor becomes very slow and jerky, and when I tell it to go a full revolution it does not do it completely. I think my issue might be due to a delay between the Arduino and Matlab communication.
All information I see online for the integration of Arduinos, stepper motors, and Matlab involves using an Adafruit motor shield, but I can't use that in my application. Does anyone have any ideas how to integrate the steppers, an arduino mega, and matlab without a motor shield? Looks like you're using the MATLAB Support Package for Arduino.
This package uses the MATLAB engine to run commands on the Arduino. To control the motors with MATLAB code, I would actually recommend the Simulink support package instead (more on why in a bit): Using the MATLAB Support package means each command to the Arduino must be communicated over the USB connection (serial protocol) to the actual chip, which introduces a delay. Additionally, MATLAB is running on an operating system, which can interrupt things too. If you were to write these command in the Arduino editor, the commands are compiled into the actual chip which eliminates this delay.
The Simulink Support Package for Arduino will actually take the model/MATLAB code and generate C code from it. This compiled code will then be deployed to the Arduino chip. No more delays from the USB connection or Windows! You can write MATLAB code directly in Simulink using the MATLAB function block, so no worries about moving from MATLAB to Simulink! I found an example of something similar to what you are doing here:. I have a couple theories.
First thing I notice in the code is that you are only using one pin. In my experience, I haven't seen a stepper that can be controlled by turning on and off a single pin. The next thing I notice is that the delay (I am reading it as 1/1000 sec) seems awfully short. The motor has physical inertia to get from one step to the next and the ones I have used are limited to like 200 steps/sec. Neither of those is necessarily the problem; you may have some kind of super-fast 2-wire stepper that I've never seen. My leading theory is that sending this many tightly packed commands over serial is problematic, because the arduino can't really multitask.
Every time a command comes over serial it has to stop other execution. This is like me telling you how to juggle in real time with commands for each muscle. It's too much to both listen and execute. So what happens is you have varying delays between your steps.