A CAN Bus New Year (Patreon)
Content
Happy New Year to everyone. Thanks for your ongoing support for my channel and projects!
I decided not to post videos for a couple of weeks over the Holiday season, but I've still been busy. Some CAN Bus testing has been taking place. See: https://en.wikipedia.org/wiki/CAN_bus
I'm using three Teensy 3.1 and 3.2, and one Teensy 3.6. Although Teensy 3.2+ supports CAN Bus directly you still need a CAN Bus transceiver to transmit the data over long distances. This makes a differential signal which means that if noise occurs on the transmission line, it occurs on both pairs of cable, but the difference between them is still the same.
This principle is the same as RS485 (which is what DMX uses), but RS485 is only half duplex which makes managing sending and receiving data a little more tricky. CAN Bus is 'Multi-Master', so any node can transmit or receive at any time and the CAN protocol sorts it out.
Each node has an ID which gives it a priority, but provided I leave a 1ms delays in my transmitting loop then all my data gets through from all three nodes that are transmitting. If I remove the delay then the highest priority always wins, but running at 1000Hz is fine for me. Otherwise I'd need to implement a system of polling each node in turn and waiting for that node to reply, which is what you'd have to do with RS485, but it appears that probably isn't necessary for most applications.
I found there are lots of forks of the FlexCAN library for Teensy, the only one I could make work is: https://github.com/tonton81/IFCT . My transceivers are based on the SN65HVD230 / PCA82C250 apparently - I just got them from eBay in a five-pack for £6.99.
The only limiting factor is that the library only allows sending 8-bit variables, but the bits can be split and combined with various Arduino functions at each end to make 16-bit or higher variables. Looks like it'll run up to 1Mbit.
I waved the wires next to the openDog while the motors were powered up and everything seems good. I should be using twisted pairs really, for now the transmission wires are just close to each other.
So this definitely has a place in multiple projects. openDog is the obvious one since that's where I left off in the last video. However any project that needs distributed sensors and uses brushless motors would benefit. In fact I have another project for early 2020 which will be using ODrives/Brushless motors and also the same load cells as openDog, so this will probably be the first candidate.
I'm considering a dedicated video about this CAN Bus setup, although I may just combine it with the next openDog video.
Files
Previews only