B-g431-esc1 CAN interface

Hi All,
I’ve done quite a bit of reading about using CAN with MCP2515 CAN Bus SPI Module Arduino and that makes sense, but its not clear to me how the integrated CAN is used in the b-g431-esc1.

I’ve also read these two threads but TBH I’m a little lost, and unsure if the libraries mentioned are applicable to the B-G and an Arduino dev environment. I’m not a software pro more a persistent hacker lol !

All I’m looking to do (at least initially) is to send individual position demands to multiple motors over a single CAN bus instead of individual hobby servo PWMs I’m doing Dev work with at the moment. I’ll be using them in a fairly harsh EMC environment and am expecting PWM not to cut it for that situation. Eventually I’ll want to return motor / driver status and other information to a central co-ordinating main board but small steps first.

Has anyone got a simple can bus exchange working on the b-g431-esc1, if so any advice on how to work with that interface within Arduino dev environment would be much appreciated.

Many thanks
Barry M

Here we go: GitHub - Igitigit2/SimpleCanLib

I am the author, but the code is a lot copied together from other sources.

Have fun,


@CNCModeller, I just saw that you were looking for Arduino explicitly. My lib works in the Arduino environment on Platformio, but not using the native Arduino tools. I would clearly recommend using platformio anyway. Arduino is great for very simple projects and to get started, but as soon as your projects get more complex, the Arduino environment will reach its limits.

Best regards,

Thanks @Grizzly, I guess I need to take the training wheel off and have a play with the Platformio IDE.

I was hoping not to have to go that far this early in the project but hey ho…

Wish me luck! :slight_smile:

Many Thanks
Barry M

1 Like

Good luck! It’s worth the efforts.

  • Chris

Hi @Grizzly ,
I’ve got your library ping pong example code working on a B-G but I also wanted to communicate with another Arduino using an MCP2515 CAN Bus spi module which allows definition of the message ID and payload. Will I be able to send and receive data between the two with your library? Can I use it for the SPI can module too? I’m guessing probably not?

As a fall back I assume I can use the spi setup to sniff out the message IDs etc sent via your library?

I’m also aware that lower value IDs are prioritised over CAN, is that something I can manage via your library too?

Looking at the message setup .h file I’m still only vaguely understanding how the approach of definition of message instances work. But I think I’m getting there.

Any thoughts would be much appreciated.

Many thanks
Barry M

Dear @CNCModeller,

That is great news, with that you have a really solid basis to develop your own application layer!

Currently, there is no support for the MCP2515 in my library and I do not own any such module. Since I am peeking at @Valentine 's Hackjammer boards however, I might add suppot for it in the future, but that won’t be very soon certainly. Supporting the chip should not be too difficult, since there are libraries which implement the low level routines in pretty much the way I need it in my library too. But, as usual, the devil will be hidden somewhere in the details probably. All that would be required will be writing a chip specific version of the class SimpleCan, which is defined in SimpleCan.h.

As a side note here: One of the great advantages of my lib is that it decouples all interrupt service code from the actual application using (on ESP32: thread safe) queues. This means, when you are handling incomming messages in your application, you are not in an interrupt service routine and you can use serial, printing and whatever you need. I had serious problems before I implemented it this way.

That should be no problem. The CAN bus doesn’t care which library is sending and receiving. In principle you will have to implement everything which my library defines in the application specific xxxProfile.h file. In that file you find the CAN IDs used as welll as the definition of functions which handle the incoming messages for those IDs (the broker class…). Note that the xxxProfile.h file defines the interfaces only. The actual implementation should be somewhere else in your code. This allows you to use one single header file to define the entire CAN bus application layer (profile) without forcing all involved modules to include header files for e.g. SimpleFOC or other code that might be required to react on received CAN IDs.

This is implicit. You can define the CAN IDs as you need them and everything else is controlled by the very low level CAN bus protocol and the way access to the bus is controlled. It happens inside the controllers.

If you need more help on this, please let me know.

Best regards,

There is a well-developed and supported CAN library used in automotive for that chip, since it’s industry standard. I also developed a sample board for development testing. Please check out this post

Implements MCP2515 / SN65HVD230 3.3v input and logic combination.

Using library:


Thanks @Valentine & @Grizzly

Yes I have used an SPI based module on my normal Arduinos. One of these:


I’m hoping to use that as a central master device that sends position demands to multiple b-g driven motors.

Will have a look at the library.:+1:

Many thanks!

Barry M

Dear Valentine,

I am aware of that library and it certainly is very good, but implements the very low level only. It is the code which I would use to extend my library to support MCP2515. My goal is to have a common interface for all supported CAN bus controllers, to keep the application free from code called from ISRs and to have a clearly separated application layer which defines CAN IDs and all the associated functionality. The application layer should be ignorant of the low level implementation and actual hardware. A good example is the ping-pong demo which comes with my lib. Both, ESP32 and G431 share the same application layer code, CAN IDs, handler for received messages, header file etc. for exchanging data.

Best regards,