# CAN bus library for ESP32 and STM32

**URL:** https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478
**Category:** Uncategorized
**Created:** [September 16, 2022, 7:35pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478 "2022-09-16T19:35:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Grizzly](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@Grizzly](https://community.simplefoc.com/u/Grizzly)
#### Post date: [September 16, 2022, 7:35pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/1 "2022-09-16T19:35:00Z")

</div>

Time to give something back to the community. I have cleaned up the code and the repo and made it public now. It can be found here:

[https://github.com/Igitigit2/SimpleCanLib.git](https://github.com/Igitigit2/SimpleCanLib.git)

Support for STM32 and ESP32 is available and I added an extensive readme.md. Probably there is still a lot to be improved in the documentation, but for now it must suffice. I hope I won’t mess up things simce I am always fighting wit github, branches and pull requests…

Anyway, have fun with it and let me know if something doesn’t work as expected!

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [September 16, 2022, 8:55pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/2 "2022-09-16T20:55:28Z")

</div>

> [@Grizzly](#):
>
> Anyway, have fun with it and let me know if something doesn’t work as expected!

Thank you, this is great.

Cheers,  
Valentine

PS In case anyone needs the ESP32 PCB DIY, with baked in CAN Transceiver:

> **[立创开源硬件平台](https://oshwlab.com/cost.co/esp32_dev)**
>
> 基于嘉立创EDA进行电路设计的硬件开源设计大本营,集嵌入式、电子模块、DIY设计、物联网、智能硬件、电子应用、电工电子等多种电路设计模块为一体的开源硬件平台

 ![image](https://community.simplefoc.com/uploads/default/original/2X/4/4af24ba398e6621da6ffb1215e11919ae08c1a2a.jpeg)  
 ![image](https://community.simplefoc.com/uploads/default/original/2X/c/cd84d0c03f580bd2fdd4c3f3981380fad9be548e.png)

---

<div class="post-metadata">

### Author: ![MoidKhan](https://community.simplefoc.com/user_avatar/community.simplefoc.com/moidkhan/32/3220_2.png) [@MoidKhan](https://community.simplefoc.com/u/MoidKhan)
#### Post date: [September 20, 2022, 11:04am UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/3 "2022-09-20T11:04:01Z")

</div>

How can it be added to the Arduino library? I mean in Arduino ide rather than platform IO.

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [September 20, 2022, 12:00pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/4 "2022-09-20T12:00:08Z")

</div>

It should work if you add the files to your Arduino project folder… its not (yet?) packaged as an Arduino library, so it won’t work via the library manager…

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [September 20, 2022, 2:22pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/5 "2022-09-20T14:22:59Z")

</div>

> [@MoidKhan](#):
>
> How can it be added to the Arduino library? I mean in Arduino ide rather than platform IO.

You can package it as a library yourself. Although I agree with @runger that it probably needs to be properly packaged as a library by @grizzly, who owns the project.

> **[Create Your Own Arduino Library - The Robotics Back-End](https://roboticsbackend.com/arduino-create-library/)**
>
> Learn how to create your own Arduino library! Step by step tutorial with complete code example and detailed explanations.

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![Grizzly](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@Grizzly](https://community.simplefoc.com/u/Grizzly)
#### Post date: [September 20, 2022, 7:28pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/6 "2022-09-20T19:28:26Z")

</div>

Unfortunately I am currently a bit short on time and not using Arduino, so I don’t know how to pack it as a lib for Arduino quickly. I think however, you should be good when copying it to Arduino’s lib folder and somehow set the defines as in the platformio.ini file (see the lines with -D). The Platfomio.ini files contains one configuration for STM32 and one for ESP32.

As soon as I find some time, I will try to add it as a lib as well or at least prepare some instructions.

---

<div class="post-metadata">

### Author: ![Grizzly](https://community.simplefoc.com/letter_avatar_proxy/v4/letter/g/a9adbd/32.png) [@Grizzly](https://community.simplefoc.com/u/Grizzly)
#### Post date: [September 20, 2022, 7:51pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/7 "2022-09-20T19:51:24Z")

</div>

Hm, bad news. I just checked if there is a simple way to use it in Arduino, but it seems there is no simple way in Arduino to set project specific defines through the compiler. I’ll probably find a way around somwow, but that means more time.

---

<div class="post-metadata">

### Author: ![Valentine](https://community.simplefoc.com/user_avatar/community.simplefoc.com/valentine/32/1024_2.png) [@Valentine](https://community.simplefoc.com/u/Valentine)
#### Post date: [September 20, 2022, 8:38pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/8 "2022-09-20T20:38:52Z")

</div>

> [@Grizzly](#):
>
> that means more time

Whoever is going to use it will have to find a way. You did the hard part.

Cheers,  
Valentine

---

<div class="post-metadata">

### Author: ![runger](https://community.simplefoc.com/user_avatar/community.simplefoc.com/runger/32/395_2.png) [@runger](https://community.simplefoc.com/u/runger)
#### Post date: [September 21, 2022, 2:57pm UTC](https://community.simplefoc.com/t/can-bus-library-for-esp32-and-stm32/2478/9 "2022-09-21T14:57:22Z")

</div>

TBH, I’d say if you’re ready for CAN-bus, you’re ready to move on from ArduinoIDE. 😃

All its advantages when you’re new to programming really become disadvantages once you have a bit of experience…
