Kategorie: Linux

  • #MonthOfMaking, Starter Electronics and new entry-level Raspberry Pi 4 with 2GB RAM in The MagPi 91

    #MonthOfMaking, Starter Electronics and new entry-level Raspberry Pi 4 with 2GB RAM in The MagPi 91

    Reading Time: 2 minutes

    Click here to buy The MagPi Magazine issue #91

    #MonthOfMaking

    #MonthOfMaking

    Once a year The MagPi magazine readers come together and commit to build something. And we all reach out to each other online and offer encouragement. Pick up your copy of The MagPi magazine #91 to learn all about #MonthOfMaking.

    Let’s build together!

    Raspberry Pi 4 now comes with 2GB RAM minimum

    Raspberry Pi 4 with 2GB

    The entry-level Raspberry Pi 4 now comes with 2GB RAM and costs the same, just $35. This is a game-changer for Raspberry Pi, and its base computer now has the power to run as an effective desktop. We interview Eben Upton, Raspberry Pi founder and CEO, about the new introductory model and what it means for the world’s best single-board computer.

    Configuring your magic mirror

    Magic mirror modules and extensions

    Building a magic mirror is one of the most impressive starter projects around, and this month PJ Evans discovers how to configure your magic mirror with extensions. These are used to sprinkle all kinds of extra features onto a magic mirror.

    Project Showcase: Bellagio Fountain

    The best community projects

    You’ll find the best projects built using Raspberry Pi inside The MagPi magazine. One of the many stars this month is this Bellagio Water Show. It’s a truck-based reproduction of the classic Vegas water show, built and controlled using Raspberry Pi.

    Starter Electronics with Raspberry Pi

    Starter Electronics with Raspberry Pi 

    Electronics is the name of the game this month, and we’re not going to leave anybody behind. Hooking up circuits and components to Raspberry Pi (with those nifty GPIO pins) is how you get a computer to control things. And it all starts with a few simple electronic projects. We’ll show you how to use GPIO pins and pick up the right starter components, then Simon Monk walks us through some famous starter projects.

    Click here to buy The MagPi Magazine issue #91

  • A birthday gift: 2GB Raspberry Pi 4 now only $35

    A birthday gift: 2GB Raspberry Pi 4 now only $35

    Reading Time: 4 minutes

    TL;DR: it’s our eighth birthday, and falling RAM prices have allowed us to cut the price of the 2GB Raspberry Pi 4 to $35. You can buy one here.

    Happy birthday to us

    In two days’ time, it will be our eighth birthday (or our second, depending on your point of view). Many of you set your alarms and got up early on the morning of 29 February 2012, to order your Raspberry Pi from our newly minted licensee partners, RS Components and Premier Farnell. In the years since, we’ve sold over 30 million Raspberry Pi computers; we’ve seen our products used in an incredible range of applications all over the world (and occasionally off it); and we’ve found our own place in a community of makers, hobbyists, engineers and educators who are changing the world, one project, or one student, at a time.

    The first Raspberry Pi

    When we first started talking about Raspberry Pi 1 Model B back in 2011, we were very clear about what we were trying to build: a desktop Linux PC with interfacing capabilities for $35. At the time, it seemed obvious that our low price point would come with compromises. Even though you could use your Raspberry Pi 1 to watch HD video, or play Quake 3, or compile the Linux kernel, or automate a factory, some things – like browsing modern, JavaScript-heavy websites – were out of reach.

    Our very first website led with an early prototype running an Ubuntu 9.04 desktop

    Improving performance

    Every subsequent product – from quad-core Raspberry Pi 2 in 2015, to 64-bit Raspberry Pi 3 in 2016, to Raspberry Pi 3+ in 2018 – whittled down those compromises a little further. By offering steadily increasing processing power at a time when the performance of traditional PCs had begun to stagnate, we were gradually able to catch up with typical PC use cases. With each generation, more people were able to use a Raspberry Pi as their daily-driver PC.

    The Raspberry Pi I’d buy for my parents

    Until, in June of last year, we launched Raspberry Pi 4. Roughly forty times faster than the original Raspberry Pi, for the first time we have a no-compromises PC for the majority of users. I’ve described Raspberry Pi 4 as “the Raspberry Pi I’d buy for my parents”, and since I bought them a Desktop Kit for Christmas they’ve found it to be basically indistinguishable in performance and functionality from other PCs.

    In a sense, this was a “mission accomplished” moment. But Raspberry Pi 4 brought its own compromises: for the first time we couldn’t fit as much memory as we wanted into the base product. While the $35 1GB device makes a great media player, home server, or embedded controller, to get the best desktop experience you need at least 2GB of RAM. At launch this would have cost you $45.

    Dropping the price of 2GB

    Which brings us to today’s announcement. The fall in RAM prices over the last year has allowed us to cut the price of the 2GB variant of Raspberry Pi 4 to $35. Effective immediately, you will be able to buy a no-compromises desktop PC for the same price as Raspberry Pi 1 in 2012. In comparison to that original machine, we offer:

    • 40× the CPU performance
    • 8× the memory
    • 10× the I/O bandwidth
    • 4× the number of pixels on screen
    • Two screens instead of one
    • Dual-band wireless networking

    And of course, thanks to inflation, $35 in 2012 is equivalent to nearly $40 today. So effectively you’re getting all these improvements, and a $5 price cut.

    We’re going to keep working to make Raspberry Pi a better desktop computer. But this feels like a great place to be, eight years in. We hope you’ve enjoyed the first eight years of our journey as much as we have: here’s to another eight!

    FAQs

    Is this a permanent price cut?

    Yes.

    What about the 1GB product?

    In line with our commitment to long-term support, the 1GB product will remain available to industrial and commercial customers, at a list price of $35. As there is no price advantage over the 2GB product, we expect most users to opt for the larger-memory variant.

    What about the 4GB product?

    The 4GB variant of Raspberry Pi 4 will remain on sale, priced at $55.

    Website: LINK

  • Play Pong with ultrasonic sensors and a Raspberry Pi | HackSpace magazine

    Play Pong with ultrasonic sensors and a Raspberry Pi | HackSpace magazine

    Reading Time: 4 minutes

    Day three of our Pong celebration leads us here, to HackSpace magazine’s ultrasonic hack of Eben’s Code the Classics Pong tribute, Boing!

    If you haven’t yet bought your copy of Code the Classics, you have until 11:59pm GMT tonight to get £1 off using the discount code PONG. Click here to visit the Raspberry Pi Press online store to secure your copy, and read on to see how you can use ultrasonic sensors to turn this classic game into something a lot more physical.

    Over to the HackSpace magazine team…

    Code the Classics is an entertaining book for a whole bunch of reasons, but one aspect of it that is particularly exciting to us makers is that it means there are some games out there that are really fun to play, but also written to be easy to understand and have high-quality game art to go along with them. Why does this excite us as makers? Because it makes them ideal candidates for testing out novel DIY games controllers!

    Pong

    We’re going to start right at the beginning of the book (and also at the beginning of computer game history) with the game Pong. There’s a great chapter on this seminal game in the book, but we’ll dive straight into the source code of our Boing! tribute game. This code should run on any computer with Python 3 (and a few dependencies) installed, but we’ll use a Raspberry Pi, as this has GPIO pins that we can use to add on our extra controller.

    Download the code here by clicking the ‘Clone or download’ button, and then ‘Download ZIP’. Unzip the downloaded file, and you should have a directory called Code‑The‑Classics-master, and inside this, a directory called boing-master.

    Open a terminal and navigate to this directory, then run:

    python3 boing.py

    If everything works well, you’ll get a screen asking you to select one or two players – press SPACE to confirm your selection, and have a play.

    Hacking Code the Classics

    So that’s how Eben Upton designed the game to be played. Let’s put our own spin on it. Games controllers are basically just sensors that take input from the real world in some way and translate that into in-game actions. Most commonly, these sensors are buttons that you press, but there’s no need for that to be the case. You can use almost any sensor you can get input from – it sounds trite, but the main limitation really is your imagination!

    We were playing with ultrasonic distance sensors in the last issue of HackSpace magazine, and this sprung to mind a Pong controller. After all, distance sensors measure in one dimension and Pong bats travel in one dimension.

    Last issue we learned that the main challenge when using the cheap HC-SR04 sensors with 3.3V devices is that they use 5V, so we need to reduce their output to 3.3V. A simple voltage divider does the trick, and we used three 330Ω resistors to achieve this – see Figure 1 for more details.

    There’s support for these sensors in the GPIO Zero Python library. As a simple test, you can obtain the distance with the following Python code:

    import gpiozero import time sensor = gpiozero.DistanceSensor(echo=15,trigger=14) while True: print(sensor.distance) time.sleep(0.1)

    That will give you a constant read-out of the distance between the ultrasonic sensor and whatever object is in front of it. If you wave your hand around in front of the sensor, you’ll see the numbers changing from 0 to 1, which is the distance in metres.

    So far, so straightforward. We only need to add a few bits to the code of our Boing! game to make it interact with the sensor. You can download an updated version of Boing! here, but the changes are as follows.

    Add this line to the import statements at the top:

    import gpiozero

    Add this line to instantiate the distance sensor object at the end of the file (just before pgzrun.go()):

    p1_distance = DistanceSensor(echo=15,trigger=14,queue_len=5)

    We added the queue_len parameter to get the distances through a little quicker.

    Finally, overwrite the p1_controls function with the following:

    def p1_controls(): move = 0 distance = p1_distance.distance print(distance) if distance < 0.1: move = PLAYER_SPEED elif distance > 0.2: move = -PLAYER_SPEED return move

    This uses the rather arbitrary settings of 10 cm and 20 cm to define whether the paddle moves up or down. You can adjust these as required.

    That’s all there is to our ultrasonic Pong. It’s great fun to play, but there are, no doubt, loads of other versions of this classic game you can make by adding different sensors. Why not see what you can come up with?

    Code the Classics

    Today is the last day to get £1 off Code the Classics with the promo code PONG, so visit the Raspberry Pi Press online store to order your discounted copy before 11:59pm GMT tonight.

    You can also download Code the Classics as a free PDF here, but the book, oh, the book – it’s a marvellous publication that deserves a physical presence in your home.

    Website: LINK

  • OpenAstroTracker is a tracking and GoTo mount for DSLR astrophotography

    OpenAstroTracker is a tracking and GoTo mount for DSLR astrophotography

    Reading Time: 2 minutes

    OpenAstroTracker is a tracking and GoTo mount for DSLR astrophotography

    Arduino TeamFebruary 26th, 2020

    Stars appear to stand still, but wait a few minutes and they won’t be in quite the same place. This means that if you want to take a long-exposure image of the sky with your DSLR you’ll have to either embrace the streaks, or use tracking hardware to compensate for this movement. Naturally, this specialized equipment can be quite expensive, but a seen here, you can now make your own 3D-printed OpenAstroTracker controlled by an Arduino Uno.

    The device features a 16×2 LED display/keypad shield, along with an optional Bluetooth module for interface. When set up, it slowly rotates the camera to compensate for star movements via two steppers on a gimbal assembly. 

    Print files for the OpenAstroTracker are available on Thingiverse and code can be found on GitHub if you’d like to examine the design or even build your own. Its creator also plans to sell it as a DIY kit — and you can sign up to be notified when it’s available.

    [youtube https://www.youtube.com/watch?v=cEigJ27LQq8?feature=oembed&w=500&h=281]

    Website: LINK

  • Win a Raspberry Pi Desktop kit SIGNED by Eben Upton!

    Win a Raspberry Pi Desktop kit SIGNED by Eben Upton!

    Reading Time: < 1 minute

    Subscribe

  • Resys is an LED drawer system that makes it easy to find your resistors

    Resys is an LED drawer system that makes it easy to find your resistors

    Reading Time: < 1 minute

    Resys is an LED drawer system that makes it easy to find your resistors

    Arduino TeamFebruary 25th, 2020

    You’ve got your design ready to go, you know you have the right components… but where exactly did you place that particular resistor? With the Resys drawer system by Lynlimer, you no longer have to wonder — just type in the needed value and the proper drawer lights up automatically.

    The device is based on an Arduino Nano, with an LCD display for text output and a numeric keypad for value entry. The proper drawers are lit via WS2812B addressable LEDs, held in 3D-printed holders. 

    It’s a clever project that could be expanded to well beyond the 16 drawers now used. Code, STLs, and circuit diagrams are available in Lynlimer’s write-up if you want to make your own!

    Website: LINK

  • Create Boing!, our Python tribute to Pong

    Create Boing!, our Python tribute to Pong

    Reading Time: 7 minutes

    Following on from yesterday’s introduction to Pong, we’re sharing Boing!, the Python-based tribute to Pong created by Eben Upton exclusively for Code the Classics. Read on to get a detailed look at the code for Boing!

    You can find the download link for the Boing! code in the Code the Classics book, available now in a variety of formats. Be sure to stick with today’s blog post until the end, for a special Code the Classics offer.

    From Pong to Boing!

    To show how a game like Pong can be coded, we’ve created Boing! using Pygame Zero, a beginner-friendly tool for making games in Python. It’s a good starting point for learning how games work – it takes place on a single screen without any scrolling, there are only three moving objects in the game (two bats and a ball), and the artificial intelligence for the computer player can be very simple – or even non-existent, if you’re happy for the game to be multiplayer only. In this case, we have both single-player and two-player modes.

    The code can be divided into three parts. First, there’s the initial startup code. We import from other Python modules so we can use their code from ours. Then we check to make sure that the player has sufficiently up-to-date versions of Python and Pygame Zero. We set the WIDTH and HEIGHT variables, which are used by Pygame Zero when creating the game window. We also create two small helper functions which are used by the code.

    The next section is the largest. We create four classes: Impact, Ball, Bat, and Game. The first three classes inherit from Pygame Zero’s Actor class, which amongst other things keeps track of an object’s location in the game world, and takes care of loading and displaying sprites. Bat and Ball define the behaviour of the corresponding objects in the game, while Impact is used for an animation which is displayed briefly whenever the ball bounces off something. The Game class’s job is to create and keep track of the key game objects, such as the two bats and the ball.

    Further down, we find the update and draw functions. Pygame Zero calls these each frame, and aims to maintain a frame rate of 60 frames per second. Gameplay logic, such as updating the position of an object or working out if a point has been scored, should go in update, while in draw we tell each of the Actor objects to draw itself, as well as displaying backgrounds, text, and suchlike.

    Our update and draw functions make use of two global variables: state and game. At any given moment, the game can be in one of three states: the main menu, playing the game, or the game-over screen. The update and draw functions read the state variable and run only the code relevant to the current state. So if state is currently State.MENU, for example, update checks to see if the SPACE bar or the up/down arrows are pressed and updates the menu accordingly, and draw displays the menu on the screen. The technical term for this kind of system is ‘finite state machine’.

    The Game class’s job is to create and keep track of the key game objects

    The game variable references an instance of the Game class as described above. The __init__ (constructor) method of Game optionally receives a parameter named controls. When we create a new Game object for the main menu, we don’t provide this parameter and so the game will therefore run in attract mode – in other words, while you’re on the main menu, you’ll see two computer-controlled players playing against each other in the background. When the player chooses to start a new game, we replace the existing Game instance with a new one, initialising it with information about the controls to be used for each player – if the controls for the second player are not specified, this indicates that the player has chosen a single-player game, so the second will be computer-controlled.

    Two types of movement

    In Boing!, the Bat and Ball classes inherit from Pygame Zero’s Actor class, which provides a number of ways to specify an object’s position. In this game, as well as games in later chapters, we’re setting positions using the x and y attributes, which by default specify where the centre of the sprite will be on the screen. Of course, we can’t just set an object’s position at the start and be done with it – if we want it to move as the game progresses, we need to update its position each frame. In the case of a Bat, movement is very simple. Each frame, we check to see if the relevant player (which could be a human or the computer) wants to move – if they do, we either subtract or add 4 from the bat’s Y coordinate, depending on whether they want to move up or down. We also ensure that the bat does not go off the top or bottom of the screen. So, not only are we only moving along a single axis, our Y coordinate will always be an integer (i.e. a whole number). For many games, this kind of simple movement is sufficient. Even in games where an object can move along both the X and Y axes, we can often think of the movement along each axis as being separate. For example, in the next chapter’s game, Cavern, the player might be pressing the right arrow key and therefore moving along the X axis at 4 pixels per frame, while also moving along the Y axis at 10 pixels per frame due to gravity. The movement along each axis is independent of the other.

    Able to move at any angle, the ball needs to move at the same speed regardless of its direction

    For the Ball, things get a bit more complicated. Not only can it move at any angle, it also needs to move at the same speed regardless of its direction. Imagine the ball moving at one pixel per frame to the right. Now imagine trying to make it move at a 45° angle from that by making it move one pixel right and one pixel up per frame. That’s a longer distance, so it would be moving faster overall. That’s not great, and that’s before we’ve even started to think about movement in any possible direction.

    The solution is to make use of vector mathematics and trigonometry. In the context of a 2D game, a vector is simply a pair of numbers: X and Y. There are many ways in which vectors can be used, but most commonly they represent positions or directions.

    You’ll notice that the Ball class has a pair of attributes, dx and dy. Together these form a vector representing the direction in which the ball is heading. If dx and dy are 1 and 0.5, then each time the ball moves, it’ll move by one pixel on the X axis and a half a pixel on the Y axis. What does it mean to move half a pixel? When a sprite is drawn, Pygame Zero will round its position to the nearest pixel. So the end result is that our sprite will move down the screen by one pixel every other frame, and one pixel to the right every frame (Figure 1).

    We still need to make sure that our object moves at a consistent speed regardless of its direction. What we need to do is ensure that our direction vector is always a ‘unit vector’ – a vector which represents a distance of one (in this case, one means one pixel, but in some games it will represent a different distance, such as one metre). Near the top of the code you’ll notice a function named normalised. This takes a pair of numbers representing a vector, uses Python’s math.hypot function to calculate the length of that vector, and then divides both the X and Y components of the vector by that length, resulting in a vector which points in the same direction but has a length of one (Figure 2).

    Vector maths is a big field, and we’ve only scratched the surface here. You can find many tutorials online, and we also recommend checking out the Vector2 class in Pygame (the library on top of which Pygame Zero is built).

    Try Boing!

    Update Raspbian to try Boing! and other Code the Classics games on your Raspberry Pi.

    The full BOING! tutorial, including challenges, further explanations, and a link to the downloadable code can be found in Code the Classics, the latest book from Raspberry Pi Press.

    We’re offering £1 off Code the Classics if you order it before midnight tomorrow from the Raspberry Pi Press online store. Visit the store now, or use the discount code PONG at checkout if you make a purchase before midnight tomorrow.

    As always, Code the Classics is available as a free PDF from the Wireframe website, but we highly recommend purchasing the physical book, as it’s rather lovely to look at and would make a great gift for any gaming and/or coding enthusiast.

    Website: LINK

  • WeatherMan

    WeatherMan

    Reading Time: 3 minutes

    Martin became enamoured of all things Raspberry Pi-flavoured in 2014. Looking for a one-box alternative to a PC for converted gadgets, he was tipped off by a reader that Raspberry Pi might work. He duly made a Raspberry Pi-powered VCR and Alexa Rotary Phone. Numerous ‘fruitful’ projects followed. There’s now a sizeable archive on Martin’s website.

    Discovering he enjoyed documenting projects as much as building them, he began specialising in giving new purpose to broken old tech – “especially items I remember being ‘the latest thing’ during the 1970s and 1980s when I was a child.”

    Helpfully, a Raspberry Pi Unicorn HAT is precisely the same size as the cassette player’s display window

    Weatherman: Walkman for weather

    Martin’s chance to ‘rescue’ one came when his mother-in-law sent him a broken old Hitachi player that she found during a clear-out.

    “I immediately fell in love with it,” Martin recalls. “It had a great retro look that drew me in”. On closer examination he realised the window in the cassette player’s door was – to the millimetre – the same size as a Raspberry Pi HAT. “At that point, all my other projects hit the back burner,” he says.

    “I’d been looking for a small case to hold a weather display for my desk for a while, and this was the perfect thing. I also had an unused Unicorn HAT HD lying around and this seemed like the ideal project for it.” To this he added servos and an awful lot of Sugru – a sort of malleable glue.

    “In the past I’ve used Lego and Meccano to put things together, but with space being so tight in the case, I used Sugru this time around. It’s very workable but sets hard like plastic, perfect for fixing components in the right place.”

    The WeatherMan currently relies on API data from the Dark Sky weather service, but Martin eventually hopes to link it up to a Raspberry Pi weather station. “With a Raspberry Pi at each end, it should hopefully be straightforward!” he says optimistically.

    The early 1980s-style ambient IoT weather display has a current conditions animation

    Getting the details right

    The main aim for what became the WeatherMan project was to keep the exterior as true as possible to the original. He wanted it to look like an ornamental piece sitting on his desk speaker, hiding a useful IoT (Internet of Things) device until it bursts into life.

    Martin thought the tape player seemed a bit naked without the iconic eighties headphones, so he looked for ways to incorporate them into the build. He drilled out the original jack plug and fittings and joined them together using a 2mm threaded rod. With a small nut on each end of the rod and a servo connector at the bottom, the headphones now respond whenever the weather is about to change. Their servo-controlled jiggling always makes Martin smile, even if it’s to alert him rain is on the way.

    Make your own WeatherMan

    Dismantle the cassette player to create as much space as you can inside. Retain any parts you want to reuse. You may need to trim down the case inside to make the components fit nicely.

    WeatherMan step 1

    You may need new bolts or a tiny magnet to make the cassette tape door close properly once you’ve tinkered inside. When you’re satisfied that it works well, hot-glue the cassette player case and door.

    WeatherMan step 2

    Use Raspbian Buster and adapted Python scripts to retrieve weather data from Dark Sky, display info on the Unicorn HAT, and (optionally) jiggle the headphones. Scripts and a ReadMe are on GitHub at magpi.cc/ghweatherman.

    WeatherMan step 3

  • Take control of your dashboard — the new Arduino IoT Cloud Dashboard with advanced features!

    Take control of your dashboard — the new Arduino IoT Cloud Dashboard with advanced features!

    Reading Time: 2 minutes

    Take control of your dashboard — the new Arduino IoT Cloud Dashboard with advanced features!

    Arduino TeamFebruary 24th, 2020

    The new dashboard for the Arduino IoT Cloud comes with a host of enhanced features. It allows you to gather and display data from multiple IoT devices in one dashboard, and control those devices as required through your dashboard to fully integrate your solution.

    Using widgets to connect to the properties enables you to set up a new dashboard in minutes, and you can fully customize your dashboard by: grouping devices however you like, dragging and dropping to rearrange the layout, and selecting from multiple options to visualize the data.

    It is now possible to import historical data into the dashboard to provide a backdated view for all your properties, hence creating a new dashboard  no longer means losing previous information. You can present the information in your dashboard as far back as you’ve been collecting the data.

    A new ‘duplicate dashboard’ function lets you copy any of your existing dashboards setup and layout, plus you can easily see which things are associated with which devices when setting up a new solution.

    [youtube https://www.youtube.com/watch?v=uMvu7mTc2QQ?feature=oembed&w=500&h=281]

    It really is that simple!

    Website: LINK

  • The History of Pong | Code the Classics

    The History of Pong | Code the Classics

    Reading Time: 7 minutes

    One topic explored in Code the Classics from Raspberry Pi Press is the origin story and success of Pong, one of the most prominent games in early video game history.

    ‘The success of Pong led to the creation of Pong home consoles (and numerous unofficial clones) that could be connected to a television. Versions have also appeared on many home computers.’

    Ask anyone to describe a game of table tennis and they’ll invariably tell you the same thing: the sport involves a table split into quarters, a net dividing the two halves, a couple of paddles, and a nice round ping-pong ball to bat back and forth between two players. Take a look at the 1972 video game Pong, however, and you’ll notice some differences. The table, for instance, is simply split in half and it’s viewed side-on, the paddles look like simple lines, and the ball is square. Yet no one – not even now – would have much trouble equating the two.

    Back in the early 1970s, this was literally as good as it got. The smattering of low-powered arcade machines of the time were incapable of realistic-looking graphics, so developers had to be creative, hoping imaginative gamers would fill the gaps and buy into whatever they were trying to achieve. It helped enormously that there was a huge appetite for the new, emerging video game industry at that time. Nolan Bushnell was certainly hungry for more – and had he turned his nose up at Spacewar!, a space combat game created by Steve Russell in 1962, then Pong would never even have come about.

    “The most important game I played was Spacewar! on a PDP-1 when I was in college,” he says, of the two-player space shooter that was popular among computer scientists and required a $120,000 machine to run. Although the visuals were nothing to write home about, the game was one of the first graphical video games ever made. It pitted two spaceships against each other and its popularity spread, in part, because the makers decided the code could be distributed freely to anyone who wanted it. “It was a great game, fun, challenging, but only playable on a very expensive computer late at night and the wee hours of the morning,” Nolan says. “In my opinion, it was a very important step.”

    Nolan was so taken by Spacewar! that he made a version of the game with a colleague, Ted Dabney. Released in 1971, Computer Space allowed gamers to control a rocket in a battle against flying saucers, with the aim being to get more hits than the enemy in a set period of time. To make it attractive to players, it was placed in a series of colourful, space-age, moulded arcade cabinets. Nolan and Ted sold 1500 of them; even though they made just $500 from the venture, it was enough to spur them into continuing. They came up with the idea for Pong and created a company called Atari.

    One of their best moves was employing engineer Al Alcorn, who had worked with Nolan at the American electronics company Ampex. Al was asked to create a table tennis game based on a similar title that had been released on the Magnavox Odyssey console, on the pretence that the game would be released by General Electric. In truth, Nolan simply wanted to work out Al’s potential, but he was blown away by what his employee came up with. Addictive and instantly recognisable, Atari realised Pong could be a major hit. The game’s familiarity with players meant it could be picked up and played by just about anyone.

    Even so, Nolan had a hard time convincing others. Manufacturers turned the company down, so he visited the manager of a bar called Andy Capp’s in Sunnyvale, California and asked them to take Pong for a week. The manager soon had to call Nolan to tell him the machine had broken: it had become stuffed full of quarters from gamers who loved the game. By 1973, production of the cabinet was in overdrive and 8000 were sold. It led to the creation of a Pong home console which sold more than 150,000 machines. People queued to get their hands on one and Atari was on its way to become a legendary games company.

    For Nolan, it was justification for his perseverance and belief. Suddenly, the man who had become interested in electronics at school, where he would spend time creating devices and connecting bulbs and batteries, was being talked of as a key player in the fledgling video game industry. But what did Nolan, Ted, Al, and the rest of the Atari team do to make the game so special? “We made it a good, solid, fun game to play,” says Nolan. “And we made it simple, easy, and quickly understood. Keeping things simple is more difficult to do than building something complex. You can’t dress up bad gameplay with good graphics.”

    Making Pong

    On the face of it, Pong didn’t look like much. Each side had a paddle that could be moved directly up and down using the controller, and the ball would be hit from one side to the other. The score was kept at the top of the screen and the idea was to force the opposing player to miss. It meant the game program needed to determine how the ball was hit and where the ball would go from that point. And that’s the crux of Pong’s success: the game encouraged people to keep playing and learning in the hope of attaining the skills to become a master.

    When creating Pong, then, the designers had a few things in mind. One of the most important parts of the game was the movement of the paddles. This involved a simple, vertical rectangle that went up and down. One of the benefits Atari had when it created Pong was that it controlled not just the software but the hardware too. By building the cabinet, it was able to determine how those paddles should be moved. “The most important thing if you want to get the gameplay right is to use a knob to move the paddle,” advises Nolan. “No one has done a good Pong using touchscreens or a joystick.”

    Look at a Pong cabinet close up – there are plenty of YouTube videos which show the game in action on the original machine – and you will see what Nolan means. You’ll notice that players turned a knob anticlockwise to move the paddle down, and clockwise to move it up. Far from being confusing, it felt intuitive.

    Movement of the ball

    With the paddles moving, Atari’s developers were able to look at the movement of the ball. At its most basic, if the ball continued to make contact with the paddles, it would constantly move back and forth. If it did not make contact, then it would continue moving in the direction it had embarked upon and leave the screen. At this stage, a new ball was introduced in the centre of the screen and the advantage was given to the player who had just chalked up a point. If you watch footage of the original Pong, you will see that the new ball was aimed at the player who had just let the ball go past. There was a chance he or she would miss again.

    To avoid defeat, players had to be quite nifty on the controls and stay alert. Watching the ball go back and forth at great speed could be quite mesmerising as it left a blurred trail across the cathode ray tube display. There was no need to waste computing power by animating the ball because the main attention was focused on what would happen when it collided with the paddle. It had to behave as you’d expect. “The game did not exist without collisions of the ball to the paddle,” says Nolan.

    Al realised that the ball needed to behave differently depending on where it hit the paddle. When playing a real game of tennis, if the ball hits the centre of the racket, it will behave differently from a ball that hits the edge. Certainly, the ball is not going to be travelling in a simple, straight path back and forth as you hit it; it is always likely to go off at an angle. This, though, is the trickiest part of making Pong “The ball should bounce up from an upper collision with more obtuse angles as the edge of the paddle is approached,” Nolan says. “This balances the risk of missing with the fact that an obtuse angle is harder to return.” This is what Pong is all about: making sure you hit the ball with the paddle, but in a manner that makes it difficult for the opposing player to return it. “A player wants the ball to be just out of reach for the opponent or be hard for him or her to predict.”

    Read on…

    This post is part of a much longer deep dive into the history of Pong in Code the Classics, our 224-page hardback book that not only tells the stories of some of the seminal video games of the 1970s and 1980s, but also shows you how to use Python and Pygame Zero to create your own games inspired by them, following examples programmed by Raspberry Pi founder Eben Upton.

    In conjunction with today’s blog post, we’re offering £1 off Code the Classics when you order your copy between now and midnight Wednesday 26 Feb 2020 from the Raspberry Pi Press online store. Simply follow this link or enter the discount code PONG at checkout to get your copy for only £11, with free shipping in the UK.

    Code the Classics is also available as a free download, although the physical book is rather delightful, so we really do recommend purchasing it.

    Website: LINK

  • Duel Disk System blends physical cards with a virtual playfield

    Duel Disk System blends physical cards with a virtual playfield

    Reading Time: < 1 minute

    Duel Disk System blends physical cards with a virtual playfield

    Arduino TeamFebruary 21st, 2020

    Yu-Gi-Oh! and other similar card games can be quite popular, but actually finding a group to play with can be challenging. Online games, on the other hand, have their advantages yet render your deck pretty much useless. As a way to combine these two worlds, Augusto Masetti has created a prototype Dual Disk System that will allow you to play with real cards in a virtual playfield.

    To play, participants attach NFC stickers inside a card sleeve, which are scanned by an NFC reader controlled by an Arduino Uno. The card ID is then compared to the YGOProDeck API database via a computer, giving players a tactile element to this virtual competition.

    Masetti’s project is still a work in progress, though we can’t wait to see the final version!

    Website: LINK

  • Room Guard: build a Raspberry Pi motion sensor alarm

    Room Guard: build a Raspberry Pi motion sensor alarm

    Reading Time: 6 minutes

    Room Guard: You’ll Need

    Why an Automation HAT?

    Many Raspberry Pi physical computing projects directly use the GPIO to connect things like sensors, buzzers, and LEDs. In this case, we’re going use the incredibly versatile Pimoroni Automation HAT. This ‘input expander’ allows us to control devices that would normally either be incompatible or even damage your Raspberry Pi. As a small buzzer may not be particularly deterring to a would-be room invader, we’ve chosen a 120dB siren that requires more current that our Raspberry Pi can safely handle. So, we will give the siren its own power supply and safely control it using one of the Automation HAT’s relays.

    A close-up of the PIR sensor’s potentiometers. Carefully adjust with a small screwdriver as they can be fragile

    Prepare your Raspberry Pi

    It’s up to you what model of Raspberry Pi you use for this project. A Raspberry Pi Zero W is more than capable of running the code and we originally prototyped our guard using one. If you’re thinking of getting clever, though, such as adding facial recognition using a camera, you might want to go for the horsepower of a Raspberry Pi 4. Either way, start by attaching the Automation HAT carefully to the GPIO header, and secure with the provided standoff posts on the opposite side to ensure the HAT doesn’t wiggle about and come loose.

    Set up the software

    We’re going to use Raspbian Buster Lite as the operating system as there’s no need for a user interface, just a basic command-line operating system. That said, there’s no harm in installing the full version if you’re more comfortable with that. Download the image from the Raspberry Pi website and flash to a microSD card. Now, as ever, it’s time to log in and update everything with sudo apt update && sudo apt upgrade. Once finished, run sudo raspi-config and set up networking (if using WiFi). Now, install the Automation HAT software by running the following command:

    curl https://get.pimoroni.com/automationhat | bash
    

    This will guide through setting up for driver software and examples. You may need to reboot your Raspberry Pi afterwards.

    Get sensitive

    The PIR sensor has three connectors: one for 5V power in (which can be provided by the HAT), ground, and in the centre is the data line. Operation is very simple. If the sensor is triggered by movement, the data line goes ‘high’ (outputs current). After a period of no movement, it goes low (no current). Its sensitivity can be controlled by adjusting one of the potentiometers (the left one when it’s turned upside down – see Figure 1). The other potentiometer sets the minimum time for which the sensor reports movement. We could connect the PIR directly to the GPIO, but as the HAT is now in the way, we’ll use its inputs instead.

    Figure 1. The PIR sensor’s potentiometers (orange). Adjust carefully with a small screwdriver, as they can be fragile

    Connect the sensor

    Although this type of PIR sensor is widely available, they do vary in wiring. In particular, the orientation of Vcc (power in) and ground can be different. The sensor we’ve recommended here has both clearly marked on the PCB. Connect the ground pin to any of the GND connectors on the Automation HAT, then connect any 5V power output to the 5V in pin on the sensor. So that we know what state the sensor is in, connect the data line to any one of the buffered inputs on the HAT. Carefully check each of the screw terminals for a solid connection.

    Test the Room Guard Automation HAT

    When you installed the software for the Automation HAT, examples and documentation were included. We can use these to quickly test and calibrate the sensor. From the command line, run the following:

    python3 ~/Pimoroni/automationhat/examples/input.py
    

    You will now be shown the reading from all the input sensors. Watch the one to which you connected the data line in the previous step. It should report a 1 when it is activated (motion has been detected) and 0 when it ‘times out’. You can carefully adjust the two potentiometers on the sensor to fine-tune the sensitivity and timings to your preferences. Press CTRL+C to stop the Python script when you’re done.

    This project works well with Raspberry Pi Zero if you’re keeping it simple

    Warning! This might get loud

    The siren is capable of an ear-splitting 120dB. Always wear ear defenders in case you accidentally set the siren off. This particular model is tolerant of voltages less than 12V and the volume reduces accordingly. We recommend starting no higher than 5V, which is still incredibly loud. The siren requires its own power supply, so you’ll need to source one (we recommend something with variable voltages so you can experiment with noise levels). Before continuing, make sure you’re happy with the siren’s noise levels. If you don’t want a loud siren, there are many buzzers and quieter alarms available that will work to demonstrate the project and will be much safer for younger makers to handle.

    Relay race

    Relays are magnetic switches, allowing one device to control another without their circuits ‘touching’. The Automation HAT comes with three relays and we’ll use one to switch the siren on and off. Making sure it’s unplugged, snip the siren’s positive line (red wire) and strip a bit of wire on both ends. Now, connect the part going to the power supply to one of the relays on the terminal marked ‘COM’ (common). Connect the other part of the red wire to the same relay on ‘NO’ (normally open). Double-check everything and make sure the wires are secure.

    Set up the roomguard.py Software

    We can now read an input and create an output using the relay. Using your favourite editor, enter the roomguard.py code here. This is a simple loop that will check the sensor twice a second to see if movement has been registered. If so, the relay is switched into place, allowing current to flow to the siren and it sounds. Once the sensor no longer registers movement, the relay is deactivated and it all goes quiet. If you don’t fancy typing it in, you can download all this code and a few extras from GitHub.

    To run the code, enter the following on the command line:

    python3 roomguard.py
    

    Try moving about!

    Now Add notifications

    We now have a working motion-detection alarm, but this is meant to be internet-connected, so let’s make it smarter. It would be useful to have a notification sent to a smartphone when the alarm is activated. There are a many different types of notification service, and adding support for most is possible using just one Python library, Apprise. Have a look at the code for roomguard_notify.py on GitHub for an example of how to add notifications. Also, check out Apprise’s documentation.

    Adding alert notifications allows you to keep on eye on things when you’re away, and you can add images too

    Add a camera

    Now the basics are working, you can augment the alarm with additional sensors and/or notifications. The Automation HAT has plenty of remaining inputs and outputs for you to play with. A simple step would be to add a Raspberry Pi Camera Module. See if you can change the code to take a photo of the intruder and then forward that image to your notification. Look at the GitHub repository for an example.

    There’s plenty of scope for adding more to the project, such as an inexpensive keypad or a camera

    Make it your own

    What else could you add? One aspect of an alarm not implemented is any kind of deactivation. Could you add a web server so you can control the alarm from your phone? How about using a keypad to set an activation code? There’s potential to add batteries and additional PIR sensors to create a standalone unit. Use facial recognition software to identify who was in your room. There’s lots of avenues to explore. Over to you.

  • Room Guard: build a Raspberry Pi motion sensor alarm

    Room Guard: build a Raspberry Pi motion sensor alarm

    Reading Time: 6 minutes

    Room Guard: You’ll Need

    Why an Automation HAT?

    Many Raspberry Pi physical computing projects directly use the GPIO to connect things like sensors, buzzers, and LEDs. In this case, we’re going use the incredibly versatile Pimoroni Automation HAT. This ‘input expander’ allows us to control devices that would normally either be incompatible or even damage your Raspberry Pi. As a small buzzer may not be particularly deterring to a would-be room invader, we’ve chosen a 120dB siren that requires more current that our Raspberry Pi can safely handle. So, we will give the siren its own power supply and safely control it using one of the Automation HAT’s relays.

    A close-up of the PIR sensor’s potentiometers. Carefully adjust with a small screwdriver as they can be fragile

    Prepare your Raspberry Pi

    It’s up to you what model of Raspberry Pi you use for this project. A Raspberry Pi Zero W is more than capable of running the code and we originally prototyped our guard using one. If you’re thinking of getting clever, though, such as adding facial recognition using a camera, you might want to go for the horsepower of a Raspberry Pi 4. Either way, start by attaching the Automation HAT carefully to the GPIO header, and secure with the provided standoff posts on the opposite side to ensure the HAT doesn’t wiggle about and come loose.

    Set up the software

    We’re going to use Raspbian Buster Lite as the operating system as there’s no need for a user interface, just a basic command-line operating system. That said, there’s no harm in installing the full version if you’re more comfortable with that. Download the image from the Raspberry Pi website and flash to a microSD card. Now, as ever, it’s time to log in and update everything with sudo apt update && sudo apt upgrade. Once finished, run sudo raspi-config and set up networking (if using WiFi). Now, install the Automation HAT software by running the following command:

    curl https://get.pimoroni.com/automationhat | bash
    

    This will guide through setting up for driver software and examples. You may need to reboot your Raspberry Pi afterwards.

    Get sensitive

    The PIR sensor has three connectors: one for 5V power in (which can be provided by the HAT), ground, and in the centre is the data line. Operation is very simple. If the sensor is triggered by movement, the data line goes ‘high’ (outputs current). After a period of no movement, it goes low (no current). Its sensitivity can be controlled by adjusting one of the potentiometers (the left one when it’s turned upside down – see Figure 1). The other potentiometer sets the minimum time for which the sensor reports movement. We could connect the PIR directly to the GPIO, but as the HAT is now in the way, we’ll use its inputs instead.

    Figure 1. The PIR sensor’s potentiometers (orange). Adjust carefully with a small screwdriver, as they can be fragile

    Connect the sensor

    Although this type of PIR sensor is widely available, they do vary in wiring. In particular, the orientation of Vcc (power in) and ground can be different. The sensor we’ve recommended here has both clearly marked on the PCB. Connect the ground pin to any of the GND connectors on the Automation HAT, then connect any 5V power output to the 5V in pin on the sensor. So that we know what state the sensor is in, connect the data line to any one of the buffered inputs on the HAT. Carefully check each of the screw terminals for a solid connection.

    Test the Room Guard Automation HAT

    When you installed the software for the Automation HAT, examples and documentation were included. We can use these to quickly test and calibrate the sensor. From the command line, run the following:

    python3 ~/Pimoroni/automationhat/examples/input.py
    

    You will now be shown the reading from all the input sensors. Watch the one to which you connected the data line in the previous step. It should report a 1 when it is activated (motion has been detected) and 0 when it ‘times out’. You can carefully adjust the two potentiometers on the sensor to fine-tune the sensitivity and timings to your preferences. Press CTRL+C to stop the Python script when you’re done.

    This project works well with Raspberry Pi Zero if you’re keeping it simple

    Warning! This might get loud

    The siren is capable of an ear-splitting 120dB. Always wear ear defenders in case you accidentally set the siren off. This particular model is tolerant of voltages less than 12V and the volume reduces accordingly. We recommend starting no higher than 5V, which is still incredibly loud. The siren requires its own power supply, so you’ll need to source one (we recommend something with variable voltages so you can experiment with noise levels). Before continuing, make sure you’re happy with the siren’s noise levels. If you don’t want a loud siren, there are many buzzers and quieter alarms available that will work to demonstrate the project and will be much safer for younger makers to handle.

    Relay race

    Relays are magnetic switches, allowing one device to control another without their circuits ‘touching’. The Automation HAT comes with three relays and we’ll use one to switch the siren on and off. Making sure it’s unplugged, snip the siren’s positive line (red wire) and strip a bit of wire on both ends. Now, connect the part going to the power supply to one of the relays on the terminal marked ‘COM’ (common). Connect the other part of the red wire to the same relay on ‘NO’ (normally open). Double-check everything and make sure the wires are secure.

    Set up the roomguard.py Software

    We can now read an input and create an output using the relay. Using your favourite editor, enter the roomguard.py code here. This is a simple loop that will check the sensor twice a second to see if movement has been registered. If so, the relay is switched into place, allowing current to flow to the siren and it sounds. Once the sensor no longer registers movement, the relay is deactivated and it all goes quiet. If you don’t fancy typing it in, you can download all this code and a few extras from GitHub.

    To run the code, enter the following on the command line:

    python3 roomguard.py
    

    Try moving about!

    Now Add notifications

    We now have a working motion-detection alarm, but this is meant to be internet-connected, so let’s make it smarter. It would be useful to have a notification sent to a smartphone when the alarm is activated. There are a many different types of notification service, and adding support for most is possible using just one Python library, Apprise. Have a look at the code for roomguard_notify.py on GitHub for an example of how to add notifications. Also, check out Apprise’s documentation.

    Adding alert notifications allows you to keep on eye on things when you’re away, and you can add images too

    Add a camera

    Now the basics are working, you can augment the alarm with additional sensors and/or notifications. The Automation HAT has plenty of remaining inputs and outputs for you to play with. A simple step would be to add a Raspberry Pi Camera Module. See if you can change the code to take a photo of the intruder and then forward that image to your notification. Look at the GitHub repository for an example.

    There’s plenty of scope for adding more to the project, such as an inexpensive keypad or a camera

    Make it your own

    What else could you add? One aspect of an alarm not implemented is any kind of deactivation. Could you add a web server so you can control the alarm from your phone? How about using a keypad to set an activation code? There’s potential to add batteries and additional PIR sensors to create a standalone unit. Use facial recognition software to identify who was in your room. There’s lots of avenues to explore. Over to you.

  • How to play sound and make noise with your Raspberry Pi

    How to play sound and make noise with your Raspberry Pi

    Reading Time: 9 minutes

    If your amazing project is a little too quiet, add high-fidelity sound with Raspberry Pi and the help of this handy guide from HackSpace magazine, written by PJ Evans.

    The PecanPi HAT features best-in-class components and dual DACs for superior audio reproduction

    It’s no surprise that we love microcontrollers at HackSpace magazine. Their versatility and simplicity make them a must for electronics projects. Although a dab hand at reading sensors or illuminating LEDs, Arduinos and their friends do struggle when it comes to high-quality audio. If you need to add music or speech to your project, it may be worth getting a Raspberry Pi computer to do the heavy lifting. We’re going to look at the various audio output options available for our favourite small computer, from a simple buzz, through to audiophile bliss.

    Get buzzing

    Need to keep it simple and under a pound?
    An active buzzer is what you need

    The simplest place to start is with the humble buzzer. A cheap active buzzer can be quickly added to Raspberry Pi’s GPIO. It’s surprisingly easy too. Try connecting a buzzer’s red wire (positive) to GPIO pin 22 (Broadcom numbering) and the black wire (ground) to any GND pin. Now, install the GPIO Zero Python library by typing this at the command line:

    sudo apt install python3-gpiozero

    Create a file called buzz.py in your favourite editor and enter the following:

    import time from gpiozero import Buzzer buzzer = Buzzer(22) buzzer.on() time.sleep(1) buzzer.off()

    Run it at the command line:

    python3 buzz.py

    You should hear a one-second buzz. See if you can make Morse code sounds by changing the duration of the sleep statement.

    Passive but not aggressive

    Raspberry Pi computers, with the exception of the Zero range, all have audio output on board. The original Raspberry Pi featured a stereo 3.5mm socket, and all A and B models since feature a four-pole socket that also includes composite video. This provides your cheapest route to getting audio from your Raspberry Pi computer.

    A low-cost passive speaker can be directly plugged in to provide sound, albeit probably quieter than you’d like. Of course, add an amplifier or active speaker and you have sound as loud as you like. This is the most direct way of adding sound to your project, but how to get the sound out?

    Need a simple solution? USB audio devices come in all shapes and sizes but are mostly plug-and-play

    Normally, the Raspbian operating system will recognise that an audio device has been connected and route audio through it. Sometimes, especially if you’ve connected an HDMI monitor with sound capability (e.g. an HDMI TV), sound will not come out of the correct device.

    To fix this, open up a terminal window and run sudo raspi-config. When the menu appears, go to Advanced Options and select Audio, then select the option to force the output through the audio jack. You may need to reboot Raspbian for all changes to take effect.

    Plug and playback

    A USB sound device is another simple choice for audio playback on Raspberry Pi. Literally hundreds are available, and a basic input/output device with better audio quality than the on-board system can be purchased for a few pounds online. Installation tends to be no more complicated than plugging the device into the USB port. You may need to select the new output, as the underlying audio system, ALSA (see the ALSA and PulseAudio section for more), may mute it by default. To fix this, run alsamixer from the command line, press F6 to select the new sound device, and if you see ‘MM’ at the bottom of the volume indicator, press M to unmute and adjust the volume with the cursor keys.

    Many DACs also come with on-board amplifiers. Perfect for passive speakers

    Unsurprisingly, when choosing your USB sound device, you can start at a few pounds and go right up to professional equipment costing hundreds. As they are low-power, USB devices do not tend to feature amplification, unless they have a separate power source.

    Let’s play

    The simplest way to play audio on Raspbian is to use OMXPlayer. This is a dedicated hardware-accelerated command-line tool that takes full advantage of Raspberry Pi’s capabilities. It sends audio to the analogue audio jack by default, so playing back an MP3 file is as simple as running:

    omxplayer /path/to/audio/file.wav

    There are many command-line options that allow you to control how the audio is played. Want the audio to loop forever? Just add --loop to the command. You’ll notice that when it’s running, OMXPlayer provides a user interface of sorts, allowing you to control playback from within the terminal. If you’d just like it to run in the background without user input, run the command like this:

    omxplayer --no-keys example.wav &

    Here, —-no-keys removes the interface, and the ampersand (&) tells the operating system to run the job ‘in the background’ so that it won’t block anything else you want to do.

    OMXPlayer is a great choice for Raspbian, but other players such as mpg321 are available, so find the tool that’s best for you.

    Another useful utility is speaker-test. This can produce white noise or vocal confirmation so you can check your speakers are working properly. It’s as simple as this:

    speaker-test -t wav -c 2

    The first parameter sets the sound to be a voice, and the -c tests stereo channels only: front left and front right.

    Phat Beats

    If space is an issue, a Raspberry Pi 4, amplifier, and speaker may not be what you have in mind. After all, your cool wearable project is going to be problematic if you’re trailing an amplifier on a cart with a 50-metre extension lead powering everything. Luckily, the clever people at Pimoroni have you covered. The Speaker pHAT is a Raspberry Pi Zero-sized HAT that not only adds audio capability to the smallest of the Raspberry Pi family, but also sports a 3 W speaker. Now you can play any audio with a tiny device and a USB battery pack.

    Small, cheap, and fun, the Speaker pHat features a 3 W speaker and LED VU meter

    The installation process is fully automated, so no messing around with drivers and config files. Once the script has completed, you can run any audio tool as before, and the sound will be routed through the speaker. No, the maximum volume won’t be troubling any heavy metal concerts, but you can’t knock the convenience and form factor.

    Playing the blues

    An easy way to get superior audio quality using a Raspberry Pi computer is Bluetooth. Recent models such as the 3B, 4, and even the Zero W support Bluetooth devices, and can be paired with most Bluetooth speakers, even from the command line. Once connected, you have a range of options on size and output power, plus the advantage of wireless connectivity.

    Setting up a Bluetooth connection, especially if you are using the command line, can be a little challenging (see the Bluetooth cheatsheet section). There is a succinct guide here: hsmag.cc/N6p2IB. If you are using Raspbian Desktop, it’s a lot easier. Simply click on the Bluetooth logo on the top-right, and follow the instructions to pair your device.

    If you find OMXPlayer isn’t outputting any audio, try installing mpg321:

    sudo apt install mpg321

    And try again:

    mpg321 /path/to/audio/file.mp3

    But seriously

    If your project needs good audio, and the standard 3.5 mm output just isn’t cutting it, then it’s time to look at the wide range of DACs (digital-to-analogue converters) available in HAT format. It’s a crowded market, and the prices vary significantly depending on what you want from your device. Let’s start at the lower end, with major player HiFiBerry’s DAC+ Zero. This tiny HAT adds 192kHz/24-bit playback via two RCA phono ports for £12.50. If you’re serious about your audio, then you can consider the firm’s full HAT format high-resolution DAC+ Pro for £36, or really go for it with the DSP (digital sound processing) version for £67. All of these will require amplification, but the sound quality will rival audio components of a much higher price.

    Money no object? The Allo Katana is a monster DAC, and weighs in at £240, but outperforms £1000 equivalents

    If money is no object and your project requires the best possible reproduction, then you can consider going full audiophile. There are some amazing high-end HATs out there, but one of the best-performing ones we’ve seen is the PecanPi DAC. Its creator Leonid Ayzenshtat sourced each individual component carefully, always choosing the best-in-class. He even used a separate DAC for each audio channel. The resulting board may make your wallet wince at around £200 for the bare board, but the resulting audio is good enough to be used in professional recording studios. If you’ve restored a gorgeous old radio back to showroom condition, you could do a lot worse than add the board in with a great amp and speaker.

    ALSA and PulseAudio

    There’s often confusion between these two systems. Raspbian comes pre-installed with ALSA (Advanced Linux Sound Architecture), which is the low-level software that makes sound work. It comes with a range of utilities to control output device, volume, and more. PulseAudio is a software layer that sits on top of ALSA to provide more features, including streaming capabilities. Chances are, if you need to do something a bit more clever than just play audio, you’ll need to install a PulseAudio server.

    Bluetooth cheatsheet

    If you want to pair a Bluetooth audio device (A2DP) on the command line, it can be a little hairy. Here’s a quick guide:

    First-time installation:

    sudo apt-get install pulseaudio pulseaudio-module-bluetooth sudo usermod -G bluetooth -a pi sudo reboot

    Start the PulseAudio server:

    pulseaudio --start

    Run the Bluetooth utility:

    bluetoothctl

    Put your speaker into pairing mode. Now, within the utility, run the following commands (pressing Enter after each one):

    power on agent on scan on

    Now wait for the list to populate. When you see your device…
    pair <dev>
    Where <dev> is the displayed long identifier for your device. You can just type in the first few characters and press Tab to auto-complete. Do the same for the following steps.

    trust <dev> connect <dev>

    Wait for the confirmation, then enter:

    quit <dev>

    Now try to play some audio using aplay (for WAV files) or mpg321 (for mp3). These instructions are adapted from the guide by Actuino at hsmag.cc/N6p2IB.

    File types

    There are command-line players available for just about every audio format in common use. Generally, MP3 provides the best balance of quality and space, but lower bit-rates result in lower sound quality. WAV is completely uncompressed, but can eat up your SSD card. If you don’t want to compromise on audio quality, try FLAC, which is identical in quality to WAV, but much smaller. To convert between audio types, consider installing FFmpeg, a powerful audio and video processing tool.

    HackSpace magazine

    This article comes direct from HackSpace magazine issue 28, out now and available in print from your local newsagent, the Raspberry Pi Store in Cambridge, and online from Raspberry Pi Press.

    If you love HackSpace magazine as much as we do, why not have a look at the subscription offers available, including the 12-month deal that comes with a free Adafruit Circuit Playground! Subscribers in the USA can now get a 12-month subscription for $60 when joining by the end of March!

    And, as always, you can download the free PDF from the Raspberry Pi Press website.

    Website: LINK

  • Audio radar – accessible radar tech

    Audio radar – accessible radar tech

    Reading Time: 2 minutes

    “The radar introduces the user in an easy and accessible way to electronics, [as well as] embedded systems and how radar detects return signals and performs filtering to measure radial velocity and distance to objects,” he explains.

    The radar is based on a Raspberry Pi 3B which hosts a web server to enter the parameters needed by the radar to operate. “The web server can be accessed by connecting to the ‘RadarPi’ WiFi and starts to broadcast upon power-up,” says Dewan. “It is also used to display the results obtained after the radar was operated.”

    What’s in a wavelength

    Normal radar uses radio waves (it was originally an acronym for RAdio Detection And Ranging); however, this version employs 8 to 12kHz of noise to measure distance – using the reflection time of the sound – and velocity, by making use of the Doppler effect. Parameters can be modified on a webpage generated by Raspberry Pi, allowing students to see how different settings change the results.

    Distance is calculated by measuring the time between the sound being emitted and then received after reflection

    “The radar proved to be a minor success in measurement of velocity, [although] with not the desired resolution and clarity due to the automatic gain of the microphone,” reveals Dewan. The automatic gain of the microphone automatically adjusts the received signals so that the signal never clips on the voltage range. When the velocity of a car is being measured, the microphone is overwhelmed by the road noise and the resulting plot is a quite faint line representing the velocity of the vehicle.

    “For distance measurement, the radar proved to be a major success,” he adds, “with the only downside being the resolution of the plot. When an object was measured at a set distance, the results would display the range ±10%. However, the known distance was always in the middle of the range and therefore a successful measurement. The reasons for the variation in distance was not investigated due to a time constraint, but initial tests proved that the automatic gain might be to blame.”

    Accessible radar

    A microphone listens for the reflected audio so calculations can be made

    Dewan’s system continues a long-running theme of projects involving radar, with this iteration trying to make it as open, affordable, and accessible as possible – which is why a Raspberry Pi was involved: “Raspberry Pi offered built-in wireless LAN and sufficient RAM capacity to host a web server,” says Dewan. “Other embedded systems, such as the STM32F04, were also considered, as a lot of previous work was done on this and the on-board analogue-to-digital (ADC) was also attractive. The STM and other Arduino-based systems had insufficient storage and RAM capacity, and therefore Raspberry Pi offered a superior solution.”

  • Audio radar – accessible radar tech

    Audio radar – accessible radar tech

    Reading Time: 2 minutes

    “The radar introduces the user in an easy and accessible way to electronics, [as well as] embedded systems and how radar detects return signals and performs filtering to measure radial velocity and distance to objects,” he explains.

    The radar is based on a Raspberry Pi 3B which hosts a web server to enter the parameters needed by the radar to operate. “The web server can be accessed by connecting to the ‘RadarPi’ WiFi and starts to broadcast upon power-up,” says Dewan. “It is also used to display the results obtained after the radar was operated.”

    What’s in a wavelength

    Normal radar uses radio waves (it was originally an acronym for RAdio Detection And Ranging); however, this version employs 8 to 12kHz of noise to measure distance – using the reflection time of the sound – and velocity, by making use of the Doppler effect. Parameters can be modified on a webpage generated by Raspberry Pi, allowing students to see how different settings change the results.

    Distance is calculated by measuring the time between the sound being emitted and then received after reflection

    “The radar proved to be a minor success in measurement of velocity, [although] with not the desired resolution and clarity due to the automatic gain of the microphone,” reveals Dewan. The automatic gain of the microphone automatically adjusts the received signals so that the signal never clips on the voltage range. When the velocity of a car is being measured, the microphone is overwhelmed by the road noise and the resulting plot is a quite faint line representing the velocity of the vehicle.

    “For distance measurement, the radar proved to be a major success,” he adds, “with the only downside being the resolution of the plot. When an object was measured at a set distance, the results would display the range ±10%. However, the known distance was always in the middle of the range and therefore a successful measurement. The reasons for the variation in distance was not investigated due to a time constraint, but initial tests proved that the automatic gain might be to blame.”

    Accessible radar

    A microphone listens for the reflected audio so calculations can be made

    Dewan’s system continues a long-running theme of projects involving radar, with this iteration trying to make it as open, affordable, and accessible as possible – which is why a Raspberry Pi was involved: “Raspberry Pi offered built-in wireless LAN and sufficient RAM capacity to host a web server,” says Dewan. “Other embedded systems, such as the STM32F04, were also considered, as a lot of previous work was done on this and the on-board analogue-to-digital (ADC) was also attractive. The STM and other Arduino-based systems had insufficient storage and RAM capacity, and therefore Raspberry Pi offered a superior solution.”

  • Build a Raspberry Pi Zero W Amazon price tracker

    Build a Raspberry Pi Zero W Amazon price tracker

    Reading Time: 2 minutes

    Have you ever missed out on a great deal on Amazon because you were completely unaware it existed? Are you interested in a specific item but waiting for it to go on sale? Here’s help: Devscover’s latest video shows you how to create an Amazon price tracker using Raspberry Pi Zero W and Python.

    Build An Amazon Price Tracker With Python

    Wayne from Devscover shows you how to code a Amazon Price Tracker with Python! Get started with your first Python project. Land a job at a big firm like Google, Facebook, Twitter or even the less well known but equally exciting big retail organisations or Government with Devscover tutorials and tips.

    By following their video tutorial, you can set up a notification system on Raspberry Pi Zero W that emails you every time your chosen item’s price drops. Very nice.

    Devscover’s tutorial is so detailed that it seems a waste to try and summarise it here. So instead, why not make yourself a cup of tea and sit down with the video? It’s worth the time investment: if you follow the instructions, you’ll end up with a great piece of tech that’ll save you money!

    Remember, if you like what you see, subscribe to the Devscover YouTube channel and give them a thumbs-up for making wonderful Raspberry Pi content!

    Website: LINK

  • This SpaceX fan created a levitating Starship lamp

    This SpaceX fan created a levitating Starship lamp

    Reading Time: < 1 minute

    This SpaceX fan created a levitating Starship lamp

    Arduino TeamFebruary 18th, 2020

    Although you might not be able to build or house your own SpaceX Starship, YouTuber “Embrace Racing” has created a levitating lamp model that will be much more attainable for non-multi-billionaires. 

    The lamp’s landing pad features an Arduino Nano inside, which is used with WS2812 LEDs to simulate the smoke plume of the rocket through a 3D-printed “clear” PLA diffuser.

    The base also contains a levitating module capable of supporting up to 400g to suspend the spacecraft in midair. While its height would tend to make it unstable, the onboard levitating magnet lowers the center of gravity, along with a battery and three LEDS that provide light from the bottom of the rocket itself. 

    Print files and other project info are available on Thingiverse.

    Website: LINK

  • AAScan is an open source, Arduino-powered 3D scanner that uses your phone

    AAScan is an open source, Arduino-powered 3D scanner that uses your phone

    Reading Time: < 1 minute

    AAScan is an open source, Arduino-powered 3D scanner that uses your phone

    Arduino TeamFebruary 18th, 2020

    3D scanners are amazing tools that literally let you turn everyday things into three-dimensional computer models. As seen on Reddit, if you want to make one yourself — using little more than a spare Android phone, Arduino, stepper motor, and 3D-printed parts — the AAScan by QLRO could be an excellent option.

    The device spins an object on a 3D-printed turntable using an Uno and ULN2003 driver board, allowing it to take ~180 images automatically via a Python script running on the phone. These images are then combined in Meshroom to create a brand new 3D model. 

    You can check out a demo of AAScan in the video below, rotating an apple to take pictures of each side.

    Website: LINK

  • Build a Raspberry Pi laser scanner

    Build a Raspberry Pi laser scanner

    Reading Time: 2 minutes

    You really don’t need anything too fancy to build this Raspberry Pi laser scanner, and that’s why we think it’s pretty wonderful.

    Rasperry Pi 3D Laser Scanner

    Cornell University: ECE 5725 Michael Xiao and Thomas Scavella

    Building a Raspberry Pi laser scanner

    The ingredients you’ll need to build the laser scanner are:

    • Raspberry Pi
    • Raspberry Pi Camera Module v2
    • Stepper motor and driver
    • Line laser
    • Various LEDs, resistors, and wires
    • Button

    To complete the build, access to a 3D printer and laser cutter would come in handy. If you don’t have access to such tools, we trust you to think of an alternative housing for the scanner. You’re a maker, you’re imaginative — it’s what you do.

    How does the laser scanner work?

    The line laser projects a line an object, highlighting a slice of it. The Raspberry Pi Camera Module captures this slice, recording the shape of the laser line on the object’s surface. Then the stepper motor rotates the object. When the object has completed a full rotation and the camera has taken an image of every slice, the Raspberry Pi processes all the images to create one virtual 3D object.

    Instructables user mfx2 has written a wonderful tutorial for the project, which also includes all files needed to build and program your own version.

    Website: LINK

  • 3D-printable Raspberry Pi bits and pieces you should totally make

    3D-printable Raspberry Pi bits and pieces you should totally make

    Reading Time: 2 minutes

    Recently, we’ve seen an awful lot of new designs online for 3D-printable Raspberry Pi cases and add-ons. Here are a few that definitely need your attention.

    Turbine RGB Lamp

    Described as “a Turbine-fin Lamp with some RGB Neopixels in the middle,” this print from Thingiverse user kryptn would be a rather lovely addition to any desk or bedside table.

    NASs…NASi?

    These two lovely network-attached storage (NAS) prints will allow you to store your files via your network…it’s all in the name.

    While araymbox’s PiNAS takes a more traditional approach to the NAS aesthetic, harrytheb’s UFO NAS casing is a little out of this world.

    Tiny Raspberry Pi Zero Case with Antenna

    The internet is crowded with Raspberry Pi cases you can print, but few are as eye-catching at this Raspberry Pi Zero case by jwillmer.

    IKEA Skadis Shelf

    The IKEA Skadis system is becoming more and more popular in workshops, studies, and craft rooms. So why not print this perfectly-sized shelf to fit your Raspberry Pi and official Raspberry Pi case into the system as well?

    Raspberry Pi 4 cooling stand

    Is this cheating? You can use this file to 3D-print your own version of the Raspberry Pi 4 cooling stand that we’re currently giving away for free on the front of The MagPi magazine.

    Share your own

    If you’ve designed any 3D-printable Raspberry Pi accessories, share them with us in the comments below!

    Bonus content

    3D PRINTING INFILL PATTERNS – What, why, and why not! || HackSpace magazine

    There’s more than one option when it comes to selecting infill patters for your 3D prints. But what are the differences, and why should you use one over the …

    Website: LINK

  • A DIY digital readout for your wood lathe

    A DIY digital readout for your wood lathe

    Reading Time: < 1 minute

    A DIY digital readout for your wood lathe

    Arduino TeamFebruary 15th, 2020

    Small wood lathes don’t typically come with an RPM readout, so after obtaining such a machine several months ago, engineer Zach — also known as ‘byte sized’ — decided to build his own custom display.

    The device uses a Nano for control, along with a Hall effect sensor to pick up on four magnets attached to the spinning handwheel.

    RPM values are shown on a series of four 7-segment displays, and everything is enclosed in a nicely 3D-printed housing. LEDs shine through a sanded acrylic window that acts as a diffuser. Power for the lathe is still provided by a single cable, with a transformer module used to convert the AC input into 5V DC for the Arduino and other electronics.

    [youtube https://www.youtube.com/watch?v=7gDZs0bImr0?feature=oembed&w=500&h=281]

    Website: LINK