MicroPython IO Pin support?
AwesomeCronk opened this issue · comments
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
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:
serial.serial_for_url()
Serial.flushInput()
(on the actual class, not the module)Serial.flushOutput()
Serial.flush()
- The
Serial.portstr
field or property - The ability to set
Serial.baudrate
while the port is open, and have it actually apply. It looks likemicropython-serial
only uses it inopen()
.
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
.
I see. Thank you for getting back to me!