Schlagwort: raspi

  • Get started with the High Quality Camera

    Get started with the High Quality Camera

    Reading Time: 7 minutes

    In this tutorial, we’ll show you how to attach a lens to the HQ Camera and adjust its focus and aperture settings. We’ll then use the supplied ribbon cable to connect it to Raspberry Pi, enable it in Raspbian, and enter some commands in a Terminal window to start capturing photos and video.

    See also: High Quality Camera Guide and The MagPi issue 93

    High Quality Camera: You’ll need

    Using the 6 mm CS-mount lens

    A low-cost 6 mm lens is available for the HQ Camera. This lens is suitable for basic photography. It can also be used for macro photography because it can focus objects at very short distances.

    Fit the lens to the camera

    Fit the lens to the camera

    The lens is a CS-mount device, so it has a short back focus and does not need the C-CS adapter that comes with the HQ Camera. Rotate the lens clockwise all the way into the back focus adjustment ring.

    Back focus adjustment ring

    Back focus adjustment ring

    The back focus adjustment ring should be screwed in fully for the shortest possible back-focal length. Tighten the back focus lock screw to make sure it does not move out of this position when adjusting the aperture or focus.

    Adjust aperture

    Adjust aperture

    To adjust the aperture, hold the camera with the lens facing away from you. Turn the middle ring while holding the outer ring, furthest from the camera, steady. Turn clockwise to close the aperture and reduce image brightness. Turn anti-clockwise to open the aperture. Once you are happy with the light level, tighten the screw on the side of the lens to lock the aperture ring.

    Adjust Focus

    Adjust focus

    To adjust the focus, hold the camera with the lens facing away from you. Hold the outer two rings of the lens; this is easier if the aperture is locked as described above. Turn the camera and the inner ring anti-clockwise relative to the two outer rings to focus on a nearby object. Turn them clockwise to focus on a distant object. You may find you need to adjust the aperture again after this.

    The 16 mm C-mount lens

    Using the 16 mm C-mount lens

    The 16 mm lens provides a higher-quality image than the 6 mm lens. It has a narrow angle of view which is more suited to viewing distant objects.

    Fit the C-CS adapter

    Ensure the C-CS adapter that comes with the HQ Camera is fitted to the lens. The lens is a C-mount device, so it has a longer back focus than the 6 mm lens and therefore requires the adapter.

    Fit the C-CS adapter
    Fit the lens to the camera

    Fit the lens to the camera

    Rotate the lens and C-CS adapter clockwise all the way into the back focus adjustment ring.

    Back focus adjustment ring

    Back focus adjustment ring

    The back focus adjustment ring should be screwed in fully. Tighten the back focus lock screw to make sure it does not move out of this position when adjusting the aperture or focus.

    Adjust aperture

    Adjust aperture

    To adjust the aperture, hold the camera with the lens facing away from you. Turn the inner ring, closest to the camera, while holding the camera steady. Turn clockwise to close the aperture and reduce image brightness. Turn anti-clockwise to open the aperture. Once you are happy with the light level, tighten the screw on the side of the lens to lock the aperture ring into position.

    Adjust focus

    Adjust focus

    To adjust the focus, hold the camera with the lens facing away from you. Turn the focus ring, labelled ‘NEAR FAR’, anti-clockwise to focus on a nearby object. Turn it clockwise to focus on a distant object. You may find you need to adjust the aperture again after this.

    Connecting and using the camera

    With your HQ Camera and mounted lens ready, it’s time to connect it to your Raspberry Pi and start capturing some images.

    Connect ribbon cable to camera

    On the bottom of the HQ Camera board, you’ll find a black plastic flap (Figure 1). Carefully pull the sticking-out edges until the flap pulls part-way out. Slide the ribbon cable, with the silver edges downwards and the blue plastic facing upwards, under the flap you just pulled out, then push the flap gently back into place with a click; it doesn’t matter which end of the cable you use. If the cable is installed properly, it will be straight and won’t come out if you give it a gentle tug; if not, pull the flap out and try again.

    Figure 1. The ribbon connector

    Connect cable to Raspberry Pi

    Find the Camera port on Raspberry Pi and pull the plastic flap gently upwards. With Raspberry Pi positioned so the HDMI port is facing you, slide the ribbon cable in so the silver edges are to your left and the blue plastic to your right, then gently push the flap back into place. As before, if the cable is installed properly, it’ll be straight and won’t come out if you give it a gentle tug; if not, pull the plastic flap out and reinsert the cable. If using a Raspberry Pi Zero, its Camera port is found on the edge of the board. However, as it’s a smaller size than the regular one on other Raspberry Pi models, you’ll need a camera adapter cable to use it.

    Tip! Longer cable

    The HQ Camera is supplied with a standard 20 cm ribbon cable for connection to Raspberry Pi. However, longer camera cables are available from the usual online retailers.

    Enable the camera

    Connect the power supply back to Raspberry Pi and let it load Raspbian. Before you can use the camera, you’ll need to tell Raspberry Pi it has one connected: in the Raspbian menu, select Preferences, then Raspberry Pi Configuration. When the tool has loaded, click the Interfaces tab, find the Camera entry in the list, and click on the round radio button to the left of ‘Enabled’ to switch it on (Figure 2, overleaf). Click OK, and the tool will prompt you to reboot your Raspberry Pi. Do so and your camera will be ready to use.

    Figure 2. Settings

    Test the camera

    To confirm that your camera is correctly installed, you can use the raspistill tool. This, along with raspivid for videos, is designed to capture images from the camera using Raspberry Pi’s command-line interface (CLI). In the Raspbian menu, select Accessories, then Terminal. A black window with green and blue writing in it will appear: this is the Terminal, which allows you to access the command-line interface. To take a test shot, type the following into Terminal:

    raspistill -o test.jpg
    

    As soon as you hit ENTER, you’ll see a large picture of what the camera sees appear on‑screen (Figure 3). This is called the live preview and, unless you tell raspistill otherwise, it will last for five seconds. After those five seconds are up, the camera will capture a single still picture and save it in your home folder under the name test.jpg. If you want to capture another, type the same command again – but make sure to change the output file name, after the -o, or you’ll save over the top of your first picture.

    Figure 3. A capture from the high quality camera

    More advanced commands

    The raspistill command has a list of options so long that it borders on the intimidating. Have no fear, though: you won’t need to learn them all, but there are a few that might be useful to you, such as:

    raspistill -t 15000 -o newpic.jpg
    

    The -t option changes the delay before the picture is taken, from the default five seconds to whatever time you give it in milliseconds – in this case, you have a full 15 seconds to get your shot arranged perfectly after you press ENTER.

    Capture video

    For shooting video, raspivid is what you need. Try it out with this Terminal command:

    raspivid -t 10000 -o testvideo.h264
    

    This records a ten-second video (10,000 milliseconds) at the default 1920 × 1080 resolution. You can also shoot slow-mo video at 640 × 480 by using:

    raspivid -w 640 -h 480 -fps 90 -t 10000 -o test90fps.h264
    

    You can use VLC to play the videos back. This application is pre-installed in the Raspbian ‘Full’ version. If it’s not, you can use the Recommended Software tool to install it.

    Tip! Using VNC

    By default, you won’t be able to view the camera preview window when accessing your Raspberry Pi remotely from another computer via VNC. However, there is a setting to make the window appear. Open the VNC Server menu on Raspberry Pi and go to Options > Troubleshooting, then select ‘Enable direct capture mode’.

  • Game of Life

    Game of Life

    Reading Time: 3 minutes

    John sadly passed away in April this year but his creation lives on, not only in memory but in different manifestations. One of the most intriguing – from our perspective at least – is a version run on a Raspberry Pi. It has been produced by software engineer Nick Kelly, and it uses the same fixed set of rules that has served the simulation well over the years.

    Nick is a software engineer living in San Francisco whose life changed when a friend introduced him to Python and web development.

    See the GitHub page for this project and follow Nick Kelly on Twitter.

    “It started as a C# assignment for one of my engineering classes at university, so I had a lot of direction and criteria for what was expected,” Nick tells us. “In terms of architecture, I usually take a very object-oriented approach, but since Python was new to me at the time, I went down the functional route.”

    To allow the changes to be observed, John Conway originally used a program written by MJT Guy and SR Bourne for a PDP-7 computer with a screen (Credit: Tore Sinding Bekkeda, CC SA 1.0)

    Game of Life Fast Facts

    • It will run using any Raspberry Pi computer

    • The code could work in an infinite space

    • The game is governed by four defined laws

    • It’s about overpopulation and evolution

    • Once run, it needs no further interaction

    That’s life (on Raspberry Pi)

    The project consists of a Raspberry Pi 2 computer, four 8×8 Adafruit LED grids, and the code. The panels each use Adafruit’s FadeCandy, a NeoPixel driver that has built-in dithering and connects to a Raspberry Pi over USB. This allows the LEDs to illuminate or switch off depending on the Game of Life’s set of rules.

    But what are they? Well, the simple premise is that you have a set of cells, some alive and some dead, behaving in accordance to what is going on around them in the adjoining eight squares. This leads to very complex behaviour and patterns. If there is a live cell with either one or fewer live neighbours, or if there are more than four live neighbours, then that cell will die. If there are two or three neighbours present, then it will remain alive. Dead cells become alive when there are three live neighbours around them, otherwise they remain in a deceased state.

    “Designing it wasn’t a challenge, but there were plenty of challenges during development,” Nick says. “Along with Python, I was also getting a very intense primer to web development and networking. Remote environments, monkey patching, GPIO – these were all foreign terms to me.”

    Controlling LEDs in Python

    Delving into a real-world project, he says, provided a perfect way to familiarise himself with a new language. “My boss at work helped me out quite a bit in terms of connecting the technologies involved, such as Raspberry Pi, LED grids, Open Pixel library, and so on,” he says. But Nick also believes improvements can still be made.

    “I’ve refactored code I wrote 24 hours ago, so I would certainly restructure this whole project and add more features,” he affirms. “Probably some web interface to select patterns and such.”

    As it stands, however, it’s a fun and mesmerising project exploring concepts of underpopulation and reproduction, and Nick has been happy to bring it back to life following John’s death. So what has been the end game? “Getting an exotic final pattern has been tough because the project would normally end with four pulsating rectangles,” Nick says. But the ‘game’ runs until the script is stopped and you’re never quite sure what you’ll see in the meantime.

    You can discover more about John Conway’s Game of Life by checking out the large collection of information posted to the LifeWiki.

  • Unicorn HAT Mini review

    Unicorn HAT Mini review

    Reading Time: 2 minutes

    One slight downside is that – unlike the full‑size Unicorn HAT HD – it doesn’t come supplied with a translucent diffuser layer to fill out the gaps in the display between the small pixels. However, you could always make your own, even out of paper.

    Push-button controls

    Four programmable push-buttons – two on either side of the matrix – feel satisfyingly springy and responsive, while their input can be read using the standard GPIO Zero library. Since the Unicorn HAT Mini uses different pixels and twin LED driver chips from the other Unicorn boards, examples and code written for those won’t run directly without a few tweaks to the code first.

    Fortunately, Pimoroni has put together a special Python library for the Unicorn HAT Mini. Note that you’ll need to enable SPI manually (in Raspberry Pi Configuration > Interfaces ) to get it to work.

    As well as enabling precise individual pixel control using RGB and brightness values, the library features eleven Python code examples to get you started. These include a nifty pixel shading demo, multicoloured scrolling text, and fun Simon and Columns to make use of the buttons. To give you an idea of how fast the matrix can be refreshed, an ‘fps’ example tries to do so as rapidly as possible while printing the frame rate to the Terminal – in our tests, it averaged an impressive 67fps.

    Of course, you can always write your own code to do whatever you like with this versatile little board. Robin Newman has even managed to control its display using OSC messages from Sonic Pi.

    Verdict

    9/10

    A versatile mini RGB LED matrix with bright pixels, a fast refresh rate suitable for animations, and the bonus of four programmable push-buttons.

  • 8GB Raspberry Pi 4 in The MagPi #94

    8GB Raspberry Pi 4 in The MagPi #94

    Reading Time: 3 minutes

    8GB Raspberry Pi 4

    A Raspberry Pi 4 with double the RAM

    With twice the memory as any previous Raspberry Pi, and 40 times the power of the original board, the new 8GB model is a powerhouse! Gareth Halfacree muses on what you can do with the ultra-powerful 8GB Raspberry Pi 4 in this month’s edition of The MagPi magazine. Plus! Eben Upton talks about the march to 64-bit computing with the all-new Raspberry Pi OS (replacing Raspbian).

    Make a 3D camera

    The best High Quality Camera tutorials and projects

    This issue we continue with amazing projects for the Raspberry Pi High Quality Camera:

    • Make a 3D camera. PJ has built an incredible 3D camera using two Raspberry Pi Zero computers and two High Quality Cameras. It’s a fun way to discover a new kind of photography.

    • High Quality Camera case hack. Ozzy and Richard have turned a High Quality Camera and an official Raspberry Pi case into an amazing homemade digital SLR camera.

    • Precise control and time-lapses. Explore the many camera image options available and shoot time-lapse videos.

    • The best High Quality Camera projects. Rob has gathered together some of the best camera projects around. All ripe for High Quality Camera conversion by budding project makers.

    Apollo Pi

    Apollo Pi Thermal Camera (and other amazing projects)

    Martin Mander creates some of the best Raspberry Pi projects around, and this month he’s turned an old barcode scanner into an incredible thermal camera.

    Just one of several amazing projects outlined in this month’s edition of The MagPi:

    • HAL 9000. Using Google Assistant to recreate the computer from the classic movie 2001: A Space Odyssey.

    • Game of Life. A beautiful tribute to John Conway with Raspberry Pi and four 8×8 Adafruit LED grids.

    • Smart Doorbell. How one reader used a Raspberry Pi, camera, and screen to build a two-way video intercom system.

    • Giant Battleships. Playing a classic game of Battleships on a giant LED matrix.

    • Coffee Maker ‘Greenhouse’. Upcycling an old coffee machine into a plant-watering gardening assistant
      .

    • BeeMonitor. This project keeps an eye on bee life cycles with Raspberry Pi and live hive data.

    • Raspberry Pi loft bed. Transform a bunk bed with LED lights and an embedded display.

    10 best Raspberry Pi robot kits

    The 10 best Raspberry Pi robot kits

    Fancy building a wheeled-wonder or robotic arm? It’s a lot easier when you start with a kit. This month Rob takes a look at some of the best robotics kits around.

    The MagPi magazine 94: Contents page

    Don’t miss out on this month’s edition of The MagPi magazine. Click here to get your copy today.

  • Win one of ten Maker pHATs!

    Win one of ten Maker pHATs!

    Reading Time: < 1 minute

    Subscribe

  • 8 Bits and a Byte interview

    8 Bits and a Byte interview

    Reading Time: 2 minutes

    How did the channel start?

    The idea of the channel started when Dane finished his first Raspberry Pi hobby project. He loved the project, but he also wanted to take it apart to be able build something else: his next project. We thought it would be a shame to just take it apart and be done with it. Around the same time, Nicole had just finished a video editing course. We were able to borrow a camera and we thought we’d try to document the project, but at this point it was just for ourselves. The video wasn’t too bad and we also realised we would be making more of these projects in the future. That’s when we had the idea that it could be fun to share them with others.

    A classic Monty Python sketch made into a robot face that argues with you. Poorly.

    From thereon it grew; we indeed built more things, although very infrequently at first. Eventually we got our own camera, so we could also document the building process and not just film the finished result. We also started writing tutorials and sharing the code, which is not only nice for others but it has actually been really beneficial for us too. When you’re working on something, it makes it very easy to track back and find how you did this same thing before. It feels a bit like cheating off your own previous work, but it’s very helpful and we do it all the time.

    When did you learn about Raspberry Pi?

    Oh that’s a tough question, we’re not sure when we first heard about them. Dane came into contact with Raspberry Pi for the first time during his internship about four years ago, where he used one to build a prototype. Nicole heard about Raspberry Pi from Dane, who couldn’t stop talking about them.

    This painting is both interactive and has space monsters, so it’s definitely the greatest.

    What was your first Raspberry Pi project?

    For both of us, the first Raspberry Pi projects were work-related prototypes. Whilst working with them, we realised Raspberry Pi [computers] were a lot of fun and that there was so much more that you could do with them. It didn’t take long before we bought one to mess around with at home.

    Dane’s first hobby project with a Raspberry Pi was Tata, a cute and fluffy remote-controlled pet that could drive around and make all kinds of monster noises. Nicole’s first Raspberry Pi-powered hobby project was a device that tracked how far our hamster Harold ran in his wheel.

  • RIoT Brick

    RIoT Brick

    Reading Time: 3 minutes

    Cloud computer engineer Alan regularly blogs about his Internet of Things inventions and has previously graced these pages with his Countdown-playing robot. “Building intrepid devices I can take along with me outdoors is the perfect way for me to combine my interests in one fell swoop,” he says. “I have been known to go running with 3D-printed devices attached to my legs (although understandably only at night) to gather data on my leg movement.”

    Last September, Alan put his movement-sensing project to the test in a gruelling endurance race across the Brecon Beacons in Wales. He created the ‘RIoT Brick’ (Rosie Internet of Things Brick) so his family – some as far away as Australia – could remotely track his progress. Hooking himself up in this way also enabled Alan to monitor basic environmental conditions during what would be “a very, very long day!”

    The Brecon Beacons, where Alan tested his project to track his progress during a gruelling running race

    RIoT Brick fast facts

    • The rugged antenna helps the RIoT Brick communicate with other transceivers (maintaining a signal and internet connectivity proved tricky for this project)

    • The LCD can be used to provide GPS co‑ordinates, but was switched off to preserve battery power during the 10 Peaks Challenge. Those following Alan’s progress via the web still got detailed data!

    • The RIoT Brick project cost less than £50 all-in

    • Remote tracker data exchange was a particular challenge

    • There was no way to check whether the transceiver was faulty

    • It didn’t matter because before the race began… the aerial broke off in Alan’s car boot

    The RIoT Brick is a Raspberry Pi Zero-based sensing station housed in a crudely 3D-printed box. Alan cheerfully explains that he prefers to adapt existing code and hardware, and tries to stay well away from designing and printing ‘stuff’ for his projects. In this instance, the Brick case was needed to protect the Raspberry Pi Zero and sensing modules from many miles of jostling on his 58-mile run across ten peaks.

    The rig securely attached to Alan’s ultra-running backpack

    The box houses a nRF24L01+ transceiver and u-blox NEO-6 GPS receiver, along with BME280 temperature/pressure/humidity and BH1750 light sensors. Alan credits the Raspberry Pi and Linux community for the ease with which he was able to get these devices up and running. “I chose a Raspberry Pi Zero as the central component as I needed a flexible Linux platform that was sufficiently powerful to run multiple applications concurrently,” he says.

    The abundance of community-developed open-source libraries available for the modules and sensors he planned to connect to it was another big draw. He made use of an SQLite database and Python SDK Amazon Web Services. “IoT Core, IoT Events, DynamoDB, S3, Cognito, Simple Email Service, Lambda, and Elasticsearch Service are used to collect, process, and present this information back to my supposedly interested family members”, he explains.

    Data from four sensors in the RIoT Brick captured details of Alan’s 10 Peaks race

    Bricks and pieces

    “During the event itself, there were several onlookers understandably baffled by the strange bright device attached to the side of my backpack,” says Alan. “A small number were even brave enough to ask! The reaction on Twitter has also been great, and I was able to raise a few pounds for Alzheimer’s Research UK as well.”

    Full instructions for RIoT can be found on GitHub.

    Create a RIoT

    Step 1. Connect your Raspberry Pi Zero to an nRF24L01+ transceiver. This will receive the data from the other sensors. You also need a u-blox NEO-6 GPS receiver to obtain GPS readings. Step 2. Temperature, pressure, humidity, and light readings are provided by BME280 and BH1750 sensors. Data from all the sensors and transceivers is stored locally in an SQLite database on Raspberry Pi Zero.
    Step 3. This useful schematic shows the data flow and how to assemble the RIoT Brick.

  • Learn JavaScript with Raspberry Pi

    Learn JavaScript with Raspberry Pi

    Reading Time: 3 minutes

    NodeSchool

    Price: Free Link: NodeSchool

    NodeSchool

    NodeSchool is an astounding resource for learning not only JavaScript but many of the tools you need to get the most out of the experience. The tutorials available are installed as a series of command-line applications that allow you to create your code for real and then have it verified automatically. This means you are breaking out of the sandbox and coding for real.

    Starting with the very basics of JavaScript, you soon progress to the Node.js environment and then on to more advanced topics such as data streaming. You can even build your own workshops! Furthermore, NodeSchool organises and runs workshops and regular groups all over the world, so beginners can get support and friends. A perfect resource for those who prefer to collaborate.

    Node.js in Action (2nd Edition)

    Author: Alex Young, Bradley Meck, Mike Cantelon
    Price: £18
    Link:
    Node.js in Action

    Node.js in action

    Manning Publications has been a supporter of Node.js since its inception in 2009. This had been showing a bit with the original Node.js in Motion book getting a bit out of date as Node.js versions raced ahead. Now the book has been brought up to date to be in line with modern Node.js practices. While it doesn’t cover the most recent developments (Node.js progresses so rapidly, it would be impractical), what the book excels at is giving a thorough grounding in how Node.js works under the bonnet, really helping the reader understand some of the key concepts that make Node.js different from browser-based JavaScript. There’s also a video course available (you may recognise the presenter).

    Essential resources

    Learning JavaScript and Node.js? You’re going to need these…

    NPM

    Node Package Manager is like Python’s pip for Node. Literally thousands of libraries to enhance your project can be installed in a single command. Always start here to avoid reinventing the wheel.

    NPM

    MDN Web Docs

    This free resource from Mozilla is like the Library of Alexandria for internet development, amongst which you’ll find comprehensive documentation on all versions of JavaScript with examples and browser support information.

    Stack Overflow

    Every developer’s little secret. A gigantic Q&A site for many subjects including Raspberry Pi, JavaScript, and Node.js. Chances are the answer to your question is here somewhere.

    Amazing frameworks

    Frameworks allow your JavaScript code to do amazing things

    Express.js

    Think writing a web server from scratch is difficult? It certainly was until Express.js came along. This library and command-line tool can scaffold a full working server in seconds, perfect for web apps and APIs.

    Electron.js

    Electron

    Electron takes the components of your web app, the JavaScript, HTML and CSS, and packages it all with a web browser to create a standalone application that can be compiled for many different platforms.

    Sequelize

    If databases are your thing but you find SQL a bore, this object-relational mapping (ORM) framework makes creating, managing, and using databases a joy. Supports many platforms and integrates with Express.

  • DIY MIDI Door

    DIY MIDI Door

    Reading Time: 3 minutes

    The kit’s manual included an example circuit for controlling the brightness of an LED by turning a potentiometer knob. So Floyd took that basic concept and added a switch and a MIDI interface to the setup to enable it to control the pitch of musical notes played.

    DIY MIDI Door: Fast facts

    • The project took Floyd one afternoon to complete

    • Floyd decided to play The Doors on his door… obviously!

    • This was his first project involving a Raspberry Pi and circuitry

    • He plans to continue exploring Raspberry Pi’s musical possibilities

    An a-door-able idea

    After testing the circuit design with a breadboard setup, Floyd glued a potentiometer to the hinge of a door so that opening the latter to different degrees alters its voltage. Read by an ADC connected to a Raspberry Pi, this then determines the note played by a synthesizer whenever the door handle is pushed down to close a circuit.

    “A C program on Raspberry Pi reads the values picked up by the converter,” he explains. “These values range between 0 and 256. On a synthesizer, all notes are numbered from 0 (that’s C0, the lowest note) to 127 (G9, the highest note). So, my program just divides the converter’s input by a certain factor and rounds those numbers and sends them [via MIDI] to the synthesizer. Pushing the door handle closes an electrical circuit which makes Raspberry Pi send a ‘note on’ command to the synth, and releasing the handle sends the ‘note off’ command.”

    It’s an ingenious use of Raspberry Pi, but not every step of the project was straightforward. For example, Floyd found that he had to spend some time finding the correct factor by which the numbers read by the ADC had to be divided. “Making the [door] movements too small wasn’t an option, because the whole system isn’t very precise. In the end, I defined some value ranges for the three or four notes which are used in the song [Break on Through (to the Other Side) by The Doors].”

    In addition, some mechanical issues popped up, such as how to design a lever to turn the potentiometer’s knob, as it had to be very tight so the door movement could be picked up precisely. He settled on a solid metal paper clip, with one end glued to the inner edge of the door and the other end attached to a notch in the potentiometer knob – after finding that it was catching on the door frame, Floyd solved the problem by simply bending the clip with a pair of pliers.

    Floyd is a keen musician, but this is the first time he’s used a door to play music!

    Scores on the doors

    Unsurprisingly, viewers of Floyd’s YouTube channel have found the idea to be very innovative. “I think most people thought it was really interesting, but in a weird way,” he says. “The kids loved it for sure. The whole system is suited for slow music (think ambient music, meditation and so on, haha – meditating on a door handle).”

    So, could we see some kind of door orchestra in the near future? “While that would make for a spectacular video, I think I’ll use the ultrasonic distance sensor for determining the note’s pitch next, creating a variation of a theremin.”

    Read more: Playing The Doors with a door

  • Vineyard Kikushima

    Vineyard Kikushima

    Reading Time: 3 minutes

    “We are now doing viniculture in Koshu city, Yamanashi Prefecture, and we aim to open a small winery in Katsunuma in the spring of this year,” says Kunio Kikushima, owner of Vineyard Kikushima. “We also aim for eco-friendly wine without any agricultural chemicals where possible. We are now doing viniculture and vinification.”

    Kunio is an ex-employee of electronics manufacturers turned vine farmer, he lives a modest lifestyle but wants to make great wine. Kunio didn’t have much experience with programming and developing, but a chance meeting with friend of The MagPi, Masafumi Ohta of the Japanese Raspberry Pi Users Group, enabled him to gain some knowledge of Raspberry Pi and how it could be used to great effect in this instance.

    The first prototype system set out in the field. Sensors hang out of the box to obtain an accurate reading

    Solving a problem

    Grapes can be prone to disease, especially in the relatively high temperatures and humidity of Vineyard Kikushima. While using agricultural chemicals and pesticides helps, they can alter the flavour of the wine, so Kunio needs a more exact method of applying them in the ideal weather conditions for maximum efficiency.

    “I wanted to check the timing of high humidity [by] collecting temperature and humidity data automatically measured at regular intervals,” he explains. “I want to check those data in real-time through the network, as the fields are scattered and far away from my office.” This also means the setup requires solar and battery electric power.

    The second box is near one of the electric fences used to keep animals out

    Field tests

    The system is currently in a trial phase, with one prototype being used for the field test, and another reserved for system development. The total cost is ¥30,000–¥40,000 [about £225–£300] including the solar power equipment. Adding 3G dongles to the system, the total expected cost will be ¥50,000–¥60,000 [about £375-£450].

    Kunio hopes to add more sensors in the future and offer the system to other farmers in the region.

    The first prototype system set out in the field. Sensors hang out of the box to obtain an

    “It is very easy to get Raspberry Pi at the store in Akihabara and online shops,” he says. “There are tons of various use cases I can see on the internet. I think I had the illusion that I could make [the vineyard-monitoring system] without any programming skills on Linux. But it is very fun for me to assemble by watching and imitating, and it could be applied to another use with the same platform if the automatic display and measurement of temperature and humidity in fields works well.

    “I could make delicious wine with Raspberry Pi.”

    How to make Raspberry Pi wine

    Step 1. The grapes are monitored from the office using the Hinno IoT system to see what the atmospheric conditions are in the fields.
    Step 2. A decision based on the monitoring tells Kunio whether or not to spray his crops. The fewer chemicals used, the better.
    Step 3. The grapes are harvested and turned into small-batch wine. There are several types that are sold from Vineyard Kikushima.

  • Hot Spotter

    Hot Spotter

    Reading Time: 3 minutes

    Made from off-the-shelf hardware, including a Raspberry Pi 3A+, the Hot Spotter can survey an area to create a heat map. “As the drone flies over an area, it records average temperatures of spots on the ground,”explains Jason. “The size of the spot depends on how high the drone is flying, in the same way the spot size from a flashlight depends on how far away it is from a surface.”

    The software creates an imaginary grid of points, spaced about one metre apart, to be used for the heat map. When the drone takes a temperature reading of a spot, it’s recorded for all the points contained within it. Then, when the heat map is generated, all the readings for a given point are averaged together. “This method helps to localise heat sources and distinguish between large warm regions versus hot spots.”

    As the drone flies a cross-hatch pattern to survey the area, its on-board GPS is used to determine its precise position while a lidar module measures the distance to the ground. This results in more accurate heat mapping than when estimating the height, as well as opening up the possibility of terrain following and obstacle avoidance.

    Preparing for take-off, the Hot Spotter drone is pictured in front of a charcoal fire used for testing purposes

    Altitude testing

    “For my tests, the drone flew about 20 metres above the ground,” says Jason. “I would like to test at other altitudes. Since the size of the spot being measured increases with altitude, the drone can cover more area from higher altitudes at the expense of heat map fidelity. Ideally I would like to create a quick map from a high altitude followed by a higher fidelity map at a lower altitude for regions that look like potential hot spots.”

    The on-board Raspberry Pi 3A+ communicates with the drone’s flight controller (using the MAVLink protocol) to receive information such its GPS position and orientation. “Raspberry Pi handles all of the calculations necessary to generate a heat map from sensor data recorded by the drone and from sensors attached directly to the GPIO using an I²C hub,” says Jason. “Raspberry Pi can also command any autonomous functions such as setting a waypoint and returning to its launch point.”

    It sends the data in real-time – using a wireless serial connection via a 500 mW transmitter – to a ground station laptop via another Raspberry Pi used as a wireless hotspot for a laptop.

    Crash landing

    It took Jason three months to build and program the Hot Spotter. However, after numerous successful test flights, disaster struck when the drone crash-landed due to a malfunctioning rotor. “It was a bummer to say the least,” he says. “I have rebuilt the drone. Better than it was before. Better… stronger… faster.”

    While he thinks the drone’s practicality is solid from a cost standpoint, its practicality ‘in the wild’ remains to be seen. “I would like to do further testing that includes real-world scenarios. There is a fire science laboratory near me and if they find it useful, the project might have a future there.”

  • ZX Spectrum Next Accelerated review

    ZX Spectrum Next Accelerated review

    Reading Time: 2 minutes

    The keyboard is a thing of beauty. The keys are responsive, although the layout is a bit weird after years of muscle memory bonded to PC.

    It’s packed with connections: HDMI and VGA for video out; 3.5 mm ear and mic mini-jacks; PS/2 for keyboard and mouse; plus the mini HDMI and micro USB ports of Raspberry Pi Zero; and two 9B9 joystick ports (compatible with Kempston, Cursor, and ZX Interface 2 Protocols). To the left of the device sits a full-size SD card slot and three buttons: Reset, Drive, and NMI. And the original Expansion port provides compatibility with classic hardware.

    The NMI button opens a menu that enables you to flick between turbo modes: 3.5MHz, 7MHz, 14MHz, and 28MHz. You can also enter POKE files, browse memory banks, and adjust various sound, graphical, and memory settings. Some period games become wonderfully playable when cranked up to 28MHz: Sentinel, originally an achingly slow trudge, becomes a fast-paced and tense 3D puzzler.

    Z80 and beyond

    The heart of the Spectrum Next is a Xilinx Spartan-6 XC6SLX16 FPGA (field-programmable gate array, magpi.cc/spartan6). FPGA isn’t emulation: the programmable logic blocks create a perfect representation of the Z80 chip.

    You can take the FPGA beyond the Z80 with processor cores. We turned our ZX Spectrum Next into a BBC Micro B and BBC Master using BeebFPGA (magpi.cc/beebfpga). Victor Trucco has made a range of Intel 8080 cores available, including MSX, NES, and Colecovision.

    A separate Anti-Brick core protect users from breaking the machine when messing around with cores, and can be used at any time to switch back to its original state.

    Alongside this sits a Raspberry Pi Zero, which enables you to load digital .tzx files as analogue cassette tape (screeches, loading screen, and all). It also brings SID (Sound Interface Device) support to the table, enabling better audio for games. There are plans afoot for Raspberry Pi Zero’s micro USB port to act as a digital joystick port, and the mini HDMI output may be used down the line to add a second display. Beyond that, Raspberry Pi Zero adds a 1GHz CPU and 512MB of RAM to the hardware – plenty of extra headroom for ambitious game developers.

    We’re impressed. From a design and build quality perspective, ZX Spectrum Next has achieved all we wanted from a new Spectrum. And it’s a great example of using the power of Raspberry Pi to add oomph to a project. From a licensing and business perspective, managing to maintain this purity of focus while blending multiple open-source and proprietary software projects, all while juggling licensing owned by (to our count) 15 separate organisations including Amstrad/Sky, is seriously impressive stuff. Bravo, SpecNext, bravo!

    Verdict

    9/10

    The ZX Spectrum Next is a lovely piece of kit. Well-designed and well-built: authentic to the original, and with technology that nods to the past while remaining functional and relevant in the modern age.

  • Make a Sense HAT rainbow display for your window

    Make a Sense HAT rainbow display for your window

    Reading Time: 9 minutes

    The Sense HAT displaying a rainbow and thank you message

    By following our step-by-step guide, you will discover how to light up rainbow and heart images on the Sense HAT’s LED matrix, as well as showing a custom scrolling message. If you don’t have a Sense HAT, you can still try out the code using the Sense HAT Emulator in Raspbian.

    Click here to download the code used in this project

    Why use a Sense HAT?

    The Sense HAT sits on top of your Raspberry Pi and adds the ability to sense and report details about the world around it. It can measure noise, temperature, humidity, and pressure, for example. The Sense HAT can show readings on an 8×8 LED matrix, but first needs to be instructed, using Python code, what sort of data it should look for. The Sense HAT’s visual display can also be programmed to show specific details including simple images. In this tutorial we’ll look at how to control the LED matrix. Don’t worry if you don’t have a Sense HAT as you can use the Sense HAT Emulator and try out the code in Raspbian.

    Attach the Sense HAT to Raspberry Pi

    Shut down your Raspberry Pi (if it isn’t already) before attaching the Sense HAT to it. Hold the Sense HAT above your Raspberry Pi and line up the yellow holes at each corner with the corresponding ones on Raspberry Pi; make sure the header on Sense HAT lines up with the GPIO pins on Raspberry Pi. The white LED matrix should be at the opposite end of your Raspberry Pi from the USB ports. Gently push the Sense HAT onto Raspberry Pi’s GPIO pins and then screw the two boards together with standoffs. Now power up your Raspberry Pi as usual.

    Open Thonny UDE

    We’re going to use a program called Thonny to instruct our Sense HAT and tell it what to do. When Raspbian loads, select Programming from the top-left raspberry menu, then choose Thonny Python IDE. Click the New icon to open a new, untitled window. We need to get our program to recognise the Sense HAT module. To do this, type these two lines of code into the Thonny window:

    from sense_hat import SenseHat sense = SenseHat() 

    Click the Save icon and name your file rainbow.py.

    Say something

    From now on, Thonny will know to use the Sense HAT whenever you type ‘sense.’ followed by a ‘.’ and a command. Let’s get the Sense HAT to say hello to us. Add this line of code to line 4 in Thonny:

    sense.show_message("Hello Rosie") 

    Of course, you can use your own name. Click Run and the letters should scroll across the LED display. If you get an error in the Shell at the bottom of the Thonny window, check your code carefully against the sense_hello.py listing. Every letter has to match.

    sense_hello.py

    from sense_hat import SenseHat
    sense = SenseHat() sense.show_message("Hello Rosie")

    Choose your colours

    We are going to get the Sense HAT to light up a rainbow and display a heart. We do this with the set_pixel() function.

    We need to tell set_pixel() which LEDs we want to light up, using x and y variables to correlate to the axes of the Sense HAT’s 8×8 grid of LEDs – see Figure 1. We also need to tell set_pixel() the colour using a three-digit code that matches the RGB (red, green, blue) value for each light.

    Figure 1 Sense HAT uses a co-ordinate system to locate each LED on the matrix. The blue light is at (0, 2) and the red light is at (7, 4)

    We’re also going to start with sense.clear(), which clears any currently lit up LEDs. The 8×8 LED display is numbered 0 to 7 in both the x (left to right) and y (top to bottom) axes. Let’s make the top-left LED red. Delete the show_message() line from your code and enter:

    sense.clear() sense.set_pixel(7, 4, 255, 0, 0) 

    The 7, 4, locates the pixel in the last column, and four rows down, and then the RGB value for red is 255, 0, 0 (which is 255 red, 0 blue, 0 green).

    Now let’s add a third line, to light up another pixel in blue:

    sense.set_pixel(0, 2, 0, 0, 255) 

    Check your code against the sense_pixels.py listing. Click Run to see your two dots light up. To add more colours, repeat this step choosing different shades and specifying different locations on the LED matrix.

    sense_pixels.py

    from sense_hat import SenseHat
    sense = SenseHat() sense.clear()
    sense.set_pixel(7, 4, 255, 0, 0)
    sense.set_pixel(0, 2, 0, 0, 255)

    Colour variables

    Working with the RGB values soon becomes frustrating. So it is much easier to create a set of variables for each three-number value. You can then use the easy-to-remember variable whenever you need that colour.

    r = (255, 0, 0) # red o = (255, 128, 0) # orange y = (255, 255, 0) # yellow g = (0, 255, 0) # green c = (0, 255, 255) # cyan b = (0, 0, 255) # blue p = (255, 0, 255) # purple n = (255, 128, 128) # pink w = (255, 255, 255) # white k = (0, 0, 0) # blank 

    Then you can just use each letter for a colour: ‘r’ for red and ‘p’ for purple, and so on. The # is a comment: the words after it don’t do anything to the code (they are just so you can quickly see which letter is which colour).

    How to pick any colour

    If you’re looking for a colour, then use the w3schools RGB Color Picker tool. Choose your colour and write down its RGB number.

    Make a heart

    Light up a pattern of RED leds on the Sense HAT matrix to form a heart.

    Now we’ve got our colours, let’s make a heart. The code in sense_heat.py enables us to draw a heart using ‘r’ letters for red lights, and ‘k’ for blank. This line of code then draws the heart:

    sense.set_pixels(heart) 
    from sense_hat import SenseHat sense = SenseHat() r = (255, 0, 0) # red
    o = (255, 128, 0) # orange
    y = (255, 255, 0) # yellow
    g = (0, 255, 0) # green
    c = (0, 255, 255) # cyan
    b = (0, 0, 255) # blue
    p = (255, 0, 255) # purple
    n = (255, 128, 128) # pink
    w =(255, 255, 255) # white
    k = (0, 0, 0) # blank heart = [ k, r, r, k, k, r, r, k, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, k, r, r, r, r, r, r, k, k, k, r, r, r, r, k, k, k, k, k, r, r, k, k, k ] sense.set_pixels(heart)

    Check your code against the sense_heart.py listing. Click Run and you will see a heart.

    Draw a rainbow

    We light up each row of the matrix a different colour of the rainbow using loops

    Creating a rainbow is a little tricker. We could just draw out each line, like a heart. But we want ours to build up line by line. For this we’ll need to light up each pixel in a row, then pause.

    On the second row (underneath from sense_hat import SenseHat), add this line of code:

    from time import sleep 

    We now have the sleep() function to slow down our program. To add a three-second pause before new pixels are lit up, you would type:

    sleep(3) 

    You can change the number of seconds by changing the number in brackets.

    Create blocks of colour

    To turn an entire row on the LED matrix red, you could type:

    for x in range(8): sense.set_pixel (x, 0, r)
    

    Press TAB to indent the second line. This loops over each LED in the first row (x, 0), replacing x with the numbers 0–7.

    We could repeat this, to set the second line to yellow, with this command:

    for x in range(8): sense.set_pixel (x, 1, y) 

    …And repeat this step until you have eight different coloured lines of LEDs. But this seems a bit clunky.

    Make a rainbow on command

    We think it’s neater to create two nested for loops for the x and y columns. Enter this code:

    for y in range(8): colour = rainbow[y] for x in range(8): sense.set_pixel(x, y, colour) sleep(1)
    

    Take a look at the sense_rainbow.py listing to see how the code should look. Click Run and a rainbow will build up line by line.

    sense_rainbow.py

    from sense_hat import SenseHat
    from time import sleep sense = SenseHat() r = (255, 0, 0) # red
    o = (255, 128, 0) # orange
    y = (255, 255, 0) # yellow
    g = (0, 255, 0) # green
    c = (0, 255, 255) # cyan
    b = (0, 0, 255) # blue
    p = (255, 0, 255) # purple
    n = (255, 128, 128) # pink
    w =(255, 255, 255) # white
    k = (0, 0, 0) # blank rainbow = [r, o, y, g, c, b, p, n] sense.clear() for y in range(8): colour = rainbow[y] for x in range(8): sense.set_pixel(x, y, colour) sleep(1)

    Write a message

    Writing messages in Python to show on your Sense HAT is really straightforward. You just need to decide on a few words to say and type them into a sense.show_message() command, as we did right at the start.

    You can easily specify the text and background colours, too. Choose a contrasting colour for the background. To use your colours in a message, type: sense.show_message(„text here“ text_colour = , followed by the colour value you chose for the text, back_colour = , followed by the colour value you chose for the background.

    Since we have already defined several colours, we can refer to any of them by name in our code. If you haven’t already consulted our rainbow colour list, take a look at the sense_rainbow.py listing and add them to your code.

    For instance, type:

    sense.show_message("THANK YOU NHS!", text_colour = w, back_colour = b) 

    Click Run and your rainbow, followed by your message, should appear on your Sense HAT’s display.

    Bring it together

    We’re now going to take the three things we have created – the heart, the rainbow, and the text message – and bring them together in an infinite loop. This will run forever (or at least until we click the Stop button).

    while True: 

    All the code indented underneath the while True: line will replay as a loop until you press Stop. Inside it we will put our code for the heart, rainbow, and text message.

    By now, you will be able to see the potential of making patterns to display on your Sense HAT. You can experiment by making the colours chase each other around the LED matrix and by altering how long each colour appears.

    Enter all the code from rainbow.py and press Run to see the final message.

    rainbow.py

    from sense_hat import SenseHat
    from time import sleep sense = SenseHat() r = (255, 0, 0) # red
    o = (255, 128, 0) # orange
    y = (255, 255, 0) # yellow
    g = (0, 255, 0) # green
    c = (0, 255, 255) # cyan
    b = (0, 0, 255) # blue
    p = (255, 0, 255) # purple
    n = (255, 128, 128) # pink
    w =(255, 255, 255) # white
    k = (0, 0, 0) # blank rainbow = [r, o, y, g, c, b, p, n] heart = [ k, r, r, k, k, r, r, k, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, r, k, r, r, r, r, r, r, k, k, k, r, r, r, r, k, k, k, k, k, r, r, k, k, k ] while True: sense.clear() sense.set_pixels(heart) sleep(3) for y in range(8): colour = rainbow[y] for x in range(8): sense.set_pixel(x, y, colour) sleep(1) sleep(3) sense.show_message("THANK YOU NHS!", text_colour = w, back_colour = b) sleep(3)

    Sense HAT Emulator

    You can try out this tutorial using the Sense HAT Emulator in Raspbian. To install it, search for ‘sense’ in the Recommended Software tool. Note: If using this Emulator, you’ll need to replace from sense_hat with from sense_emu at the top of your Python code (but not if using the online Sense HAT emulator).

    The Sense HAT displaying the rainbow message in a window display

  • The Official Raspberry Pi Camera Guide out now!

    The Official Raspberry Pi Camera Guide out now!

    Reading Time: 2 minutes

    To coincide with the launch of the High Quality Camera, Raspberry Pi Press has released a new 132-page book to show you how to set it up, shoot great photos and videos, and use it in a range of inspiring projects.

    A step-by-step illustrated guide reveals how to attach a lens to the camera and adjust its focus and aperture settings. You’ll then learn how to control the camera by issuing terminal commands – or with Python code using the picamera library – and discover the many image modes and effects available.

    To inspire you further, an exciting range of Raspberry Pi projects are showcased across the book’s 17 chapters. Take selfies and stop-motion videos, build a wildlife camera trap, experiment with high-speed and time-lapse photography, create a Minecraft photo booth, set up a security camera, use ANPR to identify vehicles, take your camera underwater, and a whole lot more!

    And if you don’t have a High Quality Camera yet, don’t worry: you can use a standard Raspberry Pi Camera Module with all the projects.

    Click here to snap up a copy of the Official Raspberry Pi Camera Guide from the Raspberry Pi Press store.

    Camera Guide - Getting started
    Camera Guide - Connecting and using
    Camera Guide - High-speed photography

  • Hamster Feeder

    Hamster Feeder

    Reading Time: 3 minutes

    “I’d made a video about controlling servo motors using a Raspberry Pi and I wanted to follow that up with a simple, practical project that would put Raspberry Pi-controlled servos into action,” he explains. To that end, the Hamster Feeder was created as a tutorial for his YouTube channel, ExplainingComputers. “It would just need a little refinement to be used to feed a real hamster,” he readily admits.

    Air pods

    Since his channel focuses on single-board computers, he decided to use a Raspberry Pi Zero running Raspbian for his project. He also handmade two little food pods, mounting a servo on the side of each one.

    “The most difficult part of the project was progressing from the idea of ‘let’s use a servo as a catch to open a door at the base of a container’, to actually having two of those little doors on two small containers suspended in the air,” Chris says.

    “I happened to have some plasticard sheet and solvent adhesive, but it was very much a situation of working out what I could design and build in a few hours, with the added complication of how to show the process in a video. I remember a very intense and frantic morning!”

    As well as sticky-taping the lid to the rest of the box, double-sided tape is used to position the servo

    Nutty coding

    After connecting the servos to his Raspberry Pi Zero, Chris turned to Python and broke his code down into three sections. “The first loads in the GPIO, time, and datetime libraries, before setting up board numbering for the GPIO pins,” he explains. “It then sets up pins 11 and 12 as GPIO outputs with software pulse-width modulation, or PWM, which is what is needed to control servos.”

    The second is dedicated to nut loading: “Here the user is invited to close (and hold shut) each pod bay door in turn, and press the ENTER key to allow the servo to move and function as a latch. To maintain a record of each door being closed, variables pod1 and pod2 are set to a value of 1 to indicate when their respective doors are shut.”

    Finally, there is a ‘main while’ loop – a control flow statement that can execute statements when a condition is true. “An if and an elif statement compare the current date and time with two hard-coded dates and times in order to check if a pod door should be opened. They also see if a door is still shut by checking its pod1 or pod2 value, and setting this to 0 once a door is opened.”

    Feeding frenzy

    Of course, improvements could be made. Servos, Chris says, could swing the doors open and closed. “It would also need some chutes to direct the nuts into a hamster cage with the pods and servos entirely separated from a live animal outside of the cage,” he continues. There’s scope to regulate the number of nuts dispensed and to remove hard-coded dates and times in the code.

    “I did think of using another servo to raise a flag saying ‘lunchtime’ every time a pod bay released some nuts,” he adds. “This said, I’m not sure that most hamsters can read and which languages they are most familiar with.”

  • Automation HAT Mini review

    Automation HAT Mini review

    Reading Time: 2 minutes

    The board’s main connections for inputs and outputs are 3.5 mm screw terminals. As well as a single relay, there are three analogue inputs, three buffered inputs, and three sinking outputs. All of these are tolerant to voltages up to 24 V – which is fine for controlling a plethora of household devices that typically have a 12 V or 24 V control board. But make sure you don’t use the board to switch mains voltages!

    Inputs and outputs

    Read via a 12-bit ADC, the analogue inputs have an accuracy of ±2%, which is fine for most purposes when you need to read a variable voltage. The digital inputs are used to tell if a connected device is on (signal above 3 V) or off (below 1 V).

    For turning devices on and off, you have a choice of the three sinking outputs and the relay. For the former, you connect your device load on the ground side; a maximum of 500 mA can be sunk between the three outputs. With a tolerance of up to 2 A, the relay can be connected on the NC (normally closed) or NO (normally open) side, depending on whether your device spends more time switched on or off respectively.

    Although created for the original Automation HAT/pHAT, Pimoroni’s getting started guide shows you how to use the board’s Python library – instead of using the curl command, you’ll need to clone it from GitHub to get the up-to-date version. The relevant code examples show the status of inputs/outputs on the LCD, including bar graphs for analogue inputs. If you’re new to the world of home automation and its terminology, you should also check out Tanya Fish’s excellent explainer on the Pimoroni blog.

    Verdict

    9/10

    It’s ideal for most home automation purposes, and we love the mini LCD, although if you need more relays you might prefer the full-size Automation HAT.

  • How to use Raspberry Pi temperature & light sensors

    How to use Raspberry Pi temperature & light sensors

    Reading Time: 4 minutes

    Temperature & Light sensor projects: You’ll need

    Both projects in this tutorial make use of the PiAnalog Python library that lets you connect analogue sensors to Raspberry Pi without special hardware.

    Although these projects sense temperature and light, you could easily adapt them to use other types or resistive sensor, including stress sensors, variable resistors, and even some types of gas sensor.

    The thermometer project
    : Install the code

    Before fetching the code from the internet, you should run Mu, which you will find in the Programming section of your main menu. If it’s not there, update your system to the latest version of Raspbian.

    Running Mu ensures that the mu_code directory is created, into which we will now copy the program code. To do this, open a Terminal window and run the commands:

    wget http://monkmakes.com/downloads/pb1.sh sh pb1.sh 

    This will copy the programs used in this tutorial into the mu_code directory, along with some others.

    Place components onto breadboard

    Using Figure 1 as a reference, push the jumper wires into the breadboard at the positions shown. Bend the resistor legs so that they fit into the holes.

    The five holes in each row on the breadboard are connected together under the plastic, so it’s very important to get the correct row for your component leg. In this project, none of the components needs to be a particular way around.

    Figure 1 The thermometer wiring diagram

    Connect breadboard to Raspberry Pi

    Again, using Figure 1 as a reference, connect the GPIO pins on Raspberry Pi to the breadboard. A GPIO template will make this easier – if you don’t have one, you’ll need to carefully count the pin positions. It doesn’t matter what colour jumper wires you use, but if you stick to the colours used in the diagram, it’s easier to check that your wiring is correct. Running the program

    Load and run the 05_thermometer.py program using Mu.

    # 05_thermometer.py
    # From the code for the Box 1 kit for the Raspberry Pi by MonkMakes.com from PiAnalog import *
    from guizero import App, Text
    import time p = PiAnalog() # Update the temperature reading
    def update_temp(): temperature = p.read_temp_c() temperature = "%.2f" % temperature # Round the temperature to 2 d.p. temp_text.value = temperature temp_text.after(1000, update_temp) # Create the GUI
    app = App(title = "Thermometer", width="400", height="300")
    Text(app, text="Temp C", size=32)
    temp_text = Text(app, text="0.00", size=110)
    temp_text.after(1000, update_temp) # Used to update the temperature reading
    app.display()

    The code is configured for the thermistor supplied with the MonkMakes Project Box 1 kit. If you look near the top of the file, you will see the line:

    temperature = p.read_temp_c().
    

    If you are using your own thermistor, you will need to add two new parameters to the method call. The first parameter is the value of Beta for the thermistor, and the second the value to R25 (resistance at 25°C). You will find both of these values in the thermistor’s datasheet. For example, if Beta is 3800 and R25 is 1 kΩ, you would use: p.read_temp_c(3800, 1000).

    After a few seconds, a window will appear, like the one in Figure 2, displaying the temperature. If you would rather have the temperature displayed in degrees Fahrenheit, then run the program 05_thermometer_f.py instead.

    Figure 2 Displaying the temperature using guizero

    Changing the temperature

    The easiest way to change the temperature of the thermistor is to pinch it between your fingers so that your body warmth heats it up. You should see the temperature steadily increase and then decrease back to room temperature when you let go of the thermistor.

    Light meter project
    : Disconnect the breadboard

    This project has almost the same layout as the thermometer, and we are just going to swap the thermistor for a phototransistor, but it is still a good idea to disconnect the breadboard from your Raspberry Pi. First, pull the jumper wires off the GPIO pins on Raspberry Pi and then take the thermistor off the breadboard.

    Place phototransistor onto breadboard

    This time, using Figure 3 as a guide, put the phototransistor legs into the breadboard. The phototransistor must go the correct way around: the longer leg should go to row 4.

    Figure 3 The light meter wiring diagram

    Connect breadboard to Raspberry Pi

    Using Figure 3 as a reference, connect the GPIO pins on Raspberry Pi to the breadboard using three female-to-male jumper wires.

    Running the program

    To use the light meter, load and run the program 08_light_meter.py in Mu.

    # 08_light_meter.py
    # From the code for the Box 1 kit for the Raspberry Pi by MonkMakes.com from guizero import App, Text
    from PiAnalog import *
    import time, math p = PiAnalog() def light_from_r(R): # Log the reading to compress the range return math.log(1000000.0/R) * 10.0 # group together all of the GUI code
    # Update the reading
    def update_reading(): light = light_from_r(p.read_resistance()) reading_str = "{:.0f}".format(light) light_text.value = reading_str light_text.after(200, update_reading) app = App(title="Light Meter", width="400", height="300")
    Text(app, text="Light", size=32)
    light_text = Text(app, text="0", size=110)
    light_text.after(200, update_reading)
    app.display()
    

    When the program starts, a window like that in Figure 4 will appear, showing the light level. Try shading the phototransistor with your hand or shining a light on it to see how the readings change.

    Figure 4 Displaying the light level

  • Work from Home and new High Quality Camera in The MagPi #93

    Work from Home and new High Quality Camera in The MagPi #93

    Reading Time: 2 minutes

    Click here to buy The MagPi magazine issue #93

    How to work from home with Raspberry Pi

    Work from home with Raspberry Pi

    Raspberry Pi 4 is seeing a boom in use as a desktop computer for the home. Whether you’re working with Raspberry Pi, or learning, or looking to do video chat; Gareth Halfacree’s Work from home feature has all the information you need
    .

    High Quality camera

    Get started with the High Quality Camera

    There’s a new official camera in town. The High Quality Camera is capable of capturing higher-resolution images than the standard Camera Module. And it works alongside a CS-mount lens, making it ideal for photography and macro photography. Our tutorial explains how the camera works, and how to start capturing images.

    Hot Spotter

    Hot Spotter and other amazing projects

    This amazing Hot Spotter project uses a Raspberry Pi drone to detect smouldering points after a wildfire. It surveys a large area and creates a heat map from temperature readings. These hot points can re-ignite, and Hot Spotter can send the data in real-time to people on the ground. The MagPi magazine is packed with projects like this.

    At home with the Internet of Things

    At home with the Internet of Things

    Upgrade your home with these amazing IoT projects. From controlling sockets, to monitoring temperature and humidity, hacking your doorbell, and automating your lights. There’s a project here for every home.

    ZX Spectrum Next Accelerated

    ZX Spectrum Next Accelerated reviewed

    We take a look at the all-new ZX Spectrum Next Accelerated. A modern re-thinking of a classic computer that uses Raspberry Pi Zero alongside an FPGA (Field Programmable Gate Array) to mimic analog tape-loading to perfection.

    We deliver to your door

    Buy The MagPi magazine issue #93 from the Raspberry Pi Press store and we will deliver it straight to your door. Plus! Take a 12-month subscription in print and we’ll give you a free Raspberry Pi Zero computer and starter kit worth £20.

  • Win one of five Raspberry Pi High Quality Camera and lens!

    Win one of five Raspberry Pi High Quality Camera and lens!

    Reading Time: < 1 minute

    Subscribe

  • Digital Making at Home

    Digital Making at Home

    Reading Time: 2 minutes

    Thousands of people have started engaging with Digital Making at Home. They’ve also had kids sharing their projects.

    Digital Making at Home is for kids who want to get into making things with technology and need a few pointers. If you or your friends are looking for ideas of how to entertain youngsters or simply want new project ideas, the Raspberry Pi project portal comes highly recommended.

    Like all Raspberry Pi projects, the tutorials are both step-by-step and free. Videos explain all about coding platforms such as Scratch and Python, helping kids to quickly catch up.

    Digital Making at Home features instructor-led tutorials

    Young coders rule!

    For families with no prior digital coding or making experience, Raspberry Pi staff members explain how they first introduced their own children to coding. Their initially tentative kids soon became confident, independent learners.

    Children can use the game-making and coding skills they’ve learned to make their own versions based on their own interests. The Raspberry Pi Foundation’s Senior Learning Manager, Marc Scott, related how his son used his new-found coding skills to create a random karate moves generator which helped him prepare for a karate exam.

    The projects, designed for all levels of experience, are self-contained and can be completed without much need for parental input, although many people tell of how much they enjoyed working through projects alongside their kids. They can be easily adapted to be more sensory, for example, so they suit learners with autism.

    Marc cautions that before kids share their work online, they’re prompted to consider what information they should be sharing about themselves. All schools now teach e-safety, so running through a checklist should be second nature.

    Video tutorials

    There is a Digital Making at Home blog
    which sees makers share the progress of their builds, troubleshoot issues that arise, and discuss ways to express their creativity. New instructor-led video posts are shared each week enabling viewers to code along with others. Subjects include making games and storytelling with code. Parents and carers can also sign up for tailored age-specific content via email sent bi-weekly.

    People can sign up for Digital Making at Home here.

  • 10 amazing Raspberry Pi audio projects

    10 amazing Raspberry Pi audio projects

    Reading Time: 3 minutes

    Wave away music

    We like yelling at our digital home assistant thing to skip the track it’s currently playing. It feels very Star Trek. Sometimes it’s more dramatic to wave the music away – just like with the Wavepad.

    Pathé news, now!

    This radio reads out your notifications from a variety of services. It doesn’t have an old-fashioned news bulletin voice, but it’s the spirit that counts.

    One song only

    Want to listen to one song, and one song only? Close a contact on this Raspberry Pi project for just that. Simple.

    Old-school personal assistant

    Martin Mander made this with the AIY Projects kit that came with The MagPi #57. We love the meta idea of how this has been repurposed.

    Dramatic music player

    Feel like a sitcom character and have some slapping bass tunes play as you walk through the door. What’s the deal with theme tunes, anyway?

    Retro internet radio

    This is a 1970 Flirt radio that upcycling maestro Martin Mander has turned into a Raspberry Pi-powered internet radio, without sacrificing much of its wonderful aesthetics.

    Tom Hanks inspired

    Using a light tripwire to sense where you are, (carefully) dancing up and down these stairs should help with your scales and arpeggios.

    Finger drumming goodness

    As well as being a lot of fun, this is a neat little conductivity experiment so you know how capacitive touch works. With a little beat added to it.

    Outer space vibes

    This official Raspberry Pi project uses an ultrasonic distance sensor – something you mostly find on robots – to create a theremin sound as you move your hand through it.

    Accessible sodar

    Using sound to detect distance is pretty standard tech, but it always helps to make it easier. This sodar project helps you do that.

  • PiVidBox

    PiVidBox

    Reading Time: 3 minutes

    “My project [PiVidBox] is a simple-to-use Raspberry Pi based media centre that even children as young as three years old can use,” he tells us.

    “It provides a simple, physical interface that’s based on old and most likely discarded hardware. It’s simple, because instead of a full-blown graphical interface that may be too complicated for small kids to operate, it uses a physical interface that relies on a simple action of plugging in USB thumb drives to Raspberry Pi.”

    PiVidBox is a quite ingenious bit of low-tech design, and anyone who has seen a toddler work a DVD player recently will understand how physical interaction is something they can understand.

    PiVidBox: Quick Facts

    • PiVidBox can also take SD cards thanks to an adapter

    • STL files are available to 3D-print the parts used

    • It uses OMXPlayer to play videos instead of dedicated HTPC software

    • Labels on the USB sticks and cards are simple images

    • All the code is available on GitHub

    The system works by having the USB drive checked by Raspberry Pi during boot, and then playing a random video from it. You can easily swap it out for other USB drives, as the script can tell: “We have thumb drives with cartoons, anime and youth shows for our kids, but we also made a thumb drive with our old favourite shows when me and my wife want to watch some reruns of nostalgic shows,” says Roiy.

    The list of components is fairly simple – the only slightly quirky part is a USB A male to USB A female cable

    Empowering kids to watch videos they choose

    “Having three kids at home, I wanted to empower them by giving them the ability to choose what video content they want to watch by themselves,” he explains. “But on the other hand, I also wanted to control what kind of content they consume rather than letting them roam freely on video streaming services such as Netflix and YouTube. I also had a pile of old Raspberry Pi [boards] and thumb drives that I wanted to use for something beneficial.

    “I had the aha moment where I was cleaning up my desk, thinking of what to do with a my old Model 1 Raspberry Pi and a bunch of old small-capacity thumb drives (around 1GB to 2GB) when I heard my youngest son calling me to help him with some Baby Shark videos he really wanted to watch.”

    The system has been a success, with Roiy telling us that his kids use it without any problems. It’s so good in fact, he’s started using it more himself when they go to sleep.

    The 3D-printable files for the USB and SD card rack for this project are available on Thingiverse

    Future plans for PiVidBox

    As with a lot of projects, this is not the end of the tinkering and tweaking. “I have dozens of ideas on how to improve this,” says Roiy. “For example: detecting if the HDMI connection is enabled and resume or pause based on the status. In this case, it pauses and unpauses the video as you switch the TV inputs. Support for extended media formats such as MP3 (so it can also be used to play music), adding Alexa or Google Home support so that skipping to the next video can be enabled by voice commands, and many other ideas.” We might have to put together a version ourselves for smaller relatives – and it’s easy to do with the instructions on the PiVidBox GitHub page.

    Step 1. Select a USB stick and plug it into the PiVidBox. As it boots, it detects the USB drive that has been inserted.
    Step 2. A video is randomly selected and played, followed by a second video, on loop, forever. Great for kids.
    Step 3. If you want to change genre, just remove the USB stick and insert another one. PiVidBox picks up on the change and begins playing anew.