Skip to content

[ESP32] CAN bus and MOD bus master RTU. #5087

Description

@beyonlo

Hello.

  1. Are there support or plans to support CAN bus on ESP32? I see that there are a implementation for pyboard https://docs.micropython.org/en/latest/library/pyb.CAN.html - is that a similar implementation on the ESP32?

  2. And about the MOD bus master RTU on micropython?
    I think that, differently of CAN bus, MOD bus implementation is not a microcontroller dependent, just works over UART, is that correct?
    I not found a implementation for the modbus master RTU in micropython libs and so on, anyone know if are there a third lib for that?

Thank you so much.

Activity

  1. rolandvs commented on Sep 11, 2019

    @rolandvs
    Contributor

    There has been some discussion on the Micropython forum about modbus:
    https://forum.micropython.org/viewtopic.php?t=5453

    You can get some more info on ESP32 CAN use via this:
    https://hackaday.io/project/20204-esp32-can-driver

  2. nos86 commented on Sep 23, 2019

    @nos86

    Hello,
    I'm interested on CAN communication as well.
    I know that Pumbaa (a fork of Micropython) exists, but its creator said me it is no longer mantained.

  3. nos86 commented on Oct 6, 2019

    @nos86

    Hello,
    I just give an update to everyone is interested.
    Since I was not able to find nothing on the web, I've decided to write the module by myself.
    A very first version has been published on my repository. If anyone is interested, here the link of it: https://github.com/nos86/micropython/tree/esp32-can-driver-v1
    Since the branch is in continuous development, I prefer to give you the link to the tag of first stable version.

    Do not hesitate to open an issue for any new request or just to highlight any bug on the code.

  4. coffice12 commented on Oct 7, 2019

    @coffice12

    Hello,
    I just give an update to everyone is interested.
    Since I was not able to find nothing on the web, I've decided to write the module by myself.
    A very first version has been published on my repository. If anyone is interested, here the link of it: https://github.com/nos86/micropython/tree/esp32-can-driver-v1
    Since the branch is in continuous development, I prefer to give you the link to the tag of first stable version.

    Do not hesitate to open an issue for any new request or just to highlight any bug on the code.

    hava a example?

  5. nos86 commented on Oct 9, 2019

    @nos86

    I have updated the Quick Ref file. Here the link to CAN Bus section: https://github.com/nos86/micropython/blob/esp32-can-driver-v1/docs/esp32/quickref.rst#can-bus

  6. beyonlo commented on Oct 9, 2019

    @beyonlo
    Author

    @nos86

    Great work. Maybe you need to contact the @dpgeorge to commit this CAN Bus driver on the master libs. :)

    By the way, did you wrote or something with a MOD bus RTU Master on MicroPython? I need to use that to read/write from ESP32 to a slave devices that implement MOD bus RTU.

    Thank you.

  7. nos86 commented on Oct 10, 2019

    @nos86

    Actually not, my goal was to develop the driver for CAN hardware for my project.
    Regarding the merge in master, I'd like to add some additional basic function before request a pull.

  8. camosoul commented on Nov 7, 2019

    @camosoul

    Things go slow when not incentivized... Last post 29 days old...

    Might a modest bounty speed things up? I'd really like a proper CAN implementation (with proper documentation to go with it) for ESP32... It's very odd that PyBoard and other MCUs with CAN are supported in uPython, but somehow ESP32 got a miss on it...

    How it got to a 1.0 release with this glaring omission is kinda ... wut? Car v1.0 doesn't have tires or a gas tank... [confusion]

    I can't code worth a damn, but I can spend money...

  9. mlokhandwala commented on Dec 12, 2019

    @mlokhandwala

    Hi @nos86,
    So how does one install the CAN bus driver? Is it install-able by pip or does one have to compile the source code? I am desperately looking to use the CAN bus in my project and currently having to make do using the UART although the PCB is intended to communicate via CAN.

  10. camosoul commented on Dec 12, 2019

    @camosoul

    Hi @nos86,
    So how does one install the CAN bus driver? Is it install-able by pip or does one have to compile the source code? I am desperately looking to use the CAN bus in my project and currently having to make do using the UART although the PCB is intended to communicate via CAN.

    It's about to be a native part of MicroPython thanks to this excellent fellow.

    See here: #5310

  11. sandervandegeijn commented on Dec 15, 2019

    @sandervandegeijn

    Great work! I really could use this for a project I'm doing since I don't care much for writing all this C-code. How does the ESP32 hold up with CAN & micropython when the can bus is quite busy?

  12. nos86 commented on Dec 17, 2019

    @nos86

    Hello @neographikal,
    for the first release, I'm not sure I'm able to include the configuration of the filter.
    If so, the software filtering at uPython level is not suitable for high bus-load conditions.

    For the next releases, I'm planning to incorporate the configuration of hardware filter (best option for very high bus load) and some software filter handled at low level by C in order to improve the flexibility of the library.

  13. sandervandegeijn commented on Dec 17, 2019

    @sandervandegeijn

    Good to know :) Thanks!

  14. sandervandegeijn commented on Dec 23, 2019

    @sandervandegeijn

    I have updated the Quick Ref file. Here the link to CAN Bus section: https://github.com/nos86/micropython/blob/esp32-can-driver-v1/docs/esp32/quickref.rst#can-bus

    Going to ask some stupid questions;

    Is this lib meant for the onboard can bus controller on the ESP32? The SDA/SDL references threw me off a bit, or is the internal one also i2c based? I'm using the internal controller with an 2551 transceiver.

    I have an proof of concept working in C now;

    void setup() {
      Serial.begin(115200);
      CAN_cfg.speed = CAN_SPEED_250KBPS;
      CAN_cfg.tx_pin_id = GPIO_NUM_5;
      CAN_cfg.rx_pin_id = GPIO_NUM_4;
      CAN_cfg.rx_queue = xQueueCreate(rx_queue_size, sizeof(CAN_frame_t));
      // Init CAN Module
      ESP32Can.CANInit();
    }
    

    is the baudrate parameter 250 for 250kbps?

    Thanks :) Going to try this, nice to have some spare time in the holidays ;)

  15. 21 remaining items

  16. skpang commented on Feb 22, 2020

    @skpang

    Hi nos86,

    I've just tried the new v3 binary but after flashed the board I'm getting this error:
    rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:2
    load:0x3f400020,len:228892

    Is this the correct binary for an Adafruit HUZZAH32 – ESP32 Feather Board ?

  17. Civilduino commented on Mar 13, 2020

    @Civilduino

    Hello @nos86, first great work implementing the CAN drivers. Did you finish the complete implementation with filters? How can I use it with the lastest MicroPython and not your bin file?

  18. Tbruno25 commented on Jun 6, 2020

    @Tbruno25

    @nos86 Anything I can do to help with the development for this?

  19. nos86 commented on Jun 10, 2020

    @nos86

    Hello @Tbruno25,
    thank you for your interest.

    The module is already ready for integration and I'm still waiting for merging.

    I saw several people that are not able to use the HEX file I've compiled. Unfortunately at this time, I don't have an hardware ready for test and I cannot check a new compiled file.

    Are you able to do it? If yes, it would be very useful for the community until my implementation is not merged in main project.

  20. skpang commented on Jun 10, 2020

    @skpang

    Hi nos86,
    I have the hardware to test. Do you have a hex file the ESP-WROOM-32D ?

  21. nos86 commented on Jun 10, 2020

    @nos86

    Hi @skpang,
    thank you for your helping but this kind of loop (where i compile the file and you test it) is very time consuming, because it's not so easy to understand why it is not working.

    The best option is that someone has the envirmoment setup and the hardware so he will be sure that the image works without problem and then I can release it for all.

  22. camosoul commented on Jun 10, 2020

    @camosoul

    @nos86

    The previous .bin you provided worked for me... I've got about 20 ESP32 boards laying about... They're not expensive. What happened to yours? Are they hard to get where you live?

    I can send you some...
    Or, you can send me knowledge.
    Or, we can do nothing and just sit around some more...

    I've got some machines running Arch Linux that could be used, ssh, etc... Even if I don't understand, you can ssh and I'll plug an ESP32 into the USB port...

    Willing to do stuff, but not good at this #LearnToCode stuff since nobody ever writes intelligible docs or wants to explain anything...

  23. Tbruno25 commented on Jun 10, 2020

    @Tbruno25

    @nos86 I can definitely help with that.

    First I compiled a new .bin from your master and have encountered the same issue @skpang reported above.

    it seems to go into an infinite boot loop with the following error:

    rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:2
    load:0x3f400020,len:234340
    ets Jun 8 2016 00:22:57

    I then realized the master branch has no machine_can.c so I checked out esp32-can-driver and tried to compile again. However I'm unable to complete as it gets interrupted by the following error:

    CC machine_can.c
    machine_can.c: In function 'machine_hw_can_recv':
    machine_can.c:301:51: error: 'MP_ROM_NONE' undeclared
    { MP_QSTR_list, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} },
    machine_can.c:301:51: note: each undeclared identifier is reported only once for each function it appears in make: *** [../../py/mkrules.mk:47: build-GENERIC/machine_can.o] Error 1

  24. jbakuwel commented on Jun 22, 2020

    @jbakuwel

    @nos86, @Tbruno25 for what it's worth: v2 of the firmware loads fine on the ESP32 board I have here but v3 goes into the mentioned infinite boot loop. What has changed between v2 and v3 that could cause this?

    @nos86, The board I have has three CAN buses, do you think it's feasible to make all those accessible with uPython?

  25. ChessSpider commented on Sep 3, 2020

    @ChessSpider

    hi @nos86 just wanted to leave behind some positivity by telling you I appreciate all the hard work you've put into this. I really hope you are able to continue the work.

  26. Tbruno25 commented on Oct 11, 2020

    @Tbruno25

    While we are waiting for this to be added to the official micropython repo, if you need CAN bus you can give this firmware a try. It's a modified version of Pycom's WIPY firmware which implements CAN -- confirmed working with a sn65hvd230 on an esp32-wroom-32.

  27. newbie-gk commented on Feb 23, 2021

    @newbie-gk

    I see that it's been a while since the last update....
    Any updates on the request being implemented in the official micropython?

  28. IhorNehrutsa commented on Jun 22, 2021

    @IhorNehrutsa
    Contributor

    WIP: esp32 CAN(TWAI) driver
    #7381

  29. FeroxTL commented on Sep 21, 2022

    @FeroxTL

    Is there any progress with this PR?

    I was able to build it with latest master version (1.19.1) with replacing definition of const mp_obj_type_t machine_can_type to

    MP_DEFINE_CONST_OBJ_TYPE(
        machine_can_type,
        MP_QSTR_CAN,
        MP_TYPE_FLAG_NONE,
        make_new, machine_hw_can_make_new,
        print, machine_hw_can_print,
        locals_dict, (mp_obj_dict_t *)&machine_can_locals_dict
    );

    but it is not working with my hardware. Maybe I missed something? I'm using VP230 for converting TTL levels of esp32 to CAN BUS levels. According to oscilloscope it should send and receive some data, but the only thing I can see is increasing rx_error_counter and bus_error_count in can.info()

  30. added
    enhancementFeature requests, new feature implementations
    on Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementationsport-esp32

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions