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 and becoming a Supporting Member. For more info: Support TMC

Very cheap CAN BUS reader with Arduino UNO, Battery Voltages Example

Discussion in 'Model S' started by Gesteur, Aug 27, 2018.

  1. Gesteur

    Gesteur Member

    Jan 24, 2018
    #1 Gesteur, Aug 27, 2018
    Last edited by a moderator: Aug 27, 2018
    Hi all,

    I have replied on different posts and thought it might be good idea to have a centralised place to put all info on how to read CAN bus from an Arduino UNO.

    The advantage of Arduino UNO + CAN BUS MCP2515 is that it's very cheap, you can get all components
    for around 10$ if not less.
    Ideal if you want to start playing around and I'm conscious that a more flexible setup could be achieved with a raspberry pi which has WIFI and Bluetooth.
    Nevertheless if you want an easy&cheap setup this should do pretty fine.

    What do you need?
    - Arduino UNO
    - CAN bus chip MCP2515
    - breadboard wires (female - male)

    Arduino UNO can be bought on ebay and many other stores.

    CAN bus Controller Module: I used the following one MCP2515 also to be found on ebay.
    MCP2515 TJA1050 EF02037 CAN Bus Shield Receiver SPI Controller IC for Arduino | eBay

    Once you get the hardware, then you can use the following Arduino MCP library written by Fowler.
    import the lib in your arduino suite.

    The wire configuration :
    connect the SPI pins from the CAN bus board to Arduino UNO

    INT -> pin 2
    CS -> pin 10
    SI -> pin 11
    SO -> pin 12
    SCK -> pin 13
    GND -> GND
    VCC -> 5V

    The Can High and Can Low from the module can be attached to the Tesla diagnostic port which is below the big 17' screen, for models 2015 and newer.
    CAN H --> x437a pin 18
    CAN L --> x437a pin 19
    check pinout at x437a diag connector pinout for Tesla Model S

    You can easily use the examples already provided in the lib and filter by the message ID you like.

    In the attached code you will find a working example of filtering and displaying msg ID 6F2 (Battery Cells Voltage and Temperature).
    The output will be on the serial port, so if you are connected with your PC via USB it will display on the serial monitor of the Arduino software.

    Code setup:

    The CAN module has an 8MHZ oscillator, so the CAN chip needs to be initialize accordingly
    CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ)

    You can change MCP_ANY to MCP_STDEXT and use MCP2515 filters to filter only specified frame IDs (in the source attached I have commented code as an example).
    I personally just use code filtering for this easy example, rxId contains the frame id, so i can do my frame handling when rxId == 0x6F2.

    Also it's a good idea to set the serial baud rate to 115200.

    So far I could read all battery information along with other stuff too, don't seem to miss any frames here.
    Havent tried yet to capture data while driving, where most probably there will be more frames on the bus.

    other setups to access the diagnostic port and read the CAN bus can be found here
    Diagnostic Port Index


    Attached Files:

    • Like x 2
    • Informative x 1
  2. Gesteur

    Gesteur Member

    Jan 24, 2018
    Attaching updated version of source code, enhanced displaying of cells voltages + module voltages.

    Attached Files:

    • Like x 2

Share This Page

  • About Us

    Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.
  • Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.