USB HID Crank Controller - Adafruit Industries

3y ago
24 Views
2 Downloads
1.11 MB
23 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Aliana Wahl
Transcription

USB HID Crank ControllerCreated by Ruiz BrothersLast updated on 2019-09-20 05:25:12 PM UTC

OverviewA USB Crank DeviceEver wonder what it's like to control things with a crank?This project explores the use of a crank mechanismthat attaches to a rotary encoder. With the AdafruitItsyBitsy M0 and CircuitPython, we can simulate a USBHuman Interface Device (HID) device (like computerkeyboards, mice, and gamepads) to trigger commands,macros and key presses. This idea was inspired by thePlay Date (https://adafru.it/F0d) device by Panic.Hinged Crank MechanismHave you ever cranked a rotary encoder? With the rightapplication, this actually feels intuitive and fun. Thisdesign features a hinged arm and free-rotating handle. Itpops out of the case and hinges out making a crank.The mechanism is a 3D print-in-place design. It press fitsover any flat nose rotary encoder.Turbo ModeThe rotary encode simulates key presses each time a pulse is produced. By turning the encoder, rapid key presses aregenerated – This is similar to the "Turbo" button prominently featured on USB gamepads. We've come up with someuse cases for this.Turn up/down volume or screen brightnessPlay MakeCode Arcade gamesScroll webpagesRotate 3D models in CURA Slicer Adafruit -controllerPage 4 of 25

DIY USB HIDThis project uses the USB HID CircuitPython library. It'sdesigned for creating custom USB input devices forcreative and assistive applications. The library supportsmost US keypresses, multimedia and gamepadcontrols.Parts ListA copy and paste friendly list of parts linked to productspage.Adafruit ItsyBitsy M0 ()Rotary Encoder ()USB microB Cable – Fully reversible ()10-wire silicone cover ribboncable (https://adafru.it/CJj)3D Printer – Inventor II ()Filament for 3D Printers ()Your browser does not support the video tag.Adafruit ItsyBitsy M0 Express - for CircuitPython & ArduinoIDEOUT OF STOCKOut Of Stock Adafruit -controllerPage 5 of 25

Rotary Encoder Extras 4.50IN STOCKAdd To CartFully Reversible Pink/Purple USB A to micro B Cable - 1mlong 3.95IN STOCKAdd To CartSilicone Cover Stranded-Core Ribbon Cable - 10 Wire 1Meter LongOUT OF STOCKOut Of StockMonoprice Inventor II 3D Printer with Touchscreen and WiFi 650.00IN STOCKAdd To Cart Adafruit -controllerPage 6 of 25

Filament for 3D Printers in Various Colors and TypesOUT OF STOCKOut Of StockPrerequisite GuidesIf you're new to soldering and CircuitPython, we suggest you walk through the following guides to get the basics.Collin's Lab – Soldering (https://adafru.it/wsa)Welcome to CircuitPython! (https://adafru.it/Bfx)Adafruit ItsyBitsy M0 Guide (https://adafru.it/F0e) Adafruit -controllerPage 7 of 25

Circuit DiagramCircuit DiagramThis provides a visual reference for wiring of the components. They aren't true to scale, just meant to be used asreference. This diagrams was created using Fritzing software (https://adafru.it/oEP).Adafruit Library for FritzingUse our Fritzing parts library to create circuit diagrams for your projects. Download the library or just grab theindividual parts. Get library and parts from GitHub Adafruit Fritzing Parts (https://adafru.it/AYZ).Wired ConnectionsThe rotary encoder connects to the Adafruit ItsyBitsy M0 with five wired connections. Ground from the switch androtary can be shared on the ground pin or ground pad (on the back of the PCB).Ground from switch on rotary encoder to Ground on ItsyBitsy M0Pin from switch on rotary encoder to pin 9 on ItsyBitsy M0Right pin on rotary encoder to pin 10 on ItsyBitsy M0Left pin on rotary encoder to pin 11 on ItsyBitsy M0Middle pin on rotary encoder to ground on ItsyBitsy M0PoweringThe Adafruit ItsyBitsy M0 can be powered via 5V via a USB connection to another device such as a computer. Adafruit -controllerPage 8 of 25

SoftwareInstall Circuit Python for ItsyBitsy M0Download the latest version of CircuitPython for the Adafruit ItsyBitsy M0. Click the green button to launch the pageand click on the purple download button for the latest stable Quick StartConnect the ItsyBitsy board to a computer (PC, mac, Linux) via a known good USB and double press the resetbutton.Download circuitpython UF2 and upload to the ITSYBOOT flash drive.Open the CIRCUITPY drive and upload the required libraries (listed below) and the code for this project in a filenamed code.py in the root directory of CIRCUITPY.Adafruit Circuit Python LibrariesDownload the CircuitPython library bundle and unzip the folder. Create a new folder in the CIRCUITPY drive and nameit "lib". The following libraries are required to run the code properly. Double check to ensure all of the files and foldersare inside the lib folder on the CIRCUITPY drive.adafruit hid //adafru.it/ENCUpload code.py Adafruit -controllerPage 9 of 25

You can click Download and download the file. Insure it saves to a file namedcode.py (if you select Download Zipyou'll need to unzip the file to see code.py. Upload the code.py file to the CIRCUITPY drive."""A CircuitPython 'multimedia' dial demoUses a ItsyBitsy M0 Rotary Encoder - HID keyboard out with neopixel ring"""import timeimport boardfrom digitalio import DigitalInOut, Direction, Pullfrom adafruit hid.keyboard import Keyboardfrom adafruit hid.keycode import Keycodefrom adafruit hid.consumer control import ConsumerControlfrom adafruit hid.consumer control code import ConsumerControlCodeimport neopixelDOT COLOR 0xFF0000PRESSED DOT COLOR 0x008080LIT TIMEOUT 15# set to your favorite webhex color# set to your second-favorite color# after n seconds, turn off ring# NeoPixel LED ring on pin D1# Ring code will auto-adjust if not 16 so change to any value!ring neopixel.NeoPixel(board.D5, 16, brightness 0.2)dot location 0 # what dot is currently lit# Encoder button is a digital input with pullup on D9button DigitalInOut(board.D9)button.direction Direction.INPUTbutton.pull Pull.UP# Rotary encoder inputs with pullup on D10 & D11rot a DigitalInOut(board.D10)rot a.direction Direction.INPUTrot a.pull Pull.UProt b DigitalInOut(board.D11)rot b.direction Direction.INPUTrot b.pull Pull.UP# Used to do HID output, see belowkbd Keyboard()# time keeper, so we know when to turn off the LEDtimestamp time.monotonic()######################### MAIN LOOP ############################### the counter counts up and down, it can roll over! 16-bit valueencoder counter 0# direction tells you the last tick which way it wentencoder direction 0# constants to help us track what edge is whatA POSITION 0B POSITION 1UNKNOWN POSITION -1 # initial state so we know if something went wrongrising edge falling edge UNKNOWN POSITION Adafruit -controllerPage 10 of 25

# get initial/prev state and store at beginninglast button button.valuerotary prev state [rot a.value, rot b.value]while True:# reset encoder and wait for the next turnencoder direction 0# take a 'snapshot' of the rotary encoder state at this timerotary curr state [rot a.value, rot b.value]if rotary curr state ! rotary prev state:#print("Changed")if rotary prev state [True, True]:# we caught the first falling edge!if not rotary curr state[A POSITION]:#print("Falling A")falling edge A POSITIONelif not rotary curr state[B POSITION]:#print("Falling B")falling edge B POSITIONelse:# uhh something went deeply wrong, lets start overcontinueif rotary curr state [True, True]:# Ok we hit the final rising edgeif not rotary prev state[B POSITION]:rising edge B POSITION# print("Rising B")elif not rotary prev state[A POSITION]:rising edge A POSITION# print("Rising A")else:# uhh something went deeply wrong, lets start overcontinue# check first and last edgeif (rising edge A POSITION) and (falling edge B POSITION):encoder counter - 1encoder direction -1print("%d dec" % encoder counter)elif (rising edge B POSITION) and (falling edge A POSITION):encoder counter 1encoder direction 1print("%d inc" % encoder counter)else:# (shrug) something didn't work out, oh well!encoder direction 0# reset our edge trackingrising edge falling edge UNKNOWN POSITIONrotary prev state rotary curr state# Check if rotary encoder went upif encoder direction E DECREMENT) #Turn Down Volume#kbd.press(Keycode.LEFT ARROW) Adafruit -controllerPage 11 of 25

#kbd.press(Keycode.LEFT ARROW)#kbd.release all()# Check if rotary encoder went downif encoder direction ME INCREMENT) #Turn Up Volume#kbd.press(Keycode.RIGHT ARROW)#kbd.release all()# Button was 'just pressed'if (not button.value) and last button:print("Button pressed!")kbd.press(Keycode.SPACE) #Keycode for spacebarkbd.release all()ring[dot location] PRESSED DOT COLOR # show it was pressed on ringtimestamp time.monotonic()# something happened!elif button.value and (not last button):print("Button Released!")# kbd.press(Keycode.SHIFT, Keycode.SIX)# kbd.release all()ring[dot location] DOT COLOR# show it was released on ringtimestamp time.monotonic()# something happened!last button button.valueif encoder direction ! 0:timestamp time.monotonic()# something happened!# spin neopixel LED around!previous location dot locationdot location encoder direction# move dot in the directiondot location len(ring)# in case we moved negative, wrap arounddot location % len(ring)if button.value:ring[dot location] DOT COLOR # turn on new dotelse:ring[dot location] PRESSED DOT COLOR # turn on new dotring[previous location] 0# turn off previous dotif time.monotonic() timestamp LIT TIMEOUT:ring[dot location] 0# turn off ring light temporarilyModify Key CodesYou can customize the key codes to form custom commands, which can be multiple keys, or have it execute just singlekeyboard characters.The rotary encoder can execute up to 3 different commands based on features. Pressing the knob and turning theknob left or right. These are commented in the code and can be changed by adjusting the key code value.List of USB HID KeycodesThe long list of available keyboard characters are listed in the webpage linked below. Most of the characters are forUS keyboard only. Function keys and modifiers can be used but some special characters are not currently OiStarting with the first command, turning the knob to the right will execute the ctrl up arrow keys. These are twodifferent keyboard characters that are separated with commas. This will essentially press the two keys simultaneously. Adafruit -controllerPage 12 of 25

The values inside the parentheses kbd.press(keycode.THISKEY) are the ones you want to change. For example, theblock of code below is executed when turning the knob to the right.# Check if rotary encoder went upif encoder direction 1:kbd.press(Keycode.CONTROL, Keycode.UP ARROW)kbd.release all()For more information and troubleshooting, please check out the CircuitPython library guide, linked below.https://adafru.it/ABUhttps://adafru.it/ABU Adafruit -controllerPage 13 of 25

3D Printing3D Printed PartsThe parts in this kit are designed to be 3D printed with FDM based machines. STL files are oriented to print "as is".Parts require tight tolerances that might need adjustment of slice settings. Reference the suggested settings Y 3D Printed Crank for Rotary EncodersNeed a crank for a rotary encoder? Here's a print-in-place model that features a hinged arm and freerotating handle. The pieces can not be disassembled.It's just one part that prints in about 20 minutes. Pressfits over any flat nose rotary encoder, for those timeswhere you need a cranky crank!Fusion 360 model included with accompanying STEP file. User parameters are setup for tolerances, length, shaftdiameter etc. Gap is set to 0.4mm in STL file. Check out the source for your own tweaks!CURA Slicing Adafruit -controllerPage 14 of 25

Parts were sliced using Ultimaker's CURA software and tested with an Ultimaker 3 and Flashforge Inventor II. The kitrequires a minimum build volume of 150mm cubed. No support material is necessary for any of the parts. Doublecheck parts are positioned in the center of the build plate before printing.SettingsUse these settings as reference. Values listed were used in Ultimaker's CURA (https://adafru.it/C26) slicing software.0.2mm Layer Height / 0.4mm nozzle0.38mm Line Width (inner & outer widths)40mm/s printing speed20% infillSupports: NoDesigning ThingsThe fusion 360 source file is included and features original sketches and feature timeline along with easily editableuser parameters. The parts can further be separated into small pieces for fitting on printers with smaller build volumes.Note: STEP file is included for other 3D surface modeling programs such as Onshape, Solidworks and Rhino.Layer by LayerInterested in CAD tutorials? Check out my playlist on YouTube (https://adafru.it/Ddm) – There's over 100 of them! Mypersonal favorite is the snap fit tutorial for cases and enclosures. Adafruit -controllerPage 15 of 25

WiringConnect Rotary Encode to ItsyBistyWe'll need to solder wires to connect the rotary encoderto the Adafruit ItsyBitsy M0.Silicone Cover Ribbon CableTo keep the wiring neat and tidy, we'll use a 10-wiresilicon cover ribbon cable – We only need five wires, sopeel off a set. Measure out a piece to about 8 cm inlength. Peel apart individual wires, on both ends, about 1cm in length. Use a pair of wire strippers to remove a bitof insulation from the tips. Tin the exposed wire byadding a bit of solder – This will help prevent the wiresfrom fraying.Wire ItsyBitsySolder the wires to the following pins on the bottom ofthe Adafruit ItsyBitsy M0.Ground pinGround padPin 10Pin 11Pin 9 Adafruit -controllerPage 16 of 25

Wire Rotary EncoderSolder the wires to the following pins on the rotaryencoder. Polarity on the left and right pins don't matteras long as they match pins on the ItsyBitsy. Doublecheck and make sure the connections match.ItsyBitsy ground pin to center pin on rotaryencoderItsyBitsy pin 10 to left pin on rotary encoderItsyBitsy pin 11 to right pin on rotary encoderWire Switch on Rotary EncoderSolder wires to the switch on the rotary encoder.ItsyBitsy ground pin to left pin on rotary encoderswitchItsyBitsy pin 9 to right pin on rotary encoder switchWired Rotary EncoderAnd now we have a nice and neatly wired rotaryencoder! Double check the wiring and make sure theconnections match. Adafruit -controllerPage 17 of 25

Adafruit -controllerPage 18 of 25

AssemblyInstall ItsyBitsy M0Place the ItsyBitsy PCB over the two standoffs on thebottom part of the enclosure. Line up the microUSB sowith the notch on the side of the case. Insert the PCB atan angle so it's under the clip. Press the edges of thePCB down to snap fit the PCB into place.Insert Rotary EncoderInsert the shaft of the rotary encoder into the circularmounting tab on the inside of the case.Install Rotary EncoderPush the body of the rotary encoder up against themounting tab. Adafruit -controllerPage 19 of 25

Install Hex NutPull the rotary encoder back and place the hex nut overthe top of the shaft. There should be enough clearanceto get the nut over the shaft.Fasten NutUse fingers to fasten the hex nut onto the threading.Rotate the rotary encoder to tighten or loosen the nut.Optionally use a pair of needle nose pliers to grab holdof the nut.Installed Rotary Encoder ItsyBitsyTake note of the rotary encoders orientation – The twometal prongs are right side up. This allows the space forthe pins and wires.Looks like there's a good amount of free space, eh?Maybe try adding some extra buttons! Adafruit -controllerPage 20 of 25

Install CrankPlace the cap end of the crank onto the tip of the rotaryencoder.Firmly press the crank onto shaft of the rotary encoderuntil it's fully seated. Adafruit -controllerPage 21 of 25

Handle HolsterThe case features a spot for holding the handle of thecrank. There's a little dimple that clips into a small grovenear the end of the handle. When the two halves of theenclosure are closed, the handle can "click" and hideinside the case.Set HandlePlace the handle of the crank over the dimple.Closing CaseGrab the top half of the enclosure and orient the halvesso the features are matching. Adafruit -controllerPage 22 of 25

Close CasePlace the top half over the bottom half. Make sure thecutouts are lined up and matching.Snap Fit ShutThe case has snap fit features that keep the halvessecured and closed shut.To open the case back up, place fingernail in betweenthe indentations on the side. Pull apart to separate thetwo halves. Adafruit -controllerPage 23 of 25

Case ClosedPlug it into a computer and try it out! Adafruit -controllerPage 24 of 25

Adafruit IndustriesLast Updated: 2019-09-20 05:25:12 PM UTCPage 25 of 25

DIY USB HID This project uses the USB HID CircuitPython library. It's designed for creating custom USB input devices for creative and assistive applications. The library supports most US keypresses, multimedia and gamepad controls. Parts List A copy and paste friendly list of parts linked to products page. Adafruit ItsyBitsy M0 Rotary Encoder ()

Related Documents:

Mode Identifier USB Serial Description Notes 000 HID KEY BYGRT HID keyboard, sends B for blue button, Y for yellow, etc. 001 HID KEY 12345 HID keyboard, sends 1,2,3, etc. 002 HID NAR BYGRT HID keyboard, same as mode 000, except keys do not auto-release 003 HID NAR 12345 HID keyboard, same as mode 001, except keys do not auto-release

HID-Device – The device providing the service of human data input and output to and from the host. HID-Host – The device using or requesting the services of a Device. The HID Bluetooth Profile uses USB definition of a HID device in order to leverage the existing class drivers for USB HID devices.

hidpri.h \PIC32 Solutions\Microchip\USB\hid_device_driver Private function and macro definitions hid.h \PIC32 Solutions\Microchip\Include\USB USB HID include file hiddesc.h \PIC32 Solutions\Microchip\Include\USB HID specific descriptor defines hidreport.h \PIC32 Solutions\Microchip

This guide is part of a series of guides that cover the basics of using Adafruit IO. It will show you how to send momentary button press data to Adafruit IO. If you haven't worked your way through the Adafruit IO feed and dashboard basics guides, you should do that before continuing with this guide so you have a basic understanding of Adafruit IO.

cam/cran b (figure 2 ls ignition controller harnesses, pn 19355863 ignition (30a fused) h g f e coils 1-3-5-7 coils 2-4-6-8 k cam/crank crank cam/crank cam note: cam plugs directly into sensor, not oem pigtail. 24x crank 1x cam (rear) - included black crank sensor connecto

OM-USB-TC User's Guide Introducing the OM-USB-TC 8 Connecting a OM-USB-TC to your computer is easy Installing a data acquisition device has never been easier. The OM-USB-TC relies upon the Microsoft Human Interface Device (HID) class drivers. The HID class drivers ship with every copy of Windows that is designed to work with USB ports.

Inside HID Mobile Access HID Mobile Access users are efficiently enrolled via an easy-to-use, online management portal. From mobile-enabled readers and secure Mobile IDs, HID Mobile Access technology is built to work seamlessly together. Scalability and Cost-Savings HID Mobile Access Portal features:

the American Board of Radiology (ABR) Core and Certifying examinations administered between January 1 – December 31, 2018. The guide has undergone a few minor changes compared to the 2018 version, which was significantly revised com- pared to earlier versions, reflecting changes in NIS content on the examinations. The primary change in this study guide is the addition of Core Concepts of .