Code Pac-Man in Python (part 2)

Code Pac-Man in Python (part 2)

Coding a Python Pac-Man-style game is a great way to learn more about Python programming and Pygame Zero. In the first part of our Pac-Man-style tutorial, we created a maze for our player to move around, and restricted movement to just the corridors. We provided some dots to eat and some ghosts to avoid. In this part we are going to give the ghosts some more brains so that they are a bit more challenging to the player. We will also add the bonus power-ups which turn the ghosts into tasty edibles, give Pac-Man some extra levels to explore and some extra lives. So far in this series we have not dealt with music, so we will have a go at putting some music and sound effects into the game. The code is in this tutorial explains how the game works. Make sure you download the code from GitHub and use this tutorial as a code-along. This tutorial was written by Mark Vanstone and first appeared in The MagPi 77. Join our newsletter for a free digital edition every month; or subscribe to The MagPi for 12-months in print and get a free Pi Zero W & Starter Kit and a copy delivered to your door every month. See also: Make with code in The MagPi #77 Pygame Zero Invaders and Pygame Zero: Space Invaders II The best Python websites and resources Create a Python game: how to make a puzzle game called Same A more advanced Pac-Man in Pygame Zero In part one, we left our ghosts wandering around the maze randomly without much thought for what they were doing, which was a bit unfair as Pac-Man could evade them without too much trouble. In the original game, each ghost had a program that it followed to characterise its movements. We are going to add some brains to two of the ghosts. The first we will make follow Pac-Man, and the second we will get to ambush by moving ahead of Pac-Man. We will still leave in some random movement, otherwise it may get a bit too difficult. Pac-Man Python: what you’ll need Raspbian Jessie or newer An image manipulation program such as GIMP, or images available here The latest version of Pygame Zero (1.2) The pacman2 folder from GitHub USB joystick or gamepad (optional) Headphones or speakers Pac-Man gets points for eating dots, and ghosts after eating power-ups Follow…
Source: Code Pac-Man in Python (part 2)

A Whisper of Moths

A Whisper of Moths

We always love to see art installations that make use of the Raspberry Pi, and A Whisper of Moths is a perfect example. This particular project involved several people from the Print Mill, which is part of Macclesfield Community ArtSpace, along with technical and labour support from IDST! (If Destroyed Still True!), another ArtSpace group. This article first appeared in The MagPi 80 and was written by Rob Zwetsloot “The moths were made by local schoolchildren using recycled A4 plastic wallets that were drawn on and/or filled with glitter, ironed between baking parchment and cut to shape,” Nick Young from the team tells us. “Some moths were also 3D-printed.” The movement of the moths was simulated by projecting randomly positioned and sized circles onto the moths, which were hanging by fishing line from fine garden netting suspended from the church balcony. The installation was interactive, with the sound of whispers being triggered as people walked through, along with the projected circles of light to simulate movement to some degree. How did such an idea come about, though? The moths were made using recycled, or by recycling, materials Lunar new year “The Town Council approached Macclesfield Community ArtSpace wishing to celebrate in some form, Chinese New Year,” Nick explains. “Macclesfield’s link with China is through silk and therefore the suggestion was made to create an installation that incorporated silk moths and engaged the local schoolchildren in the making process. Macclesfield is also striving to draw attention to the problems of single-use plastic and so we chose to use plastic and recycle it.” After following a Chinese dragon puppet and papier mâché pig down the high street in a parade during the Chinese New Year festivities, people walking into the church would trigger the display. “We had the added and unforeseen bonus of coloured light filtering through the moths as the sun shone through the huge stained glass windows,” Nick recalls. A dragon dance led the visitors to the church, where they would experience A Whisper of Moths Pi connection “We discussed motorising some or all moths, even just with vibration motors, but discarded this as inappropriate for a sustainable art-piece,” Nick says. “We decided to have a moving pattern of light [shone] around or onto the static exhibit to create the illusion of movement. We created a prototype using metres of LEDs, but these were not bright enough and on surveying the…
Source: A Whisper of Moths

The 10 best Raspberry Pi HATs

The 10 best Raspberry Pi HATs

HATs are incredible add-ons to the Raspberry Pi that increase its functionality in a huge number of ways – from added sensors and inputs for fun projects, to practical applications in business and enterprise. Here are our picks for the 10 best Raspberry Pi HATs: Sense HAT: Space-faring sensor Used in the Astro Pi devices up on the International Space Station, this cool Sense HAT (£32 / $40) has an 8×8 pixel display, environmental sensors, accelerometer, and a little joystick. There’s loads of great Raspberry Pi resources that use it as well. See: Sense HAT Essentials The Sense HAT GFX HAT: Display and inputs We really like the GFX HAT (£22 / $23) – not only is it a very nice display that is easy to program for, it also has a series of (capacitive touch) buttons. It’s amazing for practical projects or basically any Pi that’s turned on a lot The GFX HAT PoE HAT: Power over Ethernet The Raspberry Pi is very popular in enterprise settings, and the PoE HAT (£18 / $20) allows for a more efficient way to add Pi boards to a system. With PXE boot and power from the Ethernet port, you can do a lot with a 3B+. See also: Raspberry Pi PoE HAT review The Raspberry Pi PoE HAT attached to a Raspberry Pi 3B+ board Automation HAT: Automating everything Want to connect your entire house up to a Raspberry Pi? You’ll have better luck with the Automation HAT (£29 / $31), which has just a ton of connections that you can use. And it all sits on top of a Pi! See also: Home automation add-ons for Raspberry Pi The Automation HAT Picade X HAT: Totally awesome video games Powering the almighty Picade is this amazing control Picade X HAT (£16 / $17) that’s purpose-built for Pi-powered arcade machines. It includes audio and inputs, along with other bits and pieces, and it’s the perfect heart for your arcade build. See also: Picade Review The Picade X HAT has easier-to-use connections, including a ‘Hacker‘ header PaPiRus HAT: E-ink display You can make anything look 20% classier with a PaPiRus HAT e-ink display (£41 / $54). Trust us, we’ve got the science to back it up. It’s very low-power, depending on usage, and looks great even in bright sunlight. See also: PaPiRus Zero Medium review The PaPiRus HAT The PaPiRus HAT Unicorn HAT HD: High-def LEDs The wonderful…
Source: The 10 best Raspberry Pi HATs

Hack Lego Boost with Raspberry Pi

Hack Lego Boost with Raspberry Pi

The Lego Boost is designed to be run from an app on an Android or iPad tablet, using a graphics programming language not unlike Scratch. It makes a good job of this and is easy for kids to pick up, but these sorts of languages have their limitations. They can be inflexible and difficult to read, especially as the code gets bigger. By using Python, much more complex programs can created, many that are not possible with graphics-based code. So, give your Boost a boost by letting Python do the controlling. This article was written by Mike Cook and first appeared in The MagPi issue 80. Subscribe to our newsletter to get a free digital edition of The MagPi delivered to your inbox every month. Or subscribe in print to get The MagPi magazine delivered to your door. Mike is a veteran magazine author from the old days, writer of the Body Build series, plus co-author of Raspberry Pi for Dummies, Raspberry Pi Projects, and Raspberry Pi Projects for Dummies. What is Lego’s Boost? Unlike the previous Mindstorms robotics systems from Lego, the Boost system has no controlling brick to run code – instead, instructions representing the program are sent one at a time directly, over Bluetooth, in real-time to the Move Hub. This has built-in motors, LEDs, tilt sensor, and push-button. You can also plug into the Hub a smaller motor and a distance sensor or colour sensor. Also, Mindstorms uses Lego Technic beams for most constructions, known as a studless system, whereas the Boost uses the more conventional, studful brick form of construction. See Figure 1. Figure 1 Studful bricks on the left, studless beams on the right Lego’s software The standard Lego software provides a good structured learning system where the user builds a bit, programs it, and then moves on to building more. The big project is Vernie the robot and we’d recommend you do this first because the parts are already bagged up to make construction of this project easy. Vernie is built up in stages and the code you are asked to run at each stage gets increasingly complex. You can’t progress to the next level without trying, or pretending to try, the current phase. We recommend you try this first, not least for the firmware updates it can offer to your Hub – see Figure 2. Figure 2 The Lego Boost program environment running on…
Source: Hack Lego Boost with Raspberry Pi

Claire Pollard interview

Claire Pollard interview

When you’ve been around the Raspberry Pi community for a while, there are a few faces that start to become familiar. If you’ve ever visited the PiBorg desk at a Raspberry Jam, or gotten involved in the online Raspberry Pi community, you’ve likely bumped into Claire. Recently, she’s become more active in the community, so we caught up with her to see what’s up. This article first appeared in The MagPi 80 and was written by Rob Zwetsloot “I am a mathematician/computer scientist by training and have spent the last seven and a bit years working as a developer for a software company who make software for use in computer-aided design and computer-aided engineering,” Claire explains. “My job needs a lot of different skills, from technical understanding of maths, to coding, to the ability to explain my work at different levels, from academic papers to social media. “Last year, I decided to leave that job and took up a position at ModMyPi to work in the Pi community full-time. The Raspberry Pi community has always been a part of my life as my fiancé Timothy owns PiBorg, so I’ve always been to shows, helped pack and assemble kits in the early days, and helped out where I can and really enjoyed the friendly, diverse, and supportive community. When the job came up at ModMyPi, I couldn’t resist diving in and getting to use the Pi all day, every day!” Claire is also the voice of Formula Pi, the amazing robot racing league set up by PiBorg. Claire is also the voice of Formula Pi, the robotic racing league When did you first learn about the Raspberry Pi? My Dad is a big Linux fan, and he heard about the Raspberry Pi through one of the podcasts he listens to. He used to pick me up from work on his way home before I got a car, and we chatted about it on the drive home. He seemed quite excited at the prospect of a tiny Linux board that was easy to use and relatively cheap. I think we missed getting one on release week, but Timothy got one on eBay a few weeks after launch, and the rest is history! Do you have any favourite Pi projects you’ve made or been involved with? I’ve really enjoyed helping with Formula Pi and seeing it grow into the chaotic event that it is…
Source: Claire Pollard interview

Pictures from space via ham radio

Pictures from space via ham radio

What is Slow Scan TV (SSTV), then? You convert a picture into sound (similar to fax machine or dial-up modem noise) transmit the sound via radio, and convert the received sound back into a picture at the other end. The International Space Station (ISS) has a long history of transmitting SSTV pictures for global events, each lasting several days, where people the world over tune their radios to the ISS and try to receive the pictures every time it flies over their home. One such event is set to begin on 12 April 2019 to celebrate the anniversary – to the day – of the launches of Yuri Gagarin in 1961 and the first Space Shuttle, 20 years later, in 1981. You’ll need Raspberry Pi 2B or later 3.5 mm speakers or headphones RTL-SDR USB dongle (search for ‘RTL2832U’) with a good whip or dipole antenna Tape measure, at least 1 metre Install prerequisites and set the time We presume you are running a clean install of Raspbian Stretch Desktop edition and are online. Firstly, switch the audio output to the 3.5 mm headphone jack. This is needed for the way PulseAudio loops back the system audio as an input device. On the Raspbian desktop, simply right-click the speaker icon in the menu bar and choose Analog. Then, open a Terminal and install the required software for the project:sudo apt-get update sudo apt-get install rtl-sdr sox pulseaudio qsstv ntpdate -yNext, set your time zone and pull the correct time from the internet. In the Raspbian main menu, go to Preferences > Raspberry Pi Configuration > Localisation tab > Set Timezone, change Area and Location accordingly, then click OK. Finally, go back to the Terminal window to pull the time:sudo ntpdate pool.ntp.orgNote that the desktop clock in the top right only updates every minute. Install and test the RTL-SDR dongle Insert the RTL-SDR dongle into your Pi and screw in the antenna (it can sit on your desk at this stage). Then verify the RTL-SDR is working with the rtl_test program. In a Terminal window, enter:rtl_testIf you see a ‘failed to open rtlsdr device’ error, remove the dongle, reinsert it, and try rtl_test again. Leave for about 30 seconds and look out for any messages about loss of samples. Press CTRL+C when 30 seconds has elapsed. The loss of 100 bytes or so is acceptable. A good, but cheap, antenna which can pick up the…
Source: Pictures from space via ham radio

E-ink Calendar

E-ink Calendar

Some project ideas are simple yet effective, allowing makers to get creative with otherwise unused items to produce something practical or fun. In Zonglin Li’s case, inspiration struck when he was attempting to find a use for an e-ink screen he’d bought a long time ago without a clear project in mind. “I came across the box containing the screen and it reminded me that I should do something with it,” he says. This article first appeared in The MagPi 80 and was written by David Crookes At first, he considered turning it into a straightforward digital clock. “But I soon figured that it was impractical due to the long refresh time – every minute would require a full update, which is visually annoying,” he explains. He then began to think about the kinds of information which could tolerate a longer refresh period. “The project was not really ambitious at the beginning and all I wanted initially was something that could show me the date and perhaps the weather,” says Zonglin. From there, however, he had the idea of incorporating his daily activities, seeing the existence of the Google Calendar API as an ideal opportunity. Paper Pi To start, he opted to use a Raspberry Pi because of its ability to run a full OS and its abundance of GPIOs: “Having a full OS meant that I could use high-level programming languages which saved a lot of time, especially when it came to Google OAuth and API integrations. The screen manufacturer also had nice documentation for Raspberry Pi, so it was easier to get started.” He also quickly realised that the e-ink screen would be a perfect fit. “I believed it would give a feeling of a real paper calendar that happened to display up-to-date information,” he says. “The e-ink display also simplified the design, especially if you wanted to put the device in the bedroom, because it doesn’t need to be backlit to operate. Unlike using LCD, you don’t have to design the logic for adjusting the brightness either.” Some e-ink screens support rapid partial update with multiple grey scales, so Zonglin is considering upgrading to add real-time notification mirroring using Pushbullet Widget designs Even so, much of the effort went into coding, with Zonglin coming up with ideas for widgets before figuring how best to structure them. He composed a date widget from a matrix of text widgets…
Source: E-ink Calendar

Thync: commercial smart calendar built with Pi Zero

Thync: commercial smart calendar built with Pi Zero

Smart calendars are a hugely popular Raspberry Pi project, but not everybody wants to make their own. Some people just want to buy things. Thync is a commercial smart calendar project with Raspberry Pi at its heart. Vitec GmbH V is hoping to bring a Raspberry Pi-based calendar device to the masses is its Smart Calendar with Thync. Says Marc Roset, CEO and Founder of Vitec GmbH: “Managing the daily schedule, full of appointments and tasks, is a nightmare for most families. Many businessmen and professionals find the compatibility of work and family calendars almost impossible.”

Smart calendar Thync built with Raspberry Pi The Smart Calendar Thync supports the synchronisation and connection of up to five different appointment calendars. Inside the case is a Raspberry Pi Zero W powered by a battery, running a 10.1-inch TFT display. Interestingly, the Smart Calendar Thync features a gesture sensor interface. “This allows you to quickly and easily switch back and forth by moving your hand. A short upward movement allows you to display further information about your current function,” says Marc. “The simplest way is set up the product is via our app [Android and iOS]. We don’t use voice control for our product because a lot of people fear that other people can hear what they are saying.” Inside the Smart Calendar is a custom circuit board with a Pi Zero mounted on top of it Light sensing calendar The Smart Calendar Thync also features an ambient light sensor, which measures the brightness of the surrounding area, regulates the brightness, and optimises energy usage. Users are able to mount the Smart Calendar Thync on a wall or use the stand to place it on a flat surface. A Kickstarter campaign for Smart Calendar Thync can be found here. The post Thync: commercial smart calendar built with Pi Zero appeared first on The MagPi Magazine.
Source: Thync: commercial smart calendar built with Pi Zero

Zero Dongle review

Zero Dongle review

One incredible use of the Pi Zero that often gets overlooked is its ability to function as a USB gadget – you can connect it to a computer’s USB port and have it act like a USB plug-and-play device. This can be as simple as having it power on, act as USB mass storage, or even share your computer’s internet connection. This article first appeared in The MagPi 80 and was written by Rob Zwetsloot The trickiest part of setting up a Pi Zero gadget is adding the necessary hardware to connect it. Male-to-male micro USB to USB A cables aren’t very common, and not particularly neat. This is where something like the Zero Dongle comes in – slotting neatly under a Pi Zero, it’s a solid piece of PCB connecting a USB A male connector to a micro USB male connector. Dongle not dangle The Zero Dongle fastens onto a Pi Zero (any Pi Zero) using a couple of screws on the SD card end. It’s quite sturdy so you shouldn’t have to worry about it snapping down the middle. There’s only the smallest protrusion on the side, so it can slide into the Pi Zero’s micro USB data port, although it does extend out a fair bit with the main USB A connector – but that’s unavoidable. The dongle does not automatically set up your Pi as a gadget – there are no specific chips on it that will do that – so you’ll have to make the usual modifications to your SD card. You also might have a little trouble finding a case that fits it. Those are nitpicks, though – for the price and intended function, it’s exactly what you’d need for a USB gadget add-on. Verdict 9/10 A great and cheap add-on for a Pi Zero that allows it to work really well as a USB gadget device. The post Zero Dongle review appeared first on The MagPi Magazine.
Source: Zero Dongle review

Raspberry Pi Clapper

Raspberry Pi Clapper

Ash Puckett thought her life could do with a little simplifying, so she came up with a thunderclap of an idea, as she recalls: “I rolled out of bed one morning, clapped my hands, and remembered I don’t have clap-powered lighting. This project first appeared in The MagPi issue 80. Sign up to our newsletter to get a free digital edition every month, or subscribe to The MagPi and we’ll deliver it direct to your door. What better way to remedy Ash’s situation than to create my own Raspberry Pi Clapper?” What better way indeed? Ash then took a Raspberry Pi, along with a USB microphone, and created something elegantly simple, but useful at the same time. Amazingly, the entire project was conceptualised and completed in one day, then made into an online tutorial. “The challenge is in creating a guide with flexibility,” she reveals. “I wanted to create a starting point for anyone with a similar project in mind. Whether you want clap-powered music or a clap-powered garage door, there’s a common foundation they all share, and I wanted to provide that.” The Clapper device before a clap The Clapper after a clap The Clapper: quick facts Claps are detected using Nikz Jon’s pi‑clap script. You can follow Ash’s howchoo tutorial here. The PyAudio library is used to detect sound from a USB mic You could trigger many different items with a clap – use your imagination! Ash’s other Pi projects include a smart alarm clock and a music-streaming device Your clap is my command So, how does it work exactly? “The Raspberry Pi is programmed to listen for claps using a USB microphone,” explains Ash. “You can use this to trigger custom events. Pretty much anything you can control with Python can be manipulated using the power of clapping.” The possibilities, in terms of what you can control, are vast. “I’ve been able to control an LED, initiate some funky tunes, and run a few custom scripts. The proof of concept has been demonstrated – from here it’s a matter of imagination,” says Ash. “If you can control it with a Pi, you can control it with claps. This includes home automation using relays, controlling smart kitchen appliances, and lighting.” Ash used the Raspberry Pi for her make because, “I knew from experience the Pi was more than capable. You can really take advantage of the GPIO pins…
Source: Raspberry Pi Clapper