Silicon ChipVisual programming with XOD - March 2020 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Publisher's Letter
  5. Feature: The Fox Report
  6. Feature: Techno Talk by Mark Nelson
  7. Feature: Net Work by Alan Winstanley
  8. Project: Diode Curve Plotter by Tim Blythman
  9. Project: Audio DSP by Design by Phil Prosser, Words Nicholas Vinen
  10. Project: Steam Train Whistle ... or Diesel Horn by JOHN CLARKE
  11. Project: Galvanic Skin Response by Jim Rowe
  12. Feature: PIC n’ Mix by Mike Hibbett
  13. Feature: Circuit Surgery by Ian Bell
  14. Feature: AUDIO OUT
  15. Feature: Make it with Micromite by Phil Boyce
  16. Feature: Visual programming with XOD by Julian Edgar
  17. Feature: Max’s Cool Beans by Max the Magnificent
  18. Feature: Electronic Building Blocks by Julian Edgar
  19. PCB Order Form
  20. Advertising Index

This is only a preview of the March 2020 issue of Practical Electronics.

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

Articles in this series:
  • Techno Talk (February 2020)
  • Techno Talk (February 2020)
  • Techno Talk (March 2020)
  • Techno Talk (March 2020)
  • (April 2020)
  • (April 2020)
  • Techno Talk (May 2020)
  • Techno Talk (May 2020)
  • Techno Talk (June 2020)
  • Techno Talk (June 2020)
  • Techno Talk (July 2020)
  • Techno Talk (July 2020)
  • Techno Talk (August 2020)
  • Techno Talk (August 2020)
  • Techno Talk (September 2020)
  • Techno Talk (September 2020)
  • Techno Talk (October 2020)
  • Techno Talk (October 2020)
  • (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)
  • Techno Talk (July 2025)
  • Techno Talk (July 2025)
Visual programming with XOD By Julian Edgar Introducing XOD visual programming for Arduino I have a confession to make: the massive and growing use of programmable microcontrollers in hobby electronics has largely passed me by. Why? Well to be honest, I find listings of code terribly off-putting – one character in the wrong place and the program won’t run; and anyway, who wants to learn lots of arcane instructions before you can get a microcontroller board to do even the simplest thing? (OK, lots of you! But others, like me, just want to get a quick digital fix!) Well, in the last few months I’ve had an epiphany – and it’s all due to XOD (pronounced ‘zod’). XOD is a free visual programming software package for Arduino. There is no code – you simply place pre-built blocks on the screen, and then ‘wire’ them together. If you can understand a simple circuit diagram, you can program an Arduino in XOD. I’m in no doubt that an expert code writer would find many deficiencies in XOD, but for someone without that The XOD programming screen. In the main work area is the program (‘sketch’) that’s being built. Here the LCD programming box has been highlighted – the left-hand lower column on the screen shows the configurable settings for the LCD and the right-hand column displays the help file for the LCD. 60 background who wants to quickly get Arduinos doing real-world things, it’s just wonderful. Furthermore, the level of support is good. Rather than hundreds of poor YouTube videos, the software has an inbuilt tutorial with 42 clear and relevant lessons. These take you from zero knowledge through to possessing enough knowledge to build quite complex control systems. There is also a user forum that I have found supportive and helpful. Finally, XOD allows you to emulate the program on-screen – that is, you can see how the program will run, even as you write it. This makes it far easier to debug your program. Getting the software The software can be downloaded from https://xod.io/downloads/ and is available for Windows, macOS and Linux platforms. (If you don’t want to initially download the desktop version, you can also explore the software a little by using a browser version.) Prior to downloading, or using the browser version of XOD, you will be required to create an account with your email address and a password. A reminder – XOD is completely free, so you don’t get a version that is incomplete or hamstrung in what it can do. Installing and running the software is straightforward; the only issue I had was specifying the correct Arduino board when uploading to the board for the first time. For an Arduino Uno or clone, select the default ‘Arduino/ Genuino Uno’ option. You might also find that you need to specify the correct PC communication port. Practical Electronics | March | 2020 Fig.1. An Arduino Uno board – they’re incredibly cheap, and with the use of XOD visual programming software, now very easy to program. You can have projects up and running in literally minutes. Note that to use the software, the Arduino board must be connected to the USB port of the PC – the USB connection powers the board. (There is also an online simulation function available for XOD, but I have found it to be a bit erratic.) Using the software The first step after downloading XOD is to do the in-built tutorial. It’s quite detailed, and if you do all the suggested activities (the tutorials are done in the actual programming environment), it will take some hours. That said, after the first ten lessons, you’ll have enough information to LED Fig.3. The DFRobot 1602 LCD Keypad Shield module plugged into the Arduino Uno board. The Uno is programmed with the XOD software discussed in this article and the display is showing the current temperature and the setpoint at which the alarm LED lights. start programming. You can return to the tutorial at any time by going to: Help > Open Tutorial Project. I also found this page helpful: https:// dronebotworkshop.com/gettingstarted-with-xod/ The hardware In this example, I’ll use:  Arduino Uno, for example the board shown in Fig.1  Microchip MCP9700 temperature sensor IC  LED with suitable dropping resistor  10kΩ potentiometer  DFRobot 1602 LCD Keypad Shield module (Fig.3). Anode (a) Dropping resistor approx 470Ω to 1kΩ Cathode (k) 7 6 5 4 3 2 1 0 SCL SDA AREF GND 13 12 11 10 9 8 MCP9700 DIGITAL POWER ANALOG IN 5V RES 3.3V 5V GND GND VIN A0 A1 A2 A3 A4 A5 UNO 1 2 3 VDD GND VOUT MCP9700 10kΩ 1 2 3 Fig.2. The initial set up for the Arduino board temperature alarm using an MCP9700 sensor and LED with dropping (current-limiting) resistor. (LCD shield not yet added.) Practical Electronics | March | 2020 Let’s start with the temperature sensor. Connect the appropriate pins (see Fig.2) from the sensor to the on-board 5V and ground, and the output to port A5 (analogue 5). (Note: all connections are labelled on the board.) Connect the LED between pins D13 and ground. (To speed things up, I buy LEDs pre-wired with a resistor for 12V use. They’re still plenty bright enough, even when working off 5V.) Ensure correct polarity. Finally, connect the pot across the 5V and ground terminals, with its wiper (middle terminal) connected to port A4. You should now have what is shown in Fig.2. (We will get to the LCD shield later.) Writing a program Select File > New Project – you will be then confronted with a largely blank screen. This is your working area where you will build the program. On the far left and far right are two narrow columns – these display information that helps you as you proceed. Let’s make a temperature alarm, and to make it trickier, let’s average the temperature reading over about five seconds and condition the sensor output so we’re working in degrees Celsius (°C). We’ll then add a pot input to adjust the setpoint temperature, and then an LCD to show both setpoint and real-time temperatures. Sound hard? It isn’t! Functional building blocks You can see from the pictures in this article that the program is built from functional blocks (called ‘nodes’) – but where are they? Double clicking in the main work area will bring up a ‘search nodes’ box. We want to start the programming by having an analogue 61 Fig.4. Adding the first XOD block – an ‘analog-sensor’ functional box. sensor (the temperature sensor) input to the Arduino board. Typing ‘analog’ into the search box brings up xod/ common-hardware/analog-sensor. Select this by double clicking on it. A functional box called analog-sensor will then be added to the main work area – see Fig.4. Clicking on this box brings up information in the two screen columns. At right, each label on the functional box is explained, while at left these can be user-configured. The labels on this first box are: PORT – the analogue port that is going to be used for this input on the Arduino board. Change it to A5. UPD – how the input is updated. The options are ‘never’, ‘on boot’ and ‘continuously’. Set it to ‘continuously’ – shown on the box as ‘loop’. VALUE – the output value, configured automatically to be in the range 0-1. DONE – outputs a pulse when the reading is done (we don’t use this). We can re-label the box to read something other than analog-sensor – and now, using the column at left, label it Input temp. So we’ve now added an analogue input on port A5 that is continuously updated and is labelled in a way we can immediately understand. Fig.6. Adding blocks to display the sensed temperature in °C. see the real-time working of the program, as shown in Fig.5. By heating and cooling the temperature sensor you should now see the value in the watch box changing – we have an input! Hmm, but there is also an issue – at room temperature, the output of the sensor is showing 0.14 – not a ‘real’ temperature reading. We need to convert the reading to degrees Celsius, and with this sensor that means 62 multiplying this reading by 500 and subtracting 50. So how do we do that? Processing the input values Double-clicking in the workspace and searching under ‘multiply’ brings up xod/core/multiply that we then select. We connect the IN1 of the multiply box to the VAL output of the input temperature box, and using the left-hand column on the screen, change the IN2 value to 500. We then add a xod/core/subtract box and subtract 50. (Well, as you can see here, I actually used 48 – that offset giving better accuracy with the particular temp sensor I was using.) We can then add another watch box to the output of the subtract box and upload the program in debug mode to the board. You should then see the reading showing in degrees Celsius, as shown in Fig.6. Creating an input But is our input actually reading anything? Double-click the work area and type debug and a series of options pops up – select xod/debug/ watch and connect this block to the output (VAL) of the Input temp block. Upload the program to the board by pressing the ‘bug’ symbol at bottom right of the screen. This loads the program in debug form – you can then Fig.5. Adding a watch box and connecting it to the Input temp block. Fig.8. A greater box enables the system alarm to be added. The true/false box lets you see if the alarm is activated. Fig.7. Using a user-generated average function to generate five-second averages of the temperature readings. Data processing Now we want to average the temperature reading; eg, over five seconds. But if you double-click on the work area and start typing ‘average’, you’ll find you don’t get any result – there is no ‘averaging’ block available as standard. Practical Electronics | March | 2020 Upload the program in debug mode. Now the LED lights when the measured temperature is above 25°C, averaged over about five seconds. (You’ll also notice that an on-board LED lights too – it’s also connected to D13.) External pot input In the program’s current format, the set-point temperature of the alarm is typed into the software. But what if we wanted to adjust the setpoint with the external pot? As shown here, doing this takes only moments. Note that we are using port A4 for the pot input, and again, we multiply its output by 500 (no subtraction necessary) and then average the output. Here the set-point is 26.47°C. (Would you like to round this number? If so, find the xod/math/ round box and add it.) See right-hand side of Fig.9. Connecting an LCD display Now, what about showing on an LCD screen both the setpoint and monitored temperature? But I must be honest. There is a potential hardware hurdle here – and that is that LCD modules have a wide variety of different pinouts. The default LCD 16 × 2 programming block in the XOD software was not a match for the DFRobot 1602 LCD Keypad Shield module I used – that is, it wasn’t ‘plug-in compatible’ so I had to make some port changes. Doing this meant looking up the data sheet for the LCD module and changing the designated ports on the XOD LCD block (covered in a minute) to match the functions of the different pins. In the case of the DFRobot LCD this comprised: Fig.9. Here we add blocks to: a) enable the Arduino to light the LED when the alarm is triggered; and b) use the pot to adjust the setpoint. However, one of the advantages of the XOD system is that users can upload their own useful blocks for others to use. These can be found on the XOD website under ‘libraries’. By going to File > Add Library and typing in the library name as shown on the website, these extra blocks can be added. average is one of them – it’s under ‘gst/average/average’. This box has six labels, but we’re interested in only three – in, out and step. Click and drag a line from the output value of the subtract box to IN on the average block. Change STEP to 500 and INC to Continuously (shown on the box as LOOP). Now we’re averaging the output of our temperature sensor over about five seconds. But will it work? Add a watch box to the output of the average box, upload the program in debug mode to the board, and then check that the temperature reading is now averaged over a period. (Fig.7) Adding the alarm Now we’ll add the alarm part of the program. Select a xod/ core/greater box and link IN1 to the output of the average box. Change IN2 to 25 (as in, 25°C). Add a watch box to the output of the greater box. (See Fig.8.) Upload the program in debug form and check that the watch box changes from false to true when the temperature of the sensor is over 25°C. (Note how the watch box can show both values (numbers) and logic (true/false) states.). Driving the LED The next step is to light an LED when the alarm is triggered. Add a xod/common-hardware/led box to the screen – searching under ‘led’ will bring this box up. Change its port to D13 and connect its LUM pin to the output of the greater box. (See lower left, Fig.9.) Practical Electronics | March | 2020 LCD pin RS EN D4 D5 D6 D7 Arduino port D8 D9 D4 D5 D6 D7 To add the LCD shield, first remove the existing temperature sensor, LED and pot connections. Then plug in the LCD shield, ensuring it is positioned as far towards the end of the Arduino board as possible. With this done, we now need to reconnect the pot and temperature sensor inputs using the analog inputs pins on the front of the shield. The LED output also needs to be moved. The port numbers remain the same, so this takes only moments – although you will need to change from male to female connectors. The text-lcd-parallel-16x2 box is then added. L1 refers to line 1, and L2 to line 2 on the display; each is a separately addressable (see Fig.10). Line 1 is then linked to the averaged input temperature via a xod/core/concat box that is used to display the word ‘Current:’ and the numerical temperature reading. Line 2 uses a similar concat box to display the word Setpoint: and the pot’s averaged output. The changed program is then uploaded in debug mode, and you should see the complete system working. (If the LCD does not show anything, try adjusting the on-board contrast pot.) Conclusion And there we have it! We have built a digital over-temperature warning system that lights an LED when the setpoint temperature is exceeded and displays on an LCD the current temperature and the setpoint temperature. Yes, it’s a basic system, but it needed no code and was quick and easy to put together. 63 Now consider how easily it could be extended or altered – for example:  Changing the temperature averaging time requires altering only one number in the software  Fine-tuning the accuracy of the temperature sensor is as easy as changing the offset number  Adding hysteresis requires just one more programming box (a hysteresis block is available in the Libraries)  Altering what is displayed on the LCD (eg, displaying the temperature averaging time rather than setpoint) is as easy as drawing a new connecting line and changing the text label  Comparing the difference between two temperatures requires only the addition of another temperature sensor and a few boxes of programming. And the XOD software? The proof of the pudding is in the eating – in just this story we’ve not only introduced the programming software, but also managed to build a complete project! What next? I hope this piece inspired you to try XOD with an Arduino – there will be plenty more XOD-based projects in upcoming issues to tempt newbies into discovering the power of digital control. XOD files The XOD file discussed in this article can be downloaded from the March 2020 page of the PE website. Fig.10. Adding the DFRobot 1602 LCD Keypad Shield module completes the alarm project. (Note: this image only shows the lower section of the blocks; the top section is identical to the top two rows in Fig.9.) Pin compatibility issues meant this was the only complex stage of the project – but XOD took it in its stride, and the LCD shield works well – see Fig.3. 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.epemag.com 64 Practical Electronics | March | 2020