DIY Emergency Stop Button

Has someone already got a Original one and hooked up a Cansniffer to see when the messages are?
Wondering if its a Polling situation for updates, so the Controller is requestign status, if either a ACTIVATED or No message is replied the controller goes into Safe mode or if the Button could be removed/fail without the controller getting the command when the button is activated.

This topic seems to be interesting :+1: - Iā€™m also intrigued DIY modules project.

Not so long ago, I tested CAN communication in Snapmaker modules and quite deeply analyzed open sources code for controller, modules and CAN bus communication logs.

As you probably know, there are two independent CAN buses:

  • first for communication with linear&rotary modules, toolheads, etc. (8 pin cable)
  • second for communication with add-ons : socket Add-on3 (4-pin cable)

Both CAN buses are separated from each other - messages sent between e.g. linear modules on the first CAN bus are not visible on the second CAN bus.

The controller does not poll the CAN devices. Devices / modules if necessary, send specific ID messages (in case of state change, status change, etc.).
Emergency button when it is pressed sends a dedicated ID message to the controller - and then the controller sends the message ID = 0x02 to all devices on both CAN buses. The devices go to a safe stop, an information message is displayed on the screen.
The whole process takes a few milliseconds.
Modules canā€™t react to the ID message sent by the emergency button because they donā€™t receive these messages - they are on a different CAN bus.

:ok_hand: Yes, this is how it works in simplification.

I will only add from myself that when the controller already knows how many and what modules are available then it dynamically assigns the appropriate ID messages to the modules, setting the appropriate priorities. In the CAN bus, the lower the frame ID value has the higher priority and wins arbitration access to Can bus.
When connecting different Toolheads - the modules have different frame ID function -
the functions of the Toolheads have different priorities.

:thinking: I will do some more practical tests in the coming days.

1 Like

Replicating the e-stop functionality from an Arduino via an MCP2515 CAN interface module is cheap and easy since the e-stop is the simplest function.

You can see the simplicity of the module code here, where the core function is the main module loop here: Snapmaker2-Modules/stop_module.cpp at 322043f97a68e69d04e486b89cda2f722f103bc1 Ā· Snapmaker/Snapmaker2-Modules Ā· GitHub

Pseudocode: if (switch.checkStatus() && isConnected()) then ReportStatus(20) //FUNC_REPORT_STOP_SWITCH is function 20

And ReportStatus is just a basic can Send function:
ReportStatus: Snapmaker2-Modules/switch.cpp at 322043f97a68e69d04e486b89cda2f722f103bc1 Ā· Snapmaker/Snapmaker2-Modules Ā· GitHub
PushSendStandardData: Snapmaker2-Modules/can_bus.cpp at 322043f97a68e69d04e486b89cda2f722f103bc1 Ā· Snapmaker/Snapmaker2-Modules Ā· GitHub

There is also some startup code in route.cpp that inits the function list and in registry.cpp that reports the function ids (line 149) when requested (line 108).

Thereā€™s only a couple request function IDs that need to be listened for, and only 1 function response. And almost all of the code can be copy/pasted out of there (maybe not, but at least itā€™s easy to see how it functions).

I have a couple MCP2515ā€™s and have been meaning to implement something like this, probably in an ESP8266 so I can have access to it via wifi. Havenā€™t gotten around, still just a bunch of parts on the workbench. Lately Iā€™ve been using tasmota to integrate with my home automation system via MQTT - I could add the snapmaker as an MQTT module to home automation and keep a central eye on itā€¦hmmm.

1 Like

Yes I agree.
In these crazy times, semiconductor delivery times and prices are problematic.
The ready-to-use PCB module with the MCP2515 & TJA1050 is very quickly available (e.g here
or here ) and much cheaper than the standalone MCP2515 chip. :thinking:

Regarding DIY modules - Iā€™ve already implemented a compatible enclosure controller. The prototype on Arduino works fine - there is a post with details somewhere in the forum.
In that topic - I designed a dedicated PCB - I am waiting for delivery, in the simulation it will look like this:

I will use the mentioned CAN module and Arduino Nano - both cheap and easily available.

Youā€™re right - the Emergency button will be easier to implement. I think Iā€™ll try to do it tomorrow.
Once you understand what the communication between the Snapmaker modules looks like, you can implement each module (of course, those that are currently included in the controller software).

2 Likes

I am happy someone finally did that, and it sounds like you have everything well under control. Am happy to help in any way if you need, this is something I have also been working up towards, albeit adding new functionality and possibly new CAN funcIDs into the controller would be required for my project. Getting a base modular platform based around easy to acquire hardware instead of the GigaDevice ucā€™s would be a boon.

2 Likes

Did you add options to extend the CANbus for more modules aswell? Like put a header or a full D-Sub at the edge somewhere.

Hi guys.
Iā€™ve been busy the last few days, but today finally I found some time to create a program and perform some tests.
The prototype is correctly detected when the machine is started and works as the original.
When the button is pressed all modules stop immediately and an appropriate message is displayed.

You can see ā†’ here ā† how it works.

  • In standby mode - lights up in green continuously.
  • When is activated - it flashes red.
  • When connecting - it blinks red and green alternately.

I donā€™t have the original Snapmaker emergency button so I followed the information available on the official Snapmaker website.

If you have any questions, I will be happy to help.

Itā€™s just a prototype here.
I think Iā€™ll add the emergency button functionality to the enclosure controller module. I will use some typical industrial CAN socket mounted on the housing for this PCB - maybe DSUB or circular M12.

3 Likes

Great work! Looks awesome

This is awesome! Do you have the arduino sketch available somewhere or is it just @brent113ā€™s psuedocode with the dependencies properly copy/pasted from SM source?

Thanks.
Unfortunately, itā€™s a bit more complicated - you canā€™t directly copy / paste from SM sources. The most important thing in my opinion is to understand how the module registration mechanism works, how the controller dynamically allocates available functions according to priorities, calculates CRC, etc. Then you only need to program it. The platform doesnā€™t matter here.

I think I will write a separate long post about it soon :thinking:.
I will explain the mechanism of CAN operation in detail, show the details of the frames and share the files.

3 Likes

I think writing an Arduino style library that can be included in projects would be useful that implements all of the constants used by snapmaker. Iā€™m happy to help write one one of us should start it though.

2 Likes

I donā€™t know if anyone would be interested using this library :thinking: ā€¦ except ā€¦ a few electronics freaks like us :rofl:.
The constants and definitions used by snapmaker in the source header files can basically be copied and pasted but I donā€™t know if such universality is needed here (object-oriented literations, enumeration types, etc.)
I currently have a lot of programming work on similar projects but of course I can help as much as possible.

2 Likes

I usually write a full library as Iā€™m starting a project, and I havenā€™t started yet but I agree itā€™s easy in theory. Iā€™m thinking have the constants, as well as startup registration and ā€˜loop()ā€™ functions for handling the ongoing communications. Standard Arduino plugin type stuff. in init() call snapmaker.init() and in loop() call snapmaker.loop() or some other simple interface.

Anyways Iā€™ll get to that soon I think, another half a year or whatever lmao

2 Likes

There are more ā€˜electronics freaksā€™ around than you think. :wink: :smile:

1 Like

4 Likes

:rofl: :joy: :rofl:

Iā€™ve told you millions of times about exaggerating.

3 Likes

@Ronin if youā€™re willing to give me the source code for your arduino, Iā€™d be happy to refactor it into a framework/api similar to how @brent113 is describing it. My line of work is like 80% refactoring, so Iā€™ve gotten pretty good at it (and Iā€™ve probably seen plenty worse code than anything youā€™ve managed to come up with, so no judgement).

3 Likes

Hi guys.
As I mentioned > here < Iā€™m doing this only for fun, so I will share, describe and explain everything - just give me a week or two, please. Iā€™ll have a little more time after Christmas.
I am an open source enthusiast and I know that teamwork is the best.
@brent113 , @nivekmai, @albutch, @Streupfeffer, @ dozens of electronic freaks :slight_smile:
I will really be happy to help you.

4 Likes

K, my MCP2515 just showed up today, I anxiously await your writeup :stuck_out_tongue: (my hopeful plan is to build a surface modeler toolhead)

2 Likes

Thatā€™s also my plan. Awesome.

1 Like