Silicon ChipVisual programming with XOD - January 2021 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PicoLog Cloud
  5. Back Issues: PICOLOG
  6. Publisher's Letter
  7. Feature: The Fox Report by Barry Fox
  8. Feature: Techno Talk by Mark Nelson
  9. Feature: Net Work by Alan Winstanley
  10. Project: Nutube by John Clarke miniature valve stereo preamplifier by John Clarke
  11. Project: Complete Arduino DCC Controller by Tim Blythman
  12. Project: Using Cheap Asian Electronic Modules by Jim Rowe
  13. Feature: KickStart by Mike Tooley
  14. Feature: PICn’Mix by Mike Hibbett
  15. Feature: AUDIO OUT by Jake Rothman
  16. Feature: Make it with Micromite by Phil Boyce
  17. Feature: Interference and noise by Ian Bell
  18. Feature: Max’s Cool Beans by Max the Magnificent
  19. Feature: Visual programming with XOD by Julian Edgar
  20. Advertising Index: Max’s Cool Beans by Max the Magnificent
  21. PCB Order Form

This is only a preview of the January 2021 issue of Practical Electronics.

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

Articles in this series:
  • (November 2020)
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
  • Techno Talk (June 2025)
Visual programming with XOD By Julian Edgar Light Column Thermometer P icture the scene. You have some guests at your house and their eyes are attracted to a small device sitting on a shelf. The base is clear, and an electronics board can be seen, together with two projecting tubes, each pointing upwards. Sometimes the tubes fill with light, their entire columns illuminated. There seems to be a pattern in the way the tubes flash – but what is it? First the two tubes light up together, one white and one blue. They flash for a few moments and then the white tube goes dark, just the blue tube continues to flash. Both then turn off, and the cycle starts again. It’s obviously not random flashing, but what is it? This time the guests count the flashes, and realise the white and blue tubes flash twice, and then the blue tube flashes three times. But no – this time around, the blue tube flashed four times! So, what is it? Realisation dawns – it’s a thermometer, in this example reading 23°C and 24°C, respectively. This is a fun project – an indoor thermometer that displays the temperature in a unique way. It’s cheap, very easy to construct and almost as easy to customise. Cheap? The Light Column Thermometer uses an Arduino Uno board (clones now cost under £5 delivered), two clear plastic Uno enclosures (£2 each) and a handful of low-cost components. The light columns are recycled ballpoint pens illuminated by bright LEDs. Easy to construct? Soldering will take you only moments and other than that, it’s just a case of drilling some holes and screwing and gluing parts together. Customisable? The program (sketch) for the Uno is written in XOD visual programming language. XOD (pronounced ‘Zod’) was introduced in the March 2020 issue of PE and is completely free to use. Unlike lines of code that often appear impenetrable, XOD is easy to understand and hence is easy to modify. If you wish, it will take you literally moments to alter the flash duration, flash fade speed – or even how often the cycle repeats. And you don’t need to have white and blue flashing columns – just use whatever colour LEDs you prefer. Building The Light Column Thermometer uses the following parts, with the specific ones I used shown in brackets.  Arduino Uno (eBay cheap clone – *see note below)  Plastic Uno box (laser cut – I used two, eBay)  Two pre-wired 5mm LEDs (blue and white, already fitted with dropping resistors – Banggood)  LM35 DZ temperature sensor (eBay)  Two discarded clear ballpoint pen barrels (salvaged)  Assorted screws, nuts and spacers (in my parts box) The Light Column Thermometer displays the temperature by using two illuminated plastic tubes. One tube shows ‘tens’ and the other ‘units’, with the number of flashes indicating the appropriate values. Practical Electronics | January | 2021 *Note: Some low-cost Uno modules do have one ‘wrinkle’. Many use a non-standard USB communications chip, which if you are to communicate with it, needs a new PC driver. Some users report that Windows can find the driver by an automatic on-line search, but I had to download the driver from: www.wch.cn/downloads/ CH341SER_EXE.html 63 If you are new to using Arduinos, perhaps initially stick with ‘official’ products – they don’t need new drivers. The enclosure uses the baseplates of two laser-cut boxes widely sold for use with the Uno. I used two baseplates (as opposed to the normal top and bottom parts) so that the top plate didn’t have cut-outs in it. These cutouts are provided to gain access to the pins, but I spaced the top and bottom of the enclosure further apart than usual (thus giving internal access to the pins) and so I didn’t need the cut-outs. Of course, you can use just one box if you don’t mind the slots in the top panel. The top and bottom panels are spaced 20mm apart using plastic stand-offs, and the Uno is bolted to the baseplate via screws, plastic washers and nuts. All the holes in the enclosure panels for mounting are drilled out to 3mm diameter, allowing the use of normal-sized spacers and screws. (As standard, these holes appear to be 2.5mm) The side and end plates of the enclosure are not used. The light columns are, as described, salvaged ballpoint pen barrels. Pick a transparent design that has an interesting shape, preferably without writing on it. Different barrels will give different lighting effects; test the result by shining a 5mm LED down the end of the tube. LED SCL SDA AREF GND 13 12 11 10 9 8 Anode (a) LED Use prewired LEDs that include dropping resistors, or add your own resistors (approx 470Ω to 1kΩ) to standard LEDs. 7 6 5 4 3 2 1 0 LED Cathode (k) An Arduino Uno and two low-cost commercially available enclosures form the main components of the project. The upright columns are salvaged ballpoint pen bodies. DIGITAL UNO ANALOG IN A0 A1 A2 A3 A4 A5 5V RES 3.3V 5V GND GND VIN POWER LM35DZ LM35DZ 1 2 1 2 VCC VOUT 3 GND 3 Fig.1. Connection diagram for the Arduino Uno, together with the pin-outs for the two LEDs and the LM35DZ temperature sensor. Its 5V supply is taken from the Arduino. Note: you can use LEDs prewired with dropper resistors, or ordinary LEDs and choose your own resistor. 64 The end of the pen barrels I used had a short length of exposed plastic thread. Two holes just undersize of this thread diameter were drilled in the top panel and then the plastic pen barrels could be screwed into the holes. A little cyanoacrylate glue (‘superglue’) was used to secure them into place. The pre-wired 5mm LEDs were glued into the ends of the tubes. Wiring Refer to Fig.1 for the pinout of the LM35 temperature sensor. Port A0 is used for the signal, and the sensor’s 5V and ground connections can be made close by on the Uno (all Uno ports are labelled). I used header pins and soldered the LM35 straight to these. Ensure that the signal wire cannot touch the ground connection. The LEDs were wired between ground and ports D3 and D5, again using cut-off header pins. Remember the correct polarity for the LEDs – positives/anodes, to the ports; negatives/cathodes to ground. Power to the board can be supplied via the DC socket (5-12V) or USB input. Software To upload the program (sketch) to the Uno you will have first needed to install XOD on your PC (see https:// xod.io/downloads/ – remember, it’s free after you register). You will also need to download the Light Column Practical Electronics | January | 2021 Thermometer sketch from the January 2021 page of the PE website. (Note that depending on whether you have used XOD previously, the software might prompt you to do some further downloading of extra libraries.) Refer now to Fig.2. The beauty of XOD is that’s it very easy to understand. In the red box (top of diagram) we have the input from the temperature sensor, constantly read through Analog Port A0. This value is multiplied by 500, averaged and then rounded. (The ‘live’ temperature is shown in the green ‘watch’ node, that operates when the sketch is uploaded to the Uno in ‘debug’ mode. We now need to extract from this number the ‘tens’ and ‘units’ – see the green box. Dividing the value by 10 and then using a ‘floor’ node does this for the ‘tens’. Now, what about the ‘units’? The ‘modulo’ node does this by calculating the remainder of (again) dividing our temperature value by ten. Two ‘watch’ nodes allow us to see these outputs live. Let’s do the white box next – the flashing shows the number of ‘units’. Our ‘units’ number is fed to a ‘flip-n-times’ node. This node flashes the LED output the required number of times, and also sets the flash rate and duty cycle – in this case, 0.2 seconds ‘on’ and 0.5 seconds ‘off’. The ‘gate’, ‘not’ and ‘equal’ nodes then prevent an output if the ‘units’ number is zero. (Otherwise, the ‘flip-n-times’ node outputs one flash, even with a 0 input.) We then feed the output through an ‘or’ node (more on this in a moment) and then through a ‘fade’ node. The fade node gives a gradual (although still pretty fast) rise and fall in LED brightness with each flash. Now, what about the ‘tens’? The tricky part here is twofold: first, the ‘units’ column needs to flash at the same time as the ‘tens’ column when ‘tens’ are being shown, and second, the ‘units’ can’t start to flash until the ‘tens’ have finished their sequence. Flashing the ‘units’ LED when the ‘tens’ LED is flashing is achieved by the ‘or’ node. But what about not starting the ‘units’ until the ‘tens’ are done? This is done Fig.2. The Arduino sketch for the Light Column Thermometer is written in XOD visual programming language. The sketch is fully explained in the main text, but in brief, Practical Electronics | January | 2021 the red box shows the temperature input nodes, the yellow box extracts the ‘tens’ and ‘units’ from the reading, the white box flashes the LED for the ‘units’ reading, the brown box flashes the LED for the ‘tens’ reading, the yellow box starts the ‘units’ only after the ‘tens’ have finished, and the blue box sets the cycle time. 65 ‘tens’ flashes and four ‘units’ flashes). Each flash takes 0.7 seconds (0.5 off and 0.2 on), giving a total of 4.2 seconds. Add to that the one-second delay between the ‘tens’ finishing flashing and the ‘units’ starting, and we have 5.2 seconds for the sequence. Since the clock resets at (in this example) six seconds, we have a 0.8 second delay at the end of the cycle before it starts again. Taking this approach means the cycle time adapts to the required number of flashes. As with all XOD sketches, this one is easily customised. For example, if you wanted the cycle time to be longer, you could put another ‘add’ node in above the ‘clock’ and add a further (say) five seconds to the cycle time. Note that as configured, the thermometer cannot show negative temperatures, nor degrees Fahrenheit. (Both of these are quite possible, though. For example, XOD even has available a direct units conversion node for Celsius/ Fahrenheit – you might want to try adding it to the sketch.) Spacers are used to hold the two parts of the enclosure 20mm apart. This gives enough room for the wiring of the temperature sensor and two LEDs to be placed within the enclosure. by the contents of the yellow box – that registers when the ‘tens’ have finished, adds a delay of one second, and then starts the ‘units’ flashing. The brown box comprises the logic for the ‘tens’ flasher; it uses the same approach as for the ‘units’. The blue box starts the cycle. It does this by adding the ‘tens’ and ‘units’ numbers together to gain the total required number of flashes. In this example that is six (two Conclusion I find the Light Column Thermometer fascinating to watch. It can be seen from across the other side of the room, and reading it is oddly relaxing – perhaps because you have to pause and watch, rather than just glance and run. It’s also an ideal project with which to discover the fascinating world of XOD. XOD files The XOD file discussed in this article can be downloaded from the January 2021 page of the PE website. See PE March 2020 for an introduction to using XOD. Teach-In 8 CD-ROM Exploring the Arduino EE FR -ROM CD ELECTRONICS TEACH-IN 8 FREE CD-ROM The Arduino offers a remarkably effective platform for developing a huge variety of projects; from operating a set of Christmas tree lights to remotely controlling a robotic vehicle wirelessly or via the Internet. Teach-In 8 is based around a series of practical projects with plenty of information for customisation. The projects can be combined together in many different ways in order to build more complex systems that can be used to solve a wide variety of home automation and environmental monitoring problems. The series includes topics such as RF technology, wireless networking and remote web access. The CD-ROM also includes a bonus – an extra 12-part series based around the popular PIC microcontroller, explaining how to build PIC-based systems. SOFTWARE FOR THE TEACH-IN 8 SERIES FROM THE PUBLISHERS OF This CD-ROM version of the exciting and popular Teach-In 8 series has been designed for electronics enthusiasts who want to get to grips with the inexpensive, immensely popular Arduino microcontroller, as well as coding enthusiasts who want to explore hardware and interfacing. Teach-In 8 provides a one-stop source of ideas and practical information. PLUS: PICs and the PICkit 3 – A beginners guide £8.99 INTRODUCING THE ARDUINO • Hardware – learn about components and circuits • Programming – powerful integrated development system • Microcontrollers – understand control operations • Communications – connect to PCs and other Arduinos PLUS... PIC n’MIX PICs and the PICkit 3 - A beginners guide. The why and how to build PIC-based projects Teach In 8 Cover.indd 1 04/04/2017 12:24 PRICE £8.99 Includes P&P to UK if ordered direct from us SOFTWARE The CD-ROM contains the software for both the Teach-In 8 and PICkit 3 series. ORDER YOUR COPY TODAY! JUST CALL 01202 880299 OR VISIT www.electronpublishing.com 66 Practical Electronics | January | 2021