Naked Teensy Party!
So, you bought a grblHAL breakout board or just got curious about how grblHAL works on a bare Teensy 4.1 and decided to try it. This blog post will show how to get it working before you build it into a CNC machine and cover any issues you might run into.
So, what do you need? In terms of hardware, all you need is a Teensy 4.1 and a micro-USB cable. If you have one of my grblHAL Teensy 4.1 Breakout Boards, you can use that too. If nothing else, it makes for a little more stable platform but is not necessary for this. If you are not using the breakout board, you might want to plug the Teensy into a solderless breadboard to prevent it from following the whims of the USB cable. In addition, 2 or more momentary contact switches and 2 toggle switches can be used. More on that later.
First we need to build the grblHAL firmware for the Teensy. You can use the grblHAL Web Builder to do this. Select the specific options you want (number of axes, etc) though for playing with the teensy by itself they don't really matter. Press the "Generate and Download Firmware" button. You can also build it yourself from source code. Go to the grblHAL repository, download the source and build it. I don't recommend this unless you understand IDEs and building complex software systems. Even a cursory discussion of this is beyond the scope of this article. Once you build the firmware, you need to load it into the teensy 4.1. Download the teensy.exe application from pjrc.com. Follow the instructions there including obtaining the Teensy loader program for your platform.
Next, we need a way to communicate with the Teensy. The easiest is TerjeIo's ioSender. At this time it only runs on Windows 7, 8 and 10. To use it, download the distribution and extract the files to a directory you created for it. For non-Windows users, UGS or bCNC work fairly well. I have several reports that CNCjs also works well. Be sure to get the most recent version as there have been some changes to better work with grblHAL. You will also want to use a terminal application to talk directly to Grbl. The Arduino Serial Monitor works well and I also use Putty. Set your parameters to 115200 baud and 8,N,1.
So, once you have all the above in place, we will load the grblHAL binary you have chosen. I am using the 5 axis usb quad enc binary - grblHAL-5XUQ.hex from the pre-built binaries zip file downloaded from my pre-built binaries repository mentioned above. You can use any of the binaries there you want, though. Plug the USB cable into your computer and the Teensy. Next, start the Teensy loader. Using File/Open Hex File, navigate to and select the .hex file you want.
Once you have done that, press the button on the Teensy 4.1. You should see the Teensy loader flash a very brief loading message. grlHAL is now loaded, that is all you have to do.
Next, let us see if we can talk to grblHAL running on the Teensy. Normally, I use ioSender but I will first show how you can talk directly to grblHAL via a terminal application using the serial monitor in the Arduino software. Make sure to select the correct port for the Teensy 4.1. In my case it is COM22.
Once you have selected the com port, run the serial monitor (Tools/Serial Monitor). You should see the following screen though it is possible it will display nothing at all.
The Alarm 10 and Emergency Stop messages are perfectly normal and indicate that grblHAL is correctly installed. You might also see an Error: 50 in this situation. First thing to do is find out what build we are using - type $i<enter>. You should see (or something similar).
[DRIVER OPTIONS:USB.2 IOPORTS QEnc ]
I won't go into the details of the messages but in this case it shows that we are using a build from May 3, 2020. [I do not know why the numbers show up in color, something to do with how the blogging system I use works.] Next, try $$<enter>. This will display the values of all the Grbl Settings. I won't show it here for brevity's sake. Note that this is likely to change to a more human understandable form in the near future. If you try doing a rapid move like G0 X10, you will get an error 9 because grblHAL is in an alarm state.
So, the next thing to do is fix the Alarm 10, error 9 and Emergency stop messages. This is due to the fact that we don't have the control switches configured in grblHAL. It thinks that the Emergency Stop switch is open. One of the things that grblHAL does is encourage using Normally Closed (NC) switches. NC switches tend to be more EMI resilient and are the default settings. Since we have a bare Teensy, we essentially have Normally Open (NO) switches. We can correct that by either connecting NC switches or just telling grblHAL that we have NO switches. For the short term, we will use the latter approach but in your CNC machine, I encourage you to use NC so you may have to change it back at some point. If you have momentary NC switches, now is a good time to hook them up to Feed Hold and Cycle Start. There are labeled screw terminals on the Breakout Board and on a bare Teensy, Pins 16 for FH and 17 for CS. If you have toggle switches, you can connect them now also.
There are two ways to do fix the alarm state - in a serial monitor or via ioSender. Using the Serial Monitor from Arduino, we can directly change the Grbl Invert Control Pins Setting - $14. Note, if you are not using ioSender, you will need to use a serial monitor because other GCode senders are not aware of the grblHAL extensions. The simplest way is to enter $14=78<enter>, followed by $X<enter> to clear the alarm state. This tells grblHAL that Emergency Stop, Door, Cycle Start and Feed Hold are all NO switches. If you have connected any NC switches, you will need to construct a different bitfield: EStop +64, Door +8, Cycle Start +4 and Feed Hold +2. For example, if you just want Door and EStop you would add 64 and 8 so send $14=72<enter>. Now that G0 X10 should return OK. If you are going to use a GCode Sender now, close the serial monitor application - it will prevent the GCode Sender from connecting.
If you have never run ioSender before, it will come up and ask you for an IO port to use. It will show the available COM ports. If you don't know which port to use, you can get it from the Arduino Software as mentioned above. Or, you can use the device manager in Windows (windows key+"device manager"). Look in the Ports section for a Serial USB port. (Or you can try what ever ioSender suggests.) If you get the COM port wrong, the DRO section will be blank.
Once you select the right COM port and click OK, you should see the following screen.
In the lower left corner you can see that it is in the Alarm State. If you mouse over the Signals section immediately above that, you can see that Feed Hold (H), Cycle Start (S) and EStop (E) are set to on. It also shows the limit switches are on - they too are NC switches by default. To turn off H, S and E, select the Settings: Grbl tab near the center top of the screen. You will see the settings page. Click on the line with the ID value of 14 - Invert control pins. Check Feed Hold, Cycle Start, Safety Door and EStop. It should look like this:
Press the Save button, then the Reload Button and go back to the Grbl tab (leftmost tab). Press the Reset Button and the State should now show IDLE like the screen shot to the right shows. At this point you should be able to open the Jog panel and move the axes around. The DRO section should show movement when you do. To test the spindle control, close the Jog panel, enter 1000 in the RPM box and click on the CW radio button. You should see the LED on the Teensy come on indicating that the spindle signal is set to run. Try lowering and raising the spindle speed with the Override control. The LED brightness should change as you do that.
Finally, let's run some GCode and try out the 3D View tab. Download this file and use File/Load to open it.
Click on the 3D View in the lower left of the ioSender screen (and not the 3D View in the upper left). You should see "grblHAL" in the main tab. Hold the right mouse button down and drag to get an angled view. Then press the Cycle Start button and watch it run. If you have hooked up a momentary switch to the Cycle Start input, you can press that instead of the ioSender's Cycle Start button. Note that the DRO shows the cutter's position. You should also note the spindle LED on the Teensy turns on as it starts "cutting".
At this point you have a working grblHAL system running on your Teensy 4.1!
If you wish to explore grblHAL on the Teensy 4.1 a bit more, here are the pin assignments: