Loading...
 

Random Tips

Making a USB-HID Keyboard Encoder Board for PicoScope

Published by coflynn on Sun 05 of Jan., 2014
Ever wanted to control something from a knobby-looking USB peripheral? In this example I wanted to control the PicoScope software from a bunch of encoders mounted on a USB peripheral:
Image
You can see the video of the device working here:


You'll need the following to build this:
  1. Teensy++ 2.0 (http://www.pjrc.com/teensy/): $24
  2. 4-12 encoders (I used PEC11-4215K-S0024). Number of encoders depends on channels & what functions you want: $5.12 - $15.36
  3. Knobs for encoders: $0-$24 (depends on quality, sales, etc)
  4. Project box: $0-$20 (I had one sitting around that fit perfectly)

Hardware Choices

Encoder Choice

For the encoders: you've got a choice of 'splines' or 'round with flat' style shaft. I ended up choosing splines, as it was easier to get knobs which fit the 18-point spline shaft.

The specific encoder I used was part number PEC11-4215K-S0024. It's available from Newark for $1.30.

My encoders also had switches, which lets you push on them for another function. The code supports up to 12x encoders + 12x switches (e.g. 12 encoders with switches). You could of course have any other mix you want: for example 8 encoders with switches, 4 encoders without switches, and 4 separate switches.

Be sure to not use a wrench to snug up the nut. If you do that you might find something like this happens:
Image
Instead epoxy the backside if you want to make sure they don't spin.

Knob Choice

The knobs will probably be more expensive than your encoder. So it's worth seeing the best deal - for example on E-Bay there were some options of variety-packs of colours, but I couldn't get them fast enough for my project. I ended up ordering knobs from Newark as well, and used two different styles. The colours can be setup to match the colours on the PicoScope channels (e.g. for 4-channel device). You'll still have some repeated knobs though... so you can decide what you want timebase, trigger, etc to be.

The first style:
Image
The part numbers of the four colours are: MC21063, MC21064, MC21065, MC21066

The second style:
Image
The part numbers of the four colours are: MC21058, MC21059, MC21060, MC21061

USB Board

The USB board to use is a Teensy++ 2.0. I actually used the ATUSBKey device instead as I had one sitting around. It's less ideal since it has much finer header pinouts. You also have to remove many components to get all the required parts.

Connect the 'common' of the encoder & push-button to GND. Connect the other side to the following ports, which will have internal pull-ups enabled:

Encoder Connections:
Encoder 1: A = PINA.0, B = PINA.1
Encoder 2: A = PINA.2, B = PINA.3
Encoder 3: A = PINA.4, B = PINA.5
Encoder 4: A = PINA.6, B = PINA.7
Encoder 5: A = PINB.0, B = PINB.1
Encoder 6: A = PINB.2, B = PINB.3
Encoder 7: A = PINB.4, B = PINB.5
Encoder 8: A = PINB.6, B = PINB.7
Encoder 9: A = PINC.0, B = PINC.1
Encoder 10: A = PINC.2, B = PINC.3
Encoder 11: A = PINC.4, B = PINC.5
Encoder 12: A = PINC.6, B = PINC.7

Push Button connections:
Button 1: PINE.0
Button 2: PINE.1
Button 3: PINE.2
Button 4: PINE.3
Button 5: PINE.4
Button 6: PINE.5
Button 7: PINE.6
Button 8: PINE.7
Button 9: PIND.0
Button 10: PIND.1
Button 11: PIND.2
Button 12: PIND.3

The results might look something like this:
Image

Unconnected inputs will be ignored, since they will always read as high due to internal pull-ups. So e.g. you can have just 4 encoders & 12 buttons or so forth.

Changes in encoders or buttons get mapped to unique key presses. I don't know what they are explicitly, just try them & see.

The Bootloader

The device will jump to bootloader (allowing you to update firmare) if you hold down two buttons when plugging the USB cable in. The two buttons are 1 & 4 if buttons normally open, 2 & 3 if buttons normally closed.

If you are using a Teensy++ device, you can also force bootloader entry with the special button on the device. This probably won't be easily reachable, which is why I've added the bootoader with buttons 1 & 4 trick.

If you ARE NOT using a Teensy++ device: PINE.2 is also the Hardware Boot Button. If things get really screwed up, you can force a re-entry of bootloader mode with the following:
  1. Push button connected to PINE2 & hold it (Button 3)
  2. Push & release reset button
  3. Release button connected to PINE2, unit can now be programmed with e.g. FLIP.

Programming Software

You'll need to use the programmer (see http://www.pjrc.com/teensy/loader.html)(external link) to load the initial hex file, assuming you are using a Teensy++ 2.0 device.

If there are later changes in the file, you can use that program to load new changes. Again you can force the bootloader to run by holding down two specific buttons when you plug the USB cable in. This avoids you needing to open up your case full of wires.

If you are not using a Teensy++ 2.0 device, you'll probably need to use Atmel's FLIP software.

Software

You can find the source code at https://github.com/colinoflynn/encoderhid . You can also download a hex file from that same link - look for EncoderBoard.hex in the main folder.

Newest Blog Posts

Videos on YouTube