brendan-w / python-OBD

OBD-II serial module for reading engine data
GNU General Public License v2.0
1.02k stars 360 forks source link

MicroPython IO Pin support? #237

Closed AwesomeCronk closed 2 years ago

AwesomeCronk commented 2 years ago

I would like to use this library in a future project, using a MicroPython device + LCD display as a code indicator so I don't have to go get my dad's reader or go to the shop when my car throws a code. That said, in the example code, all I see is code using Unix-like or Windows serial ports. Can Python-OBD use the IO pins of a MicroPython device? If not, is there a way to patch that in when using it? It should be noted that MicroPython has a UART class that allows relatively simple UART (same as RS232) interfacing: https://docs.micropython.org/en/latest/library/machine.UART.html

interfect commented 2 years ago

To get obd to work on MicroPython, you'd need to get or fake its dependencise: pyserial and pint.

pint just does unit conversion, and looks to have no mandatory dependencies of its own, so it ought to work just fine if you can convince MicroPython to use any modules.

pyserial I don't think knows how to run on MicroPython. There's a micropython-serial which would give you something when you import serial, but it doesn't actually implement the right API. obd wants to call serial.serial_for_url(), for example, and that's not in there.

To patch in MicroPython support in your setup, you'd need to write a better version of micropython-serial that implements all the methods that obd actually uses. For starters, that's:

Also I think micropython-serial isn't actually meant to work on real MicroPython, since it says "Unix port" in the description and does everything with os and termios. So you'd also probably have to reqrite what's there in terms of machine.UART.

AwesomeCronk commented 2 years ago

I see. Thank you for getting back to me!