I have recently been looking at adding basic NMEA 2000 support to PyPilot, and since I've had some success I thought I'd share.
There are two parts to full N2K support in my eyes:
1. Sensor support is quite simple really, this is what I have fundamentally working already - I can send and receive PGNs from the net and get data from them into pypilot sensors.
2. Control support is far more complicated, the available reverse engineered PGNs are frankly not very helpful (no way to set wind mode, only track or heading), so we would probably need to define "proprietary" pypilot PGNs to use...this I am not looking at yet, but would be worth discussion.
I have managed to get N2K connected on a tinypilot with the Pican-M, and have included in the code a slightly modified version of https://github.com/tomer-w/nmea2000 which can run on Python 3.8 (the original library is >=3.12).
The code is available here: https://github.com/JohnCHarrington/pypilot/tree/n2k
Any comments are very welcome - the code is rather messy currently as it was a bit of a nightmare to get working, but at least wind input is fully working (sending and receiving PGNs works, I just only had wind data on the network at home so I can't check the other PGNs and adjust to ensure they are correctly processed - will do that soon).
Next steps for me are:
There are two parts to full N2K support in my eyes:
- Sensor support - transferring the sensor info to/from the network as we do with 0183
- Control support - controlling the pypilot from an N2K connected device
1. Sensor support is quite simple really, this is what I have fundamentally working already - I can send and receive PGNs from the net and get data from them into pypilot sensors.
2. Control support is far more complicated, the available reverse engineered PGNs are frankly not very helpful (no way to set wind mode, only track or heading), so we would probably need to define "proprietary" pypilot PGNs to use...this I am not looking at yet, but would be worth discussion.
I have managed to get N2K connected on a tinypilot with the Pican-M, and have included in the code a slightly modified version of https://github.com/tomer-w/nmea2000 which can run on Python 3.8 (the original library is >=3.12).
The code is available here: https://github.com/JohnCHarrington/pypilot/tree/n2k
Any comments are very welcome - the code is rather messy currently as it was a bit of a nightmare to get working, but at least wind input is fully working (sending and receiving PGNs works, I just only had wind data on the network at home so I can't check the other PGNs and adjust to ensure they are correctly processed - will do that soon).
Next steps for me are:
- Check other relevant input/output PGNs on a more complete net (need to go test on the boat where I have other sensors and consumers available)
- Clean up the code a bit more!
- New tinypilot image with N2K enabled? EDIT: I noted that sean is working on a tc16 tinypilot image - that would potentially make this a lot easier to set up as it could run on python 3.12?
- A little hardware work to power the pypilot from N2K - plan I think is to have a separate box (to keep it away from the IMU) with a small buck converter and a panel mounted N2K connector, then a 6-wire cable from there to the pypilot box where the 4 N2K wires will go to a waveshare CAN HAT, and the 5V/GND to the pi directly.

