This post describes how to configure your Raspberry Pi so that it can easily connect to the network and send files serially to your CNC machine. This is especially useful if you have to move a thumb drive or laptop around the shop to transfer or drip feed files. The Raspberry Pi is a small single board computer that runs Linux and will behave just like a regular computer, but it is much smaller and more economical.
Create the Micro-SD Card
The micro SD card is like the hard drive of the Raspberry Pi. It needs the OS to be installed on it for it to run. The easiest way to get this set up is to download the Raspberry Pi imager tool located here:
https://www.raspberrypi.com/software/
Follow the steps in the tool to install the latest Raspian (Debian) OS onto your micro-SD card. This will take at least 15 minutes. Once the OS is written to the card, eject it and insert it into the Raspberry Pi.
One thing worth noting here is that the Raspberry Pi requires a power supply that can source about 2.5 Amps at 5V. A standard cell phone charger may not be adequate to power the pi. Please check the ratings before powering up, especially if the pi is sourcing the power to the LCD screen through the USB port.
Typing Commands
The rest of this post describes how to type commands in on the prompt. If you are new to Linux, this can be daunting. The "command prompt" window is where all of the commands listed in blue below should be typed. The bold text indicates that is text that should be updated or placed inside one of the files. This post assumes the 'nano' application is installed on your pi. It is used to edit text files.
Screen Setup
There isn't much point in doing any other setup if the screen isn't working. Depending on the screen that you use, there may need to be some OS setup to make the screen display correctly. Sometimes the seller will include instructions that can be very helpful. If you have them, follow those instructions and skip to the next step.
Here are the instructions for my 7" LCD screen. I am listing them just in case they may be useful for yours.
1. Open the "config.txt" file in the /boot/firmware folder.
sudo nano /boot/firmware/config.txt
2. Add the statement in the "config.txt" file, press Ctrl+X to exit, press Y to save. The "display_rotate=1" is all that is necessary. Anything after the # is a comment. For example: to rotate your display 180 degrees, set it it to "display_rotate=2".
display_rotate=1 #0: 0; 1: 90; 2: 180; 3: 270
3. Restart the Raspberry Pi after saving.
sudo reboot
If you have a touchscreen, it may also be necessary to rotate the touch interface as well.
1. Install libinput
sudo apt-get install xserver-xorg-input-libinput
2. If not already there, create the 'xorg.conf.d' directory in /etc/x11.
sudo mkdir /etc/X11/xorg.conf.d
3. Copy the file "40-libinput.conf" to the directory that was just created.
sudo cp /usr/share/X11/xorg.conf.d/40-libinput.conf /etc/X11/xorg.conf.d/
4. Edit "/etc/X11/xorg.conf.d/40-libinput.conf"
sudo nano /etc/X11/xorg.conf.d/40-libinput.conf
Find the touchscreen section and add one of the following statements inside. Press Ctrl+X to exit and Y to save.
for 0 degrees of rotation, enter:
Option "CalibrationMatrix" "1 0 0 0 1 0 0 0 1"
for 90 degrees of rotation, enter:
Option "CalibrationMatrix" "0 1 0 0 -1 1 0 0 1"
for 180 degrees of rotation, enter:
Option "CalibrationMatrix" "-1 0 1 0 -1 1 0 0 1"
for 270 degrees of rotation, enter:
Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1"
5. Restart your Raspberry Pi
sudo reboot
Configuration
Once the pi is booted up and logged in, go to Preferences -> Raspberry Pi Configuration. Ensure the options are selected as shown:
The important items here are that the I2C and Serial Port need to be enabled and the Serial Console needs to be disabled. The SSH and VNC are up to a user preference. If you don't know what they are, they can be disabled.
Installing Software
Since the CNCFeeder application will use the serial port, first make sure that the other devices that use the port are turned off. On the Pi 4, the bluetooth module uses the same serial port that we want to use, so disable it.
cd /boot/firmware
sudo nano config.txt
At the end of the file, add the following line:
dtoverlay=disable-bt
Save the file by Ctrl-O (Write Out), then exit with Ctrl-X.
Next, disable the services. At the command prompt enter:
sudo systemctl stop getty.target
sudo systemctl disable hciuart
After those items have been changed, a reboot is required for them to take effect.
sudo reboot
Note: If the bluetooth and getty service are not properly disabled, the pins will not be configured properly by the hat EEPROM chip on startup.
In order to run the CNCFeeder application, the first thing to get installed is WiringPi:
cd
sudo apt-get install git
git clone http://github.com/WiringPi/WiringPi
cd WiringPi
./build
Now extract the CNCFeeder application from the tar file that was downloaded from the shopping cart. This can be done by copying the tar file to the desired folder and right-clicking on it. Select "Extract here".
Alternatively, the software can be extracted from the command line:
tar -xvf CNCFeeder_v0.2.0.tar
Once all of that is installed, then the CNCFeeder application can be run. If you downloaded it, or copied it over from a thumb drive, it is not necessary to install anything else. The software can simply be run.
Making a Shared Network Folder
One of the best parts about using a Raspberry Pi is the ability to use wireless or wired networking to transfer files. This eliminates the need for transferring files by running a thumb drive back and forth to the machine.
This section goes over how to set up the network hostname and a Samba Server on the pi. The Samba Server piece of software is needed so Windows based systems can interact with the shared folders even though the file system is different.
Setting the Hostname of the Pi
In networking, it is easiest to refer to computers by a hostname, rather than an IP address. This means we don't need to go through the effort of setting up a static IP or anything like that. The hostname should be descriptive of what function that computer has. In a shop of multiple Pi's, each connected to a different machine, I suggest changing the hostname to something that intuitively refers to that machine. Since my machine is a Rebel Max, I chose to set my hostname to "rebelmax". Note that the default is "raspberrypi". The default may be fine to leave as is if there is only one Pi on the network. If there are more than one, please consider changing the hostnames.
Here is a link to a site that offers multiple ways to change the hostname:
https://www.tomshardware.com/how-to/raspberry-pi-change-hostname
Samba Server
A Samba Server is the background process that will allow you to share a folder and make it available to other Windows based machines on the network.
Follow these steps to set up the samba server.
sudo apt-get install samba samba-common-bin
mkdir /home/pi/NCFiles
The “smb.conf
” configuration file is where you will store all your settings for your shares.
sudo nano /etc/samba/smb.conf
Add the following lines to the end of the file:
[NCFiles]
path = /home/pi/NCFiles
writeable=Yes
create mask=0777
directory mask=0777
public=yes
Save the file by pressing Ctrl-O, then exit with Ctrl-X.
The text inside the [] "NCFiles" is the root shared folder. For instance, it will appear on the Windows network as "\\raspberrypi\NCFiles". In my case, since my machine host name is rebelmax, the shared network folder is "\\rebelmax\NCFiles".
Next, open up the file explorer and right-click on the shared folder. Go to the Permissions tab and change the "Change Content" dropdown to "Anyone".
Note that these settings allow anyone to connect to the pi and modify the contents of that folder. If you prefer to have some network security, there are other guides online that can help you set that up.
Making Software Run on Startup
This section is optional, but helpful for shops that don't need to do anything on the Pi except one specific application.
There are many online resources for describing multiple ways of doing this. Here is one site that lists 3 ways to run an app on startup:
https://www.makeuseof.com/how-to-run-a-raspberry-pi-program-script-at-startup/
Running the software
Navigate to the folder the CNCFeeder application was installed into and type:
./CNCFeeder
Troubleshooting
All is well until something goes wrong.. And since this is Linux, there is a lot to go wrong..
If the software thinks it is sending a file, but the TX light on the hat doesn't turn on while the software is sending, then there is a hardware or pin configuration issue. If the TX light does light up when the software is sending a file, chances are it is a software configuration issue.
Software Settings
If the hat is used to connect to the CNC machine with the db25 cable, then the software should be configured to use the /dev/ttyAMA0 serial port.
The CNC machine has parameters that determine the serial port settings such as baud rate, data bits, stop bits, parity, etc. Check your CNC machine user manual or parameters to know what is required by the software. For most applications, the following settings will be close:
Pin Configuration
First, trouble with any hat could indicate that the hat EEPROM chip did not properly configure the GPIO pins for the hat requirements. The first thing to try is a command to see if the pi can communicate with that EEPROM chip on the hat.
i2cdetect -y 20
The thing to look at here is to make sure the 50 row and 0 column has a '50' in the table. If it is '--' then the pi cannot see the hat EEPROM chip. There may be a connection issue with the hat or other hardware issue.
Next, assuming that the i2c EEPROM chip is working, the OS must use that data to correctly configure the GPIO pins. For this product, we are mainly concerned with the TX and RX pins.
The following command will display how each of the IO pins is configured:
gpio readall
The thing to look for here is the physical pins 8 and 10 need to be configured to ALT0. (the '0' is a zero). Pins 11 and 36 should be configured as ALT3.
If you find that the board has pins 8 and 10 configured as something else, the quick fix is to enter the following commands, but this will need to be done after every reboot:
gpio mode 14 ALT0
gpio mode 15 ALT0
gpio mode 16 ALT3
gpio mode 17 ALT3
Note: If the bluetooth and getty service are not properly disabled, the pins will not be configured properly by the hat EEPROM chip on startup. Please see the "Installing Software" section above for instructions.
At this point, clicking the send button on the software should cause the TX light to turn on while the software is sending a file.
If the CNC machine still cannot receive the file correctly, then check the other software settings to see if other settings work better.
Incomplete Sends
If the file sends, but contains errors or is incomplete, then there is either a problem with the flow control settings, or there simply needs to be more delay when sending to allow the receiver time to save the data. If this is the case, try increasing the "Packet Delay" preference value. The default values shown in the image above should work for most instances.
Some CNC controllers require the programs to include the '%' character at both the start and the end of the file. Make sure that the file is formatted correctly before sending it to your CNC machine.
If the file sends but the CNC machine never completes and continues to be in receive mode, then the Flow Control settings need to be adjusted.