Raspberry Pi Blog

This is the official Raspberry Pi blog for news and updates from the Raspberry Pi Foundation, education initiatives, community projects and more!

Make a retro console with RetroPie and a Raspberry Pi — part 1

Discover classic gaming on the Raspberry Pi and play homebrew ROMs, with this two-part tutorial from The MagPi Editor Lucy Hattersley.

Raspberry Pi retro games console

Turning a Raspberry Pi device into a retro games console is a fun project, and it’s one of the first things many a new Pi owner turns their hand to.

The appeal is obvious. Retro games are fun, and from a programming perspective, they’re a lot easier to understand than modern 3D powerhouses. The Raspberry Pi board’s small form factor, low power usage, HDMI connection, and wireless networking make it a perfect micro-console that can sit under your television.

RetroPie

There are a bunch of different emulators around for Raspberry Pi. In this tutorial, we’re going to look at RetroPie.

RetroPie combines Raspbian, EmulationStation, and RetroArch into one handy image. With RetroPie you can emulate arcade games, as well as titles originally released on a host of 8-bit, 16-bit, and even 32- and 64-bit systems. You can hook up a joypad; we’re going to use the Wireless USB Game Controller, but most other USB game controllers will work.

You can also use Bluetooth to connect a controller from most video games consoles. RetroPie has an interface that will be very familiar to anyone who has used a modern games console, and because it is open-source, it is constantly being improved.

You can look online for classic games, but we prefer homebrew and modern releases coded for classic systems. In this tutorial, we will walk you through the process of setting up RetroPie, configuring a gamepad, and running a homebrew game called Blade Buster.

Get your microSD card ready

RetroPie is built on top of Raspbian (the operating system for Raspberry Pi). While it is possible to install RetroPie from the desktop interface, it’s far easier to format a microSD card† and copy a new RetroPie image to the blank card. This ensures all the settings are correct and makes setup much easier. Our favourite method of wiping microSD cards on a PC or Apple Mac is to use SD Memory Card Formatter.

Attach the microSD card to your Windows or Mac computer and open SD Card Formatter. Ensure the card is highlighted in the Select card section, then click Format.

Download RetroPie

Download the RetroPie image. It’ll be downloaded as a gzip file; the best way to expand this on Windows is using 7-Zip (7-zip.org).

With 7-Zip installed, right-click the retropie-4.4-rpi2_rpi3.img.gz file and choose 7-Zip > Extract here. Extract GZ files on a Mac or Linux PC using gunzip -k <filename.gz> (the -k option keeps the original GZ file).

gunzip -k retropie-4.4-rpi2_rpi3.img.gz

Flash the image

We’re going to use Etcher to copy the retropie-4.4-rpi2_rpi3.img file to our freshly formatted microSD card. Download Etcher. Open Etcher and click Select Image, then choose the retropie-4.4-rpi2_rpi3.img image file and click Open.

Etcher should have already located the microSD card; remove and replace it if you see a Select Drive button. Click Flash! to copy the RetroPie image to the microSD card.

See our guide for more information on how to use Etcher to flash SD cards.

Set up the Raspberry Pi

Insert the flashed microSD card to your Raspberry Pi. Now attach the Raspberry Pi to a TV or monitor using the HDMI cable. Connect the USB dongle from the Wireless USB Game Controller to the Raspberry Pi. Also attach a keyboard (you’ll need this for the setup process).

Insert the batteries in the Wireless USB Game Controller and set the power switch (on the back of the device) to On. Once everything is connected, attach a power supply to the Raspberry Pi.

See our quickstart guide for more detailed information on setting up a Raspberry Pi.

Configure the gamepad

When RetroPie starts, you should see Welcome screen displaying the message ‘1 gamepad detected’. Press and hold one of the buttons on the pad, and you will see the Configuring screen with a list of gamepad buttons and directions.

Tap the D-pad (the four-way directional control pad on the far left) up on the controller and ‘HAT 0 UP’ will appear. Now tap the D-pad down.
Map the A, B, X, Y buttons to:

A: red circle
B: blue cross
X: green triangle
Y: purple square

The Left and Right Shoulder buttons refer to the topmost buttons on the rear of the controller, while the Triggers are the larger lower buttons.

Push the left and right analogue sticks in for the Left and Right Thumbs. Click OK when you’re done.

Top tips from Lucy

Install Raspbian desktop

RetroPie is built on top of the Raspbian operating system. You might be tempted to install RetroPie on top of the Raspbian with Desktop interface, but it’s actually much easier to do it the other way around. Open RetroPie from EmulationStation and choose RetroPie setup. Select Configuration tools and Raspbian tools. Then choose Install Pixel desktop environment and Yes.

When it’s finished, choose Quit and Restart EmulationStation. When restarted, EmulationStation will display a Ports option. Select it and choose Desktop to boot into the Raspbian desktop interface.

Username and password

If RetroPie asks you for the username and password during boot, the defaults are pi and raspberry.

The MagPi magazine issue 81

The rest of this article can be found in the latest issue of The MagPi magazine, which is out now and can be purchased online, at the Raspberry Pi Store, or from many independent bookshops, such as WHSmith and Barnes & Noble. We’ll also post the second half on the blog tomorrow!

The MagPi magazine issue 81

You can also download issue 81 for free from The MagPi website, where you’ll find information on subscription options, and the complete MagPi catalogue, including Essentials guides and books, all available to download for free.

the MagPi subscription

7 Comments

Meet us at Maker Faire Bay Area 2019

We’ll be attending Maker Faire Bay Area this month and we’d love to see as many of you there as we can, so be sure to swing by the Raspberry Pi stand and say hi!

Our North America team will be on-hand and hands-on all weekend to show you the wonders of the Raspberry Pi, with some great tech experiments for you to try. Do you like outer space? Of course, why wouldn’t you? So come try out the Sense HAT, our multi-sensor add-on board that we created especially for our two Astro Pi units aboard the International Space Station!

We’ll also have stickers, leaflets, and a vast array of information to share about the Raspberry Pi, our clubs and programmes, and how you can get more involved in the Raspberry Pi community.

And that’s not all!

Onstage talks!

Matt Richardson, Executive Director of the Raspberry Pi Foundation North America and all-round incredible person, will be making an appearance on the Make: Electronics by Digi-Key stage at 3pm Saturday 18 May to talk about Making Art with Raspberry Pi.

Matt Richardson

Hi, Matt!

And I’m presenting too! On the Sunday, I’ll be on the DIY Content Creators Stage at 12:30pm with special guests Joel “3D Printing Nerd” Telling and Estefannie Explains it All for a live recording of my podcast to discuss the importance of community for makers and brands.

There will also be a whole host of incredible creations by makers from across the globe, and a wide variety of talks and presentations throughout the weekend. So if you’re a fan of creative contraptions and beastly builds, you’ll be blown away at this year’s Maker Faire.

Showcasing your projects

If you’re planning to attend Maker Faire to showcase your project, we want to hear from you. Leave a comment below with information on your build so we can come and find you on the day. Our trusty videographer Fiacre and I will be scouting for our next favourite Raspberry Pi make, and we’ll also have Andrew with us, who is eager to fill the pages of HackSpace magazine with any cool, creative wonders we find — Pi-related or otherwise!

Discounted tickets!

Maker Fair Bay Area 2019 will be running at the San Mateo County Event Center from Friday 17 to Sunday 19 May.

If you’re in the area and would like to attend Maker Fair Bay Area, make use of  our 15% community discount on tickets. Wooh!

For more information on Maker Faire, check out the Maker Faire website, or follow Maker Faire on Twitter.

See you there!

5 Comments

Portable retro CRT game console: the one-thumb entertainment system

OTES is the one-thumb entertainment system that, unsurprisingly, requires only one thumb to play.

One-Thumb Entertainment System

Uploaded by gocivici on 2019-04-29.

Retro handheld gaming

Straight out the bat, I have to admit that had this existed in the 80s, it would have been all I played with. OTES oozes gaming nostalgia, and the constant clicking would have driven my mother mad, as did the tap tap tap of my Game Boy or NES controller.

Designed to play PICO8 games, with its developers eager to see more people create one-button controlled games for the console, OTES replaces the concept of game cartridges with individual SD cards, allowing for players to swap out games as they would have with a Nintendo Game Boy, SEGA Game Gear, Atari Lynx, and other stand-alone cartridge consoles.

Building OTES

As mentioned, OTES uses the PICO-8 environment at its core and runs on a Raspberry Pi Zero W with interchangeable SD cards. And as the games designed for the project only require one button, it makes for a fairly simple setup.

For the body, the project’s maker, govinci, sources an old JVC video camera in order to cannibalise the CRT viewfinder.

The most important thing first. You have to find an old camcorder which has a CRT viewfinder. It’s usually easy to tell if a camcorder has a CRT viewfinder since it’s a bulky part sticking off the side of the camcorder. I found this viewfinder on an old JVC camcorder which I bought from the flea market. To test the viewfinder I used a 9v battery to power up the camcorder. There was no image on the viewfinder but I got a static white noise which is enough to tell if the viewfinder works.

The CRT viewfinder (that’s it to the right of the battery) was then connected to the Raspberry Pi and power source, and nestled snugly into a 3D-printed body.

Close the case up, turn on the Pi, and boom: one working, single-button console game player with a very personal point of view.

Govinci says:

Currently, It has one game called ODEF (Ocean Defender) developed by me and my friends. (You can play it here.) And I hope there will be many others as people develop games that can be played with only one button on this platform.

You heard the man: go get developing. (I can think of plenty of circumstances where only needing one free finger to fit in a spot of gaming would be really, really convenient.) You can make your own console by following the build diary at Instructables. Let us know if you give it a whirl!

6 Comments

Recreate iconic 1980s game explosions | Wireframe issue 12

Rik Cross, Senior Learning Manager here at the Raspberry Pi Foundation, shows you how to recreate the deadly explosions in the classic game, Bomberman.

An early incarnation of Bomberman on the NES; the series is still going strong today under Konami’s wing.

Creating Bomberman

Bomberman was first released in the early 1980s as a tech demo for a BASIC compiler, but soon became a popular series that’s still going today. Bomberman sees players use bombs to destroy enemies and uncover doors behind destructible tiles. In this article, I’ll show you how to recreate the bombs that explode in four directions, destroying parts of the level as well as any players in their path!

The game level is a tilemap stored as a two-dimensional array. Each tile in the map is a Tile object, which contains the tile type, and corresponding image. For simplicity, a tile can be set to one of five types; GROUND, WALL, BRICK, BOMB, or EXPLOSION. In this example code, BRICK and GROUND can be exploded with bombs, but WALL cannot, but of course, this behaviour can be changed.

Each Tile object also has a timer, which is decremented each frame of the game. When a tile’s timer reaches 0, an action is carried out, which is dependent on the tile type. BOMB tiles (and surrounding tiles) turn into EXPLOSION tiles after a short delay, and EXPLOSION tiles eventually turn back into GROUND. At the start of the game, the tilemap for the level is generated, in this case consisting of mostly GROUND, with some WALL and a couple of BRICK tiles. The player starts off in the top-left tile, and moves by using the arrow keys. Pressing the SPACE key will place a bomb in the player’s current tile, which is achieved by setting the Tile at the player’s position to BOMB. The tile’s timer is also set to a small number, and once this timer is decremented to 0, the bomb tile and the tiles around it are set to EXPLOSION.

Here’s Rik’s example code, which recreates Bomberman’s explosions in Python. To get it running on your system, you’ll first need to install Pygame Zero — you can find full instructions here. And you can download the code here.

The bomb explodes outwards in four directions, with a range determined by the RANGE, which in our code is 3. As the bomb explodes out to the right, for example, the tile to the right of the bomb is checked. If such a tile exists (i.e. the position isn’t out of the level bounds) and can be exploded, then the tile’s type is set to EXPLOSION and the next tile to the right is checked. If the explosion moves out of the level bounds, or hits a WALL tile, then the explosion will stop radiating in that direction. This process is then repeated for the other directions.

There’s a nice trick for exploding the bomb without repeating the code four times, and it relies on the sine and cosine values for the four direction angles. The angles are 0° (up), 90° (right), 180° (down) and 270° (left). When exploding to the right (at an angle of 90°), sin(90) is 1 and cos(90) is 0, which corresponds to the offset direction on the x- and y-axis respectively. These values can be multiplied by the tile offset, to explode the bomb in all four directions.

Get your copy of Wireframe issue 12

You can read the rest of the feature in Wireframe issue 12, available now at Tesco, WHSmith, and all good independent UK newsagents.

Or you can buy Wireframe directly from Raspberry Pi Press – delivery is available worldwide. And if you’d like a handy digital version of the magazine, you can also download issue 12 for free in PDF format.

Make sure to follow Wireframe on Twitter and Facebook for updates and exclusives. Subscribe on the Wireframe website to save up to 49% compared to newsstand pricing!

1 Comment

‘Gender Balance in Computing’ research project launch

I am excited to reveal that a consortium of partners has been awarded £2.4 million for a new research project to investigate how to engage more girls in computing, as part of our work with the National Centre for Computing Education. The award comes at a crucial time in computing education, after research by the University of Roehampton and the Royal Society recently found that only 20% of computing candidates for GCSE and 10% for A level Computer Science were girls.

The project will investigate ways to make computing more inclusive.

The project

‘Gender Balance in Computing’ is a collaboration between the consortium of the Raspberry Pi Foundation, STEM Learning, BCS, The Chartered Institute for IT, and the Behavioural Insights Team. Our partners, Apps for Good and WISE, will also be working on the project. Trials will run from 2019–2022 in Key Stages 1–4, and more than 15,000 students and 550 schools will be involved. It will be the largest national research effort to tackle this issue to date!

Our research around gender balance has many synergies with the work of the wider National Centre for Computing Education (NCCE) programme, which also focuses on pedagogy and widening participation. We will also be working with NCCE Computing Hubs when planning and implementing the trials.

How it will work

‘Gender Balance in Computing’ will develop and roll out several projects that aim to increase the number of girls choosing to study a computing subject at GCSE and A level. The consortium has already identified some of the possible reasons why a large percentage of girls don’t consider computing as the right choice for further study and potential careers. These include: feeling that they don’t belong in the subject; not being sufficiently encouraged; and feeling that computing is not relevant to them. We will go on to research and pilot a series of new interventions, with each focusing on addressing a different barrier to girls’ participation.

We will also trial initiatives such as more inclusive pedagogical approaches to teaching computing to facilitate self-efficacy, and relating informal learning opportunities, which are often popular with girls, to computing as an academic subject or career choice.

Signposting the links between informal and formal learning is one of the interventions that will be trialled.

Introducing our partners

WISE works to increase the participation, contribution, and success of women in the UK’s scientific, technology, and engineering (STEM) workforce. Since 1984, they have supported young women into careers in STEM, and are committed to raising aspirations and awareness for girls in school to help them achieve their full potential. In the past three years, their programmes have inspired more than 13,500 girls.

The Behavioural Insights Team have worked with governments, local authorities, businesses and charities to tackle major policy problems. They generate and apply behavioural insights to inform policy and improve public services.

Apps for Good has impacted more than 130,000 young people in 1500 schools and colleges across the UK since their foundation in 2010. They are committed to improving diversity within the tech sector, engaging schools within deprived and challenging contexts, and enthusing girls to pursue a pathway in computing; in 2018, 56% of students participating in an Apps for Good programme were female.

“A young person’s location, background, or gender should never be a barrier to their future success. Apps for Good empowers young people to change their world through technology, and we have a strong track record of engaging girls in computing. We are excited to be a part of this important work to create, test, and scale solutions to inspire more girls to pursue technology in education. We look forward to helping to build a more diverse talent pool of future tech creators.” Sophie Ball & Natalie Moore, Co-Managing Directors, Apps for Good

The Raspberry Pi Foundation has a strong track record for inclusion through our informal learning programmes: out of the 375,000 children who attended a Code Club or a CoderDojo in 2018, 140,000 (37%) were girls. This disparity between the gender balance in informal learning and the imbalance in formal learning is one of the things our new research project will be investigating.

The challenge of encouraging more girls to take up computing has long been a concern, and overcoming it will be critical to ensuring that the nation’s workforce is suitably skilled to work in an increasingly digital world. I’m therefore very proud to be working with this group of excellent organisations on this important research project (and on such a scale!). Together, we have the opportunity to rigorously trial a range of evidence-informed initiatives to improve the gender balance in computing in primary and secondary schools.

If you work at a school in England you can register your interest in taking part in this project here.

13 Comments

We’re on a stamp!

The Royal Mail is issuing a series of six stamps celebrating 50 years of British Engineering this week (available from 2 May). We’re absolutely made up to be one of the engineering projects chosen: we’re in some exalted company.

This series is also celebrating the 50th anniversary of the Royal Academy of Engineering’s MacRobert Award, which Raspberry Pi won in 2017. (I had had a baby what felt like about five minutes before the photos from the MacRobert Award presentation ceremony were taken, so please don’t judge.) The Raspberry Pi stamp sits alongside stamps featuring the Falkirk Wheel, catalytic converters, Crossrail, CT scanners, and synthetic bone grafts. We don’t envy the people having to make the choices about what to put on stamps like this: how do you sift through fifty years of great engineering in a country like Great Britain that produces so much to admire? We’re very proud to have been included — and we’re buying a huge stack of them to use on all our post for the foreseeable future.

You can buy your own presentation pack at the Royal Mail website (or at Post Offices) from Wednesday 2 May; or you can pre-order now. We’re a little sad that British stamps now come with a sticky back, so we won’t be able to imagine all of you gently licking the back of a Raspberry Pi, but otherwise we’re absolutely made up.

21 Comments

Interactive fiction with Python | Hello World issue 8

Nicholas Provenzano explains how he introduced Python to students in his literature class, bridging computer science and literacy.

Literature classes seem like the last place you would find students coding, but interactive fiction has been around for decades. Students love to play computer games, and the very best games have amazing stories. This project will allow students to create their own piece of fiction and then use Python to turn it into a text-based computer game. Students will have a chance to create their own hero and monsters, treasures and traps and so much more while being introduced to Python. Students that love to write, and students that love to code, will love this lesson.

Hello World issue 8

I’ve been thinking a lot recently about to ways to bring computer science into the literature classroom. I set out exploring the Raspberry Pi projects page, where I saw a project that allowed the user to create their own text-based computer game using Python. I thought this would be a great way to engage students in reading, writing, and programming.

Students create their own piece of fiction and then use their stories to create an amazing text-based computer game based on the role-playing game (RPG) tutorial from Raspberry Pi: helloworld.cc/rpg. From the first day working on this project, my students fell in love with the writing and the coding. They couldn’t wait to create their game and share them with their friends.

The project is best introduced with a focus on creative writing, where students should create an outline for their own adventure story. With that in hand, introduce the students to the Raspberry Pi RPG tutorial. It is much easier for students to create their game if they draw out the rooms on paper to help them visualise the game they’re creating. The more time they are given to create their game, the more complex it can become. Students will be able to fully explore the code while creating a fun game they can share with others.

Hello World issue 8

This project is the perfect way to bring coding to a literature class. Students that love to write will be introduced to text-based programming, while students that love to code will have an opportunity to explore fiction through their own writing.

My students were excited to spend their time creating a complex story, and an even more complex game to challenge their friends and their teacher. Students who struggled with the code were helped by other students who’d already moved ahead. We spent a week on this project, but you could spend longer, depending on the breadth of the stories and games. Watching students use their critical thinking skills to plan out a maze for their players was great to see.

The best part was watching students who do not normally engage in reading and writing lessons become leaders as they embraced the coding and were excited to turn their story into a game and share it with everyone. This project will become a mainstay in my teaching for years to come.

Take this to your club or classroom

For the complete lesson plan of the above project, download Hello World issue 8 for free and turn to pages 80–81.

Hello World issue 8

Get Hello World issue 8 for free

Hello World is available to download for free in PDF format anywhere in the world. Subscribe to Hello World today to receive the latest issues into your inbox as soon as they’re released.

Hello World issue 8

If you are a UK-based educator, you can also subscribe for free print copies of Hello World, which will be delivered to your door at no extra cost.

And, lastly, if you’d like to purchase Hello World magazine, you can buy the latest issue via the Raspberry Pi Press website.

4 Comments

Intelli-T Raspberry Pi sensor alarm | The MagPi issue 81

Never knowingly run out of tea-bags again with this ingenious system, using a Raspberry Pi and Arduino to create a weight sensor and alarm.

The Intelli-T Raspberry Pi sensor alarm

Faced with the, almost unthinkable, problem of no tea-bags in the house, Robin Mitchell was inspired to contrive an invention that would eliminate the possibility of that scenario ever happening again, and the Intelli-T Raspberry Pi Sensor Alarm was born. As he explains, “One of the biggest problems that faces many British homes, as well as my own, is having a stable supply of tea… an issue with knowing how many tea-bags are available in the house. Hence, an intelligent tea-bag container was needed!”

Simplici-tea

Simple in its design, the project consists of only a few elements, as Robin tells us: “The first element is the weight sensor itself, which weighs the tea-bag container. This weight sensor is connected to a standard HX711 ADC, which is then read by an Arduino. The Arduino then sends the weight data to the Raspberry Pi, which can keep track of how many bags there are, and play interesting facts about tea when a tea-bag is removed.”

The Intelli-T Raspberry Pi sensor alarm

Clever, but as with many inventions, not entirely straightforward to construct, with the weight sensor providing the main issue, as Robin elaborates: “The problem with weight sensors is that they require plenty of fine-tuning and can be very noisy. While this is not a problem for heavier items, trying to accurately weigh tea-bags is a nightmare. On reflection, it would have been better to use a much smaller weight sensor, so that the weight of the individual tea-bags is larger with respect to the minimum weight that the sensor can register (this would improve the accuracy).”

Brewing ideas

Undeterred, Robin successfully completed his tea-bag detection system, and feels that this kind of weight-sensing system could easily be used in other projects. “One area that could benefit from a similar system would be industrial systems that need to count parts such as resistors, transistors, capacitors, and even potentiometers. Of course, part counting can also be useful for the everyday hobbyist who wants to keep check of their component stock, and someone like myself who stocks many thousands of parts needs to keep an accurate check on inventory regularly (as I own a small electronics business).”

There certainly appears to be some scope here for future projects but, as for tea-bag detection, Robin thinks he has taken that particular piece of work as far as he can. “The project was great fun, but since I no longer drink bagged tea (lemon tea rules!), I don’t have a use for it any more.”

Not that Robin is short of ideas for other projects. “Each day of my life is all about creating projects around many platforms, with the Raspberry Pi included. Only recently, I designed a simple IoT monitoring station for an IoT sensor that can be affixed to a drill, and the vibration data streamed to the Raspberry Pi via a local network. All I can say is that the Raspberry Pi is a fantastic platform for prototyping and project building!”

The MagPi magazine issue 81

This article is from the latest issue of The MagPi magazine, which is out today and can be purchased online, at the Raspberry Pi Store, or from many independent bookshops, such as WHSmith and Barnes & Noble.

The MagPi magazine issue 81

You can also download issue 81 for free from The MagPi website, where you’ll also find information on subscription options, and the complete MagPi catalogue, including Essentials guides and books, all available to download for free.

the MagPi subscription

1 Comment

Create wearable tech with Sophy Wong and our new book | HackSpace magazine #18

Forget Apple Watch and Fitbit — if we’re going to wear something electronic, we want to make it ourselves!

Wearable Tech Projects, from the makers of HackSpace magazine, is a 164-page book packed with projects for the fashionable electronics enthusiast, with more than 30 projects which will blink, flash, and spark joy in your life.

Sophy Wong HackSpace Wearable Tech Projects book

Make a wearable game controller

Fans of Sophy Wong will already know about the amazing wearable tech that she develops. We wanted to make sure that more people discovered her work and the incredible world of wearable technology. You’ll start simple with sewable circuits and LEDs, and work all the way up to building your own wearable controller (complete with feathers) for an interactive, fully immersive game of Flappy Bird.

Sophy Wong HackSpace Wearable Tech Projects book

Pick up the tricks of the trade

Along the way, you’ll embed NFC data in a pair of cufflinks, laser cut jewellery, 3D print LED diffusers onto fabric for a cyberpunk leather jacket, and lots more.

 

Sophy Wong HackSpace Wearable Tech Projects book

Learn new techniques from Sophy Wong

You’ll discover new techniques for working with fabric, find out about the best microcontrollers for your projects, and learn the basics of CircuitPython, the language developed at Adafruit for physical computing. There’s no ‘Hello, World!’ or computer theory here; this is all about practical results and making unique, fascinating things to wear.

Get your copy today

Wearable Tech Projects is available to buy online for £10 with free delivery. You can also get it from WHSmith and all the usual high street retail suspects.

And that’s not all. There is also a new issue of HackSpace magazine out now, with an awesome special feature on space! You can find your copy at the same retailers as above. You can also download both Issue 18 and the Wearables book for free from the HackSpace website.

 

No Comments

An Introduction to C & GUI Programming – the new book from Raspberry Pi Press

The latest book from Raspberry Pi Press, An Introduction to C & GUI Programming, is now available. Author Simon Long explains how it came to be written…

An Introduction to C and GUI programming by Simon Long

Learning C

I remember my first day in a ‘proper’ job very well. I’d just left university, and was delighted to have been taken on by a world-renowned consultancy firm as a software engineer. I was told that most of my work would be in C, which I had never used, so the first order of business was to learn it.

My manager handed me a copy of Kernighan & Ritchie’s The C Programming Language, pointed to a terminal in the corner, said ‘That’s got a compiler. Off you go!’, and left me to it. So, I started reading the book, which is affectionately known to most software engineers as ‘K&R‘.

I didn’t get very far. K&R is basically the specification of the C language. Dennis Ritchie, the eponymous ‘R’, invented C, and while the book he helped write is an excellent reference guide, it is not a great introduction for a beginner. Like most people who know their subject inside out, the authors tend to assume that you know more than you do, so reading the book when you don’t know anything about the language at all is a little frustrating. I do know people who have learned C from K&R, and they have my undying respect!

I ended up learning C on the job as I went along; I looked at other people’s code, hacked stuff together, worked out why things didn’t work, asked for help from my colleagues, made a lot of mistakes, and gradually got the hang of it. I found only one book that was helpful for a beginner: it was called C For Yourself, and was actually one of the manuals for the long-extinct Microsoft QuickC compiler. That book is now impossible to find, so I’ve always had to tell people that the best book for learning C as a beginner is ‘C For Yourself, but you won’t be able to find a copy!’

Writing An Introduction to C & GUI Programming

When I embarked on this project, the editor of The MagPi and I were discussing possible series for the magazine, and we thought about creating a guide to writing GUI applications in C — that’s what I do in my day job at Raspberry Pi, so it seemed a logical place to start. We realised that the reader would need to know C to benefit from the series, and they wouldn’t be able to find a copy of C For Yourself. We decided that I ought to solve that problem first, so I wrote the original beginners’ guide to C series for The MagPi.

(At this point, I should stress that the series is aimed at absolute beginners. I freely admit that I have simplified parts of the language so that the reader does not have to absorb as much in one go. So yes, I do know about returning a success/fail code from a program, but beginners really don’t need to learn about that in the first chapter — especially when many will never need to write a program which does it. That’s why it isn’t explained until Chapter 9.)

An Introduction to C and GUI programming by Simon Long published by Raspberry Pi Press

So, the beginners’ guide to C came first, and I have now got round to writing the second part, which was what I’d planned to write all along. The section on GUIs describes how to write applications using the GTK toolkit, which is used for most of the Raspberry Pi Desktop and its associated applications. GTK is very powerful, and allows you to write rich graphical user interfaces with relatively few lines of code, but it’s not the most intuitive for beginners. (Much like C itself!) The book walks you through the basics of creating a window, putting widgets on it, and making the widgets do useful things, and gets you to the point where you know enough to be able to write an application like the ones I have written for the Raspberry Pi Desktop.

An Introduction to C and GUI programming by Simon Long published by Raspberry Pi Press

It then seemed logical to bring the two parts together in a single volume, so that someone with no experience of C has enough information to go from a standing start to writing useful desktop applications.

I hope that I’ve achieved that and if nothing else, I hope that I’ve written a book which is a bit more approachable for beginners than K&R!

Get An Introduction to C & GUI Programming today!

An Introduction to C & GUI Programming is available today from the Raspberry Pi Press online store, or as a free download here. You can also pick up a copy from the Raspberry Pi Store in Cambridge, or ask your local bookstore if they have it in stock or can order it in for you.

Alex interjects to state the obvious: Basically, what we’re saying here is that there’s no reason for you not to read Simon’s book. Oh, and it feels really nice too.

55 Comments