CAN BUS : multiple closed loop stepper configuration

Hi,
I´m new to Klipper, I used marlin for a while on ultimaker printer at work and started building my custom 3D printer/CNC/laser cutter based on C-Beam open build.

to make it short
it´s a dual Y&Z axis with one stepper on each axis, each stepper is controled by closed loop controler, right now MKS servo57B, but due to the awfull design on DIR/STEP/ENABLE, I burned one SKR-pro v1.1 board, I´m now investigating using BTT-S57V2 closed loops ( they have optocouplers which won´t burn GPIO due to power feedback)
X axis, extruders are single stepper motors controled, each with closed loop

the toolhead is switchable to receive CNC tool motor, or multi head extruder toolhead (1 material, 1 support and maybe a cyclops for color) , or a laser printer/cutter

the BTT-S57B closed loop controler has CAN interface, so discovered Klipper, and beguns to have lot of ideas ;). BTT-S57B boards (derived from BTT-S42B) firmware is awfully designed, but there is a fork at Using CAN examples? · Discussion #19 · CAP1Sup/Intellistep · GitHub

I´m considering creating my own closed loop controler to had some interface like thermal print head analog input, end/start switch plugs… and maybe more… (power controler board addons…)

all this long for my question… I´ve read the klipper CAN documentation, which will transmit Klipper´s low level messages 8Bytes per 8Bytes from/to the host
I´ve read the klipper MCU low level messages documentation, and If I correctly understood, the host will send queue_step commands and stepper_get_position, config_analog_in commands to make the stepper move, get it´s position or have a value of the analog pin at regular interval…

but now I´m wondering how to write the host config file… looks like the host config file is designed to act has remote direct GPIO controler

I´m wondering how I can write something like
[MCU StepperZ1]
canbus_uuid: 0x1341235
step_per_mm ← is it rotation_distance?
thermal_sensor

[extruder]
canbus_uuid: 0x1341235
rotation_distance: 2mm???
nozzle_diameter: 0.500
filament_diameter: 3.500
heater_pin: PB4
sensor_type: EPCOS 100K B57560G104F
sensor_pin: PK5
control: pid
pid_Kp: 22.2
pid_Ki: 1.08
pid_Kd: 114
min_temp: 0
max_temp: 210

I don´t get why the closed loop controler firmware´s pinout has to be filled, or maybe the PB4 for example is just an ID? and the MCU will receive a queue_digital_out oid=PB4 clock=1000 on_ticks=1 to switch heater on when clock reach 1000? what is the unit of 1000 btw? us? ms? and the closed loop MCU will know that PB4 is heater?
is it possible then to have in config file “heater_pin: heater” and then have a message like queue_digital_out oid=heater clock=WhatIsIT? on_ticks=1000 t

is there an example of communication between the host and several MCU?

thanks and regards
JLM

Here’s a sample multi-mcu config. It would be the same if you’re using multiple CAN boards. The pins are prefixed by the MCU name.

https://github.com/KevinOConnor/klipper/blob/master/config/sample-multi-mcu.cfg

I don’t know of anyone running the S57B v2 board with Klipper. In theory, it should be possible to run Klipper on the board via the CAN interface. (As noted, that would come up just like any other multi-mcu configuration in Klipper.) However, Klipper does not currently support the stepper motor driver, nor does it currently support closed loop motor control.

-Kevin

@jakep_82 Thanks for the config! it made me understand lot of things about configuration

@koconnor right now no S57B v2 board has firmware that can speak with klipper, I’m thinking about adding the function in the redesigned firmware… I made reverse engineering schematics, it can even be transformed into a whole klipper subsystem, with minor board tunning (removal of the central dip switch and use it as extension interface allowing to have 1 thermal sensor attached, 2 fan control and 1 start switch (or two by software detection, it just require to have both switches in // with GND level meaning “limit reached”, knowing if it’s start limit or end limit is just a matter of direction… if we are moving toward start it’s homing reached detection) what is nice with closed loop controler is that they know the position of the motor…
regarding if klipper support this “stepper motor driver” or a “closed loop motor control” is not really important, as long as klipper support “step/Dir/En” interface

for example, according to the configuration given a S57Bv2 modified to have 2 FAN control, one thermal and filament presence detector, would have the following klipper config :

   [mcu auxboard]
       can: /dev/xxxxxxxx

   [extruder]
       step_pin: auxboard:STP
       dir_pin: auxboard:DIR
       enable_pin: !auxboard:EN
       microsteps: 16
       rotation_distance: 33.500
       nozzle_diameter: 0.400
       filament_diameter: 1.750
       heater_pin: auxboard:Heater
       sensor_type: EPCOS 100K B57560G104F
       sensor_pin: auxboard:ThemalSensor
       control: pid
       pid_Kp: 22.2
       pid_Ki: 1.08
       pid_Kd: 114
       min_temp: 0
       max_temp: 250
   [fan]
       pin: auxboard:FAN

The S52b’MCU will then translate the STP, DIR, EN, FAN, Heater, ThemalSensor “PINS” into real actions on according to the real board connection

thanks all for the replies,
I now want to make the GitHub - CAP1Sup/Intellistep: A rework of the terribly coded firmware from the BTT S42B v2 boards< firmware compatible to klipper
so I would like to know if there is a “protocol” library and “CAN protocol” library to be used to support the klipper protocol?