Silicon ChipThe Colour Maximite 2 – part two - August 2020 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Businesses need to handle ‘black swan’ events better
  4. Feature: Measuring distance & motion with lidar and SODAR by Dr David Maddison
  5. Project: USB SuperCodec by Phil Prosser
  6. Feature: Microchip’s new Hello FPGA kit by Tim Blythman
  7. Project: A homemade Switchmode 78XX replacement by Tim Blythman
  8. Serviceman's Log: Fixing heaters – it’s a gas by Dave Thompson
  9. Product Showcase
  10. Project: 1MHz-6GHz Arduino-based Digital RF Power Meter by Jim Rowe
  11. Vintage Radio: Velco 1937 'kit' radio restoration by Ken Kranz
  12. PartShop
  13. Project: The Colour Maximite 2 – part two by Geoff Graham & Peter Mather
  14. Feature: Vintage Workbench by Alan Hampel
  15. Market Centre
  16. Advertising Index
  17. Notes & Errata: DIY Reflow Oven, April-May 2020
  18. Outer Back Cover

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

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

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

Items relevant to "USB SuperCodec":
  • USB SuperCodec PCB [01106201] (AUD $12.50)
  • USB SuperCodec Balanced Input Attenuator add-on PCB [01106202] (AUD $7.50)
  • Parts source grid for the USB SuperCodec (Software, Free)
  • USB SuperCodec PCB pattern (PDF download) [01106201] (Free)
  • USB SuperCodec Balanced Input Attenuator add-on PCB pattern (PDF download) [01106202] (Free)
  • USB SuperCodec front panel artwork (PDF download) (Free)
  • Drilling and cutting diagrams for the USB SuperCodec Balanced Input Attenuator (PDF download) (Panel Artwork, Free)
Articles in this series:
  • USB SuperCodec (August 2020)
  • USB SuperCodec (August 2020)
  • USB SuperCodec – part two (September 2020)
  • USB SuperCodec – part two (September 2020)
  • USB SuperCodec – part three (October 2020)
  • USB SuperCodec – part three (October 2020)
  • Balanced Input Attenuator for the USB SuperCodec (November 2020)
  • Balanced Input Attenuator for the USB SuperCodec (November 2020)
  • Balanced Input Attenuator for the USB SuperCodec, Part 2 (December 2020)
  • Balanced Input Attenuator for the USB SuperCodec, Part 2 (December 2020)
Items relevant to "A homemade Switchmode 78XX replacement":
  • Switchmode 78xx Replacement PCB [18105201] (AUD $2.50)
  • Kit for the Switchmode 78xx Regulator replacement (Component, AUD $13.50)
  • Switchmode 78xx Regulator PCB pattern (PDF download) [18105201] (Free)
Items relevant to "1MHz-6GHz Arduino-based Digital RF Power Meter":
  • Wideband Digital RF Power Meter PCB [04106201] (AUD $5.00)
  • 16x2 Alphanumeric serial (I²C) LCD module with blue backlight (Component, AUD $12.50)
  • Arduino sketch for the Wideband Digital RF Power Meter (Software, Free)
  • Wideband Digital RF Power Meter PCB pattern (PDF download) [04106201] (Free)
  • Wideband Digital RF Power Meter lid panel artwork & drilling diagrams (PDF download) (Free)
Items relevant to "Velco 1937 'kit' radio restoration":
  • Velco 1937 Radio Files (SPICE models and Valve Data) (Software, Free)
Items relevant to "The Colour Maximite 2 – part two":
  • Colour Maximite 2 PCB [07107201] (AUD $10.00)
  • Colour Maximite 2 front & rear panels (PCB, AUD $10.00)
  • Colour Maximite 2 software and documentation (Free)
  • Colour Maximite 2 PCB pattern (PDF download) [07107201] (Free)
  • Colour Maximite 2 front and rear panel cutting diagrams and front panel artwork (PDF download) (Free)
Articles in this series:
  • The all-new Colour Maximite 2 (July 2020)
  • The all-new Colour Maximite 2 (July 2020)
  • The Colour Maximite 2 – part two (August 2020)
  • The Colour Maximite 2 – part two (August 2020)
Items relevant to "Vintage Workbench":
  • Tektronix T-130 LC Meter Supplemental Materials (Software, Free)
Articles in this series:
  • Vintage Workbench (June 2020)
  • Vintage Workbench (June 2020)
  • Vintage Workbench (July 2020)
  • Vintage Workbench (July 2020)
  • Vintage Workbench (August 2020)
  • Vintage Workbench (August 2020)

Purchase a printed copy of this issue for $10.00.

Colour Maximite 2 Words and MMBasic by Geoff Graham Design and firmware by Peter Mather Part 2 We introduced the Colour Maximite 2 last month, but now we delve into the details of building it. As it turns out, that is quite easy because all the complex stuff is on the preassembled Waveshare CoreH743I CPU Board. The PCB that you need to populate is a simple double-sided board with mostly through-hole passive components. You should be able to finish it off it in an hour or two. B efore starting, take precautions against static electricity which could damage the STM32 processor. You do not need to go overboard here, but you should discharge yourself by occasionally touching a grounded point on your workbench and making sure that you do not unnecessarily handle the CPU board and its connecting pins, The main ‘motherboard’ PCB is labelled “Colour Maximite 2: V2.1” and measures 130 x 102mm. As shown in the PCB overlay diagram, Fig.5, it has cut-outs on either side to clear the moulded posts in its plastic case, and two small cut-outs at the front with a ‘peninsula’ in between that has three exposed copper pads on it. This is the “Nunchuk” connector. Start by soldering the two 80-pin sockets used for the plug-in CPU module. The trick here is to solder them in such a way that the solder does not wick up the pins, preventing the CPU module from being properly inserted. So use the following procedure. Place the motherboard on a flat surface and insert both 80-pin connectors in their correct places on the board. Then gently push the CPU board into these connectors. We say gently because you do not want to bend the pins 88  Silicon Chip on the connectors or the CPU board. Then, while holding the CPU board in place on the motherboard, turn the board over and solder all the connector’s pins. Don’t use a lot of solder; only a small amount is required for each pin. The CPU board can then be unplugged and placed aside while the remaining components are fitted. Next to go in should be the audio socket. The reason for this is that the PCB is a little crowded around it, and it is an SMD part, so if you leave the audio socket to last, it will be difficult to get your soldering iron in without causing damage. Solder its five large pins to the pads on the top of the board. Next, solder the SD card socket, which is also surface mounted. This This is the assembled motherboard without the Waveshare CPU board plugged in. Usually hidden by the CPU board are three capacitors, a resistor and the SD card socket. Note that this is a prototype and the final PCB will vary slightly in its layout (see the panel for details). Australia’s electronics magazine siliconchip.com.au The Colour Maximite 2 in its case. If you remember computers like the Tandy TRS80, Commodore 64 or Apple II from the 80s, you will be right at home playing with this. The differences are that this is about a hundred times faster, has a much better display and costs a fraction of the price! Fig.5: follow this PCB ► overlay diagram to build the ‘motherboard’. Once you’ve fitted the connectors and larger components, there isn’t much to it. The remaining components are a few small ceramic capacitors and 46 miniature 0.25W resistors. SMD resistors can be used instead, if desired. has two small posts on the underside which click into matching holes in the PCB to ensure perfect alignment. With the socket in position, solder the two tabs on the right side of the socket (viewed from the front) and five on the left side. Some are tiny and can be easily missed, so count them when you have finished (seven in total). Some are also close to the shield of the socket. So take care not to cause a solder bridge there. Note that the socket must be held firm to the PCB while soldering, as any gap between it and the PCB will prevent an inserted SD card from making reliable contact with the connector pins. Finish it off by soldering the nine pins at the rear. To do this, spread some flux paste over the pins and load up your fine-tipped soldering iron with a little solder; a small bump is all that you need. For each pin, slide the tip of your iron over the solder pad towards the connector so that the tip hits the connector’s pin, and the solder should magically flow around the pin. If you get a solder bridge, don’t worry and carry on with the other pins. Finally, examine your soldering using a powerful magnifier and clean up any solder bridges using solder wick. Be careful here, as solder wick can suck siliconchip.com.au up all the solder so you might have to come back and resolder any pins that look like they don’t have enough solder. The last device that is to be soldered on the top side of the PCB is the battery holder, so you might as well do that now. Its orientation is shown on the PCB silkscreen, and the pads are large, so this should be an easy job. Through-hole parts Next, it is worth soldering the highprofile connectors and the power switch. They will hold the PCB off the bench when you later place it upside down to mount the capacitors and vertically-mounted resistors. There is nothing complicated about soldering these components. It is just a case of placing them in position as shown in Fig.5 and the PCB silkscreen printing, and soldering their pins. After you have done this, go back with a magnifier to check and rectify any suspicious joints. You can then install the optional IR receiver and DS18B20+ temperature sensor if you wish. These can easily be added later, so they are not critical. There are only five capacitors on the motherboard. Three of these are situated under the CPU module, and they Australia’s electronics magazine should be mounted flat on their sides so that they will not obstruct the CPU module when it is plugged in. The board is designed to accept polarised Tantalum types for the 10µF and 1µF values, but we’ve specified ceramics as they perform better and are more reliable, and that is what we’re supplying in our kits. Unlike Tantalum capacitors, which are a type of electrolytic capacitor, they are not polarised, so you don’t need to worry about their orientations. Ten of the resistors sit flat on the PCB, and they can be soldered next (see the colour code table on page 97). The pads are spaced to suit 0.5W or 0.6W resistors, but you can use smaller 0.25W resistors if you want to (that’s what we supply in our kits). There is an additional eleventh resistor (4.7kW) near the back panel which is only required if you are installing the optional DS18B20+ temperature sensor. Still, you might as well install it now anyway, as it’s cheap and easy and you might want to add that sensor later (this is also supplied in our kit, even though the sensor itself isn’t). Then there are 35 resistors used in the R-2R ladders for the VGA analog outputs. As mentioned last month, August 2020  89 ► these are vertically mounted to save space, although you can also use 3216/1206-size surface mount resistors. Make sure that they match the silkscreen legend and will not get in the way of the CPU board when it is plugged in. The USB-serial converter chip comes in a 14-pin DIL package, and you should use an IC socket for this, so that you can pull the chip out if you suspect that something is wrong. Into this socket, you can plug the MCP2221A from Microchip or the Microbridge, as mentioned last month (our kit comes with the latter). Both work identically, but the MCP2221A does not need programming, so it will be the preferred option for some. The Microbridge (May 2017; siliconchip.com.au/Article/10648) is a PIC16F1455 or PIC16F1454 microcontroller programmed with the Microbridge firmware, which you can download for free from our website. There are six pads beside this chip for an optional six-pin header to allow you to program this chip, although the ones we supplied come pre-programmed, so that should not be necessary if you’re building it from a kit. The last item to install is the vertically-mounted LED module which indicates power and SD card activ- ity. Using this module makes it easy to get the correct alignment with the matching holes in the front panel, but you can use discrete 3mm LEDs if you wish. If using discrete LEDs, temporarily mount the motherboard in the case (see below and don’t forget the spacers). Then, fit the front panel and bend the leads of the two LEDs to suit the front panel holes. With the leads in place on the motherboard and the LEDs poking through the front panel, you can tack-solder one lead for each LED from the top of the motherboard to keep it in place. Finally, remove the motherboard and securely solder and trim the LED’s leads on the underside of the PCB. Initial testing Before you apply power, it is good insurance to go over both sides of the motherboard in detail with a magnifier, to confirm that all the solder joints are good and nothing has been missed. The current drawn by the motherboard and the STM32 processor is a good indication of the state of both. So, for the first test, make sure that the CPU module is not plugged in, place a CR1220 battery in the battery holder and do not connect anything else (VGA, SD card etc). Using a Type-A to Type-B USB ca- Fig.6: the current drawn by the motherboard and STM32 processor is a good indication of whether they are functioning correctly. You can easily measure this by plugging in the USB power cable with the front panel switch off and connecting a DMM set to measure milliamps across the switch terminals, as shown here. 90  Silicon Chip Australia’s electronics magazine ble, plug the motherboard into a 5V source but leave the front panel power switch off (up). Set your multimeter to measure direct current on the order of 200mA and place the probes across the switch contacts as shown in Fig.6. The reading should be 0mA. Next, prepare the Waveshare CPU module by removing any jumpers, set the power switch on the top side to “5VIN” and the BOOT CONFIG switch to “Flash”. Then plug the module into the motherboard. Make sure that the orientation is correct; the USB socket on the top of the module’s PCB should be to the rear of the computer and the 20pin IDC connector to the front. Again, with nothing else connected to the motherboard, plug it into a source of 5V. Measure the current across the power switch, which should now be about 45mA. If the CPU module has had the Colour Maximite 2 firmware loaded (your supplier might have done this), the current drawn will be about 180mA. Anything significantly different from these numbers indicates a problem; see the fault-finding steps below. Communicating with the STM32 processor The STM32 processor includes its own firmware loader/programmer so the Colour Maximite 2 firmware can be easily loaded via USB using a personal computer or laptop. You do not need any specialised hardware. First, go to the STM32 manufacturer’s website at siliconchip.com.au/ link/ab2x and download the STM32CubeProgrammer software. This is free software, but ST requires that you have an ST account or provide your name and email address. They will then email you a link to download the software. Windows, Linux and macOS versions of this software are available. Install the appropriate version on your computer and check that it runs. Now set the BOOT CONFIG switch to “SYSTEM” – this tells the STM32 processor to expect a firmware upload. Note that this is different from the position of the switch used in our initial tests above. Disconnect all cables, including the USB Type-B power cable. Use a USB Type-A to Type-A cable to connect the USB Keyboard port to a USB port on your desktop or laptop siliconchip.com.au 2 Select connect, refresh if needed 1 Select USB the screenshot (the USB port number may vary). Click on the “Connect” button. You should then see a series of messages as shown in Fig.7, concluding with the message “Data read successfully”. Any messages in red indicate an error. Programming the firmware 3 Check messages Fig.7: the STM32CubeProgrammer software is used to load the firmware into the STM32 processor. Select USB as the communications method; if the USB connection is not recognised, click on the small blue circle to refresh the entry. Your screen should look like this (the USB port number may vary). computer. This will power up the Colour Maximite 2 regardless of the position of the power switch. You should also hear a sound from your desktop computer as the Colour Maximite 2 connects to it. Note that if you don’t have a Type-A to Type-A cable, you can use a TypeA to micro Type-B cable and plug it into the USB power on the WaveShare STM32 module. But this won’t be accessible later when the case is assembled, and you have to unplug Fig.8: this is the “Erasing and Programming” mode. Select the firmware file (it will have an extension of .bin), tick the “Verify programming” checkbox and click on the “Start Programming” button. Then wait for the “Download verified successfully” dialog box. The operation will take under a minute, and any errors will result in a message in red. siliconchip.com.au the WaveShare module to get to this port, so it’s a good idea to get a hold of a Type-A to Type-A cable. Run the STM32CubeProgrammer software on your computer. On the top-right of the program window, select USB as the communications method (see Fig.7). If the program does not recognise the USB connection, click on the small blue circle to the right of the Port drop-down list to refresh the entry. Your screen should look like Now click on the download button on the left side of the STM32CubeProgrammer window. The software will switch to the “Erasing and Programming” mode, as illustrated in Fig.8. Use the “Browse” button to select the firmware file you downloaded from our website (it has a .bin extension) and tick the “Verify programming” checkbox. Then click on the “Start Programming” button. The STM32CubeProgrammer software will program the firmware into the flash memory on the STM32 (it calls this “downloading”). After a short time, a dialog box will pop up saying “File download completed”. Do not do anything at this point, as the software will then start reading back the firmware programmed into the flash. When this has completed successfully, another dialog box will pop up saying “Download verified successfully”, as shown in Fig.8. The whole operation will take under a minute, and any error messages will be shown in red. If all is OK, dismiss all the dialog boxes and close the STM32CubeProgrammer software. Remove the USB 1 Select programming 3 Tick verify 2 Load firmware 4 Start programming 5 Dismiss dialog boxes 6 Check messages Australia’s electronics magazine August 2020  91 Type-A to Type-A cable from the USB Keyboard port and plug in your VGA monitor and USB keyboard. On the CPU board, set the BOOT CONFIG switch back to “Flash” and plug the Colour Maximite 2 into power and set the power switch to on (down). You should now see the Maximite logo on the VGA monitor, along with the version number of the firmware that you have just loaded, as shown in Fig.9. Note that initially, some monitors may truncate the text on the margins or show an image that seems to shimmer or flicker. In most cases, this can be fixed by pressing the auto setup button on the monitor or, failing that, using the monitor’s image setup mode to adjust parameters such as the clock, phase and position. When MMBasic is first loaded, it will prompt for the keyboard type and the date/time. On subsequent firmware upgrades, MMBasic will preserve these settings (in addition to the real-time clock settings) and will not prompt for them again. All of these can be changed later using the relevant OPTION commands. As a final test, the current drawn with the STM32 running the Colour Maximite 2 firmware should be 160220mA, depending on the current drawn by your keyboard and SD card. If you wish to load another version of the firmware (eg, to upgrade it), this can be done by repeating the steps above. To avoid having to open the case up to change the position of the BOOT CONFIG switch when upgrading, MMBasic has a handy command: “UPDATE FIRMWARE”. This reboots the Colour Maximite 2 directly into bootloader mode. Case assembly The motherboard is designed to sit in a standard ABS plastic instrument case available from Altronics and Jaycar. Some suppliers will include the front and back panels made up as printed circuit boards, without copper tracks and with cut-outs in the correct places. In that case, they should just drop straight in. If not, you will have to manually make the cut-outs in the blank panels supplied with the enclosure by following the dimensions in Fig.10. The simplest way of doing this is to download this as a PDF file from the Silicon Chip website and print them with 1:1 scaling. You can use that as the template for the cut-outs. Fig.10 also includes the front panel artwork. We printed this onto heavyduty adhesive-backed paper and then covered the printed surface with adhesive clear plastic film, of the type used to cover books. After you have trimmed the label and made the cutouts using a sharp razor blade or hobby knife, stick it onto the front panel for a professional result. An additional benefit of this technique is that you can make the cut-outs in the plastic front panel slightly larger than necessary, and the adhesive label will hide any rough edges. The motherboard can be fastened to the pillars in the enclosure using four ordinary 8mm M3 screws (self-tappers are not required) – see Fig.11. You need to add 5mm spacers on each mounting pillar to elevate the PCB and its connectors to match the Fig.9: when you power up the Colour Maximite 2 with a VGA monitor plugged in, you will see a splash screen like this. It shows the version of MMBasic installed. Check this against the latest version on the Author’s website to see whether an upgrade is available. When MMBasic is first loaded, it will prompt for the keyboard type and the date/time. 92  Silicon Chip Australia’s electronics magazine cut-outs in the front and rear panels. You may be able to get away with two M3 nuts instead of the 5mm spacer, but it would be better to use the real thing. What can I do with it? Here are a few things that you can try out first, just to prove that you have a working computer. All of these commands should be typed at the command prompt (“>”). What you type is shown in bold, and MMBasic’s output is shown in normal text. Try a simple calculation: > PRINT 1/7 0.1428571429 See how much memory you have: > MEMORY Flash: 0K ( 0%) Program (0 lines) 516K (100%) Free RAM: 0K ( 0%) 0 Variables 0K ( 0%) General 5471K (100%) Free What is the current time? > PRINT TIME$ 09:04:01 Draw a circle: > CIRCLE 400, 100, 50 Draw a line: > LINE 0, 0, 799, 399 Fault-finding What if it does not work? The first step is to measure the current drawn by the assembled device. If it is 160220mA then that indicates that the firmware has been loaded and is running correctly. If this is OK but you cannot see anything on your VGA monitor, that probably means that something is wrong between the STM32 processor and the monitor. Try a different VGA cable, check for bent pins on the CPU module, check the ladder resistors and, of course, check your soldering. If the current drain is about 45mA then it’s likely that the firmware has not been correctly loaded into the STM32 processor, so you should re-run those steps. Anything other than the above indicates a serious problem. You can test the Waveshare CPU module by removing it from the mothsiliconchip.com.au Fig.10: these are the cut-outs required for the front and back panels. You can download this diagram from the Silicon Chip website, print them with 1:1 scaling and use them as templates for making the cuts. The front panel artwork can be printed onto adhesive-backed paper to make a label (see text). erboard, placing shorting jumpers on all header pins except PA9-VBUS and setting the power switch to USB and the BOOT CONFIG switch to SYSTEM. Then plug a USB cable into the micro USB connector on the top of the Waveshare module and the other end into your desktop computer. Both LEDs on the module should illuminate, and it should connect to your computer. If the VBUS LED does not illuminate, you probably have not configured the board correctly, or USB power is not available. If VBUS illuminates but the PWR LED doesn’t, check the 3.3V regulator on the underside of the module. Then, using the steps listed above, try loading the Colour Maximite 2 firmware onto the STM32 processor using this USB cable and your desktop computer. The procedure is the same as described above when loading the firmware via the USB keyboard port using the STM32CubeProgrammer software. If this process goes without a hitch, you can be sure that your Waveshare CPU module is perfectly OK and your problem must be something to do with the motherboard. By the way, this is an alternative method of loading the firmware if you siliconchip.com.au do not want to use a USB Type-A to Type-A cable to load the firmware via the USB Keyboard port. The motherboard itself is so simple that, if you suspect a fault with it, you can just use traditional troubleshooting steps. Check for bent pins (especially on the Waveshare CPU module), check all component leads/pads are soldered, check for short circuits between pads and pins etc. A table showing the pin layout of the Waveshare CPU module can be found overleaf. Calibrating the real-time clock (RTC) We have found that the out-of-thebox accuracy of the real-time clock in the STM32 is rather poor. This is not a huge problem, as usually the date/ time is only used for time-stamping files on the SD card. But if you would like it to be more accurate, the STM32 can be tweaked to correct for any drift. This is done in MMBasic with the OPTION RTC CALIBRATE command. This command takes a number between -511 and + 512; each step corresponds to a change of about 0.0824 seconds per day. Negative numbers will slow the clock down while positive will speed it up. With a bit of patience, you can get it spot-on. The best approach is to set the time accurately using an Internet time source, eg: TIME$ = “hh:mm:ss” Then, after (say) a week, check the current clock time with the following statement: PRINT TIME$ Fig.11: the motherboard fastens to four of the pillars in the enclosure using 8mm-long M3 machine screws (self-tappers are not required) and 5mm spacers. The spacers elevate the PCB and its connectors to match the cut-outs in the front and rear panels. Australia’s electronics magazine August 2020  93 Simple arithmetic (number of seconds offset ÷ [0.0824 × total days passed]) will then tell you the correction needed, and you can apply that as follows: OPTION RTC CALIBRATE ±nn Just make sure to get the correction sign right, ie, make it positive if the clock drifted behind the actual time, or negative if it was ahead. Interacting with MMBasic Communication with the Colour Maximite 2 is via the console at the command prompt (ie, the greater than symbol > on the console). On startup, MMBasic issues the command prompt and waits for a command to be entered. It will also return to the command prompt if your program ends or if an execution error is encountered. When the command prompt is displayed, you can issue commands related to the program that you are working on (EDIT, LIST and RUN). You can set some options (the OPTION command) and delete, copy and rename files and directories (FILES command). Almost any command can be entered at the command prompt; this is often used to test a command to see how it works. A simple example is the PRINT command, which you can test by entering the following at the command prompt: PRINT 2 + 2 Not surprisingly, MMBasic will print out the number 4 before returning to the command prompt. This ability to test a command at the command prompt is handy when you are learning to program in BASIC. The CTRL-C sequence (hold down the CTRL key then press the C key) is called the break key or character. When you type this on the console, it will interrupt whatever MMBasic is doing and immediately return control to the command prompt. Remember this, as it can get you out of all sorts of difficult situations. Test Program “bounce.bas” BOX 0, 0, 800, 600, 1, RGB(yellow), RGB(black) x = 400 y = 300 dx = 1 dy = 1 DO CIRCLE x, y, 30, 2, ,0, RGB(red) x = x + dx IF x = 31 OR x = 768 THEN dx = dx * -1 y = y + dy IF y = 31 OR y = 568 THEN dy = dy * -1 PAUSE 2 LOOP do with it. As you read the following, keep the user manual handy so that you can look up the details of the commands used. You can use the built-in editor to enter this program. If you have used a text editor before, you will find its operation familiar. The keyboard arrow keys move your cursor around the text while the Home and End keys take you to the beginning or end of the line. The delete key deletes the character at the cursor, while backspace deletes the character before the cursor. You must have a properly formatted card in the SD card slot, as this is where the editor will save your file when you have finished entering it. To start the editor, type EDIT “bounce. bas” at the command prompt and press Enter. Then type in the program shown above. Press the F2 key to save your program and run it. You should see a yellow boundary drawn around the edges of the screen and a red ball bouncing around inside it, as shown in Fig.12. As mentioned earlier, you may need to adjust your monitor to see all of the yellow boundary (ie, press the auto setup button on your monitor). If there was an error in your program, you will get a message with the line number and the error description. You can then re-enter the command EDIT (or press F4 at the command prompt) and you will be taken back into the editor, with the cursor positioned on the line that caused the error. Correct the error and then save/re-run the program by pressing F2. Program details This program demonstrates how BASIC and the graphics commands work. At the start, we draw a box which is as big as the screen using yellow for the outline and filled with black. The RGB() function returns a colour value so, for example, RGB(yellow) will return the value of the colour yellow, and that is passed to the BOX command as the colour to be used. The next two lines set the variables x and y to the initial coordinates (or position) of the centre of the ball that we are going to draw. By setting x = 400 and y = 300, we start by positionFig.12: if you’ve entered the test program correctly, once you run it, you will see a screen like this. The ball will bounce around the screen, changing direction each time it touches one of the edges. Test program This simple program will cause a red ball to zoom around the screen bouncing off the ‘walls’. It is not particularly complex, nor is it very useful, but it is worth exploring as it will give you a feel using the Colour Maximite 2 and what you can 94  Silicon Chip Australia’s electronics magazine siliconchip.com.au Table 1: Pin Layout of Waveshare STM32 Module LEFT No. 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 GND PE2 PE4 PE6 PI8 PC14 PI9 PI11 PF1 PF3 PF5 PF7 PF9 PH0 RST PC1 PC3 PA1 PH2 3.3V 3.3V PH4 PA3 PA5 PA7 PC5 PB1 PF11 PF13 PF15 PG1 PE8 PE10 PE12 PE14 PB10 PH6 PH8 PH10 3.3V RIGHT 5VIN PE3 PE5 VBAT PC13 PC15 PI10 PF0 PF2 PF4 PF6 PF8 PF10 PH1 PC0 PC2 VREF+ PA0 PA2 PH3 GND GND PH5 PA4 PA6 PC4 PB0 PB2 PF12 PF14 PG0 PE7 PE9 PE11 PE13 PE15 PB11 PH7 PH9 PH11 5VOUT PI7 PI5 PDR PE0 PB8 PB7 PB5 PB3 PG14 PG12 PG10 PD7 PD5 PD3 PD1 PC12 PC10 PA14 GND GND PI1 PH15 PH13 PA13 PA11 PA9 PC9 PC7 PG8 PG6 PG4 PG2 PD14 PD12 PD10 PD8 PB14 PB12 GND GND PI6 PI4 PE1 PB9 BOOTO PB6 PB4 PG15 PG13 PG11 PG9 PD6 PD4 PD2 PD0 PC11 PA15 PI3 PI2 3.3V 3.3V PI0 PH14 PA12 PA10 PA8 PC8 PC6 PG7 PG5 PG3 PD15 PD13 PD11 PD9 PB15 PB13 PH12 3.3V No. 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 Table 1: use this pin layout as a guide if you need to troubleshoot the Waveshare CPU module, as the silkscreen ends up upside-down relative to pin 1 and how the module is placed on the Colour Maximite 2 PCB. ing the ball in the centre of the screen. The coordinate system used by MMBasic involves two axes: the x or horizontal axis and y or the vertical axis. x = 0 and y = 0 refers to the pixel at the top left of the screen. The coordinates get larger as you move to the right and down the screen. So x = 799 and y = 599 is the position of the pixel in the bottom right corner (the default resolution of the screen is 800 x 600 pixels). dx and dy are the amounts by which we move the ball in the x and y-axis every time the program loops around siliconchip.com.au (d = delta). With these both set to 1, the ball moves right and down one pixel each time the loop is executed. When the ball hits a wall, the polarity of these is reversed (more on that below). DO…LOOP The program then enters a DO… LOOP which causes the enclosed code to be repeated forever (well, at least, until something stops it!). The first thing that we do in this loop is to draw a circle (ie, our ball) at the coordinates given by the variables x and y and with a radius of 30 pixels. The Australia’s electronics magazine outline of the ball is black and is two pixels thick, while the centre is filled with red. Drawing the outline in black means that when we move the ball and redraw it, the black outline will erase any part of the last ball’s image that was left behind. This works well because we only ever move the ball by one pixel at a time. We then either increment or decrement the value of x depending on the value of dx, which is 1 or -1. This results in the ball moving one pixel either left or right on the next loop, August 2020  95 when the ball is redrawn. The program line after that checks to see if the ball is about to hit the left or right boundaries and, if it is, it reverses the sign of dx, causing the ball to travel in the opposite direction. The same is done for the vertical direction (dy) and taken together, this means that the ball will appear to bounce off all four edges of the screen. The purpose of the PAUSE 2 command is to slow down the program so that you have time to see the ball move. To see how fast the Colour Maximite 2 can really go, change this to PAUSE 0 (or remove that line entirely) and then re-run the program. The ball will just turn into a blur. You will notice that while this program is running, you will not get the command prompt back. This is because MMBasic is now busy executing your program and drawing the bouncing ball. You can stop the program whenever you want to by Last-minute PCB changes The motherboard illustrated in the photographs has gone through a few changes and so may not exactly match the PCB overlay diagram and final board that you receive. Most changes were minor layout adjustments, but one significant change was the provision for an external 8MHz crystal oscillator to replace the 8MHz crystal on the Waveshare CPU board. In testing, it was found that some VGA modes (such as 800x600 pixel 16-bit colour) caused difficulty for some monitors. This was traced to instability in the on-chip 8MHz oscillator in the Cortex-M7 CPU. Most constructors will be unaffected and will not need to do anything. However, if this change is needed, it can be easily implemented by removing the 8MHz crystal on the Waveshare CPU board and installing the external oscillator and a capacitor on the motherboard. The parts required are one SMD 100nF 50V X7R ceramic capacitor in a 3216/1206 package, and one 5x7mm SMD 8MHz oscillator (QX7 XO 25ppm), eg, RS Cat 813-6194. 96  Silicon Chip entering CTRL-C at the console, and you should get the command prompt back again. best way to understand it is to get in there and try it out. Full-screen editor The File Manager is a great way of managing the files and directories on the SD card. You can always use the traditional BASIC commands at the command prompt (COPY, CHDIR etc) to do this, but the File Manager is much easier. It provides a graphical list of the contents of the SD card and, using the arrow and Page Up/Down keys, you can select a file or directory and rename it, delete it, edit it etc. To get into the File Manager, use the FILES command or press the F1 key at the command prompt. On startup, it defaults to listing the current directory. Fig.13 shows what it looks like. Files and directories are colour-coded, and the status lines at the bottom will tell you what file you have selected and the key commands that are available to you. You can choose a different sorting order for files and directories by using the CTRL-S key. Positioning the cursor on a directory and hitting Enter will take you into that directory; if the directory has a name consisting of two dots (ie, “..”), pressing Enter will take you up the directory tree by one level. Hitting Enter while a program file is selected will run that program, and pressing F4 will edit it. You can even play a WAV, FLAC or MP3 file via the audio output by selecting it and pressing Enter. CTRL-F will enter the search mode, which works similarly to search in the full-screen editor. This will prompt you for the search text and, as you type this in, the cursor will automatically be positioned on the first file or directory with a matching name. You can then use the down arrow key to search for the next occurrence, or the up arrow for the previous occurrence. As with the editor, the best way to get to know the File Manager is to fire it up and try it out. If you are familiar with the editor used in the original Colour Maximite and the Micromite, this editor is similar but it has extra features. These include a much larger clipboard (capable of holding many lines), the ability to edit very long lines (the screen will scroll sideways) and a much-enhanced search function. Entering the above program should have given you a feel for how the editor works and, as we said, its operation is reasonably intuitive. The colour-coded text makes it easier to understand the program (commands are in cyan, comments in yellow, constants in green and so on). The status bar at the bottom of the screen shows the name of the file being edited, and the location of the cursor within it. Below this, there is a summary of the common key commands. Two important functions of the editor need further explanation: search mode and mark mode. CTRL-F enters search mode. This will prompt you for the search text, and as you type this, the editor will automatically position the cursor at the first match found. You can then use the down arrow key to search for the next occurrence, or the up arrow for the previous occurrence. In this mode, the Enter key leaves the cursor where it is and returns to normal editing mode, while CTRL-V will replace the searched text with whatever is in the clipboard (see below). Escape (Esc) aborts the search. CTRL-S enters mark mode. In this mode, you can use the arrow keys, Home or End to mark (or select) text and copy it to the clipboard. It will be highlighted on the screen as you move the cursor around. Then CTRL-C will copy the selection to the clipboard while CTRL-X will copy and delete (cut) the selection. Delete (Del) will simply delete the selection without changing the clipboard, and Escape (Esc) will return to the normal editing mode without changing anything. You can use the editor to edit any text file, not just programs – all you need to do is specify the full file name, including the file’s extension (eg, EDIT “myfile.txt”). As we said before, the Australia’s electronics magazine File Manager The serial console Usually, a VGA monitor and USB keyboard are used as the console for MMBasic. But as mentioned last month, you can connect to a desktop or laptop computer via the serial console and use its keyboard and screen to siliconchip.com.au Resistor Colour Codes do the same job. This is handy if your Colour Maximite 2 does not have an attached monitor and keyboard; it also makes it easier to transfer programs and data between the two. To access the serial console, connect the Colour Maximite 2 to your personal computer via the USB Type-B connector on the rear panel (this also provides power). When you do this, the Colour Maximite 2 will appear as a USB virtual serial port, which acts much like a standard serial port. Windows 10 includes the required device driver. For Linux, Mac and earlier Windows versions, you can get a driver and instructions from Microchip at siliconchip.com.au/link/ab2y You will need a terminal emulator program on your desktop computer. This acts like an old-fashioned computer terminal; it will display text received via the serial link, and any key presses will be sent back. For Windows users, Tera Term is a good choice. You can download it from http://tera-term.en.lo4d.com/ For Mac users, a terminal emulator is built into macOS (Terminal); refer to the Colour Maximite 2 User Manual for instructions (siliconchip.com. au/link/ab2z). For Linux users, there are a few options like PuTTY (https:// www.putty.org/). The terminal emulator and the serial port that it is using should be set to the Colour Maximite 2 standard o o o o o o o o o No.   6   1   2   19   13   3   1   1 Value 10kΩ 4.7kΩ 1kΩ 240Ω 120Ω 75Ω 10Ω 2.2Ω 4-Band Code (1%) brown black orange brown yellow violet red brown brown black red brown red yellow brown brown brown red brown brown violet green black brown brown black black brown red red gold brown of 115,200 baud, eight data bits and one stop bit. When you have the serial port and terminal emulator set up, reset the Colour Maximite 2 and you should see the MMBasic banner and prompt on the terminal emulator. Loading a program from a PC If you have prepared a program on your computer, you can transfer it to the Colour Maximite 2 via the serial console using either the AUTOSAVE or XMODEM commands. The AUTOSAVE command looks like this: AUTOSAVE “filename” After this, you can simply copy the program to your desktop computer’s clipboard and paste it into the terminal emulator (eg, Tera Term). From the Colour Maximite 2’s perspective, this is the same as if a high-speed typist types in the program. After the pro- 5-Band Code (1%) brown black black red brown yellow violet black brown brown brown black black brown brown red yellow black black brown brown red black black brown violet green black gold brown brown black black gold brown red red black silver brown gram has transferred, press the F1 key and MMBasic will save the program to the SD card and return to the command prompt. The XMODEM command is a bit more complicated and uses the XModem protocol to transfer a BASIC program file, including an integrity check which will detect most transfer errors. The Colour Maximite 2 User Manual goes into the details of how to do this – it is reasonably straightforward. MMEdit Another convenient method of creating your programs and sending it to the Colour Maximite 2 is to use MMEdit, written by Jim Hiley from northern Tasmania. It can be installed on a Windows computer and it allows you to edit your program on the PC then, with a single button click, transfer it to the Colour Maximite 2 for testing. MMEdit is easy to use with colourcoded text, mouse-based cut and paste and many more useful features such as bookmarks and automatic indenting. Because the program runs on your PC, you can save and load your programs to and from the computer’s hard disk. MMEdit can be downloaded from Jim’s website at www.c-com.com.au/ MMedit.htm It is free, although he would appreciate a small donation. Conclusion Fig.13: one of the new features of the Colour Maximite 2 is the File Manager, shown here. Use the arrow keys and Enter to navigate the files and directories on the SD card. Other keyboard commands available are shown at the bottom of the screen. siliconchip.com.au Australia’s electronics magazine So there you have it. The Colour Maximite 2 is a powerful but inexpensive computer that is fun to use. Now would be a good time to download our tutorial “Introduction to Programming with the Colour Maximite 2” (siliconchip.com.au/link/ab30) and start working your way through it. Enjoy! For updates to MMBasic and more, go to the Author’s website at http:// geoffg.net/maximite.html SC August 2020  97