Silicon ChipMake it with Micromite - April 2022 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PICOLOG
  5. Publisher's Letter
  6. Feature: Go eco, get ethical! by Mark Nelson
  7. Feature: The Fox Report by Barry Fox
  8. Feature: Net Work by Alan Winstanley
  9. Back Issues: Digital FX Unit by John Clarke
  10. Project: 64-KEY MIDI MATRIX by Tim Blythman
  11. Project: Digital FX Unit by John Clarke
  12. Feature: P955H PIC Training Circuit by Peter Brunning
  13. Project: High-current Battery Balancer by Duraid Madina
  14. Feature: Circuit Surgery by Ian Bell
  15. Feature: Flowcode Graphical Programming by Martin Whitlock
  16. Feature: AUDIO OUT by Jake Rothman
  17. Feature: Max’s Cool Beans by Max the Magnifi cent
  18. Feature: Make it with Micromite by Phil Boyce
  19. PCB Order Form
  20. Advertising Index

This is only a preview of the April 2022 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
Make it with Micromite Phil Boyce – hands on with the mighty PIC-powered, BASIC microcontroller Part 35: Mini-Project: iButton-controlled Electronic Door Lock T his month, we are going to n If the iEDL display is also a touchscreen, begin the iButton Electronic Door Lock (iEDL) mini-project. The idea is to bring together the topics covered in the last three articles (January – March 2022) of the Make it with Micromite (MIWM) series and put all we learnt to practical use. Do note that we will not be describing details of the various electromechanical door solenoids (or ‘holding magnets’) that are typically used for locking/releasing a door. Our iEDL will simply provide a set of change-over relay contacts that can either be interfaced with an existing electromechanical lock, or alternatively used to control any new mechanicalhardware that needs to be installed. The concept behind the iEDL is simple – issue an iButton key to anyone that is permitted to open (ie, access) one or any selected door(s) in a building. For example, doors around the home, in an office environment or even a large commercial business premises. An iEDL is located next to each restricted door, and on presenting a valid iButton key, a person can unlock the door. This might sound the same as any other simple electronic door lock, so what makes the iEDL so special? then for extra security a PIN can also be requested (in addition to presenting the iButton-key) n Using a ‘master Configuration Button key’, the iEDL can be triggered to enter a configuration mode. The ability to switch the iEDL to behave as a configuration tool avoids the need to link the iEDL to a computer, and creates a standalone solution n In configuration mode, the name of the keyholder can be programmed into an EEPROM iButton key n In configuration mode, an iButton key can be reassigned to a new user or wiped from the system n In configuration mode, an iEDL can be programmed with a descriptor (such as ‘Staff Entrance’), and this can be shown on the iEDL display n This project really comes to life when more than one iEDL is implemented on a site. Each iEDL can be programmed with a single Category ID, which can be set when the iEDL is in configuration mode. If access settings (ie, one or more Category IDs) are also programmed into an EEPROM key (as well as the keyholder’s name), then a user can be granted access to certain category doors, but denied access to other category doors. This also means that an iEDL does not need to contain a list of valid key numbers – instead, the single Category ID programmed into the iEDL is checked against the Category IDs programmed into the presented EEPROM iButton, and access is then either permitted, or denied, accordingly. iEDL features The simple answer is there’s a Micromite at the heart of our iEDL, so it can easily be programmed in MMBASIC with as many features and options that we can dream up; and thus we can create a much more intelligent and flexible lock. For example: n Incorporate a TFT display in the iEDL, so the name of the person trying to gain access can be shown – this creates a better user experience Micromite code The code in this article is available for download from the PE website. 66 Fig.1. Three MIWM modules are used in the iEDL prototype: (from top to bottom) a) The Micromite Keyring Computer (MKC); b) The Development Module (DM); c) The TFT-adaptor (complete with piezo sounder). Practical Electronics | April | 2022 From the above list of examples, it can be seen how the functionality of the solution could be made to behave in an intelligent way. All that is required is a change to the main program-code in the iEDL; with the hardware remaining exactly the same. We will be incorporating many of the above features (next month), but first we need to discuss how to assemble an iEDL. Hardware As mentioned above, the iEDL hardware is built around a Micromite; so, in keeping with the original concept of this series, the prototype iEDL was based on the following modules: n Micromite Keyring Computer (MKC – from MIWM Part 2, PE March 2019) – see Fig.1a n Development Module (DM – from MIWM Part 3, PE April 2019) – see Fig.1b n TFT-adaptor (MIWM Part 15, PE April 2020) – see Fig.1c. This contains the touchscreen, as well as a piezo sounder n iButton reader (from MIWM Part 32, PE Jan 2022) – see Fig.2 n LED (if not built into the iButton reader), plus current-limiting resistor n Low-cost relay module – see Fig.3. Note that the MKC and DM can be substituted with an alternative Micromite module, as has been discussed elsewhere in this series. For example, it is possible to use an Explore28 (or Explore64), but this would need to be hard-wired to a touch-TFT. To avoid having to hardwire a TFT, it is better to use a 28-pin Micromite BackPack module (version 2 – see PE, May 2018; PCBs are available from the PE PCB Service) which would just need the required iButton reader, LED, piezo sounder and relay module to be connected. Once you have chosen your preferred Micromite to build the iEDL, you just need to add the required external parts. To assist with assembly, please refer to Fig.4; Fig.2. The DS9092L is our preferred iButton reader. It contains a centremounted LED which assists in locating the exact position for where to present the iButton. Practical Electronics | April | 2022 this summarises the Micromite pin number connections to all the other parts of the iEDL. A point worth noting here is that the cost of an iEDL is around £50 (uncased), so it is a much cheaper solution compared to commercially available door-access systems – but, can be fully configured (ie, programmed) to behave as you need it to. (Do note that questions relating to compatibility of the iEDL with your home or work insurance provider are your responsibility!) a) b) 26 T_IRQ 15 T_DO 14 L S1 Piezo buzze T_DI 3 r T_CS 7 22 T_CL K SDO (MISO ) L ED SCK 25 SDI (MO SI) 2 R1 1 c) 3.3V iButton reader R2 7 D/ C 23 RESET 6 9 iButton CS 0V G ND 5V V CC d) 5V J4 TFT 0V R3 1 e) NO 21 L ED1 CO M 0V NC 5V 10 Circuit assembly Fig.4. Pin connections between the Micromite and the five main The most complex elements of the iEDL: a) The TFT has 14 contacts connected connection inside as shown (note the 10Ω backlight resistor); b) the piezo is the iEDL is between connected between pin 26 (PWM 2A) and I/O pin 22; c) The the Micromite and the iButton reader (with 4.7kΩ pull-up) is connected between I/O touchscreen. If you pin 9, and 0V; d) An LED (and series current-limiting resistor) are using an MKC, DM is connected between I/O pin 10, and 5V; e) The relay module and TFT-adaptor, then needs 5V power. I/O pin 21 controls the change-over contact. these connections are channel 2A, and I/O pin 22 is set low (or already made for you (and likewise if high, rather than left ‘floating’), then a using a 28-pin Backpack). However, tone will be heard. Unless you are using if you are building an iEDL with an an MKC with the TFT adaptor (which Explore28 (or Explore64) module, has a built-in piezo), you will need to then you will need to make the ten connect an external piezo sounder to connections shown in Fig.4a, plus the the Micromite. 10Ω current-limiting resistor required for The iButton reader is connected to Pin 9, the TFT backlight. These connections as shown in Fig.4c. This requires a 4.7kΩ ensure all aspects of the touchscreen pull-up resistor to function correctly (as work when using the Micromite’s builtexplained in MIWM Part 32, PE Jan 2022). in TFT driver. Whether the iButton reader has a builtTo provide audible feedback to the user, in LED, or you use an external LED, a piezo sounder is connected between you will require the usual LED currentpin 26 and pin 22 (see Fig.4b). Pin 26 limiting resistor to be connected in series. is a PWM output, and when MMBASIC The exact value will depend on the is set to output a square wave on PWM LED being used, but a typical value is somewhere between 330Ω and 1kΩ. This LED is useful for highlighting where the iButton reader is located in dark conditions. It is connected to pin 10, as shown in Fig.4d; setting pin 10 low turns the LED on. Finally, the relay module is connected to Micromite pin 21 (and 5V power), as shown in Fig.4e. Setting pin 21 low turns the relay on (and hence switches the relay’s change-over contacts). Hardware assembly is straightforward Fig.3. This low-cost relay module is whichever Micromite module you use; readily available online. It contains a set and it’s easy to understand how the of change-over contacts, and hence can Micromite interacts with each element. be interfaced to the electromechanical Remember, it is the MMBASIC code hardware that in turn controls the locking/ which makes everything come to life (and releasing of the door. enables the intelligence and features). 67 Fig.7. GUI TEST TOUCH allows you to test the accuracy of the calibration. If it’s too inaccurate, simply use GUI CALIBRATE again. Fig.5. GUI TEST LCDPANEL should result in this built-in test-pattern animation appearing on the TFT screen. Configuring the iEDL Once you have completed the required connections between the Micromite and each iEDL element, perform all the usual visual checks. When everything looks correct, apply power to the iEDL, and then connect the Micromite to your preferred terminal program (eg, TeraTerm). When a connection is established, you will need to configure two specific Micromite OPTIONs, followed by careful calibration of the touchscreen. So, assuming that the two OPTIONs aren’t yet set, start by configuring the TFT display driver with the command: OPTION LCDPANEL ILI9341,L,2,23,6 On pressing Enter, the TFT should go blank (rather than appearing whiteish/ grey). If it doesn’t, then power down, recheck everything, then power back up. The TFT’s backlight should flash briefly, and then the display will go blank. Now type GUI TEST LCDPANEL and you should see the usual built-in animated test pattern (a circles patterns – see Fig.5). Next, you need to configure the touchscreen. This is carried out with the command OPTION TOUCH 7,15 followed by the command GUI CALIBRATE On pressing Enter, the TFT will display the calibration screen, as shown in Fig.6. Follow the onscreen instructions using a plastic stylus to touch the four crosshairs that pop up, one at a time. Once this step is completed, you can check the accuracy of calibration by typing the command GUI TEST TOUCH On pressing ENTER, the screen will clear, and you can use a stylus to write words on the screen (see Fig.7). If the position of the pixels appearing are offset too far from the tip of the stylus, then you will need to recalibrate the screen (GUI CALIBRATE). Once accurate screen configuration has been completed you can proceed to testing the piezo sounder, the LED, the relay module and the iButton reader. Testing the iEDL Fig.6. The touchscreen is calibrated with the command GUI CALIBRATE. Use a plastic stylus and simply follow the onscreen instructions to complete calibration. 68 To test the piezo sounder, begin by setting PWM channel 2A (pin 26) to output a square wave with a frequency of 1kHz. This is achieved by typing the command: PWM 2,1000,50 (1000Hz with a 50% duty cycle). Nothing should be heard at this point since you also need to set pin 22 to 0V, which is achieved by typing the command: SETPIN 22,DOUT On pressing Enter, you should hear the piezo sounder (if not, then check the commands have been typed correctly, and also the piezo’s two pins are connected to pins 26 and 22. The tone of the sounder can be changed by altering the relevant PWM parameter. To see this (or rather to hear it), type: PWM 2,500,50 This will change the frequency from 1kHz to 500Hz. The piezo is silenced by typing: SETPIN 22,OFF (which causes pin 22 to float). Alternatively, the piezo sounder can be silenced by typing: PWM 2,STOP The LED is tested by setting I/O pin 10 to a digital output. To turn it on, set pin 10 low by typing: SETPIN 10,DOUT If the LED does not light, first check the command has been entered correctly, then check the connections to the series resistor, and to the LED. Be sure to check the value of the resistor is somewhere in the region between 330Ω to 1kΩ. If it is too high (possibly due to mis-reading the resistor’s colour bands) then the chances are the LED could be so dim, that it appears not to be working at all. If after these checks it still doesn’t light, then ensure that the LED is installed correctly (remember, LEDs are polarised components and hence they must be inserted the correct way round). Once the LED is lit, then check it is turned off by typing the command: PIN(10)=1 The relay module is tested in a similar way as the LED – simply replace the reference to pin 10 with pin 21. Thus, to energise the relay, type the following command: SETPIN 21,DOUT You should hear the relay click; if not, perform the usual checks. Once this is working correctly, ensure you can switch the relay off again by typing: PIN(21)=1 (again, you should hear a click as the relay coil is de-energised). Finally, you need to test the iButton reader. To do this, you will require at least one iButton; this can be either a DS1990 (ID only), or a DS1971 (EEPROM) iButton. Type in the following program into the EDITor: DO ONEWIRE RESET 9 TEXT 160,120,MM.ONEWIRE,CM,1,3 PAUSE 10 LOOP Practical Electronics | April | 2022 Fig.8. The AZTouch enclosure is an attractive wall mounted case. a) (left) the image that convinced me to try and fit an iEDL inside. b) (right) my first attempt at fitting the iEDL into a modified AZ-Touch enclosure. Note the iButton reader lower right. Next, RUN the program and check that a 0 character is displayed in the centre of the TFT. Then tap (and hold) an iButton onto the reader and make sure that the 0 changes to a 1 while the iButton is in contact with the reader. If this test fails, then check the code is entered correctly, and also that the iButton reader is connected to pin 9. Also check the value of the pull-up resistor; it needs to be 4.7kΩ. Once the above tests have been successfully completed, then we can be guaranteed that the iEDL has been assembled correctly. The iEDL is now ready for the main program code to be loaded; however, this will have to wait until next month. So, in the meantime, why not try and modify some of the recent iButton demo code so that it displays information (such as the iButton’s unique ID number) on the TFT display instead of in the Terminal screen. Essentially, this means replacing the relevant PRINT commands with TEXT commands, along with using the correct parameters that the TEXT command requires. Refer to the simple DO... LOOP program listed above for such an example, and also refer to the Micromite User Manual to check the parameters used – for example, to add some colour. that the version of the iEDL shown in the photo is based on an Explore64, and is positioned behind the front panel, rather than installed inside the enclosure. I just thought that I would share this first attempt at trying to fit an iEDL into an AZ-Touch enclosure. I hope this inspires you to think about how to house your iEDL. Next time Now that we have assembled, configured, and tested the iEDL mini-project, next month we will discuss how the program code works. Until then, stay safe, and have FUN! Housing the iEDL One thing to think about is how to install the iEDL into a suitable enclosure. Many technically brilliant electronic projects are let down by being housed in a poor casing. Custom 3D-printed enclosures have become more popular over the last few years; however, this approach is only practical if you have access to a 3D-printer (and arguably have lots of spare time to print the numerous prototypes that you’ll end up printing so that you get everything positioned correctly). However, one nice looking (and readily available) enclosure that grabbed my attention recently was the AZ-Touch (see Fig.8). This is a wall-mounted unit with a cut-out for either a 2.4-inch or 2.8-inch ILI9341 touchscreen. As a bonus, a compatible ILI9341 TFT is included in the AZ-Touch kit (Google for a list of AZ-Touch sources). Although many pictures online show the AZ-Touch mounted in a portrait orientation, there is nothing stopping us from using this enclosure in a landscape orientation. So, I decided to purchase a handful of these kits and attempted to modify things to see if I could successfully house the iEDL inside. An early prototype is shown in Fig.8b, but do note Practical Electronics | April | 2022 JTAG Connector Plugs Directly into PCB!! No Header! No Brainer! Our patented range of Plug-of-Nails™ spring-pin cables plug directly into a tiny footprint of pads and locating holes in your PCB, eliminating the need for a mating header. Save Cost & Space on Every PCB!! Solutions for: PIC . dsPIC . ARM . MSP430 . Atmel . Generic JTAG . Altera Xilinx . BDM . C2000 . SPY-BI-WIRE . SPI / IIC . Altium Mini-HDMI . & More www.PlugOfNails.com Tag-Connector footprints as small as 0.02 sq. inch (0.13 sq cm) 69