Jump to content

CAN bus UPDATE script


Dirk

Recommended Posts

On 2/26/2024 at 3:30 PM, Dirk said:

It is not a stupid question. I have only heard a few in my whole life, but... It is a difficult question to answer.

 Found canbus_uuid=403544310df5, Application: Klipper - OCTOPUS PRO 1.01
 Found canbus_uuid=a74fbb9bdf70, Application: Klipper - CARTOGRAPHER v3
 Found canbus_uuid=21c36fa97c26, Application: Klipper - SBB2209 RP2040

 

You use "Cartographer probe v3"
RP2040 and OCTOPUS PRO 1.01 ... all together via CAN, right?

Can You please post here Your CAN Setup?
I mean CAN speed each device for katapult and Klipper
can0 file ?
TRSYNC_TIMEOUT ?
Main MCU, raspberry pi or something bigger?

I ask, because ...
So long I use raspberry pi 4 with OCTOPUS PRO (H723) and Mellow RP2040, I do not have any issues with CAN. Use OCTOPUS as CAN bridge.
But as soon I add Mellow ERCF easy board over CAN, have errors,
Tryed to move to raspberry pi 5 ... the same thing.
Right now I make some tests with "Dell Optiplex 7040 USFF"
looks much better, but I must slow down the CANbus to 500.000
With 1.000.000 I have "Timer Too Close" errors.

In the future will install something like "Cartographer" over CAN too.
Will have all things over CAN but must solve CAN issues before 🙂

 

Link to comment
Share on other sites

1 hour ago, Sergey said:

all together via CAN, right?

yes. The 120 ohm termination is not on my SB2209, but on the cartographer. So it is last in the chain.

1 hour ago, Sergey said:

Can You please post here Your CAN Setup?

All exactly set up like here

1 hour ago, Sergey said:

So long I use raspberry pi 4 with OCTOPUS PRO (H723) and Mellow RP2040, I do not have any issues with CAN. Use OCTOPUS as CAN bridge.
But as soon I add Mellow ERCF easy board over CAN, have errors

if I am not wrong, @mvdveer has a same set up over here and a similar one here. (maybe he used a U2C on his ERCF build). He did not have any timer-too-close- problems if I remember right. 

I do know timer-too-close errors from this description from Esoterical and I am glad I have not ran into them (yet). 

I think the best is to go ask Esoterical on Discord with such unspecific errors as TTC. He has a huge amount of experience, patience and tools.

Good luck.

 

 

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

@Dirk

Maybe im doing something wrong.. and yes, im very certain I am...

Getting an error executing the file, the CMOD executable rights have been applied on the flashCAN.sh file, and confirmed them.

Editted the file in Notepadd++ and only added my UUID and USBID in the right places.

"bad interpreter"

image.thumb.png.7f3e99e7012b3b30e4d31a94fe79609b.png

 

EDIT: Ah, I guess I have to EXECUTE the file.. ok not a Linux guy, but I try to survive.. this is how it was mentioned in the file, but my guess its not correct?

 

EDIT2: IGNORE, somehow the file got corrupted by Notepadd++, never had that before, fixed it by running: 

sed -i -e 's/\r$//' flashCAN.sh

 

  • Like 1
Link to comment
Share on other sites

Another question, I had to put my board in katapult mode to get the USB id, is there any way to get it OUT of this mode again, without powering off the machine?

The command to put it IN katapult mode:

python3 ~/katapult/scripts/flashtool.py -i can0 -u 29186379db86 -r

  • Like 1
Link to comment
Share on other sites

9 minutes ago, Buurman said:

im doing something wrong

I don't know. if you have ran the command

sudo chmod +x flashCAN.sh

succesfully, then it should be okay... 

Was never so sure about things in command line... Back in the time we didnt have google. or wiki. now we do..

https://linuxsimply.com/bash-scripting-tutorial/error-handling-and-debugging/error-handling/bin-bash-m-bad-interpreter/

Apparently your notepad++ added extra dos characters which bash doesnt like.

try this

sudo apt-get install dos2unix

then 

dos2unix flashCAN.sh

This should fix it.

then try running flashCAN.sh again.

Link to comment
Share on other sites

17 minutes ago, Buurman said:

any way to get it OUT of this mode again, without powering off the machine?

flashing the board will get it out of katapult mode 🙂

Or you can push the reset button on the board.

let me see if the manual says something...

[edit] no. no code to remove to chip from katapult mode, except reset/reboot it.

Edited by Dirk
  • Thanks 1
Link to comment
Share on other sites

24 minutes ago, Buurman said:

EDIT: Ah, I guess I have to EXECUTE the file.. ok not a Linux guy, but I try to survive.. this is how it was mentioned in the file, but my guess its not correct?

EDIT2: IGNORE, somehow the file got corrupted by Notepadd++, never had that before, fixed it by running: 

haha

yes... the script is executable. apparently the #!/bin/bash at the top of the file and the chmod commands take care of this

you then indeed need to execute it with chdir to the directory its in. and then do a ./flashCAN.sh from ssh

 

I hope the corrupt files is not a regular thing. corrupt sd card? It might explain why your mellow fly is not working anymore.

Link to comment
Share on other sites

Ran it, and stuff still seems to work... 😛 

Ok my webcam stopped working, but guess it needs a reboot - check yes it did...working.

Uncommented the makemenu lines, looking forward to future updates!!! thanks a lot! LEarned a lot again last 2 days.

Still dont know why my other board stopped working, but my best guess is that I loaded a wrong config to it.. it is possible and easy to make a mistake..

You woul just expect the BOOT0 jumper would overrule all, but maybe not.. 

Link to comment
Share on other sites

12 minutes ago, Dirk said:

I hope the corrupt files is not a regular thing. corrupt sd card? It might explain why your mellow fly is not working anymore.

No its a windows thing, opened it ones in a windows edittor maybe over WinSCP, that added hidden characters to the file, Linux doesnt like them.

Nothing to do with the rest of things I made go wrong 😛  thats just me... 

  • Haha 1
Link to comment
Share on other sites

7 minutes ago, Buurman said:

looking forward to future updates!!! thanks a lot! LEarned a lot again last 2 days.

That is cool. If you understand this script a little, you will understand how this CAN flashing goes... And that makes it easier to deal with problems you might encounter...

Because you have the ercf mellow can board, you need to add that to the script in a similar way as the toolhead-pcb.

 

You need to run the script only if a klipper update makes your setup 'dirty'. I understand it does not happen so often. 

 

Further your mellow board... I think it is worth reflashing it with STMLink. You could start making up a drawer with -toolhead-pcb's-for-in-case. 

Link to comment
Share on other sites

18 minutes ago, Buurman said:

Uncommented the makemenu lines,

 

## once you have run through this script, comment out (put a # in front of the line) the line which has the "make menuconfig" in it.

 

You mean, commented them (out) ... so they are not part of the script anymore, right? 😄

And thanks for featuring it 🙂 (didn't know it was possible!) I am glad it has helped you, and will probably in the future. 

 

 

Link to comment
Share on other sites

58 minutes ago, Dirk said:

And thanks for featuring it 🙂 (didn't know it was possible!

Me neither! Lets see what the boss thinks about it, maybe we can keep it there for a while.... 

 

Yeah I put a # in front of it, ok I am not a linux guy, but I know some scripting, I wrote programs on a Atari 800XL in my time... oh crap.. thats about 40 years ago.. ssst..

1 hour ago, Dirk said:

I think it is worth reflashing it with STMLink. You could start making up a drawer with -toolhead-pcb's-for-in-case

Great minds think alike, I already had it hooked up to my PC to try STMLink, see if I can empty it and reflash it.

And I build Vorons 2.4 350's out of a hobby, but yeah.. im over 20 builds now.. so yeah, I need those Toolheads anyhow.. I build them all with Canbus.

Link to comment
Share on other sites

  • 3 weeks later...

Is it possible to turn this into a Macro that can be ran from within the Fluid or Mainsail interfaces? I have the Github update Macro, which I think would be similar. Would be cool if you could paste in the appropriate settings for your board into drop downs for the Macro and then just run it when needed.

Link to comment
Share on other sites

  • 2 weeks later...
On 4/9/2024 at 1:18 AM, kingstar said:

Is it possible to turn this into a Macro

Sorry for my late reply. Must have overseen this question between all those notifications 🙂
It is of course possible to run it quite similar to the github synchronization script from within mainsail.

This script is only run when you have to re-flash all your CAN boards. (and / or with a katapult update).

It works as such, that you have to first time go through the whole process, and select the specific options for your boards. These are then saved. Then you disable the code that lets you select the board-specific-options by commenting them out. And a second time you run the script, it does remember the options from the first time. So you do not have to look it up and go through all those steps again.

Now calling this script from the mainsail interface would be possible. But I doubt if it would be an addition to comfort? I do not feel it will.
The next time I get an error in Mainsail, that I have a dirty klipper and need to flash all my boards, I will just startup ssh and run the script by typing the name. To me it is as easy as pushing a button

But please feel free to implement it and add a guide on how to do it for all of us. 

 

 

  • Like 1
Link to comment
Share on other sites

I played around with this a bit and figured out how to run the script from within Mainsail as a Macro. The problem is that within the script there is a portion to kill the Klipper service. That stops the script running the in the Mainsail interface. I don't see a way around this at the moment.

Link to comment
Share on other sites

10 hours ago, kingstar said:

kill the Klipper service.

Ah of course..

You need to stop the klipper service to flash klipper to the MCU indeed...

I am wondering if a delayed flashing / a run on reboot would also be an option. I am sure the klipper guys would know... 

But cool you got it that far. 

Link to comment
Share on other sites

  • 4 weeks later...
On 2/26/2024 at 8:19 AM, Dirk said:

I have been converting my Voron 2.4 from many-cables-to-the-toolhead, into a single can-cable (4 wires) system.

Even though I saw here that many people really did not like the CAN bus on their printers, mainly because it was new and unknown.

The problem of the web is and always has been, that you never hear the 'satisfied' people. Only the very unhappy, the very happy and the sales-people.

I hope this script will make it easier for some to make the step to the 'new'.

I have never been afraid of new things. The problem was finding a way to find the set up I needed. From one came the other and what happened was, that I was able to combine information from a few sites / github pages I visited, and was able to write a simple script that did all the work.

Actually very much like every software / game in the pre-windows 95 era, came with its own 'set-up' disk, with config.bat / setup.bat files. As long as I do not have a Klipper '95, I think this script will do for me.

I tested it, and it takes 3 to 4 minutes to update the mainboard and toolhead PCB. Faster than 5 minutes I heard mentioned before.

I will paste the script down here, with all the comments and the instructions. and attach as an attachment also. If there is a better way, let me know.

It is information gathered mainly from Esoterical's guide. You will need information from this guide to set up your own script. 

-------------------------------- SCRIPT flashCAN.sh ------------------------------------------------------------------

#!/bin/bash
### without the extensive documentation and work of Esoterical, this would never have been possible. 
### Besides Esoterical, this script builds standing on shoulders of:
### Eddie the engineer. https://www.youtube.com/watch?v=1P4UrJxChL8 Thanks!
### cruiten https://github.com/cruiten/Voron-Related/blob/main/CANbus/Documentation/SB2040_CAN/flash_klipper_script.md Thanks!

### uses # https://docs.kernel.org/kbuild/kconfig.html KCONFIG_CONFIG is used to define an alternative config file...
### to define a separate config file for mainboard (eg Octopus) or for a canbus toolhead PCB. For both cases one for katapult and one for klipper.

### the make menuconfig commands use the Esoterical github provided 'mainboard/common_hardware and toolhead_flashing/common_hardware maps provided image options
### https://canbus.esoterical.online/mainboard_flashing/common_hardware.html
### https://canbus.esoterical.online/toolhead_flashing/common_hardware.html

### HOW TO USE: Follow Esotericals guide, starting at the begin: https://canbus.esoterical.online/Getting_Started.html
### it will lead you through setting up a can network on your Klipper running os. 
### I skipped the part about dedicated can_boards, and continued with the klipper USB 2 CAN bridge provided by my mainboard: https://canbus.esoterical.online/mainboard_flashing
### will go through flashing your mainboard for CAN. go through EVERY step. and DO NOT skip the STOP warnings. This will install katapult. USB2CANbus bridge 
### afterwards it will assist you through flashing your toolhead: https://canbus.esoterical.online/toolhead_flashing
### like with the mainboard, you will install katapult and then the klipper can interface on it.
### when you are finished, you get advise on how to finish it: https://canbus.esoterical.online/Final_Steps.html

## You are happy and you see an update from Klipper in mainsail. You push the update button and your whole system is unaccessable, 
## because your hardware is no more up to date with the latest klipper...
## in that case you can follow the "so you clicked the update button???" : https://canbus.esoterical.online/Updating.html

## because I did not want to go through the same repetitive steps, I made this below script. 
## If I did not think this would be faster than the 5 minute update teamfdm.com @mvdveer needs to update his printers, I would have kept it to myself.

## -------------------------------------------------------- HOW TO USE -----------------------------------------------------------
## save this document and copy to your klipper system into the /klipper directory.
## give it a name (eg. flashCAN.sh)
## ssh into your system. go to your klipper directory and run the command: sudo chmod +x flashCAN.sh
## now you can run the script by typing the following command in ssh
## ~/klipper/flashCAN.sh

## make sure to fill in your OWN values for 
## - usb-katapult_your_mainboard_usb_id
## - yourmainboarduuid
## - yourtoolheaduuid

# these are values for me! 
# yourmainboardUUID=403544310df5
# katapult_your_mainboard_usb_id = usb-katapult_stm32f446xx_200035000851313133353932-if00
# yourtoolheaduuid =21c36fa97c26


## while installing CAN the first time, note your usb-katapult-mainboard-usb-id, mainboard UUID, toolhead UUID. 
## or if you have a functioning CAN network, run ~/klippy-env/bin/python ~/klipper/scripts/canbus_query.py can0 to see a list of installed CAN devices.
## the UUID for mainboard and toolhead you need to put in your printer.cfg file, so you can retrieve it from there.
## But the USB serial ID you have to obtain after you put the mainboard into katapult boot flash mode (STEP 2 A below).

## after  the command  python3 ~/katapult/scripts/flashtool.py -i can0 -u yourmainboarduuid -r 
## you will need to type: "ls /dev/serial/by-id" and it will give you your USB serial ID.

## once you have run through this script, comment out (put a # in front of the line) the line which has the "make menuconfig" in it.
## and the next time you have a klipper update that breaks your CAN, all you have to do, is to run this script once.


#-------------------------------------FINAL WORDS--------------------------------------------------
# this script is for me and my set up.
# HARDWARE
# Raspberry Pi 4B, 8mb
# Voron 2.4, 350
# Octopus Pro mainboard
# SB2209 (RP2040) Big Tree Tech 2 part Toolhead PCB
# Cartographer 3D Eddy Probe in CAN mode
# with built in accelerometer / resonance tester
# The Octopus functions as a CAN bridge. Cartographer 3D is connected to The SB2209 (RP2040). 
# The CAN bus is terminated at the Cartographer 3D probe.

# SOFTWARE:
# OS: Raspbian GNU/Linux 11 (bullseye)
# Distro: MainsailOS 1.2.1 (bullseye)
# klipper: v0.12.0-114-ga77d0790

# if you are not using this script on my system then anything can happen which I am not responsible for.




echo "STEP 1 - UPDATE KATAPULT FROM GIT if needed"
test -e ~/katapult && (cd ~/katapult && git pull) || (cd ~ && git clone https://github.com/Arksine/katapult) ; cd ~

echo "STEP 2a - FLASH MAINBOARD KATAPULT so we can flash it easily"
cd ~/katapult
make clean KCONFIG_CONFIG=config.mainboardKatapult # cleans old files
make menuconfig KCONFIG_CONFIG=config.mainboardKatapult # this can be commented out for automation AFTER you have filled out correct fields for your card. or leave it in to have some control
make KCONFIG_CONFIG=config.mainboardKatapult # this creates a deploy.bin
python3 ~/katapult/scripts/flashtool.py -i can0 -u yourmainboarduuid -r # puts mainboard in katapult flash mode
python3 ~/katapult/scripts/flashtool.py -f ~/katapult/out/deployer.bin -d /dev/serial/by-id/usb-katapult_your_mainboard_usb_id # flashes katapult to mainboard


echo "STEP 2b - FLASH MAINBOARD so it works as a CAN BRIDGE, over KATAPULT"
cd ~/klipper
make clean KCONFIG_CONFIG=config.mainboardUSB2CANbb # cleans old files
make menuconfig KCONFIG_CONFIG=config.mainboardUSB2CANbb # configuration for klipper-U2CBB. comment this line for automation
make KCONFIG_CONFIG=config.mainboardUSB2CANbb # this creates klipper.bin 
sudo service klipper stop
# mainboard still in katapult forced flash mode. so feel free to flash klipper can bridge on it!
python3 ~/katapult/scripts/flashtool.py -f ~/klipper/out/klipper.bin -d /dev/serial/by-id/usb-katapult_yourmainboardusbid # flashes klipper-U2CBB to MAINBOARD
sudo service klipper start


echo "STEP 3a UPDATE TOOLHEAD KATAPULT so we can flash it easily"
cd ~/katapult
make clean KCONFIG_CONFIG=config.toolheadKatapult # clean old files
make menuconfig KCONFIG_CONFIG=config.toolheadKatapult # comment out for full automation after once filled out!
make KCONFIG_CONFIG=config.toolheadKatapult # build katapult deployer.bin
python3 ~/katapult/scripts/flashtool.py -i can0 -u yourtoolheaduuid -r # put toolhead board into katapult flash mode
python3 ~/katapult/scripts/flashtool.py -i can0 -u yourtoolheaduuid -f ~/katapult/out/deployer.bin # flash the katapult binary


echo "STEP 3b UPDATING TOOLHEAD KLIPPER over KATAPULT"
cd ~/klipper
make clean KCONFIG_CONFIG=config.toolheadKlipper
make menuconfig KCONFIG_CONFIG=config.toolheadKlipper
make KCONFIG_CONFIG=config.toolheadKlipper
sudo service klipper stop
python3 ~/katapult/scripts/flashtool.py -i can0 -u yourtoolheaduuid -f ~/klipper/out/klipper.bin
sudo service klipper start

echo " The Klippper update flash script has finished. Hopefully all is working again :-)"

scriptend.jpg

scriptstart.jpg

flashCAN.sh 7.38 kB · 26 downloads

This is a super interesting project.. hmm gonna have to follow

  • Like 1
Link to comment
Share on other sites

@Dirk Question:

My v0.1/2 M5P/EBB36 is now no longer talking to me, I think it needs a complete update (mainboard firmware, klipper on the M5P and klipper on the EBB36). How useful is your script going to be for my situation?

I've looked at esoterics guide/how-to and found it overly complicated. I prefer a simplier approach.

Link to comment
Share on other sites

25 minutes ago, TitusADuxass said:

found it overly complicated

look closer. It is not.

Once you have run through it for 1 printer, it will be so easy.

It is way easier than trying to follow any other guide, especially the Chinese ones.

Usually when it is not talking to you, it means there is something else the matter. But if it needs an update, such as here in the canbus script, it will complain that it does need an update.

Open a new thread and post your data there and I am sure we will figure it out.

 

 

Link to comment
Share on other sites

29 minutes ago, TitusADuxass said:

How useful is your script going to be for my situation?

I haven't answered your question.

It can be very useful. If you understand what the script does.

It is actually meant to be run once in its current state. You need to follow the instructions on Esotericals page (which options to select for your board, and do not confuse them!). Then script SAVES these values. And reloads them when you re-run the script. So you can uncomment those lines (which I have referenced) after running the first time and selecting the correct options. A second time, it will do it all the flashing / updating by itself, without any input.

So it is worth the effort to run it. But as I said, if it is not telling you you need an update, you need to fix that first.

  • Like 3
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...