Monthly Archives: May 2014

The USB HID controller is going to consist of 3 interfaces. First up is the keyboard interface which will allow me to send keystrokes to the PC, next is the rawhid interface which I will need to receive data from the PC to display on the LCD. Finally I have included a debug interface to help with debugging the Teesny++ 2.0 firmware.

I can take the information I learned from the Teesny controller tests and convert it into a working controller. This part of the HID controller is actually pretty easy as all we need to do is send keystrokes to Mach3 when a button is pressed or a joystick is moved. As the joysticks I am using are the microswitch kind, everything is done using digital IO pins.

The LCD display I am going to use is a KS0107/KS0108 based 128×64 pixel module, and I am using the excellent openGLCD library with it. The only changes I have made are to the ‘pinconfig_ks0108-Teensy.h‘ file. By adjusting the Teensy++ 2.0 pin connections to the LCD, the PCB design was much easier. (The commented out lines are the original pins)

As you can see from the pictures below, the PCB design itself is pretty straight forward, I decided to bring out some extra pins & ground connections in case I wanted to make changes or additions in the future. (I would like at some point to make a RPM sensor for the spindle)

Schematic

Board Layout

The next thing I need to do is find a way to talk to Mach3. Fortunately Mach3 has a plugin system and some nice kind chap has made a plugin wizard template. Using Simon Inns usbHid Class I was able to send information from the Mach3 plugin to the HID controller.

The last thing I needed to do was make sure that I had keyboard shortcuts for all the things I wanted to control in Mach3. This was accomplished by making a custom screen set using machscreen and setting up the keyboard shortcuts.

Freshly Milled PCB

Part Assembled

Fully Assembled

The Teensy2++ software is pretty straight forward, so I wont go over it in too much detail, but here’s the main loop…

The Mach3 plugin sends data to the HID by using it’s VID & PID. I just check the HID data coming in every loop, and to make sure it is a valid packet I check the first 2 bytes and last 2 bytes, which should be 0xAA55 (1010101001010101 in binary). This is a pretty basic check but seems to work well for my purpose., as I am only ever going to have one controller connected.

I use the 3rd byte as a command byte which only has a couple of states. 0x80 means send the revision number back to Mach3 to display in the plugin window and 0x01 means LED data has been sent from Mach3 for us to display on the LCD.

The other important part is the joystick/button code and again this is pretty simple. I am using the bounce library to check for rising/falling edges and then just send the relevant keystroke if needed.

That covers the basics and there are plenty of comments in the code, but I’ll try and answer any questions if anyone has any. I have included the Teensy2++ cnc device software as well as the sketch. You will need to do some file editing to the ‘boards.txt’ and add the relevant includes. (See this guide)