Silicon ChipFlexible Digital Lighting Controller, part 2 - November 2020 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Why is electronics male-dominated?
  4. Feature: MEMS (Micro-Electromechanical Systems) by Dr David Maddison
  5. Project: Eight Small LED Christmas Ornaments by Tim Blythman
  6. PartShop
  7. Project: Two Large LED Christmas Stars by Barry Cullen & Tim Blythman
  8. Project: Balanced Input Attenuator for the USB SuperCodec by Phil Prosser
  9. Serviceman's Log: One repair leads to another by Dave Thompson
  10. Vintage Radio: RCA BP-10 "miniature" valve portable radio by Ian Batty
  11. Feature: A Rundown on New 8-pin PIC Microcontrollers by Tim Blythman
  12. Feature: The Vintage Matrox ALT-512 Graphics Card by Hugo Holden
  13. Project: Flexible Digital Lighting Controller, part 2 by Tim Blythman
  14. Feature: Electronic ‘Wearables’ and the Jaycar Sparkle Stitch by Tim Blythman & Nicholas Vinen
  15. Market Centre
  16. Advertising Index
  17. Notes & Errata: USB SuperCodec, August-October 2020; History of the Australian GPO, September 2020; Shirt Pocket Oscillator, September 2020; Frequency Reference Signal Distributor, April 2020; 45V 8A Linear Bench Supply, October-December 2019
  18. Outer Back Cover

This is only a preview of the November 2020 issue of Silicon Chip.

You can view 44 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Eight Small LED Christmas Ornaments":
  • Tiny LED Cap PCB [16111193] (AUD $3.00)
  • Tiny LED Stocking PCB [16111194] (AUD $3.00)
  • Tiny LED Reindeer PCB [16111195] (AUD $3.00)
  • Tiny LED Bauble PCB [16111196] (AUD $3.00)
  • Tiny LED Sleigh PCB [16111197] (AUD $3.00)
  • Tiny LED Star PCB [16111198] (AUD $3.00)
  • Tiny LED Candy Cane PCB [16111199] (AUD $3.00)
  • PIC12F1572-I/SN (or equivalent) programmed for the Tiny LED Christmas Ornaments (Programmed Microcontroller, AUD $10.00)
  • Tiny LED Christmas Ornament complete kit (Component, AUD $15.00)
  • Firmware for the LED Christmas Ornaments (Software, Free)
  • Eight Tiny LED Xmas Ornament PCB patterns (PDF download) [16111191-16111199] (Free)
Articles in this series:
  • Eight Small LED Christmas Ornaments (November 2020)
  • Eight Small LED Christmas Ornaments (November 2020)
  • Christmas LED Icicle Decoration (November 2022)
  • Christmas LED Icicle Decoration (November 2022)
Items relevant to "Two Large LED Christmas Stars":
  • Stackable LED Star PCB [16109201] (AUD $12.50)
  • RGB Stackable LED Star PCB [16109202] (AUD $15.00)
  • ATmega328P-AUR or ATmega88PB-AUR programmed for the RGB Stackable LED Star [1620920A.HEX or 1620920B.HEX] (Programmed Microcontroller, AUD $10.00)
  • Kit for the RGB Stackable LED Christmas Star (Component, AUD $40.00)
  • Firmware for the 30 RGB LED Xmas Star (Software, Free)
  • RGB Stackable LED Star PCB pattern (PDF download) [16209202] (Free)
  • Stackable LED Star PCB pattern (PDF download) [16109201] (Free)
Items relevant to "Balanced Input Attenuator for the USB SuperCodec":
  • USB SuperCodec PCB [01106201] (AUD $12.50)
  • USB SuperCodec Balanced Input Attenuator add-on PCB [01106202] (AUD $7.50)
  • Parts source grid for the USB SuperCodec (Software, Free)
  • USB SuperCodec PCB pattern (PDF download) [01106201] (Free)
  • USB SuperCodec Balanced Input Attenuator add-on PCB pattern (PDF download) [01106202] (Free)
  • USB SuperCodec front panel artwork (PDF download) (Free)
  • Drilling and cutting diagrams for the USB SuperCodec Balanced Input Attenuator (PDF download) (Panel Artwork, Free)
Articles in this series:
  • USB SuperCodec (August 2020)
  • USB SuperCodec (August 2020)
  • USB SuperCodec – part two (September 2020)
  • USB SuperCodec – part two (September 2020)
  • USB SuperCodec – part three (October 2020)
  • USB SuperCodec – part three (October 2020)
  • Balanced Input Attenuator for the USB SuperCodec (November 2020)
  • Balanced Input Attenuator for the USB SuperCodec (November 2020)
  • Balanced Input Attenuator for the USB SuperCodec, Part 2 (December 2020)
  • Balanced Input Attenuator for the USB SuperCodec, Part 2 (December 2020)
Articles in this series:
  • The Matrox ALT-256 Graphics Card (October 2020)
  • The Matrox ALT-256 Graphics Card (October 2020)
  • The Vintage Matrox ALT-512 Graphics Card (November 2020)
  • The Vintage Matrox ALT-512 Graphics Card (November 2020)
Items relevant to "Flexible Digital Lighting Controller, part 2":
  • Flexible Digital Lighting Controller main PCB [16110202] (AUD $20.00)
  • Flexible Digital Lighting Controller Micromite Master PCB [16110201] (AUD $5.00)
  • Flexible Digital Lighting Controller CP2102 Adaptor PCB [16110204] (AUD $2.50)
  • Flexible Digital Lighting Controller LED slave PCB [16110205] (AUD $5.00)
  • PIC16F1705-I/P programmed for the Flexible Digital Lighting Controller [1611020A.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC32MX170F256B-50I/SP programmed for the Flexible Digital Lighting Controller Micromite master [1611020B.hex] (Programmed Microcontroller, AUD $15.00)
  • PIC16F1455-I/P programmed for the Flexible Digital Lighting Controller WS2812 Slave [16110205.HEX] (Programmed Microcontroller, AUD $10.00)
  • Si8751AB 2.5kV isolated Mosfet driver with integral power supply (Component, AUD $10.00)
  • Micromite LCD BackPack V3 complete kit (Component, AUD $75.00)
  • Hard-to-get parts for the Flexible Digital Lighting Controller (Component, AUD $100.00)
  • Flexible Digital Lighting Controller front panel PCB [16110203] (AUD $20.00)
  • Firmware and software for the Fiexible Digital Lighting Controller (Free)
  • Firmware and PC software for the Digital Lighting Controller [1611010A.HEX] (Free)
  • Flexible Digital Lighting Controller mains slave PCB patterns (PDF download) [16110202-3] (Free)
  • Flexible Digital Lighting Controller Master PCB patterns (PDF download) [16110201, 16110204] (Free)
  • Flexible Digital Lighting Controller LED slave PCB pattern (PDF download) [16110205] (Free)
  • Drilling and cutting diagrams for the Flexible Digital Lighting Controller Micromite master (PDF download) (Panel Artwork, Free)
  • Cutting diagram for the Flexible Digital Lighting Controller mains slave rear panel (PDF download) (Panel Artwork, Free)
  • Cutting diagrams and front panel artwork for the Flexible Digital Lighting Controller LED slave (PDF download) (Free)
  • Matte/Gloss Black UB3 Lid for Micromite LCD BackPack V3 or Pico BackPack using 3.5in screen (PCB, AUD $5.00)
Articles in this series:
  • Flexible Digital Lighting Controller, part 1 (October 2020)
  • Flexible Digital Lighting Controller, part 1 (October 2020)
  • Flexible Digital Lighting Controller, part 2 (November 2020)
  • Flexible Digital Lighting Controller, part 2 (November 2020)
  • Flexible Digital Lighting Controller, part 3 (December 2020)
  • Flexible Digital Lighting Controller, part 3 (December 2020)
  • Digital Lighting Controller Translator (December 2021)
  • Digital Lighting Controller Translator (December 2021)

Purchase a printed copy of this issue for $10.00.

Flexible D i g i ta l Lighting Controller Part two – Controlling it – by Tim Blythman Our new Digital Lighting Controller is a great way to control Christmas lighting displays, among many other applications. We described the fourchannel slave unit last month, which does the actual light dimming. Now we will explain a few different ways to control one or more of them. T he first article in this series described a follow-up to our hugely successful Digital Lighting Controller from 2010. There are several significant advantages to the new unit. It can control twice as many lights (64 compared to 32) as well as RGB LED strips. It also gives you more options for controlling the light show, including using an Arduino, a Micromite or a PC. The new slave unit also uses a Mosfet-based trailing edge dimming technique, making it compatible with new94 Silicon Chip er LED lamps. It receives serial data via an optoisolator, making the interface simple and safe. That means that you can control the lights directly from a computer, using not much more than a tiny USB-serial adaptor, such as the common CP2102based types. As such, we’ve designed a small adaptor board with a USB socket at one end and a Cat5 socket at the other, making this dead easy. We have also written PC software that can be used to run the Digital LightAustralia’s electronics magazine ing Controller using this Adaptor, written in the cross-platform programming language, “Processing”. We’re providing a few sample programs to demonstrate different possibilities. As well, we have designed a PCB for a Micromite-based master controller. While this is based on the Micromite V3 BackPack hardware, we are programming it in C (and not Micromite’s native BASIC) for improved performance and some extra features needed in this role. We’ll also describe an Arduinobased master unit. siliconchip.com.au Communications protocol The serial protocol we are using to communicate between the slave unit and master unit of the Digital Lighting Controller is inspired by DMX512, which uses serial data at 250,000 baud over an RS-485 differential physical layer. Our system, on the other hand, operates at 38,400 baud with a logic-level single-ended signal, making it compatible with virtually any microcontroller or computer. The 8-bit raw serial data gives 256 brightness levels for each light. At a binary level, the data is practically indistinguishable from that used in DMX512 (see https://en.wikipedia.org/wiki/ DMX512). It’s only the electrical part of the protocol that differs. One simple trick The DMX-512 protocol (and by extension, ours) relies on devices receiving a serial ‘break’ to synchronise with the master controller. This happens when the serial signal sits at a logic zero level for an entire data byte (eight bits) plus the stop bit. As the receiver does not see the stop bit, it assumes a framing error has occurred (the transmitter has not sent correctly framed data) – see Fig.9. To guarantee that a break is received correctly, most transmitters will send around 13 bit-times of zero. DMX-512 requires 23 bit-times at the zero level, followed by at least three bit-times at the one level (called a “mark after break”). Since a break is not normal data, we also need a special way of sending it. We’ll explain three different options. Hardware break Some hardware, especially devices like USB-serial converters, can send a break automatically. This requires a Fig.9: the serial break signal is necessary to synchronise data between the master and slave units. It’s not as simple to send as normal serial data, but there is generally a way to do it. special command, and the controlling software must be able to issue it. During our testing, we found that TeraTerm (a popular Windows serial terminal program) can send a break by using the Alt-B key combination. Paired with a CP2102 USB-Serial converter, we were able to successfully send commands to slave units by pressing Alt-B (to send a break), then Alt-<at> (to send a 0x00 byte) followed by the data. While handy to know about, this technique is not available on all hardware or through the software interface of the Processing programming language, so we investigated other options. Baud rate A well-known trick for sending a break on serial hardware with variable baud rates is to send carefully crafted data at a slower baud rate. An example can be seen at the bottom of Fig.9. Here, a zero byte at a slower (by half) baud rate appears to be a break condition to the receiver, which is operating at a higher baud rate. This is what we have done for the Processing program we have created. We switch from 38,400 baud to 9600 baud and transmit a 0xC0 byte. At 38,400 baud, this is equivalent to 28 bit times (one start bit and six data bits times four) at the zero level followed by 12 bit times (two data bits plus one stop bit times four) at the one level, which satisfies the DMX-512 break and makeafter-break criteria. Bit-banging The final technique (which we use in our Arduino and Micromite code) is to take control of the serial output pin and manually hold it low for an appropriate time. The isn’t an option under the Processing language, as we don’t have direct hardware control. Still, it is quite easy with many microcontrollers, where direct control of the I/O pins is possible. Our Micromite master unit uses a variant of this. Since 38,400Hz is close to many audio sample rates, we control both the audio and serial data via an interrupt which is triggered 38,400 times per second. The interrupt directly drives the output pin for the serial data, producing the break condition by counting out (Left): the Micromite Master consists of a Micromite V3 Backpack and 3.5in touch panel paired with this add-on board. (Below): a simpler option allowing Slave units to be controlled from a PC is shown below. A small PCB connects to a CP2102 USB-Serial adapter. siliconchip.com.au Australia’s electronics magazine November 2020  95 enough zero and one bits, followed with the serial data. So it is effectively a software serial solution that also incorporates the break. Master hardware Our most basic controller design is the CP2102 Adaptor PCB, which connects a low-cost CP2102 USB/Serial adaptor to a Cat5 cable. Last month, we said that you could simply use a Cat5 test cable with an Arduino Uno or similar for testing. But if you are trying to operate multiple slaves, the 6N137 fast optoisolator on the slave units requires a reasonable amount of current to work correctly – at least 5mA. The 220Ω resistor on each slave ensures that it will work even with a 3.3V signal. But under more typical conditions and with a 5V supply, the slave unit can consume up to 16mA. Many microcontrollers can only supply 20mA per pin, so you’ll probably only be able to drive two or maybe three slave units directly. Even then, the microcontroller pin will be working quite hard. Our CP2102 Adaptor includes a driver circuit capable of delivering around 200mA so that it can drive more slave units; up to 16, in fact. Conveniently, it also has an RJ45 socket, so pre-made Cat5 leads plug right in. Its circuit is shown in Fig.10. CON1 is a six-way header which corresponds to the most common type of CP2102 module. The CP2102 can either be soldered onto this board or plugged in via a header socket. This circuit is designed to work with the 3.3V versions of the CP2102 module, but should work with 5V versions too SC Ó (we haven’t tested it, though). The serial signal from the computer is fed to the base of PNP transistor Q1 via a 10kΩ resistor. When TX is high, which is the idle state, no base current flows and the second 10kΩ resistor pulls Q1’s collector low. When TX is low, Q1 conducts and Q1’s collector voltage goes to +3.3V. So the output signal is inverted. N-Channel Mosfet Q2 forms a second inverter. In the idle state, it is off as its gate is held low by the 10kΩ resistor. When TX goes low, Q2 switches on, pulling its drain low and allowing current to flow through DATA+/DATAlines from the 5V rail. The 27Ω 1W protects Q2 from a short circuit across the DATA+ and DATA- pins while still ensuring that all slave units receive enough current, even if a full complement of 16 are attached. We haven’t added any capacitors as such a device will usually be attached to a computer’s USB port, and the USB specifications say that a maximum of 10µF should be present on the bus. Since the CP2102 module already has a 10µF capacitor on board, we can’t add more. But the 10µF that is present will help to stabilise the 5V rail on our module. You could also use this converter board with other serial sources. They must be logic-level (not RS-232 or RS485), but they can use either 5V or 3.3V signalling. If using 5V signalling, pin 1 of CON1 should be connected to a source of 5V rather than 3.3V. Thus, you can use this hardware with an Arduino board to drive multiple slave units. See Fig.13 for an example of how to do this. A 3.3V Micromite can drive it too, using wiring DLC CP2102 INTERFACE Fig.10: the CP2102 interface is simple, but allows a computer to control the full complement of up to 16 slave units (controlling 64 sets of lights!). Mosfet Q2 can supply up to 200mA to drive the 16 optos in such a setup. 96 Silicon Chip Australia’s electronics magazine similar to that for the CP2102 USBSerial adaptor. CP2102 Adaptor construction Referring to the PCB overlay diagram (Fig.11), start by fitting the two 10kΩ resistors and follow with the larger 1W resistor. Place Q2 next. Check that it is the 2N7000 part and orientate it to match the silkscreen on the PCB. Crank its leads out, if necessary. Do the same for Q1 and trim the leads for both transistors. Slot the RJ45 socket (CON2) in place and ensure it is flat against the PCB. The tabs should help to hold it in place. Solder two end pins and confirm the part is still flat and square before soldering the remainder. As discussed, you may wish to solder the CP2102 Adaptor PCB directly to your CP2102 USB-Serial Adaptor. In this case, we recommend soldering a pin header for CON1, then solder the CP2102 USB-Serial Adaptor to the top of these pins. Alternatively, since most CP2102 USB-Serial adaptors are fitted (or at least supplied) with headers, you can fit the CP2102 Adaptor board with a female header socket. This is soldered to the top of the PCB (as seen in the photo), then bent over to align with the CP2102 USB-Serial adaptor header. Some heatshrink tubing applied to the whole assembly will provide protection and insulation. But leave the heatshrink off until you’ve tested it and confirmed that it works. Once the whole unit is assembled, connect its USB plug to a computer and run a CAT5 cable from the CP2102 adaptor to your first Digital Lighting Controller slave unit. The COM light on the slave unit should not light up Fig.11: the USB Adaptor board is easy to make, thanks to the prebuilt USB-Serial module. Just fit the few parts as shown here and you’re ready to connect your PC to the lighting controller slave units. siliconchip.com.au Screen1: Processing is easy to learn and is similar to the Arduino IDE. Creating your own sequence software is as simple as writing values to an array which is then automatically sent to the slaves. yet; if it does, there may be a problem with your construction. You don’t need to connect any lamps yet as the front panel LEDs will provide feedback, but you can if you want to. Testing Most up-to-date operating systems have built-in support for these devices and it will be automatically recognised on being plugged in. If this doesn’t happen, you can download drivers from siliconchip.com.au/link/ab59 If you have a terminal program like TeraTerm, you can use this to communicate with the Digital Lighting Controller slave unit. Open a connection to the correct serial port (eg, COM port on Windows) and set the baud rate to 38,400. Then send a break with Alt-B, then a 0x00 byte with Ctrl-2 (the same as Ctrl<at>, but there’s no need to press shift). Any non-zero data bytes following this should cause the CH0-CH3 LEDs to light on a connected slave (depending on what address is set). You can press the tilde key (~) as it has a relatively high ASCII value of 126. Other terminal programs may work similarly, but we haven’t tested these. PC control software We’ve written some sample programs in the Processing language to interface with the CP2102 Adaptor. We’ve used Processing for a few reasons: it’s freely available, open-source and available on Windows, Mac and Linux and there is even an Android variant. Thus it’s a siliconchip.com.au Screen2: the Digital Lighting Controller Processing sample program allows lamps to be controlled using sliders. You can use our sample code to create your own sequence and control software. great choice for making software that can be used on many computers. It is based on Java. As we have mentioned previously, the Arduino IDE is based on Processing. So if you’ve had experience with Arduino, then you should be at home with Processing. We’re using Processing version 3.5.3 on Windows 10, although we did test our programs on a Raspberry Pi running Processing 3.4 too. You can download Processing from https://processing.org/download/ Once installed, you can also export a standalone app for your platform (you will also need to have Java installed to run the standalone app). Once Processing is installed, open the sketch program in our download package (“Simple_DLC_Master”) using the File -> Open menu option. You should see the first few lines of the code, as shown in Screen1. Then run it using Ctrl-R or by pressing the green play arrow. This simple program provides basic control of up to 16 lamp channels – see Screen2. The serial port (COM port under Windows) is selected by pressing “+” or “-” and then press “s” to start a connection. The COM port name will light up green, and the COM light on the slave unit should start flickering in time with the “TX” icon on the application. If it doesn’t light up green, then the serial port may not be available or may be in use by another program. Clicking on the sliders changes the output levels and thus the brightness Australia’s electronics magazine of any connected lamps. You can press the “OFF” button to set all the lights to the off state immediately. If all this is working well, your Digital Lighting Controller System is complete and functional. You may wish to use this program as the basis for your own custom controller, but we still have a few more options to show you. Lights and sound We’ve also written a Processing program which emulates the basic features of the master unit used with the 2010 Digital Lighting Controller. So you can use the existing sequencing software to generate sequences (accompanied by music) to run on the newer Digital Lighting Controller hardware. That software is included in the download package for this project. The older software was limited (by the file format it generates) to controlling 32 channels, so this program is also. But you could use our software as the basis of a system which synchronises sound and lights for more than 32 channels with some modifications. The sketch is called “Digital_Lighting_Controller”, and it uses an external library to provide some features; in this case, the audio playback. The library can be added in the Processing IDE by clicking Sketch -> Import Library… -> Add Library… (see Screen3); Then type the word ‘minim’ in the search window; this is the name of the library. The correct library is shown in Screen4. Click this item and then click install. Open the sketch and run it. A window November 2020  97 Screen3: we are using the ‘minim’ Processing library for audio playback so that we can synchronise the light display with sound. The library system works similarly to Arduino libraries, although the interface is a bit different. should appear, as shown in Screen5. This has some control buttons at the top, the status of the first 32 output channels below, and details on the file currently being played at the bottom of the screen. We have included some demonstration sequences but could not include music due to copyright – see the text file accompanying the demo sequences for details. The original music files are still available online but need to be converted to a PCM (uncompressed) WAV format, for example, using software like Audacity (a free download). For more information on using the original Christmas Light Controller software, refer to the December 2010 issue, starting on page 66 (siliconchip. com.au/Article/391). There are seven pages in that issue explaining how the sequencing software works, so it’s well worth a read if you plan to use it. It can create two file types. Those with the LSN file extension are simply lighting sequences and will play on their own. Those with an LSQ file extension are similar but must be accompanied by a WAV file of the same name, which will be played at the same time. In our Processing software, use the “Open” button to select a file of either LSN or LSQ type. Then click the “Up” or “Down” buttons to scroll through the available serial ports to find the CP2102 Adaptor. Finally, click on the COM port name to connect to it. At this point, the COM light on the slave units should start flashing. Now click the “Play” button to start the sequence playback. The mimic lights on 98 Silicon Chip Screen4: search for ‘minim’ in the Contribution Manager screen; the correct item is highlighted here. This is the only extra software that is needed to work with our example code. the window should flash in time to those connected to the slave units, and music will play from your computer. The “Pause” and “Stop” buttons work as you would expect. Micromite master We have also put together some test software for both the Micromite and Arduino platforms. These programs are simple, but are a good start for those wishing to design their own controller, especially to control more than 32 lighting channels. If you would prefer a standalone master unit, we’ve also designed a Micromite based unit that can do the same job as the PC software described above, without tying up your computer. Like the older dsPIC-based design, it reads data from an SD card and produces a stereo audio output plus serial data to control the lamps. Now, while we say it’s based on a Micromite, due to the amount of computing power involved, it wasn’t possible to make this work in the BASIC language (ie, using MMBasic). Fortunately, it is easy to program the Micromite hardware with ‘C’ code compiled using Microchip’s MPLAB X software. You’ll need the Micromite V3 BackPack hardware to build our Micromite master. There are two reasons for this. The first is that the V3 BackPack is the only one that has the SD card socket wired back to the microcontroller. The second is that the V3 BackPack supports the larger 3.5in ILI9488 LCD module. This has 480 x 320 pixels, and we use this to display more information Australia’s electronics magazine than would be possible on the smaller 2.8in displays. For information on building the V3 BackPack, see our August 2019 issue (siliconchip.com.au/Article/11764). But construction is pretty self-explanatory, and we sell a complete kit for this module (siliconchip.com.au/ Shop/20/5082). So you shouldn’t have trouble building it even if you don’t have that magazine; there’s no need to add any of the optional components. Since the SD card uses pin 4, make sure you don’t fit a memory chip, as it would interfere with SD card operation. You will also need to make a small add-on board; its circuit is shown in Fig.12. This provides extra hardware interfaces, including the lighting slave driver. That part of the circuit is identical to the circuit of the CP2102 Adaptor shown in Fig.10. The serial output is also available at pin header CON3 for testing purposes. The board also includes a stereo audio output via a 3.5mm headphone socket. The Micromite produces the audio signals as a PWM signal on pins 5 (left) and 24 (right) of I/O header CON1. A pair of 10kΩ resistors provide a 2.5V midpoint on the 5V rail to re-bias these signals, which is bypassed by a 220µF capacitor. We’ll follow the left channel from here as the right is identical in operation. The PWM signal is low-pass filtered by a 3kΩ series resistor and 100nF capacitor to the 2.5V rail to remove the PWM signal and harmonics. It is then AC-coupled and biased to 2.5V, then fed to non-inverting input pin 3 of op amp IC1. Our prototype uses an LMsiliconchip.com.au Screen6: the PIC32PROG GUI is the simplest way to program the PIC microcontroller for this project. It can also be used to reinstate the MMBasic interpreter, in case you ever need to do that. Screen5: our demo software plays sequence files generated by the original Digital Lighting Controller software from 2010. It has lamp mimics so you can easily check that everything is working as expected. C6482AIN, but we also successfully tested the lower-voltage MCP6272. IC1 is configured for unity gain by direct feedback from output pin 1 to inverting input pin 2 through a 3kΩ resistor. Since we are using a 3.3V Micromite, the output swing is at most 3.3V and should not stray too close to SC Ó the op-amp’s 0V and 5V rails. Still, a rail-to-rail op-amp is preferred due to the low headroom. The output from the op-amp is again AC-coupled by a 1µF capacitor and biased to circuit ground by a 22kΩ resistor. A 100Ω series resistor isolates the output from the external wiring. DIGITAL LIGHTING CONTROLLER MASTER siliconchip.com.au The buffered stereo signals are fed to stereo 3.5mm socket CON4, and can be used as a line-level signal to feed to an amplifier, or for driving headphones. PIC32 software As we mentioned, BASIC is too slow to handle both the audio and control Fig.12: the Micromite master board includes the same driver circuit as the CP2102 Adaptor, plus an op-amp circuit to feed audio from the PIC32 to a 3.5mm stereo jack socket. Australia’s electronics magazine November 2020  99 data. But our solution (written in C) should still look familiar to those who use the graphical capabilities of the Micromite BackPack. At power-up, it shows a splash screen while it scans the SD card. It looks for sequence files (with LSN or LSQ file extensions) and displays a count of those found. If there is an error (for example, no card is inserted), an error code and message is shown. The “Reset” button can then be used to perform a soft reset of the microcontroller, which might clear the error. The control signal (on the RJ45 socket CON2) is sent the whole time the unit is running, so you should see the COM light of the attached slaves light up. When the scan is complete, two options are shown. The first is “Test mode”. Pressing this goes to a screen showing 16 sliders and three buttons. The “Toggle” button at left cycles between the four groups of 16 sliders, to allow the control of any of the 64 lamp outputs. Touching the slider above will adjust the brightness of that lamp. The “Tone” button toggles a 600Hz sine wave output at the audio socket CON4. The sound continues for a short while after being turned off due to buffering (the RAM buffers for audio and control data total 28kB). “Exit” returns to the main page. If all is well, the second button labelled “Continue” leads to a page with playback controls. The playback screen shows information about the currently selected sequence, including its duration and information about any associated WAV file. Fig.14: this Micromite add-on board can be attached to the main Micromite V3 BackPack via female header 220mF strips, as shown here, or you can solder pin headers to this board and sockets to the BackPack. The rest of the construction is straightforward; lay the electrolytic capacitor over and ensure its orientation is correct. Also check the orientation of IC1 and don’t mix up Q1 and Q2. Pressing “Play” starts playback of the sequence. It can be paused with the “Pause” button, which will light up when it is active. Play can also be used to resume from a pause. The “Loop” button cycles between “Loop off”, “Loop one” and “Loop all”. The “Next” and “Previous” move between sequences manually. If a track is playing, Previous returns to the start of the current track, while it moves to the previous track if playback is stopped or paused. In summary, this Micromite master code provides similar features to the original Digital Lighting Controller master, but is more intuitive to drive and has the extra test mode features. Software operation The software starts by initialising the LCD, SD card and other I/O peripherals and starts a timer interrupt. The 38,400Hz timer interrupt manages quite a few things. The main tasks are to shift out the serial data to control attached slaves, and to play back the audio data. A state machine cycles through producing a break condition, a make condition and then the 65 data bytes that are sent. At the end of each cycle (which Fig.13: this shows how to connect an Arduino board (in this case, an Uno) to lighting slaves using the CP2102 interface. You can use our example code as a starting point for your own lighting control software. 100 Silicon Chip Australia’s electronics magazine lasts around 17ms), the software also checks if the sequence data requires any of the lamp brightness values to change. Another part of the interrupt routine processes data from 56 x 512-byte audio buffers, which are effectively raw WAV data. Compensation is made for the difference between the playback rate (38,400Hz) and the audio sample rate, and whether the sample format is 8-bit or 16-bit, stereo or mono. As each buffer empties, it is marked as empty, and the next is processed. The main loop re-loads empty buffers from the SD card. This is so that the SPI peripheral is not interrupted by the interrupt routine, which would cause data corruption if it was not managed very carefully. The 28kB buffer allows audio to play for about 1/6 second at CD quality. When all the buffers empty, playback stops. The sequence data is managed similarly, although its size is not proportional to its playback length. The test tone is 600Hz because the 512-byte buffers are filled with eight 64-cycle samples of sinewave data. Using whole sinewave cycles means that the software doesn’t have to keep track of what part of the wave it is producing; it merely fills each block with the same data each time. Projects with a graphical interface always devote a lot of resources to this, and much of the code is for displaying data on the LCD. This is kept to a minimum during playback, to reduce demand on the processor when it is working hardest. Construction We’ll assume that you’ve already built the Micromite V3 BackPack and have the mounting parts for the 3.5in LCD. Note that if you order the Microsiliconchip.com.au This PCB turns a Micromite V3 Backpack into a controller capable of playing WAV audio and driving the Slave units of our Digital Lighting Controller. mite V3 BackPack kit from the SILICON CHIP ONLINE SHOP (Cat SC5082), you have the option to have the chip preprogrammed for this project. The add-on PCB is quite simple, so building it will probably take less time than the BackPack. Refer to its overlay diagram, Fig.14, during construction. Start by fitting the smaller resistors where shown. Use a multimeter to check the values if you aren’t sure about the colour bands. Follow with the larger 1W resistor near CON2. Fit the 1µF ceramic capacitors next, as they are small and have a low profile. These are not polarised, so can be fitted either way. Follow with the 100nF MKT capacitors. The single electrolytic capacitor needs to be laid on its side to fit into the PCB stack. Bend its leads, observing their polarity (longer lead = positive) and solder it to the PCB. Install the transistors next, being sure not to mix them up. The BC557 (PNP) is near the top of the PCB with the Nchannel Mosfet underneath it. Be sure to align them with their footprints; you may need to crank the leads to fit their pads. Parts list – CP2102 Adaptor module 1 PCB coded 16110204, 45 x 20.5mm 1 CP2102 USB-Serial converter [SILICON CHIP ONLINE SHOP SC3543] 1 6-way female header socket (CON1) OR 1 6-pin header (CON1) – see text 1 RJ45 PCB-mount socket (CON2) [Altronics P1448] 1 BC557 PNP transistor, TO-92 (Q1) 1 2N7000 N-Channel Mosfet, TO-92 (Q2) 2 10kW 1/4W or 1/2W resistors 1 27W 1W resistor 1 10cm length of 25mm diameter heatshrink tubing (optional; clear is ideal) IRM-02-5 module availability Since last month, many vendors have sold out of the Meanwell IRM-02-05 module. Digi-key was expecting more stock around late October but this may sell quickly too. If you can’t get the IRM-02-05, use the IRM-01-5. It is a drop-in replacement; the only difference is its 1W rating instead of 2W. The board draws less than 1W – ­the only reason we didn’t specify the IRM-01-5 initially is that the difference in price is very small. siliconchip.com.au The usual arrangement for the Micromite 18-way header is to fit the male header to the Micromite BackPack PCB and the female header to the PCB below this, although the reverse will work perfectly well. This might be necessary if you have previously fitted the female header to the Micromite BackPack, as we did with our Micromite RCL Box (June & July 2020; siliconchip.com.au/ Series/345). Fit the headers, ensuring both are square. You might like to temporarily secure the boards together using the 12mm tapped spacers and machine screws. We fitted the four-way header to our boards too, but it is not strictly necessary as the master unit PCB does not have a corresponding socket. Solder IC1 in place, observing the pin 1 notch orientation. We used a socket so we could try different op amps, but you will get more reliable results by soldering this chip directly to the PCB. Finally, add CON2 and CON4. CON3 (the serial data header) is entirely optional. Push each connector down firmly onto the PCB. In particular, the RJ45 socket does not have much clearance above it, so it must be flat against the PCB. Solder one pin in place and check Parts list – Micromite master module 1 Micromite V3 BackPack with 3.5in LCD (kit Cat SC5082, programmed with 1611020B.HEX) 1 USB Type-A to Mini-B cable 1 double-sided PCB coded 16110201, 86 x 55mm 1 UB3 Jiffy box [Jaycar HB6013, Altronics H0203] 2 M3 x 12mm tapped spacers 2 M3 x 25mm machine screws 1 18-pin header (CON1) 1 18-way female header socket (CON1) 1 RJ45 PCB-mount socket (CON2) [Altronics P1448] 1 2-pin header (CON3; optional) 1 PCB-mount stereo 3.5mm socket (CON4) [Altronics P0094] Semiconductors 1 LMC6482AIN or MCP6272 dual rail-to-rail op-amp, DIP-8 (IC1) 1 BC557 PNP transistor, TO-92 (Q1) 1 2N7000 N-channel Mosfet, TO-92 (Q2) Capacitors 1 220µF 16V electrolytic 4 1µF ceramic 3 100nF MKT Resistors (all ¼W 1% metal film, except where noted) 4 22kW 4 10kW 4 3kW    2 100W 1 27W 1W 5% Australia’s electronics magazine November 2020  101 each connector is still flat before soldering the remaining pins. Plug the PCB into the back of the Micromite BackPack for testing and programming. Most modern operating systems will already have drivers for the Microbridge USB interface, but if not, instructions can be found in the original Micromite BackPack article. Programming the PIC Unless you have purchased a preprogrammed microcontroller or kit, the PIC32 on the BackPack needs to be programmed with a HEX file. Since we are not using BASIC, we can’t use the regular MMBasic upload method, but you can use the onboard Microbridge IC over USB, which is the simplest method. Alternatively, if you have a PIC programmer such as a PICkit 3, PICkit 4 or Snap, you can program the chip using that. We fitted a right-angled header to the ICSP header on the BackPack so that it wouldn’t foul the boards above or below. But it did protrude far enough to hit the enclosure. We simply shortened our pins slightly (by about 1mm) with a pair of sidecutters to solve that. Microbridge programming We previously described how to use the Microbridge to program a HEX file to the PIC32 on the Micromite BackPack using the command line. But there is also a Windows GUI program available called “P32P GUI” (see Screen6). It can be downloaded from the Back Shed Forum at www.thebackshed.com/docregister/ ViewDoc.asp?DocID=21 Extract the program from the ZIP file and run it. Select the HEX file (16110201.HEX, available from our website) using the “select file” button, then press the pushbutton on the Micromite BackPack PCB; the LED on the BackPack should light up, indicating that it is ready to be programmed. Then push the “flash PIC32” button to start the process. Once complete, the LCD should show the main screen. also connect speakers or headphones to the 3.5mm socket. Check that you get a test tone and that the slave responds to commands. There is also some debugging data output at 38,400 baud on the USB-serial adaptor (Microbridge), which you can view using a serial terminal program such as TeraTerm. You can copy the sample LSQ files from our software bundle to an SD card; even without WAV files, you will be able to initiate playback of the lamp sequences. Use the Digital Lighting Sequencer software (originally written for the 2010 Lighting Controller) to generate custom sequences. PICkit programming Finishing the master unit While the PICkit 3 and PICkit 4 (but not Snap) can supply power when programming the chip, it is best to power it from the USB socket if the LCD is attached, as its backlight requires substantial current. In the Microchip IPE, select “PIC32MX170F256B” as the part, click “Apply”, then “Connect”. Browse for the HEX file, then click “Program”. The LCD should light up with the splash screen. To complete the board stack, remove the two spacers closest to the main (14-way) LCD header. Thread 25mm machine screws through the acrylic front panel, washers and LCD PCB, and secure with the existing 12mm spacers. The Micromite BackPack PCB is then secured with two more 12mm spacers on the 25mm screws and the existing machine screws at the other end. Finally, secure the new master unit PCB onto the new spacers using short machine screws. Operation With no SD card inserted, only the “Test” screen will be operational. Connect an RJ45 cable to a slave unit and Case cutting Fig.15 shows the holes required in Fig.15: holes must be cut in the Jiffy box for the SD card, USB socket, audio output socket and RJ45 slave connector. Download and print this diagram for use as a template. To make rectangular cutouts, drill a series of small holes just inside the perimeter, then use a file or side cutters to knock out the centre section, and flat or triangular files to smooth the edges. 102 Silicon Chip Australia’s electronics magazine siliconchip.com.au The PCB mounts below the Micromite PCB and sits to one side, allowing its RJ45 socket and headphone jack to protrude from the case. the master unit Jiffy box. Note that the BackPack PCB sits reversed compared to our other projects, so that the SD card slot is at the top. Thus, the RJ45 and 3.5mm sockets are at the left, and the USB socket is at the right. Check this carefully before you begin cutting. It can be fiddly to get the board into the case. Try putting the left-hand side of the acrylic front panel in place, then pivot the right-hand end down to get the sockets into their corresponding holes. If they are snug, you might need to enlarge the holes slightly. Then you just need to attach the acrylic panel into the UB3 Jiffy box with the supplied screws to complete assembly (or slightly longer self-tappers, if you find they’re a bit short). Any USB power supply should be capable of powering the unit. Conclusion The many options that we’ve presented here demonstrate just how flexible the new Digital Lighting Controller can be. We think many people will want to take advantage of being able to control mains-powered lamps through such a simple interface and incorporate our design into existing lighting displays along with addressable LED strips, especially when using an Arduino. We’ll have more information about combining our mains slave units with LED strips in a short follow-up article next month, which will cover both Arduino and Micromite-based approaches. In the meantime, we expect that many people will use our slave units with their own custom controllers. We look forward to seeing what you can create, using the new Flexible Digital Lighting Controller as a starting point! SC Some people are justIMPOSSI BLE to buy Christmas gifts for! You know how hard it is: you want to give a Christmas Gift that will really be appreciated . . . but what to give this Christmas? Problem solved! Give them the Christmas Gift that KEEPS ON GIVING – month after month after month: a SILICON CHIP gift subscription For the technical person in your life, from beginner and student through to the advanced hobbyist, technician, engineer and even PhD, they will really appreciate getting their own copy of SILICON CHIP every month in the mail. They’re happy because they don’t have to queue at the newsagent each month. You’re happy because it actually costs less to subscribe than buying it each month CHOOSE FROM 6, 12 OR 24 month subscriptions Start whenever you like (Jan-Dec is very popular!) And we even pay for the postage! Don’t forget to let us know wh o the gift sub is for! Ordering your gift subscription is easy! eMAIL (24/7) To MAIL PAYPAL (24/7) PHONE (9-4, Mon-Fri) ONLINE (24/7) Place OR OR OR OR Log onto silicon<at>siliconchip.com.au Use PayPal to pay All order details – including Your Call (02) 9939 3295 with your order with order & credit card details silicon<at>siliconchip.com.au (including credit card details) – credit card details & contact no Order: http://siliconchip.com.au/giftsub and follow the prompts! include your contact info! Don’t forget to include all details! and tell us who the gift is for! to PO Box 139, Collaroy NSW 2097 CHRISTMAS IS ONLY 7 WEEKS AWAY! siliconchip.com.au Australia’s electronics magazine November 2020  103