Thursday 13 February 2020

CNCjs on a Raspberry Pi 3A+

Having read and tried to follow the official CNCjs help file on installing, this was the short version that worked for me.


Headless boot

1, Add a linux format file to the boot partition of the ssd ( using lf not crlf) containing

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB

network={
    ssid="«your_SSID»"
    psk="«your_PSK»"
    key_mgmt=WPA-PSK
}

2, Add an empty 'ssh' file to the boot partition to enable ssh

Install the SD card and power on. (wait quite a while the first time)

Installing node and CNCjs

1, Do a
sudo raspi-config 
and disable console on serial but enable hardware serial

2, Run the following

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
nvm install 10
nvm use 10
npm install -g cncjs


Also
https://learn.watterott.com/hats/rpi-uno-hat/arduino/
https://cnc.js.org/docs/rpi-setup-guide/
https://learn.adafruit.com/program-an-avr-or-arduino-using-raspberry-pi-gpio-pins/programming

Gotchas
PM2 didn't work, used crontab
didn't need sudo for npm commands

To flash GRBL
Follow the install instructions on watterott.com to get avrdude installed then
wget <latest grbl hex file>
sudo avrdude -p atmega328p -P /dev/ttyS0 -c arduino -v -U flash:w:<latest grbl hex file>:i


Extras
Set GPIO on while the PI is running
Edit /boot/config.txt
Add 
dtoverlay=gpio-poweroff,gpiopin=26,active_low

After 4 secs or so the IO pulls low and when the PI is shudown, goes off