can_bus_with_arduino_in_7_steps_with_pictures
can_bus_with_arduino_in_7_steps_with_pictures
Arduino in 30 Seconds!
omarCartera
Hello Arduinos!
The first 3 steps are the basic ones that will initiate a CAN
BUS at your home, the rest of the steps are a little bit
advanced and real-life CAN situations.
x1 Breadboard.
x1 MCP2515 Microchip CAN Controller.
x1 MCP2551 Microchip CAN Transceiver.
x1 20KΩ Resistor.
x1 10KΩ Resistor.
x1 100Ω Resistor.
x1 16 MHz Crystal Oscillator.
x2 27 pF Capacitors.
x3 LEDs.
x3 220Ω Resistors.
Schematic key:
A Big Example:
At any time, every CAN BUS node sees the message being
sent through the bus. But not all of them read it and send it
to their ECUs. That's because in our example the rear wing
ECU or the front-right headlights ECU don't care at all about
a problem in the engine, so they see the message that
contains engine failure and ignore it. On the other hand, they
are the only ECUs who read the messages like: retract the
wing or shut the headlights.
Check the attached files for the code, and come back here
for the explanation.
For the first piece of information, as it fits in one byte and our
code let us deal with every byte of the buffer separately, all
you need to do here is to extract the car speed directly from
the first byte only, easy!
i.e. car_speed = buf[0];
For the rest cases where the signal bits take more or less
than a byte, you will need bit manipulation to put those bits
in the right setup before reading them.
Then, shift this value 8 bits to the left to put the higher
byte you read in its right position.
engine_rpm = engine_rpm << 8;
Now, mask off all byte 2 bits except the first six bits
used for the RPM signal.
char temp = buf[2] & 0x3F;
To read the value of Check Engine and Oil bits, you will
need to mask off all the bits but the one you want, piece of
cake!
Attached here are the Eagle files for the layout. The layout
was designed, printed on a copper board but not yet milled
or tested, you can revise the design and give your comments
below, you can also print it and make your own PCB and then
tell us what you ended up with. And you can even suggest
enhancements to the layout design!
Some say, with our CAN setup, we can talk to our cars
through their OBD-II port, just like the mechanic in the
previous paragraph, by sending the so called PIDs to the
OBD requesting some parameter from the car
communication buses and wait for the response message
carrying the values you asked for.
I didn't try it, but I will do this very soon. Take care of your
connections and read about OBD before you plug
anything to your car.