Silicon ChipFlowcode Graphical Programming - August 2022 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions
  5. Publisher's Letter: The power of batteries
  6. Feature: Time for a total rethink? by Mark Nelson
  7. Feature: Net Work by Alan Winstanley
  8. Project: Multi-purpose Battery Manager by Tim Blythman
  9. Project: Simple MIDI Music Keyboard by Tim Blythman
  10. Project: NANO PONG ON YOUR TV by TIM BLYTHMAN
  11. Project: USB Power Delivery Chargers by Jim Rowe
  12. Feature: Make it with Micromite by Phil Boyce
  13. Feature: KickStart by Mike Tooley
  14. Feature: Max’s Cool Beans by Max the Magnifi cent
  15. Feature: Flowcode Graphical Programming by Martin Whitlock
  16. Feature: Circuit Surgery by Ian Bell
  17. PCB Order Form
  18. Advertising Index

This is only a preview of the August 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)
Flowcode Flowcode Graphical Programming C void interrupt( void) { if ( intcon & 4 ) { clear_ bit( intcon, 2) ; FCM_ INTERRUP T_ TMR o( ) ; Assembly movlw D′7′ bsf STA TUS, RP 0 bcf STA TUS, RP 1 movwf _ adcon1 movlw D′192′ movwf _ option_ reg Hex : 04 0000008 A 011228 37 : 08 0008 00F000F00S030 EF10000 : 1000100004 0EF2000A 0 EF300B A 110A 1229 28 35 2 8 6 C : 2000200D9 28 FE28 07 3 Programming with Flowcode – Part 5: Building a Digital Clock I n this second and final part of the basic RTC Clock series we will cover the User Macros, variables, component functions and some new concept not covered in any previous articles. The core aim here is to build on last month’s description of the algorithm and create a working application in Flowcode. To do this, we will create three User Macros. We have split the program into three parts for two reasons. First, in the free version of Flowcode there is a limit of 20 icons that can be used in any one User Macro and with this constraint our program is too large to fit into one User Macro. Second, it is good programming practice to build program sections out of standalone User Macros. It makes program writing, editing and understanding easier and more efficient. (You can download the full program from the August 2022 page of the PE website.) Variables – global and local We discussed variable types in some detail last month, so now we need to define and describe the local and global variables that will be used in the program. First, here are the global variables used in the program. ReadKeypadValue1 Byte, Initial value = 0 ReadKeypadValue1 is used within the main User Macro to read the keypad value. If a key is pressed then the ChangeSettings User Macro is called. After the ChangeSettings User Macro is exited, then the ReadKeypadValue1 is used to determine if Hours (ReadKeypadValue1 = 1), Minutes (ReadKeypadValue1 = 2) or Seconds (ReadKeypadValue1 = 3) are adjusted. SetTime Byte, Initial value = 0 SetTime contains the value of either Hours, Minutes or Seconds assigned within the TimeSetValidity User Macro. SetTime is then used to set the time of the RTC. SetTimeStatus Byte, Initial value = 0 SetTimeStatus is only used within 58 the TimeSetValidity User Macro. It is used to count how many times the keypad has been pressed to enter Hours, Minutes or Seconds. For example, if key 1 is pressed, it will allow you to enter one more value and an additional key, eg, # or *. TempString[2] String length of 2 bytes TempString holds the entered time that’s being adjusted and converted from the SetTime variable, and then displayed on the LCD. A string is used to display the time, rather than a byte because if the time is 09 Fig.1. Adding three variables at once with the same (in the morning) then a byte variable type and initial value. will result in only ‘9’ being displayed because all leading zeros are discarded. However, with TempString, ‘09’ will be sent to the display. TimeString[8] String length of 8 bytes TimeString is only used in the Main User Macro. It retrieves the time from the RTC; eg, 09:24:58 (nine hours, twenty-four minutes and fifty-eight seconds in the morning), and it is then sent to the display. Adding the global variables Now we add the global variables. Continuing from last month, open the project to which you have added the project components. (Note: to make the variables easier to follow, I have decided to rename the one shown Fig.2. Adding multiple string variables. in PE, July page 50 Fig.6. From KeyPadValue to ReadKeypadValue1.) the process quicker, using fewer steps. Select the Globals icon from projTo do this, use Create a New Variable ect explorer. Notice that the first three and enter (including the commas) the global variables listed above are the names: ReadKeypadValue1, SetTime, same type – ie, a byte, initialised with SetTimeStatus. Enter 0 for Initial Value a value of 0. This means we can add all and leave Variable type to Byte, as shown three at the same time, which makes in Fig.1. Finally, select OK. Practical Electronics | August | 2022 Multiple string variables can also be added in one hit, but if their lengths are different just add [variable Length] at the end of each variable name. For example, since TempString has a value of two bytes and TimeString has a value of 8 bytes. You just enter: TempString[2], TimeString[8]. Remember to change Variable type to String, as shown in Fig.2. Again, select OK. Fig.3. Flowchart showing the overall algorithm of the Digital Clock. Note that anything not included in the ChangeSettings or TimeSetValidity User Macros is part of the Main User Macro. Start Initialise LCD and RTC Set RTC time Retrieve time from RTC, send time to LCD Has key 1 been pressed? Read keypad value There are two local variables in the ChangeSettings User Macro. Has a key been pressed? For Hours Y N Has key 2 been pressed? Y For Minutes Has key * been pressed? Y Clear digits N N Delay 100ms Has key 3 been pressed? N Y For Seconds Enter time digits, followed by * or # ChangeSettings User Macro .ExitChangeSettings Bool, Initial value = 0 .ExitChangeSettings is used to keep the program running within the loop. If the value is 0 then the loop will keep running until the value of .ExitChangeSettings is 1. .KeypadValue2 Byte, Initial value = 0 .KeypadValue2 is the keypad value when any key is pressed. If no keys are pressed, then the value stays at 255. If the 1 key is pressed then the value of .KeypadValue2 is 1; if the 7 key is pressed then the value of .KeypadValue2 is 7, and so on. The TimeSetValidity User Macro has just one local variable. .EndTimeSetRoutine Bool, Initial value = 0 At the end of the TimeSetValidity User Macro there is an expression within a calculation icon: .Return = .EndTimeSetRoutine. The value of .EndTimeSetRoutine variable is assigned to .Return, so when the TimeSetValidity User Macro has exited, the value of .Return is passed back to the ChangeSettings User Macro. We explained last month that this is the only way a local variable can be passed from one User Macro to another. Note that unlike other local variables, you don’t create .Return, this is done automatically. ReadKeypadFromChangeSettings Byte, parameter so no initial value .KeypadValue2 is passed to this parameter so that it can be used by the TimeSetValidity User Macro. See section with Fig.7 in last month’s article for an explanation of parameters. The User Macros Now we turn to the heart of the program – the three User Macros. Before proceeding it would be a good idea to refresh your memory of the program overview from the end of last month’s article. Practical Electronics | August | 2022 Y N Local variables Now we turn to the Local variables. You will recall from last month that they can only be set in a User Macro that uses them. You add them in the Project explorer. Select the Macros Icon, click on the ‘+’ of the appropriate User Macro, which will then show a Variables heading, under which you can doubleclick on ‘Add new’. Run set time routine N Has key # been pressed? N Y Time validation check OK? Y TimeSetValidity User Macro The flowchart in Fig.3 is an update of Fig.9 from last month, but with two red boxes added. One indicates the location of the ChangeSettings User Macro and the other is the TimeSetValidity User Macro. The rest of the diagram is the Main User Macro. You can see the User Macros in Fig.4 – this image is just to give you a rough overview of their construction. They are too big to reproduce properly here, so download them from the August 2022 page of the PE website. Notice that on these diagrams, each icon is numbered, and we will provide a commentary on each icon’s performance and contribution to the program. The three User Macros are called Main, ChangeSettings and TimeSetValidity. Main starts the program, displays the time and does this continuously providing no key is pressed. If a key is pressed the program transfers to the ChangeSettings User Macro, which first checks to see if the key pressed is 1, 2 or 3. If it isn’t one of these then the program returns to Main. If 1, 2 or 3 has been pressed then the program allows the user to enter Hours, Minutes or Seconds followed by a * (to clear the entry) or # (to accept the entered value). If the value is accepted then the program moves to the TimeSetValidity User Macro, which checks if a viable value has been entered. If not, then it returns the program to the ChangeSettings User Macro. If the value is viable then the program moves back to Main and updates the time. Now that you understand the purpose and operation of each User Macro, we will take each one and explain every icon according to the number label on the downloaded diagrams. Main User Macro You should know by now that every program must have a User Macro called ‘Main’. After the automatically inserted BEGIN icon, the 16 user-inserted icons perform the following roles. 1. lcd_16x2 Start This function initialises the display and must be placed before any other LCD component functions – otherwise, the display will be blank. This is an example of a function with no inputs or outputs. 59 Fig.4 a) Main User Macro. Fig.4. ‘Reduced’ versions of the three User Macros – download full-size versions from the August 2022 page of the PE website. 2. RTC1 Initialise This function initialises the RTC and must be placed before any other RTC component functions, otherwise the RTC component will not function. 3. Loop The loop must be present, so that the code does not reach the end of the User Macro and come to a halt. The loop ensures the code repeats indefinitely. 4. RTC1 GetTimeString, IncludeSeconds = 1, Return Value(STRING) = TimeString This is a function that requires an input and an output. In the Component properties box, the input is under Expression and the output is the under Return Value, in this case the variable required is a string. If the expression is a 1 then seconds are added to the string; eg, the string variable will be 21:42:34. If the expression is 0 then seconds are not added, and the string variable will be 21:42. Fig.4. b) ChangeSettings User Macro. 5. lcd_16x2 Cursor, x = 0, y = 1 This function is just an input. The expression values set the cursor position. In this case the cursor on the LCD will be set at the far left (x = 0) and the second row down (y = 1). 6. lcd_16x2 PrintString, Text = TimeString This is an input, the value of the string (TimeString) is sent to the display, starting at the cursor position set in icon 5. 7. Keypad_3x4 GetNumber, Return Value(BYTE) = ReadKeypadValue1 When a keypad button is pressed the value returned to the ReadKeypadValue1 variable represents the number of the keypad, except for the * and # keys which return 11 and 12, respectively. 8. Command Icon Decision: KeypadValue < 255 This statement will only be true (Yes branch) if a button is pressed and thus the value of KeypadValue becomes less than the default value of 255 (no buttons pressed). 9. User Macro = ChangeSettings This icon calls the ChangeSettings User Macro when it needs to be accessed. 10. lcd_16x2 Clearline, Line = 0 Clears the top row of the display. Fig.4. c) TimeSetValidity User macro. 11. Command Icon Decision: < 2 The Yes branch will only be accessed if the SetTimeStatus is less than 2. If that is the case the RTC will not be updated with the new time. 12. Command Icon Switch, Switch = KeypadValue, Cases =1, 2, 3 Setting up the Command Icon Switch is a little more complicated than other icons. Fig.5. shows the details. The Cases are the values expected. So, if ReadKeypadValue1 = 1 then the =1 branch will be accessed (Icon 13). If ReadKeypadValue1 = 2 then the =2 branch will be accessed (Icon 14) and so on. If none of the Cases match the ReadKeypadValue1 variable, then only the branch below the diamond icon is accessed. 13. RTC1 SetHours, Hours = SetTime, Mode = 0, WhichClock = 0 This sets the hours of the RTC. There are three inputs. Hours is set with the contents of the SetTime variable. Mode sets a 24hour format ( Mode = 0) or a 12-hour format (Mode = 1). For 60 Practical Electronics | August | 2022 6. lcd_16x2 PrintString, Text = “hours” This is placed within branch = 1, so it will only be accessed if 1 is pressed on the keypad. 7. lcd_16x2 PrintString, Text = “minutes” This is placed within branch = 2, so it will only be accessed if 2 is pressed on the keypad. 8. lcd_16x2 PrintString, Text = “seconds” This is placed within branch = 3, so it will only be accessed if 3 is pressed on the keypad. Fig.5. Setting up the Command Icon Switch. possible future upgrades to the project, WhichClock sets the type of clock: Main (WhichClock = 0) , Alarm1 (WhichClock = 1) or Alarm 2 (WhichClock = 2). 9. WaitReleased The program will halt here if the keypad is detected as being pressed. The program will continue as soon as the keypad has been released. 14. RTC1 SetMins, Minutes = SetTime, WhichClock = 0 Sets the minutes of the RTC 10. Command Icon Loop, Loop until selected, Expression = .ExitChangeSettings Test the loop at the start and if .ExitChangeSettings remains at 0 then the loop will carry on until .ExitChangeSettings changes from 0 to 1 15. RTC1 SetSecs, Seconds = SetTime, WhichClock = 0 Sets the seconds of the RTC 11. lcd_16x2 Cursor, x = 0, y = 1 Set the cursor position starting at 0. Here, the cursor on the LCD will be set at the far left (x = 0) and the second row down (y = 1). 16. Command Icon Delay = 100ms Adds a delay time of 100 milliseconds, so the display is not updating too rapidly. 12. Keypad_3x4 GetNumber, Return Value:(BYTE) = .KeypadValue2 If the keypad is pressed then the key pressed will be assigned to .KeypadValue2 variable. 17. Loop end You do not need to add anything to this icon; it’s the end of the program, so program flow jump back to icon 3. ChangeSettings User Macro Next, the ChangeSettings User Macro, which is called only when a key on the keypad has been pressed. 1. lcd_16x2 Clear Clears the whole display; there are no inputs or outputs. 2. Command Icon Calculation: SetTimeStatus = 0 This is just a calculation. When this icon is accessed, SetTimeStatus and .ExitChangeSettings are assigned to 0 (Note the period is required at the start because .ExitChangeSettings is a local variable.) Also, the string variable TempString is cleared. 13. Command Icon Decision: .KeypadValue2< 255 If the keypad is not pressed, then the value will default to 255, so the No branch is accessed. As soon as a key is pressed then the Yes branch will be accessed as the value will be between 0 and 12. 14. User Macro TimeSetValidity, ReadKeypad = .KeypadValue, Return Value(BYTE) = .ExitChangeSettings The value of local variable .KeypadValue2 is passed to the input of the TimeSetValidity User Macro. As soon as the TimeSetValidity User Macro has ended, the value of .ExitChangeSettings in the TimeSetValidity User Macro will be passed back to the ChangeSetting User Macro. 15. Command Icon Delay = 100ms Adds a delay of 100ms to prevent the display updating too rapidly. 3. lcd_16x2 PrintString, Text = “Set “ Note the deliberate space after Set and before the closing double quote mark. 16. Loop end Only exit loop if .ExitChangeSettings has been changed from 0 to 1, otherwise go back to icon 10. 4. Command Icon Switch, Switch = ReadKeypadValue1 There are three cases, 1, 2 and 3. As before (Fig.5) enter ReadKeypadValue1 for the variable name (below ‘Switch:’) and only tick cases 1, 2 and 3. TimeSetValidity User Macro 5. Command Icon Calculation: .ExitChangeSettings = 1 This is placed below the diamond icon, so if any value other than 1, 2 or 3 is entered then .ExitChangeSettings will change from 0 to 1. That in turn allows the loop to exit from the end of the User Macro at icon 16. Practical Electronics | August | 2022 The third User Macros is TimeSetValidity. This is only called after you have a) chosen via the keypad which time parameter to set (hours (1), minutes (2) or seconds (3)) and b) entered the first digit of a value. (See ChangeSettings User Macro, icon 14.) 1. Command Icon Decision: .ReadKeypadFromChangeSettings == 12 The Yes branch will be accessed if the # key is pressed (which has a key value of 12). 61 10. lcd_16x2 ClearLine(1) Clears the second row of the display. 11. lcd_16x2 PrintString, Text = TempString Display the value of the TempString variable. 12. keypad_3x4 WaitReleased Stop at this point if any key of the keypad is pressed. 13. Command Icon Calculation: .Return = .EndTimeSetRoutine Assign the .Return variable with the value of .EndTimeSetRoutine variable. (Important point: you don’t add the .Return variable. It is automatically added when a Return type is selected within the dropdown at the bottom of Create a New Macro pop up.) Components function types Component functions (eg, functions used by displays or keypads) can be one of four types in terms of inputs and outputs. It’s important to know which is which, so here is a brief overview. Fig.6. Setting up the Cursor function of the lcd_16x2. 2. Command Icon Calculation: .EndTimeSetRoutine = 1 .EndTimeSetRoutine is assigned 1 only if the Yes branch (1) was accessed, otherwise it will be the default value of 0. 3. Command Icon Decision: .ReadKeypadFromChangeSettings == 11 The Yes branch will be accessed if the * key is pressed (which has a key value of 11). 4. Command Icon Calculation: SetTimeStatus = 0 Assigns the SetTimeStatus with 0; and TempString = “” (the two empty quote marks clear the string). No input or output required At the start of the Main User Macro, examine lcd_16x2 Start (icon 1). Any variables within () after the name represents the input value, but since the brackets are empty no input is required. (Note that Start is the function, and lcd_16x2 is the component.) Only an input is required Next, consider lcd_16x2 Cursor in the Main User Macro, icon5. Note the two sets of numbers which represents the cursor x and y position, separated by a comma. These inputs can be a number or a variable which is compatible for the component. All inputs are entered under the Expression column as shown in Fig.6. Note in Fig.6 that the Return Value is greyed out because a returned value would be an output, which in this case is not needed. 5. lcd_16x2 ClearLine(1) Clears the second row of the LCD. Only an output is required If you look at the Main User Macro, icon 7, the component function is keypad_3x4 GetNumber which occurs when a button is pressed. The output value is returned to the ReadKeypadValue1 variable. 6. Command Icon Decision: (.ReadKeypad < 255) && (SetTimeStatus < 2) The Yes branch is accessed only when a key is pressed (255 = no key pressed) AND if the SetTimeStatus is less than 2. Both input and output are required Last, look at the Main User Macro, icon 4. Here, the input for RTC1 GetTimeString is the 1 in the brackets, while the output is returned to the TimeString variable. 7. Command Icon Calculation: TempString = TempString + ToString$ (.ReadKeypad) The keypad is read and the ToString$ coverts the keypad value from a byte to a string; the result is added to the TempString variable. SetTimeStatus = SetTimeStatus + 1 increments the value of the SetTimeStatus by 1; SetTime = StringToInt$ (TempString) converts the value of TempString back to a byte value and is assigned to the SetTime variable. Finally, note that a component does not necessarily always operate with just one of the above (eg, only input or only output), it depends on which function of the component being used. For example the first two categories above both used the component lcd_16x2 but with different functions, Start and Cursor. 8. Command Icon Decision: (ReadKeypadValue1 == 1 && SetTime > 23) || (ReadKeypadValue1 == 2 && SetTime > 59) || (ReadKeypadValue1 == 3 && SetTime > 59) The Yes branch is accessed if (ReadKeypadValue1 AND SetTime is greater than 23) OR if (ReadKeypadValue1 is 2 AND SetTime is greater than 59) OR if (ReadKeypadValue1 is 3 AND SetTime is greater than 59). 9. Command Icon Calculation TempString = “” clears the TempString variable. SetTimeStatus = 0 assigns the SetTimeStatus variable with 0. SetTime = 0 assigns the SetTime variable with 0. 62 Setting up a simulation Now that we have the three User Macros, it’s time to look at using Flowcode’s simulation tools. We won’t go over the full simulation procedure – we have already covered that (see: PE, February 2022), but here are some points worth emphasising. When running a simulation in Flowcode, the key parameters to watch as we step through or run the program are the variables. Before running a simulation you can check what variables are in the program by selecting the appropriate Globals or Locals icons within Project explorer (if closed, Project explorer can be opened within the view menu). Naturally, local variables, if any, can only be seen if you select the appropriate User Macro tab at the top of each User Macro flowchart. In this project, Main doesn’t use local variables, so you would need to select either the ChangeSettings or TimeSetVailidity tab to see local variables. Practical Electronics | August | 2022 To start the simulation press the F8 key, which will open the Simulation debugger window. Referring to Fig.7, select the global variables you wish to watch, by clicking on ‘…’ in the Value field for Expression. Then choose Add variable from the resulting pop up and select the Globals or Locals icon, depending on what you are interested in simulating. Again, remember if to want to add and watch local variables they will only be available for adding if either you or the simulator have accessed the appropriate User Macro tab. While the simulator is running the current User Macro will be shown on the left of the simulation debugger at the bottom of the list and the User Macro which called it will appear immediately above it; again, see Fig.7. Also, since the values of local variables can only be viewed when in the appropriate User Macro, if you are in a different User Macro then you will see ‘Unknown or missing local variable’ highlighted in blue, as shown in Fig.7. This is normal, the correct value will be displayed when the relevant User Macro is accessed. With local variables, on the simulation debugger, the User Macro name is shown first, then a period/full stop, then the name of the local variable. For example, .ExitChangeSettings will be shown as ChangeSettings. ExitChangeSettings Three periods/full stops (…) after a variable means that part of the name is hidden as it is too long for the window width. To adjust the width, hover the cursor between any variable and the value, then the cursor will change to double arrows, hold the left mouse button down and drag the variable window size. At the top of Fig.7 you can see the Simulation slider. Slide it so that it changes from Fast (no updates) to Fast (with updates). This setting means you can see the variables values change. Running a simulation After the variables have been added to the simulation make sure you can view the 2D Dashboard panel (see PE, January 2022). We are now ready to run the simulation. Run the program by pressing Go in the Debug ribbon. If all is working, then you should see the time constantly updating in the LCD on the 2D Dashboard panel. Now test setting the time. Press 1 on the keypad, the display should change from displaying the time to the words ‘Set hours’, shown on the top line of the display. Try pressing an invalid time eg, 72. You should see the numbers disappear as the program does not allow 72 to be set for hours. Add a valid time (12) and then press the * to clear your entry or press # to enter the value. (Note that there is an important RTC limitation when simulating Practical Electronics | August | 2022 Fig.7. The simulation debugger window – note the speed slider and ‘Unknown’ values. in Flowcode – the only time which can be displayed is the local PC time, you cannot set the display to a random non-PC time. Of course, on your actual project hardware this limitation will not apply. Debugging software When you run a simulation, it is important to note any information shown in the Icon Lists window. This window doesn’t have to be always open because it will automatically pop up if the simulation produces an issue that needs highlighting. For example, with the simulation stopped, right-click on the Keypad_3x4 Getnumber component within the Main User Macro and select Disable. Now remove the initial value of ReadKeypadValue1 variable. Run the simulation and the Icon List should pop up showing ‘Uninitialized variable’ (see Fig.8), indicating an error that needs correcting. (An uninitialized variable is a real problem – it will usually cause your hardware to contain a random value, resulting in unexpected performance.) Setting up the hardware In this project, we’ve focused the bulk of both articles on the software, but what about the hardware? The hardware should be built on breadboard. It’s a straightforward build – just follow the schematic in Fig.9. If you built the LCD Temperature Monitor (PE, April 2022) then you should recognise the wiring for the display. The rest of the connections to the keypad and RTC are not difficult but do pay attention to the resistors – there are two values and these are wired differently. When the wiring is finished you are ready to send the code to the target device. Now power it up. Once the hardware is running the LCD will show the time, but it will be a random time because you haven’t set up the RTC with the correct time. Use the keypad to enter the correct Hours, Minutes and Second. Fig.10 shows the system up and running. Fault finding hardware Even the simplest circuits can exhibit faults. The following are the most common problems you are likely to encounter. Display is showing one row of rectangles First check you have initialised the display in the Main User Macro. If that has been done correctly then check the connections to the display’s data, RS and RW lines. Make sure they match the schematic (Fig.9). Also, check that the connections to the LCD in its component properties in Flowcode match the hardware in the schematic. Do note that RW is not shown in component properties since it is just connected to GND. Display is blank Check the supply pins are at the correct voltage and vary the contrast trimmer. Verify the voltage on the contrast pin (3) varies from 0 to 5V. Display is showing two rows of rectangles This normally means the contrast voltage is wrong. Follow the ‘display is blank’ fault finding. Display shows a random time For example, the display shows 02:01:00 and it does not change. This will be an issue between the RTC and the RedBoard/ Uno. Check the connections match for Flowcode and your hardware. The SDA and SCK connections could be reversed on your hardware, or open circuit. Always check the correct power supply is going to the RTC pins. Fig.8. Icon Lists window highlighting an error during a simulation. 63 + 5 V 1 2 3 A 4 5 6 B 7 8 9 C * 0 # D Fig.9. Full schematic for the RedBoard-RTC Digital Clock with 16x2 LCD display. R1 R2 R3 R4 C1 C2 C3 C4 1 2 3 4 5 6 7 8 NC 3x 1 VIN D0/ RX 4 x 1 RESET D1/ TX D2 IOREF D3 G ND D4 A REF D5 2 7 8 9 10 D6 15 A VDD D0 D4 D1 D5 D2 D6 D3 D7 RS E VO Contrast 3 R/ W 5 VSS 1 Redoard/ A rduino Uno 11 12 13 14 4 6 A 1 D8 A 2 D9 A 3 D10 SCL/ A 5 D11 SDA / A 4 D12 D13 K 16 A O D7 SCL SCL SDA SDA VCC 32K 16 x2 LCD ( See text ) 3V3 VR1 1 RTC DS3231M Module* G ND G ND G ND SQ W G ND 5 *P ull- up resistors not req uired. 0V Try Flowcode for free! Fig.10. The Digital Clock up and running. Martin Whitlo is an Applications Engineer at Matrix TSL – which is the company behind Flowcode. 64 We hope you found this article interesting. If you’d like to try Flowcode for free then just go to https:// ow ode. o.u download and download the code. You’ll get a 30-day free trial of the full version – but that’s not all. Even after the 30 days are up your copy of Flowcode will continue to work, but at a reduced level with a limit on the size of program you can run and access to a more basic set of parts. However, for beginners it is still an ideal platform with which you can build and run programs, on for example, the Arduino Uno/ RedBoard or a PIC 16F88 that we are using in this project. Only when you are sure that you want to use Flowcode do you need to buy inexpensive access to say a Raspberry Pi or Bluetooth module. (See: https ow ode. o.u buy pro ess for all the modules available and what they contain.) What’s more, as soon as you buy any module, the restrictions on the size of your code are removed. If you get stuck with anything relating to Flowcode use (installation, software, creating flowcharts, compiling to hardware, hardware not working…) then there are forums set up to help you: https www. ow ode. o.u oru s dis ount One more thing – Flowcode is deliberately designed to be inexpensive, but PE readers can get a further 20% discount when they use the code PE20 at checkout. Practical Electronics | August | 2022