"Why not RS-485?" - you may ask.
Because why not? (I couldn't find a better name, please suggest!) Do you want to communicate with several Arduinos and/or Raspberries, other microcontrollers and SBC-s? "Duh, use Bluetooth or Wi-Fi." But it's not the optimal solution in every case, wired communication is better in several aspects! If half-duplex, byte-oriented communication under 1 Mbps is suitable for your project, give it a try!
The LIN bus is based on a really nice idea: you have the world's cheapest interface in practically EVERY microcontroller (and SBC), namely UART. Just wire it to a bus and ready to roll! The idea is the same: why not use a really popular bus IC and hack it?
Also the CAN transceivers are more modern than the RS-485. The CAN is well-documented in ISO 11898-1, a single twisted-pair is enough to go up to 1000 meters, and you can implement collision detection. So, wanna try?
Get an Arduino and a CAN "level shifter", not a full CAN compatible peripheral! I used the TLE6250.
Step 1: The Theory
The TLE6250 converts the CAN-compatible signals to simple TTL and you can feed this TX-RX signals to the Arduino's TX-RX (but not crossed: TX-TX and RX-RX).
Use twisted pair wires with 120 Ohm terminal resistors on each end for best performance, but it will work on your desk with jumper wires and without resistor.
Each board connects to the same bus - so everyone gets the very same message, even the sender! (that's how you check message integrity, if you get what you sent, everything went fine)
For absolute beginners: use master-slave topology, one master and several slaves. This can be insufficient in many cases, the pros can implement a token-ring based communication or wait for the final implementation here: https://github.com/the-developer-guy/
How to implement CSMA-CD is not decided yet. Performance calculations needed.
Step 2: Assembling and Testing
This transceiver is available in SO-8, so it's easy to solder it to a Protoshield!
- TxD - Tx (pin 1), RxD - Rx (pin 0)
- INH to ground and RM to high to enable
- GND to ground, Vcc to 5V
- CANH to one com wire, CANL to the other
Done! In this case the brown and red wires were the CANH and CANL wires. I used a Leonardo for Serial1 -> Serial monitoring and an Arduino Uno for generating traffic. If you are within the CAN specifications, you are good to go!
Participated in the
Arduino Contest 2019