<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Photons, Electrons, and Dirt &#187; USB Human Interface Device (HID)</title>
	<atom:link href="https://bikerglen.com/blog/category/usb/usb-hid/feed/" rel="self" type="application/rss+xml" />
	<link>https://bikerglen.com/blog</link>
	<description>A blog by Glen Akins</description>
	<lastBuildDate>Mon, 16 Feb 2026 00:47:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>PIC16F1459 USB Volume Knob</title>
		<link>https://bikerglen.com/blog/pic16f1459-usb-volume-knob/</link>
		<comments>https://bikerglen.com/blog/pic16f1459-usb-volume-knob/#comments</comments>
		<pubDate>Mon, 14 Oct 2019 17:18:23 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[3D Printing]]></category>
		<category><![CDATA[Microchip]]></category>
		<category><![CDATA[PIC18]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Human Interface Device (HID)]]></category>

		<guid isPermaLink="false">https://bikerglen.com/blog/?p=1607</guid>
		<description><![CDATA[The PIC16F1459 is proving to be quite the versatile part when it comes to building USB devices. Previously, I&#8217;ve used it to upgrade my giant keyboard, various flavors of one-key keyboards, a USB-controlled industrial stack light, and an annoying CAPS &#8230; <a href="https://bikerglen.com/blog/pic16f1459-usb-volume-knob/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_1600" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-top.jpg"><img class="wp-image-1600 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-top-1024x682.jpg" alt="The completed USB volume knob project. It uses an off-the-shelf knob and a PIC16F1459 microcontroller. The enclosure is 3D printed." width="640" height="426" /></a><p class="wp-caption-text">The completed USB volume knob. The 3D printed enclosure houses a custom board design, a PIC16F1459 microcontroller, and an optical encoder. The knob itself is an aluminum off-the-shelf component from TE Connectivity.</p></div>
<p>The PIC16F1459 is proving to be quite the versatile part when it comes to building USB devices. Previously, I&#8217;ve used it to upgrade my <a href="https://bikerglen.com/blog/building-a-giant-usb-three-key-mechanical-keyboard/">giant keyboard</a>, various flavors of <a href="https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/">one-key keyboards</a>, a USB-controlled <a href="https://bikerglen.com/blog/pic16f1459-usb-stack-light-controller/">industrial stack light</a>, and an annoying CAPS LOCK <a href="https://bikerglen.com/blog/the-annoying-caps-lock-warning-buzzer/">warning buzzer</a>.  In this project, I&#8217;m going to use the PIC16F1459 to build a USB volume knob that works similarly to the volume keys on some USB keyboards. Read on to find out more about the design of the USB volume knob.</p>
<p><span id="more-1607"></span></p>
<h2>Enclosure Design</h2>
<h3>Design Inspiration and Criteria</h3>
<p>Believe it or not, I designed the enclosure for this project before I ever even thought about building a USB volume knob. A few months ago, I set out to to design a generic enclosure that was somewhat roomy that I could use for any small project. The volume knob just happened to be the first project to come along after designing the generic enclosure.</p>
<div id="attachment_1237" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/notch-connectors.jpg"><img class="size-large wp-image-1237" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/notch-connectors-1024x682.jpg" alt="Close up of the notch and connectors." width="640" height="426" /></a><p class="wp-caption-text">Close up of the notch and connectors.</p></div>
<p>I thought about enclosures I designed in the past and a few elements of two enclosures in particular struct me as unique and something I should bring forward to my generic enclosure design. The first was the round form factor and the rear panel notch on the USB <a href="https://bikerglen.com/blog/pic16f1459-usb-stack-light-controller/">stack light controller</a> base. These are shown in the photo of the stack light controller above.</p>
<div id="attachment_1147" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/side-view.jpg"><img class="size-large wp-image-1147" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/side-view-1024x683.jpg" alt="If you look closely, you can see the overlapping lips on each half of the enclosure in this photo." width="640" height="427" /></a><p class="wp-caption-text">If you look closely, you can see the overlapping lips on each half of the enclosure in this photo.</p></div>
<p>The second was the way the overlapping lips worked to seal the two halves of the <a href="https://bikerglen.com/blog/homebrew-rgb-led-light/">PIC24 DMX RGB light</a> together. If you look closely, you can see these in the photo of the light&#8217;s enclosure above.</p>
<p>After deciding on these key design elements, I narrowed down a few other design criteria:</p>
<ol>
<li>The enclosure should bolt together with 2-56 threaded black oxide screws and nuts.</li>
<li>The enclosure should be 0.75 inch tall since this was the largest commonly available 2-56 thread black oxide screw length.</li>
<li>The enclosure would be 60 mm in diameter.</li>
<li>The flat edge of the board that would accommodate any necessary connectors would be 24 mm wide. 24 mm easily allows for a micro USB connector or USB C connector plus a second small connector or reset button,</li>
<li>The enclosure walls would be 1.5 mm thick.</li>
<li>The circular overhangs above and below the notch would be 2 mm thick to imply the enclosure is thicker and sturdier than it really is.</li>
</ol>
<h3>Parametric Modeling</h3>
<div id="attachment_1625" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/parameters.png"><img class="size-large wp-image-1625" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/parameters-1024x601.png" alt="Parameters used to control the size of the enclosure." width="640" height="376" /></a><p class="wp-caption-text">Parameters used to control the size of the enclosure.</p></div>
<p>Since this was a generic enclosure being designed for a project that doesn&#8217;t exist yet, it&#8217;d be great to be able to resize the enclosure later based on the actual needs of the project. Fortunately Fusion 360 supports parametric modeling. With parametric modeling, you define a list of parameters and their values. Instead of specifying a fixed value when drawing a feature in the model, you use the name of the parameter instead. Now when you go back to the table and change the parameter&#8217;s value, the model will automatically update and resize based on the new value.</p>
<p>The list of parameters and their values I used for this enclosure is shown in the photo above. When I sketched the circle that became the base of the model, I entered &#8220;enclosure_diameter&#8221; for the diameter of the circle rather than &#8220;60 mm.&#8221; Now if I decide I want a larger enclosure, I can go back to the table and change the expression for the enclosure_diameter from &#8220;60 mm&#8221; to &#8220;70 mm&#8221; and the base will magically grow to 70 mm in diameter. Another cool thing is expressions can be chained like the calculation of the board diameter above which is based on the enclosure diameter, the wall thickness, and a small offset.</p>
<p>Parametric modeling can be difficult to get right. It takes a bit of planning and foresight to get it right. The enclosure bottom seems to work OK. For some reason, the enclosure top doesn&#8217;t move its screw holes correctly when the diameter is changed and the enclosure_height doesn&#8217;t really work at all. I may fix this in a later version of the enclosure design. I called it good enough for now though and moved on.</p>
<h3>Enclosure Bottom</h3>
<div id="attachment_1628" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-bottom-top.png"><img class="size-large wp-image-1628" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-bottom-top-1024x819.png" alt="Interior view of the bottom half of the enclosure." width="640" height="512" /></a><p class="wp-caption-text">Interior view of the bottom half of the enclosure.</p></div>
<p>The photo above shows the interior of the bottom half of the completed enclosure. The board rests on top of the hexagonal extrusions that hold the hex nuts.</p>
<div id="attachment_1629" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-bottom-bottom.png"><img class="size-large wp-image-1629" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-bottom-bottom-1024x819.png" alt="Exterior view of the bottom half of the enclosure." width="640" height="512" /></a><p class="wp-caption-text">Exterior view of the bottom half of the enclosure.</p></div>
<p>The photo above shows the exterior of the bottom half of the completed enclosure. The hexagonal holes hold the hex nuts that secure the two halves of the enclosure together.</p>
<h3>Enclosure Top</h3>
<div id="attachment_1630" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-top-bottom.png"><img class="size-large wp-image-1630" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-top-bottom-1024x819.png" alt="Interior view of the top half of the enclosure." width="640" height="512" /></a><p class="wp-caption-text">Interior view of the top half of the enclosure.</p></div>
<p>The photo above shows the interior of the top half of the completed enclosure. The screws that hold the enclosure together run through the center of the hollow posts. The ends of the hollow posts hold the circuit board in place. The flat portion notched out of the rear of the enclosure is very visible in this view.</p>
<div id="attachment_1631" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-top-top.png"><img class="size-large wp-image-1631" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/enc-top-top-1024x819.png" alt="Exterior view of the top half of the enclosure." width="640" height="512" /></a><p class="wp-caption-text">Exterior view of the top half of the enclosure.</p></div>
<p>The photo above shows the exterior of the top half of the completed enclosure. The holes are tapered so that the flat head screws lay flush with the top of the enclosure.</p>
<p>That&#8217;s the finished generic version of the enclosure. Once we&#8217;ve selected an encoder and knob, we&#8217;ll add a hole for the encoder as well as a hole for a female micro USB B connector.</p>
<h3>Creating and Exporting a Board Outline</h3>
<div id="attachment_1634" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/bottom-with-board.png"><img class="size-large wp-image-1634" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/bottom-with-board-1024x819.png" alt="A generic circuit board located inside the enclosure. I added a 3D model of a right-angle tactile switch to see how a reset button might fit inside the enclosure." width="640" height="512" /></a><p class="wp-caption-text">A generic circuit board located inside the enclosure. I added a 3D model of a right-angle tactile switch to see how a reset button might fit inside the enclosure.</p></div>
<p>Since this was a generic enclosure design, it only made sense to have an empty board outline I could use a starting point when designing various boards to fit inside the enclosure.</p>
<p>I constructed a plane on top of the hex standoffs then created a sketch on that plane. I projected the interior of the enclosure and offset it by 0.5 mm away from the walls of the enclosure to create the board outline. I also need to create keepouts for the hex standoffs and circular posts that contact the board inside the enclosure. I projected these from the bottom and top of the enclosure into the sketch as well.</p>
<div id="attachment_1636" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/board-outline1.png"><img class="size-large wp-image-1636" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/board-outline1-1024x974.png" alt="The completed board outline in Eagle PCB. The white outline is on the Dimension (20) layer. The hex and round keep out areas are on the blue bKeepout (40) and red tKeepout (39) layers respectively." width="640" height="609" /></a><p class="wp-caption-text">The completed board outline in Eagle PCB. The white outline is on the Dimension (20) layer. The hex and round keep out areas are on the blue bKeepout (40) and red tKeepout (39) layers respectively.</p></div>
<p>Once the sketch was completed, I exported it as a DXF file from Fusion 360 then imported it into the dimension layer in Eagle PCB. I moved the hex standoff lines to the bottom keepout layer and the round standoff lines to the top keepout layer. I left the board outline on the dimension layer. The DXF export and import wasn&#8217;t perfect so I had to patch up the board outline some on the dimension layer. Finally, I added the holes for the 2-56 screws and saved the file as an Eagle BRD file to use as a starting point for any designs utilizing the enclosure.</p>
<h2>Selecting an Encoder</h2>
<p>A tweet from one my co-workers was the inspiration to build a USB volume knob based on the work I&#8217;d done on the small keyboards and caps lock warning buzzer. Turning a variable resistor would not work for a USB volume knob though because a variable resistor outputs an absolute resistance / position value and there is not a USB HID command to set the volume to a fixed level. You can turn the volume down, you can turn the volume up, and you can toggle mute with USB HID. That&#8217;s it.</p>
<p>Also, a variable resistor has fixed end points in its rotation. Even if I could hack something to detect which way the variable resistor was being turned and send the correct USB HID commands to the computer, eventually I&#8217;d hit an endpoint in the knobs rotation and that endpoint would likely not be aligned with the lowest volume or highest volume setting on the computer.</p>
<div id="attachment_1638" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/encoders.jpg"><img class="size-large wp-image-1638" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/encoders-1024x682.jpg" alt="Two different types of encoders." width="640" height="426" /></a><p class="wp-caption-text">Two fundamentally different encoder examples.</p></div>
<p>I needed a device that could signal the volume to go up when turned one direction and that could signal the volume to go down when turned the other direction. Also pushing the knob should toggle mute. Fortunately such a device exists&#8211;the rotary encoder. I&#8217;ve heard them called incremental encoders, rotary pulse generators, or simply encoders. These come in a bunch of different varieties.</p>
<p>The photo above shows two examples. The one with the ribbon cable is an optical rotary encoder with a quadrature encoded output. The smaller one is a mechanical rotary encoder that closes different switch contacts based on CW or CCW rotation of the shaft. The optical encoder is over $30. The mechanical encoder is closer to $3.</p>
<p>As an aside, the optical encoder pictured above has been in production for over 30 years. It was originally developed within the test and measurement division of HP for use on the front panels of their test equipment. When Agilent split off from HP in 2000, the production of the encoder went to Agilent. The encoder then went to Avago in the Agilent-Avago split in 2015. It&#8217;s currently sold by Broadcom after the Avago acquistion of Broadcom and their subsequent name change.</p>
<p>Here are some key parameters to be aware of when selecting an encoder:</p>
<ul>
<li>Shaft size: 1/4-inch (6.35 mm) and 6 mm are the most common sizes. Shaft size needs to match the diameter of the hole in the center of the chosen knob.</li>
<li>Shaft shape: Either round or D shaped. Round works. D shaped is easier to lock into place and prevent rotation of the knob on the shaft.</li>
<li>Shaft length: The value is all over the place. It&#8217;s important that the locking screw on the chosen knob can make solid contact with whatever length shaft is chosen. It&#8217;s also aesthetically important that the shaft is not too long otherwise the knob will bottom out and look way too far away from the chassis.</li>
<li>Smooth or with detents: Smooth encoders rotate freely. Encoders with detents click into place after each change in output state.</li>
<li>Optical or mechanical: Optical encoders have longer lifetimes, offer more pulses per revolution, and are more expensive. Mechanical encoders are the opposite.</li>
<li>Number of pulses per revolution: How many pulses does the knob generate in one revolution. 16, 32, 120, and 256 are common values. Some specialized encoders for motor shaft positioning applications generate even more.</li>
<li>Encoding: quadrature / gray scale or discrete pulse per direction. We&#8217;ll get into quadrature / gray scale encoding in the software section below.</li>
<li>Integrated switch: Some encoders have an integrated pushbutton switch; others don&#8217;t.</li>
<li>Supply voltage: Optical encoders typically run from a specific supply voltage and have open-drain / open-collector outputs. Mechanical encoders are a bit more flexible in terms of acceptable voltages.</li>
<li>Panel mount or board mount. Panel mount encoders have threaded stems and mount to the panel using a hex nut. Board mount encoders solder directly to the board. The distance between board and enclosure and encoder and knob all have to be considered during design with either type. I generally find board mount encoders to be less flexible in terms of positioning than panel mount encoders.</li>
</ul>
<div id="attachment_1591" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/2.jpg"><img class="wp-image-1591 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/2-1024x575.jpg" alt="2" width="640" height="359" /></a><p class="wp-caption-text">The Grayhill 62S11-M5-020C encoder used for this project. The sticker is leftover from another project and was used to keep the encoder from shorting to the board during software development.</p></div>
<p>I picked the Grayhill 62S11-M5-020C encoder that&#8217;s shown in the photo above. It has the following attributes:</p>
<ul>
<li>1/4&#8243; diameter D shaft.</li>
<li>Detented with 32 pulses per revolution.</li>
<li>Optical with quadrature encoding and an integrated switch.</li>
<li>Panel mount with a short ribbon cable and small connector.</li>
</ul>
<p>All this goodness was not cheap. The encoder goes for about $45 at quantity one.</p>
<h2>Selecting a Knob</h2>
<div id="attachment_1640" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/knobs.jpg"><img class="wp-image-1640 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/knobs-1024x682.jpg" alt="knobs" width="640" height="426" /></a><p class="wp-caption-text">Three alternative knob options for the USB volume knob.</p></div>
<p>After selecting an encoder, the next step was to select a knob. I need a knob to fit a 1/4&#8243; shaft and I wanted metal knob. I narrowed down to the four options shown in the picture above. The two larger knobs are made by TE Connectivity. They have a glossy finish. The two smaller knobs are made by Kilo International. They have a matte finish.</p>
<p>My favorite knob is the one front and center in the photograph but I decided it was too small compared to the enclosure. The knob I ultimately selected and is on the USB volume knob in the photo above is TE Connectivity part # KN1251B1/4 and sells for about $15. The runner up knob is Kilo International part # OEDNI-90-4-5 and sells for about $7. I&#8217;m definitely going to have to build something in the future that uses a few of the Kilo International knobs.</p>
<h2>Finishing the Enclosure Design</h2>
<div id="attachment_1642" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/section-analysis1.png"><img class="size-large wp-image-1642" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/section-analysis1-1024x819.png" alt="Section analysis showing the vertical alignment of the encoder within the enclosure." width="640" height="512" /></a><p class="wp-caption-text">Section analysis showing the vertical alignment of the encoder within the enclosure.</p></div>
<p>Now that I had a knob and encoder picked out, it was time to return to the enclosure design. The encoder has a 3/8-32 thread and <a href="https://littlemachineshop.com/images/gallery/PDF/TapDrillSizes.pdf">requires a 0.3970&#8243; hole (PDF link)</a>. I created a hole centered on the top half of the enclosure with this diameter then it was time to think about the vertical alignment of the enclosure, circuit board, encoder, and knob.</p>
<p>Fortunately Grayhill had a 3D model of their encoder and TE Connectivity had a 3D model of their knob. I imported these into the enclosure design and used the joint tool to place the encoder in the hole and to place the knob on the end of the encoder shaft. The Grayhill 3D model wasn&#8217;t an exact match so there&#8217;s a rogue connector and cable protruding outside the enclosure but that&#8217;s OK for now.</p>
<p>Fusion 360&#8217;s section analysis tool allowed me to see a cutaway view of how the knob, encoder, PCB, and enclosure fit together. I played with the alignment until I found something where there was enough clearance between the knob and the enclosure to allow the integrated push button in the encoder to be pressed.</p>
<p>This ultimately required the encoder to be recessed 4.5 mm below the top of the enclosure and the knob to be elevated 1/16&#8243; above the end of the shaft of the encoder. I could use washers to satisfy the former requirement. Instead I bulked up the 3D printed material between the encoder and enclosure to the required thickness. To satisfy the latter requirement, I placed a 1/16&#8243; spacer with an outside diameter of 1/4&#8243; into the knob before mounting it on the encoder&#8217;s shaft. Kind of a kluge but it works well.</p>
<p>I added the cutout for the micro USB B connector to the rear of the enclosure using the same technique I used when making connector cutouts on the <a href="https://bikerglen.com/blog/homebrew-rgb-led-light/">DMX-controlled RGB LED light</a>. The final version of the 3D printed enclosure with the micro USB B connector cutout and the encoder and knob mounted is shown the image below. I then generated the STL files and sent them for 3D printing at Sculpteo using <a href="https://www.sculpteo.com/blog/2017/10/25/how-to-design-for-hp-multi-jet-fusion-technology/">HP&#8217;s Multi Jet Fusion 3D</a> printing technology.</p>
<div id="attachment_1594" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/puck_v2_v16_grayhill_encoder-v7.png"><img class="size-large wp-image-1594" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/puck_v2_v16_grayhill_encoder-v7-1024x819.png" alt="Finished enclosure design." width="640" height="512" /></a><p class="wp-caption-text">Finished enclosure design.</p></div>
<h2>Designing the Electronics and Board</h2>
<div id="attachment_1643" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/schematic.png"><img class="size-large wp-image-1643" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/schematic-1024x764.png" alt="Completed schematic." width="640" height="478" /></a><p class="wp-caption-text">Completed schematic.</p></div>
<p>The schematic for the electronics is shown in the image above. It&#8217;s identical to the schematic for the updated version of the <a href="https://bikerglen.com/blog/updates-to-the-annoying-caps-lock-warning-buzzer/#more-1548">Annoying CAPS LOCK Warning Buzzer</a> except for the addition of a connector for the Grayhill optical rotary encoder and a few more LEDs.</p>
<p>The Grayhill encoder requires +5V DC to power the infrared light sources inside the encoder. It has open-drain / open-collector outputs and requires 2.2k pullup resistors on its CH A and CH B outputs to function. The encoder&#8217;s integrated push button switch uses the PIC&#8217;s internal weak pullup function so no pullup resistor is required on the switch output signal.</p>
<div id="attachment_1644" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/board.png"><img class="size-large wp-image-1644" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/board-985x1024.png" alt="Completed board." width="640" height="665" /></a><p class="wp-caption-text">Completed board.</p></div>
<p>The USB volume knob board is 56 mm in diameter. It is absolutely roomy compared to the 1&#8243; x 1&#8243; boards used for the caps lock warning buzzer and assorted one key keyboards. As a result, the layout was significantly easier and faster to finish.</p>
<p>I started with the generic board outline file I created while designing the enclosure. On that board outline I placed the critical components like the USB connector, the encoder connector, and the ESD suppression diodes first.</p>
<p>I placed the rest of the components next while leaving a big open area in the center to avoid any components making contact with the metallic base of the encoder or interfering with the folding of the encoder&#8217;s ribbon cable. After placing all the components, it was time to route the board.</p>
<p>I created a ground plane on each side of the board then connected the two ground planes using lots of vias through the board. Horizontal traces run on the front side of the board and vertical traces run on the rear. The +5V power is routed where its needed using traces. The completed and stuffed board is shown in the photo below.</p>
<div id="attachment_1646" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/board.jpg"><img class="size-large wp-image-1646" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/board-1024x682.jpg" alt="The completed and stuffed circuit board. I left the buzzer off for now." width="640" height="426" /></a><p class="wp-caption-text">The completed and stuffed circuit board. I left the buzzer off for now.</p></div>
<h2>Software</h2>
<p>I did have one slight snag while building this project: the software. Just because volume keys are on many USB keyboards doesn&#8217;t mean the volume keys function like the rest of the keys on the keyboard. The USB HID spec treats the volume keys quite differently. As a result, the software I used on the one key keyboards and caps lock warning buzzer was going to require some pretty arcane (if USB HID is not your thing) modifications to control the computer&#8217;s volume.</p>
<h3>USB HID Report Descriptors</h3>
<p>During device enumeration, the connected USB device tells the USB host what type of device it is. If it is a USB HID device, the device also has to tell the host the types and formats of reports it will send to the host and the types and formats of reports it expects from the host. This is done using a USB HID report descriptor.</p>
<p>The USB HID report descriptor is built using codes from the USB HID specification and a supplementary document called the USB HID usage tables. The USB HID report descriptor provides the host with enough information to parse USB input reports or to create USB output reports.</p>
<p>This offloads a lot of complexity from the device to the host. The host must be able to deal with arbitrarily formatted input reports from USB HID devices. It must also be able to create arbitrarily formatted output reports to send to USB HID devices. There&#8217;s no guarantee that different USB HID devices that perform similar functions will have identical or even similarly formatted input and output reports.</p>
<p>The code below shows the USB HID report descriptor that my small one key keyboards and the caps lock warning buzzer use. It asks the host to send an output report with the status of the five common LEDs (Num Lock, Scroll Lock, Caps Lock, etc.) and three padding bits. It also tell the host that the device will send the state of the eight modifier keys followed by up to six keys from the key code chart when polled by the host.</p>
<pre>const struct{uint8_t report[HID_RPT01_SIZE];}hid_rpt01={
{   0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x08,                    //   REPORT_COUNT (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
    0x95, 0x05,                    //   REPORT_COUNT (5)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x05, 0x08,                    //   USAGE_PAGE (LEDs)
    0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
    0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x03,                    //   REPORT_SIZE (3)
    0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
    0x95, 0x06,                    //   REPORT_COUNT (6)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
    0xc0}                          // End Collection
};</pre>
<p>Further complicating things, the volume control keys are not a part of the keyboard usage page in the HID usage tables. They&#8217;re part of a separate usage page called the consumer control usage tables. If we want to send volume control keys to the host, we need to send some HID usage codes from a different usage table than we used for the keyboard.</p>
<p>Unfortunately, there&#8217;s no way to mix the keyboard usage with the consumer usage in a single input report. This means our device needs to send one type of input report when a keyboard key is pressed and a second, different type of input report when the volume is adjusted. (Or we could do away with sending keyboard usage input reports altogether but I wanted to keep the caps lock status and did not want to preclude sending +/- key presses instead of volume up / volume down in the future.)</p>
<p>Telling the host our device is capable of sending two different USB input reports is done using USB HID collections. There&#8217;s already one USB HID collection in the code above. The code below builds on the code above and adds a second USB HID collection. Everything up to the start of the second USB HID collection in the code below is identical to the code above.</p>
<pre>const struct{uint8_t report[HID_RPT01_SIZE];}hid_rpt01={
{   0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x85, 0x01,                    //   REPORT_ID
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x08,                    //   REPORT_COUNT (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
    0x95, 0x05,                    //   REPORT_COUNT (5)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x05, 0x08,                    //   USAGE_PAGE (LEDs)
    0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
    0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x03,                    //   REPORT_SIZE (3)
    0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)
    0x95, 0x06,                    //   REPORT_COUNT (6)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
    0xc0,                          // End Collection

    0x05, 0x0C,                    // USAGE_PAGE (Consumer Devices)
    0x09, 0x01,                    // USAGE (Consumer Control)
    0xA1, 0x01,                    // COLLECTION (Application)
    0x85, 0x02,                    //   REPORT_ID
    0x05, 0x0C,                    //   USAGE_PAGE (Consumer Devices)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x07,                    //   REPORT_COUNT (7)
    0x09, 0xB5,                    //   USAGE (Scan Next Track)
    0x09, 0xB6,                    //   USAGE (Scan Previous Track)
    0x09, 0xB7,                    //   USAGE (Stop)
    0x09, 0xCD,                    //   USAGE (Play / Pause)
    0x09, 0xE2,                    //   USAGE (Mute)
    0x09, 0xE9,                    //   USAGE (Volume Up)
    0x09, 0xEA,                    //   USAGE (Volume Down)
    0x81, 0x02,                    //   INPUT (Data, Variable, Absolute)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x81, 0x01,                    //   INPUT (Constant)
    0xC0}                          // End Collection
};</pre>
<p>The first thing this new, second USB HID collection does is tell the host we&#8217;re going to send codes from the USB HID consumer control usage tables. This is done using the USAGE_PAGE and USAGE instructions. Next, this input report will have an ID of 0x02. Then it tells the host we&#8217;re going to send the state of the track controls and volume controls and one padding bit. Lastly, it closes the collection with the end collection instruction. This <a href="https://www.microchip.com/forums/m618147.aspx">forum post</a> on Microchip&#8217;s website was invaluable in figuring out the modifications that were required to send the volume keys in a USB input report.</p>
<p>Another slight wrinkle is that if there is only one type of input report, the input report ID is not specified in the USB input reports sent from the device to the host. If there&#8217;s more than one type of input report, however, the input report ID must be specified in the USB input report. This means our USB input reports need to be bumped in length from eight bytes to nine bytes everywhere they&#8217;re referenced in our code.</p>
<p>If you&#8217;re really curious about all the code changes to support a second type of USB HID input report, I suggest doing a diff between the annoying caps lock warning buzzer source code and the USB volume knob source code. Source code for both devices is in my Github repositories.</p>
<h3>Decoding the Encoder’s Quadrature Outputs</h3>
<div id="attachment_1683" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/quadrature-codes.png"><img class="size-large wp-image-1683" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/quadrature-codes-1024x321.png" alt="Truth table and waveform illustration from the Grayhill encoder data sheet." width="640" height="201" /></a><p class="wp-caption-text">Truth table and waveform illustration from the Grayhill encoder data sheet.</p></div>
<p>If you look at OUTPUT A and OUTPUT B in the above diagram, you can see that OUTPUT B lags OUTPUT A by 90 degrees. This is called quadrature encoding. As a result, the outputs of the encoder looks like a gray code counter and only one output signal changes per click / move of the encoder.</p>
<p>To determine the direction the encoder is moving you need to know the last state of the two outputs and the current state of the two outputs. Based on the last state and the current state, you can determine if the encoder is being turned clockwise or counterclockwise.</p>
<p>For example, let&#8217;s start at position number 3 in the diagram above. A and B are both high. We save this state to a variable. Some amount of time later, we read the encoder again. If A and B are still both high, the encoder has not been turned. If however, A is now low while B is still high, the encoder has been turned one click clockwise. If however, A is still high while B is now low, the encoder has been turned one click counterclockwise.</p>
<p>To avoid missing encoder pulses, software must read the encoder at least twice as fast as the highest expected pulse rate. My software polls the encoder at a 1 kHz rate. This allows the encoder to be turned up to 500 pulses per second without missing a pulse. With a manually turned knob with only 32 pulses per revolution, that rate is acceptable. If you have a microcontroller capable of generating interrupts on the change of state of input pins, you can handle much higher rotational speeds.</p>
<p>The code to read the encoder and determine whether the volume needs to go up or down is shown below. The variable last_knob holds the last known state of the encoder&#8217;s outputs. The variable this_knobs is assigned the current state of the encoder&#8217;s outputs. The switch statement determines which way the knob is being turned and updates the signed variable value_knob up or down based on the direction the knob is turned.</p>
<pre>#define S2_PORT  PORTBbits.RB5      // CHA
#define S3_PORT  PORTBbits.RB4      // CHB

void BUTTON_UpdateStates (void)
{
    ...
    // this_knob = { CHB, CHA }
    this_knob = (S3_PORT &lt;&lt; 1) | S2_PORT;
    switch (last_knob) {
        case 0: if (this_knob == 1) { value_knob--; } else if (this_knob == 2) { value_knob++; } break;
        case 1: if (this_knob == 0) { value_knob++; } else if (this_knob == 3) { value_knob--; } break;
        case 2: if (this_knob == 0) { value_knob--; } else if (this_knob == 3) { value_knob++; } break;
        case 3: if (this_knob == 1) { value_knob++; } else if (this_knob == 2) { value_knob--; } break;
    }
    last_knob = this_knob;
}</pre>
<p>Inside the code that responds to the USB bus&#8217;s input polling requests is code to see if value_knob is less than or greater than zero. This code is shown below. If it&#8217;s less than zero, it sets the volume_down bit in the USB input report that will be sent to the host computer. If it&#8217;s greater than zero, it sets the volume_up bit in the USB input report that will be sent to the host computer. There&#8217;s quite a bit of abstraction and redirection in this code since I did not attempt to simplify it any from the Microchip for Library Applications source code.</p>
<pre>inputReport.report_id = 0x02;
if(BUTTON_IsPressed(BUTTON_USB_DEVICE_HID_KEYBOARD_KEY_0) == true) {
    inputReport.modifiers.media.mute = 1;
}
if(BUTTON_IsPressed(BUTTON_USB_DEVICE_HID_KEYBOARD_KEY_1) == true) {
    inputReport.modifiers.media.volumeDown = 1;
}
if(BUTTON_IsPressed(BUTTON_USB_DEVICE_HID_KEYBOARD_KEY_2) == true) {
    inputReport.modifiers.media.volumeUp = 1;
}</pre>
<p>Inside the BUTTON_isPressed function below is the actual check to see if value_knob is positive or negative. The caller calls BUTTON_isPressed with the value BUTTON_S2 to see if the volume needs to be turned down. If it does, the function returns true and value_knob is incremented to mark that we&#8217;ve handled this volume down request from the user. The caller calls BUTTON_isPressed with the value BUTTON_S3 to see if the volume needs to be turned up. If it does, the function returns true and value_knob is decremented to mark that we&#8217;ve handled this volume down request from the user. BUTTON_S1 implements the mute function.</p>
<p>The incrementing and decrementing of the value_knob variable allows for the encoder to be turned faster than volume updates can be sent over the USB bus. Once the encoder stops turning, the USB bus will eventually catch up and value_knob will settle on zero. The code that generates the USB input reports might need to be updated to send a &#8216;0&#8217; for all the mute / volume keys between presses for this to work properly.</p>
<pre>bool BUTTON_IsPressed(BUTTON button)
{
    switch(button) {
        case BUTTON_S1:
            return ((state1 &gt;= 2) ? true : false);
        case BUTTON_S2:
            if (value_knob &lt; 0) {
                value_knob++;
                return true;
            }
            return false;
        case BUTTON_S3:
            if (value_knob &gt; 0) {
                value_knob--;
                return true;
            }
            return false;
        case BUTTON_NONE:
            return false;
    }
    return false;
}</pre>
<h3>Program the Bootloader</h3>
<div id="attachment_1687" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/programming-bootloader.jpg"><img class="wp-image-1687 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/programming-bootloader-1024x682.jpg" alt="An extremely staged photo of using the Tag-Connect cable to program the USB bootloader." width="640" height="426" /></a><p class="wp-caption-text">An extremely staged photo of using the Tag-Connect cable to program the USB bootloader.</p></div>
<p>Up until this point, I had been using the MPLAB X IDE and my REAL ICE debugger to program and debug the firmware directly on the PIC16F1459. Now  that the firmware was debugged, it was time to go to a more production oriented approach to programming and updating the USB volume knob firmware.</p>
<p>I used the MPLAB X IDE and my REAL ICE programmer to program a USB bootloader into the microcontroller. This allows updates to the firmware to be made directly over the USB bus without taking the USB volume knob apart and without using a dedicated programmer and programmer cable. This is the exact same USB bootloader I used on the one key keyboards and annoying caps lock warning buzzer.</p>
<h3>Program the Firmware</h3>
<div id="attachment_1567" style="width: 451px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/usb-bootloader.png"><img class="size-full wp-image-1567" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/usb-bootloader.png" alt="The main (and only) window of the Microchip Library for Applications USB Bootloader utility." width="441" height="442" /></a><p class="wp-caption-text">The main (and only) window of the Microchip Library for Applications USB Bootloader utility.</p></div>
<p>Once the bootloader was programmed into the PIC16F1459, I could update the USB volume knob firmware using the Microchip Library for Applications (MLA) USB Bootloader Utility. A screenshot of the utility is shown above. The process is as follows:</p>
<ol>
<li>Launch the MLA bootloader utility from the MLA install directory.</li>
<li>Hold down the knob while plugging the USB volume knob into the USB port on the PC.</li>
<li>Wait for the device attached and device ready messages as shown in the dialog box above.</li>
<li>Click the open button in the GUI and select the .hex file from the dist directory inside the USB volume knob firmware directory.</li>
<li>Click the program button to program the firmware into the USB volume knob.</li>
<li>Click the reset button to reset the PIC and launch the application firmware. You can also unplug the USB volume knob then plug it back into the PC. Do not hold down the knob this time.</li>
<li>Test the firmware update by turning the knob to change the volume and pressing the knob to mute / unmute the volume.</li>
</ol>
<h3>Testing</h3>
<div id="attachment_1689" style="width: 263px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/volumes.png"><img class="size-full wp-image-1689" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/volumes.png" alt="Turn the knob and you should see the volume go up and down. Press the knob and you should see the volume mute and unmute." width="253" height="185" /></a><p class="wp-caption-text">Turn the knob and you should see the volume go up and down. Press the knob and you should see the volume mute and unmute.</p></div>
<p>Test the knob before assembling the knob into the enclosure. Turn the knob to change the volume and press the knob to mute / unmute the volume.</p>
<h2>Assembly</h2>
<div id="attachment_1648" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/assembly.jpg"><img class="size-large wp-image-1648" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/assembly-1024x683.jpg" alt="Parts and tools required for assembly. Note how the encoder's ribbon cable is accordion folded into place." width="640" height="427" /></a><p class="wp-caption-text">Parts and tools required for assembly. Note how the encoder&#8217;s ribbon cable is accordion folded into place.</p></div>
<p>Assembly went pretty smoothly. First mount the encoder to the top of the enclosure using the hardware included with the encoder. Next accordion fold the ribbon cable as shown in the photograph above. Connect the encoder cable to the circuit board then press the circuit board against the top of the enclosure. While holding the circuit board in place, thread a few screws through the top of the enclosure and fit the bottom of the enclosure over the screws. Insert the nuts into their recesses on the bottom of the enclosure and tighten all four screws using a 3/64&#8243; or 0.050&#8243; hex driver.</p>
<p>A top view of the assembled USB volume knob is shown in the photo below.</p>
<div id="attachment_1600" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-top.jpg"><img class="size-large wp-image-1600" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-top-1024x682.jpg" alt="The completed USB volume knob project. It uses an off-the-shelf knob and a PIC16F1459 microcontroller. The enclosure is 3D printed." width="640" height="426" /></a><p class="wp-caption-text">The completed USB volume knob project. It uses an off-the-shelf knob and a PIC16F1459 microcontroller. The enclosure is 3D printed.</p></div>
<p>A side view of the rear of the assembled USB volume knob is shown in the photo below.</p>
<div id="attachment_1602" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-rear.jpg"><img class="size-large wp-image-1602" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-rear-1024x682.jpg" alt="Flat section on the rear of the enclosure to accommodate the micro USB connector." width="640" height="426" /></a><p class="wp-caption-text">Flat section on the rear of the enclosure to accommodate the micro USB connector.</p></div>
<p>My desk is kind of slick. I dug through the junk drawer in the kitchen to find some rubber bumpers to place on the bottom of the USB volume knob to keep it in place while turning it. I only had two bumpers left. That&#8217;d be kind of wobbly so I cut the waste material surrounding the two remaining bumpers to size then stuck it on the bottom of the USB volume knob instead:</p>
<div id="attachment_1601" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-bottom.jpg"><img class="size-large wp-image-1601" src="https://bikerglen.com/wp/wp-content/uploads/2019/10/usb-volume-knob-bottom-1024x682.jpg" alt="Rubber stuck to bottom of enclosure to keep it from sliding on my desk." width="640" height="426" /></a><p class="wp-caption-text">Rubber stuck to bottom of enclosure to keep it from sliding on my desk.</p></div>
<h2>Design Files</h2>
<p>Design files are available for the enclosure, board, and software in my <a href="https://github.com/bikerglen/usb-volume-knob">Github repository</a> for the project.</p>
<h2>Resources</h2>
<p>The following online resources were helpful while figuring out the needed USB input report descriptors to report desired volume changes to the PC:</p>
<ul>
<li>This Microchip forum post:<br />
<a href="https://www.microchip.com/forums/m618147.aspx"> https://www.microchip.com/forums/m618147.aspx</a></li>
<li>This tutorial on USB HID Report Descriptors:<br />
<a href="https://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/">https://eleccelerator.com/tutorial-about-usb-hid-report-descriptors/</a></li>
</ul>
<p>Readers may also find the following resources helpful:</p>
<ul>
<li>A good description of the USB HID setup process:<br />
<a href="http://kevincuzner.com/2018/02/02/cross-platform-driverless-usb-the-human-interface-device/">http://kevincuzner.com/2018/02/02/cross-platform-driverless-usb-the-human-interface-device/</a></li>
<li>The USB HID Landing Page:<br />
<a href="https://www.usb.org/hid">https://www.usb.org/hid</a></li>
<li>The USB Device Class Definition for Human Interface Devices (HID):<br />
<a href="https://www.usb.org/sites/default/files/documents/hid1_11.pdf">https://www.usb.org/sites/default/files/documents/hid1_11.pdf</a></li>
<li>The USB HID usage tables:<br />
<a href="https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf">https://www.usb.org/sites/default/files/documents/hut1_12v2.pdf</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/pic16f1459-usb-volume-knob/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updates to the Annoying CAPS LOCK Warning Buzzer</title>
		<link>https://bikerglen.com/blog/updates-to-the-annoying-caps-lock-warning-buzzer/</link>
		<comments>https://bikerglen.com/blog/updates-to-the-annoying-caps-lock-warning-buzzer/#comments</comments>
		<pubDate>Mon, 30 Sep 2019 04:40:56 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[3D Printing]]></category>
		<category><![CDATA[Microchip]]></category>
		<category><![CDATA[PIC18]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Human Interface Device (HID)]]></category>

		<guid isPermaLink="false">https://bikerglen.com/blog/?p=1548</guid>
		<description><![CDATA[In my first post on the Annoying CAPS LOCK Warning Buzzer, I concluded with a list of future improvements to make to the project. Those updates are now implemented and the Annoying CAPS LOCK Warning Buzzer is more robust than &#8230; <a href="https://bikerglen.com/blog/updates-to-the-annoying-caps-lock-warning-buzzer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_1549" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer-updates.jpg"><img class="size-large wp-image-1549" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer-updates-1024x683.jpg" alt="Some minor updates to the annoying caps lock warning buzzer." width="640" height="427" /></a><p class="wp-caption-text">Some new additions to the annoying caps lock warning buzzer (circled in green).</p></div>
<p>In my <a href="https://bikerglen.com/blog/the-annoying-caps-lock-warning-buzzer/">first post on the Annoying CAPS LOCK Warning Buzzer</a>, I concluded with a list of future improvements to make to the project. Those updates are now implemented and the Annoying CAPS LOCK Warning Buzzer is more robust than ever. Read on to find out more about the improvements.</p>
<p><span id="more-1548"></span></p>
<h2>Goals for Improvements</h2>
<p>The list of new features and improvements is pretty short:</p>
<ol>
<li>Include a ground plane on both sides of the board. Route +5V as traces.</li>
<li>Add some basic ESD protection.</li>
<li>Add a button and LED to use with a USB bootloader and firmware update utility to apply firmware updates.</li>
<li>Make the button and LED accessible without disassembling the buzzer.</li>
</ol>
<p>Let&#8217;s run through each of the improvements separately.</p>
<h2>Ground Plane</h2>
<p>On the old board, the ground plane was on the component / top layer with a +5V plane on the bottom. This wasn&#8217;t causing any problems (that I know of) but the ground plane was broken by up all the pads for the surface-mount components. In the new version, both sides of the board contain a filled ground plane with lots of vias to bond the two ground planes to each other. The +5V is now routed as traces on the bottom of the board.</p>
<p>In theory this will reduce noise on the board and improve the electromagnetic compatibility of the board. One day I&#8217;ll have to bring both the old board and new board to work, find a spectrum analyzer and EMC probe set, and learn to make some EMC measurements. In the meantime, at least I didn&#8217;t break anything with the ground plane changes.</p>
<h2>ESD Protection</h2>
<div id="attachment_1558" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/esd-protection.jpg"><img class="wp-image-1558 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/esd-protection-1024x683.jpg" alt="esd-protection" width="640" height="427" /></a><p class="wp-caption-text">That&#8217;s the Nexperia PRTR5V0U2X ESD protection diode below the five millimeter mark on my Adafruit PCB ruler. It&#8217;s small but not any worse than an SOT-23 transistor to hand solder.</p></div>
<p>The second change was to add some basic ESD protection using a Nexperia <a href="https://assets.nexperia.com/documents/data-sheet/PRTR5V0U2X.pdf">PRTR5V0U2X ultra-low capacitance double rail-to-rail ESD protection diode</a>. This single device protects both USB data lines even in the absence of a supply voltage. The device needs to be located as close as possible to the USB connector and be very-well connected to the ground plane of the board.</p>
<h2>Button and LED and Resistor</h2>
<div id="attachment_1560" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/button-led-resistor.jpg"><img class="size-large wp-image-1560" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/button-led-resistor-1024x683.jpg" alt="A KMR2 tactile switch, an 0805 1k resistor, and an 0805 orange LED." width="640" height="427" /></a><p class="wp-caption-text">A KMR2 tactile switch, an 0805 1k resistor, and an 0805 orange LED.</p></div>
<p>The next improvement was to enable the use of the Microchip Library for Applications (MLA) USB bootloader to update the firmware on the Annoying CAPS LOCK Warning Buzzer. At boot time, the USB MLA bootloader checks a pushbutton switch. If the switch is pushed, the bootloader goes into a mode where the application firmware can be updated over USB. If the switch is not pressed, the USB MLA bootloader boots directly into the application firmware.</p>
<p>I needed a small pushbutton switch to use with the bootloader. I searched Digi-Key and Mouser looking for an SMD tactile switch. I found lots of candidates. I finally settled on a C&amp;K Switches KMR211NGLFS tactile switch. If you have an Adafruit Feather M0 board, this is very similar to the reset switch on that board.</p>
<p>The MLA USB bootloader can also blink an LED to indicate the state of the bootloader. I decided to take advantage of this feature. I selected a Dialight 599-0130-007F 0805 SMD orange LED. Any color would work but orange is somewhat different than the typical red or green LEDs on projects. Finally, I needed a current limiting resistor for the LED. I went with a small 1k 5% 0805 SMD resistor.</p>
<h2>Enclosure Modifications</h2>
<div id="attachment_1563" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/caps-lock-buzzer-v2-v5.png"><img class="size-large wp-image-1563" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/caps-lock-buzzer-v2-v5-1024x683.png" alt="The updated enclosure. Two two millimeter diameter holes on the bottom allow access to the tactile switch and LED." width="640" height="427" /></a><p class="wp-caption-text">The updated enclosure. Two two millimeter diameter holes on the bottom allow access to the tactile switch and LED.</p></div>
<p>To make the pushbutton and LED accessible without having to disassemble the warning buzzer, I added two 2 mm holes to the bottom of the enclosure. When the board is placed in the enclosure, one hole is directly over the pushbutton and the other hole is directly over the LED. The pushbutton can be pushed via a small screwdriver or paper clip. The LED light is visible by turning the buzzer upside down.</p>
<h2>Updated Schematic</h2>
<div id="attachment_1564" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/caps-lock-buzzer-v2-schematic.png"><img class="size-large wp-image-1564" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/caps-lock-buzzer-v2-schematic-1024x764.png" alt="Updated schematic. The U2, SW1, R2, and USER1 LED are new to this version of the design." width="640" height="478" /></a><p class="wp-caption-text">Updated schematic. The U2, SW1, R2, and USER1 LED are new to this version of the design.</p></div>
<p>The schematic above show the updates made for the second version of the warning buzzer. U2, SW1, R2, and the USER1 LED are new to this version of the design.</p>
<h2>Updated Boards</h2>
<div id="attachment_1562" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/new-vs-old-boards.jpg"><img class="size-large wp-image-1562" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/new-vs-old-boards-1024x683.jpg" alt="Old board on the left. New board on the right." width="640" height="427" /></a><p class="wp-caption-text">Old board on the left. New board on the right.</p></div>
<p>The photo above shows the old version of the design on the left and the new version of the design on the right. Most of components and traces are in the same place. The current limiting resistor for LED D2 / USER1 is on the reverse side of the board. Notice the many vias on the new design of the board. These vias connect the ground planes on each side of the board together.</p>
<h2>Updated Enclosure</h2>
<div id="attachment_1597" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer-back-1.jpg"><img class="size-large wp-image-1597" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer-back-1-1024x682.jpg" alt="The bottom of the annoying CAPS LOCK warning buzzer with the modifications to expose the LED and pushbutton." width="640" height="426" /></a><p class="wp-caption-text">The bottom of the annoying CAPS LOCK warning buzzer with the modifications to expose the LED and pushbutton.</p></div>
<p>The bottom of the updated enclosure is shown in the above photo. The hole with the orange glow is the LED. The other hole is for accessing the pushbutton swtich.</p>
<h2>Updated BOM</h2>
<p>The components that are new to the second version of the design are listed in the table below. You&#8217;ll also need a second 0805 1k 5% resistor.</p>
<table width="994">
<tbody>
<tr>
<td width="42">Line #</td>
<td width="126">Mfr. #</td>
<td width="126">Manufacturer</td>
<td width="508">Description</td>
<td width="70">Order Qty.</td>
<td width="122">Price (USD)</td>
</tr>
<tr>
<td>1</td>
<td>KMR211NGLFS</td>
<td>C&amp;K Switches</td>
<td>Tactile Switch</td>
<td>1</td>
<td>$0.52</td>
</tr>
<tr>
<td>2</td>
<td>PRTR5V0U2X,215</td>
<td>Nexperia</td>
<td>5.5V ESD Protection Diodes</td>
<td>1</td>
<td>$0.51</td>
</tr>
<tr>
<td>3</td>
<td>599-0130-007F</td>
<td>Dialight</td>
<td>0805 Orange LED</td>
<td>1</td>
<td>$0.26</td>
</tr>
</tbody>
</table>
<h2>Using the Bootloader</h2>
<div id="attachment_1567" style="width: 451px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/usb-bootloader.png"><img class="size-full wp-image-1567" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/usb-bootloader.png" alt="The main (and only) window of the Microchip Library for Applications USB Bootloader utility." width="441" height="442" /></a><p class="wp-caption-text">The main (and only) window of the Microchip Library for Applications USB Bootloader utility.</p></div>
<p>The MLA USB bootloader must be programmed using a PIC programmer such as the PICkit 4 or ICD 4 and the MPLAB X IDE or IPE. Once the bootloader is programmed, the bootloader can be used to update the application firmware. To update the firmware:</p>
<ol>
<li>Launch the MLA bootloader utility from the MLA install directory.</li>
<li>Hold down the button using a paper clip or small screwdriver while plugging the warning buzzer into the USB port on the PC. Be sure to push on the pushbbutton; not the LED.</li>
<li>Wait for the device attached and device ready messages as shown in the dialog box above.</li>
<li>Click the open button in the GUI and select the .hex file from the dist directory inside the caps lock buzzer firmware directory.</li>
<li>Click the program button to program the firmware into the warning buzzer.</li>
<li>Click the reset button to reset the PIC and launch the application firmware. You can also unplug the warning buzzer then plug it back into the PC. Do not hold down the pushbutton this time.</li>
<li>Test the firmware update by toggling the CAPS LOCK key on the keyboard to turn the warning buzzer off and on.</li>
</ol>
<h2>Design Files</h2>
<p>All design files are in my <a href="https://github.com/bikerglen/caps-lock-buzzer">caps-lock-buzzer repository on github</a>.</p>
<p>The v2 schematic and board files:</p>
<ul>
<li><a href="https://github.com/bikerglen/caps-lock-buzzer/blob/master/boards/v2/caps-lock-buzzer.sch">Schematic</a></li>
<li><a href="https://github.com/bikerglen/caps-lock-buzzer/blob/master/boards/v2/caps-lock-buzzer.brd">Board</a></li>
</ul>
<p>The Fusion 360 Archive and STL files for the enclosure:</p>
<ul>
<li><a href="https://github.com/bikerglen/caps-lock-buzzer/blob/master/enclosure/v2/caps-lock-buzzer-v2-v5.f3z">Fusion 360 Archive</a></li>
<li><a href="https://github.com/bikerglen/caps-lock-buzzer/blob/master/enclosure/v2/caps-lock-buzzer-v2-top.stl">Enclosure Top STL File</a></li>
<li><a href="https://github.com/bikerglen/caps-lock-buzzer/blob/master/enclosure/v2/caps-lock-buzzer-v2-bottom.stl">Enclosure Bottom STL File</a></li>
</ul>
<p>The updated software:</p>
<ul>
<li><a href="https://github.com/bikerglen/caps-lock-buzzer/blob/master/software/HID_Bootloader_-_PIC16F1459_-_v5.10.zip">PIC16F1459 Bootloader Project</a> for use with this Hardware</li>
<li><a href="https://github.com/bikerglen/caps-lock-buzzer/tree/master/software/caps-lock-buzzer-pic16f1459-btld.X">Caps Lock Buzzer Firmware</a> for use with the Bootloader and this Hardware</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/updates-to-the-annoying-caps-lock-warning-buzzer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Annoying CAPS LOCK Warning Buzzer</title>
		<link>https://bikerglen.com/blog/the-annoying-caps-lock-warning-buzzer/</link>
		<comments>https://bikerglen.com/blog/the-annoying-caps-lock-warning-buzzer/#comments</comments>
		<pubDate>Sun, 15 Sep 2019 16:50:46 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[3D Printing]]></category>
		<category><![CDATA[Microchip]]></category>
		<category><![CDATA[PIC18]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Human Interface Device (HID)]]></category>

		<guid isPermaLink="false">https://bikerglen.com/blog/?p=1395</guid>
		<description><![CDATA[The only way to make CAPS LOCK even more annoying was to make it audible! Now never type a password in all upper case, join 500 lines together in vi, or turn a harmless forum post into an ANGRY SCREED &#8230; <a href="https://bikerglen.com/blog/the-annoying-caps-lock-warning-buzzer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><iframe src="https://www.youtube.com/embed/-V8hzF0jGLM" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe></p>
<p>The only way to make CAPS LOCK even more annoying was to make it audible! Now never type a password in all upper case, join 500 lines together in vi, or turn a harmless forum post into an ANGRY SCREED without warning again! This project uses a PIC16F1459 to monitor the USB output report containing the CAPS LOCK status from the connected PC. When CAPS LOCK is enabled, the PIC turns on an annoying warning buzzer. Read on to build your own.</p>
<p><span id="more-1395"></span></p>
<h2>Motivation</h2>
<div id="attachment_1407" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer.jpg"><img class="size-large wp-image-1407" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer-1024x775.jpg" alt="The completed annoying caps lock warning buzzer." width="640" height="484" /></a><p class="wp-caption-text">The completed annoying caps lock warning buzzer.</p></div>
<p>The CAPS LOCK key is the most annoying key on the keyboard. It&#8217;s always getting in the way. Ever enter a password with CAPS LOCK enabled? Enough times to get locked out of your account? Yeah, me too.</p>
<p>The only way to make CAPS LOCK even more annoying was to make it loud! As a side effect, you&#8217;ll always know when CAPS LOCK is enabled so entering the wrong password, joining lines when you&#8217;re just trying to scroll down in vi, or answering an entire email in ANGRY SCREED format should be history.</p>
<h2>Derived from the One Key USB Keyboard</h2>
<div class="mceTemp">
<div id="attachment_948" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00651_crop2.jpg"><img class="wp-image-948 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00651_crop2-1024x682.jpg" alt="The single ESC key USB keyboard." width="640" height="426" /></a><p class="wp-caption-text">The single ESC key USB keyboard.</p></div>
<p>This project is almost identical to my <a href="https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/">one key USB keyboard</a> project. The key switch and LED have been replaced by a transistor and a buzzer. The enclosure has a round hole instead of a square hole. The software previously turned on an LED when CAPS LOCK was set. Now it uses a different pin to enable the buzzer instead. A few small changes yield an entirely different result. The selecting parts section below is repeated verbatim from that design. Skip forward to the schematic section if you&#8217;ve already read it.</p>
</div>
<h2>Selecting Parts</h2>
<h3>Picking a USB Microcontroller</h3>
<p>I chose a PIC16F1459 in an SSOP-20 package for the microcontroller. The PIC16F145x family provides a minimal parts count solution to implementing the USB 2.0 standard. No external oscillator is required because this micro has an internal 48MHz oscillator and uses active clock tuning to fine-tune the internal oscillator frequency to the recovered clock from the USB host. This micro, a USB connector, and three capacitors are all that are needed to implement a fully-functional USB 2.0 device.</p>
<div id="attachment_930" style="width: 1012px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/min-sch.png"><img class="wp-image-930 size-full" src="https://bikerglen.com/wp/wp-content/uploads/2018/05/min-sch.png" alt="Minimal PIC16F1459 schematic for USB 2.0 operation." width="1002" height="351" /></a><p class="wp-caption-text">Minimal PIC16F1459 schematic for USB 2.0 operation.</p></div>
<p>Once I selected the microcontroller, I needed to pick a package for the microcontroller. The PIC16F1459 is available in DIP, SOIC, SSOP, and QFN packages. I chose the SSOP-20 package. The two larger packages were too big to fit in the allocated board space and the QFN package, though smaller, would be considerably more difficult to hand solder.</p>
<h3>The USB Connector</h3>
<p>Next up was to find a suitable USB Micro-B connector. Since the entire board was to be hand soldered, I wanted a connector with locating pins to position the connector on the board while I soldered it and with enough room between the connector housing and the five signals pins that I could easily see what I was doing with a microscope. I ordered a bunch of USB Micro-B connectors, examined each of them, and finally found a Wurth Electronics connector that met my needs.</p>
<div id="attachment_937" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC_2096_crop.jpg"><img class="wp-image-937 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2018/05/DSC_2096_crop-1024x681.jpg" alt="DSC_2096_crop" width="640" height="426" /></a><p class="wp-caption-text">Wurth Electronics USB Micro-B Receptacle part number 629105136821. It has little black plastic posts to keep the connector centered while soldering and plenty of room between the shell and pins for the soldering iron, flux, solder, and inevitably, wick.</p></div>
<h2>Schematic</h2>
<div id="attachment_1408" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer-schematic.png"><img class="size-large wp-image-1408" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzer-schematic-1024x764.png" alt="Schematic of the annoying caps lock warning buzzer." width="640" height="478" /></a><p class="wp-caption-text">Schematic of the annoying caps lock warning buzzer.</p></div>
<p>Pictured above is the complete schematic for the caps lock buzzer. Let&#8217;s take a closer look at the buzzer, the transistor switch, and programming the PIC16F1459.</p>
<h3>The Buzzer</h3>
<div id="attachment_1410" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzers.jpg"><img class="size-large wp-image-1410" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/buzzers-1024x682.jpg" alt="Buzzer candidates. I went the smallest of the three." width="640" height="426" /></a><p class="wp-caption-text">Buzzer candidates. I went with the smallest of the three.</p></div>
<p>The buzzer needed to run from 5V since that is the USB bus voltage. The current consumption needed to be less than 1 A to prevent overloading the USB bus. I selected a through-hole buzzer to make aligning the buzzer with the board and consequently the hole in the 3D printed enclosure simpler. The final criteria was to select a buzzer that fit in the existing one-key keyboard enclosure without protruding too much. I found a buzzer that ran from 5V, consumed 35 mA, and only protruded out of the existing enclosure design by 0.42 mm. The frequency is 2.7 kHz with an SPL of 80 dBA.</p>
<h3>Designing the Transistor Switch</h3>
<p>The transistor switch circuit is a pretty basic transistor switch circuit. When the PIC drives the PWM0 signal, current flows from the base through the emitter of the transistor. This current turns on the transistor and a current conducts from the positive supply rail, through the buzzer, and from the collector to the emitter of the transistor.</p>
<p>R1 is selected to drive the transistor into the saturation region and to minimize the heat dissipation in the transistor. A 1k resistor usually works well but let&#8217;s calculate the resulting current with a 1k resistor to double check. To calculate the minimum base-emitter current, we need to know the worst-case output voltage at the output of the PIC and the worst-case base-emitter saturation voltage of the transistor.</p>
<p>From the data sheet, the V(OH) of the PIC is V(DD)-0.7 volts and the V(BE)(SAT) of the transistor is 1.0 V. The minimum base-emitter current will be (5 &#8211; 0.7 &#8211; 1.0 V) / (1 k) = 3.3 mA. The current consumption of the selected buzzer is 35 mA and the h(fe) of the transistor is 200. The base current required to drive the transistor into the saturation region is 35 mA / 200 = 0.175 mA.</p>
<p>The transistor will definitely be operating in the saturation region when the PIC turns on the PWM0 output signal. We could use a higher resistor if we want to further minimize the heat dissipation of the transistor but 3.5 mA is much less than the maximum base-emitter current of the transistor and I have a lot of 0805 1k resistors in my parts box.</p>
<p>Diode D1 is present to protect the transistor from the flyback voltage generated by the inductive load of the buzzer when the transistor is switched off. The voltage that is created at the collector of the transistor will be safely sunk to the positive supply rail rather than building up to a level that could potentially destroy the transistor.</p>
<h3>Programming the PIC16F1459</h3>
<div id="attachment_1414" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/IMG_20190310_162519.jpg"><img class="size-large wp-image-1414" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/IMG_20190310_162519-1024x576.jpg" alt="The old way of programming." width="640" height="360" /></a><p class="wp-caption-text">The old way of programming.</p></div>
<p>In previous designs, I&#8217;ve used a row of plated holes designed to make with a six-position, single-row, square-post, 0.1&#8243; pitch header to connect to the PIC programmer and debugger (shown above). This works well but takes up a lot of area on both sides of the board.</p>
<div id="attachment_1412" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/tag-connect.jpg"><img class="wp-image-1412 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/tag-connect-1024x682.jpg" alt="Tag-Connect programming cable connected to the programming pins on the circuit board,." width="640" height="426" /></a><p class="wp-caption-text">The new way: a Tag-Connect programming cable connected to the programming pins on the circuit board.</p></div>
<p>For this design, I&#8217;m using a <a href="http://www.tag-connect.com/">TAG-Connect cable</a> to connect the programmer/debugger to the board (shown above). This uses roughly half the area of the 0.1&#8243; header and only requires holes for three small alignment pins.</p>
<h2>Board</h2>
<div id="attachment_1419" style="width: 857px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/boards1.png"><img class="wp-image-1419 size-full" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/boards1.png" alt="boards" width="847" height="387" /></a><p class="wp-caption-text">A rendering of the boards from OSHPark.com.</p></div>
<p>Shown above is a rendering of the completed board design. The board outline is identical to the board outline of the one-key keyboard board outline. The layout is very similar as well. Note the footprint for the Tag-Connect programming cable to the left of the buzzer on the bottom of the board.</p>
<h2>Software</h2>
<h3>USB Output Reports and the CAPS LOCK State</h3>
<p>The CAPS LOCK state of a keyboard attached to a PC is maintained by the PC; not the keyboard. If you attach five keyboards to a PC and hit the CAPS LOCK key on one keyboard, the CAPS LOCK light on all five attached keyboards will illuminate. You can then hit the CAPS LOCK key on a different keyboard and all the CAPS LOCK lights will turn off.</p>
<p>This is implemented by the connected PC sending a periodic USB output report to all the attached keyboards. Inside this USB output report is a bit indicating the current state of the CAPS LOCK, NUM LOCK, and SCROLL LOCK keys. Attached keyboards examine these bits when the USB output report is received and turn their lights on and off according to these bits.</p>
<p>The annoying caps lock buzzer looks like a keyboard to the host PC except it doesn&#8217;t have any keys. The host sends the periodic USB output reports to our &#8220;keyboard&#8221; and when the USB output report is received, our &#8220;keyboard&#8221; turns the buzzer on or off to match the state of the CAPS LOCK bit in the USB output report.</p>
<h3>Writing the Software</h3>
<p>The software for this design is based on the <a href="https://www.microchip.com/mplab/microchip-libraries-for-applications">Microchip Library for Applications</a> (MLA) USB HID demo for low-pin count PIC micrcontrollers. In the unmodified version of the software, the software turns an LED on or off based on the USB output reports described in the previous section.</p>
<p>To make the annoying caps lock warning buzzer, I only had to change the pin used to turn the LED on or off from the default in the software to pin RC2, disable sending any pressed keys to the host PC, and recompile.</p>
<h2>Initial Bring Up</h2>
<div id="attachment_1424" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/power-supply.jpg"><img class="wp-image-1424 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/power-supply-1024x683.jpg" alt="power-supply" width="640" height="427" /></a><p class="wp-caption-text">One milliamp with an unprogrammed microcontroller and the buzzer turned off is about right. It&#8217;s now safe to connect the buzzer to the PC without worrying about damaging the PC.</p></div>
<p>For the initial bring up and programming, I used a <a href="https://www.keysight.com/us/en/products/dc-power-supplies/bench-power-supplies/e36300-series-triple-output-power-supply-80-160w.html">Keysight 36312A DC power supply</a> and a <a href="http://luislab.com/99-double-banana-plug-to-usb-a">double-banana plug to USB Type A adapter from Luislab</a> (shown above). I set the DC power supply to 5 Volts and set the current limit to 50 mA. This way if I accidentally shorted power to ground while soldering or there was a defect in the board, the power supply would go into current limit mode at a safe limit rather than causing damage to the board or my PC.</p>
<p>The USB Type A ports on a PC are required by the USB spec to have a self-resetting PTC fuse on them to protect the PC against damage if the connected USB device or cable has a short or draws too much current. The trip point for the thermal fuse is 1 A. In theory, I could plug the board into my PC for the initial bring up but the PC&#8217;s USB port is really not designed to limit current. It&#8217;s a safer option for my design and my PC to use a current-limited DC power supply for the initial bring up than to use one of my PC&#8217;s USB ports or a phone charger.</p>
<h2>Measurements</h2>
<h3>Verifying the Transistor Switch is Operating in the Saturation Region</h3>
<div id="attachment_1422" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/IMG_20190915_094831.jpg"><img class="size-large wp-image-1422" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/IMG_20190915_094831-1024x576.jpg" alt="Using my 34461A to measure V(CE)." width="640" height="360" /></a><p class="wp-caption-text">Using my 34461A to measure V(CE).</p></div>
<p>After bringing up the board and programming the microcontroller, I wanted to verify the transistor in the transistor switch was operating its saturation region. To do this, I used a <a href="https://www.keysight.com/en/pdx-2891615-pn-34461A/digital-multimeter-6-digit-truevolt-dmm?cc=US&amp;lc=eng">Keysight 34461A DMM</a> to measure the voltage between the collector and emitter of the transistor while the buzzer was on. The measurement was 4.1515 mV. The transistor is clearly operating in its saturation region. If it had not been, I would have needed to lower the value of R1 to increase the base-emitter current.</p>
<h3>Current Measurements</h3>
<div id="attachment_1513" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/probe.jpg"><img class="size-large wp-image-1513" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/probe-1024x683.jpg" alt="USB current probe board." width="640" height="427" /></a><p class="wp-caption-text">USB current probe board.</p></div>
<p>To measure the current I built a USB current probe board. This board connects the USB D+, D-, and ground lines directly from input to output. The +5V USB power from the PC is brought out to a red banana jack and the +5 power to the target is brought out to a black banana jack. A DMM in current measuring mode can then be connected to the two binding posts and used to measure the current consumption of the USB device.</p>
<div id="attachment_1512" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/on.jpg"><img class="size-large wp-image-1512" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/on-1024x670.jpg" alt="Current measurement with the buzzer on." width="640" height="419" /></a><p class="wp-caption-text">Current measurement with the buzzer on.</p></div>
<p>To measure the current, I connected the USB Type A plug on the current probe board to my PC using a USB extension. I connected the annoying CAPS LOCK warning buzzer to the the USB Type A receptacle on the current probe board using a USB A to Micro B cable. I then connected the banana jacks on the current probe board to the the low range current measurement inputs on my <a href="https://www.keysight.com/en/pdx-2882338-pn-U1272A/handheld-digital-multimeter-4-digit-ip54?cc=US&amp;lc=eng">Keysight U1272A</a> DMM.</p>
<p>With the buzzer off and the annoying CAPS LOCK warning buzzer enumerated on the USB bus on my PC, I measured a current of 8.062 mA. I then engaged CAPS LOCK on my PC and measured the current with the buzzer on. With the buzzer on, I measured a current of 35.64 mA. Both of these numbers are well below the maximum a USB Type A port on a PC can supply and reasonably match the expected values in the data sheets for the PIC16F1459 microcontroller and the buzzer.</p>
<p>(Disclaimer: I work for Keysight. The E36312A was purchased through our employee discount program. The 34461A and U1272A were purchased at full price before my employment there.)</p>
<h2>Enclosure</h2>
<div id="attachment_1429" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/09/enclosure.jpg"><img class="size-large wp-image-1429" src="https://bikerglen.com/wp/wp-content/uploads/2019/09/enclosure-1024x683.jpg" alt="The one-key USB keyboard enclosure modified for the buzzer." width="640" height="427" /></a><p class="wp-caption-text">The one-key USB keyboard enclosure modified for the buzzer.</p></div>
<p>The enclosure for this project is identical to the enclosure for the one-key USB keyboard project except the rectangular cutout has been replaced by a 10 mm diameter circular hole.</p>
<h2>Future Improvements</h2>
<p>I need to place a button and LED on the board and make them accessible from the bottom of the enclosure so that I can implement a USB bootloader for updating the buzzer firmware. I also need to add a <a href="https://www.nexperia.com/products/esd-protection-tvs-filtering-and-signal-conditioning/low-capacitance-esd-protection-for-high-speed-interfaces/PRTR5V0U2X.html">Nexperia PRTR5V0U2X ESD protection diode</a> to the USB D+ and D- data signals.</p>
<p>Breaking Update: The improvements have been made! They&#8217;re described in <a href="https://bikerglen.com/blog/updates-to-the-annoying-caps-lock-warning-buzzer/">this post</a>.</p>
<h2>BOM</h2>
<p>Here&#8217;s the BOM for this project. This BOM is also present in the design files for this project on Github. See the next section for a link.</p>
<table width="994">
<tbody>
<tr>
<td width="42">Line #</td>
<td width="126">Mfr. #</td>
<td width="126">Manufacturer</td>
<td width="508">Description</td>
<td width="70">Order Qty.</td>
<td width="122">Price (USD)</td>
</tr>
<tr>
<td>1</td>
<td>C1206C474K5RACTU</td>
<td>KEMET</td>
<td>50V 0.47uF X7R 1206 10%</td>
<td>1</td>
<td>$0.23</td>
</tr>
<tr>
<td>2</td>
<td>C1210C105K4PACTU</td>
<td>KEMET</td>
<td>16V 1uF X5R 1210 10%</td>
<td>1</td>
<td>$1.26</td>
</tr>
<tr>
<td>3</td>
<td>C1206C104J4RACTU</td>
<td>KEMET</td>
<td>16V 0.1uF X7R 1206 5%</td>
<td>1</td>
<td>$0.56</td>
</tr>
<tr>
<td>4</td>
<td>629105136821</td>
<td>Wurth Elektronik</td>
<td>USB Micro B</td>
<td>1</td>
<td>$1.21</td>
</tr>
<tr>
<td>5</td>
<td>PIC16F1459-I/SS</td>
<td>Microchip</td>
<td>8-bit MCU</td>
<td>1</td>
<td>$1.66</td>
</tr>
<tr>
<td>6</td>
<td>1N4148W-7-F</td>
<td>Diodes Incorporated</td>
<td>General Purpose Diode</td>
<td>1</td>
<td>$0.16</td>
</tr>
<tr>
<td>7</td>
<td>FMMT619TA</td>
<td>Diodes Incorporated</td>
<td>BJT NPN</td>
<td>1</td>
<td>$0.55</td>
</tr>
<tr>
<td>8</td>
<td>CR0805-JW-102ELF</td>
<td>Bourns</td>
<td>0805 1K 5%</td>
<td>1</td>
<td>$0.10</td>
</tr>
<tr>
<td>9</td>
<td>CX-0905C</td>
<td>CUI Inc.</td>
<td>Buzzer</td>
<td>1</td>
<td>$2.43</td>
</tr>
</tbody>
</table>
<h2>Design Files</h2>
<p>All of the design files for this project can be found in the <a href="https://github.com/bikerglen/caps-lock-buzzer">project&#8217;s repository</a> on Github.</p>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/the-annoying-caps-lock-warning-buzzer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Piggybacking USB onto an Industrial Push Button</title>
		<link>https://bikerglen.com/blog/usb-big-red-button/</link>
		<comments>https://bikerglen.com/blog/usb-big-red-button/#comments</comments>
		<pubDate>Wed, 13 Mar 2019 19:08:09 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[3D Printing]]></category>
		<category><![CDATA[Microchip]]></category>
		<category><![CDATA[PIC18]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Human Interface Device (HID)]]></category>

		<guid isPermaLink="false">https://bikerglen.com/blog/?p=963</guid>
		<description><![CDATA[In this project, I mount the electronics from my single-key USB keyboard project to the back of an industrial mushroom push button switch. The finished big red button now activates my screensaver with a single overly-large button press. The biggest &#8230; <a href="https://bikerglen.com/blog/usb-big-red-button/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_966" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105700.jpg"><img class="size-large wp-image-966" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105700-1024x576.jpg" alt="The completed USB-connected big red button." width="640" height="360" /></a><p class="wp-caption-text">The completed USB-connected big red button.</p></div>
<p>In this project, I mount the electronics from my <a href="https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/">single-key USB keyboard</a> project to the back of an industrial mushroom push button switch. The finished big red button now activates my screensaver with a single overly-large button press. The biggest issues in this project were where to mount the USB electronics and how to connect the USB cable between the button and my computer.</p>
<p><span id="more-963"></span></p>
<h2>A Few Words About Industrial Controls</h2>
<p>Industrial push buttons and indicators are the exact opposite of today&#8217;s sleek capacitive touchscreens. They&#8217;re tactile, bulky, single-purpose, take some force to operate, and are built to take abuse from both the environment and users. When a button fails after years of abuse, they&#8217;re modular to facilitate quick repairs and get whatever process they&#8217;re controlling back online quickly. (They do make industrial-rated touchscreen controllers if you really do need to have a touchscreen, e.g., to show / control process parameters.)</p>
<div id="attachment_1038" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/buttons.jpg"><img class="size-large wp-image-1038" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/buttons-1024x669.jpg" alt="Random Omron switch parts including a shrouded red non-illuminated push button, illuminated mushroom button, a mounting collar, LED, NO contacts, illumination unit, NC contacts, and an assembled non-illuminated mushroom button." width="640" height="418" /></a><p class="wp-caption-text">Random Omron switch parts including a shrouded red non-illuminated push button, illuminated mushroom button, a mounting collar, LEDs, NO contacts, illumination unit, NC contacts, and an assembled non-illuminated mushroom button.</p></div>
<p>In the photo above are a few disassembled Omron 22mm push button switches. The typical switch consists of an actuator, a mounting collar or frame, contact blocks, and, if illuminated, an illumination unit. The actuator is the part that mounts to the panel and is exposed to the user. These vary in shape and color often depending on if they&#8217;re designed to be easy to press (emergency power off) or hard to press (start self-destruct sequence).</p>
<p>The part immediately behind the actuator is a frame that connects the contact blocks to the actuator. The contact blocks do the electrical switching and are available in a variety of configurations such as normally open, normally closed, screw terminals, quick connect terminals, etc.</p>
<p>On these Omron controls, the contact blocks snap to the frame and a plunger on the actuator presses a plunger on the contact block to change the state of the contacts. In other designs, they mount using screws. Finally, if the switch is illuminated, there&#8217;s an illumination unit that can hold an LED or incandescent bulb. Below is a page from an <a href="http://www.ia.omron.com/data_pdf/cat/a22n_m22n_a30n_a254-e1_4_5_csm1045427.pdf?id=3443.">Omron Industrial Automation catalog</a> showing some of the available configurations and how they fit together.</p>
<div id="attachment_1022" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/omron-catalog-page1.jpg"><img class="wp-image-1022 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/omron-catalog-page1-724x1024.jpg" alt="" width="640" height="905" /></a><p class="wp-caption-text">A page from the Omron industrial controls catalog.</p></div>
<p>By splitting the switch into so many pieces, the exact switch needed for a job can be built from its component parts. Also repairs can be performed quickly. For example if the actuator is broken, one can disconnect the frame, replace the actuator, reconnect the frame, and be back in business without any rewiring.</p>
<h2>Where to Mount the Electronics</h2>
<p>The immediate goals for this project were (1) to use a big red button and (2) to connect it to a computer using USB. Like any engineering project, there&#8217;s tons of ways to get to a solution and it&#8217;s my job to pick the optimum solution (where optimum is open to debate).</p>
<p>My first thought was to build a small box that had screw terminals for a contact closure input on one side and a USB connector on the other side. This box would sit between the big red button&#8217;s enclosure and the computer. A small circuit board would hold the USB electronics and I&#8217;d 3D print a case for it.</p>
<p>My second thought was to just let a loose circuit board float between the contact blocks inside the big red button&#8217;s enclosure. Things are pretty well insulated so it would be unlikely to short out. But I didn&#8217;t want this thing rattling inside my switch. Then it finally came to me, what if I could mount the electronics to the switch just like a contact block mounts to the switch?</p>
<h2>Mechanical Design</h2>
<div id="attachment_1005" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/lid-and-button.jpg"><img class="size-large wp-image-1005" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/lid-and-button-1024x576.jpg" alt="Raw materials. The lid of the enclosure and pushbutton switch with mushroom operator." width="640" height="360" /></a><p class="wp-caption-text">Raw materials. The lid of the enclosure and pushbutton switch with mushroom operator.</p></div>
<p>Omron Industrial Automation makes some relatively inexpensive industrial push buttons that are available from the usual distributors. They also make a nice bright yellow enclosure specifically for emergency stop / emergency power off / big red button mushroom switches. I went to Digi-Key and ordered an Omron A22NN-BMM-NRA-G100-NN mushroom switch for $10.97 and to Arrow and ordered an OmronA22NZ-A-B01Y single button enclosure for $12.74. These are shown in the photo above.</p>
<div id="attachment_994" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/A22NZ_S_G1A-v1.png"><img class="wp-image-994 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/A22NZ_S_G1A-v1-1024x709.png" alt="Stock Omron Contact Block 3D Model." width="640" height="443" /></a><p class="wp-caption-text">The stock Omron normally open contact block 3D model with a bit of additional color.</p></div>
<p>I needed a starting point for my PCB holder. Fortunately, Omron and most of the other industrial controls vendors publish 3D models of their devices. These models are primarily used during design of industrial control panels to make sure everything fits without interference. I downloaded Omron&#8217;s 3D model of their contact block, shown above, then used Fusion 360 to carve out an area to hold a small PCB. This most likely violates Omron&#8217;s terms of use for their models but since this is a one-off, personal, non-commercial project (aka a hack), I&#8217;m going to call it fair use and not lose any sleep over it.</p>
<div id="attachment_1001" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/contact-block-clip-in-board-knubs-v2-b.png"><img class="size-large wp-image-1001" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/contact-block-clip-in-board-knubs-v2-b-1024x709.png" alt="A render of the contact block circuit board holder and circuit board. Sometimes renders don't work out in real life." width="640" height="443" /></a><p class="wp-caption-text">A render of the contact block circuit board holder and circuit board. Sometimes renders don&#8217;t work out in real life.</p></div>
<p>With a bit of work, I carved out an area to hold the circuit board, fit the board into the model, and added some tabs to hold the board in place without screws. Be sure to scrape off the switch plunger too otherwise you&#8217;ll end up with a fixed piece of plastic on top of the contact block frame that blocks the operation of the button.</p>
<div id="attachment_1004" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/failures.jpg"><img class="size-large wp-image-1004" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/failures-1024x576.jpg" alt="Failure is good as long as you learn from it, right?" width="640" height="360" /></a><p class="wp-caption-text">Failure is good as long as you learn from it, right?</p></div>
<p>This design took a few iterations to get right. I printed the PCB holder in different materials at different 3D printing places. The SLS PA nylon process at Shapeways had different dimensions than the SLS PA nylon process at Sculpteo. The HP JetFusion process at Sculpteo had different dimensions than the SLS PA nylon process at Sculpteo. In addition, the HP JetFusion nylon is more brittle / less flexible than the SLS PA nylon. I finally got a print of a holder that would work in the SLS PA nylon process from Sculpteo.</p>
<div id="attachment_997" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/boards.jpg"><img class="size-large wp-image-997" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/boards-1024x464.jpg" alt="Three failed boards and one good board. Fails: 1) screws rather than tabs. 2) header strip hits holder. 3) slots too small to accommodate tabs. Success: slots and header strip work!" width="640" height="290" /></a><p class="wp-caption-text">Three failed boards and one good board. Fails: 1) screws rather than tabs. 2) header strip hits holder. 3) slots too small to accommodate tabs. Success: slots and header strip work!</p></div>
<p>Unfortunately, I broke the tabs off the holder trying to fit the circuit board into the holder. Rather than redesign the holder, I redesigned the circuit board to have slightly bigger notches that wouldn&#8217;t stress the tabs as much during insertion. I went through a total of four revisions of the circuit board. The post office even lost two revisions of the boards for two weeks before finally finding them and delivering them.</p>
<div id="attachment_986" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_104835.jpg"><img class="size-large wp-image-986" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_104835-1024x576.jpg" alt="The finished circuit board and 3D printed holder next to the back parts of an Omron switch." width="640" height="360" /></a><p class="wp-caption-text">The finished circuit board and 3D printed holder next to the back parts of an Omron switch.</p></div>
<p>Success. After many more weeks and iterations than it should have taken, I finally got things right. With a bit of finesse and luck, I was able to place the finished circuit board into the 3D printed holder. I didn&#8217;t test the electronics before putting the board in the holder. Luckily, they did work.</p>
<p>Finally, I did a bit of assembly in Fusion 360 to see if there was any hope of a USB cable mating with the USB connector on the PCB. I couldn&#8217;t get section analysis to work in the render view of Fusion 360 so I just lopped the bottom of the enclosure off for the render.</p>
<div id="attachment_1019" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/A22NZ_A_B01Y-v6-b.jpg"><img class="wp-image-1019 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/A22NZ_A_B01Y-v6-b-1024x709.jpg" alt="" width="640" height="443" /></a><p class="wp-caption-text">Will a USB cable connect to the board inside the enclosure? That&#8217;s a definite maybe.</p></div>
<h2>Electrical Design</h2>
<div id="attachment_987" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105314.jpg"><img class="wp-image-987 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105314-1024x576.jpg" alt="Board assembled into holder. i had access to isopropyl alchohol and lint-free cleaning swabs so the board is a bit cleaner than my usual boards." width="640" height="360" /></a><p class="wp-caption-text">Board assembled into holder. I had access to isopropyl alcohol and lint-free cleaning swabs during assembly so the board is a bit cleaner than my usual boards.</p></div>
<p>The electrical design on this project was easy. It&#8217;s the same electronics as on the <a href="https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/">single-key USB keyboard</a> project except I added a Texas Instruments TPD2E2U06QDBZRQ1 ESD protection device to the USB data lines and replaced the Cherry MX keyboard switch with a two pin 0.1&#8243; right angle header. Next time I might try a Nexperia PRTR5V0U2X that can protect both the USB power line and USB data lines.</p>
<h2>Software Design</h2>
<div id="attachment_1007" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190310_162519.jpg"><img class="size-large wp-image-1007" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190310_162519-1024x576.jpg" alt="Programming the bootloader is a bit of a pain but thankfully it only has to be done once." width="640" height="360" /></a><p class="wp-caption-text">Programming the bootloader is a bit of a pain but thankfully it only has to be done once.</p></div>
<p>The software is divided into two parts, a bootloader and the application software. These are the same as on the <a href="https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/">single-key USB keyboard</a> project too. The USB bootloader is programmed into the part using any PIC programmer such as a REAL ICE or MPLAB ICD 4. It&#8217;s a bit awkward holding the programmer adapter on the board as shown in the photo above but it only has to be done once. The bootloader then enables the application software to be updated over USB without disassembling the completed project.</p>
<p>Once the bootloader is programmed, the application software may be updated by holding down the big red button while connecting the USB cable to the computer. This action enables the bootloader then the bootloader utility from the Microchip Libaries for Applications may be run to load new application software onto the PIC16F1459.</p>
<p>Currently I have two versions of the application software. One inserts a poop emoji into Microsoft documents. The other hits right-ctrl to escape Oracle&#8217;s VirtualBox&#8217;s keyboard capture then left-ctrl &amp; left-alt &amp; l to invoke the RHEL screensaver / screen lock on my Linux box at work.</p>
<h2>Final Touches</h2>
<p>Now the only thing left to do was to assemble everything. It took a bit of finesse to get the board mounted into the holder without breaking anything.</p>
<div id="attachment_987" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105314.jpg"><img class="size-large wp-image-987" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105314-1024x576.jpg" alt="Board assembled into holder." width="640" height="360" /></a><p class="wp-caption-text">Board assembled into holder.</p></div>
<p>Next was a dry fit test of the assembled push button.</p>
<div id="attachment_1033" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/dry-fit.jpg"><img class="size-large wp-image-1033" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/dry-fit-1024x683.jpg" alt="Yep, everything fits!" width="640" height="427" /></a><p class="wp-caption-text">Yep, everything fits!</p></div>
<p>I used some jumper wires with a two position 0.1&#8243; socket header attached to connect the contact block to the circuit board.</p>
<div id="attachment_986" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_104835.jpg"><img class="size-large wp-image-986" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_104835-1024x576.jpg" alt="The finished circuit board and 3D printed holder next to the back parts of an Omron switch." width="640" height="360" /></a><p class="wp-caption-text">The finished circuit board and 3D printed holder next to the back parts of an Omron switch.</p></div>
<p>Then I snapped the contact block and holder into place on the switch frame and mounted the switch frame to the actuator. Sliding the little yellow lever below the USB cable locks the frame to the actuator.</p>
<div id="attachment_988" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105452.jpg"><img class="wp-image-988 size-large" title="Assembled Switch and USB Board" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105452-1024x576.jpg" alt="IMG_20190224_105452" width="640" height="360" /></a><p class="wp-caption-text">Here&#8217;s a view with everything assembled and mounted to the top half of the enclosure.</p></div>
<p>And voila! The finished project!</p>
<div id="attachment_966" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105700.jpg"><img class="size-large wp-image-966" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190224_105700-1024x576.jpg" alt="The completed USB-connected big red button." width="640" height="360" /></a><p class="wp-caption-text">The completed USB-connected big red button.</p></div>
<h2>Design Files</h2>
<p>If you&#8217;re interested in the mechanical design files for the project, let me know via Twitter and I&#8217;ll post them to github. In the meantime, check out the software and schematic for my single-key keyboards on <a href="https://github.com/bikerglen/small-keyboards">github</a>.</p>
<h2>An Important Safety Note</h2>
<p>As fun as this project may have been, please do NOT use USB for an actual safety-related emergency stop or emergency power off. USB is just not reliable enough for safety-related devices.</p>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/usb-big-red-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenting the Single ESC Key USB Keyboard!</title>
		<link>https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/</link>
		<comments>https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/#comments</comments>
		<pubDate>Tue, 15 May 2018 20:51:25 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[3D Printing]]></category>
		<category><![CDATA[Microchip]]></category>
		<category><![CDATA[PIC18]]></category>
		<category><![CDATA[USB]]></category>
		<category><![CDATA[USB Human Interface Device (HID)]]></category>

		<guid isPermaLink="false">http://bikerglen.com/blog/?p=878</guid>
		<description><![CDATA[After building the “awesomely impractical” giant three-key keyboard, I decided it was time to build something a bit more practical—presenting the single ESC key USB keyboard! This keyboard has exactly one function which is to provide an optimal ESCing experience &#8230; <a href="https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_948" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00651_crop2.jpg"><img class="size-large wp-image-948" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00651_crop2-1024x682.jpg" alt="The single ESC key USB keyboard." width="640" height="426" /></a><p class="wp-caption-text">The single ESC key USB keyboard.</p></div>
<p>After building the “<a href="https://blog.hackster.io/ginormous-3-switch-keyboard-is-awesomely-impractical-748b79e471b3">awesomely impractical</a>” giant <a href="http://bikerglen.com/blog/building-a-giant-usb-three-key-mechanical-keyboard/">three-key keyboard</a>, I decided it was time to build something a bit more practical—presenting the single ESC key USB keyboard! This keyboard has exactly one function which is to provide an optimal ESCing experience regardless of whatever keyboard you normally use. In exchange for giving up a USB port, you get a dedicated tactile, clicky Cherry MX blue ESC key.</p>
<p><span id="more-878"></span></p>
<p>The only possible target demographics for this keyboard are vi/vim users on touch strip MacBooks or those who like wasting USB ports on needless functions. On the slightly more practical side, there’s a three-key version too. With a bit of programming, these three keys can be assigned whatever functions are needed. On mine, the first key does CTRL-ALT-DEL, the second key locks the screen (META-L), and the third key is an escape key.</p>
<div id="attachment_949" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00658_crop.jpg"><img class="wp-image-949 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00658_crop-1024x683.jpg" alt="The three key USB keyboard." width="640" height="427" /></a><p class="wp-caption-text">The three key USB keyboard. The LEDs underneath the keycaps are really only useful for debugging.</p></div>
<h2>Goals</h2>
<p>The only real goal with this keyboard was to see how small I could build a functional USB keyboard with a Cherry MX key switch. The keyboard needed to have an enclosure and the enclosure needed to be easy to assemble and disassemble which meant using screws to hold it together versus snapping together.</p>
<h2>Selecting Parts</h2>
<h3>Picking a USB Microcontroller</h3>
<p>I chose a PIC16F1459 in an SSOP-20 package for the microcontroller. The PIC16F145x family provides a minimal parts count solution to implementing the USB 2.0 standard. No external oscillator is required because this micro has an internal 48MHz oscillator and uses active clock tuning to fine-tune the internal oscillator frequency to the recovered clock from the USB host. This micro, a USB connector, and three capacitors are all that are needed to implement a fully-functional USB 2.0 device.</p>
<div id="attachment_930" style="width: 1012px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/min-sch.png"><img class="size-full wp-image-930" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/min-sch.png" alt="Minimal PIC16F1459 schematic for USB 2.0 operation." width="1002" height="351" /></a><p class="wp-caption-text">Minimal PIC16F1459 schematic for USB 2.0 operation.</p></div>
<p>Once I selected the microcontroller, I needed to pick a package for the microcontroller. The PIC16F1459 is available in DIP, SOIC, SSOP, and QFN packages. I chose the SSOP-20 package. The two larger packages were too big to fit in the allocated board space and the QFN package, though smaller, would be considerably more difficult to hand solder.</p>
<h3>The USB Connector</h3>
<p>Next up was to find a suitable USB Micro-B connector. Since the entire board was to be hand soldered, I wanted a connector with locating pins to position the connector on the board while I soldered it and with enough room between the connector housing and the five signals pins that I could easily see what I was doing with a microscope. I ordered a bunch of USB Micro-B connectors, examined each of them, and finally found a Wurth Electronics connector that met my needs.</p>
<div id="attachment_937" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC_2096_crop.jpg"><img class="wp-image-937 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC_2096_crop-1024x681.jpg" alt="DSC_2096_crop" width="640" height="426" /></a><p class="wp-caption-text">Wurth Electronics USB Micro-B Receptacle part number 629105136821. It has little black plastic posts to keep the connector centered while soldering and plenty of room between the shell and pins for the soldering iron, flux, solder, and inevitably, wick.</p></div>
<h3>The Other Electrical Components</h3>
<p>The rest of the electrical components weren&#8217;t super critical—a 0.47uF capacitor on the VUSB pin, a 0.1uF capacitor on the VDD pin, 1uF of bulk capacitance on the board, an LED, and a resistor. I used 1206 packages for the caps and resistor and a 3528 package for the LED because these were parts I had on hand.</p>
<div id="attachment_932" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/final-sch.png"><img class="size-large wp-image-932" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/final-sch-1024x264.png" alt="Complete one key USB keyboard schematic." width="640" height="165" /></a><p class="wp-caption-text">Complete one key USB keyboard schematic.</p></div>
<h2>The PCB</h2>
<p>Cherry MX key switches nominally occupy a 3/4” by 3/4” square area on the PCB. I decided to try to make the PCB 1” by 1”. It would have to be double sided with the key switch and LED on one side and the rest of the components on the other.</p>
<p>I drew a 1” x 1” board outline with 0.05” radius corners then placed a 0.1” diameter hole in each of the four corners. The holes are 0.1” from the edges of the board. I also tried to keep a 0.2” square keep out in each corner, but I ended up putting one cap, C2, a bit closer to the hole than I should have. The board turned out fine, but it significantly complicated the design of the enclosure. More on that later.</p>
<p>I found Eagle PCB libraries for the PIC, the USB connector, and the Cherry MX key switch. Links to these are in the Useful Resources section at the end of the blog post. I placed these components, wired everything up, made the gerbers, and ordered boards.</p>
<div id="attachment_926" style="width: 1017px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/one-key-top-and-bottom.png"><img class="size-full wp-image-926" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/one-key-top-and-bottom.png" alt="One key USB right keyboard PCB top and bottom views." width="1007" height="501" /></a><p class="wp-caption-text">One key USB right keyboard PCB top and bottom views.</p></div>
<h2>The Enclosure</h2>
<p>While the boards were being manufactured, I turned to the design of the enclosure.</p>
<h3>PCB 3D Model</h3>
<p>The first step was to use ecad.io to turn my PCB design into a 3D model that I could use to test the fit of the enclosure.</p>
<div id="attachment_911" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/one-key-model.png"><img class="size-large wp-image-911" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/one-key-model-1024x733.png" alt="3D model of the PCB." width="640" height="458" /></a><p class="wp-caption-text">3D model of the PCB.</p></div>
<h3>Critical Dimensions</h3>
<p>The second step was to gather a list of critical dimensions. These are based on past experience and reading specs:</p>
<ul>
<li>Wall thickness: 1.5mm.</li>
<li>Space between PCB edges and walls: 0.5mm.</li>
<li>Board thickness: 1.6mm but allow 1.65mm.</li>
<li>2-56 screw free fit hole diameter: 2.54mm.</li>
<li>2-56 screw countersink diameter and angle: 5.30mm and 82 degrees.</li>
<li>2-56 nut cavity: 5mm across flats, 2mm deep.</li>
<li>Maximum USB Micro-B overmold dimensions: 10.6 by 8.5mm.</li>
<li>Minimum USB Micro-B mated clearance: 1.3mm</li>
<li>3D printer minimum wall thickness: 0.6mm, ideally 1mm.</li>
</ul>
<h3>Enclosure Bottom</h3>
<p>I started with the enclosure bottom. The PCB is 25.4mm x 25.4mm so the enclosure needed to be 29.4mm x 29.4mm to allow for the 1.5mm wall thickness and 0.5mm space around the board edges. I added screw holes and recesses for the nuts on underside of the bottom of the enclosure.</p>
<div id="attachment_913" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosre-bottom-2.png"><img class="wp-image-913 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosre-bottom-2-1024x682.png" alt="enclosre bottom 2" width="640" height="426" /></a><p class="wp-caption-text">Enclosure bottom (exterior view).</p></div>
<div id="attachment_912" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosre-bottom.png"><img class="wp-image-912 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosre-bottom-1024x682.png" alt="Enclosure Bottom" width="640" height="426" /></a><p class="wp-caption-text">Enclosure bottom (interior view).</p></div>
<p>Here I hit the first snag. I needed at least 0.6mm and, ideally, 1mm of material around the top and sides of the hex nut recesses on the bottom of the enclosure to meet my 3D printer&#8217;s minimum wall specs. If I added this material all the way to the top of the enclosure, it would have necessitated a 6mm square keepout area in each corner of the PCB. Unfortunately capacitor C2 was already in this keepout area (see illustration below).</p>
<p>Since C2 was in the way, I only brought the material up 1.5 mm from the interior of the enclosure (which is 3mm from the exterior of the enclosure). This left a 1mm wall between the top of the nut recess and the interior of the enclosure. This was was within specs for printing and provided plenty of clearance for C2. Problem solved but next time I would have tried to move the capacitor over a bit on the PCB!</p>
<div id="attachment_905" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/nut-recess-clearance.png"><img class="size-large wp-image-905" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/nut-recess-clearance-1024x666.png" alt="C2 is in the upper left hand corner. Dark blue is a face of the 6mm x 6mm cube around the nut recess. Light blue is the nut recess. The arrow indicates the 1mm wall thickness between the cube face and nut recess." width="640" height="416" /></a><p class="wp-caption-text">C2 is in the upper left hand corner. Dark blue is a face of the 6mm x 6mm cube around the nut recess. Light blue is the nut recess. The arrow indicates the 1mm wall thickness between the cube face and nut recess.</p></div>
<p>The second snag involved the the overall height of the enclosure. Initially the bottom was 5mm high making the enclosure 11.65mm high overall. I planned on using 7/16&#8243; screws to assemble the enclosure. Unfortunately, my 7/16” screws were 0.020” short and barely reached the nuts. Also, the maximum USB plug overmold thickness is 8.5mm so for thick USB plugs the keyboard could be resting on the bottom of the USB plug versus resting on its own bottom.</p>
<p>Increasing the bottom height to 6.05mm and the overall enclosure height to 12.7mm solved both these issues. First, I could use 0.5” screws to assemble everything which more than adequately reached the recessed nuts. Second, this increased the distance from the center of the USB receptacle to the bottom of the housing to 4.7mm which is greater than the 4.25mm required by the USB Micro-B max overmold dimension specification.</p>
<div id="attachment_907" style="width: 838px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/overmold-clearance.png"><img class="size-full wp-image-907" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/overmold-clearance.png" alt="6.05 mm bottom height meets 4.25mm USB overmold clearance requirement." width="828" height="439" /></a><p class="wp-caption-text">6.05 mm bottom height meets 4.25mm USB overmold clearance requirement.</p></div>
<p>The last critical dimension is the minimum mated clearance of a USB Micro-B receptacle and USB Micro-B plug. This dimension is listed as 1.3mm in the USB Micro-B connector specification. When a USB cable is plugged into the connector on the USB keyboard, they need to be fully mated. In order to support this requirement, the distance from the exterior face of the enclosure to the metal guides on the USB receptacle needs to be less than 1.3mm. In my design, they&#8217;re 0.7mm which will work.</p>
<div id="attachment_909" style="width: 889px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/mated-clearance.png"><img class="wp-image-909 size-full" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/mated-clearance.png" alt="0.7mm clearance between receptacle guides and exterior face of enclosure." width="879" height="714" /></a><p class="wp-caption-text">0.7mm clearance between receptacle guides and exterior face of enclosure.</p></div>
<h3>Enclosure Top</h3>
<div id="attachment_916" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosure-top-2.png"><img class="wp-image-916 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosure-top-2-1024x683.png" alt="enclosure top 2" width="640" height="427" /></a><p class="wp-caption-text">Enclosure top (exterior view).</p></div>
<div id="attachment_915" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosure-top-1.png"><img class="wp-image-915 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/enclosure-top-1-1024x682.png" alt="enclosure top 1" width="640" height="426" /></a><p class="wp-caption-text">Enclosure top (interior view).</p></div>
<p>The enclosure top was significantly less challenging to design. The height needed to be the board height (1.65mm) plus the height to the bottom of the depressed key cap (about 5mm). I drew the exterior walls of the enclosure, added some cylinders around the screws, drew the countersink holes, cut out a square for the key switch, and added a bit of a notch around the USB connector. The cylinders are 1.65mm shorter than the enclosure so that the board fits completely recessed into the top of the enclosure.</p>
<div id="attachment_918" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/recessed-board.png"><img class="size-large wp-image-918" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/recessed-board-1024x682.png" alt="PCB fits recessed into the bottom of the top half of the enclosure." width="640" height="426" /></a><p class="wp-caption-text">PCB fits recessed into the bottom of the top half of the enclosure.</p></div>
<h3>Manufacturing the Enclosure</h3>
<p>I still don&#8217;t own a 3D printer. Instead, I opted to have my enclosures 3D printed at a service bureau on a selective laser sintering (SLS) 3D printer in black PA12 nylon. They turned out great. 3D prints on these machines are accurate and consistent from print to print.</p>
<h2>Three Key Stretch</h2>
<p>The three key version of the keyboard is a stretch of the one key version of the keyboard.</p>
<h3>PCB</h3>
<div id="attachment_928" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/3keypcb.png"><img class="size-large wp-image-928" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/3keypcb-1024x824.png" alt="Three key USB keyboard PCB top and bottom views." width="640" height="515" /></a><p class="wp-caption-text">Three key USB keyboard PCB top and bottom views.</p></div>
<h3>Enclosure</h3>
<div id="attachment_920" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/three-key-enclosure-rear.png"><img class="size-large wp-image-920" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/three-key-enclosure-rear-1024x683.png" alt="Rear view of the three key enclosure." width="640" height="427" /></a><p class="wp-caption-text">Rear view of the three key enclosure.</p></div>
<h2>Building the Keyboard</h2>
<div id="attachment_951" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00674_crop.jpg"><img class="wp-image-951 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00674_crop-1024x682.jpg" alt="DSC00674_crop" width="640" height="426" /></a><p class="wp-caption-text">Three variations of the small USB keyboards: single key with USB top, single key with USB right and optional LED and light pipe, and finally the three key version.</p></div>
<p>The keyboard has three variations:</p>
<ol>
<li>Single key with USB top. There&#8217;s a hidden red LED on the right hand side of the key.</li>
<li>Single key with USB right. There&#8217;s an LED on the top side of the key. Whether to expose the LED, keep the LED hidden, or use a light pipe to direct the LED light is up to you.</li>
<li>Three key with USB top. This board has a provision for a 3MM through-hole LED under each key. These three LEDs really don&#8217;t add much to the project but having them to indicate the USB status is helpful when bringing up the board.</li>
</ol>
<p>To build the keyboard, pick one of three basic variations then select the the PCB, enclosure, parts, and software for your board from the downloads section below. The one key USB right and one key USB top keyboards use the same 3D printed enclosure. To program the microcontroller, you need a PIC programmer such as a PICkit, ICD, or Real ICE.</p>
<div id="attachment_943" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00650.jpg"><img class="size-large wp-image-943" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00650-1024x683.jpg" alt="The parts and pieces required to build the single-key keyboard." width="640" height="427" /></a><p class="wp-caption-text">The parts and pieces required to build the single-key keyboard.</p></div>
<p>When assembling the PCB, I recommend soldering the USB connector first then soldering the PIC16F1459 next. After those two parts are soldered to the board, check the pins and traces for solder bridges very carefully then move on to soldering the rest of the surface mount components. Lastly, solder the Cherry MX key switch to the board. Do not solder a connector to the programming header on the PCB.</p>
<p>To program the micro, open the project in MPLAB X. Build the project. Connect the keyboard and programmer to USB ports on the PC. Finally program the micro while holding the programmer&#8217;s connector and a header in the holes of the programming of the header on the PCB.</p>
<p>When programming is complete, the red LED should flash quickly and the keyboard should begin working immediately. If it doesn&#8217;t, the most likely issue is solder bridges between the pins of the USB connector or PIC. To change what the key does, modify the key codes sent by the software on lines 359 to 372 of the function <span class="pl-en">APP_KeyboardTasks</span> in the file app_device_keyboard.c.</p>
<p>Once you&#8217;re happy with the operation of the keyboard, unplug it and assemble the case around the PCB. Finally, select a key cap and place the key cap on the key switch.</p>
<h2>More Photos</h2>
<p>Here are a few more photos.</p>
<div id="attachment_954" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00678_crop.jpg"><img class="size-large wp-image-954" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00678_crop-1024x683.jpg" alt="One key with USB top." width="640" height="427" /></a><p class="wp-caption-text">One key with USB top.</p></div>
<div id="attachment_953" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00680_crop.jpg"><img class="size-large wp-image-953" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00680_crop-1024x683.jpg" alt="Three key." width="640" height="427" /></a><p class="wp-caption-text">Three key.</p></div>
<div id="attachment_955" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00679_crop.jpg"><img class="size-large wp-image-955" src="http://bikerglen.com/wp/wp-content/uploads/2018/05/DSC00679_crop-1024x683.jpg" alt="One key USB right with optional LED and light pipe." width="640" height="427" /></a><p class="wp-caption-text">One key USB right with optional LED and light pipe.</p></div>
<p>Have fun! I hope you enjoyed this project!</p>
<h2>Downloads</h2>
<h3>PCB</h3>
<p>Pick one of the following PCB designs depending on which version of the keyboard you’d like to make. These link to directories on github containing both Eagle PCB files for modifying and Gerbers for manufacturing:</p>
<ul>
<li><a href="https://github.com/bikerglen/small-keyboards/tree/master/boards/one%20key%20usb%20right">Single key version with USB port on the right side</a></li>
<li><a href="https://github.com/bikerglen/small-keyboards/tree/master/boards/one%20key%20usb%20top">Single key version with USB port on the top</a></li>
<li><a href="https://github.com/bikerglen/small-keyboards/tree/master/boards/three%20key%20usb%20top">Three key version with USB port on the top</a></li>
</ul>
<h3>Enclosure</h3>
<p>Pick an enclosure to match the selected PCB. The single-key USB right and single-key USB top keyboards both use the same single-key enclosure. These link to directories on github containing both STEP files for modifying and STL files for printing:</p>
<ul>
<li><a href="https://github.com/bikerglen/small-keyboards/tree/master/enclosures/one%20key%20by%20half%20inch">Single key version for use with 2-56 x 1/2” screws</a></li>
<li><a href="https://github.com/bikerglen/small-keyboards/tree/master/enclosures/one%20key%20by%20short">Single key version for use with 2-56 x 7/16” screws</a> (not recommended, see note below)</li>
<li><a href="https://github.com/bikerglen/small-keyboards/tree/master/enclosures/three%20key%20by%20half%20inch">Three key version for use with 2-56 x 1/2” screws</a></li>
</ul>
<p>Note: the 7/16&#8243; screws I ordered from McMaster-Carr were approximately 0.020” short of 7/16”. They worked but it took some finagling to get the screw threads to catch the nuts. For this reason, I’d recommend the 1/2” version of the enclosure. Also 2-56 x 1/2” screws are much more common, easier to find, and less expensive than 2-56 x 7/16” screws.</p>
<h3>Software</h3>
<p>Pick a software version. All software versions support from one to three keys. The default configuration is for key 1 to type an <em>a</em>, key 2 to type a <em>b</em>, and key 3 to type a <em>c</em>. The Non-USB bootloader version is the easiest to work with but it gets old disassembling and re-assembling the keyboard to update the firmware. If you select the USB bootloader version, you will also need the USB bootloader and the Microchip USB hex bootloader app.</p>
<p>These link to directories on github containing both the MPLAB X projects and pre-built .hex files that may be directly programmed into the part without opening or building the projects:</p>
<ul>
<li><a href="https://github.com/bikerglen/small-keyboards/tree/master/software/tkk-pic16f1459.X">Non-USB bootloader version</a>. Requires disassembling keyboard to update firmware.</li>
<li>USB bootloader version. After bootloader is programmed, firmware may be updated over USB without disassembling keyboard.</li>
<li>USB bootloader. Bootloader for the USB bootloader version of the keyboard software.</li>
</ul>
<p>If you selected the USB bootloader version, you’ll also need the Microchip USB hex bootloader app. This app is distributed as part of the Microchip Library for Applications (MLA) and may be downloaded <a href="http://www.microchip.com/mplab/microchip-libraries-for-applications">here.</a></p>
<h2>Bill of Materials</h2>
<h3>Electrical Parts</h3>
<p>Part numbers in parenthesis are <a href="https://www.digikey.com/">Digi-Key</a> part numbers. Part numbers in brackets are <a href="https://www.mouser.com/">Mouser</a> part numbers.</p>
<ul>
<li>N=1 PIC16F1459-I/SS USB microcontroller. Microchip part # PIC16F1459-I/SS (PIC16F1459-I/SS-ND)</li>
<li>N=1 USB Micro-B PCB mount jack. Wurth part # 629105136821 (732-3155-1-ND)</li>
<li>N=1 0.47µF 50V 1206 capacitor. Similar capacitors with voltage ratings down to 16V may be substituted. Kemet # C1206C474K5RACTU (399-3498-1-ND)</li>
<li>N=1 0.1µF 50V 1206 capacitor. Similar capacitors with voltage ratings down to 16V may be substituted. Kemet # C1206C104K5RAC7867 (399-1249-1-ND)</li>
<li>N=1 1µF 16V 1206 capacitor. Similar capacitors may be substituted. Kemet # C1210C105K4PACTU [80-C1210C105K4P]</li>
<li>N=1  or N=3 Cherry MX blue key switch or similar. Cherry # MX1A-E1NW (CH197-ND)</li>
<li>N=1 or N=3 1kΩ 1206 resistors depending on if you selected the single key or three version of the keyboard. (optional, only needed if you add LEDs to your keyboard) Bourns # CR1206-JW-102ELF (CR1206-JW-102ELFCT-ND)</li>
<li>N=1 Red 3528 surface mount LED (optional, for the single key version of the keyboard). Kingbright # AA3528ES (754-1531-1-ND)</li>
<li>N=3 Red 3mm through hole LED (optional, for the three key version of the keyboard). Kingbright # WP710A10ID (754-1606-ND)</li>
</ul>
<h3>Mechanical Parts</h3>
<ul>
<li>N=4 2-56 x 1/2” or 7/16” black oxide socket cap flat head screws. McMaster-Carr part # 91253A081 (1/2”) or 91253A080 (7/16”) depending on the version of the enclosure selected above.</li>
<li>N=4 2-56 black oxide hex nuts. McMaster-Carr part #96537A110.</li>
<li>An assortment of Cherry MX compatible key caps. I ordered mine from <a href="http://www.maxkeyboard.com/products/cherry-mx-keycap/backlight-novelty-keycap/">Max Keyboard</a>.</li>
</ul>
<h3>Challenge Parts</h3>
<p>The single key version with USB port on the right side contains a single red LED above the key switch. A suggested challenge would be to open a hole in the enclosure and use a light pipe to pipe the LED’s light to the top of the enclosure. If you want to attempt this challenge, I recommend Visual Communications Company’s round 3mm x .125” diffuse light pipe, part # LFB012CTP (LFB012CTP-ND at Digi-Key). A possible solution to this challenge is located <a href="https://github.com/bikerglen/small-keyboards/tree/master/enclosures/top%20with%20light%20pipe%20opening">here</a>.</p>
<h2>Useful Resources</h2>
<p>Here is a list of resources I found useful during the construction of this project:</p>
<ul>
<li>SparkFun Cherry MX Eagle PCB <a href="https://github.com/sparkfun/SparkFun-Eagle-Libraries/blob/master/SparkFun-Switches.lbr">footprint</a>.</li>
<li>PIC16F1459-I/SS Eagle PCB <a href="http://digikey.ultralibrarian.com/?customers=RycPF1rrFAfHhx1FKbDMvyIhfAaVpfojYtrMkEWUzmMQdSfcVO7y%2blSpZPdVwobWTDvUSYygHvldEcommnlKY74M1oqx1amo9RHpyTg76aUim0tW8Ixasn2vKKgF2HxKUqAC9sXJVfIVyvnE2QxaAMefuQ97QukV0%2bx2GaAAxXHaw2RROBbtuzW8EoEJ8BRB6maVzCgLHexQO7mi4z8iPKxQyioAUo3ABSeiKMMsjE4DYwGW8SRk4qw2NtZx8cG%2fo1HtREBRFClZPrpxKvuPhMjIDjuW%2bDQrnAnzjzaiol2T3xYDM4m6c0PpWtamCw9D30myp3N%2brt%2bnBANG7Gkl3g%3d%3d&amp;parts=PIC16F1459-I%2fSS-ND&amp;submit">footprint</a>.</li>
<li>Wurth part 629105136821 <a href="http://katalog.we-online.de/en/em/COM_MICRO_SMT_TYPE_B_HORIZONTAL/629105136821?m=n&amp;sp=http%3A%2F%2Fwww.we-online.com%2Fweb%2Fen%2Fwuerth_elektronik%2Fsearchpage.php%3Fsearch%3D629105136821">Eagle PCB footprint and STEP 3D model</a>.</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/presenting-the-single-esc-key-usb-keyboard/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
