kizniche / Mycodo

An environmental monitoring and regulation system
http://kylegabriel.com/projects/
GNU General Public License v3.0
2.96k stars 494 forks source link

CAN Bus for sensors and relays #1347

Open samuk opened 11 months ago

samuk commented 11 months ago

Is your feature request related to a problem? Please describe. I2C can be flaky, some of my systems may end up some distance from main compute module.

Describe the solution you'd like Add software support for the CAN Bus components found in the open hardware Acorn CM4 carrier

I think this would enable CAN Bus communication to:

Describe alternatives you've considered Using I2C over RJ45 as in the Hiveboard/ Droneboard project/ product

Additional context Quite new to Canbus, so this may not be well formed or particularly coherent.

It looks like the relevant package is socketcan

FlooSz commented 11 months ago

You can also use MQTT for good communication between Mycodo and e.g. Tasmota on a ESP, if you only care about the RJ45 connector: It doesn't matter which cable you use for sensors or relays, as long as the cable is designed for the appropriate voltage, but for this side of the relay you could also connect an RJ45 socket to the I2C bus and use the same wires on the other side

Until there is a solution to your problem/upgrade, I would also find the topic interesting

FlooSz commented 11 months ago

I can try to write you a code for a custom input, but we maybe must troubleshoote and and upgrade the code, I need for this all errors that will happen, and for starting I need to know which Sensors you want to use and which measurements will be required (Temp, Moisture,...and the units please)

samuk commented 11 months ago

Thanks, I'm not particular about the cables. As you say they don't matter all that much with CAN Bus or I2C.

I do have a preference for cabled over wireless. Improving the reliability of cable runs of 10m - 20m would be my goal.

This is just at research phase at the moment, but good to know it seems possible. Initially I'd probably look to emulate the sensors from https://atlas-scientific.com/product/wi-fi-aquaponics-kit/

LucidEye commented 10 months ago

@samuk

If you need to increase the distance between your Raspberry Pi and your wired sensors there are a few options that are inexpensive and already available instead of having to develop hardware and software to adapt the CAN bus for Mycodo.

Adafruit has this active terminator which allows you to use a standard Ethernet cable (RJ45) as an "extension cord" (up to 100 feet) between the Pi and your i2c sensors. It changes the signal for longer distances so you don't have to worry about things like line capacitance, pull-up resistors, or EMI. There are several people on the DIY Forum and on the Discord who are successfully using these active terminators to increase i2c distances. https://www.adafruit.com/product/4756

Sparkfun also makes these i2c range extenders that use standard Ethernet (RJ45) cables as i2c extension cords (up to 100 feet). They also use the STEMMA QT or QWIIC connectors which makes it easy to connect sensors. You need to attach one Endpoint adapter to your Pi's i2c pins, and then use the Ethernet as the long cable run, and then have another endpoint adapter on the far end of the Ethernet cable, and that's where your sensors go... https://www.sparkfun.com/products/16988

They also have these mid-point adapters for dropping sensors anywhere along the cable run. https://www.sparkfun.com/products/18000

wbard93 commented 10 months ago

I've tried a few different I2C interfaces but have not been able to get it to be reliable. I'm currently working on a custom design using an ATMEGA328 on an interface board to go between the RPi I2C and an external RS485 bidirection bus.

I'm not familiar with CAN parts so it would be a while before I'd be able to look into that and experiment.

samuk commented 9 months ago

The carrier board uses the standard MCP2515 which is in the Linux kernel.

https://www.amazon.com/dp/B0BVH43P9L