CAN bus implementation

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
SwimDude0614
Posts: 32
Joined: Mon Mar 10, 2014 1:32 am

CAN bus implementation

Post by SwimDude0614 » Sun Jun 08, 2014 4:26 pm

I just bought a car that has OBD-II in it (finally! been getting tired of pre-OBD cars) and am very interested in poking into that port and investigating all the possibilities. The Micropython board seems perfect for this venture since it is tiny, has built-in CAN support, and gives me access to a high-level language (I sure don't need assembly for data at these speeds!).

This thread is a starting point for discussion and questions that I will have along the way.

First question:
Just to confirm I didn't miss something, CAN has not yet been brought out to a python module yet correct? It's of course still available at the register level in hardware, but no python interface yet?

Learning about the CAN protocol:
Marginally helpful: http://cache.freescale.com/files/microc ... AN1798.pdf
Much more helpful: http://www.ti.com/lit/an/sloa101a/sloa101a.pdf
Last edited by SwimDude0614 on Mon Jun 09, 2014 7:01 pm, edited 2 times in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: CAN bus implementation

Post by dhylands » Sun Jun 08, 2014 4:45 pm

SwimDude0614 wrote:First question:
Just to confirm I didn't miss something, CAN has not yet been brought out to a python module yet correct? It's of course still available at the register level in hardware, but no python interface yet?
That is correct.

SwimDude0614
Posts: 32
Joined: Mon Mar 10, 2014 1:32 am

Re: CAN bus implementation

Post by SwimDude0614 » Sun Jun 08, 2014 4:48 pm

Great! I have my work cut out for me :) My board arrived a couple weeks ago and I've been dying to play with it! Finally have a reason to now

SwimDude0614
Posts: 32
Joined: Mon Mar 10, 2014 1:32 am

Re: CAN bus implementation

Post by SwimDude0614 » Mon Jun 09, 2014 2:22 am

What have I gotten myself into! I just want to go back to SPI! :shock:

Ha... I'll get this. But wow - this protocol is a lot more complicated than I expected going into it.

nekomatic
Posts: 37
Joined: Thu May 08, 2014 9:31 pm

Re: CAN bus implementation

Post by nekomatic » Fri Jun 13, 2014 9:02 am

This is exactly what I was planning to use my micropython board for (adding a trip computer and fuel economy gauge to our old Honda Civic) except that the car now needs a gearbox repair and we're probably going to ditch it in favour of something newer that will probably have that feature already...

You're probably aware of this, and I don't want to put you off developing CANbus code for micropython if you want the challenge, but the ELM Electronics series of interface chips translates the various OBD protocols into what is claimed to be a simpler command set over a serial interface. OBD to USB, Bluetooth or wifi interfaces that reproduce the ELM protocol are cheap on eBay. Ready-made serial interfaces are much less common and more expensive but the hardware interface as shown on the ELM datasheets looks pretty straightforward if you know any electronics.

There's a Python module, pyobd, for talking to an OBD port via an ELM compatible interface.

Do let us know what progress you make!

SwimDude0614
Posts: 32
Joined: Mon Mar 10, 2014 1:32 am

Re: CAN bus implementation

Post by SwimDude0614 » Fri Jun 13, 2014 7:33 pm

I am aware of the ELM along with a number of other options (I even have an mbed sitting around with ready-to-go OBDII stuff as well as a Parallax Propeller and a few others :P). But, I like the idea of giving back to the micropython community and creating this CAN bus implementation. It might take a while - it's not very high on my priority list - but I'll keep slowly chipping away at it. I do at least have a Saleae Logic so that will hopefully make life much easier!

If anyone else is interested in kicking in on this or helping me out, let me know I'll and commit the snippets of code that I'm working on. My git repo is https://github.com/SwimDude0614?tab=repositories for anyone curious.

User avatar
TravisT
Posts: 72
Joined: Sun Feb 23, 2014 2:31 pm
Location: Portland, OR
Contact:

Re: CAN bus implementation

Post by TravisT » Sun Jun 22, 2014 1:44 am

Hello,

I am looking at switching processors over to the STM one used by micro python. I am also a huge fan of the python programming language. However CAN is a must, so I am very interested in how things are going with your library or if any official support is being expressed. I would be willing to help, and would be willing to help fund development if it could help make this library happen quicker and be more stable.

How far have you gotten?

Thanks
_______________
Travis Travelstead

SwimDude0614
Posts: 32
Joined: Mon Mar 10, 2014 1:32 am

Re: CAN bus implementation

Post by SwimDude0614 » Mon Jun 23, 2014 12:57 am

TravisT wrote:Hello,

I am looking at switching processors over to the STM one used by micro python. I am also a huge fan of the python programming language. However CAN is a must, so I am very interested in how things are going with your library or if any official support is being expressed. I would be willing to help, and would be willing to help fund development if it could help make this library happen quicker and be more stable.

How far have you gotten?

Thanks
I've barely started. But, knowing now that there is some interest other than my own, I can try to move my focus back to it. Been playing with the msp430 lately lol

SwimDude0614
Posts: 32
Joined: Mon Mar 10, 2014 1:32 am

Re: CAN bus implementation

Post by SwimDude0614 » Mon Jun 23, 2014 2:23 am

I'm taking baby steps. I wanted to be sure I could flash a custom-compiled version of uPy before going any further with the CAN development... and it's a good thing I did. I'm getting the following error from dfu-util:

Code: Select all

david@balrogJr:~/reusable/micropython/stmhal$ sudo dfu-util -a 0 -D build-PYBV10/firmware.dfu 
dfu-util 0.5

(C) 2005-2008 by Weston Schmidt, Harald Welte and OpenMoko Inc.
(C) 2010-2011 Tormod Volden (DfuSe support)
This program is Free Software and has ABSOLUTELY NO WARRANTY

dfu-util does currently only support DFU version 1.0

More than one DFU capable USB device found, you might try `--list' and then disconnect all but one device
david@balrogJr:~/reusable/micropython/stmhal$ dfu-util --listdfu-util 0.5

(C) 2005-2008 by Weston Schmidt, Harald Welte and OpenMoko Inc.
(C) 2010-2011 Tormod Volden (DfuSe support)
This program is Free Software and has ABSOLUTELY NO WARRANTY

dfu-util does currently only support DFU version 1.0

Found Runtime: [03f0:231d] devnum=0, cfg=1, intf=3, alt=0, name="UNDEFINED"
Found DFU: [0483:df11] devnum=0, cfg=1, intf=0, alt=0, name="UNDEFINED"
Found DFU: [0483:df11] devnum=0, cfg=1, intf=0, alt=1, name="UNDEFINED"
Found DFU: [0483:df11] devnum=0, cfg=1, intf=0, alt=2, name="UNDEFINED"
Found DFU: [0483:df11] devnum=0, cfg=1, intf=0, alt=3, name="UNDEFINED"
Anyone know why I'm getting four identical devices and how to fix it?

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: CAN bus implementation

Post by blmorris » Mon Jun 23, 2014 2:28 am

Don't know if this is the problem you are having, but I think you need to be using DFU-util >= 0.7 to be compatible with ST's DFU extensions.

Post Reply