MicroPython CAN bus for ESP32
-
- Posts: 2
- Joined: Sat Sep 21, 2019 2:07 pm
MicroPython CAN bus for ESP32
I have been searching up and down for a solid MicroPython library that allows the use of the internal CAN bus controller of an ESP32 board.
Unfortunately I couldn't find anything.
CAN bus is a very essential must have function, and I am genuinely surprised that is is not included in the machine library for the ESP32 hardware.
Does anyone have a solution? I would donate to this forum a reasonable sum if someone would implement it.
Additionally, I also couldn't find a MicroPython library to control an external CAN controller (e.g. for the MCP2515)…
I would appreciate any help.
Alex
Unfortunately I couldn't find anything.
CAN bus is a very essential must have function, and I am genuinely surprised that is is not included in the machine library for the ESP32 hardware.
Does anyone have a solution? I would donate to this forum a reasonable sum if someone would implement it.
Additionally, I also couldn't find a MicroPython library to control an external CAN controller (e.g. for the MCP2515)…
I would appreciate any help.
Alex
Re: MicroPython CAN bus for ESP32
Hello.
I agree, CAN Bus, like as MOD bus are very essential, and I am surprised too those it is not included in the micropython for ESP32.
For the CAN Bus, ESP32 has the MAC/Controller, but not the transceiver. But if you need just to communicate from a microcontroller to microcontroller, like as ESP32 to ESP32, or ESP32 to STM, and so on, you do not need the transceiver.
I agree, CAN Bus, like as MOD bus are very essential, and I am surprised too those it is not included in the micropython for ESP32.
For the CAN Bus, ESP32 has the MAC/Controller, but not the transceiver. But if you need just to communicate from a microcontroller to microcontroller, like as ESP32 to ESP32, or ESP32 to STM, and so on, you do not need the transceiver.
-
- Posts: 2
- Joined: Sat Sep 21, 2019 2:07 pm
Re: MicroPython CAN bus for ESP32
Dear beyonlo,
Thank you for your reply.
At this point I am not worried about the bus driver, this I would do externally of course.
Maybe someone can tell me if and how it would be possible to make an official request directly to the MicroPython developers who could be in charge of this.
Thank you for your reply.
At this point I am not worried about the bus driver, this I would do externally of course.
Maybe someone can tell me if and how it would be possible to make an official request directly to the MicroPython developers who could be in charge of this.
Re: MicroPython CAN bus for ESP32
Hi, you can to try to open a issue in the https://github.com/micropython/micropython
There has many open requests, and maybe more developers can see your request. I don't know if there is the best way, but is another place that you can to try.
There has many open requests, and maybe more developers can see your request. I don't know if there is the best way, but is another place that you can to try.
Re: MicroPython CAN bus for ESP32
aklein9999 wrote: ↑Mon Sep 23, 2019 2:39 pmMaybe someone can tell me if and how it would be possible to make an official request directly to the MicroPython developers who could be in charge of this.
Yup, this is the best way. Unfortunately the word "CAN" isn't very easy to search for in the existing bugs.beyonlo wrote: ↑Mon Sep 23, 2019 11:22 pmHi, you can to try to open a issue in the https://github.com/micropython/micropython
The feature you want is not terribly difficult to implement (compared to some of the other features that people are looking for!) and is supported by the ESP-IDF (see https://docs.espressif.com/projects/esp ... s/can.html ).
MicroPython is an open source project and the ESP32 port is almost entirely contributed by volunteers. CAN would obviously be a great feature. If you need this feature to be implemented then finding a way to fund someone else to do it might be a good option to get it done sooner. Whomever you find to implement it probably doesn't need that much MicroPython experience -- CAN and ESP-IDF experience is probably far more useful, so you could probably search outside of the MicroPython community.
I personally would love to see more of this "sponsored development of features" so I'm glad to see you offering. (But I understand that other people feel differently).
Re: MicroPython CAN bus for ESP32
For the STM32 port there is CAN support from the beginning and recently FDCAN is added for the H743. The python class/bindings with C are already there so that any effort for the ESP32 can get a head start!
R
R
Re: MicroPython CAN bus for ESP32
Yeah, that's a great point. And possibly some additional inspiration, the MCPWM implementation from this thread viewtopic.php?f=18&t=6998 is a great example of a self-contained implementation of making an ESP-IDF feature available to Python. (Specifically this commit: https://github.com/bskp/micropython_esp ... 4425fc7928 )
Re: MicroPython CAN bus for ESP32
Seems like development stopped. Is anyone aware of a functional CAN implementation on esp32?
Re: MicroPython CAN bus for ESP32
Just brought the file machine_can.c from the fork
https://github.com/nos86/micropython/tr ... can-driver
into the MicroPython V1.13 project compiled with esp-idf-v4.0.1.
There were some minor adaptions to macro usage around error strings with MP_ERROR_TEXT necessary and I also changed the constant mentioned in the single PR 'Fix CAN std id length 11 bit' on the project of nos86. Also don't forget to adjust the modmachine.c/h files with the incantation for the CAN module like
Enabling the compilation and inclusion of the CAN module can then be managed by having
in mpconfigboard.h for whatever board you compile MicroPython.
After that the CAN module comes up when issuing
Further testing is needed for sure, but so far so good, I'll report back when I can connect to my Sol-Ark 12K inverter via CAN.
https://github.com/nos86/micropython/tr ... can-driver
into the MicroPython V1.13 project compiled with esp-idf-v4.0.1.
There were some minor adaptions to macro usage around error strings with MP_ERROR_TEXT necessary and I also changed the constant mentioned in the single PR 'Fix CAN std id length 11 bit' on the project of nos86. Also don't forget to adjust the modmachine.c/h files with the incantation for the CAN module like
Code: Select all
for modmachine.c
:
{ MP_ROM_QSTR(MP_QSTR_TouchPad), MP_ROM_PTR(&machine_touchpad_type) },
{ MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) },
#if MICROPY_HW_ENABLE_CAN
{ MP_ROM_QSTR(MP_QSTR_CAN), MP_ROM_PTR(&machine_can_type) },
#endif
{ MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&machine_dac_type) },
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) },
:
for modmachine.h
:
extern const mp_obj_type_t machine_rtc_type;
extern const mp_obj_type_t machine_sdcard_type;
extern const mp_obj_type_t machine_can_type;
:
Code: Select all
#define MICROPY_HW_ENABLE_CAN (1)
After that the CAN module comes up when issuing
Code: Select all
from machine import CAN