<?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; Fusion 360</title>
	<atom:link href="https://bikerglen.com/blog/category/3d-cadcam/fusion-360/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>Homebrew DMX-Controlled RGB LED Light</title>
		<link>https://bikerglen.com/blog/homebrew-rgb-led-light/</link>
		<comments>https://bikerglen.com/blog/homebrew-rgb-led-light/#comments</comments>
		<pubDate>Sat, 13 Apr 2019 01:28:29 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[3D Printing]]></category>
		<category><![CDATA[DMX / Art-Net]]></category>
		<category><![CDATA[Fusion 360]]></category>
		<category><![CDATA[Lighting]]></category>
		<category><![CDATA[PIC24]]></category>
		<category><![CDATA[RGB LED]]></category>

		<guid isPermaLink="false">https://bikerglen.com/blog/?p=1041</guid>
		<description><![CDATA[This project is a small DMX-512 controlled, color-changing RGB LED light. The light can be controlled via the DMX512 protocol or it can run a number of built-in programs depending on how the software is configured. The light incorporates an &#8230; <a href="https://bikerglen.com/blog/homebrew-rgb-led-light/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_1052" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190324_102016_cover_photo.jpg"><img class="wp-image-1052 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20190324_102016_cover_photo-1024x682.jpg" alt="" width="640" height="426" /></a><p class="wp-caption-text">Assembled homebrew DMX-controlled RGB LED light fixture.</p></div>
<p>This project is a small DMX-512 controlled, color-changing RGB LED light. The light can be controlled via the DMX512 protocol or it can run a number of built-in programs depending on how the software is configured. The light incorporates an advanced 16-bit PIC24 microcontroller with PWM capabilities, a 3D printed enclosure, a laser cut acrylic lid, a custom switching power supply, and a MEMS oscillator. The light measures roughly 2.25&#8243; square by 1.25&#8243; high. This light is the evolution of my RGB LED light designs that span back over a decade.</p>
<p><span id="more-1041"></span></p>
<p>(This next section is long. If you want to skip the history of how this design came to be and go directly to a description of the design instead, click <a href="#hardware-design">here</a>.)</p>
<h2>Early RGB LED Light Designs</h2>
<p>The biggest influence on these RGB LED light designs has been the introduction of low-cost PCB manufacturers that cater to hobbyists and the introduction of affordable 3D printing.</p>
<h3>Mechanical Form Factors</h3>
<p>Early low-cost PCB manufacturing services such as those from ExpressPCB offered a <a href="https://www.expresspcb.com/miniboardplus-standard/">fixed-sized board with two layers and no solder masks for a low cost</a>. As a result, the board designs used through-hole components, were limited  to the sizes made available by the board house unless you wanted to pay a ton extra, and you were lucky to find an interesting enclosure that would hold your board. The free PCB layout tools of the time were a bit limited too but they worked well enough for simple boards.</p>
<p>The photo below shows one of my designs from the early 2000s. The board is about 3&#8243; by 2&#8243;, has through-hole components only, uses a <a href="https://www.microchip.com/wwwproducts/en/PIC16F688">PIC16F688 microcontroller</a>, and uses a linear regulator to step 24V down to 5V for the microcontroller. The linear regulator is not very efficient and runs hot to the touch. The ice cube enclosure is an Ikea lamp they sold in the early 2000s. I made a ton of these as gifts for family and friends.</p>
<p>If you&#8217;re interested in making a color changing lamp of your own, Ikea has tons of low-cost lamps that are extremely suitable to retrofitting with your own RGB LEDs and electronics.</p>
<div id="attachment_1064" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00750.jpg"><img class="wp-image-1064 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00750-1024x683.jpg" alt="DSC00750" width="640" height="427" /></a><p class="wp-caption-text">An RGB LED color changing light design of mine from the early 2000s. The circuit board was manufactured by ExpressPCB and it&#8217;s powered by a PIC16F688 microcontroller. The entire assembly was retrofitted into an ice cube lamp from Ikea.</p></div>
<h3>The Early Electronics</h3>
<p>Below is a close-up of the board from the ice cube lamp. There&#8217;s a microcontroller to control the LEDs, a Maxim part for receiving DMX, an oscillator, a linear regulator, and a transistor switch.</p>
<p><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00745.jpg"><img class="alignnone size-large wp-image-1065" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00745-1024x683.jpg" alt="DSC00745" width="640" height="427" /></a></p>
<p>The microcontroller is a <a href="https://www.microchip.com/wwwproducts/en/PIC16F688">Microchip PIC16F688</a>. The code for this microcontroller was written in assembly. PWM was initially implemented in the main loop of the code. These lights could only cycle through a serious of colors. Later PWM was implemented in an interrupt service routine (ISR). Once PWM was in the ISR, the main loop of the code was reworked to receive DMX. Now these lights could cycle through a series of colors or be controlled via DMX.</p>
<p>The worst part of these lights was there was no provision for in-circuit programming or debugging. The PIC16F688 supported in-circuit programming but I didn&#8217;t have room on the board for the connector. Updating the software required removing the PIC from the board, placing it in a dedicated programming fixture, re-programming the part, then placing the PIC back in the socket. For in-circuit debugging, a special bond out version of the chip had to be used.</p>
<h2>Technology Evolves—Custom Boards and Better CPUs</h2>
<div id="attachment_1067" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00770.jpg"><img class="wp-image-1067 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00770-1024x683.jpg" alt="DSC00770" width="640" height="427" /></a><p class="wp-caption-text">RGB LED lighting controller based on a PIC18F1320 microcontroller. Custom board size with solder masks but still using all through-hole components. This module drove a board of LEDs located in a lamp too small to hold both the LED board and driver electronics.</p></div>
<h3>Custom Boards</h3>
<p>In the late 2000s, SparkFun launched a low-cost PCB manufacturing service called BatchPCB. Pricing was $2.50 per square inch plus shipping. The service offered two layer boards with solder masks and silkscreens. They supported custom-sized boards and would even cut to a custom outline if provided. At the same time, Eagle CAD launched a free hobbyist version of their schematic capture and PCB layout tools.</p>
<p>These two developments suddenly allowed hobbyists to make their own high-quality custom boards of any shape and size. I took full advantage of the situation and made several new RGB LED lamps. Many of these boards were either round or designed to fit in extruded aluminum enclosures like the one in the photo above. The green boards on this blog post were all made at BatchPCB.</p>
<p>In 2010, DorkbotPDX launched a similar PCB batching service and opened it up to the general public. Hobbyists now had two different board services catering to small orders. DorkbotPDX eventually became <a href="https://oshpark.com/">oshpark.com</a> then in <a href="https://www.sparkfun.com/news/1138">2013 SparkFun shut down Batch PCB and referred users to OSHPark</a>. In June 2016, Autodesk purchased Eagle PCB. A free version of <a href="https://www.autodesk.com/products/eagle/free-download">Eagle PCB</a> continues to exist but users looking to upgrade to larger board areas have to move to Autodesk&#8217;s controversial pay-as-you-go usage model. For users looking for non-commercial / open source PCB CAD tools, <a href="http://kicad-pcb.org/">KiCad</a> has made terrific strides in the past two years and is now a viable alternative to Eagle PCB.</p>
<h3>Better CPUs and Better Tools</h3>
<div id="attachment_1078" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00779.jpg"><img class="wp-image-1078 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00779-1024x683.jpg" alt="DSC00779" width="640" height="427" /></a><p class="wp-caption-text">RGB LED lamp based on a PIC18F1320 microcontroller. The PIC18 has supports in-circuit programming and debugger and has enough horsepower to do ISR-based dimming while receiving DMX-512 or commands from an IR remote control.</p></div>
<p>Around the same time as the hobbyist PCB revolution, I upgraded the microcontroller in my lights from a PIC16F688 to a PIC18F1320. The PIC18F1320 had a PC-based toolchain that included a free C compiler and debugger. Additional optimizations could be purchased for the compiler but the free version was good enough to dim the LEDs inside an interrupt service routine. No more assembly code! The PIC18F1320 also offered in-circuit programming and debugging capabilities. These two capabilities shaved tons of time off the software development process.</p>
<h3>Evolution of Software-Based Dimming</h3>
<p>Another change I made around this time frame was to move from <a href="https://en.wikipedia.org/wiki/Pulse-width_modulation">pulse width modulation</a> (PWM) dimming to <a href="https://en.wikipedia.org/wiki/Pulse-density_modulation">pulse density modulation </a>(PDM) dimming. In PWM dimming, the duty cycle of a fixed-frequency square wave varies from 0% to 100% to dim the LED from completely off to completely on. In PDM dimming, both the frequency and density of a series of pulses vary to dim the LED from completely off to completely on. See the figure below.</p>
<div id="attachment_1085" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/pwm-vs-pdm.png"><img class="wp-image-1085 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/pwm-vs-pdm-1024x608.png" alt="pwm-vs-pdm" width="640" height="380" /></a><p class="wp-caption-text">In PWM dimming, the duty cycle of a square wave varies in proportion to the commanded LED brightness. The frequency of the square wave is the frequency of the ISR timer divided by the resolution of the system. In PDM dimming, the pulse density varies in proportion to the commanded LED brightness. The maximum frequency of the pulses is the frequency of the ISR timer. PDM dimming can result in higher refresh rates and less flickering when recorded on video.</p></div>
<p>To implement PDM dimming in software a variable is used as an accumulator. At a fixed frequency inside an interrupt service routine, the commanded brightness level is added to the accumulator. If the accumulator rolls over, i.e., the carry bit is set after the add, the output pin is asserted. If the carry bit is clear, the output pin is deasserted. In some architectures, it&#8217;s possible to directly copy the carry value to the output pin without using any comparison or branch instructions.</p>
<p>In my implementation, the accumulator and commanded brightness are both 16 bit unsigned integers but only the lower 10 bits of the integers are used. If after an add the 11th bit is set, that&#8217;s considered a carry and the output pin is asserted. If not, the output pin is cleared. The 11th bit is then cleared in preparation for the next cycle of the algorithm. This is repeated for each of the red, green, and blue channels.</p>
<p>Here&#8217;s the code for the red channel:</p>
<pre>        // default to all LEDs off
        pwm_temp = 0;

        // process red LED
        pwm_red_counter += pwm_red_level;
        if (pwm_red_counter &gt;= 1024) {
            pwm_red_counter -= 1024;
            pwm_temp |= RED_LED_BIT;
        }

        // process remaining channels
        // ...

        // update port a
        LATA = pwm_temp;</pre>
<p>The use of 10-bit accumulators gives 1024 distinct levels of brightness. Using 1024 levels enables better <a href="https://learn.adafruit.com/led-tricks-gamma-correction/the-quick-fix">gamma correction</a> and thus better brightness resolution particularly at lower brightness levels.</p>
<h3>A Step Backwards for Free Compilers Necessitates the Move to Hardware PWM</h3>
<p>Up until this point, I had been using the Windows-only MPLAB IDE and the free version of the C18 compiler. The limited optimizations of the free C18 compiler were sufficient to move in and out of the dimming ISR quickly enough to leave spare CPU cycles available in the main loop of the code.</p>
<p>Sometime around 2010, Microchip released the MPLAB X IDE and their new XC8 compiler. These were both cross platform and ran on Windows, Mac, and Linux. This was great. We could use the development tools wherever we wanted. Unfortunately the free version of the XC8 compiler had poorer performance when entering and exiting interrupts than the C18 compiler.</p>
<p>This resulted in the PIC18F1320 spending almost 100% of its time inside the ISR and as a result my ISR-based software dimming routines no longer functioned. This necessitated an upgrade to a PIC24 microcontroller with PWM done in hardware. With a PIC24 and PWM hardware, the performance of the compiler and the ISR entry/exit routines was no longer critical.</p>
<p>As a side note, in late 2018, I did break down and purchase the pro version of the XC8 compiler but at $1000 it&#8217;s out of reach for most hobbyists. In addition to the generated code running faster, the generated code is smaller. The pro version of the compiler is thus useful for compiling space constrained applications such as USB bootloaders and the Ethernet code included with their PoE eval board too.</p>
<h2>Some PIC Micros Have Hardware PWM!</h2>
<p>To take my RGB lights to the next level, I needed a better microcontroller that included hardware PWM features. Fortunately, Microchip has the Microchip Advanced Part Selector or <a href="https://www.microchip.com/maps/Microcontroller.aspx">MAPS tool</a>. This online tool lets you perform a parametric search through all their available devices to find devices that meet your needs.</p>
<p>The basic requirements were a PIC24 with at least 3 PWM channels and sufficient memory to not worry about the limitations of the free compiler. One additional requirement was the availability of a low-cost development board that would permit programming and testing of the PWM peripheral without having to build my own boards.</p>
<p>After some searching I found my part, the <a href="https://www.microchip.com/wwwproducts/en/PIC24EP128MC202">PIC24EP128MC202</a><a href="https://www.microchip.com/wwwproducts/en/PIC24HJ128GP202">,</a> and development board, the <a href="https://www.microchip.com/Developmenttools/ProductDetails/DM330013-2">Microstick II</a>. The PIC24EP128MC202 has three channels of hardware-based 16-bit PWM. Within an hour of receiving the development board and microcontroller, I had the basic PWM functionality working. Time to design some boards.</p>
<h3>The 6&#8243; Strip with 16-bit PWM Dimming and Gamma Correction</h3>
<div id="attachment_792" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2017/12/DSC00555_2048w.jpg"><img class="size-large wp-image-792" src="https://bikerglen.com/wp/wp-content/uploads/2017/12/DSC00555_2048w-1024x683.jpg" alt="PIC24-based RGB LED Strips. Each strip is 152.4mm long and contains six of each color of LED." width="640" height="427" /></a><p class="wp-caption-text">PIC24-based RGB LED Strips. Each strip is 152.4mm long and contains six of each color of LED.</p></div>
<p>The first RGB LED lamp design to use the PIC24EP128MC202 was a six-inch strip light. The strip light used six each of 3528 red, green, and blue surface mount LEDs. The board also featured slots that snapped into 3D printed tilted stands. The board was powered by 24V and had DMX control.</p>
<h3>DIN Rail Mount</h3>
<p><a href="https://bikerglen.com/wp/wp-content/uploads/2017/12/DSC00565_2048w.jpg"><img class="alignnone size-large wp-image-796" src="https://bikerglen.com/wp/wp-content/uploads/2017/12/DSC00565_2048w-1024x683.jpg" alt="DSC00565_2048w" width="640" height="427" /></a></p>
<p>The second iteration of the PIC24EP128MC202-based RGB LED controller was designed to control LED strips for my <a href="https://www.youtube.com/watch?v=5HJUm69fgeg">crate beast Halloween prop</a>. The requirements for this controller were that it be able to drive a few feet of LED strips and had a DIN-rail mount form factor so that it could be mounted beside the PLC that controlled the operation of the prop. This necessitated moving to large MOSFET power transistors instead of the smaller BJT transistors used on the strip version. Also, all I/O was placed on pluggable terminal blocks to facilitate quick repairs should they be required.</p>
<h3>Round v1</h3>
<p><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00753_crop.jpg"><img class="alignnone size-large wp-image-1063" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/DSC00753_crop-1024x683.jpg" alt="DSC00753_crop" width="640" height="427" /></a></p>
<p>The next iteration was a 2&#8243; round version of the six inch strip light. The electronics were placed on one board, the LEDs were placed on a second board, and the two boards connected together using some header strips and header pins. The electronics board contained slots that snapped into a mounting bracket. This permitted the board to lay flat or be taped or screwed in place. There were still some minor annoyances like not having a case, the power supply hit the bottom of the LED board, and the oscillator and low ESR caps are huge.</p>
<h3>Round v2</h3>
<p>That brings us to the latest version of the RGB LED lamp. The basic requirements were:</p>
<ul>
<li>The lamp is completely enclosed.</li>
<li>The lamp uses a low-profile switching power supply.</li>
<li>The lamp uses a small oscillator.</li>
<li>The lamp uses a small and inexpensive low-ESR cap for the PIC24.</li>
</ul>
<p>Other than the above, I liked the round form factor, software, and basic functionality of the first round version.</p>
<h2 id="hardware-design">Hardware Design</h2>
<div id="attachment_1055" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20181128_103851.jpg"><img class="size-large wp-image-1055" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20181128_103851-1024x576.jpg" alt="This board has a lot of experiments including a MEMS oscillator, a custom switching power supply, and a new low-ESR capacitor for the PIC24's Vcap pin." width="640" height="360" /></a><p class="wp-caption-text">This board has a lot of experiments including a MEMS oscillator, a custom switching power supply, and a new low-ESR capacitor for the PIC24&#8217;s Vcap pin.</p></div>
<p>This design had lots of new things to try out: a new power supply, a new oscillator, a new capacitor, and a new enclosure with an overlapping lip designed to compensate for tolerances in the vertical stack up of the assembly.</p>
<h3>Selecting a PIC24 Variant</h3>
<p>Picking a PIC24 was easy. The design would use the same PIC24EP128MC202 that the previous three iterations used. Below is a schematic showing the basic connections for the PIC24. To this basic schematic, we&#8217;ll add a switching power supply, a 10 MHz MEMS oscillator, DMX transmit and receive capability, and some transistor switches that control the LEDs.</p>
<div id="attachment_1098" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/1.png"><img class="size-large wp-image-1098" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/1-1024x764.png" alt="Basic PIC24 connections." width="640" height="478" /></a><p class="wp-caption-text">Basic PIC24 connections.</p></div>
<h3>Low ESR Cap Selection</h3>
<p>One of the goals for this project was to use a smaller and less expensive low-ESR cap on the PIC24&#8217;s VCAP/VDDCORE pin. Here&#8217;s the requirements according to the PIC24EP128MC202 data sheet:</p>
<p style="padding-left: 30px;">A low-ESR (&lt; 1 Ohm) capacitor is required on the VCAP pin, which is used to stabilize the voltage regulator output voltage. The VCAP pin must not be connected to VDD and must have a capacitor greater than 4.7 μF (10 μF is recommended), 16V connected to ground. The type can be ceramic or tantalum.</p>
<p>After perusing capacitor data sheets for over an hour, I finally settled on a TDK part that had &lt; 1 Ohm ESR at all frequencies between 10kHz and 100MHz. The TDK <a href="https://product.tdk.com/info/en/documents/chara_sheet/CGA5L1X7R1C106M160AC.pdf">CGA5L1X7R1C106M160AC</a> capacitor is a 10uF +/- 20% ceramic capacitor with an X7R temperature characteristic, a rating of 16V, a 1206 package, and best of all, a price of about fifty cents in small quantities. The previous low ESR cap was huge and over three dollars.</p>
<h3>TI Simple Switcher Buck Converter</h3>
<p>Another goal for this project was to use a lower-profile switching power supply capable of stepping the input +24V power supply voltage down to +3.3V for the PIC24 microcontroller and other digital logic. I had been using a Cui V7803-500 high-efficiency switching drop-in linear regulator replacement on the previous designs. This part is very tall and causes interference when mating the LED board to the logic board. I needed something shorter.</p>
<div id="attachment_1100" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/2.png"><img class="size-large wp-image-1100" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/2-1024x764.png" alt="TI Simple Switcher schematic." width="640" height="478" /></a><p class="wp-caption-text">TI Simple Switcher schematic.</p></div>
<p>TI has a series of high input voltage step down switching regulators called <a href="http://www.ti.com/power-management/non-isolated-dc-dc-switching-regulators/step-down-buck/buck-converter-integrated-switch/simple-switcher.html">TI Simple Switchers</a>. These are easy to use and require minimum external support components. I selected one of these then used their reference design schematic and PCB layout to recreate the circuit and layout on my project.</p>
<p>The schematic for the switching power supply is shown in the schematic above. Also on this schematic page are decoupling capacitors for all the digital circuitry and the power / data input connector. This power supply circuit has plenty of vertical clearance. Unfortunately as built, it occupies more board real estate than the CUI device.</p>
<h3>SiTime MEMS Oscillator</h3>
<p>To make room for the new switching power supply, I needed a smaller oscillator. Most small crystal oscillators are in leadless packages that are hard to solder. While I was working on this project, news broke about high helium atmospheres crashing iPhones. The root cause was helium penetrating the MEMS oscillator used in the iPhone and changing the oscillator&#8217;s frequency. I did a bit more research and discovered a company called <a href="https://www.sitime.com/">SiTime</a> that makes a wide range of MEMS oscillators.</p>
<p>Digging further, they had a <a href="https://www.sitime.com/products/automotive-high-temp-oscillators/sit2024">3.3V version in a tiny, easy-to-solder SOT23-5 package</a> that could be programmed to run at 10MHz. Even better, Digi-Key sells them and will program them to your requested frequency. The exact manufacturer part number is <a href="https://www.digikey.com/product-detail/en/sitime/SIT2024BETS-33N/SIT2024BETS-33N-ND/7422259">SIT2024BETS-33N</a> and the Digi-Key part number is <a href="https://www.digikey.com/product-detail/en/sitime/SIT2024BETS-33N/SIT2024BETS-33N-ND/7422259">SIT2024BETS-33N-ND</a>. Just add one to your cart and specify the programming frequency in the order notes. As shown in the schematic below, they&#8217;re pretty easy to use too. Just add a decoupling capacitor and tie the output enable pin high.</p>
<p><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/3.png"><img class="alignnone size-large wp-image-1104" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/3-1024x764.png" alt="3" width="640" height="478" /></a></p>
<h3> Receiving DMX</h3>
<p>The hardware for transmitting and receiving the DMX protocol is remarkably simple. If you want to spend a lot of money you can use isolated RS-485 transceivers. I&#8217;d already spent enough on this project so I used a <a href="http://www.ti.com/product/SN65HVD11">TI SN65HVD11D</a> as shown in the schematic below. Hook up the D- and D+ lines to the DMX connector. Hook up the data in, data out, and direction lines to the microcontroller. At some point, I need to figure out an ESD protection circuit for the DMX D+ and D- signals.</p>
<div id="attachment_1103" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/4.png"><img class="size-large wp-image-1103" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/4-1024x764.png" alt="DMX transmit / receive circuitry. This could use some ESD protection in a future version." width="640" height="478" /></a><p class="wp-caption-text">DMX transmit / receive circuitry. This could use some ESD protection in a future version.</p></div>
<h3>Transistor Switches</h3>
<p>I&#8217;ve been using FMMT619TA NPN BJT transistors to switch the strings of RGB LEDs on and off for what feels like forever now. There was no reason to change now. These are in a tiny SOT-23 package. They&#8217;re rated for 2A. They can easily switch on and off the 40mA of LED strings without getting hot or requiring heat sinks. A 1k resistor connected between each of the PIC&#8217;s PWM outputs and each transistor&#8217;s base limits the base current to prevent destruction of the transistor while also supplying enough base current to drive the transistor into its saturation region.</p>
<div id="attachment_1105" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/5.png"><img class="wp-image-1105 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/5-1024x764.png" alt="5" width="640" height="478" /></a><p class="wp-caption-text">NPN BJT transistors used to switch the LEDs on and off.</p></div>
<h3>Completed Schematic</h3>
<p>Below is the completed schematic for the RGB lamp&#8217;s controller board.</p>
<div id="attachment_1109" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/6.png"><img class="wp-image-1109 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/6-1024x796.png" alt="6" width="640" height="498" /></a><p class="wp-caption-text">Completed schematic.</p></div>
<h3>Board Layout</h3>
<p>Now that the schematic was complete, it was time to move on to the board layout. I drew the initial board outline as a sketch in Fusion 360. I exported the sketch as a DXF file then imported the DXF file on to layer 20, the dimension layer, in Eagle PCB. A few of the arcs and lines had to be touched up by hand to get the board outline to be a completely closed shape.</p>
<div id="attachment_1117" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/pcb-layout.png"><img class="wp-image-1117 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/pcb-layout-979x1024.png" alt="pcb-layout" width="640" height="669" /></a><p class="wp-caption-text">Completed board layout.</p></div>
<p>Components are arranged similarly to how they are on the first version of the round PCB RGB LED lamp. The power supply layout is copied from the TI Simple Switcher evaluation board. The power transistors that switch the LEDs on and off are on the back of the board. The top layer includes a +3.3V power fill. The bottom layer includes a ground fill. A second ground fill was included on the top layer directly underneath the switching power supply. This ground fill is heavily coupled to the bottom layer ground fill using tons of vias.</p>
<div id="attachment_1115" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/controller.png"><img class="wp-image-1115 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/controller-1024x500.png" alt="controller" width="640" height="313" /></a><p class="wp-caption-text">Oshpark board renders.</p></div>
<p>The final step in the board design process was to upload the board&#8217;s gerber files to Oshpark and check the renders for any final mistakes. This is where problems with the silk screen like incorrectly mirrored or overlapping text become apparent. Finally I ordered boards and assembled them when they arrived. Below is a photo of both sides of the assembled board.</p>
<div id="attachment_1130" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/stuffed-board.jpg"><img class="size-large wp-image-1130" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/stuffed-board-1024x512.jpg" alt="The completed board. Probably should get some isopropyl alchohol and clean it up a better sometime." width="640" height="320" /></a><p class="wp-caption-text">The completed board. Probably should get some isopropyl alchohol and clean it up a better sometime.</p></div>
<h3>The LED Board</h3>
<p>The LED board was simple in comparison to the controller board. It&#8217;s just a bunch of through hole LEDs, resistors, and terminal strips. The LEDs are arranged in a pair of red LED strings, a pair of green LED strings, and a pair of blue LED strings. Each red string uses 7 LEDs and each green and blue string use 5 LEDs. The resistors were chosen to limit the current to each string of LEDs to 15 mA.</p>
<p>Here&#8217;s the schematic. I have no idea if those CREE part numbers are good or not anymore. They&#8217;re several years old. I used LEDs from my parts stock. Sometime I&#8217;ll have to look up the exact part number I used and add them to this post.</p>
<div id="attachment_1131" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/led-board-sch.png"><img class="size-large wp-image-1131" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/led-board-sch-1024x764.png" alt="Led board schematic." width="640" height="478" /></a><p class="wp-caption-text">Led board schematic.</p></div>
<p>Here&#8217;s the Oshpark render:</p>
<div id="attachment_1116" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/led-board.png"><img class="wp-image-1116 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/led-board-1024x500.png" alt="led-board" width="640" height="313" /></a><p class="wp-caption-text">Oshpark render of the LED board.</p></div>
<p>And here&#8217;s a photo of both sides of the assembled LED board.</p>
<div id="attachment_1133" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/led-board.jpg"><img class="size-large wp-image-1133" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/led-board-1024x512.jpg" alt="The assembled LED board. Guess which LEDs are red." width="640" height="320" /></a><p class="wp-caption-text">The assembled LED board. Guess which LEDs are red.</p></div>
<h2>Mechanical Design</h2>
<div id="attachment_1054" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20181128_105508.jpg"><img class="size-large wp-image-1054" src="https://bikerglen.com/wp/wp-content/uploads/2019/03/IMG_20181128_105508-1024x576.jpg" alt="This build had two circuit boards, a 3D printed enclosure, a laser cut acrylic lid, and numerous screws and standoffs." width="640" height="360" /></a><p class="wp-caption-text">This build had two circuit boards, a 3D printed enclosure, a laser cut acrylic lid, and numerous screws and standoffs that all had to come together and function as a single unit.</p></div>
<p>This build was one of my more complicated mechanical designs as well. The enclosure needed to hold two circuit boards and a lens. It also had to have a cutout for the power / data connector. The vertical stackup had lots of tolerances yet the enclosure still needed to fit together tightly regardless of the actual dimensions of the parts used. I also planned on using a relatively new 3D printing process and material.</p>
<h3>Material</h3>
<p>Most of my 3D printing experience is with nylon printed on Electro Optical System&#8217;s line of selective laser sintering (SLS) printers. Around the time of this project, HP released their line of <a href="https://www8.hp.com/us/en/printers/3d-printers.html">HP Multi Jet Fusion 3D printers</a>. The service bureau I normally use for 3D prints, <a href="https://www.sculpteo.com/en/">Sculpteo</a>, was making a big push to popularize HP&#8217;s Jet Fusion process and get users to try out the new material. I figured I&#8217;d give it a try.</p>
<p>Sculpteo has a <a href="https://www.sculpteo.com/blog/2017/08/22/plastic-3d-printing-technologies-hp-multi-jet-fusion-vs-sls/">comparison</a> of the EOS&#8217;s SLS and the HP Jet Fusion technology. The design rules for both printers are very similar and I don&#8217;t tend to push the design rules with either technology. This means that what I print on one printer will usually print on the other printer without issues. Generally, the thinnest printable feature is 0.7mm thick and a thickness of 1.5mm to 2.0mm works well for walls.</p>
<p>The biggest differences between the two printers for me are the accuracy of the parts, the stiffness of the material, and the color options. The Jet Fusion prints have better accuracy and are slightly stiffer / less flexible than the EOS SLS parts.</p>
<div id="attachment_1135" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/plastics.jpg"><img class="size-large wp-image-1135" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/plastics-1024x682.jpg" alt="Two project enclosures printed on HP Jet Fusion 3D printers. One is the raw finish. The other is dyed black." width="640" height="426" /></a><p class="wp-caption-text">Two project enclosures printed on HP Jet Fusion 3D printers. One is the raw finish. The other is dyed black.</p></div>
<p>On the downside, Jet Fusion prints have less finishing options than EOS SLS parts. The EOS SLS PA12 nylon is white. This permits finished parts to be dyed just about any color. The Jet Fusion nylon is a dark gray. The only real color options are the raw dark gray, which is what I used on this project, and dyed black. Above is a photo of two different projects in the raw finish and the dyed black finish.</p>
<h3>Enclosure Bottom</h3>
<p>The enclosure bottom was designed to hold the PCB by the four tabs extending out from the central circular part of the board. These tabs fit in four recesses in the enclosure bottom and hold the board TODO mm above bottom of the enclosure. This allows room for small surface mount components like resistors, capacitors, and SOT23 transistors to be mounted on the bottom of the board.</p>
<p>The cavities that hold the tabs and board are 1.65mm deep to hold the 1.6mm thick board. The clearance between the board and all edges of the interior of the enclosure is 0.5mm. On the underside of the enclosure are four recesses to hold 2-56 pan head hex drive screws.</p>
<p>Here&#8217;s a render of the bottom half of the enclosure as viewed from the top:</p>
<div id="attachment_1139" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/bottom-top.png"><img class="wp-image-1139 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/bottom-top-1024x690.png" alt="bottom top" width="640" height="431" /></a><p class="wp-caption-text">Render of the bottom half of the enclosure as viewed from the top.</p></div>
<p>Here&#8217;s a render of the bottom half of the enclosure as viewed from the bottom:</p>
<div id="attachment_1140" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/bottom-bottom.png"><img class="wp-image-1140 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/bottom-bottom-1024x690.png" alt="bottom-bottom " width="640" height="431" /></a><p class="wp-caption-text">Render of the bottom half of the enclosure as viewed from the bottom.</p></div>
<h3>Enclosure Top</h3>
<p>The enclosure top rests on the enclosure bottom and hold the circuit board in place. It is tall enough to hold both boards with some clearance between the top of the LEDs and the bottom of the lid. Here&#8217;s a render of the top half of the enclosure as viewed from the top:</p>
<div id="attachment_1141" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/top-top.png"><img class="wp-image-1141 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/top-top-1024x690.png" alt="top-top" width="640" height="431" /></a><p class="wp-caption-text">Render of the top half of the enclosure as viewed from the top.</p></div>
<p>Here&#8217;s a render of the top half of the enclosure as viewed from the bottom:</p>
<div id="attachment_1142" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/top-bottom.png"><img class="wp-image-1142 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/top-bottom-1024x690.png" alt="top-bottom" width="640" height="431" /></a><p class="wp-caption-text">Render of the top half of the enclosure as viewed from the bottom.</p></div>
<h3>Connector Cutout</h3>
<p>To create the cutout for the connector, I used the Fusion 360 construction, sketch, and extrude commands. The first step was to use the construction tools to create four planes each offset from the sides of the connector by 0.25mm. The photo below shows the constructed planes:</p>
<div id="attachment_1143" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/construction.png"><img class="wp-image-1143 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/construction-1024x690.png" alt="constructing connector feedthrough" width="640" height="431" /></a><p class="wp-caption-text">Construction planes offset 0.25mm from the outside surfaces of the connector.</p></div>
<p>The next step was to create a new sketch on the bottom plane. This rectangle needed to be sized to cut away the portions of the enclosure around the connector. The left edge was at the left plane. The right edge was at the right plane. The front extended just beyond the enclosure front. The rear extended just beyond the inside wall of the enclosure.</p>
<p>Once the rectangle was sketched, I exited the sketch and used the extrude command to cut both halves of the enclosure. The extrusion height ran from the bottom plane to the top plane and the mode was set to cut:</p>
<div id="attachment_1144" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/extrude-up.png"><img class="wp-image-1144 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/extrude-up-1024x731.png" alt="the cut operation" width="640" height="457" /></a><p class="wp-caption-text">The extrude and cut operation.</p></div>
<p>This left me with a hole perfectly sized for the power / data connector.</p>
<h3>Compensating for Vertical Tolerances</h3>
<p>The vertical stackup has a lot of different components with varying tolerances. A solution was needed to ensure the enclosure halves fit together snug regardless of the individual component tolerances. The solution was to create overlapping lips on each half of the enclosure. If the vertical stackup came up short, the enclosure halves would rest on each other. If the vertical stackup came up tall, the lip would still fill the gap between the enclosure halves even if they didn&#8217;t directly rest on each other. Circled in red below is the lip that runs all the way around both halves of the enclosure.</p>
<div id="attachment_1138" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/Holder-02-v6-2.jpg"><img class="wp-image-1138 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/Holder-02-v6-2-1024x690.jpg" alt="Holder 02 v6 2" width="640" height="431" /></a><p class="wp-caption-text">Circled in red is the lip that runs all the way around both halves of the enclosure.</p></div>
<p>On the bottom half of the enclosure, the lip wall is 0.7mm thick and runs along the outside surface of the enclosure. It&#8217;s 1mm tall. On the top half of the enclosure, the lip is 0.8mm thick and extends 0.25mm into the inside of the enclosure. The clearance between the two lip walls when assembled is 0.25mm. On the top half of the enclosure, the overall lip height is 2mm. That is divided into two portions each with a height of 1mm. The lower portion mates with the lip on the bottom half of the enclosure. The upper portion is there to meet the minimum wall thickness requirements for the 3D printing process.</p>
<p>The photo below shows the overall stackup of the components inside the light fixture. You can see the lip on the two enclosure halves too.</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>
<h3>Laser Cutting the Lid</h3>
<p>The final mechanical part of the project was to laser cut a lid for the enclosure out of clear acrylic. The laser cutting service requires a DXF file with the outline to cut. To generate a DXF file to cut, I created a sketch on the top of the enclosure then used the sketch project command to project the geometry of the top of the enclosure into the sketch. Once that was completed, I right clicked on the sketch in the design browser and selected export DXF. I uploaded the DXF file to the laser cutting service and received a laser cut acrylic lid for the project about a week later.</p>
<h2>Software</h2>
<h3>Setting the Config Bits</h3>
<p>One of the more painful steps when using a new PIC microcontroller for the first time is determining the correct values for the processor&#8217;s config bits. These bits are programmed alongside the firmware. The usually control the clock source for the processor and the functionality of some I/O pins. When they&#8217;re wrong, things don&#8217;t work as expected. Errors in the config bits can result in your PIC running at half speed, one-fourth speed, or hilariously, 32kHz instead of 32MHz. Here&#8217;s the values of the config bits I used on this project:</p>
<pre>// FICD
#pragma config ICS = PGD3
#pragma config JTAGEN = OFF

// FOSCSEL
#pragma config FNOSC    = FRC
#pragma config PWMLOCK  = OFF
#pragma config IESO     = OFF

// FOSC
#pragma config POSCMD   = EC
#pragma config OSCIOFNC = OFF
#pragma config IOL1WAY  = OFF
#pragma config FCKSM    = CSECMD

// FWDT
#pragma config PLLKEN   = ON
#pragma config WINDIS   = OFF
#pragma config FWDTEN   = OFF</pre>
<p>The FICD config bits control debugging. In this case, the in-circuit debugging is placed on the PGD3 pins and JTAG is disabled. The FOSCSEL bits select the internal RC oscillator. The internal RC oscillator will be used at power up until the PLL is configured and locked to the external SiTime MEMS oscillator.</p>
<p>The FOSC bits select an external oscillator on the clock input, set the OSC2 pin as a general purpose IO, enable clock switching, and enable multiple reconfigurations of the peripheral pin select module. Clock switching must be enabled to switch from the internal RC oscillator to the PLL clock output later in software. The PPS select allow the external IO pins on the PIC24 to be assigned to different peripherals inside the PIC24. If you&#8217;re designing a brushless motor controller or antilock brake system where malfunctions could be destructive, setting the IOL1WAY bit to ON would be a good idea to prevent errant software glitches from reconfiguring the IO pins. In our case, multiple reconfigurations are fine.</p>
<p>The final group of bits are the FWDT watchdog timer bits. We enable PLL lock detection but disable the watchdog timer. Again, if you&#8217;re designing a brushless motor controller or antilock brake system where malfunctions could be destructive, enabling the watchdog timer might be a good idea.</p>
<h3>Clock Switchover</h3>
<p>Based on the configuration bits, our PIC24 boots with the internal RC oscillator as the clock source for the CPU. The PIC24 is capable of running much faster than that though by locking its internal PLL to an external clock source and running from the PLL clock output. Here&#8217;s the code to do that:</p>
<pre>    // Configure PLL prescaler, PLL postscaler, PLL divisor
    // with 10MHz external clock
    // Fin   = 10MHz
    // Fplli = Fin/N1  = 10/2  = 5MHz     0.8 &lt; Fplli &lt; 8.0
    // Fsys  = Fplli*M = 5*32  = 160MHz   120 &lt; Fsys  &lt; 340
    // Fosc  = Fsys/N2 = 160/2 = 80MHz    15  &lt; Fosc  &lt; 120
    // Fcy   = Fosc/2  = 80/2  = 40MHz
    PLLFBD             = 30; // PLLFBD  = M-2  = 32-2 = 30
    CLKDIVbits.PLLPOST =  0; // N2 = 2 =&gt; PLLPOST = 0 
    CLKDIVbits.PLLPRE  =  0; // N1 = 2 =&gt; PLLPRE  = 0
    
    // Initiate Clock Switch to Primary Oscillator with PLL (NOSC=0b011)
    __builtin_write_OSCCONH(0x03);
    __builtin_write_OSCCONL(OSCCON | 0x01);

    // Wait for Clock switch to occur
    while (OSCCONbits.COSC!= 0b011);
    
    //  Wait for PLL to lock
    while (OSCCONbits.LOCK!= 1);</pre>
<p>The code above boots using the internal RC oscillator and enables the PLL. We then switch immediately to using the clock output from the PLL. Once the PLL is locked to the external SiTime MEMS oscillator, we boot into the main portion of our code. The result is that our PIC24 is now running at its maximum rated speed.</p>
<h3>Using the PWM Peripheral</h3>
<p>The following initialization code configures the PWM peripheral to run at a PWM frequency of 1220.7 Hz (1220.7 Hz is the 80 MHz Fosc divided by 65536):</p>
<pre>    // initialize PWM
    PTCONbits.EIPU = 1;
    PTCON2bits.PCLKDIV = 0b000;
    PTPER = 65535;

    PHASE1 = PHASE2 = PHASE3 = 0;
    PDC1 = PDC2 = PDC3 = 0x100;
    DTR1 = DTR2 = DTR3 = 0;
    ALTDTR1 = ALTDTR2 = ALTDTR3 = 0;
    IOCON1 = IOCON2 = IOCON3 = 0xC000;
    PWMCON1 = PWMCON2 = PWMCON3 = 0x0000;
    FCLCON1 = FCLCON2 = FCLCON3 = 0x0003;
    
    PTCONbits.PTEN = 1;</pre>
<p>The following code is then used to update the PWM peripheral with new red, green, and blue values:</p>
<pre>PDC1 = PMapLut[rx_data[0]];
PDC2 = PMapLut[rx_data[1]];
PDC3 = PMapLut[rx_data[2]];</pre>
<p>The PWM peripheral has 16-bit resolution so I also needed a new gamma table to take advantage of the increased resolution. The PMapLut array holds the gamma correction table. Here&#8217;s the most recent version of my gamma table:</p>
<pre>static const unsigned short PMapLut[256] = {
       0,    63,  127,  191,  191,  255,  255,  319,  319,  383,  447,  447,  511,  511,  575,  639,
      703,  703,  767,  831,  895,  895,  959, 1023, 1087, 1151, 1151, 1215, 1279, 1343, 1407, 1471, 
     1535, 1599, 1663, 1727, 1791, 1855, 1919, 1983, 2047, 2111, 2239, 2303, 2367, 2431, 2495, 2623, 
     2687, 2751, 2815, 2943, 3007, 3135, 3199, 3263, 3391, 3455, 3583, 3647, 3775, 3839, 3967, 4031, 
     4159, 4287, 4351, 4479, 4607, 4735, 4799, 4927, 5055, 5183, 5311, 5439, 5567, 5631, 5759, 5887,
     6015, 6207, 6335, 6463, 6591, 6719, 6847, 6975, 7167, 7295, 7423, 7615, 7743, 7871, 8063, 8191,
     8383, 8511, 8703, 8831, 9023, 9151, 9343, 9535, 9727, 9855,10047,10239,10431,10623,10751,10943,
    11135,11327,11519,11775,11967,12159,12351,12543,12735,12991,13183,13375,13631,13823,14079,14271,
    14527,14719,14975,15167,15423,15679,15871,16127,16383,16639,16895,17151,17407,17663,17919,18175,
    18431,18687,18943,19199,19519,19775,20031,20351,20607,20863,21183,21503,21759,22079,22335,22655,
    22975,23295,23551,23871,24191,24511,24831,25151,25471,25791,26175,26495,26815,27135,27519,27839,
    28223,28543,28927,29247,29631,29951,30335,30719,31103,31423,31807,32191,32575,32959,33343,33727,
    34175,34559,34943,35327,35775,36159,36607,36991,37439,37823,38271,38719,39103,39551,39999,40447,
    40895,41343,41791,42239,42687,43135,43647,44095,44543,45055,45503,46015,46463,46975,47423,47935,
    48447,48959,49471,49983,50495,51007,51519,52031,52543,53055,53631,54143,54655,55231,55743,56319,
    56895,57407,57983,58559,59135,59711,60287,60863,61439,62015,62591,63167,63807,64383,65023,65535
};</pre>
<h3>Selecting and Configuring Modes</h3>
<p>When the software begins operation, it checks the pushbutton switch to see if it is depressed. If it is, the software checks to see that the switch remains depressed 50 times over one second. If it is, the software enters its configuration mode.</p>
<p>In configuration mode, the default operation of the light and the DMX address can be set by sending a specially formatted DMX packet to the light. The light can be configured for gamma-corrected 8-bit or raw 16-bit DMX operation, random strobe mode, sine oscillator mode, color wash mode, or lamp test mode. Once the mode is configured, the red channel blinks three times and the light returns to normal operation.</p>
<h4>DMX</h4>
<p>In DMX mode, the software listens for its DMX address. Once three (GC 8-bit mode) or six (raw 16-bit mode) addressed bytes are received, the software updates the PWM levels with the received light levels. To configure GC 8-bit mode and set the fixture address, the following DMX packet is sent to the fixture while it is in configuration mode:</p>
<pre>&lt;dmx addr hi byte&gt; &lt;dmx addr lo byte&gt; &lt;0x00&gt; &lt;~dmx addr hi byte&gt; &lt;~dmx addr lo byte&gt; &lt;0xff&gt;</pre>
<p>To configure raw 16-bit mode and set the fixture address, the following DMX packet is sent to the fixture while it is in configuration mode:</p>
<pre>&lt;dmx addr hi byte&gt; &lt;dmx addr lo byte&gt; &lt;0x00&gt; &lt;~dmx addr hi byte&gt; &lt;~dmx addr lo byte&gt; &lt;0xff&gt;</pre>
<p>The DMX address in the packets above ranges from 1 to 512.</p>
<h4>Random Strobe</h4>
<p>In random strobe mode, the three channels of the fixture blink randomly. This mode was supported to blink the white lights on my Crate Beast Halloween project. In that project, an additional IO pin on the PIC24 had to be asserted to enable the flashing lights. To configure random strobe mode, send the following DMX packet to the fixture while it is in configuration mode:</p>
<pre>0x02 0x02 0x00 0xfd 0xfd 0xff</pre>
<h4>Sine Oscillators</h4>
<p>In sine oscillator mode, the three channels output a sine wave. The frequency of the sine wave varies smoothly and randomly causing the lights to go in and out of sync with each other over time. This mode is great for slow ambient background light effects when you don&#8217;t want to worry about programming a complete DMX show.</p>
<p>A friend and I wrote this software initially while I was in college in the early 90s. Over the decades, it&#8217;s been run on numerous platforms. I currently use this mode in my Crate Beast Halloween prop for the red background lighting inside the crate, the background fire effect on my zombie pit, and the green/cyan/UV foreground lighting on my zombie containment unit.</p>
<p>To configure sine oscillator mode, send the following DMX packet to the fixture while it is in configuration mode:</p>
<pre>0x02 0x01 0x00 0xfd 0xfe 0xff</pre>
<h4>Color Wash</h4>
<p>In color wash mode, the fixture smoothly scrolls through a color wheel of 1536 different fully saturated RGB hues. This mode is great for slow ambient background color-changing light effects when you don&#8217;t want to worry about programming a complete DMX show. To configure color wash mode, send the following DMX packet to the fixture while it is in configuration mode:</p>
<pre>0x02 0x04 0x00 0xfd 0xfb 0xff</pre>
<h4>Lamp Test</h4>
<p>In lamp test mode, the fixture cycles through each channel at full brightness with about a one second pause between channels. To configure lamp test mode, send the following DMX packet to the fixture while it is in configuration mode:</p>
<pre>0x02 0x03 0x00 0xfd 0xfc 0xff</pre>
<h2>Changes for Next Version</h2>
<div id="attachment_1149" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2019/04/IMG_20190324_102016_cover_photo.jpg"><img class="size-large wp-image-1149" src="https://bikerglen.com/wp/wp-content/uploads/2019/04/IMG_20190324_102016_cover_photo-1024x682.jpg" alt="The finished light. It's never too early to start thinking about the next version." width="640" height="426" /></a><p class="wp-caption-text">The finished light. It&#8217;s never too early to start thinking about the next version.</p></div>
<p>After disassembling the light several times to hold down the configuration button during power up, one change I would make to the hardware would be to make the button accessible without disassembling the light. The easiest way to accomplish this change would be to create a new board layout that uses a right-angle button, place the button close to the edge of the board, then finally place a small hole in the enclosure that permits pressing of the button with a small non-conductive object such as a toothpick.</p>
<p>Another upgrade would be to make the firmware upgradeable over the DMX interface. This would require a bi-directional RS-485 adapter for a PC or Mac and the installation of a bootloader in the PIC24&#8217;s FLASH memory. If the configuration button were held down during power up, the bootloader could listen for a command to load new firmware over the DMX interface. If the command was received, the upgrade would continue. If not, the bootloader would time out and jump into the existing firmware which could then permit configuring the operating mode and DMX address or jump to normal operation. This should only require software changes and thus be possible using the existing hardware.</p>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/homebrew-rgb-led-light/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PIC18 Four-Channel DMX Relay Controller</title>
		<link>https://bikerglen.com/blog/pic18-four-channel-dmx-relay-controller/</link>
		<comments>https://bikerglen.com/blog/pic18-four-channel-dmx-relay-controller/#comments</comments>
		<pubDate>Tue, 03 Oct 2017 20:31:11 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[CNC Milling]]></category>
		<category><![CDATA[DMX / Art-Net]]></category>
		<category><![CDATA[Fusion 360]]></category>
		<category><![CDATA[Lighting]]></category>
		<category><![CDATA[Microchip]]></category>
		<category><![CDATA[PIC18]]></category>

		<guid isPermaLink="false">http://bikerglen.com/blog/?p=732</guid>
		<description><![CDATA[Halloween was right around the corner and I needed a timer with a bunch of relays to trigger some store-bought props and a fog machine periodically. (Mental note: read fog machine specs carefully—not all come with timer remotes.) My first &#8230; <a href="https://bikerglen.com/blog/pic18-four-channel-dmx-relay-controller/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_733" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-a.png"><img class="size-large wp-image-733" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-a-1024x683.png" alt="PIC18F1320-based, four-channel DMX Relay Controller" width="640" height="427" /></a><p class="wp-caption-text">A four-channel DMX relay controller based on a PIC18F1320.</p></div>
<p>Halloween was right around the corner and I needed a timer with a bunch of relays to trigger some store-bought props and a fog machine periodically. (Mental note: read fog machine specs carefully—not all come with timer remotes.) My first thought was an Arduino and cheap relay board. Second thought was to build something with a micro and some relays. Third thought was that if I’m going to build something, might as well add DMX and package it up into a neat enclosure. Hence, the four channel DMX-controlled relay project was born.</p>
<p><span id="more-732"></span></p>
<p><strong>Design Parameters</strong></p>
<p>My go to 8-bit micro is a <a href="http://www.microchip.com/wwwproducts/en/PIC18F1320">PIC18F1320</a>. I’ve used them on tons of projects, all the development tools are already installed on my computer, and I’m pretty familiar with their idiosyncrasies and peripherals. I’ve also already written both DMX transmitter and DMX receiver code for this micro. The other micros I use a lot are all <a href="http://www.microchip.com/design-centers/16-bit">PIC24s</a> but a 16-bit micro is overkill for this project. PIC18F1320 it is!</p>
<p>Another constraint on this design was to have something that easily fits in an enclosure. I’ve been using <a href="https://www.hammfg.com/electronics/small-case/extruded/1455">Hammond extruded aluminum enclosures</a> for a while now too. They’re well made and look sharp. One of their smaller enclosures holds a 50mm by 80mm PCB which should be plenty of room for this design. Using the smallest enclosure possible reduces the cost of the board, the enclosure, and the end panels.</p>
<p>One last constraint that bears mentioning is the relay selection. I’m only switching small low-voltage, low-current loads. The <a href="https://www.components.omron.com/product-detail?partId=226">Omron G5V-1 series</a> of relays are physically small and capable of switching up to 1A at 24VDC. This matched the sorts of loads I was expecting to switch and four of them would fit on my PCB.</p>
<p>Design decisions made: use a PIC18F1320, use a Hammond 1455C801 enclosure, and use Omron G5v-1DC5 relays.</p>
<p><strong>Schematic</strong></p>
<p>Here’s the schematic for the DMX relay controller. The controller consists of a PIC 18 microcontroller, a crystal oscillator, a power supply, a programming connector, a DMX interface, some relays and their drivers, and an illuminated pushbutton.</p>
<div id="attachment_739" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/dmx-relay-schematic.png"><img class="size-large wp-image-739" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/dmx-relay-schematic-1024x682.png" alt="DMX relay board schematic." width="640" height="426" /></a><p class="wp-caption-text">DMX relay board schematic.</p></div>
<p>I had previously built a few PIC18 projects that used pulse width modulation (PWM) to dim four channels of LEDs with 10-bit resolution. Those projects were powered from 24V and ran the PIC18 as fast as it would run (FCY=40MHz) so there would be plenty of time to service the very frequent interrupts while still listening to the serial port for DMX data. I started with that hardware and software as the basis for this new design but swapped out the LED drivers for some relay drivers and relays.</p>
<p>The PIC18F1320 is capable of running at 40MHz at 5V with a 10MHz crystal oscillator. There&#8217;s also a PIC18LF1320 variant that will run at 24MHz at 3.3V with a 6MHz crystal oscillator. Either would work for this design. I went with the 5V version and made this a 5V-only design simply because I&#8217;ve had an easier time finding stock, off-the-shelf crystal oscillators in my preferred package for hand soldering that run at 5V than 3.3V.</p>
<p>For an oscillator, I picked a 10MHz, 5V ECS part that I’ve used on past designs. It’s a little big but it’s also very easy to solder by hand. I’m running the PIC18 oscillator in its HSPLL oscillator mode. With the 10MHz crystal, the PIC18 runs with an FCY of 40MHz—way faster than needed for this project because the relays are only either on or off and creation of PWM outputs in an interrupt service routine is not required.</p>
<p>For a power supply, I typically use <a href="http://www.cui.com/product/power/dc-dc-converters/non-isolated/0.5-a-output-current/v78-500-series">Cui V7805-500</a> or <a href="http://www.cui.com/product/power/dc-dc-converters/non-isolated/0.5-a-output-current/vxo78-500-series">Cui VXO7805-500</a> switching DC-DC converters. Both have a very wide input voltage range&#8211;from about 6 to 30+ volts. The wide input voltage is important if controlling, for example, a strand of five or six blue or green LEDs wired in series. In this example, the LEDs would be powered from +24V and then the +24V would be connected to the input of the regulator to generate +5V for the microcontroller. Using a cheap linear regulator such as the <a href="https://en.wikipedia.org/wiki/78xx">LM7805</a> with a 24V input would result in at least burned fingers and quite possibly a failure of the regulator without a proper heatsink.</p>
<p>The Cui regulators can supply 500mA of current while still running cool to the touch. The relays and the rest of the design only consume about 160mA so plenty of margin. As with most regulators, the CUI parts require some capacitors on both the inputs and outputs for stability. I designed the board to hold one of these switching regulators but ultimately decided not to stuff the component and fed the board directly from a 5V power supply connected to the power connector.</p>
<p>The Microchip standard programming interface is a 6-pin single-row 0.1” header. A number of years ago (possibly over a decade ago), I decided I wanted to use a connector that occupied less board space than the single-row header. I started using a 10-pin double row 2mm header. I should probably switch to 5-pin single row 2mm header at some point. Other than the connector, it’s the same as the standard programming interface.</p>
<p>I copied and pasted both the 2mm header and the /MCLR pin circuitry for this design from an earlier PIC24 design. On PIC24 designs, the /MCLR reset pin requires a 10k pull-up resistor and is particularly sensitive to electrostatic discharge. The 330Ω resistor and 0.1µF capacitor form a low-pass filter and serve to reduce the likelihood of an ESD event resetting the microcontroller. They’re not needed on the PIC18 design so I stuffed the 330Ω resistor pads with a 0Ω jumper and left the 0.1µF capacitor off the board altogether. These changes are noted in the schematic’s info layer.</p>
<p>For the DMX interface, I’m using <a href="http://www.te.com/usa-en/product-5520251-4.html">two RJ-45 connectors</a> and a Texas Instruments <a href="http://www.ti.com/product/SN65HVD06">SN65HVD06 RS-485 transceiver</a>. The RJ-45 connectors are wired using the less popular <a href="http://www.dl.colorkinetics.com/files/web/support/pro/wiring/RJ45_TO_RJ45.pdf" target="_blank">Color Kinetics standard</a> where pin 1, the white with orange stripe wire, is the inverting or (-) data signal and pin 2, the orange wire, is the non-inverting or (+) data signal.</p>
<p>As mentioned above, I’m using four Omron G5V-1-DC5 relays. The coil voltage is 5V and the coil draws 30mA when energized. The relay’s contacts can switch up to 1 V at 24VDC. Because the board layout does not have adequate separation between traces for AC line voltage and the board is in an ungrounded aluminum enclosure, this design is NOT suitable for switching AC line voltage. Use with small DC loads under 24V only.</p>
<p>I did not physically have room to connect all the relays’ contacts pins to the outside world. Instead I connected the commons of the top two relays together and the commons of the bottom two relays together and routed these two signals to the outside world. I routed out the normally-open contacts for all four relays. This only required a six position screw terminal strip which fit comfortably on the circuit board and the end panels of the enclosure.</p>
<p>Finally, it’s always good to have a pushbutton and an LED on a microcontroller project. I’m using a <a href="http://www.nkkswitches.com/wp-content/themes/impress-blank/search/inc/part.php?part_no=GB15JVC" target="_blank">very slim NKK illuminated pushbutton</a> that will fit between the RJ-45 jacks and the side of the enclosure. The pushbutton will be used to set the DMX address and the LED indicates the state of the microcontroller: DMX address programming, DMX address confirmation, DMX data valid, or running an idle loop. More on this later in the software section.</p>
<p><span style="color: #000000;"><b>Designing the Board for the Enclosure</b></span></p>
<div id="attachment_779" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/keepouts.png"><img class="size-large wp-image-779" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/keepouts-1024x668.png" alt="Avoid these keep out regions when designing a board to fit the Hammond 1455C801 extruded aluminum enclosure." width="640" height="418" /></a><p class="wp-caption-text">Avoid these keep out regions when designing a board to fit the Hammond 1455C801 extruded aluminum enclosure.</p></div>
<p>The board was designed to fit in a <a href="https://www.hammfg.com/part/1455C801" target="_blank">Hammond 1455C801</a> extruded aluminum enclosure. The enclosure has 2mm deep card guides on either side of it to hold an 80mm x 50mm circuit board. In addition, the channel for the end panel screws extends an additional 1.55mm into the interior volume of the enclosure. Any components on the board need to avoid the volume occupied by the card guides and screw channel. This requires a 3.55mm  high keep out region at both the bottom and top edges of the board. I used 4mm to be safe. This is particularly important for conductive components and vias that could possibly make contact with the conductive enclosure.</p>
<p>When placing components on the ends of the enclosure, they need to avoid the screws that hold the end panels to the extruded chassis and protrude through both the plastic bezel and end panels. The centers of the screws are 2mm from the edge of the board. The screws have a radius of 2.5mm. The minimum aluminum around any component on the end panels should be about 1mm. If you add these up, the outside edges of any components protruding through an end panel should be at least 5.5mm from the edge of board.</p>
<p>The plastic bezel is 1.5mm thick. The end panels are 1.5mm thick. The outside faces of the end panels will then be 3mm from the left and right edges of the board. Any components that are flush mounted will need to hang off the edge of the board by 3mm. Adjust this dimension up or down depending on the desired amount for a component to extend past or be recessed into the face of the enclosure.</p>
<p><strong>Layout</strong></p>
<div id="attachment_740" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/dmx-relay-board.png"><img class="wp-image-740 size-large" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/dmx-relay-board-1024x584.png" alt="dmx-relay-board" width="640" height="365" /></a><p class="wp-caption-text">DMX relay board PCB layout.</p></div>
<p>For a layout, I started with a previous design that used this same enclosure, same pushbutton, and same connectors. The only change was moving from a five position Phoenix header to a six position Phoenix header. I’m happy with the layout but I really need to find a smaller surface mount crystal oscillator package that is easy to solder by hand.</p>
<p><strong>Ordering Boards</strong></p>
<p>I ordered the boards from <a href="https://oshpark.com/projects/S3gRq4cx/" target="_blank">OSHPark</a>. Here are the renders. The cost for three boards was $31.00.</p>
<div id="attachment_741" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/relay-board-oshpark-render-top.png"><img class="size-large wp-image-741" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/relay-board-oshpark-render-top-1024x641.png" alt="OSHPark render of the top of the DMX relay controller board." width="640" height="401" /></a><p class="wp-caption-text">OSHPark render of the top of the DMX relay controller board.</p></div>
<div id="attachment_742" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/relay-board-oshpark-render-bottom.png"><img class="size-large wp-image-742" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/relay-board-oshpark-render-bottom-1024x641.png" alt="OSHPark render of the bottom of the DMX relay controller board." width="640" height="401" /></a><p class="wp-caption-text">OSHPark render of the bottom of the DMX relay controller board.</p></div>
<p><strong>Enclosure End Panel Design</strong></p>
<p>Once the boards were back and stuffed, I verified they fit in the enclosure as intended. The clearance between the bottom of the board and the enclosure is a bit tight so I used some wire cutters to trim the leads of the longer components to prevent them from making contact with the enclosure and creating a short. Ideally, I’d move to 100% surface mount components when using this enclosure, but I have not done so yet.</p>
<div id="attachment_736" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-b-1280.jpg"><img class="size-large wp-image-736" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-b-1280-1024x682.jpg" alt="Data side of the DMX relay controller." width="640" height="426" /></a><p class="wp-caption-text">Data side of the DMX relay controller.</p></div>
<div id="attachment_737" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-c-1280.jpg"><img class="size-large wp-image-737" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-c-1280-1024x682.jpg" alt="Power side of the DMX relay controller." width="640" height="426" /></a><p class="wp-caption-text">Power side of the DMX relay controller.</p></div>
<p>Now that I knew the boards fit the enclosure, it was time to design the end panels. I first did this for this arrangement of connectors and pushbuttons on this enclosure over a decade ago. I did it using hand-drawn sketches before the days of easily accessible and affordable CAD packages. Unfortunately, I lost my notes.</p>
<p>The basic process is to draw a dimensioned 2D sketch of the circuit board with the components on one end of the enclosure. Now draw a dimensioned sketch of the end panel over this sketch. The end panel needs to be placed over the circuit board just like it will be when the enclosure is assembled. With a bit of math, you can extrapolate the y positions and heights of the components on the board to the x and y positions of the components on the end panel.</p>
<p>Once the centers of all the components on the panel are known, it’s time to calculate the hole and cut out sizes. When calculating cut out sizes, the smallest milling bit available at Front Panel Express has a diameter of 1mm. The corners of any cutouts will necessarily have a rounded corner with a radius of 0.5mm. If you make the cutout about 0.5mm larger than component, the component will fit easily into the cutout when assembling the enclosure but there could be a bit of interference in the corners.</p>
<p>Repeat for the other end of the enclosure. I’m sure this process could be sped up and made less error prone using Fusion 360 or any other reasonably decent CAD software.</p>
<p>I used <a href="https://www.frontpanelexpress.com/" target="_blank">Front Panel Express</a> to design and mill the end panels. Once I had the x-y coordinates and cutout sizes, I launched their software. I copied the dimensions from the enclosure data sheet for the basic dimensions of the panel and and the location and dimensions of the screw holes. I chose a thickness of 1.5mm for the end panels.</p>
<p>I then transcribed the positions and dimensions of my cut outs from my notes into Front Panel Express. The final end panels are shown in the figure below.</p>
<div id="attachment_744" style="width: 648px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/Untitled-1.png"><img class="size-full wp-image-744" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/Untitled-1.png" alt="Front and rear panels for the DMX relay board’s enclosure." width="638" height="589" /></a><p class="wp-caption-text">Front and rear panels for the DMX relay board’s enclosure.</p></div>
<p><strong>Verifying Fit</strong></p>
<div id="attachment_738" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-d.jpg"><img class="size-large wp-image-738" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/pic18-dmx-relay-d-1024x683.jpg" alt="3D render of the DMX controller in its enclosure with end panels." width="640" height="427" /></a><p class="wp-caption-text">3D render of the DMX controller in its enclosure with end panels.</p></div>
<p>Before spending the money to have the end panels fabricated, I checked their dimensions using <a href="https://www.frontpanelexpress.com/" target="_blank">Front Panel Express</a>, <a href="http://ecad.io" target="_blank">ecad.io</a>, and <a href="https://www.autodesk.com/products/fusion-360/overview" target="_blank">Autodesk Fusion 360</a>. The first step is to gather the required files for Fusion 360.</p>
<p>In the Front Panel Express design software, I exported my front panels as DXF files without reference points. I used ecad.io and the .brd file from Eagle PCB to create a 3D mechanical model of my circuit board without any components on it and exported it as a STEP v2.14 assembly file. I then dug around the component manufacturers’ websites to find 3D models of the enclosure and all the components that would extend through the end panels.</p>
<p>Once I had all the required files, I launched Fusion 360 and uploaded all the files. The DXF files for the end panels needed some depth. I opened each DXF file, used the Push/Pull tool to change the depth of the panels to 1.5mm then hid the sketch and saved the files.</p>
<p>At this point, I created a new design and new component in Fusion 360. I imported each component I previously uploaded into the new design and used the joint command in the assemble menu to place the components on the circuit board, the circuit board in the enclosure, and then the panels on the end of the enclosure.</p>
<p>I used the interference command under the inspect menu to check for interferences between the screw heads and my panels and the connectors and pushbutton and my panels. The interference command detected some interference in the corners of a few of the connectors but it was not enough to concern me.</p>
<p>At this point, I was confident in ordering the panels from Front Panel Express.</p>
<p><strong>Software<br />
</strong></p>
<p>The software has four main functions: initialization, DMX address programming, normal DMX run mode, and DMX failure mode.</p>
<p>After reset, the initialization function initializes all the hardware then checks to see if the pushbutton is held down. If the pushbutton is held down and continues to be held down for an entire second, the software jumps into the DMX address programming mode. If the pushbutton is not held down or is released early, the software reads the board’s existing DMX address from the PIC18’s EEPROM and jumps into the DMX run mode.</p>
<p>In the DMX address programming mode, the software listens to the incoming data stream for a DMX channel with the level set to 0xFF. Once a channel with that level is detected, the address of that channel becomes the address of the first relay. The last three relays are assigned the next three consecutive addresses after the first relay. For example, if 0xFF is received on channel 8, the relays will be assigned to channels 8, 9, 10, and 11. Once programming is complete, the address information is saved in EEPROM, the pushbutton light blinks three times, and the software enters the DMX run mode.</p>
<p>In the DMX run mode, the software listens to the incoming data stream for the DMX channels matching the addresses of the relays. Levels for the matching channels are saved to memory. Once the level for the last relay is received, all the relays are updated to their new states. If a level is less than 128, the corresponding relay will be turned off. If a level is greater than or equal to 128, the corresponding relay will be turned on. If less than four relays of channels are received, the relays will not be updated.</p>
<p>While in DMX run mode, if the software does not receive a valid DMX stream for ten seconds, the software will leave DMX run mode and enter DMX failure mode. As soon as a valid DMX stream is received, the software will leave DMX failure mode and return to DMX run mode.</p>
<p>While in DMX failure mode, an idle loop is executed. In this loop, the user can write software to control the relays in absence of a valid DMX signal. This could be as simple as turning all the relays off. For my zombie fogger project, this loop turns on the zombie’s LED lighting and triggers the zombie’s sound effects and fog machine every 30 seconds.</p>
<p><strong>The Final Product</strong></p>
<p>Here’s a photograph of the final product with the end panels installed.</p>
<div id="attachment_788" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/dmx-relay-v2-enclosure-with-panels.jpg"><img class="size-large wp-image-788" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/dmx-relay-v2-enclosure-with-panels-1024x683.jpg" alt="DMX relay controller with machined end panels installed." width="640" height="427" /></a><p class="wp-caption-text">DMX relay controller with machined end panels installed.</p></div>
<p><strong>But wait…there&#8217;s more!</strong></p>
<p>As an added bonus, with the Luminair 3 app and an Art-Net to DMX interface, I can control my zombies from an iPad!</p>
<div id="attachment_761" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/10/ipad-zombies.jpg"><img class="size-large wp-image-761" src="http://bikerglen.com/wp/wp-content/uploads/2017/10/ipad-zombies-1024x696.jpg" alt="Control zombies with an iPad!" width="640" height="435" /></a><p class="wp-caption-text">Control zombies with an iPad!</p></div>
<p><strong>Design Files</strong></p>
<p>Design files are located in my <a href="https://github.com/bikerglen/pic18-dmx-relay-board" target="_blank">Github account</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/pic18-four-channel-dmx-relay-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating Custom 3D Printed LED Bar Graphs</title>
		<link>https://bikerglen.com/blog/custom-3d-printed-led-bar-graphs/</link>
		<comments>https://bikerglen.com/blog/custom-3d-printed-led-bar-graphs/#comments</comments>
		<pubDate>Sat, 29 Apr 2017 19:17:04 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[3D Printing]]></category>
		<category><![CDATA[Fusion 360]]></category>
		<category><![CDATA[Matlab]]></category>

		<guid isPermaLink="false">http://bikerglen.com/blog/?p=644</guid>
		<description><![CDATA[While building my zombie containment unit, I decided I wanted some LED displays or bar graphs to complement the containment status video running on the smaller secondary video monitor. Some other containment units used LED air pressure gauges from eBay. &#8230; <a href="https://bikerglen.com/blog/custom-3d-printed-led-bar-graphs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_647" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2017/04/01.banner.DSC_1663.jpg"><img class="wp-image-647 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2017/04/01.banner.DSC_1663-1024x682.jpg" alt="Three different bar graphs built using Matlab, Eagle, Fusion 360, and 3D printing." width="640" height="426" /></a><p class="wp-caption-text">Three different bar graphs built using Matlab, Eagle, Fusion 360, and 3D printing.</p></div>
<p>While building my <a href="https://youtu.be/48f4Io2PyE8">zombie containment unit</a>, I decided I wanted some LED displays or bar graphs to complement the containment status video running on the smaller secondary video monitor. Some other containment units used LED air pressure gauges from eBay. I wanted to achieve a similar look, but I also wanted my gauge to be software controllable so I could change the number of segments lit in response to events in the playback of the two videos. I decided it was time to build my own LED bar graphs.</p>
<p><span id="more-644"></span></p>
<p>My initial thought was to buy some <a href="http://www.lumex.com/content/files/ProductAttachment/SSA-LXB10SUGW-CUR.pdf">pre-made curved bar graph segments</a> and build my own board to hold them. Unfortunately, no distributors stocked these bar graphs and I  didn’t want to purchase the minimum order quantity of 500.</p>
<p>I decided to build a board to hold a bunch of discrete LEDs arranged in a circle and at the correct angles. Soldering them by hand and keeping everything perfectly aligned, however, was going to be problem. I also did not want light from the lit LEDs to bleed into the unlit LEDs. Fortunately 3D printing could solve both of these problems: a 3D printed holder could hold the LEDs while soldering them and act as a separator to prevent light bleed.</p>
<p><strong>Picking LEDs and a Driver IC</strong></p>
<div id="attachment_659" style="width: 650px" class="wp-caption alignnone"><a href="https://bikerglen.com/wp/wp-content/uploads/2017/04/02.leds_and_driver.DSC_1667.jpg"><img class="wp-image-659 size-large" src="https://bikerglen.com/wp/wp-content/uploads/2017/04/02.leds_and_driver.DSC_1667-1024x682.jpg" alt="1 x 5 mm LEDs, MAX6954 driver IC, and 2 x 5 mm LEDs." width="640" height="426" /></a><p class="wp-caption-text">1 x 5 mm LEDs, MAX6954 driver IC, and 2.5 x 5 mm LEDs.</p></div>
<p>The first step is to pick some LEDs and a driver IC to drive them. I searched Kingbright’s <a href="http://www.kingbrightusa.com/">website</a> and settled on two possible LED candidates in three different colors.</p>
<p>The first LED was a 1 x 5 mm rectangular LED with a 2.8 x 5 mm base. I settled on the <a href="http://www.kingbrightusa.com/product.asp?catalog_name=LED&amp;product_id=WP1053IDT">625nm red version of this LED</a>, part number WP1053IDT. Finding this LED in stock in green and yellow proved to problematic but I still wanted to do a display that used red, yellow, and green LEDs so I decided to build a second display with another LED too.</p>
<p>The second LED was a 2.5 x 5 mm rectangular LED. This LED’s dimensions are constant throughout its height. This LED was stocked in <a href="http://www.kingbrightusa.com/product.asp?catalog_name=LED&amp;product_id=WP513IDT">red</a> (WP513IDT), <a href="http://www.kingbrightusa.com/product.asp?catalog_name=LED&amp;product_id=WP513YDT">yellow</a> (WP513YDT), and <a href="http://www.kingbrightusa.com/product.asp?catalog_name=LED&amp;product_id=WP513GDT">green</a> (WP513GDT) by a <a href="http://www.mouser.com/Search/Refine.aspx?Keyword=WP513">distributor</a> too.</p>
<p>After searching for quite some time for a suitable driver IC, I finally settled on a <a href="https://www.maximintegrated.com/en/products/power/display-power-control/MAX6954.html">Maxim MAX6954 common cathode LED display driver</a> in a 36-pin SSOP package. This driver IC can drive up to 128 discrete LEDs, sixteen 7-segment dispays, eight alphanumeric displays, or some combination in between. It requires very little external circuitry and has a simple SPI interface for controlling the attached LEDs. Then I looked at the cost—about $20 each in single quantities. Ouch! But board space was at a premium and I wanted to add a few 7-segment displays to the graphs too so this IC was the perfect fit for the job.</p>
<p><strong>Trigonometry Time<br />
</strong></p>
<p>After picking out the basic components, the next step is to decide on a board size, the number of LEDs on the board, and the radius and length of the arc that encompasses the LEDs. The 3D printing process imposes a constraint on these decisions: the minimum wall thickness in the selected 3D printing process is about 1.5 to 2mm so the LEDs can be no closer to each other at their closest points than about 1.5mm.</p>
<p>I settled on a 50.8mm (2”) diameter board with the LEDs arranged in a 270 degree arc with a radius of 18.5mm. For the smaller 1 x 5mm LEDs, I placed 24 LEDs on this arc and for the larger 2.5 x 5mm LEDs, I placed 18 LEDs on this arc.</p>
<p>For the first three LEDs on the first board, I did the calculations by hand then moved and rotated the LEDs using the Eagle PCB command line. This quickly became monotonous and error prone.</p>
<p><strong>Matlab to the Rescue</strong></p>
<div id="attachment_665" style="width: 636px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/matlab-dimensions.png"><img class="size-full wp-image-665" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/matlab-dimensions.png" alt="Variables used by the Matlab script and their relationship to the final board layout." width="626" height="605" /></a><p class="wp-caption-text">Variables used by the Matlab script and their relationship to the final board layout.</p></div>
<p>To simplify these calculations, I wrote a <a href="https://github.com/bikerglen/circular-bar-graphs/blob/master/bar_graph_blog_post.m">Matlab script</a>. When executed, the Matlab script sets a bunch of variables that control the spacing and position of the LEDs on the bar graph board, calculates the position and rotation of each LED, then generates an <a href="https://github.com/bikerglen/circular-bar-graphs/blob/master/bar_graph_blog_post.scr">Eagle PCB script</a> that will place the LEDs, draw a board outline, and draw some informational lines that show where each LED and the 3D printed LED holder will be located on the board.</p>
<p>The variables are as follows (see the diagram above for their relationship to the completed board):</p>
<ul>
<li><strong>nLedPos</strong>: the number of LEDs in a complete circle.</li>
<li><strong>nLeds</strong>: the number of LEDs used on the bar graph.</li>
<li><strong>r</strong>: the radius of the arc containing the LEDs in millimeters.</li>
<li><strong>xOffset</strong> and <strong>yOffset</strong>: the x and y offsets to the center of the board in millimeters. It’d be nice to keep the bar graph centered at the origin but my Eagle PCB license will only permit components to be placed in a small area northeast of the origin.</li>
<li><strong>keepout</strong>: the width of the region occupied by the 3D printed holder in millimeters. This is measured normal to the arc containing the LEDs. For example with r = 18.5mm, a keep out region will be created between arcs at a radius of 14mm and a radius of 23mm.</li>
<li><strong>radius</strong>: radius of the board for the board outline layer.</li>
<li><strong>ledw</strong> and <strong>ledh</strong>: the width and height of the LED plus any margin for the hole in the 3D printed holder.</li>
</ul>
<p>With the Matlab script and generated Eagle PCB script, it’s pretty quick and easy to iterate through multiple designs in Eagle PCB and see how the LEDs will be spaced and placed on the board.</p>
<p><strong>Designing the Board</strong></p>
<p>With all the design decisions completed, it‘s time to run the Matlab script and note the location of the generated Eagle PCB script. Open Eagle PCB and generate <a href="https://github.com/bikerglen/circular-bar-graphs/blob/master/bar_graph_blog_post.sch">a schematic containing the number of required LEDs</a>. These should be labeled D1 … Dn where n is the number of LEDs (nLeds) from the Matlab script. See the figure below as an example.</p>
<div id="attachment_667" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_sch_0.png"><img class="size-large wp-image-667" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_sch_0-1024x764.png" alt="Schematic with just the LEDs." width="640" height="478" /></a><p class="wp-caption-text">Schematic with just the LEDs.</p></div>
<p>Select switch to board to generate a board from the schematic. It’ll look something like the picture below.</p>
<div id="attachment_668" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_brd_0.png"><img class="size-large wp-image-668" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_brd_0-1024x516.png" alt="Default layout after generating the board from the schematic." width="640" height="323" /></a><p class="wp-caption-text">Default layout after generating the board from the schematic.</p></div>
<p>Delete the default board outline from the dimension layer then run the <a href="https://github.com/bikerglen/circular-bar-graphs/blob/master/bar_graph_blog_post.scr">generated Eagle PCB script</a> using the File…Execute Script… menu option in the PCB layout tool. The board should now look something like this with all the LEDs, board outline, and dimensions placed:</p>
<div id="attachment_669" style="width: 614px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_brd_1.png"><img class="size-full wp-image-669" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_brd_1.png" alt="Board after LEDs, dimensions, and keep outs have been placed by the generated Eagle PCB script." width="604" height="604" /></a><p class="wp-caption-text">Board after LEDs, dimensions, and keep outs have been placed by the generated Eagle PCB script.</p></div>
<p>At this point, if you don’t like the placement of the LEDs, change the parameters in Matlab and repeat the process.</p>
<p>The final step is to add the rest of the components required by the design to the schematic and finish the board layout. Here’s my <a href="https://github.com/bikerglen/circular-bar-graphs/blob/master/bar%20graph%20meter%202in%20clip%20in%20w%2047uF.sch">final schematic</a>:</p>
<div id="attachment_670" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_sch_1.png"><img class="size-large wp-image-670" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_sch_1-1024x764.png" alt="Final schematic." width="640" height="478" /></a><p class="wp-caption-text">Final schematic.</p></div>
<p>And my <a href="https://github.com/bikerglen/circular-bar-graphs/blob/master/bar%20graph%20meter%202in%20clip%20in%20w%2047uF.brd">final board layout</a>:</p>
<div id="attachment_671" style="width: 613px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_brd_2.png"><img class="size-full wp-image-671" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/bar_graph_blog_post_brd_2.png" alt="Final board layout." width="603" height="603" /></a><p class="wp-caption-text">Final board layout.</p></div>
<p>And the boards fabbed from the above files:</p>
<div id="attachment_672" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/03.boards.jpg"><img class="size-large wp-image-672" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/03.boards-1024x768.jpg" alt="The fabbed board for a 270 degree arc with 24 1 x 5mm LEDs." width="640" height="480" /></a><p class="wp-caption-text">The fabbed board for a 270 degree arc with 24 1 x 5mm LEDs.</p></div>
<p>I added some notches to the board outline to allow the boards to snap into a holder for either surface or panel mounting the finished displays:</p>
<div id="attachment_680" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/04.board_and_holder.DSC_1675.jpg"><img class="size-large wp-image-680" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/04.board_and_holder.DSC_1675-1024x683.jpg" alt="Snap-in board holder." width="640" height="427" /></a><p class="wp-caption-text">Board placed into a 3D printed plastic snap-in bracket for surface mounting.</p></div>
<p><strong>Designing the LED Holder</strong></p>
<p>I used Autodesk Fusion 360 to design the LED holder. The first step in creating the holder is to create a sketch matching the dimensions of the LED holder keep out area from the PCB board and with a hole for a single LED. We’ll duplicate the LED hole to all the required positions after extruding the sketch into a 3D body.</p>
<p>Some reminders of the required dimensions:</p>
<ul>
<li>The radii of the keep out area are 18.5mm ± (9mm/2) = 14mm and 23mm. These arcs extend 270 degrees from -45° to 225°.</li>
<li>The center of one of the LEDs (D20) is at r = 18.5mm and θ = (360/32/2) = 5.625°.</li>
<li>From printing a rectangular piece with different sizes of LED holes, I learned the LED hole needs to be 0.2mm larger than the LED so for a 1 x 5mm LED, the hole needs to be 1.2 x 5.2mm.</li>
</ul>
<p>To create the sketch:</p>
<ol>
<li>As always in Fusion 360, first things first: create a new component to hold your design.</li>
<li>Create a new sketch.</li>
<li>Create two circles centered at the origin, one with a radius of 14mm and the second with a radius of 23mm.</li>
<li>Create two lines radiating outward from the origin to the edge of the outermost circle. One line should be at an angle of 225°; the second at an angle of -45°. Both lines should have a length of 23mm.</li>
</ol>
<p>It should look something like this now:</p>
<div id="attachment_684" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.02.23-PM.png"><img class="size-large wp-image-684" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.02.23-PM-1024x584.png" alt="Circles and lines complete." width="640" height="365" /></a><p class="wp-caption-text">Circles and lines complete.</p></div>
<ol start="5">
<li>Now use the trim tool to delete the unneeded lines.</li>
</ol>
<p>It’ll look something like this now:</p>
<div id="attachment_685" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.04.19-PM.png"><img class="size-large wp-image-685" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.04.19-PM-1024x584.png" alt="Trim complete." width="640" height="365" /></a><p class="wp-caption-text">Trim complete.</p></div>
<p>Now add the hole for the LED:</p>
<ol start="6">
<li>Create a line from the origin with a length of 18.5mm and an angle of 5.625°.</li>
<li>Create a 3 point rectangle. The first point is at the end of the line drawn in the previous step. The second point is 2.6mm (1/2 of 5.2mm) back along the same line. The third point is up 0.6mm (1/2 of 1.2mm) from the same line.</li>
<li>Create two more 3 point rectangles so that you end up with a final rectangle that is 1.2 x 5.2mm. It’ll be divided up into four regions.</li>
</ol>
<div id="attachment_686" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.11.57-PM.png"><img class="size-large wp-image-686" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.11.57-PM-1024x584.png" alt="Location of rectangular cut out for one LED." width="640" height="365" /></a><p class="wp-caption-text">Location of rectangular cut out for one LED.</p></div>
<ol start="9">
<li>Now use the trim tool to get rid of the excess lines leaving just a single rectangle for the LED hole.</li>
</ol>
<div id="attachment_687" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.16.35-PM.png"><img class="size-large wp-image-687" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.16.35-PM-1024x584.png" alt="Finished sketch." width="640" height="365" /></a><p class="wp-caption-text">Finished sketch.</p></div>
<p>Now create the 3D body and the required LED holes:</p>
<ol start="10">
<li>Exit the sketch and use the press pull tool to extrude the sketch up 3.5mm. This is the height of the portion of the led that is 1 x 5mm (4mm) minus 0.5mm.</li>
<li>Select the four faces of the LED hole.</li>
<li>Select Pattern…Circular Pattern from the Create menu.</li>
<li>Click Axis in the popup dialog box and select the Y axis to rotate the pattern about the Y axis.</li>
<li>For quantity, enter 32.</li>
<li>Uncheck the holes outside the body of the LED holder.</li>
<li>Click OK.</li>
</ol>
<div id="attachment_688" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.23.23-PM.png"><img class="size-large wp-image-688" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.23.23-PM-1024x584.png" alt="Creating the circular pattern." width="640" height="365" /></a><p class="wp-caption-text">Creating the circular pattern.</p></div>
<div id="attachment_689" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.24.45-PM.png"><img class="size-large wp-image-689" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.24.45-PM-1024x584.png" alt="Circular pattern complete." width="640" height="365" /></a><p class="wp-caption-text">Circular pattern complete.</p></div>
<p>Next I created a shroud on the bottom of the LED holder to mask light escaping from the bottom. This shroud is 4mm tall and 1.5mm thick on both the inside out side radius of the LED holder.</p>
<ol start="17">
<li>Select the bottom of the LED holder and select create a new sketch.</li>
<li>Create two center point arcs located at the origin with a radius of 15.5 and 21.5mm on the bottom face of the LED holder.</li>
<li>Stop the sketch.</li>
<li>Select the two faces between the arcs and the outside edges of the LED holder.</li>
<li>Use the push pull tool to extrude these two faces down 4mm.</li>
</ol>
<div id="attachment_692" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.30.55-PM.png"><img class="size-large wp-image-692" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.30.55-PM-1024x584.png" alt="Arcs on bottom of LED holder." width="640" height="365" /></a><p class="wp-caption-text">Arcs on bottom of LED holder.</p></div>
<div id="attachment_693" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.34.03-PM.png"><img class="size-large wp-image-693" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.34.03-PM-1024x584.png" alt="LED holder with shroud extruded." width="640" height="365" /></a><p class="wp-caption-text">LED holder with shroud extruded.</p></div>
<p>At this point the LED holder is complete. Since I opted to mount my board using a board holder with snap-in tabs, I creating a cutting tool out of the tabs on the board holder and used the cutting tool to remove any plastic on the LED holder that might interfere with the snap-in tabs. My finished LED holder looked like this on the bottom:</p>
<div id="attachment_694" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.40.21-PM.png"><img class="size-large wp-image-694" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.40.21-PM-1024x584.png" alt="LED holder with plastic removed to prevent interference with snap-in board holder." width="640" height="365" /></a><p class="wp-caption-text">LED holder with plastic removed to prevent interference with snap-in board holder.</p></div>
<p><strong>Verifying the Fit</strong></p>
<div id="attachment_695" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.48.34-PM.png"><img class="size-large wp-image-695" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-12.48.34-PM-1024x584.png" alt="Verifying the fit of the circuit board, board holder, and LED holder in Fusion 360." width="640" height="365" /></a><p class="wp-caption-text">Verifying the fit of the circuit board, board holder, and LED holder in Fusion 360.</p></div>
<p>The final step before manufacturing the LED holder is to make sure the LED holder and the LEDs on the circuit board will fit together properly. To do this, I used <a href="https://www.ecad.io/">ecad.io</a>. After logging into the website, I uploaded my Eagle PCB board file and 3D models of the LEDs and other components obtained from the component manufacturers’ websites. Once everything was placed in ecad.io, I created a STEP AP214 Part File containing a 3D mechanical model of the board and components. Once the file was created, I downloaded the resulting .step file to my computer.</p>
<p>Back in Fusion 360, I uploaded the .step file and added the LED holder and board holder components to the model. I visually checked for interference but I could have also used the Inspect…Interference command in Fusion 360. Once I was satisfied with the fit, I selected the LED holder component and selected Make…3D Print. I set mesh refinement to fine and opted to save the .stl file to my computer rather than use the 3D Print Utility. Finally, I uploaded the .stl files to a 3D printing service and printed the models.</p>
<div id="attachment_696" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/05.led_holder.DSC_1685.jpg"><img class="size-large wp-image-696" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/05.led_holder.DSC_1685-1024x683.jpg" alt="Finished 3D printed LED holders for the 24 LED bar graph." width="640" height="427" /></a><p class="wp-caption-text">Finished 3D printed LED holders for the 24 LED bar graph.</p></div>
<p><strong>Final Assembly</strong></p>
<p>To assemble the bar graphs, I soldered all the surface mount components to the board. After these were done, I stuffed the LEDs into their pads and placed the 3D printed LED holder over the LEDs. I then very carefully soldered the LEDs in place. After soldering all the LEDs, I removed the LED holder to see how they looked:</p>
<div id="attachment_697" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/06.no-holders.DSC_1684.jpg"><img class="size-large wp-image-697" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/06.no-holders.DSC_1684-1024x683.jpg" alt="No way the soldering job would be this neat without the use of a 3D printed part to hold the LEDs in place during assembly." width="640" height="427" /></a><p class="wp-caption-text">No way the soldering job would be this neat without the use of a 3D printed part to hold the LEDs in place during assembly.</p></div>
<p>Here’s the assembled LED bar graph with the LED holder and board holder in place:</p>
<div id="attachment_698" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/07.assembled.DSC_1689.jpg"><img class="size-large wp-image-698" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/07.assembled.DSC_1689-1024x683.jpg" alt="Assembled LED bar graph." width="640" height="427" /></a><p class="wp-caption-text">Assembled LED bar graph.</p></div>
<p><strong>More Ideas and Options</strong></p>
<p>In addition to the surface mount snap-in mounting bracket, I made a panel mount for the LED bar graphs:</p>
<div id="attachment_699" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/08.panel_mount.DSC_1678.jpg"><img class="size-large wp-image-699" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/08.panel_mount.DSC_1678-1024x682.jpg" alt="Panel mount. With a circular diffused gray translucent acrylic cover, this would look even better." width="640" height="426" /></a><p class="wp-caption-text">Panel mount. With a circular diffused gray translucent acrylic cover, this would look even better.</p></div>
<p>One of the coolest things about 3D printing your own bar graphs is that you’re no longer limited to mass produced bar graph displays in stock shapes. You can make your own displays in any shape you want. For my <a href="https://youtu.be/48f4Io2PyE8">zombie containment unit</a>, I made one circular red display and a 2nd display in the shape of a squiggle. I mounted both of these to an aluminum panel and stuck it to the front of the prop:</p>
<div id="attachment_702" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-1.02.44-PM.png"><img class="size-large wp-image-702" src="http://bikerglen.com/wp/wp-content/uploads/2017/04/Screen-Shot-2017-04-29-at-1.02.44-PM-1024x574.png" alt="A circular bar graph and a randomly shaped bar graph on my zombie containment unit Halloween prop." width="640" height="359" /></a><p class="wp-caption-text">A circular bar graph and a randomly shaped bar graph on my zombie containment unit Halloween prop.</p></div>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/custom-3d-printed-led-bar-graphs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build a Pair of Robotic Googly Eyes</title>
		<link>https://bikerglen.com/blog/build-a-pair-of-robotic-googly-eyes/</link>
		<comments>https://bikerglen.com/blog/build-a-pair-of-robotic-googly-eyes/#comments</comments>
		<pubDate>Sun, 26 Apr 2015 03:06:38 +0000</pubDate>
		<dc:creator><![CDATA[Glen]]></dc:creator>
				<category><![CDATA[Fusion 360]]></category>
		<category><![CDATA[Robotics]]></category>

		<guid isPermaLink="false">http://bikerglen.com/blog/?p=392</guid>
		<description><![CDATA[Build your very own pair of giant robot googly eyes! These eyes are built from laser cut acrylic panels and motorized using a pair of NEMA-14 stepper motors. This post is the first in a series of three posts. In &#8230; <a href="https://bikerglen.com/blog/build-a-pair-of-robotic-googly-eyes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="attachment_400" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00179.jpg"><img src="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00179-1024x682.jpg" alt="Completed robotic googly eyes. The scleras (whites of the eyes) are about 8&quot; (200mm) in diameter with 5&quot; (125mm) pupils." width="640" height="426" class="size-large wp-image-400" /></a><p class="wp-caption-text">Completed robotic googly eyes. The scleras (whites of the eyes) are about 8&#8243; (200mm) in diameter with 5&#8243; (125mm) pupils.</p></div>
<p>Build your very own pair of giant robot googly eyes! These eyes are built from laser cut acrylic panels and motorized using a pair of NEMA-14 stepper motors. This post is the first in a series of three posts. In this post, we&#8217;ll build the googly eyes. In the 2nd post, <a href="http://bikerglen.com/blog/bringing-the-robotic-googly-eyes-to-life/">we&#8217;ll look at hardware and software to animate the googly eyes</a>. In the 3rd and final post, we&#8217;ll connect the eyes to OpenCV to make them <a href="http://bikerglen.com/blog/tracking-people-with-the-googly-eyes-and-opencv/">track motion and faces in a room</a>.</p>
<p><span id="more-392"></span></p>
<p><strong>3D Model</strong></p>
<p>Before buying any parts or doing any building, I designed the eye balls in Autodesk Fusion 360. A 3D model of the eyeballs can be viewed online using their free 3D viewer software <a href="http://a360.co/1CytiFw" title="Googly Eyes 3D Model Web Viewer" target="_blank">here</a>. The 3D model was useful for making sure all the parts would fit together, building the bill of materials for the project, and seeing where all the pieces go when it was time to assemble the googly eyes. A Fusion 360 archive file for the googly eyes can be downloaded <a href="https://github.com/bikerglen/googly-eyes/raw/master/mechanical/googly-eyes-3d-model-fusion360-archive.f3d" title="Googly Eyes 3D Model Fusion 360 Archive File">here</a>.</p>
<p><strong>Required Parts</strong></p>
<div id="attachment_398" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00163.jpg"><img src="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00163-1024x682.jpg" alt="The parts required to build a set of robotic googly eyes." width="640" height="426" class="size-large wp-image-398" /></a><p class="wp-caption-text">The parts required to build a set of robotic googly eyes.</p></div>
<p>The parts for this project are listed below. The total cost was about $85 excluding the shipping and handling charges.</p>
<ul>
<li>2 Pololu NEMA-14 35x28mm Stepper Motors, Item #1208, $12.95 ea</li>
<li>1 Pololu 2-Pack of Aluminum Mounting Hubs for 5mm Shafts, M3 Holes, Item #1998, $7.49 for 2</li>
<li>8 Keystone #6 Aluminum Round Spacers, 1/2&#8243;, Item #3466, $0.37 ea</li>
<li>6 Keystone 6-32 Aluminum Hex Standoffs, 1-3/4&#8243;, Item #1819, $1.00 ea</li>
<li>4 M3-0.50 x 8mm Black Oxide Button Head Socket Cap Screws, McMaster-Carr #91239A113, $6.43 for 100</li>
<li>12 6-32 x 0.375&#8243; Button Head Socket Cap Head Screws, McMaster-Carr #92949A146, $3.93 for 100</li>
<li>8 M3-0.50 x 18mm Button Head Socket Cap Screws, McMaster-Carr #92095A472, $6.00 for 100</li>
<li>2 Laser Cut Acrylic Eye Whites (scleras)*</li>
<li>2 Laser Cut Acrylic Eye Blacks (pupils)*</li>
<li>1 Laser Cut Acrylic Wall Mounting Plate*</li>
</ul>
<p>*DXF files for use at Ponoko are provided in the next section. The materials and cutting cost was $38.17.</p>
<p><strong>Cutting the Acrylic Pieces</strong></p>
<p>I had Ponoko cut the acrylic pieces for the googly eyes. Total cost excluding shipping was $38.17 at the time I built my pair of googly eyes. You&#8217;ll need the two design files below.</p>
<p><a href="https://github.com/bikerglen/googly-eyes/raw/master/mechanical/p2_nema_14_white_sclera_0.118.dxf">p2_nema_14_white_sclera_0.118.dxf</a><br />
<a href="https://github.com/bikerglen/googly-eyes/raw/master/mechanical/p2_nema_14_black_pupils_0.118.dxf">p2_nema_14_black_pupils_0.118.dxf</a></p>
<p>(Right click and choose save as if you have trouble downloading the files.)</p>
<p>Both of these files are sized to be cut from Ponoko&#8217;s P2-sized material. The file p2_nema_14_white_sclera_0.118.dxf contains two scleras (the white parts of the eyes). I cut these out of glossy white 3mm acrylic. The file p2_nema_14_black_pupils_0.118.dxf contains four pupils and two wall mounting brackets. I cut these out of glossy black 3mm acrylic.</p>
<p><strong>Assembly</strong></p>
<p>Start assembly by attaching the mounting hubs to the shafts of the stepper motors. The top of the hub should sit flush with the end of the shaft. Tighten the set screws to their final torque. The photo in the parts list above shows the hubs mounted to the stepper motors.</p>
<div id="attachment_414" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00173.jpg"><img src="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00173-1024x682.jpg" alt="Postion of motor and spacers on the rear of the eye white. Notice the wires exit the stepper motor away from the 1.75&quot; spacers." width="640" height="426" class="size-large wp-image-414" /></a><p class="wp-caption-text">Postion of motor and spacers on the rear of the eye white. Notice the wires exit the stepper motor away from the 1.75&#8243; spacers.</p></div>
<p>Next up is to connect the motors to the rear of the eye whites. Insert one of the M3-0.5 x 18mm screws through one of the four smaller holes on the front of the acrylic eye white. Place a spacer on the screw on the back side of the eye white then insert the screw into the corresponding mounting hole on one of the stepper motors. Point the side of the stepper motor with the wires down and away from the three larger 6-32 holes so that the wires will clear the spacers that are installed in the next step. Repeat this procedure for the remaining three M3 screws then repeat for the second eyeball.</p>
<div id="attachment_415" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00168.jpg"><img src="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00168-1024x682.jpg" alt="The motor and spacers mounted to the rear of the eye whites." width="640" height="426" class="size-large wp-image-415" /></a><p class="wp-caption-text">The motor and spacers mounted to the rear of the eye whites.</p></div>
<p>Now connect the eye whites to the spacers. The spacers will connect the eyeballs to the wall mounting plate. Insert a 6-32 x 0.375&#8243; screw through one of the three larger holes on the front side of the acrylic eye white. Tighten a spacer onto the screw on the rear of the eye white. Repeat this procedure for the two remaining 6-32 screw holes then repeat for the second eyeball.</p>
<div id="attachment_417" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00181.jpg"><img src="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00181-1024x432.jpg" alt="Side view of the googly eyes mounted on the wall hanging bracket." width="640" height="270" class="size-large wp-image-417" /></a><p class="wp-caption-text">Side view of the googly eyes mounted on the wall hanging bracket.</p></div>
<p>Acrylic scratches easily so carefully flip the assembly over and place it on a soft surface such as a towel. Position the wall mounting bracket over one of the eyeballs. Insert a 6-32 x 0.375 screw through the wall mounting bracket and into the corresponding spacer on the eyeball. I mounted my wall mounting bracket to the eyeballs such that the motor wires exited the bottom when the wall mounting bracket is hung on the wall. Holes are provided for either orientation. Finish attaching the first eyeball to the wall mounting bracket then repeat for the second eyeball.</p>
<p>Flip the eyeballs over and use the M3-0.5 x 8mm black oxide screws to mount the pupils to the mounting hubs on the ends of the stepper motors.</p>
<p>Congratulations! You&#8217;ve built your very own pair of giant robotic googly eyes! </p>
<div id="attachment_400" style="width: 650px" class="wp-caption alignnone"><a href="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00179.jpg"><img src="http://bikerglen.com/wp/wp-content/uploads/2015/04/DSC00179-1024x682.jpg" alt="Completed robotic googly eyes." width="640" height="426" class="size-large wp-image-400" /></a><p class="wp-caption-text">Completed robotic googly eyes</p></div>
<p><strong>Next Steps</strong></p>
<p>In the next post in this series, we&#8217;ll look at making the eyeballs move using <a href="http://bikerglen.com/blog/bringing-the-robotic-googly-eyes-to-life/">an Arduino and some simple stepper motor drivers</a>. In the final post, we’ll use OpenCV to make the googly eyes <a href="http://bikerglen.com/blog/tracking-people-with-the-googly-eyes-and-opencv/">track faces in the room</a>.</p>
]]></content:encoded>
			<wfw:commentRss>https://bikerglen.com/blog/build-a-pair-of-robotic-googly-eyes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
