ESP32 and MCP2515 Wiring + Code for Opel Astra H CAN BUS (Pin 6 & Pin 14)

Hello everyone,

I want to connect an ESP32 with an MCP2515 module to my Opel Astra H in order to read water temperature and voltage via CAN BUS (pin 6 and pin 14). I already have the OLED display connected, so that part is done.

My main questions are:

  1. How should I wire the MCP2515 to the ESP32 to properly connect to the car’s CAN BUS (pin 6 & pin 14)?
  2. Can someone provide example code to read water temperature and voltage from the car and display it on the OLED?

I would greatly appreciate a clear wiring diagram or pin mapping and a code example so I can start receiving data.

Thank you in advance!

There have been many posts on doing this. Are you going to connect to the OBD connector or are you going to tap the CAN bus and take a chance on destroying your vehicle. Here is some reading that may help, automotive is one of the worst electrical environments you will encounter.

Arduinos are designed for experimentation and learning, often used with breadboards and loose wires, which can become unreliable if vibrated. They are not built for harsh, dirty, or electrically noisy environments commonly found in industrial, automotive, or other commercial applications, making them unsuitable for such settings.

To ensure we can provide the most accurate assistance, please include detailed information about your setup. Specify the exact board, shield, wiring configuration, and power sources you are using. An annotated schematic is ideal, as it provides a clear overview of your setup, but be sure to also include links to the technical specifications of your hardware components.

Before posting your code, please review the forum guidelines and use code tags for better readability. Also, provide links to the technical information about your hardware, and include a preliminary schematic that shows all power, ground, and connections. For additional guidance, you can refer to this link: Useful Links and Tutorials. Note that in this context, breadboard diagrams are not considered proper schematics.

Valuable Resources for Automotive Electronics:

  1. STMicroelectronics Application Note AN2689:
    This application note provides guidelines on protecting automotive electronics from electrical hazards, focusing on design and component selection. Reading this will greatly enhance your understanding of automotive circuit protection.
    Read AN2689

  2. Analog Devices: Automotive Electronics Design:
    This article distills key insights into designing automotive electronics, offering practical advice for engineers.
    Read the article

  3. Diodes Incorporated: Transient Voltage Suppression in Automotive:
    Learn about techniques to protect automotive circuits from transient voltage, which is critical for ensuring reliable operation in harsh conditions.
    Read the article

  4. AEC-100 Standards Webinar:
    This webinar from Monolithic Power Systems provides a detailed overview of AEC standards, essential for understanding automotive electronics requirements.
    Watch the webinar

  5. Understanding Automotive Electronics, An Engineering Perspective by William B. Ribbens:
    This comprehensive book offers an in-depth look into automotive electronics from an engineering perspective, making it an invaluable resource.
    Access the book

  6. Check this for OBD ISO9141 Code Meaning & How To Fix OBD negotation initialization procedure https://cdn.standards.iteh.ai/samples/16738/20ff360c25c6462b811ebc0c9256eee0/ISO-9141-2-1994.pdf Then there is https://github.com/muki01/OBD2_K-line_Reader PID codes: OBD-II PIDs - Wikipedia

  7. Load Dump and Cranking Protection for Automotive Backlight LED Power Suppl https://www.ti.com/lit/an/snva681a/snva681a.pd

  8. Quality requirements:

These resources should provide a strong foundation for anyone involved in automotive electronics design. If you need further help or more resources, feel free to ask!

Setting Up Arduinos with CAN using MCP2515 Modules

I suggest starting with a few Arduinos and setting them up for CAN communication using MCP2515 CAN modules and Cory Fowler's library: MCP_CAN_lib on GitHub. The send and receive examples work great, and you can combine them to send and receive within a single Arduino UNO. Note that the modules cannot acknowledge themselves; CAN communication requires at least two nodes for acknowledgment.

Important Tips for Setting Up Your CAN Bus:

  1. Connect Grounds: Ensure that the ground from each Arduino UNO is connected to reduce noise.
  2. Bus Termination: Properly terminate both physical ends of the CAN bus with 120 Ohm resistors. Failing to terminate both ends will cause communication issues. You can measure the resistance across the CAN leads using an ohmmeter; a resistance close to 120 Ohms indicates proper termination. Only two terminators are needed in total—none are required for nodes in the middle of the bus.
  3. Crystal Configuration: MCP2515 modules may have different crystals; be sure to set the initialization code to match the specific crystal frequency of your module. Check the module’s specifications for guidance.
  4. CAN Specification: The CAN protocol has two parts:
  • Part A (CAN 2.0A): Standard format with an 11-bit identifier.
  • Part B (CAN 2.0B): Extended format with a 29-bit identifier.
    Most devices will likely use CAN 2.0A. The MCP2515 module connects via SPI and is compatible with other SPI devices, but it’s best to start with just the CAN module first.
  1. Minimum Two Nodes Required: A CAN bus needs at least two active nodes because the protocol requires an acknowledgment within each frame. The receiver must be active during transmission to provide this acknowledgment. If the message isn’t acknowledged, the transmitter will register an error and increment its internal error counter. Once the error count reaches its limit, the transmitter shuts down, a process managed by the CAN controller transparently.

For a more in-depth understanding, refer to this helpful tutorial: Interfacing MCP2515 CAN Bus Module with Arduino.

For J1939: GitHub - Kentucky-Fried-Circuits/ARD1939: j1939-compatible CAN library based on ARD1939 by Cooper Hill Technolgies · GitHub

Hello. I am new to this field and am installing by looking at the internet pages.

Salam qardaş məndə axdarıram qoşmuşam bir hissəsini artıq sürət mator isdiliyi mator qazı rpm tapmışam kilometrajla akumulyatorda ilişib qalmışam 1/2 gümə onlarıda yəqin inşallah taparam

What part of my response do you not understand. Without knowing what you have I cannot give an accurate answer.

Salam qardaş çox gözəl. Mən yeni olduğum üçün hələki tapmaqda çətinlik çəkirəm. Mümkündürsə səndə olan kodlaşmanı paylaşarsan. Şəxsi də ola bilər burda da . Əvvəlcədən təşəkkürlər.

Hello. We need coding to measure water temperature and voltage. Thanks in advance.

Sən nəsə tapmısan? Məndə kilometrajnan akumulyator birdə benzin qalıb

Mən chatgpt və geminidən kod istəmişəm o da verdiyi kodlar düz gəlmir:)))

Kodları hardan axtarırsız zəhmət olmasa məlumat verərsiz

you can write the codes yourself. If you do not want to do that there is a for hire section.
Here’s a clear Azeri translation of your text:


Bu, çox maraqlı və əyləncəli ola biləcək bir layihə kimi səslənir! Lakin nəzərə alın ki, biz pulsuz dizayn və ya kod yazma xidməti deyilik. Sizin dizaynınıza və ya kodunuza kömək etməkdən məmnun olarıq, amma əvvəlcə özünüz bir cəhd etməlisiniz. Xahiş edirik, əvvəlcə dizaynınızı hazırlayın və kodunuzu yazın, sonra onu şərhlərlə izah edilmiş sxem və düzgün işləməyən hissələrin açıqlaması ilə birlikdə paylaşın. Əgər bunun üçün ödəniş etmək istəyirsinizsə, “for hire” bölməsi də mövcuddur.

Məncə müəllim/professor sizdən bunu necə edəcəyinizi öyrənməyi və etdiklərinizi başa düşməyi gözləyir. Bu, əsas materialdır və bunu mənimsəməsəniz, işiniz getdikcə daha çətin olacaq.


1. Əvvəlcə İşinizi Göstərin:

Kömək istəmədən əvvəl, dizayn etməyə və ya kod yazmağa bir cəhd edin. İşinizi və düzgün işləməyən hissələri paylaşın. Bu, sizin çəkdiyiniz ilkin sxemi də əhatə etməlidir.

2. Aydın Sənədləşdirmə Təqdim Edin:

Biz layihənizi görə bilmədiyimiz üçün şərhlərlə izah edilmiş sxem (ən yaxşısı) və ya quruluşunuzun aydın rəsmini paylaşın. Aydın şəkillər də faydalıdır, amma Fritzing diaqramlarından istifadə etməyin, çünki onlar sxem deyil, sadəcə naqilləmə diaqramıdır və problemlərin həlli üçün ideal deyil.

3. Texniki Təfərrüatları Daxil Edin:

Əgər xüsusi bir avadanlıqdan istifadə olunubsa, texniki məlumatlara keçidlər əlavə edin. Oxşar komponentlərin çox versiyası ola bilər, buna görə də dəqiq təfərrüatlar vacibdir. Mən prosessorun UNO olduğunu fərz edəcəyəm. Çox vaxt prosessor ESP32 kimi göstərilir, xahiş edirik hansını istifadə etdiyinizi qeyd edin və link paylaşın.

4. Resurslara İstinad Edin:

Əlavə kömək üçün faydalı linklər və dərsliklərdən istifadə edin: Arduino Forum-da faydalı linklər. Əlbəttə ki, mənim fikrimcə ən yaxşı məlumat mənbələrindən biri Arduino Cookbook-dur. Kitabı başdan sona skimm edin və maraqlandığınız layihələrdə dayanaraq oxuyun.


Əgər istəyirsinizsə, mən bunu bir qısa, daha “təlimat üslubunda” versiyaya da çevirə bilərəm ki, tələbələr üçün daha asan oxunsun və addım-addım izləmək rahat olsun.

İstəyirsiniz onu da hazırlayım?

Salam qardaş necəsən? Tapa bilmisən bir şey? Mən hər şey etdim idləri də tapıram amma nəticə olmadı. Maraq üçün çalışıram ki,maşına yerləşdirim. HUD cihaz almışam maşında var. Çox iridir,xoşa gəlmir.Mən usta deyiləm firmada işləyirəm. Bəlkə də getdiyim rayonlardan birində olursan. Sənə bir çay alaram:))) Mümkündürsə köməklik et. Əvvəlcədən Təşəkkürlər.

Salam qardaş çən hamısını tapmışam 2 aya yaxındıki


bir bir yığıramki tapım pulnannyığım satım bakıdayam mən

Salam qardaş.Allah işini avand eləsin.