You are on page 1of 100
FREE DVD £29.90 HANDS-ON PROJEGTSIFORS = Dine Into c oN ( @ Raspberry Pi @ Arduino @ Retroigaming» Discover, PLGA Cearn)to or program hardware forjretro computing im Linux Magazine Expand your Linux skills with: In-depth articles on trending topics, including Bitcoin, ransomware, cloud computing, and more! © How-tos and tutorials on useful tools that, will save you time and protect your data © Troubleshooting and optimization tips © Insightful news on crucial developments in the world of open source © Cool projects for Raspberry Pi, Arduino, and other maker-board systems Hello Pens akerSpace ser elcome to the Makerspace special edition, Although, ‘MakerSpace is a computer magazine, we're not going to talk about Windows or Linux or the latest Apple computers, and we ‘won't be delving into the details of An- droid or 10S smartphones. Instead, -Makerspace focuses on technology that you can use to build your own stutf. ‘Our goal is to help you turn your ideas into reality If you're interested in electronics but ‘haven't had the time or the skills (yet), studying these maker projects might be the final kick you need to start that pro- ¢gramming class, learn soldering, or do ‘whatever else you've been thinking, But don’t worry about skills or time right now. Many articles in this issue only require that you own a single- board system such as a Raspberry Pi (which you can purchase for a few dol- Jats) and download and install some files on an SD card Bring Back the Fascination From your smartphone, you read emails, search the web, order stuff online, play ‘games, and chat with friends. When you sit down ata larger computer screen, ‘you write leters and longer documents, ‘work on spreadsheets, and maybe even. record and edit a video, And, if you are still in school or work (either from home or an office), you most likely run video conferencing software, We've become accustomed to computers being ex- tuemely powerful and letting us do all kinds of things. A few decades ago, however, things were very different. If you've been using computers since the 1980s, you will remember how machines fasci- nated us, letting us watch in awe when the computer *Ieamed” a new feature: “Oh wow, it has stereo sound, you hear that?" "Oh, look how smooth that ani- ‘mation runs on the sereen.” Today, we expect that our computers, can do anything. If there's something, your computer cannot do today, it's just a question of time before the possibility becomes reality. If your computer is too slow for a specific task today, chances are that there's a cloud service that still lets you do it. Because we are sur- rounded by technology and accustomed to using it all the time, we find it diffi. cult to be fascinated by it Occasional Awe Sometimes a piece of technology can inspite fascination. Maybe the technol ‘ogy can perform a task that we hadn’t thought it could do. While turning on lights with voice commands is stan: dard technology today, I was delighted the first time I successfully connected small devices to make that happen. KERSPACE 3 Figure 1: The CPC 464 with its built-in tape recorder came with either a green or color monitor. Here you see the cheaper green model and two important accessories: the 3+ Pro joystick. (The amazement tends to wear off, es pecially when it doesn’t always work perfectly because the voice commands need to travel toa server on a different continent and back tothe light switeh.) ‘Maybe the technology is a modern recreation of your childhood home com- puter (Figure 1). The original machines have a tendency to eventually fll While there are many tutorials on how to repair these machines or find re placement parts for burn-out chips i's not always possible to bring a machine back to life. However, a retro computing community exists that eagerly designs and builds new hardware that is just Figure 2: The tiny Arduino Nano: The PCB dimen- sions are 18x45mm. © arduino.cc ich floppy disk drive and the Compe! like your old Commodore C64 ot Sin- clair 2X Spectrum, just a little more user-friendly. Maybe you see the price of a tiny com: puter, such as a Raspberry Pi or even an Arduino (Figure 2), and wonder how a $20 or $40 machine can perform tasks that would have required an expensive top-of-the-line desktop computer only 20 years ago. Or maybe you suddenly see how far the technology has advanced. I re. cently tried out the Raspberry Pi soft ‘ware recommended in some of the arti- cles in this issue. I created separate SD cards for each article and then stored the SD cards in little plastic bags (Fig. ure 3), which re: minded me of ‘working with Figure floppy disks in the 1990s, My SD cards have a 32GB capacity. Considering that a floppy disk can hold 1.44MB, a single SSD card equals about 22,000 floppy disks. (In case you are wondering, I still have my collection of 5.25-inch, 3.5 inch, and 3-inch floppy disks at hand, but it's a bit of an effort to read them.) Projects and More In the first section of this issue, we have collected a small showcase of in teresting projets ~ some are useful Some are pretty, and some are just fun because it can be dane. Take our Steam punk lunchbox computer (page 14): Do you need that? No, but it's fun to add those copper tubes toa Raspberry Pi and let it play music, On page 34, we show you how to build a kitchen timer from a Pi Zero and a seven-segment dis- play. You could buy a ready-made times, but why not build your own? Other projects inthis iste use Arduino, STM32, and Adafruit Tinket MO micro controllers, In the Tools & Development section, we introduce you to CircuitPython, a Python runtime environment that helps with cross-platform development (page 44), You can use CireuitPython vith microcontrollers but also with more powerful hardware like the Rasp Pis. If you need to set up a network. connection for a “headless” Rasp Pi (a machine without a monitor and key. board), we show you how to tse Berry Lan (page 48) In the Deep Dive section, you can learn in detail how serial communication works (page $6), and we show you how single SD card can hold much more data than all the floppy disks I've owned. to install the educational Linux From Scratch system on a Rasp Pi (page 64). The last section of this issue is pure ret entertainment: We look atthe current trend to rebuild old home com: puters with FPGA technology. After an introduction and overview of past and present projects (page 80), we focus oon two popular machines with active doveloper and user communities: the MEGAGS (page 87) and the ZX Spec- ‘rum Next (page 92). Ifyou manage to et hold of one ofthese machines ora clone, you can replay all the old Speccy and Commodore 64 classics. However, you don't need new hardware to play Pens those games one more time. In many cases, software emulation of the old home computer is good enough. On. page 68, we show you how to turn a Raspberry Pi into a gaming platform with RetroPie, which lets you run titles {or classic gaming consoles like the Super Nintendo (Figure 4). Mad Skills? A bit earlier, | mentioned that skills ‘might be required. Can I actually do everything that we have described in this issue? No, definitely not. I proba- bly could learn most of the skills, but I don't feel the need to replicate every- : Playing Super Mario Kart on RetroPie is very much like the gaming experience on a Super Nintendo. thing that everyone else is doing, 1 spend considerable time online wateh- ing videos of people siting in theit basement, unpacking new tech stuf, and connecting it to some computing device from the 1980s, 1990s, or maybe even from today. They solder stuff and make new adapter cables. They replace dead capacitors and other chips with fresh parts, and they rejoice when they make @ home computer load files from a modern 64GB mi- ‘roSD card, And that makes me smile, too, even if | don't have (and never had) that specific kind of machine. 1f you are into learning new skis, take a look at our cover DVD, which contains the complete Raspberry Pt Geek archive (see page 8 for more information) Let's Get Excited ‘While not every topic in this issue will interest every reader, | hope that we can ‘excite you with some, maybe many, of the ideas presented here. As you browse ‘through the magazine and read some of the articles, ! hope you will share in our ‘authors’ enthusiasm and love for their topies. We've had a good time putting ‘this special issue together, trying the projects out (even if there was the odd angry cry when stuff did not work cor- rectly on the first attempt), and writing the articles. We hope you enjoy the fin- ished product If you like what you find in this issue, ‘why not write to us and tell us what ‘worked for you? Send us your feedback at edit@l inuxnewnedi a.con MAKERSPACE Makers pace PROJECT: 10 WS2812 LEDs 28 ioBroker + Rasp Pi Control a matrix of WS2812 LEDs with Control home automation devices from the Raspberry Pi various manufacturers with a single 14 bunchdox Portable Pi interface by combining free software A lunchbox- and a Raspberry Pi. style portable 34, Kitchen Timer Qo Raspberry A simple kitchen helper > Pi computer with two timers assists provides budding chefs in f @ @ external control coping with dishes y for a steampunk that are unlikely to robotic skull be ready at the same time. 1 Christmas Tinkering JQ _lnstrumented Garden Make your own Christmas music box Place long-range with a microcontroller, servomotor, wireless sensors in a NeoPixel LED ring, and mini-MP3 player. garden and keep track of ambient conditions BQ Escape Room Puzzle with gauges and time-based graphs. A digital puzzle presents a challenge for young people in an escape room. 44, SircuitPython 48 BerryLan The CircuitPython run-time Control a headless Raspberry Pi from environment runs on almost all your smartphone, microcomputers and microcontrollers, making it perfect for cross- platform programming. 3 Welcome 8 On the DVD 98 Masthead bas 3 51 Pi Zero USB Gadget ‘Turn a Pi Zero into a universal USB flash drive that emulates storage, a serial port, Ethernet, and more GO Ne TTT 68 14 80 RetroPie Bring back old games from more than 50 classic game consoles. Lakka Lakka Linux comes with everything you need to play retro games - and you can even install games directly in the user interface. All you need is a Raspberry Pi and, ideally, a simple gamepad. FPGA Home Computers If you're not satisfied with your current operating system, you can update to a new release or switch to a different distro. Imagine if you could do the same with your hardware, at zero cost. It turns out that you can, thanks to FPGA chips, which have become popular in the retro-gaming community. 87 Serial Communications We explore serial communications, from the electrical specs to protocols and libraries and provide an example of serial communication with an Arduino. Linux from Scratch on a Pi The detLFS project helps you compile Linux from source code - either to explore the system or to prepare for a project with special requirements. MEGA65 Home Computer ‘The MEGAGS, an FPGA-based C65 clone, promises to become a modern successor to the Commodore C64,one of the most successful machines of the 8-bit home computer era. Sinclair ZX Spectrum Next Back in the "80s, the Zilog Z80 was a powerful processor, and the home computers of the Sinclair ZX Spectrum series made good use of it. Today it can be hard to find a Speccy in good condition, but a specialized FPGA computer saves the day: We present the Sinclair ZX Spectrum Next. Strings and YOUR DVD INCLUDES... + More than 2,000 pages of RPi goodness + Searchable database + Complete code repository + Articles in PDF and HTML format + No DRM - read anywhere else RASPBERRY PL TURES Mecca for Makers! The cool, colorful, and always inventive Raspberry Pi Geek magazine was a favorite with makers around the world because you just never knew what you would find inside. A coffee roaster? A pedometer for hamsters? An automated launcher for cat toys? RPG looked down deep into the fabric of the loT universe, exploring technologies such as MQTT, Mathematica, Mindstorms, and 3D printing. Readers could learn by programming in Python, Scratch, PHP, and Turtle Graphics and polish their skills at Retro Gaming, Minecraft, PyChess, Arduino, and littleBits. Raspberry Pi Geek magazine went out of print in 2017, but the legacy lives on in the official Raspberry Pi Geek Archive DVD — a complete collection of every issue in lavishly illustrated and easily accessible PDF format! bist s)el) del ease altel ge Sa 10 Control WS2812 LEDs RLSM O Mme Colorful Lights Control a matrix of WS2812 LEDs with the Raspberry Pi. ou are probably familiar with the large colored LED strips in many shop windows. Often these light stzips use WS2812 RGB LEDs. Ready-made controllers are available, but they usually have a very limited feature set. In this article, I show you how to control a matrix of WS2812 LEDs with the Raspberry Pi. Power Games The WS2812 is a programmable RGB LED that is driven by a small controller that has a data byte for each of the three basic colors (red, green, and blue). This arrangement makes it possible to display ‘more than 16 milion colors with one LED. Each LED has four connections: two for the SV power supply and two (DI, data in, and DO, data out) for asyn- chronous serial data transmission, ‘The output of one LED can be con: nected to the input of the next, which theoretically allows any number of 'WS2812 units to be connected in series However, at some point, it takes so ‘much time to write the values into the LEDS that they start to flicker. With 1,024 LEDs in series, its just about pos: sible to supply all the LEDs with data 30 times per second so that no visible flick: ering occurs. ‘The signal for driving the LEDs is constructed so that every single data bit Is encoded in a complete period of the signal. The pulse/pause time of the sig: nal indicates whether you are looking at a logical 1 or a logical 0. This method is well suited because a continuously changing signal is less susceptible to in: terference. Synchronization occurs ‘when a single data bit is transmitted in 2 period of 1.25ys. Resetting an LED re- 4quites a low signal on the data line for at least 5Oms, ‘As you can see, generating a signal for the WS2812 is not easy. The program rust be written in a machine-oriented ‘programming language like C. Moreover, very precise timing behavior must be ‘maintained. Fortunately, you can use a library that takes care of generating the correct signal. Because I plan to use a Raspberry Pi to control the matrix, another minor obsta cle is the operating voltage and the sig nal level of the WS2812 diodes, which need SV. The Raspberry Pi provides that ‘operating voltage, but the signal levels it generates reach a maximum of 3.3V. If you look up the corresponding values in the WS2812 data sheet [1], you will find that the LEDs only detect signals from 3.6V upward without error, which makes ‘an additional semiconductor necessary to raise the signal level. On the Internet you can find many examples by hackers that have done without this additional semiconductor. It might work, but it might not. The 74HC125 quad buier/ line driver used in this project costs just 25 cents ~ well-invested money for assured signal levels, ‘The library has a setting for the bright- ness of the WS2812 LEDs. This value should be set as low as possible, because a single LED draws up to 12mA of cur- rent at full brightness. For a typical strip ‘with 64 diodes multiplied by 64, this re- sults in a total eurrent of almost 800mA for the Raspberry Pi to provide. This amount of current would overload many power supplies. Also, you should nat send that much current through a ribbon cable. I you need the full brightness of the LEDs or want to work with more than 64 LEDs, you have to supply them ‘with sufficient power from a separate SV power supply. Hardware Structure ‘When setting up the hardware, you have only one point to consider: If you gener: ate the signal with a PWM generator, you need root privileges to execute the program. If you use the SPI interface, the program will run with user rights. You should avoid being the root user as often. as possible Using the SPI interface (BCM pin 10, header pin 19) to generate the LED si nals isa sensible option: Connect Rasp: berty Pi header pin 19 to the input of the 74HC125 and its output to the input of the WS2812 LED matrix [21 ‘The SMD version of the 74HC125 (31, which you solder on a prefabricated board [4], ensures you do not use too ‘much space, To distribute the current RASPBERRY_SV_PIN2 wes2nte_sy RASPOERRY_5_V_PIN_A — RASPBERRY_MOSI_PIN.19 Z4HC250 52812 MATRIXDI on RASPBERRY_GNO_PIN 6 ws2612_6NO RASPBERRY_GND_PIN14 Connect the 74HCI25 to SV Figure 1; The circuit diagram for controlling the signal level to the 'WS2812 LED matrix. The pin numbers correspond to the physical header pins. WS2812 LED: Geass that flows through the ribbon cable, use both Pi SV connectors and two ground lines (Figure 1). ‘To protect the LED matrix and the 74HC125, 1 3D-printed a case made of transparent filament for the assembly (Figure 2). The case contains simple stress relief to prevent the thin wires ‘coming off the PCB and the LED matrix. ‘The 3D printer STL and SCAD files can bbe found on the Linux Magazine FTP site [5]. Preparing the Raspberry Pi ‘On the Raspberry Pi, you need 10 use a current image ofthe Raspberry Pi OS and desktop [6]. Moreover, the installa- tion ofthe WS2812 driver requires some additional tools and libraries (5); auto apt update so apt upgrade {mato apt instalt openjak-i0-jae 2 ‘one boi1d-eosential 1ibpered 2 Linpores-aer ov ‘To control the LEDs over the SPI inter face, you have to activate them with raspi-config in menu item S Interfacing ‘Options | P4 SPI ‘To save energy, the Raspberry Pi mod- ‘ls from the third generation onward lower the CPU frequency, which also ‘changes the frequency ofthe SPI clock ‘generator. Data transfer to the WS2812 LEDs will not function properly until you set the SPI generator to a fixed frequency bby adding the line cone fegeaso to the end of the config. tx file you want to drive more than 6 LEDs, the SPI butter might be too small. ‘The butler size is defined by adding opiaev.wuseia-65526, to the single-line /boot /endt ine. txt file. To apply the changes, restart the Raspberry Pi. Installing the ¢ Library The € (7 library uses BCM notation for the GPIOs, which means thatthe SPI pin is number 10 in the soitware (header pin 19) The brary i rely available for download online. To install the library fon the Raspberry Pi, enter MAKERSPACE " Listing 1: WS28Test java 1) soars. 3008 Amport con. gino .nber1ing.we201.%; public ol seetest{ public statis void min(steing|) args) { eens ezeisLeasteip matrix = now s281xLedstrip(e4, 10, 900000, 10,4,0,£alo2, Least? ‘ype. S2811_ STRIP GR, natrix.sotPixe](0,255,0,0)5 atzix.setPixe](1,0,288,0): atrix, setPixe](2,0,0,255): atrix.render(}: Vf mean Vfetase 4 git clone netpe://eithub.con/? denrtt/roLvczarecit 4 od miveone 4 scone 4 est 410 ‘The last command starts a test program that makes the LED matrix light up in different colors, Java Wrapper Various programming languages have ‘wrappers forthe C library, including Java (8). A wrapper is piece of software that provides functions of one programming language by means of an interface to an- other programming language. ‘To install the Java wrapper, use the commands tote 4 git clone netpe://eithsb.con/? 5e)5 6 of moi ueadie-java/are/scrigte 5 tasn crenata Svein. sn 5 oa ~/rpi-nootix-java/ 5 /eradien nesonble ~x signirchiver ‘To run the wrapper, you also need the Logit library, which you can download and install with: 1 wget http: //apache 2eat-forun.et/2 ogeine/loess/2.19-2/2 apacte-Logsj-2.19.1-bin.tar.ge 5 tar xe 2 speche-1ogs-2.19.1-bin-ter.6z Note thatthe library must be in the class path during execution. ‘After completing all the installation steps, test the WS2812 strip with an ini tial small program (Listing 1) that im- ports the library for controlling the ‘Table 1: Ws281xLedStrip() Parameters om Cor 1 ‘Number of LEDs connected 2 GPIO connection used (10 for SP, 18 for PWM) 3 int Frequency for controlling the LEDs ‘ int Direct memory access to use (10 typically a good choice) 5 int Brightness, 0 to 255 (4to 32s recommended 6 int PWM channel i boolean Signal inversion lif using an inverting level converter) Ledstriptype See Table 2 boolean true turns off the LEDs when the program ends ‘Table 2: LedStripType LeastripType.SKsB12_STAIP_ LeastripType.Us2811_STRIP_cType> 2 MAKERS! GBH, RBGH, CRB, GER, BRAM, BORH RE, RBG, GRE, GBR, BRS, BOR LEDs; then, to communicate with the LEDs, it creates an object named natri, ‘Table 1 shows the meanings ofthe indi- vidual parameters. The abject sets the first three pixels to red, green, and blue, and the natrx,render() command ‘writes the data to the LEDs. ‘To build the Java program, use the command: $ sevae -

You might also like