Stand alone OBC/PDModule EV system Can 2015 - SOLVED

My Nissan Leaf Forum

Help Support My Nissan Leaf Forum:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.
49thdiver said:
Hi, I have just started to scratch the surface on this and immediately found a few interesting remarks, regarding Raspberry Pi and Python.

Regarding PPi.GPIO
- If you need more accurate timing use bare metal RPi (which makes it work like a microcontroller), use a real-time OS with a better pre-emptive dispatcher or run the timing function on an Arduino (which is a single task microcontroller).

Regarding the Python function Time
- Note that this module is unsuitable for real-time or timing critical applications. This is because you can not predict when Python will be busy garbage collecting. It also runs under the Linux kernel which is not suitable for real time applications - it is multitasking O/S and another process may be given priority over the CPU, causing jitter in your program. If you are after true real-time performance and predictability, buy yourself an Arduino

In my experience capturing and processing CAN on a Nissan Leaf is a challenging feat, the sheer volume of data is huge. The leaf is sending and receiving data at millisecond (ms)speeds perhaps microsecond (us) speeds. Just to fake out the OBC you need to send on average 5 messages every 10ms. To do rea-ltime CAN filtering I ended up using Mux's bare metal processor design with "C" to be able to catch and process the messages from the Leaf.

So my Question out to the group before I dig too much deeper does anybody else have any experience and success with using a RPi and Python in this kind of a real-time application where the timing is critical ie sending multiple messages every 10ms with sustained accuracy
General comments welcome my only experience with Python is with processing data for user interface for a web based OBDII device.

Thanks, all the best to everyone over the winter season -10 on Vancouver Island this morning, very unusual. the Ev got us where we needed to go, YEAH.

Consider not using a RPi and especially not Python for the reasons you note. Consider writing your application in "C" and using a development board like this for the actual interface;
It has the functions you'll need, e.g. real time interrupts, timers, & a UART

And with the CAN function (EFM8 and MCP2515) here;

If you want to overkill the application, here's a 32 bit solution;

Silicon Labs provides a C compiler running on Windows, which loads the development board's flash memory once complied.
It also provides an assembler output, if you like to tweak the assembler code.
Thanks lorenfb, All my work so far has been done on a Arduino Due and seems to work well that said there have been speed challenges with some other CANBUS EV work. I have also had the pleasure of using Muxans Bridge based on the XMEGA32C which definitely is up to the job.

Thanks for the comments suggestions and links to some other cool hardware.

In case there are others interested in the Raspberry Pi idea I thought I should provide an update so far.
I managed to squeeze some time into getting as RPi set up with a Waveshare duel port CAN Hat.

I have connected it to my Android DUE transmitting the CAN commands that would normally go to the OBC.

It seems to be receiving them ok. My next step is to try and get the Python code running on the RPi and analyze the
data output.

Even if this proves to not be a suitable platform for running the LEAF OBC, it may be suitable for CAN Logging with a decent user interface which is certainly a good tool to have if your trying to hack these LEAF's.

Stay tuned.
Conclusions on using a Raspberry Pi as an OBC controller.
After a fair bit of messing about with different bits of hardware and software I was able to get some good clean recordings of the Raspberry Pi CAN data transmission and indeed with no other know tasks working in the background the data and the timing all looks good. I will next try the raspberry pi on my car in place of the Arduino Due and report back on whether it works properly or not.
Well sorry folks it only took 5 months to get back to testing this on my test bench.
The good news is the python code works perfectly. Well done Cees and friend.
Here is a really quick short sloppy video shot last night to wrap this up.

Note : when I say unregulated what I mean is the code does not stop charging when the battery is full that needs to be added for what ever battery you are charging. Be warned.
I will update the code eventually when I get that project finished completely.
On to installing a 30KW battery in the Kubvan and the 24Kw is going to go into my RAVEV.
Should be a good summer.