TMC is an independent, primarily volunteer organization that relies on ad revenue to cover its operating costs. Please consider whitelisting TMC on your ad blocker or making a Paypal contribution here: paypal.me/SupportTMC

Using a Raspberry Pi 3 to interface with powertrain bus CAN3

Discussion in 'Model S: Driving Dynamics' started by apacheguy, Mar 31, 2016.

  1. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    At this point, there are several CAN loggers available (TM-Spy, lolachampcar’s logger, obrien28’s Beaglebone Black, and CANtact to name a few). None of them provided quite what I was looking for so I created my own. I’ll be documenting the project here so others can follow along.

    Features:

    Powertrain CAN3 interface and logging
    Optimized for output through HTTP/CGI

    Advantages:

    Powered directly by 12 V line on the connector
    Wifi capability on the Pi 3 allows me to access over home network, remotely (VPN), or while on the go through an in-car hotspot
    Robustness. Eventually I plan to interface the logging with my server DB through a web based API

    You will need:

    Raspberry Pi 3
    PiCAN2 shield with DC DC converter (priced below Evenchick's CANtact)
    CAN3 to DB9 connector (FastTech, OVMS cable)

    Setup:

    Connect everything together and follow the online setup procedure for PiCAN2. Install python can. Install apache2 and configure for CGI. Place python scripts (downloaded from Github) in cgi-bin. Design a simple interface. You can copy mine – easy enough to replicate with screenshots below, otherwise create your own UI.

    Misc. notes: Vampire draw is not appreciably altered. Idle power consumption 1-2 watts. My car still sleeps like a beauty for 8-10 hours before waking to recharge the 12 V. This is a normal sleep cycle. Still having issues with the in-car hotspot so I had to make the graph in my driveway. Granny acceleration wasn’t very exciting, but I did it mostly as a test to see if it could keep up with the frame rates. I measured 1700 fps in my single motor and had no issues.

    Github (apach3guy)

    apach3guy · GitHub

    Disclaimer: Note that this project provided me with my first experience coding in Python… and also my first experience interfacing with a Controller Area Network. I am far from fluent in any coding language. So yes, I’m sure there are bugs and issues will crop up (especially with signed integers), but it is tested and working on my setup.

    Thanks go to wk057 and obrien28 for providing the bulk of the framework.

    chart.png IMG_0049.PNG IMG_0050.PNG
     
    • Like x 1
  2. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    Still need to figure out what's going on with pack current. Seems to have trouble with data that spills over 1000 A, but no trouble with those just a hair below. I've updated my decode to match wk's and I'll give it another go.
     
  3. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    with attachment...
     

    Attached Files:

  4. joshua.MA

    joshua.MA Member

    Joined:
    Feb 25, 2012
    Messages:
    23
    Location:
    Portland, Oregon
    Was the graph generated by your cgi code or offline?
     
  5. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    Offline in excel. Pi logger generates csv files which are easily imported.
     
  6. FlasherZ

    FlasherZ Sig Model S + Sig Model X + Model 3 Resv

    Joined:
    Jun 21, 2012
    Messages:
    7,019
    #6 FlasherZ, Apr 22, 2016
    Last edited: Apr 22, 2016
    Hey apacheguy, while waiting for my PiCAN2 board to arrive I decided to get everything installed and squared up. I found a problem in your latest GIT pull. bms.py line 60 is missing a "0x" in front of "7FFF" which creates a syntax error.

    My PiCAN shield should be here tomorrow (the USPS apparently has a rather large definition of "2" when it comes to "2-day priority"). The OVMS cable is on a slow boat from China (literally).
     
  7. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    Yeah, I have more recent versions available. I'll try to commit those changes tomorrow.
     
  8. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    I created a cronjob to run cloud.py every 30 minutes. Basically cloud.py stores some key parameters and posts to a cloud URL as JSON. Let me know if there is any interest in this and I can upload to github.
     
  9. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    V2 committed to Github. New features and improvements.
     
  10. FlasherZ

    FlasherZ Sig Model S + Sig Model X + Model 3 Resv

    Joined:
    Jun 21, 2012
    Messages:
    7,019
    QQ for you (before I make a bad assumption). On the PiCAN2 board, which side are your solder pads configured for? OBD2 (pins 2/3/5) or CAN (pins 3/7/2)?
     
  11. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    CAN spec calls out on the Fasttech cable. Close the solder jumpers SJ1-3 on the right.

    Other misc notes:

    Cable attaches to CAN output below the 17".
    Scripts all generate web output except for logger and logger_spc. Logger is to replicate Bill's logger functionality. Logger_spc is intended to log a supercharging session for 45 min or so.
     
    • Like x 1
  12. FlasherZ

    FlasherZ Sig Model S + Sig Model X + Model 3 Resv

    Joined:
    Jun 21, 2012
    Messages:
    7,019
    Thanks. It appears cable will be here tomorrow. Now I just have to dig out my soldering station.
     
  13. apacheguy

    apacheguy Sig 255, VIN 320

    Joined:
    Oct 21, 2012
    Messages:
    3,711
    Location:
    So Cal
    Hit 327 kW at 90%. Highest I've ever seen before. The non-perf DU appears to handle a max of 326 kW from the pack. Based on the mech power I get a DU efficiency around 90%.
     

    Attached Files:

  14. Stiction

    Stiction Member

    Joined:
    Jun 7, 2015
    Messages:
    58
    Location:
    United States
    Check out scipy and matplotlib for python. You can do really cool graphs of all kinds directly from python.
     

Share This Page