I'm hoping to create a set of user triggerable physical buttons for CNCJS based on the code for the cncjs-pendant-raspi-gpio. For my own Marlin and SKR Pro 1.2 based MPCNC setup I want to be able to trigger the tool on and off, and initiate a feedhold from physical buttons mounted next to the machine.
My coding-fu is weak so I'm hoping to use this existing code as a basis for something that works, even if I produce a very inellegant solution to my problem!
You will require two resistors per button, a 1k and a 10k to build as a current limiter/voltage divider to protect the GPIO.
Pin Number, GPIO Pin, Button Function, GCode Called
Pin 16, GPIO 23, Stop Tool and Shutdown if held (Red button), M05
Pin 17, NA, 3.3v supply to bring GPIO high on button press, NA
Pin 18, GPIO24, Start Tool (Green Button), M03
Pin 20, NA, Common ground for all buttons, NA
Pin 22, GPIO25, Feed Hold function that efectively pauses the cut (Yellow button), M0 but requires 'emergency parser' to be enabled in firmware to really be useful. M108 can be used to restart.
If this works, hopefully it will be of help to others, or a basis for a more elegent and effecient method!
All constructive comments welcomed.
Thanks!
Installation
# Clone Repository
cd ~/
wget https://github.com/nelmdog/button-mod-of-cncjs-pendant-raspi-gpio/archive/master.zip
unzip master.zip
git clone https://github.com/nelmdog/button-mod-of-cncjs-pendant-raspi-gpio.git
cd button-mod-of-cncjs-pendant-raspi-gpio-master
npm install
chmod u+x bin/button-mod-of-cncjs-pendant-raspi-gpio
Run bin/button-mod-of-cncjs-pendant-raspi-gpio
to start.
.
.
.
.
npm install cncjs-pendant-raspi-gpio
sudo npm install -g cncjs-pendant-raspi-gpio@latest --unsafe-perm --build-from-source
# Clone Repository
cd ~/
#wget https://github.com/cncjs/cncjs-pendant-raspi-gpio/archive/master.zip
#unzip master.zip
git clone https://github.com/cncjs/cncjs-pendant-raspi-gpio.git
cd cncjs-pendant-raspi-gpio*
npm install
Run bin/cncjs-pendant-raspi-gpio
to start. Pass --help to cncjs-pendant-raspi-gpio
for more options.
Eamples:
bin/cncjs-pendant-keyboard --help
node bin/cncjs-pendant-raspi-gpio --port /dev/ttyUSB0
Install Production Process Manager [PM2]
# Install PM2
sudo npm install -g pm2
# Setup PM2 Startup Script
# sudo pm2 startup # To Start PM2 as root
pm2 startup # To start PM2 as pi / current user
#[PM2] You have to run this command as root. Execute the following command:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
# Start CNCjs (on port 8000, /w Tinyweb mount point) with PM2
## pm2 start ~/.cncjs/cncjs-pendant-raspi-gpio/bin/cncjs-pendant-raspi-gpio -- --port /dev/ttyUSB0
pm2 start $(which cncjs-pendant-raspi-gpio) -- --port /dev/ttyUSB0
# Set current running apps to startup
pm2 save
# Get list of PM2 processes
pm2 list
- G-Code: M9
- G-Code: M8
- G-Code: M7
- G-Code: $X "Unlock"
- G-Code: $X "Unlock"
- G-Code: $SLP "Sleep"
- G-Code: $SLP "Sleep"
- G-Code: $H "Home"
- 3 Sec: sudo poweroff "Shutdown"
See the fivdi/onoff Raspberry Pi GPIO NodeJS repository for more infomation.