Lateo.net - Flux RSS en pagaille (pour en ajouter : @ moi)

🔒
❌ À propos de FreshRSS
Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.
À partir d’avant-hierInformatique & geek

43 secondes pour récupérer la clé Bitlocker d’un PC à l’aide d’un Raspberry Pi Pico

Par : Korben

Depuis maintenant plusieurs années, les utilisateurs de Windows ont la possibilité de sécuriser leurs données avec Bitlocker, l’outil de chiffrement de Microsoft. C’est hyper simple à mettre en place et les constructeurs l’ont adopté depuis longtemps en intégrant à leurs ordinateurs la fameuse puce TPM (Trusted Platform Module).

Ce qui permet à Bitlocker d’y stocker toutes les informations critiques relatives à la configuration de l’ordinateur, mais surtout la Master Key, c’est-à-dire la clé qui permet de déchiffrer tout le contenu.

C’est là qu’entre en scène le chercheur en sécurité StackSmashing qui a mis au point un moyen d’extraire physiquement cette clé à l’air d’un Raspberry Pi Pico à moins de 10 balles, d’un peu de soft, et d’un petit PCB maison. Grâce aux pins de son PCB, il peut alors se brancher directement au bus LPC de la puce TPM qui se trouve au dos de la carte mère, ce qui permet d’intercepter les messages transmis (donc la master key) entre la puce TPM et le CPU de l’ordinateur.

Comme vous pouvez le voir sur la vidéo, son bricolage est spécifique à certains modèles de laptop Lenovo (Thinkpad), mais ça peut-être facilement adapté (ou alors en soudant des fils) à tout type d’ordinateur comme il le montre à la fin, avec la Surface Pro (et un petit trou dans sa carlingue)

Toutefois, n’allez pas croire que votre ordinateur est forcément sensible à cette attaque surtout s’il est récent puisqu’à présent, les fabricants de processeurs comme Intel ou AMD ont directement intégré le TPM au CPU, donc c’est plus la même partie de plaisir.

Source

Protégez vos fichiers avec Picocrypt – Simple, sûr et portable

Par : Korben

Il y a des moments où vous vous trouvez avec un tas de documents importants et confidentiels, que vous souhaitez protéger des regards indiscrets. Que ce soit pour cacher vos photos de vacances, des dossiers professionnels sensibles ou simplement pour sécuriser vos projets personnels, un outil de cryptage robuste et facile à utiliser est un élément essentiel de votre arsenal numérique. Vous me demandez : « Mais Korben, existe-t-il un outil capable de faire tout cela sans avoir besoin d’être un super génie de la cryptographie ? » Bien sûr que oui ! Laissez-moi vous présenter Picocrypt.

Picocrypt est un logiciel de cryptage simple, sécurisé et gratuit qui utilise le chiffrement XChaCha20 et la fonction de dérivation de clé Argon2id pour protéger vos fichiers avec une facilité déconcertante. Il se démarque de ses concurrents tels que VeraCrypt, 7-Zip, BitLocker et Cryptomator par sa légèreté et sa portabilité, tout en offrant une interface intuitive même pour les débutants.

En plus de protéger vos fichiers contre les intrusions, Picocrypt prévoit également le pire en offrant des fonctions avancées telles que la protection contre la corruption des fichiers via Reed-Solomon, ainsi que l’utilisation de fichiers clés multiples pour sécuriser un volume partagé. Imaginez un scénario où chaque membre de votre équipe détient un fichier clé, et tous ces fichiers clés sont nécessaires pour déchiffrer le document sécurisé mis en commun.

L’un des atouts majeurs de Picocrypt est sa capacité à déjouer les attaques des ordinateurs quantiques grâce à son chiffrement basé sur une clé privée (c’est pas moi qui le dis, je ne suis pas un spécialiste du cassage de code quantique, mais c’est ce que les dev de Picocrypt expliquent).

L’outil possède également un générateur de mots de passe sécurisés, des commentaires non chiffrés ainsi qu’un mode « parano » offrant une sécurité maximale en combinant XChaCha20 et Serpent.

Maintenant que je vous ai bien chauffé, vous vous demandez peut-être où vous pouvez obtenir ce petit bijou ?

Et bien, rendez-vous sur ce lien pour accéder au GitHub officiel de Picocrypt, où vous pourrez télécharger la dernière version pour Windows, macOS et Linux. Si votre antivirus le signale comme un virus, signalez-le comme un faux positif, ce sera sympa pour les suivants. Une version installable est également dispo pour Windows.

Notez que Picocrypt ne nécessite pas de droits d’administrateur sur la machine et est même disponible dans le navigateur sous la forme d’une interface web limitée. Pour discuter du projet et poser des questions, rendez-vous sur le Reddit r/Picocrypt.

Bref, si vous cherchez un outil simple, sûr et portable pour protéger vos précieux fichiers, ne cherchez pas plus loin que Picocrypt.

A télécharger ici.

Qui connaît la console rétro PICO-8 ?

Par : Korben

Avez-vous déjà entendu parler de la PICO-8 ?

Et bien il s’agit d’une console qui a la particularité de ne pas vraiment être une console. Je m’explique. La PICO-8 se présente comme une console ordinaire, mais sans avoir l’inconvénient du hardware.

En effet, la PICO-8 possède tout ce qui fait d’une console une console tels que des outils de dev, une plateforme de distribution, un format d’affichage, des specs machines bien précises et bien sûr une communauté de gamers sauf que la console est totalement virtuelle. C’est si vous voulez, un émulateur de jeu rétro pour une machine qui n’a jamais existé physiquement.

Elle a donc sa propre identité et ses propres spécificités et à la place des traditionnelles cartouches physiques, les programmes conçus pour PICO-8 sont distribués sur des images PNG qui ont des têtes de cartouches, avec des étiquettes et une capacité de stockage de 32k.

Que du bonheur !

En suivant les spécs, chacun peut donc développer ses propres jeux. Et on trouve des trucs très cool sur la PICO-8 comme un jeu Ghostbusters nommé Bustin’, un street fight nommé Fighter Street II ou encore un pacman nommé Picoman. Bref, vous l’aurez compris, c’est pour le fun, le challenge mais également pour le plaisir des joueurs.

Si vous voulez tester la console sur macOS, Windows ou Linux, vous pouvez la télécharger contre une quinzaine de dollars ou tout simplement vous rendre ici pour jouer à une version online.

Un super projet auquel je vous invite à jeter un œil et pourquoi pas commencer à développer des jeux.

Teaching with Raspberry Pi Pico in the computing classroom

Par : Dan Elwick

Raspberry Pi Pico is a low-cost microcontroller that can be connected to another computer to be programmed using MicroPython. We think it’s a great tool for exploring physical computing in classrooms and coding clubs. Pico has been available since last year, amid school closures, reopenings, isolation periods, and restrictions for students and teachers. Recently, I spoke to some teachers in England about how their reception of Raspberry Pi Pico, and how they have found using it to teach physical computing to their learners.

A student uses a Raspberry Pi Pico in the computing classroom.

This blog post is adapted from issue 18 of Hello World, our free magazine written by computing educators for computing educators.

Extra-curricular engagement

At secondary schools, a key use of Raspberry Pi Pico was in teacher-led lunchtime or after-school clubs. One teacher from a girls’ secondary school in Liverpool described how he introduced it to his Women in Tech club, which he runs for 11- to 12-year-old students for half an hour per week at lunchtime. As this teacher has free rein over the club content and a personal passion for Raspberry Pi, his eventual aim for the club participants was to build a line-following car using Pico.

On a wooden desktop, electronic components, a Raspberry Pi Pico, and a motor next to a keyboard.

The group started by covering the basics of Pico, such as connecting it with a breadboard and making LEDs flash, using our ‘Getting started with Raspberry Pi Pico’ project guide. The teacher described how walking into a room with Picos and physical computing kits grabs students’ attention: “It’s massively more engaging than programming Python on a screen… They love the idea of building something physical, like a car.” He has to remind them that phones aren’t allowed at school, as they’re keen to take photos of the flashing lights to show their parents. His overall verdict? “Once the software had been installed, [Picos are] just plug and play. As a tool in school, it gives you something physical, enthuses interest in the subject. If it gets just one person choosing the subject, who wouldn’t have done otherwise, then job done.”

“If it gets just one person choosing the subject, who wouldn’t have done otherwise, then job done.”

Teacher at a Liverpool girls’ secondary school

Another teacher from a school in Hampshire used Picos at an after-school club with students aged 13 to 15. After about six sessions of less than 50 minutes last term, the students have almost finished building motorised buggies. The first two sessions were spent familiarising students with the Picos, making LEDs flash, and using sensors. In the next four sessions, the students made their way through the Pico-focused physical computing unit from our Teach Computing Curriculum. The students worked in pairs, and initially some learners had trouble getting the motors to turn the wheels on their buggies. Rather than giving them the correct code, the teacher gave them duplicate sets of the hardware and suggested that they test each piece in turn to ‘debug’ the hardware. Thus the students quickly worked out what they needed to do to make the wheels turn.

A soldered Raspberry Pi Pico on a breadboard.

For non-formal learning settings such as computing and coding clubs, we’ve just released a six-project learning path called ‘Introduction to Raspberry Pi Pico’ for beginner digital makers. You can check out the path directly, or learn more about how we’ve designed it to encourage learners’ independence.

Reinforcing existing computing skills

Another key theme that came through in my conversations with teachers was how Raspberry Pi Pico can be used to reinforce learners’ existing computing skills. One teacher I interviewed, from a school in Essex, has been using Picos to teach computing to 12- to 14-year-olds in class, and talked about the potential for physical computing as a pedagogical tool for recapping topics that have been covered before. “If [physical computing] is taught well, it enhances students’ understanding of programming. If they just copy code from the board, it becomes about the kit and not how you solve a problem, it’s not as effective at helping them develop their computational thinking. Teaching Python on Pico really can strengthen existing understanding of using Python libraries and subroutines, as well as passing subroutine arguments.”

“If [physical computing] is taught well, it enhances students’ understanding of programming.”

Teacher at an Essex secondary school

Another teacher I spoke to, working at a Waterlooville school and relatively new to teaching, talked about the benefits of using Pico to teach Python: “It takes some of the anxiety away from computing for some of the younger students and makes them more resilient. They can be wary of making mistakes, and see them as a hurdle, but working towards a tangible output can help some students to see the value of learning through their mistakes.”

Raspberry Pi Pico attached with jumper wires to a purple LED.

This teacher was keen for his students to get a sense of the variety of jobs that are available in the computing sector, and not just in software. He explained how physical computing can demonstrate to students how you can make inputs, outputs, and processing very real: “Give students a Pico and make them thirsty about what they could do with it — the device allows them to interact with it and work out how to bend it to what they want to do. You can be creative in computing without just writing code, you can capture information and output it again in a more useful way.”

“Working towards a tangible output can help some students to see the value of learning through their mistakes.”

Teacher at a Waterlooville school

One of the teachers we spoke to was initially a bit cynical about Pico, but had a much better experience of using it in the classroom than expected: “It’s not such a big progression from block-based microcontrollers to Pico — it could be a good stepping stone between, for example, a micro:bit and a Raspberry Pi computer.”

Why not try out Raspberry Pi Pico in your classroom or club? It might be the engagement booster you’ve been looking for!  

Top teacher tips for activities with Raspberry Pi Pico

  • Prepare to install Thonny (the software we recommend to program Pico) on your school’s or venue’s IT systems, and ask your IT technician for support.
  • It takes time to unpack devices, connect them, and pack them back up again. Build this time into your plan!

Free learning resources for using Raspberry Pi Pico in your classroom or club

Teachers at state schools in England can borrow physical computing kits with class sets of Raspberry Pi Picos from their local Computing Hub. We’ve made these kits available through our work as part of the National Centre for Computing Education. The Pico kit is perfect for teaching the Pico-focused physical computing unit from our Teach Computing Curriculum.

Qualified US-based educators can still get their hands on 1 of 1000 free Raspberry Pi Pico hardware kits if they sign up to our free course Design, build, and code a rover with Raspberry Pi Pico. This course shows you how to introduce Pico in your classroom. We’ve designed the course on the Pathfinders Online Institute platform, specifically for US-based educators, thanks to our partners at Infosys Foundation USA. These Raspberry Pi Pico kits are also available at PiShop.us.

For non-formal learning settings, such as Code Clubs and CoderDojos, we’ve created a six-project learning path: ‘Introduction to Raspberry Pi Pico’. This path is for beginner digital makers to follow and create Pico projects, all the while learning the skills to independently design, code, and build their own projects. All of the components for the path are available as a kit from Pimoroni.

The post Teaching with Raspberry Pi Pico in the computing classroom appeared first on Raspberry Pi.

Get kids coding and learning electronics with Raspberry Pi Pico

Since the release of the Raspberry Pi Pico microcontroller in 2021, we have seen people all over the world come up with creative Pico-based inventions.

Raspberry Pi Pico with its inbuilt LED blinking.
The Raspberry Pi Pico microcontroller.

Now, thanks to our brand-new and free ‘Introduction to Raspberry Pi Pico’ learning path, young coders can easily join in and make their own cool Pico projects! This free learning path has six guided projects to help kids to independently develop their coding skills, and their skills in physical computing and electronics.

A girl creates a physical computing project.
Physical computing is a great way to help young people get creative with coding.

In this post, I’ll tell you about Raspberry Pi Pico, what kids can make by following our free ‘Intro to Pico’ path, and what skills they will be learning.

Meet Raspberry Pi Pico

Raspberry Pi Pico is a physical computing device that is low-cost and easy to use. It’s much smaller than any Raspberry Pi computer, and it needs much less power. That’s because it’s not a full computer but instead a microcontroller. That means Pico is a device that you program by writing code on any computer, and then sending that code to Pico via a USB cable.

Raspberry Pi Pico has GPIO pins (like Raspberry Pi computers do). These pins mean it can interact with different types of physical computing components, such as buttons, buzzers, and LEDs.

In the ‘Intro to Raspberry Pi Pico’ path, we’ve designed new digital making projects specifically using Pico. By following the projects in the path, young people learn to make things with different electronic components. They’ll bring to life their own LED fireflies; they’ll make music with a sound machine and dial (a potentiometer); they’ll look after themselves and people around them by making a mood indicator and a heart rate visualiser. To find out more, visit the path, or scroll to the bottom of this post and click on ‘Details about the projects’.

The specially designed structure of our learning paths helps kids become confident and independent coders and digital makers. Through this project path, we want to show young people what is possible with Raspberry Pi Pico and inspire them to continue their digital making journey beyond the six projects. Seeing tech creations from our amazing community is super special to us, and we would love to hear about what your young coders have made with Pico. Kids can share their projects in the path gallery, or you can tag us on social media if you post photos!   

alt=""

Learning skills and independence with our project paths 

While young people make all these Raspberry Pi Pico projects, they will learn the skills and independence to make and code their very own, unique creations with a Pico. We have designed our new project paths to help kids become independent digital makers. As they progress through a path, kids gain new skills, practise what they have learnt, and finally write and follow their own project brief. 

Our learning paths help kids develop many of the skills that are important to all coders and digital makers, no matter how much experience they have: 

  • How to turn an idea on paper into a tech creation
  • How to debug a project
  • How to combine new information with what they already know about digital making 

The learning paths also encourage kids to make projects about the things that matter to them.  

Key questions answered

Who is this path for?

We have written the projects in this path with young people around the age of 9 to 13 in mind. 

Programs for Raspberry Pi Pico are written in a text-based language called MicroPython. That means a young person who wants to start the ‘Intro to Pico’ path needs to be familiar with typing on a keyboard.

A young person codes at a Raspberry Pi computer.

If your kid has never coded in a text-based language before, they could complete our free ‘Introduction to Python‘ project path first, but this is not a prerequisite.

What will young people learn?

To help with the programming aspects of the projects, the instructions in the path tell young people about:  

  • Displaying output
  • Arithmetic expressions
  • Importing from a library
  • While loops
  • Nested if statements
  • Defining and calling functions
  • Events
Raspberry Pi Pico attached with jumper wires to a purple LED.
We still get excited by a flashing LED.

One of the great things about this project path is that it helps young people explore physical computing and electronics. In the ‘Intro to Pico’ path, they’ll use:

  • Single-colour LEDs
  • Multi-colour LEDs (so-called RGB LEDs)
  • Buzzers
  • Switches (including switches the kids will make out of craft materials!)
  • Buttons
  • Potentiometers (dials)

How much time is needed to complete the path?

We’ve designed the path to be completed in around six one-hour sessions, with one hour per project. However, the project instructions encourage kids to upgrade their projects and go further if they wish. This means that they might want to spend a little more time getting their projects exactly as they imagine. 

What software is needed for the projects?

Young people need a web browser so they can follow the project instructions. The first two projects in the path provide detailed instructions for how to install the free software needed for the projects. 

alt=""
The projects in the path show you how to program Raspberry Pi Pico using MicroPython in the Thonny software.

What hardware is needed for these projects?

The first step of each project lists what components are needed to create the project. You can purchase a kit from Pimoroni that includes all of the components used in the path:

‘Intro to Raspberry Pi Pico’ kit list (click here)
  • 1 × soldered Raspberry Pi Pico
  • 1 × USB cable
  • 1 × red LED
  • 1 × blue LED
  • 2 × yellow LEDs
  • 6 × single-colour LEDs (random)
  • 3 × RGB LEDs
  • 15 × 75 ohm resistors (max 220 ohm)
  • 2 × potentiometers
  • 8 × push buttons (optional, these can be made from crafting materials)
  • 15 × pin–socket jumper wires
  • 38 × socket–socket jumper wires
  • 4 × pin–pin jumper wires

What can young people do next?

Explore Python coding with us 

If your young coders enjoy MicroPython, they’ll also love our Python learning paths: ‘Introduction to Python‘ and More Python‘. Both are structured in the same way as our Pico path, and will help young people learn Python while creating their own visual designs.

A girl points happily at a project on the Raspberry Pi Foundation's projects site.
Details about the projects in ‘Intro to Raspberry Pi Pico’
The ‘Intro to Raspberry Pi Pico’ path is structured according to our Digital Making Framework, with three Explore projects, two Design projects, and a final Invent project. You can also check out our learning graph to see the progression of skills and knowledge throughout the path.

Explore project 1: LED firefly


The ‘LED firefly’ project introduces creators to Raspberry Pi Pico while they make their first project with a blinking LED. They program the LED with a blink pattern that is common to fireflies in the wild. To upgrade their projects, creators can place their LED firefly into a glass jar to create a twinkling effect.  

Explore project 2: Party popper


‘Party popper’ introduces creators to the RGB LED and a buzzer. To form the popper, they craft a pull switch out of kitchen foil and cardboard. When the popper is activated, the RGB LED flashes in their chosen colour, and a ‘tada’ sound plays on the buzzer. 

Explore project 3: Beating heart


‘Beating heart’ uses a potentiometer (dial) to control the pulsing speed of an LED. Creators craft their own hearts using red paper and origami before placing the pulsing LED inside. In this way, they create a model of a heart they can use to learn about medicine or to bring to life a favourite toy. 

Design project 1: Mood indicator


In the ‘Mood indicator’ project, kids use switches and an RGB LED to create a device that can communicate a need or a mood to another person. This Design project gives young creators lots of opportunities to use their new skills to create something personal to them.

Design project 2: Sound machine

 
‘Sound machine’ is a project for kids to work with the different tones that a buzzer can make. They can use the buzzer to create sound effects, or to recreate their favourite songs. Once they have decided on their sounds, they can think about how a user of their project might choose to play them. 

Invent project: Sensory gadget

 
This project gives creators that chance to pick their favourite elements of the path to create something totally unique to them. They could make all sorts of sensory gadgets, from a Picosaber to a candle that can be blown out. Creators are encouraged to showcase their creations in the path gallery to give other young makers inspiration. 

The post Get kids coding and learning electronics with Raspberry Pi Pico appeared first on Raspberry Pi.

See what sounds look like with Raspberry Pi Pico

Raspberry Pi Pico powers this real-time audio spectrogram visualiser using a digital microphone to pick up the sound and an LCD display to show us what those sounds “look” like.

See Sound in Real-Time Using Your Raspberry Pi Pico

First things first

First off, let’s make sure we know what all of those words mean, because “audio spectrogram visualiser” is a bit of a mouthful:

  • A spectrogram is a way of representing the range of frequencies in a signal and their strength, or “loudness”. For example, a spectrogram could show the mixture of higher and lower frequency sounds that make up the sound of a spoken word.
  • The visualiser bit comes in when these frequencies are presented as waveforms that you can see on the screen.
  • And the audio part is simply because Sandeep is visualising sounds in this project (rather than, for example, radio frequencies or seismic waves).
Sadly, Sandeep’s machine can’t tell you why the baby is crying

Perfectly portable sound monitor

This pocket-sized device can be carried around with you and lets you see a visual representation of your surrounding audio environment in real time. So, if you wander into a peaceful bird reserve or something, the LCD display will show you something very different to what you’d see if you were in, say, Wembley Stadium during an FA Cup final.

Above, you can see Sandeep’s creation in action in the vicinity of a crying baby.

See Sound in Real-Time Using Your Raspberry Pi Pico

Hardware

That is a satisfyingly affordable hardware list.

How does it work?

In the video below, you can see there is a direct correlation between the original audio signal’s amplitude (on the left) and the audio spectrogram’s representation of the signal on the right.

The Microphone Library for Pico captures data from Sandeep’s digital microphone. Arm’s CMSIS-DSP library processes the audio in real-time, then transforms it into spectrograms. These are then displayed one row at a time on the LCD screen, using the ST7789 Library for Pico.

Maker Sandeep Mistry created the original project guide on behalf of the Arm Software Developers team. Check out his other tutorial on how to create a USB Microphone with the Raspberry Pi Pico.

The post See what sounds look like with Raspberry Pi Pico appeared first on Raspberry Pi.

Automatically tune your guitar with Raspberry Pi Pico

You sit down with your six-string, ready to bash out that new song you recently mastered, but find you’re out of tune. Redditor u/thataintthis (Guyrandy Jean-Gilles) has taken the pain out of tuning your guitar, so those of us lacking this necessary skill can skip the boring bit and get back to playing.

Before you dismiss this project as just a Raspberry Pi Pico-powered guitar tuning box, read on, because when the maker said this is a fully automatic tuner, they meant it.

How does it work?

Guyrandy’s device listens to the sound of a string being plucked and decides which note it needs to be tuned to. Then it automatically turns the tuning keys on the guitar’s headstock just the right amount until it achieves the correct note.

Genius.

If this were a regular tuning box, it would be up to the musician to fiddle with the tuning keys while twanging the string until they hit a note that matches the one being made by the tuning box.

It’s currently hardcoded to do standard tuning, but it could be tweaked to do things like Drop D tuning.

Pico automatic guitar tuner
Waiting for that green light

Upgrade suggestions

Commenters were quick to share great ideas to make this build even better. Issues of harmonics were raised, and possible new algorithms to get around it were shared. Another commenter noticed the maker wrote their own code in C and suggested making use of the existing ulab FFT in MicroPython. And a final great idea was training the Raspberry Pi Pico to accept the guitar’s audio output as input and analyse the note that way, rather than using a microphone, which has a less clear sound quality.

These upgrades seemed to pique the maker’s interest. So maybe watch this space for a v2.0 of this project…

Shred, Otto, shred

(Watch out for some spicy language in the comments section of the original reddit post. People got pretty lively when articulating their love for this build.)

Inspiration

This project was inspired by the Roadie automatic tuning device. Roadie is sleek but it costs big cash money. And it strips you of the hours of tinkering fun you get from making your own version.

All the code for the project can be found here.

The post Automatically tune your guitar with Raspberry Pi Pico appeared first on Raspberry Pi.

Free computer science courseware and hardware for American educators

Today we’re announcing two brand-new, fantastic, free online courses for educators in the USA. And to kickstart their learning journey, we are giving qualified US-based educators the chance to get a free Raspberry Pi Pico microcontroller hardware kit. This is all thanks to our partners at Infosys Foundation USA, who are committed to expanding access to computer science and maker education in public schools across the United States.

In a classroom, a teacher and a student look at a computer screen while the student types on the keyboard.
Bring computer science to your students with the help of our new free online courses.

You can find both new courses on the Pathfinders Online Institute platform, which supports US classroom educators to bring high-quality computer science and maker education content to their kindergarten through 12th grade students. And best of all, the platform is completely free!

Learn how to teach the essentials of programming

The first course we’ve created for you is called Programming essentials in Scratch. It supports teachers to introduce the essentials of programming to fourth to eighth grade students. The course covers the key concepts of programming, such as variables, selection, and iteration. In addition to learning how to teach programming effectively, teachers will also discover how to inspire their students and help them create music, interactive quizzes, dance animations, and more.

A girl sits by a desktop computer, with her Scratch coding project showing on the screen.
Scratch is a block-based programming language and ideal for teaching key programming concepts.

Discover how to teach physical computing

Our second new course for you is called Design, build, and code a rover with Raspberry Pi Pico. It gives teachers of fourth to eighth grade students everything they need to start teaching physical computing in their classroom. Teachers will develop their students’ knowledge of the subject by using basic circuits, coding a Raspberry Pi Pico microcontroller to work with motors and LEDs, and designing algorithms to navigate a rover through a maze. By the end of the course, teachers will have all the resources they need to inspire students and help them explore practical programming, system design, and prototyping.

On a wooden desktop, electronic components, a Raspberry Pi Pico, and a motor next to a keyboard.
Take our free course to learn how to build and code a rover with your students.

Get one of 1,000 free hardware kits

And thanks to the generous support of Infosys Foundation USA, we’re able to provide qualified educators with a FREE kit of materials to participate in the Design, build, and code a rover with Raspberry Pi Pico course. We’re especially excited about this because the kit includes our first-ever microcontroller, Raspberry Pi Pico. This offer is available to 1,000 US-based K–12 public or charter school teachers on a first-come, first-served basis.

To claim your kit, just create a free account on Pathfinders Online Institute and start the course. On the first page of the course, you’ll receive instructions on how to apply for a free kit.

A soldered Raspberry Pi Pico on a breadboard.
The first 1,000 qualified educators who sign up for Design, build, and code a rover with Raspberry Pi Pico receive all a free hardware kit.

If you’re not a qualified educator, or if you’ve missed out on the opportunity to get the free hardware, we still welcome you to join the course! You can find the materials yourself, or purchase the kit from our partners at PiShop.us.

Thank you to Infosys Foundation USA

All of us at the Raspberry Pi Foundation want to thank the Infosys Foundation USA team for collaborating with us on this new resource and learning opportunity for educators. We appreciate and share their commitment to support computer science and maker education.

The post Free computer science courseware and hardware for American educators appeared first on Raspberry Pi.

Add 57,600 pixels to your Raspberry Pi Pico

In the latest issue of HackSpace magazine, Ben Everard tests whether a bit of kit from Spotpear can turn Raspberry Pi Pico into a games machine.

The snappily named Raspberry Pi Pico display 1.54-inch LCD by Spotpear ($11.89) brings in a 240×240 pixel IPS screen and ten buttons in a joypad-like arrangement. There’s four for direction, four for action, a select, and a start. At least, they’re labelled like this. You can use them for anything you like.

Spot pear Pico screen front
The buttons are just a bit too small and fiddly for us

To help you get started, there’s a short manual, which includes example code for MicroPython and C.

This example code is easy enough to use, but it is a little messy. The mechanism for controlling the hardware isn’t separated into its own module, so you’re left with either the task of building the library yourself or having slightly untidy code. Not the biggest inconvenience, but compared to how neatly some maker hardware companies manage their code, we found ourselves off to a disappointing start.

There are also some sample UF2 files included along with the C example code, but these appear to have been built for different hardware and work either partially or not at all. The actual example code did compile and work properly.

Impressive quality

When we ran the example code, we were impressed with the quality of the screen. With 240×240 pixels in just 1.54 inches, there’s a high pixel density that can give crisp graphics. Obviously, high pixel densities are a double-edged sword. While they can look great, it does mean higher RAM use, more time transferring data, and more data to process.

Fortunately, Pico is well-suited to the task of driving screens. Each pixel can take 16 bits of colour data, so a full-frame buffer is just 115,200 bytes. The display data is transferred by SPI, and Pico has a maximum SPI frequency of half the clock speed. For MicroPython, that means 62.5MHz. The actual data transfer rate is a little less than this because of overhead of the protocol, but we were able to drive full-frame refreshes at over 40 fps, which is plenty for smooth animations.

Spot pear Pico screen back
Pico slots in the back, which is perfect for space-constrained builds

Obviously, if you’re looking to do animations, sending the data is only half the story. You also need to calculate the frame before it’s displayed. If you’re using MicroPython, you are quite limited by the amount of processing you can do and still keep a high frame rate (though you could use the second core to offload some of the processing). With C, you’ve got much more scope, especially as you could potentially offload the data transfer using direct memory access (DMA).

Battery-sucking light

The one disappointing thing about the screen is that there’s no control over the backlight. According to the documentation, it should be attached to pin 13, but it isn’t. You can’t turn it on or off – it’s just permanently on, and quite bright. That’s a deal-breaker for anything running off battery power, as it will suck up a lot of power. However, if you want a display permanently on, this might be perfectly acceptable.

While we were quite impressed by the screen, we can’t say the same for the other part of the hardware – the buttons. They’re small, stiff, and have very little movement. The end result is a button that is hard to press, and hard to know if you’ve pressed it. They’re the sort of buttons that are commonly used as reset buttons as they’re hard to accidentally press.

We had hoped that this screen would make a good base for a games console, but unfortunately these buttons would just make for a frustrating experience. They might be OK for a menu-driven user interface, but that’s about it.

Another minor annoyance in this is the lack of any mounting holes. This makes it hard to embed into a project as the user interface.

We wanted to like this project. It’s got a good, high-res screen and a nice layout of buttons. However, the choice of components makes it hard to see how we’ll use this in our projects. We’re considering removing the surface-mount buttons and soldering wires onto them to make a more useful device, but if you’re going to go to that level of surgery, it’s probably better to start with a plain screen and work your way up from there.

Verdict

5/10

Good screen, but awful buttons

Price: $11.89

HackSpace magazine issue 46 out NOW!

Each month, HackSpace magazine brings you the best projects, tips, tricks and tutorials from the makersphere. You can get it from the Raspberry Pi Press online store or your local newsagents.

hackspace front cover red and yellow graphics featuring a spanner and test tube

As always, every issue is free to download from the HackSpace magazine website.

The post Add 57,600 pixels to your Raspberry Pi Pico appeared first on Raspberry Pi.

Pico Pico Synth | HackSpace #44

In the latest issue of HackSpace magazine, Ben Everard shows us how to create a framework for building audio devices using Raspberry Pi Pico, called PicoPicoSynth.

Raspberry Pi Pico combines processing power with the ability to shuffle data in and out quickly. This makes it a good fit for a lot of different things, but the one we’ll be looking at today is sound synthesis.

There are a huge number of ways you can make sound on a programmable electronic device, but there’s always space for one more way, isn’t there? We set about trying to create a framework for building audio devices using Raspberry Pi Pico that we’ve called PicoPicoSynth, because it’s a small synth for Pico.

Pico audio hero image from HackSpace
We’re working on a DIY audio board to accompany this software. Hopefully, we’ll be able to show it off in a future issue

Sequencer magic

The program is powered by a sequencer. This is a structure that contains (among other things) a sequence of notes that it plays on a loop. Actually, it contains several sequences of notes – one for each type of noise you want it to play. Each sequence is a series of numbers. A -1 tells the sequencer not to play that note; a 0 or higher means play the note. For every point in time (by default, 24,000 times a second), the sequencer calls a function for each type of noise with the note to play and the time since the note first sounded. From these inputs, the callback function can create the position of the sound wave at this point, and pass this back to the sequencer. All the sounds are then mixed and passed on to the Pico audio system, which plays them.

Manipulating waveforms

This setup lets us focus on the interesting bit (OK, the bit this author happens to find interesting – other people may disagree) of making music. That is playing with how manipulating waveforms affects the sound.

You can find the whole PicoPicoSynth project at hsmag.cc/GitHubPPSynth. While this project is
ongoing, we’ve frozen the version used in this article in release 0.1, which you can download from hsmag.cc/PPSythV1. Let’s take a look at the example_synth file, which shows off some of the features.

github for the pico audio project
You can grab the latest version of this code from GitHub

You can create the sound values for PicoPicoSynth however you like, but we set it up with wavetables in mind. This means that you pre-calculate values for the sound waves. Doing this means you can do the computationally heavy work at the start, and not have to do it while running (when you have to keep data flowing fast enough that you can keep generating sound).

The wavetables for our example are loaded with:

low_sine_0 = get_sinewave_table(50,
24000);
low_sine_1 = get_sinewave_table(100,

24000);
bongo_table = create_wavetable(9054);
for (int i = 0; i < BONGOSAMPLES; i++) {
bongo_table->samples[i] =

bongoSamples[i] * 256;
}

The first two create sine waves of different frequencies. Since sine waves are useful, we’ve created a helper function to automatically generate the wavetable for a given frequency.

The third wavetable is loaded with some data that’s included in a header file. We created it by loading a bongo WAV file into hsmag.cc/WavetableEd, which converts the WAV file into a C header file. We just have to scale it up from 8 bits to 16 by multiplying it by 256. There’s no helper function to do the job here, so we have to load in the samples ourselves.

Callback functions

That’s the data – the other thing we need are the callback functions that return the values we want to play. These take two parameters: the first is the number of samples since the note was started, and the second is the note that’s played.

int16_t bongos(int posn, int note) {

if (note == 0 ) {
return no_envelope(bongo_table,

1, posn);
}
if (note == 1 ) {
return no_envelope(bongo_table,

0.5, posn);
}
else {
return 0;
}
}

int16_t low_sine(int posn, int note) {
if (note == 0 ) {
return bitcrush(envelope(low_

sine_0, 1, posn, posn, 5000, 10000, 15000,
40000),32768,8);
}
if (note == 1 ) {
return bitcrush(envelope(low_

sine_1, 1, posn, posn, 5000, 10000, 15000,
40000),32768,8);
}
else {
return 0;
}
}

The note is 0 or higher – it corresponds to the number in the sequence, and you can use this however you like in your program. As you can see, both of our functions play sounds on notes 0 and 1.

The library includes a few functions to help you work with wavetables, the main two being
no_envelope and envelope. The no_envelope function also takes a multiplier – it’s 1 in the first instance and 0.5 in the second. This lets us speed up or slow down a sample, depending on what we want to play.

pico audio HAT
We used Pimoroni’s Pico Audio Pack, but other forms of audio output should be possible

Attack, decay, sustain, and release

An envelope may be familiar to you if you’ve worked with synths before, and it’s used to convert a constant tone into something that sounds a bit like an instrument being played. You supply four values – the attack, decay, sustain, and release times. During the attack phase, the volume ramps up. During the decay phase, it partially drops to a level that it holds during the sustain phase, and finally it drops to 0 during the release phase. This gives a much more natural sound than simply starting or stopping the sample.

The envelope function also has a multiplier, so we could use the same wavetable for both, but it’s more accurate to generate a specific wavetable for each note if you’ve got the space to store it.

There are also a few sound effects in the synth library that you can apply – BitCrunch, for example. This compresses the sample bit depth down to give the sine wave a distorted sound.

These callbacks don’t have to be sound. You could equally use them to co-ordinate a lighting effect, control physical hardware, or do almost anything else.

Last coding stretch

Now we’ve got the sounds set up, it’s time to link them all together. This is done with the code below.

int bongo_sequence[] = {1, 1, -1, -1, -1,
0, -1, -1};
int low_sine_sequence[] = {-1, -1, 1, -1,

-1, -1, 0, -1};

struct sequencer main_sequencer;
init_sequencer(&main_sequencer, BEATNUM,

BEATFREQ);

//add up to 32 different sequences here
add_sequence(&main_sequencer, 0, bongo_

sequence, bongos, 0.5);
add_sequence(&main_sequencer, 1, low_

sine_sequence, low_sine, 0.5);

Sequences are stored as int arrays that have to be the same length as the sequencer (stored in the BEATNUM macro). This can be any integer up to 32. The numbers in here can be anything you like, as they’re just passed back to the callback functions defined above. The sole limitation being that only numbers 0 or greater are played. We also pass the BEATFREQ value which contains the number of samples per beat.

The final step in setting up the sound is to add up to 32 different sequences to your sequencer.

With everything set up, you can set the music playing with:

    while (true) {

     //do any processing you want here
     give_audio_buffer(ap, fill_next_

buffer(&main_sequencer, ap, SAMPLES_PER_BUFFER));
    }

Each time this loops, it calculates the next 256 (as stored in the SAMPLES_PER_BUFFER macro) and passes them to the audio system. You can do any other processing you like in the loop, provided it can run fast enough to not interrupt the sound playing.

code block for pico audio project
The envelope function creates a donk, bong, bing, or other sound from a note with a constant volume

That’s all there is to it. Set this code running on a Pico that’s plugged into a Pimoroni Audio Pack (you should be able to make it work with other audio systems – see the ‘Audio output’ box, overleaf) and you’ll hear some strange bumps and wobbles.

Of course, it’s unlikely that you’ll want to listen to exactly this strange combination of distorted sine waves and low bitrate bongos. You can take this base and build your own code on top of it. The callback functions can do anything you like, provided they run quickly enough and return a 16-bit integer. How you use this is up to you.

Issue 44 of HackSpace magazine is on sale NOW!

Each month, HackSpace magazine brings you the best projects, tips, tricks and tutorials from the makersphere. You can get it from the Raspberry Pi Press online store or your local newsagents.

HackSpace 44 cover

As always, every issue is free to download from the HackSpace magazine website.

The post Pico Pico Synth | HackSpace #44 appeared first on Raspberry Pi.

Build a Raspberry Pi Pico piano

Did you catch the very cool Raspberry Pi Pico piano project shared on the latest Digital Making at Home livestream? The sibling maker group from the GurgleApps family, Amelie, Caleb, and Ziva, chatted about how they got into coding before inviting us into miniature musical mayhem.

Watch the siblings on the latest Digital Making at Home livestream

What do you need to make a Raspberry Pi Pico piano?

  • Raspberry Pi Pico
  • Resistors
  • Copper-plated boards
  • Analog pin (to ‘play’ the resistor ‘keys’)
kids hands showing the pieces of the pico piano
The siblings trialled lots of different materials to find the best keyboard

Multiple coding options

The siblings made two separate keyboards: one coded in MicroPython and another coded in Circuit Python. The Circuit Python-coded board also has MIDI functionality! Watch the video below to learn more about the exploration process.

The original build video on YouTube walks you through the electronics part of the project

Power of resistors

So how do the resistors power this project? Four resistors are connected from ground to power in series, with the highest voltage in the far right-hand resistor (see image below). The voltage drops as we move along the series to the far left-hand resistor. Analog pins sit between each resistor and act as the ‘notes’ on the piano.

makers holding up whiteboard explaining the mechanics
Resistor series lesson in session

Perf finish

You don’t even need a board like the kids made, you can just twist or solder a series of resistors together to make the base of your piano and then ‘play’ it by pressing an analog pin against the wires. With a board, the piano looks much cooler though.

A perf board would also work for this project if you don’t want to go to the trouble of making your own piano board but still want something that looks a little more ‘piano-like’ than a bunch of resistors.

raspberry pi pico fixed to back of piano board

Appearances matter

To make the snazzy board you see in the video, the kids grabbed a copper-plated board and drew out designs on sticky paper (their printer was broken so this was a homely, if more time-consuming, option). Stick the paper designs to the copper board, put that board in etching solution, and you’ve got a homemade piano keyboard. They also tried using a Sharpie to draw designs straight onto the board, but the sticker designs look a lot more slick.

  • piano coming out of black liquid
    Sharpie-drawn designs are finished in a ferric chloride solution
  • piano board sat in bowl in white liquid
    Then tin solution gives the board a silvery finish

Resistor placement perfection and coding

Resistor placement took some time to perfect: the siblings tried out a few cheap copper boards before they got it right. The video below shows you how to code your Pico piano.

This video show you how to code your piano with Raspberry Pi Pico

Subscribe to the GurgleApps family’s channel on YouTube for more electronics and coding projects. And subscribe to our YouTube channel for young people and educators for even more fun, family-friendly coding and physical computing videos!

The post Build a Raspberry Pi Pico piano appeared first on Raspberry Pi.

Raspberry Pi Pico-controlled model railroad

The Orient Express. The Flying Scotsman. Ivor the Engine. All juggernauts of the rail community, but none powered by our microcontroller and all, thus, inferior in our eyes. Raspberry Pi Pico has been used in cooler and more interesting ways every day since its launch in January this year, but this is the first time we’ve seen it powering a miniature railway. KushagraK7 shared this compact application on Instructables, and we ended up down a rabbit hole of model trains enthusiasm.

The Motor Channel on YouTube is a great community for miniature railway enthusiasts

What does Raspberry Pi Pico do here?

KushagraK7’s Raspberry Pi Pico controls the track voltage to control the speed of the train using pulse-width modulation (PWM). PWM is a method of reducing the average power delivered by an electrical signal. A motor driver powers the locomotive itself.

mini railroad build kit
Photo from KushagraK7’s Instructable

You gotta speed it up and then you gotta slow it down

This particular setup is designed to make the train start off slowly then speed up gradually each time it travels over a sensored segment of the track — that is, a segment equipped with an infrared sensor to detect whether a train is there. A therapeutic loop of the speeding-up process plays from this point in KushagraK7’s YouTube video.

sensored parts of train track
The ‘sensored’ part of the train track ready to be connected

Once the train reaches its top speed, it slows down again, coming to a complete halt after it passes the sensored track section once more. The train stops for a set amount of time, then starts up again. Fast, faster, slow, stop. Fast, faster, slow, stop. And on and on and on again. All without any human interaction needed – you can just watch. Super satisfying.

Hardware

Learn how to make a low-cost sensored track “in minutes” with this previous Instructable from the maker

How do I build it?

KushagraK7 has created an illustrated step-by-step tutorial for other miniature railway enthusiasts to follow, including when you should tidy up your wires, plus ideas to tinker with the code to adjust speed and stopping patterns.

Point us to your Raspberry Pi-powered model railway projects in the comments. Choo choooooooo.

The post Raspberry Pi Pico-controlled model railroad appeared first on Raspberry Pi.

Debugging embedded software with Raspberry Pi Pico

In this article from the latest issue of HackSpace magazine, Rob Miles takes a look at debugging. You’ll find what a debugger does and discover how to add hardware that can be used to tell us what our devices are really thinking.

Figure 1 An ESP32-PROG (on the right) connected to a DOIT ESP32 device using direct connection to the JTAG pins
Figure 1: An ESP32-PROG (on the right) connected to a DOIT ESP32 device using direct connection to the JTAG pins

Bug origins

Whenever your program doesn’t do what you want it to, you’ve got a bug. An early bug was an insect that got stuck in the contacts of an early computer. Bugs can be caused by many things, including poor specification, programmer error, or plain bad luck. The very first programmers had no way of fixing their bugs other than staring at their code and trying to work out what had gone wrong. However, if you are writing a program on a desktop computer today, one of the tools at your disposal will be your trusty debugger. This allows you to stop a program, look at what it is doing, and then continue, or even step through individual program statements.

Building code for debugging

To understand how a debugger works, we can start by considering the compilation process. Some languages, including C++, are compiled. A program called a compiler converts program source code into low-level machine code which tells the hardware what to do. This machine code is loaded into the target computer which runs your code. To see how this works, consider the following loop function.

void loop() {
  i = i + 1;
  j = j  - 1;
}

Each time the loop function is called, it will add 1 to the value in the variable i and subtract 1 from the value in the variable j. We might want to run this function on an ESP32 device. This can’t understand C++ statements, so the compiler converts them into a sequence of instructions that it can understand. 

In the Figure 2 table, you can see the instructions produced by the compiler for the statements in the loop function. They have been simplified slightly and a description added. The first column shows the address in memory of that instruction. Computers store programs and data in numbered locations. When a program is running, the processor takes machine code instructions from a location and performs them. It then moves down memory to the next instruction. The instructions from the loop function are stored in memory starting at location number 83.

Figure 2 ESP32 Assembler table
Figure 2: ESP32 Assembler table

The second column shows the machine code values stored in the ESP32. The first instruction is made up of three bytes which have the values 0xfd (in hex), 0x25, and 0x92. When the program is running, the ESP32 decodes and performs these instructions.

The opcode column contains the name of the operator, and the operands are the things that the operator works on. The opcode and operands columns aren’t needed by the ESP32: it only needs the machine code bytes. Those two columns are just for us to read. From them, we can work out that the variable i is being held in location 40018, and the variable j is held in location 4001C. It is also worth noting that the ESP32 performs subtraction by adding a negative number.

Breaking in is hard to do

If the loop function above is not doing what we think it should be, then we can look at the values in i and  j each time it runs. One way to do this would be to replace the machine code instruction at location 83 with an instruction that jumps into some debugging code that we can use to view the contents of our variables. When the program reaches this statement in the program, it would enter our debugger. This is called setting a breakpoint in the code. The debugger could show the contents of the registers and then we could tell the debugger to jump back into the loop function and continue execution of our program.

Figure 3 Wiring diagram for connecting an ESP32‑PROG (left) to a DOIT ESP32 (right)
Figure 3: Wiring diagram for connecting an ESP32‑PROG (left) to a DOIT ESP32 (right)

To create a breakpoint, the debugger program uses information provided by the compiler which tells the debugger where all the variables are stored and the location of each program statement. This information is produced when a program is compiled in ‘debug’ mode. The debugger uses this to work out where to insert the breakpoint code that will pause the program. This works well if the debugger is running on the same computer as the program being debugged. However, when we are writing programs for an embedded device, this is not the case. ESP32 code is sent from our computer into the target device to run. There is no way that the debugger can set a breakpoint by modifying the program code because it doesn’t have access to it. So, how can we put breakpoints into code running inside an embedded device?

We’ve been expecting you, Mr Bond

In the early days of embedded development, developers used versions of processors called ‘bond-out’ devices. These were special versions of processors which brought out the internal signals, including the address lines that identified the memory location that the hardware was accessing at any given instant. These chips were made by ‘bonding’ extra wires to the internal circuitry, hence the name.

Developers used hardware that monitored the addresses being used and detected when particular locations were being read or written. This extra hardware, called an ‘in-circuit emulator’, was the only way to debug early embedded code. To debug our loop function, we would tell the hardware to stop the device when it detected an attempt to read from the program memory at address 83 (where the machine code for the loop function starts). The circuitry would then read the registers in the device and allow us to view their contents. This method worked well, but the emulators were expensive and only large companies could afford them.

Figure 04 Debugging with Visual Studio Code
Figure 04: Debugging with Visual Studio Code

Enter JTAG

As the power and complexity of microprocessors grew, it became harder to make bond-outs to expose all the internal signals that make hardware debugging possible. To address this, manufacturers formed a Joint Tag Action Group (JTAG) to define standards by which a device can expose its internal state using just a few pins.

Many circuit boards have pins labelled JTAG which are used during manufacture and testing. Sometimes these pins can also be used for hardware debugging. Not all processors support hardware debugging connections. The ATmega328P processor used in the Arduino Uno cannot be debugged in this way. However, the ESP32 does provide these connections. Some of the general-purpose input/output (GPIO) pins on an ESP32 can be used as JTAG connectors. To debug code running in hardware, you’ll need some way of connecting your development computer to the JTAG signals on the target device. Espressif (the same company that makes the ESP32) produces a great device for this. It is called the ESP32-PROG.

The ESP32-PROG

You can pick up an ESP32-PROG device for around £15 or so. It can also be used to program an ESP32. It can be connected via a ribbon cable or you can use DuPont cables (socket to socket), as shown in Figure 1.

The table above shows the connections between an ESP32 and the ESP-PROG device.

Figure 3 shows how the socket on the ESP-PROG can be connected to an ESP32 device. Note that both the ESP32 and the ESP-PROG will need to be connected to a power source via their micro USB  connectors. You will still deploy your program using a connection to the ESP32 device. If you encounter problems with program deployment, disconnect the ESP32 USB cable from your PC and try again.

The OpenOCD connection

The debugging itself is managed by the ‘Open On-Chip Debugger’ (OpenOCD) software. This provides a connection between the hardware and the software environment that you use to write and debug your code. OpenOCD talks to the ESP-PROG device over USB. The ESP-PROG provides two serial port connections to the host computer. One can be used for programming an ESP32 via the 6-pin connector on the ESP-PROG. The other is used to control debugging.

The three pins on the bottom edge of Pico are for connecting a debugger

Debugging with Visual Studio Code and PlatformIO

Visual Studio Code is a free development environment that runs on PC, Mac, and Raspberry Pi. PlatformIO is a free plug-in for embedded development using Visual Studio Code. PlatformIO includes the OpenOCD framework. A PlatformIO project contains a platform.ini file that contains the project configuration options. We need to edit this file and add two lines to our configuration:

debug_tool = esp-prog
debug_init_break = tbreak setup

Now we can open up the debug window in Visual Studio Code and start the debugger.

This shows how to connect a Pico to a Raspberry Pi for program deployment and debugging. You will need to add a USB power source to the Pico, as the connections shown are just for data
This shows how to connect a Pico to a Raspberry Pi for program deployment and debugging. You will need to add a USB power source to the Pico, as the connections shown are just for data

Hardware debugging with Raspberry Pi PICO

The Raspberry Pi Pico device exposes JTAG signals that can be used for hardware debugging. You can wire these directly to a Raspberry Pi and use that as the debugging and development platform, or you can use another Raspberry Pi Pico device as a debugging probe. 

The Pico documentation gives detailed instructions on how to do this here. You can use the GNU Debugger to debug a program from the command line.

(gdb) b main
Breakpoint 1 at 0x1000035c: file /home/pi/pico/pico-examples/blink/blink.c, line 9.
(gdb) continue
Continuing.
Thread 1 hit Breakpoint 1, main () at /home/pi/pico/pico-examples/blink/blink.c:9
9       int main() {
(gdb) step
14          gpio_init(LED_PIN);

The statements above are from a GDB debug session investigating the blink demo program for the Pico. The debugging commands that were entered are shown in bold. You can see a breakpoint being set on the main method, and then the program stepping on from the breakpoint to the first statement which initialises the LED. If you want to use Visual Studio Code to debug your programs on Raspberry Pi, you can do this as well.

Hardware debugging for the win

Hardware debugging is very powerful. It lets you look inside your devices to see exactly what they are doing. You do need to be a bit careful when you use it sometimes, because the debugging process stops the target device and all background processes. On a device like the ESP32, this can cause problems with WiFi and Bluetooth connections being maintained during debugging. However, given the low cost of getting started, you should definitely consider adding the technique to your armoury of tools.

Issue 43 of HackSpace magazine is on sale NOW!

Each month, HackSpace magazine brings you the best projects, tips, tricks and tutorials from the makersphere. You can get it from the Raspberry Pi Press online store or your local newsagents.

HackSpace issue 43 cover

As always, every issue is free to download from the HackSpace magazine website.

The post Debugging embedded software with Raspberry Pi Pico appeared first on Raspberry Pi.

Make a Raspberry Pi Pico-based Midi Fighter | HackSpace 43

Par : Liz Clark

MIDI Fighter-style controllers (MIDI controllers with grids of arcade buttons) have been a staple of the DIY MIDI controller community for years. This project, featured in the latest issue of HackSpace magazine, continues that tradition with the Raspberry Pi Pico. A grid of 16 arcade buttons lets you play MIDI notes faster than you can yell “Hadouken!”, either live with hardware or with your digital audio workstation (DAW) of choice.

Do you think they painted the studio bright pink especially? Perfect match for the purple MIDI
Do you think they painted the studio bright pink especially? Perfect match for the purple MIDI

The Pico is the perfect board for a project like this. With all the GPIO pins, you can directly wire your inputs and outputs without issue. The copious GPIO also allows this MIDI controller to have some special features. There is a screen with a GUI representing the 4×4 button grid, along with the assigned MIDI note numbers. Below the screen is a five-way navigation switch that allows you to select the individual buttons and adjust their MIDI note number on the fly rather than having to adjust the code.

Need more buttons? Add a GPIO expander
Need more buttons? Add a GPIO expander

Finally, there is an AW9523 expander board for control over the arcade buttons’ LEDs. Both the screen and AW9523 are Adafruit STEMMA boards, which means they can be chained together to work over I2C.

Of course, there are some parts of this project that are optional, like the buttons’ LEDs and the screen. Feel free to use this build as a jumping-off point for a simpler MIDI controller or change up some of the features to better suit your needs.

All the grounds get connected together
All the grounds get connected together

Inspiration

Noé Ruiz and I love to collaborate on projects together. We’ve worked on a few MIDI projects in the past, and had discussed wanting to do a MIDI Fighter at some point. The MIDI Fighter-style controller also has a special place in my maker heart, since it was my very first DIY MIDI project that I worked on a few years ago. It had code written with Arduino, and was one of my first big soldering projects as well.

When the Raspberry Pi Pico came out, Noé and I thought it would be perfect for a MIDI Fighter, since it had so many GPIO. Noé also wanted to add another feature: the ability to change MIDI notes on the fly instead of having to edit the code. Noé is an accomplished beat drummer and felt that this feature would streamline his live drumming process when working on a beat with his DAW and software instruments. I was excited for the challenge to implement that feature and code up a user-friendly GUI. I think that it really makes this version of the classic MIDI Fighter-style controller stand out from the crowd.

Usage

The Raspberry Pi Pico MIDI Fighter has features that make it ideal for both playing live and noodling at home working on a track. You can use it with your computer’s DAW over USB and change the assigned MIDI notes on the fly for different settings or to different note input options. The fast and accurate nature of the arcade buttons makes them great candidates for live beat making and performance.

3D printed standoffs make assembly easy
3D printed standoffs make assembly easy

For more on this project’s 3D-printed case, assembly and code, head to page 52 of the latest issue of HackSpace magazine.

And an in-depth, step-by-step tutorial by myself and Noé Ruiz is available on the Adafruit Learning System.

Issue 43 of HackSpace magazine is on sale NOW!

Each month, HackSpace magazine brings you the best projects, tips, tricks and tutorials from the makersphere. You can get it from the Raspberry Pi Press online store or your local newsagents.

HackSpace issue 43 cover

As always, every issue is free to download from the HackSpace magazine website.

The post Make a Raspberry Pi Pico-based Midi Fighter | HackSpace 43 appeared first on Raspberry Pi.

How to add LoRaWAN to Raspberry Pi Pico

Arguably the winner of the standards war around wide area networking protocols for the Internet of Things, LoRaWAN is a low-powered, low-bandwidth, and long-range protocol. Intended to connect battery-powered remote sensors back to the internet via a gateway, on a good day, with a reasonable antenna, you might well get 15km of range from an off-the-shelf LoRa radio. The downside is that the available bandwidth will be measured in bytes, not megabytes, or even kilobytes.

An Adafruit RFM95W LoRa Radio breakout connected to a Raspberry Pi Pico.
An Adafruit RFM95W LoRa Radio breakout connected to a Raspberry Pi Pico

Support for LoRa connectivity for Raspberry Pi Pico was put together by Sandeep Mistry, the author of the Arduino LoRa library, who more recently also gave us Ethernet support for Pico. His library adds LoRa support for Pico and other RP2040-based boards using the Semtech SX1276 radio module. That means that breakouts like Adafruit’s RFM95W board, as well as their LoRa FeatherWing, are fully supported.

LoRaWAN coverage?

To make use of a LoraWAN-enabled Pico you’re going to need to be in range of a LoRa gateway. Fortunately there is The Things Network, an open-source community LoRaWAN network that has global coverage.

About The Things Network

Depending on where you are located, it’s quite possible that you’re already in coverage. However, if you aren’t, then you needn’t worry too much.

A map of The Things Network gateways in the United Kingdom

The days when the cost of a LoRaWAN base station was of the order of several thousand dollars are long gone. You can now pick up a LoRa gateway for around £75. However I built my own gateway a couple of years ago. Unsurprisingly, perhaps, it was based around a Raspberry Pi.

Getting the source

If you already have the Raspberry Pi Pico toolchain set up and working, make sure your pico-sdk checkout is up to date, including submodules. If not, you should first set up the C/C++ SDK and then afterwards you need to grab the project from GitHub.

$ git clone --recurse-submodules https://github.com/sandeepmistry/pico-lorawan.git
$ cd pico_lorawan

Make sure you have your PICO_SDK_PATH set before before proceeding. For instance, if you’re building things on a Raspberry Pi and you’ve run the pico_setup.sh script, or followed the instructions in our Getting Started guide, you’d point the PICO_SDK_PATH to

$ export PICO_SDK_PATH = /home/pi/pico/pico-sdk

Afterwards you are ready to build both the library and the example applications. But before you do that we need to do two other things: configure the cloud infrastructure where our data is going to go, and wire up our LoRa radio board to our Raspberry Pi Pico.

Set up an application

The Things Network is currently migrating from the V2 to V3 stack. Since my home gateway was set up a couple of years ago, I’m still using the V2 software and haven’t migrated yet. I’m therefore going to build a V2-style application. However, if you’re using a public gateway, or building your own gateway, you probably should build a V3-style application. The instructions are similar, and you should be able to make your way through based on what’s written below. Just be aware that there is a separate Network Console for the new V3 stack and things might look a little different.

Migration from TTN V2 to V3

While any LoRa device in range of your new gateway will have its packets received and sent upstream to The Things Network, the data packets will be dropped on the ground unless they have somewhere to go. In other words, The Things Network needs to know where to route the packets your gateway is receiving.

In order to give it this information, we first need to create an application inside The Things Network Console. To do this all you’ll need to do is type in a unique Application ID string — this can be anything — and the console will generate an Application EUI and a default Access Key which we’ll use to register our devices to our application.

Adding an application

Once we’ve registered an application, all we have to do then is register our individual device — or later perhaps many devices — to that application, so that the backend knows where to route packets from that device.

Registering a device

Registering our device can be done from the application’s page in the console.

Registering a device to an application

The Device ID is a human-readable string to identify our remote device. Since RFM9W breakout board from Adafruit ships with a sticker in the same bag as the radio with a unique identifier written on it we can use that to postpend a string to uniquely identify our Pico board, so we end up with something like pico-xy-xy-xy-xy-xy-xy as our Device ID.

We’ll also need to generate a Device EUI2. This is a 64-bit unique identifier. Here again we can use the unique identifier from the sticker, except this time we can just pad it with two leading zeros, 0000XYXYXYXYXYXY, to generate our Device EUI. You could also use pico_get_unique_board_id( ) to generate the Device EUI.

If you take a look at your Device page after registration you’ll need the Application EUI2 and Application Key2 to let your board talk to the LoRa network, or more precisely to let the network correctly route packets from your board to your application.

2 Make a note of your Device EUI, Application EUI, and Application Key.

Wiring things up on a breadboard

Now we’ve got our cloud backend set up, the next thing we need to do is connect our Pico to the LoRa breakout board. Unfortunately the RFM95W breakout isn’t really that breadboard-friendly. At least it’s not breadboard-friendly if you need access to the radio’s pins on both sides of the board like we do for this project — in this case the breakout is just a little bit too wide for a standard breadboard.

Connecting a Raspberry Pi Pico to an Adafruit RFM9x LoRa radio board.
Connecting a Raspberry Pi Pico to an Adafruit RFM95W LoRa Radio breakout

Fortunately it’s not really that much of a problem, but you will probably need to grab a bunch of male-to-female jumper wires along with your breadboard. Go ahead and wire up the RFM95W module to your Raspberry Pi Pico. The mapping between the pins on the breakout board and your Pico should be as follows:

Pico RP20401 SX1276 Module RFM95W Breakout
3V3 (OUT) VCC VIN
GND GND GND GND
Pin 10 GP7 DIO0 G0
Pin 11 GP8 NSS CS
Pin 12 GP9 RESET RST
Pin 14 GP10 DIO1 G1
Pin 21 GP16 (SPI0 RX) MISO MISO
Pin 24 GP18 (SPI0 SCK) SCK SCK
Pin 25 GP19 (SPI0 TX) MOSI MOSI
Mapping between physical pins, RP2040 pins, SX1276 module, and RFM95W breakout

These pins are the library default and can be changed in software.

Building and deploying software

Now we have our backend in the cloud set up, and we’ve physically “built” our radio, we can build and deploy our LoRaWAN application. One of the example applications provided by the library will read the temperature from the on-chip sensor on the RP2040 microcontroller and send it periodically to your Things Network application over the LoRaWAN radio.

void internal_temperature_init() {
    adc_init();
    adc_select_input(4);
    adc_set_temp_sensor_enabled(true);
}

float internal_temperature_get() {
    float adc_voltage = adc_read() * 3.3f / 4096;
    float adc_temperature = 27 - (adc_voltage - 0.706f) / 0.001721f;

    return adc_temperature;
}

Go ahead and change directory to the otaa_temperature_led example application in your checkout. This example uses OTAA, so we’ll need the Device EUI, Application EUI, and Application Key we created.

$ cd examples/otaa_temperature_led/

Open the config.h file in your favourite editor and change the REGION, DEVICE_EUI, APP_EUI, and APP_KEY to the values shown in the Network Console. The code is expecting the (default) string format, without spaces between the hexadecimal digits, rather than the byte array representation.

#define LORAWAN_REGION          LORAMAC_REGION_EU868
#define LORAWAN_DEVICE_EUI      "Insert your Device EUI"
#define LORAWAN_APP_EUI         "Insert your Application EUI"
#define LORAWAN_APP_KEY         "Insert your App Key"
#define LORAWAN_CHANNEL_MASK    NULL

I’m located in the United Kingdom, with my LoRa radio broadcasting at 868MHz, so I’m going to set my region to LORAMAC_REGION_EU868. If you’re in the United States you’re using 915MHz, so need to set your region to LORAMAC_REGION_US915.

Then after you’ve edited the config.h file you can go ahead and build the example applications.

$ cd ../..
$ mkdir build
$ cd build
$ cmake ..
$ make

If everything goes well you should have a UF2 file in build/examples/otaa_temperature_led/ called pico_lorawan_otaa_temperature_led.uf2. You can now load this UF2 file onto your Pico in the normal way.

Grab your Raspberry Pi Pico board and a micro USB cable. Plug the cable into your Raspberry Pi or laptop, then press and hold the BOOTSEL button on your Pico while you plug the other end of the micro USB cable into the board. Then release the button after the board is plugged in.

A disk volume called RPI-RP2 should pop up on your desktop. Double-click to open it, and then drag and drop the UF2 file into it. If you’re having problems, see Chapter 4 of our Getting Started guide for more information.

Your Pico is now running your LoRaWAN application, and if you want to you should be able to see some debugging information by opening a USB Serial connection to your Pico. Open a Terminal window and start minicom.

$ minicom -D /dev/ttyACM0

Sending data

However, you’ll need to turn to the Network console to see the real information. You should see an initial join message, followed by a number of frames. Each frame represents a temperature measurement sent by your Pico via LoRaWAN and the Gateway to The Things Network application.

Data coming via LoRaWAN to the Things Network
Data coming via LoRaWAN to The Things Network

The payload value is the temperature measured by the Raspberry Pi Pico’s internal temperature sensor in hexadecimal. It’s a bit outside the scope of this article, but you can now add a decoder and integrations that allow you decode the data from hexadecimal into human-readable data and then, amongst various other options, save it to a database. To illustrate the power of what you can do here, go to the “Payload Formats” tab of your application and enter the following Javascript in the “decoder” box,

function Decoder(bytes, port) {
 
  var decoded = {};
  decoded.temp = bytes[0];
  
  return decoded;
}

then scroll down and hit the green “save payload functions” button.

Returning to the “Data” tab you should see that the payload, in hexidecimal, is now post-pended with the temperature in Celcius. Our simple decoder has taken our payload and translated it back into a Javascript object.

Sending commands

As well as sending temperature data, the example application will also let you toggle the LED on your Raspberry Pi Pico directly from The Things Network console.

Sending data back to your Raspberry Pi Pico via LoRaWAN

Go to the Device page in the Network Console and type “01” into the Downlink Payload box, and hit the “Send” button. Then flip to the Data tab. You should see a “Download scheduled” line, and if you continue to watch you should see the byte downlinked. When that happens the on-board LED on your Raspberry Pi Pico should turn on! Returning to the Network Console and typing “00” into the Payload box will (eventually) turn the Pico’s LED off.

Remember that LoRaWAN is long-range, but low-bandwidth. You shouldn’t expect an instant response to a downlinked command.

Where now?

The OTAA example application is a really nice skeleton for you to build on that will let you take data and send it to the cloud over LoRa, as well as send commands back from the cloud to your LoRa-enabled Pico.

Arm Innovation Coffee – The Things Network

There will be more discussion around the Things Network and a live demo of LoRaWAN from a Raspberry Pi Pico during this week’s Arm Innovation Coffee at 10:00 PDT (18:00 BST) this Thursday (29 April).

Wrapping up

Support for developing for Pico can be found on the Raspberry Pi forums. There is also an (unofficial) Discord server where a lot of people active in the community seem to be hanging out. Feedback on the documentation should be posted as an Issue to the pico-feedback repository on GitHub, or directly to the relevant repository it concerns.

All of the documentation, along with lots of other help and links, can be found on the Getting Started page. If you lose track of where that is in the future, you can always find it from your Pico: to access the page, just press and hold the BOOTSEL button on your Pico, plug it into your laptop or Raspberry Pi, then release the button. Go ahead and open the RPI-RP2 volume, and then click on the INDEX.HTM file.

That will always take you to the Getting Started page.

The post How to add LoRaWAN to Raspberry Pi Pico appeared first on Raspberry Pi.

Custom USB games controllers with Raspberry Pi Pico | HackSpace 42

Games controllers – like keyboards – are very personal things. What works for one person may not work for another. Why, then, should we all use almost identical off-the-shelf controllers? In the latest issue of HackSpace magazine, we take a look at how to use Raspberry Pi Pico to create a controller that’s just right for you.

home made retro gaming joystick box
Gaming like it’s 1989

We’ll use CircuitPython for this as it has excellent support for USB interfaces. The sort of USB devices that we interact with are called human interface devices (HIDs), and there are standard protocols for common HIDs, including keyboards and mice. This is why, for example, you can plug almost any USB keyboard into almost any computer and it will just work, with no need to install drivers.

We’ll be using the Keyboard type, as that works best with the sorts of games that this author likes to play, but you can use exactly the same technique to simulate a mouse or a gamepad.

Before we get onto this, though, let’s take a look at the buttons and how to wire them up.

We’re going to use eight buttons: four for direction, and four as additional ‘action’ buttons. We’ll connect these between an I/O pin and ground. You can use any I/O pin you like. We’re going to use slightly different ones in two different setups, just because they made sense with the physical layout of the hardware. Let’s take a look at the hardware we’re using. Remember, this is just the hardware we want to use. The whole idea of this is to create a setup that’s right for you, so there’s no need to use the same. Think about how you want to interact with your games and take a look at the available input devices and build what you want.

The connectors should just push onto the buttons and joysticks
The connectors should just push onto the buttons and joystick

The first setup we’re creating is an Arcade box. This author would really like an arcade machine in his house. However, space limitations mean that this isn’t going to be possible in the near future. The first setup, then, is an attempt to recreate the control setup of an arcade machine, but use it to play games on a laptop rather than a full-sized cabinet.

Arcade controls are quite standard, and you can get them from a range of sources. We used one of Pimoroni’s Arcade Parts sets, which includes a joystick and ten buttons (we only used four of these). The important thing about the joystick you pick is that it’s a button-based joystick and not an analogue one (sometimes called a dual-axis joystick), as the latter won’t work with a keyboard interface. If you want to use an analogue joystick, you’ll need to switch the code around to use a mouse or gamepad as an input device.

You can solder the pin headers straight onto Pico
You can solder the pin headers straight onto Pico

As well as the electronics, you’ll need some way of mounting them. We used a wooden craft box. These are available for about £10 from a range of online or bricks and mortar stores. You can use anything that is strong enough to hold the components.

The second setup we’re using is a much simpler button-based system on breadboard-compatible tactile buttons and protoboard. It’s smaller, cheaper, and quicker to put together. The protoboard holds everything together, so there’s nothing extra to add unless you want to. You can personalise it by selecting different-sized buttons, changing the layout, or building a larger chassis around this.

Insert coin to continue

Let’s take a look at the arcade setup first. The joystick has five pins. One is a common ground and the others are up, down, left, and right. When you push the joystick up, a switch closes, linking ground to the up pin. On our joystick the outermost pin is ground, but it’s worth checking on your joystick which pin is which by using a multimeter. Select continuity mode and, if you push the joystick up, you should find a continuous connection between the up pin and ground. A bit of experimentation should confirm which pin is which.

In order to read the pins, we just need to connect the directional output from the joystick to an I/O pin on Pico. We can use one of Pico’s internal pull-up resistors to pull the pin high when the button isn’t pressed. Then, when the button is pressed, it will connect to ground and read low. The joystick should come with a cable that slots onto the joystick. This should have five outputs, and this conveniently slots into the I/O outputs of Pico with a ground on one end.

You can solder the pin headers straight onto Pico
You can solder the pin headers straight onto Pico

The buttons, similarly, just need to be connected between ground and an I/O pin. These came with cables that pushed onto the button and plugged into adjacent pins. Since Pico has eight grounds available, there are enough that each button can have its own ground, and you don’t have to mess around joining cables together.

Once all the cables are soldered together, it’s just a case of building the chassis. For this, you need five large holes (one for the joystick and four for the buttons). We didn’t have an appropriately sized drill bit and, given how soft the wood on these boxes is, a large drill bit may have split the wood anyway. Instead, we drilled a 20 mm hole and then used a rotary tool with sanding attachment to enlarge the hole until it was the right size. You have to go quite easy with both the drill and the sanding tool to avoid  turning everything into shards of broken wood. Four small holes then allow bolts to keep the joystick in place (we used M5 bolts). The buttons just push into place.

With a combination of small sections of wire and jumpers, you can create whatever pattern of wiring you like on protoboard

With a combination of small sections of wire and jumpers, you can create whatever pattern of wiring you like on protoboard

The only remaining thing was a 12 mm hole for a micro USB cable to pass through to Pico. If you don’t have a 12 mm drill bit, two overlapping smaller holes may work if you’re careful.

The buttons just push-fit into place, and that’s everything ready to go.

A smaller approach

Our smaller option used protoboard over the back of Pico. Since we didn’t want to block the BOOTSEL button, we only soldered it over part of Pico. However, before soldering it on at all, we soldered the buttons in place.

Tactile switches typically have four connections. Well, really they have two connections, but each connection has two tabs that fit into the protoboard. This means that you have to orientate them correctly. Again, your multimeter’s continuity function will confirm which pins are connected and which are switched.

Protoboard is a PCB that contains lots and lots of holes and nothing else. You solder your components into the holes and then you have to create connections between them.

We placed the buttons in the protoboard in positions we liked before worrying about the wiring. First, we looked to connect one side of each switch to ground. To minimise the wiring, we did this in two groups. We connected one side of each of the direction buttons together and then linked them to ground. Then we did the same to all the action buttons.

There are two ways of connecting things on protoboard. One is to use jumper wire. This works well if the points are more than a couple of holes apart. For holes that are next to each other, or very close, you can bridge them. On some protoboard (which doesn’t have a solder mask), you might simply be able to drag a blob of solder across with your soldering iron so that it joins both holes. On protoboard with solder mask, this doesn’t work quite so well, so you need to add a little strand of wire in a surface-mount position between the two points and solder it in. If you’ve got a pair of tweezers to hold the wire in place while you solder it, it will be much easier.

For longer connections, you’ll need to use jumper wire. Sometimes you’ll be able to poke it through the protoboard and use the leg to join. Other times you’ll have to surface-mount it. This all sounds a bit complicated, but while it can be a bit fiddly, it’s all fairly straightforward once you put solder to iron.

Program it up

Now that we’ve got the hardware ready, let’s code it up. You’ll first need to load CircuitPython onto your Pico. You can download the latest release from circuitpython.org. Press the BOOTSEL button as you plug Pico into your USB port, and then drag and drop the downloaded UF2 file onto the RP2 USB drive that should appear.

We’ll use Mu to program Pico. If you’ve not used CircuitPython before, it’s probably worth having a quick look through the ’getting started’ guide.

The code to run our games controller is:

import board
import digitalio
import gamepad
import time
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

kbd = Keyboard(usb_hid.devices)

keycodes = [Keycode.UP_ARROW, Keycode.DOWN_ARROW, Keycode.LEFT_ARROW, Keycode.RIGHT_ARROW,                   Keycode.X, Keycode.Z, Keycode.SPACE, Keycode.ENTER]

pad = gamepad.GamePad(
    digitalio.DigitalInOut(board.GP12),
    digitalio.DigitalInOut(board.GP14),
    digitalio.DigitalInOut(board.GP9),
    digitalio.DigitalInOut(board.GP15),
    digitalio.DigitalInOut(board.GP16),
    digitalio.DigitalInOut(board.GP17),
    digitalio.DigitalInOut(board.GP18),
    digitalio.DigitalInOut(board.GP20),
)
last_pressed = 0
while True:
    this_pressed = pad.get_pressed()
    if (this_pressed != last_pressed):
        for i in range(8):
            if (this_pressed & 1<<i) and not (last_pressed & 1<<i):
                kbd.press(keycodes[i])
            if (last_pressed & 1<<i) and not (this_pressed & 1<<i):
                kbd.release(keycodes[i])
        last_pressed = this_pressed
    time.sleep(0.01)

This uses the HID keyboard object (called kbd) to send key press and release events for different key codes depending on what buttons are pressed or released. We’ve used the gamepad module that is for keeping track of up to eight buttons. When you initialise it, it will automatically add pull-up resistors and set the I/O pins to input. Then, it will keep track of what buttons are pressed. When you call get_pressed(), it will return a byte of data where each digit corresponds to an I/O pin. So, the following number (in binary) means that the first and third buttons have been pressed: 00000101. This is a little confusing, because this is the opposite order to how the I/Os are passed when you initialise the GamePad object.

The while loop may look a little unusual as it’s not particularly common to use this sort of binary comparison in Python code, but in essence, it’s just looking at one bit at a time and seeing either: it’s now pressed but wasn’t last time the loop ran (in which case, it’s a new button press and we should send it to the computer), or it isn’t pressed this loop but was the previous loop (in which case, it’s newly released so we can call the release method).

The << operator shifts a value by a number of bits to the left. So, 1<<2 is 100, and 1<<3 is 1000. The & operator is bitwise and so it looks at a binary number and does a logical AND on each bit in turn. Since the right-hand side of the & is all zeros apart from one bit (at a different position depending on the value of i), the result will be dependent on whether the value of this_pressed or last_pressed is 1 or 0 at the position i. When you have an if condition that’s a number, it’s true if the number is anything other than 0. So, (this_pressed & 1<<2) will evaluate to true if there’s a 1 at position 2 in the binary form of this_pressed.  In our case, that means if the joystick is pushed left.

You can grab this code from the following link – hsmag.cc/USBKeyboard. Obviously, you will need to update the GPIO values to the correct ones for your setup when you initialise GamePad.

We’ve taken a look at two ways to build a gamepad, but it’s up to you how you want to design yours.   

Issue 42 of HackSpace magazine is on sale NOW!

hackspace issue 42 cover

Each month, HackSpace magazine brings you the best projects, tips, tricks and tutorials from the makersphere. You can get it from the Raspberry Pi Press online store or your local newsagents. As always, every issue is free to download from the HackSpace magazine website.

The post Custom USB games controllers with Raspberry Pi Pico | HackSpace 42 appeared first on Raspberry Pi.

Drag-n-drop coding for Raspberry Pi Pico

Introducing Piper Make: a Raspberry Pi Pico-friendly drag-n-drop coding tool that’s free for anyone to use.

piper make screenshot
The ‘Digital View’ option displays a dynamic view of Raspberry Pi Pico showing GPIO states

Edtech startup Piper, Inc. launched this brand new browser-based coding tool on #PiDay. If you already have a Raspberry Pi Pico, head to make.playpiper.com and start playing with the coding tool for free.

Pico in front of Piper Make screen
If you already have a Raspberry Pi Pico, you can get started right away

Complete coding challenges with Pico

  • Piper Make challenges 01
Learn about circuits and sensors as you complete each coding challenge

The block coding environment invites you to try a series of challenges. When you succeed in blinking an LED, the next challenge is opened up to you. New challenges are released every month, and it’s a great way to guide your learning and give you a sense of achievement as you check off each task.

But I don’t have a Pico or the components I need!

You’re going to need some kit to complete these challenges. The components you’ll need are easy to get hold of, and they’re things you probably already have lying around if you like to tinker, but if you’re a coding newbie and don’t have a workshop full of trinkets, Piper makes it easy for you. You can join their Makers Club and receive a one-off Starter Kit containing a Raspberry Pi Pico, LEDs, resistors, switches, and wires.

Piper Make starter kit
The Starter Kit contains everything you need to complete the first challenges

If you sign up to Piper’s Monthly Makers Club you’ll receive the Starter Kit, plus new hardware each month to help you complete the latest challenge. Each Raspberry Pi Pico board ships with Piper Make firmware already loaded, so you can plug and play.

Piper Make starter kit in action
Trying out the traffic light challenge with the Starter Kit

If you already have things like a breadboard, LEDs, and so on, then you don’t need to sign up at all. Dive straight in and get started on the challenges.

I have a Raspberry Pi Pico. How do I play?

A quick tip before we go: when you hit the Piper Make landing page for the first time, don’t click ‘Getting Started’ just yet. You need to set up your Pico first of all, so scroll down and select ‘Setup my Pico’. Once you’ve done that, you’re good to go.

Scroll down on the landing page to set up your Pico before hitting ‘Getting Started’

The post Drag-n-drop coding for Raspberry Pi Pico appeared first on Raspberry Pi.

Graphic routines for Raspberry Pi Pico screens

Pimoroni has brought out two add‑ons with screens: Pico Display and Pico Explorer. A very basic set of methods is provided in the Pimoroni UF2 file. In this article, we aim to explain how the screens are controlled with these low-level instructions, and provide a library of extra routines and example code to help you produce stunning displays.

You don't have to get creative with your text placement, but you can
You don’t have to get creative with your text placement, but you can

You will need to install the Pimoroni MicroPython UF2 file on your Pico and Thonny on your computer.

All graphical programs need the following ‘boilerplate’ code at the beginning to initialise the display and create the essential buffer. (We’re using a Pico Explorer – just change the first line for a Pico Display board.)

import picoexplorer as display
# import picodisplay as display
#Screen essentials
width = display.get_width()
height = display.get_height()
display_buffer = bytearray(width * height * 2)
display.init(display_buffer)

The four buttons give you a way of getting data back from the user as well as displaying information
The four buttons give you a way of getting data back from the user as well as displaying information

This creates a buffer with a 16-bit colour element for each pixel of the 240×240 pixel screen. The code invisibly stores colour values in the buffer which are then revealed with a display.update() instruction.

The top-left corner of the screen is the origin (0,0) and the bottom-right pixel is (239,239).

Supplied methods

display.set_pen(r, g, b)

Sets the current colour (red, green, blue) with values in the range 0 to 255.

grey = display.create_pen(100,100,100)

Allows naming of a colour for later use.

display.clear()

Fills all elements in the buffer with the current colour.

display.update()

Makes the current values stored in the buffer visible. (Shows what has been written.)

display.pixel(x, y)

Draws a single pixel with the current colour at
point(x, y).

display.rectangle(x, y ,w ,h) 

Draws a filled rectangle from point(x, y), w pixels wide and h pixels high.

display.circle(x, y, r)

Draws a filled circle with centre (x, y) and radius r.

display.character(78, 112, 5 ,2)

Draws character number 78 (ASCII = ‘N’) at point (112,5) in size 2. Size 1 is very small, while 6 is rather blocky.

display.text("Pixels", 63, 25, 200, 4)

Draws the text on the screen from (63,25) in size 4 with text wrapping to next line at a ‘space’ if the text is longer than 200 pixels. (Complicated but very useful.)

display.pixel_span(30,190,180)

Draws a horizontal line 180 pixels long from point (30,190).

display.set_clip(20, 135, 200, 100)

While the screens are quite small in size, they have plenty of pixels for display
While the screens are quite small in size, they have plenty of pixels for display

After this instruction, which sets a rectangular area from (20,135), 200 pixels wide and 100 pixels high, only pixels drawn within the set area are put into the buffer. Drawing outside the area is ignored. So only those parts of a large circle intersecting with the clip are effective. We used this method to create the red segment.

display.remove_clip()

This removes the clip.

display.update()

This makes the current state of the buffer visible on the screen. Often forgotten.

if display.is_pressed(3): # Y button is pressed ?

Read a button, numbered 0 to 3.

You can get more creative with the colours if you wish
You can get more creative with the colours if you wish

This code demonstrates the built-in methods and can be downloaded here.

# Pico Explorer - Basics
# Tony Goodhew - 20th Feb 2021
import picoexplorer as display
import utime, random
#Screen essentials
width = display.get_width()
height = display.get_height()
display_buffer = bytearray(width * height * 2)
display.init(display_buffer)

def blk():
    display.set_pen(0,0,0)
    display.clear()
    display.update()

def show(tt):
    display.update()
    utime.sleep(tt)
   
def title(msg,r,g,b):
    blk()
    display.set_pen(r,g,b)
    display.text(msg, 20, 70, 200, 4)
    show(2)
    blk()

# Named pen colour
grey = display.create_pen(100,100,100)
# ==== Main ======
blk()
title("Pico Explorer Graphics",200,200,0)
display.set_pen(255,0,0)
display.clear()
display.set_pen(0,0,0)
display.rectangle(2,2,235,235)
show(1)
# Blue rectangles
display.set_pen(0,0,255)
display.rectangle(3,107,20,20)
display.rectangle(216,107,20,20)
display.rectangle(107,3,20,20)
display.rectangle(107,216,20,20)
display.set_pen(200,200,200)
#Compass  points
display.character(78,112,5,2)   # N
display.character(83,113,218,2) # S
display.character(87,7,110,2)   # W
display.character(69,222,110,2) # E
show(1)
# Pixels
display.set_pen(255,255,0)
display.text("Pixels", 63, 25, 200, 4)
display.set_pen(0,200,0)
display.rectangle(58,58,124,124)
display.set_pen(30,30,30)
display.rectangle(60,60,120,120)
display.update()
display.set_pen(0,255,0)
for i in range(500):
    xp = random.randint(0,119) + 60
    yp = random.randint(0,119) + 60
    display.pixel(xp,yp)
    display.update()
show(1)
# Horizontal line
display.set_pen(0,180,0)
display.pixel_span(30,190,180)
show(1)
# Circle
display.circle(119,119,50)
show(1.5)
display.set_clip(20,135, 200, 100)
display.set_pen(200,0,0)
display.circle(119,119,50)
display.remove_clip()

display.set_pen(0,0,0)
display.text("Circle", 76, 110, 194, 3)
display.text("Clipped", 85, 138, 194, 2)
display.set_pen(grey) # Previously saved colour
# Button Y
display.text("Press button y", 47, 195, 208, 2)
show(0)
running = True
while running:
    if display.is_pressed(3): # Y button is pressed ?
        running = False
blk()

# Tidy up
title("Done",200,0,0)
show(2)
blk()

Straight lines can give the appearance of curves
Straight lines can give the appearance of curves

We’ve included three short procedures to help reduce code repetition:

def blk() 

This clears the screen to black – the normal background colour.

def show(tt)

This updates the screen, making the buffer visible and then waits tt seconds.

def title(msg,r,g,b)

This is used to display the msg string in size 4 text in the specified colour for two seconds, and then clears the display.

As you can see from the demonstration, we can accomplish a great deal using just these built-in methods. However, it would be useful to be able to draw vertical lines, lines from point A to point B, hollow circles, and rectangles. If these are written as procedures, we can easily copy and paste them into new projects to save time and effort.

You don't need much to create interesting graphics
You don’t need much to create interesting graphics

In our second demonstration, we’ve included these ‘helper’ procedures. They use the parameters (t, l, r, b) to represent the (top, left) and the (right, bottom) corners of rectangles or lines.

def horiz(l,t,r):    # left, top, right

Draws a horizontal line.

def vert(l,t,b):   # left, top, bottom

Draws a vertical line.

def box(l,t,r,b):  # left, top, right, bottom

Draws an outline rectangular box.

def line(x,y,xx,yy): 

Draws a line from (x,y) to (xx,yy).

def ring(cx,cy,rr,rim): # Centre, radius, thickness

Draws a circle, centred on (cx,cy), of outer radius rr and pixel thickness of rim. This is easy and fast but has the disadvantage that it wipes out anything inside ring

def ring2(cx,cy,r):   # Centre (x,y), radius

Draw a circle centred on (cx,cy), of radius rr with a single-pixel width. Can be used to flash a ring around something already drawn on the screen. You need to import math as it uses trigonometry.

def align(n, max_chars):

This returns a string version of int(n), right aligned in a string of max_chars length. Unfortunately, the font supplied by Pimoroni in its UF2 is not monospaced.

What will you create with your Pico display?
What will you create with your Pico display?

The second demonstration is too long to print, but can be downloaded here.

It illustrates the character set, drawing of lines, circles and boxes; plotting graphs, writing text at an angle or following a curved path, scrolling text along a sine curve, controlling an interactive bar graph with the buttons, updating a numeric value, changing the size and brightness of disks, and the colour of a rectangle.  

The program is fully commented, so it should be quite easy to follow.

The most common coding mistake is to forget the display.update() instruction after drawing something. The second is putting it in the wrong place.

When overwriting text on the screen to update a changing value, you should first overwrite the value with a small rectangle in the background colour. Notice that the percentage value is right-aligned to lock the ‘units’ position. 

It’s probably not a good idea to leave your display brightly lit for hours at a time. Several people have reported the appearance of ‘burn’ on a dark background, or ‘ghost’ marks after very bright items against a dark background have been displayed for some time. We’ve seen them on our display, but no long-term harm is evident. Blanking the screen in the ‘tidy-up’ sequence at the end of your program may help.

We hope you have found this tutorial useful and that it encourages you to start sending your output to a display. This is so much more rewarding than just printing to the REPL.

If you have a Pimoroni Pico Display, (240×135 pixels), all of these routines will work on your board.

Issue 41 of HackSpace magazine is on sale NOW!

Each month, HackSpace magazine brings you the best projects, tips, tricks and tutorials from the makersphere. You can get it from the Raspberry Pi Press online store or your local newsagents. As always, every issue is free to download from the HackSpace magazine website.

The post Graphic routines for Raspberry Pi Pico screens appeared first on Raspberry Pi.

How to add Ethernet to Raspberry Pi Pico

Raspberry Pi Pico has a lot of interesting and unique features, but it doesn’t have networking. Of course this was only ever going to be a temporary inconvenience, and sure enough, over Pi Day weekend we saw both USB Ethernet and Ethernet PHY support released for Pico and RP2040.

Raspberry Pi Pico and RMII Ethernet PHY
Raspberry Pi Pico and RMII Ethernet PHY

The PHY support was put together by Sandeep Mistry, well known as the author of the noble and bleno Node.js libraries, as well as the Arduino LoRa library, amongst others. Built around the lwIP stack, it leverages the PIO, DMA, and dual-core capabilities of RP2040 to create an Ethernet MAC stack in software. The project currently supports RMII-based Ethernet PHY modules like the Microchip LAN8720.

Breakout boards for the LAN8720 can be found on AliExpress for around $1.50. If you want to pick one up next day on Amazon you should be prepared to pay somewhat more, especially if you want Amazon Prime delivery, although they can still be found fairly cheaply if you’re prepared to wait a while.

What this means is that you can now connect your $4 microcontroller to an Ethernet breakout costing less than $2 and connect it to the internet.

Building from source

If you already have the Raspberry Pi Pico toolchain set up and working, make sure your pico-sdk checkout is up to date, including submodules. If not, you should first set up the C/C++ SDK. Afterwards you need grab the the project from GitHub, along with the lwIP stack.

$ git clone git@github.com:sandeepmistry/pico-rmii-ethernet.git
$ cd pico-rmii-ethernet
$ git submodule update --init

Make sure you have your PICO_SDK_PATH set before before proceeding. For instance, if you’re building things on a Raspberry Pi and you’ve run the pico_setup.sh script, or followed the instructions in our Getting Started guide, you’d point the PICO_SDK_PATH to

$ export PICO_SDK_PATH = /home/pi/pico/pico-sdk

then after that you can go ahead and build both the library and the example application.

$ mkdir build
$ cd build
$ cmake ..
$ make

If everything goes well you should have a UF2 file in build/examples/httpd called pico_rmii_ethernet_httpd.uf2. You can now load this UF2 file onto your Pico in the normal way.

Go grab your Raspberry Pi Pico board and a micro USB cable. Plug the cable into your Raspberry Pi or laptop, then press and hold the BOOTSEL button on your Pico while you plug the other end of the micro USB cable into the board. Then release the button after the board is plugged in.

A disk volume called RPI-RP2 should pop up on your desktop. Double-click to open it, and then drag and drop the UF2 file into it. Your Pico is now running a webserver. Unfortunately it’s not going to be much use until we wire it up to our Ethernet breakout board.

Wiring things up on the breadboard

Unfortunately the most common (and cheapest) breakout for the LAN8720 isn’t breadboard-friendly, although you can find some boards that are, so you’ll probably need to grab a bunch of male-to-female jumper wires along with your breadboard.

LAN8720 breakout wired to a Raspberry Pi Pico on a breadboard.
LAN8720 breakout wired to a Raspberry Pi Pico on a breadboard (with reset button)

Then wire up the breakout board to your Raspberry Pi Pico. Most of these boards seem to be well labelled, with the left-hand labels corresponding to the top row of breakout pins. The mapping between the pins on the RMII-based LAN8720 breakout board and your Pico should be as follows:

Pico RP20401 LAN8720 Breakout
Pin 9 GP6 RX0
Pin 10 GP7 RX1 (RX0 + 1 )
Pin 11 GP8 CRS (RX0 + 2)
Pin 14 GP10 TX0
Pin 15 GP11 TX1 (TX0 + 1)
Pin 16 GP12 TX-EN (TX0 + 2)
Pin 19 GP14 MDIO
Pin 20 GP15 MDC
Pin 26 GP20 nINT / RETCLK
3V3 (OUT) VCC
Pin 38 GND GND
Mapping between physical pin number, RP2040 pin, and LAN8720 breakout

1 These pins are the library default and can be changed in software.

Once you’ve wired things up, plug your Pico into Ethernet and also via USB into your Raspberry Pi or laptop. As well as powering your Pico you’ll be able to see some debugging information via USB Serial. Open a Terminal window and start minicom.

$ minicom -D /dev/ttyACM0

If you’re having problems, see Chapter 4 of our Getting Started guide for more information.

Hopefully, so long as your router is handing out IP addresses, you should see something like this in the minicom window, showing that your Pico has grabbed an IP address using DHCP:

pico rmii ethernet - httpd                              
netif status changed 0.0.0.0                            
netif link status changed up                            
netif status changed 192.168.1.110

If you open up a browser window and type the IP address that your router has assigned to your Pico into the address bar, if everything goes well you should see the default lwIP index page:

Viewing the web page served from our Raspberry Pi Pico.

Congratulations. Your Pico is now a web server.

Changing the web pages

It turns out to be pretty easy to change the web pages served by Pico. You can find the “file system” with the default lwIP pages inside the HTTP application in the lwIP Git submodule.

$ cd pico-rmii-ethernet/lib/lwip/src/apps/http/fs
$ ls 
404.html   img/        index.html
$ 

You should modify the index.html file in situ here with your favourite editor. Afterwards we’ll need to move the file system directory into place, and then we can repackage it up using the associated makefsdata script.

$ cd ..
$ mv fs makefsdata 
$ cd makefsdata
$ perl makefsdata

Running this script will create an fsdata.c file in the current directory. You need to move this file up to the parent directory and then rebuild the UF2 file.

$ mv fsdata.c ..
$ cd ../../../../../..
$ rm -rf build
$ mkdir build
$ cd build
$ cmake ..
$ make

If everything goes well you should have a new UF2 file in build/examples/httpd called pico_rmii_ethernet_httpd.uf2 , and you can again load this UF2 file onto your Pico as before.

The updated web page served from our Raspberry Pi Pico.
The updated web page served from our Raspberry Pi Pico

On restart, wait till your Pico grabs an IP address again and then, opening up a browser window again and typing the IP address assigned to your Pico into the address bar, you should now see an updated web page.

You can go back and edit the page served from your Pico, and build an entire site. Remember that you’ll need to rebuild the fsdata.c file each time before your rebuild your UF2.

Current limitations

There are a couple of limitations on the current implementation. The RP2040 is running underclocked to just 50MHz using the RMII modules’ reference clock, while the lwIP stack is compiled with NO_SYS so neither the Netcon API nor the Socket API is enabled. Finally, link speed is set to 10 Mbps as there is currently an issue with TX at 100 Mbps.

Where next?

While the example Sandeep put together used the lwIP web server, there are a number of other library application examples we can grab and twist to our own ends, including TFTP and MQTT example applications. Beyond that, lwIP is a TCP/IP stack. Anything you can do over TCP you can now do from your Pico.

Wrapping up

Support for developing for Pico can be found on the Raspberry Pi forums. There is also an (unofficial) Discord server where a lot of people active in the new community seem to be hanging out. Feedback on the documentation should be posted as an Issue to the pico-feedback repository on GitHub, or directly to the relevant repository it concerns.

All of the documentation, along with lots of other help and links, can be found on the Getting Started page. If you lose track of where that is in the future, you can always find it from your Pico: to access the page, just press and hold the BOOTSEL button on your Pico, plug it into your laptop or Raspberry Pi, then release the button. Go ahead and open the RPI-RP2 volume, and then click on the INDEX.HTM file.

That will always take you to the Getting Started page.

The post How to add Ethernet to Raspberry Pi Pico appeared first on Raspberry Pi.

What is PIO?

Par : Alex Bate

Microcontroller chips, like our own RP2040 on Raspberry Pi Pico, offer hardware support for protocols such as SPI and I2C. This allows them to send and receive data to and from supported peripherals.

But what happens when you want to use unsupported tech, or multiple SPI devices? That’s where Programmable I/O, or PIO, comes in. PIO was developed just for RP2040, and is unique to the chip.

PIO allows you to create additional hardware interfaces, or even new types of interface. If you’ve ever looked at the peripherals on a microcontroller and thought “I need four UARTs and I only have two,” or “I’d like to output DVI video,” or even “I need to communicate with this accursed serial device I found, but there is no hardware support anywhere,” then you will have fun with PIO.

We’ve put together this handy explainer to help you understand PIO and how it can be used to add more devices to your Raspberry Pi Pico.

For more information on PIO and RP2040, check out this article from HackSpace magazine.

The post What is PIO? appeared first on Raspberry Pi.

Raspberry Pi Pico – Vertical innovation

Our Chief Operating Officer and Hardware Lead James Adams talked to The MagPi Magazine about building Raspberry Pi’s first microcontroller platform.

On 21 January we launched the $4 Raspberry Pi Pico. As I write, we’ve taken orders for nearly a million units, and are working hard to ramp production of both the Pico board itself and the chip that powers it, the Raspberry Pi RP2040.

Close up of R P 20 40 chip embedded in a Pico board
RP2040 at the heart of Raspberry Pi Pico

Microcontrollers are a huge yet largely unseen part of our modern lives. They are the hidden computers running most home appliances, gadgets, and toys. Pico and RP2040 were born of our desire to do for microcontrollers what we had done for computing with the larger Raspberry Pi boards. We wanted to create an innovative yet radically low-cost platform that was easy to use, powerful, yet flexible.

It became obvious that to stand out from the crowd of existing products in this space and to hit our cost and performance goals, we would need to build our own chip.

I and many of the Raspberry Pi engineering team have been involved in chip design in past lives, yet it took a long time to build a functional chip team from scratch. As well as requiring specialist skills, you need a lot of expensive tools and IP; and before you can buy these things, there is a lot of work required to evaluate and decide exactly which expensive goodies you’ll need. After a slow start, for the past couple of years we’ve had a small team working on it full-time, with many others pulled in to help as needed.

Low-cost and flexible

The Pico board was designed alongside RP2040 – in fact we designed the RP2040 pinout to work well on Pico, so we could use an inexpensive two-layer PCB, without compromising on the layout. A lot of thought has gone into making it as low-cost and flexible as possible – from the power circuitry to packaging the units on to Tape and Reel (which is cost-effective and has good packing density, reducing shipping costs).

“This ‘full stack’ design approach has allowed optimisation across the different parts”

With Pico we’ve hit the ‘pocket money’ price point, yet in RP2040 we’ve managed to pack in enough CPU performance and RAM to run more heavyweight applications such as MicroPython, and AI workloads like TinyML. We’ve also added genuinely new and innovative features such as the Programmable I/O (PIO), which can be programmed to ‘bit-bang’ almost any digital interface without using valuable CPU cycles. Finally, we have released a polished C/C++ SDK, comprehensive documentation and some very cool demos!

A reel of Raspberry Pi Pico boards

For me, this project has been particularly special as I began my career at a small chip-design startup. This was a chance to start from a clean sheet and design silicon the way we wanted to, and to talk about how and why we’ve done it, and how it works.

Pico is also our most vertically integrated product; meaning we control everything from the chip through to finished boards. This ‘full stack’ design approach has allowed optimisation across the different parts, creating a more cost-effective and coherent whole (it’s no wonder we’re not the only fruit company doing this).

And of course, it is designed here in Cambridge, birthplace of so many chip companies and computing pioneers. We’re very pleased to be continuing the Silicon Fen tradition.

Get The MagPi 103 now

You can grab the brand-new issue right now online from the Raspberry Pi Press store, or via our app on Android or iOS. You can also pick it up from supermarkets and newsagents, but make sure you do so safely while following all your local guidelines.

magpi magazine cover issue 103

Finally, there’s also a free PDF you can download. Good luck during the #MonthOfMaking, folks! I’ll see y’all online.

A banner with the words "Be a Pi Day donor today"

The post Raspberry Pi Pico – Vertical innovation appeared first on Raspberry Pi.

Make an animated sign with Raspberry Pi Pico

Light up your living room like Piccadilly Circus with this Raspberry Pi Pico project from the latest issue of HackSpace magazine. Don’t forget, it’s not too late to get your hands on our new microcontroller for FREE if you subscribe to HackSpace magazine.

HUB75 LED panels provide an affordable way to add graphical output to your projects. They were originally designed for large advertising displays (such as the ones made famous by Piccadilly Circus in London, and Times Square in New York). However, we can use a little chunk of these bright lights in our projects. They’re often given a ‘P’ value, such as P3 or P5 for the number of millimetres between the different RGB LEDs. These don’t affect the working or wiring in any way.

We used a 32×32 Adafruit screen. Other screens of this size may work, or may be wired differently. It should be possible to get screens of different sizes working, but you’ll have to dig through the code a little more to get it running properly.

The most cost- effective way to add 1024 RGB LEDs to your project

The most cost- effective way to add 1024 RGB LEDs to your project

The protocol for running these displays involves throwing large amounts of data down six different data lines. This lets you light up one portion of the display. You then switch to a different portion of the display and throw the data down the data lines again. When you’re not actively writing to a particular segment of the display, those LEDs are off.

There’s no in-built control over the brightness levels – each LED is either on or off. You can add some control over brightness by flicking pixels on and off for different amounts of time, but you have to manage this yourself. We won’t get into that in this tutorial, but if you’d like to investigate this, take a look at the box on ‘Going Further’.

The code for this is on GitHub (hsmag.cc/Hub75). If you spot a way of improving it, send us a pull request

The code for this is on GitHub. If you spot a way of improving it, send us a pull request

The first thing you need to do is wire up the screen. There are 16 connectors, and there are three different types of data sent – colour values, address values, and control values. You can wire this up in different ways, but we just used header wires to connect between a cable and a breadboard. See here for details of the connections.

These screens can draw a lot of power, so it’s best not to power them from your Pico’s 5V output. Instead, use a separate 5V supply which can output enough current. A 1A supply should be more than enough for this example. If you’re changing it, start with a small number of pixels lit up and use a multimeter to read the current.

With it wired up, the first thing to do is grab the code and run it. If everything’s working correctly, you should see the word Pico bounce up and down on the screen. It is a little sensitive to the wiring, so if you see some flickering, make sure that the wires are properly seated. You may want to just display the word ‘Pico’. If so, congratulations, you’re finished!

However, let’s take a look at how to customise the display. The first things you’ll need to adapt if you want to display different data are the text functions – there’s one of these for each letter in Pico. For example, the following draws a lower-case ‘i’:

def i_draw(init_x, init_y, r, g, b):
    for i in range(4):
        light_xy(init_x, init_y+i+2, r, g, b)
    light_xy(init_x, init_y, r, g, b)

As you can see, this uses the light_xy method to set a particular pixel a particular colour (r, g, and b can all be 0 or 1). You’ll also need your own draw method. The current one is as follows:

def draw_text():
    global text_y
    global direction
    global writing
    global current_rows
    global rows

    writing = True
    text_y = text_y + direction
    if text_y > 20: direction = -1
    if text_y < 5: direction = 1
    rows = [0]*num_rows
    #fill with black
    for j in range(num_rows):
    rows[j] = [0]*blocks_per_row

    p_draw(3, text_y-4, 1, 1, 1)
    i_draw(9, text_y, 1, 1, 0)
    c_draw(11, text_y, 0, 1, 1)
    o_draw(16, text_y, 1, 0, 1)
    writing = False

This sets the writing global variable to stop it drawing this frame if it’s still being updated, and then just scrolls the text_y variable between 5 and 20 to bounce the text up and down in the middle of the screen.

This method runs on the second core of Pico, so it can still throw out data constantly from the main processing core without it slowing down to draw images.

Get HackSpace magazine – Issue 40

Each month, HackSpace magazine brings you the best projects, tips, tricks and tutorials from the makersphere. You can get it from the Raspberry Pi Press online store, The Raspberry Pi store in Cambridge, or your local newsagents.

Each issue is free to download from the HackSpace magazine website.

When you subscribe, we’ll send you a Raspberry Pi Pico for FREE.

A banner with the words "Be a Pi Day donor today"

The post Make an animated sign with Raspberry Pi Pico appeared first on Raspberry Pi.

How to get started with FUZIX on Raspberry Pi Pico

FUZIX is an old-school Unix clone that was initially written for the 8-bit Zilog Z80 processor and released by Alan Cox in 2014. At one time one of the most active Linux developers, Cox stepped back from kernel development in 2013. While the initial announcement has been lost in the mists because he made it on the now defunct Google+, Cox jokingly recommended the system for those longing for the good old days when all the source code still fitted on a single floppy disk.

FUZIX running on Raspberry Pi Pico
FUZIX running on Raspberry Pi Pico.

Since then FUZIX has been ported to other architectures such as 6502, 68000, and the MSP430. Earlier in the week David Given — who wrote both the MSP430 and ESP8266 ports — went ahead and ported it to Raspberry Pi Pico and RP2040.

So you can now run Unix on a $4 microcontroller.

Building FUZIX from source

FUZIX is a “proper” Unix with a serial console on Pico’s UART0 and SD card support, using the card both for the filesystem and for swap space. While there is a binary image available, it’s easy enough to build from source.

If you don’t already have the Raspberry Pi Pico toolchain set up and working you should go ahead and set up the C/C++ SDK.

Afterwards you need grab the the Pico port from GitHub.

$ git clone https://github.com/davidgiven/FUZIX.git
$ cd FUZIX
$ git checkout rpipico

Then change directory to the platform port

$ cd Kernel/platform-rpipico/

and edit the first line of the Makefile to set the path to your pico-sdk.

So for instance if you’re building things on a Raspberry Pi and you’ve run the pico_setup.sh script, or followed the instructions in our Getting Started guide, you’d point the PICO_SDK_PATH to

export PICO_SDK_PATH = /home/pi/pico/pico-sdk

After that you can go ahead and build both the FUZIX UF2 file and the root filesystem.

$ make world -j
$ ./update-flash.sh

If everything goes well you should have a UF2 file in build/fuzix.uf2 and a filesystem.img image file in your current working directory.

You can now load the UF2 file onto your Pico in the normal way.

Go grab your Raspberry Pi Pico board and a micro USB cable. Plug the cable into your Raspberry Pi or laptop, then press and hold the BOOTSEL button on your Pico while you plug the other end of the micro USB cable into the board. Then release the button after the board is plugged in.

A disk volume called RPI-RP2 should pop up on your desktop. Double-click to open it, and then drag and drop the UF2 file into it.

The volume will automatically unmount, and your Pico is now running Unix. Unfortunately it won’t be much use without a filesystem.

Building a bootable SD card

The filesystem.img image file we built earlier isn’t a bootable image. Unlike the Raspberry Pi OS images you might be used to, you can’t just use something like Raspberry Pi Imager to write it to an SD card. We’re going to have to get our hands a bit dirtier than that.

The following instructions are for building your file system on a Raspberry Pi, or another similar Linux platform. Comparable tools are available on both MS Windows and Apple macOS, but the exact details will differ.

Go grab a microSD card. As the partitions we’re going to put onto it are only going to take up 34MB it doesn’t really matter what size you’ve got to hand. I was using a 4GB card, as that was the smallest I could find, but it’s not that important.

Now plug the card into a USB card reader and then into your Raspberry Pi or laptop computer. We’re going to have to build the partition table that FUZIX is expecting, which consists of two partitions: the first a 2MB swap partition, and the second a 32MB root partition into which we can copy the root filesystem, our filesystem.img file.

Raspberry Pi 4 with USB card reader
Raspberry Pi 4 with USB card reader.

After plugging your card into the reader you can find it from the command line using the lsblk command. If you’ve have a blank unformatted card it will be visible as /dev/sda.

$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    1  3.7G  0 disk 
mmcblk0     179:0    0 14.9G  0 disk 
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 14.6G  0 part /
$

But if the card is already formatted you might instead see something like this

$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    1  3.7G  0 disk 
└─sda1        8:1    1  3.7G  0 part /media/pi/USB
mmcblk0     179:0    0 14.9G  0 disk 
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 14.6G  0 part /
$

which is a FAT-formatted card with a MBR named “USB”, which your Raspberry Pi has automatically mounted under /media/pi/USB.

If your card has mounted, just go ahead and unmount it as follows:

$ umount /dev/sda1

Then looking using lsblk you should see

$ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    1  3.7G  0 disk 
└─sda1        8:1    1  3.7G  0 part 
mmcblk0     179:0    0 14.9G  0 disk 
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 14.6G  0 part /
$

at which point we can delete the current partition table by zeroing out the first part of the card and deleting the “start of disk” structures.

$ sudo dd if=/dev/zero of=/dev/sda bs=512 count=1

If you run lsblk again afterwards you’ll see that the sda1 partition has been deleted.

Next we’ll use fdisk to create a new partition table. Type the following

$ sudo fdisk /dev/sda

to put you at the fdisk prompt. Then type “o” to create a new DOS disklabel

Command (m for help): o
Created a new DOS disklabel with disk identifier 0x6e8481a2.

followed by “n” to create a new partition:

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-7744511, default 2048): 2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-7744511, default 7744511): +2M 
Created a new partition 1 of type 'Linux' and of size 2 MiB.

Depending on the initial state of your disk you may be prompted that the partition “contains a vfat signature” and asked whether you want to remove the signature. If asked, just type “Y” to confirm.

Next, we’ll set the type for this partition to “7F

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 7F
Changed type of partition 'Linux' to 'unknown'.

to create the 2MB swap partition that FUZIX is expecting. From here we need to create a second 32MB partition to hold our root file system:

Command (m for help): n
Partition type
   p   primary (1 primary, 0 extended, 3 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (6144-7744511, default 6144): 6144
Last sector, +/-sectors or +/-size{K,M,G,T,P} (6144-7744511, default 7744511): +32M

Created a new partition 2 of type 'Linux' and of size 32 MiB.

Afterwards if you type “p” at the fdisk prompt you should see something like this:

Command (m for help): p
Disk /dev/sda: 3.7 GiB, 3965190144 bytes, 7744512 sectors
Disk model: STORAGE DEVICE  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xe121b9a3

Device     Boot Start   End Sectors Size Id Type
/dev/sda1        2048  6143    4096   2M 7f unknown
/dev/sda2        6144 71679   65536  32M 83 Linux

If you do, you can type “w” to write and save the partition table.

Finally, we can copy our root file system into our second 32MB partition:

$ sudo dd if=filesystem.img of=/dev/sda2
65535+0 records in
65535+0 records out
33553920 bytes (34 MB, 32 MiB) copied, 14.1064 s, 2.4 MB/s
$

You can now eject the SD card from the USB card reader, because it’s time to wire up our breadboard.

Wiring things up on the breadboard

If you’re developing on a Raspberry Pi, and you haven’t previously used UART serial — which is different from the “normal” USB serial — you should go read Section 4.5 of our Getting Started guide.

FUZIX wiring diagram
Connecting a Raspberry Pi to a Pico and SD card.

Here I’m using Adafruit’s MicroSD Card Breakout, and wiring the UART serial connection directly to to the Raspberry Pi’s serial port using the GPIO headers.

However, if you’re developing on a laptop you can use something like the SparkFun FTDI Basic Breakout to connect the serial UART to your computer. Again, see our Getting Started guide for details: Section 9.1.4 if you’re on Apple macOS, or Section 9.2.5 if you’re on MS Windows.

Connecting a laptop to a Pico and SD card.

Either way, the mapping between the pins on your Raspberry Pi Pico and the SD card breakout is the same, and should be as follows:

Pico RP2040 SD Card
3V3 (OUT) +3.3V
Pin 16 GP12 (SPI1 RX) DO (MISO)
Pin 17 GP13 (SPI1 CSn) CS
Pin 18 GND GND
Pin 19 GP14 (SPI1 SCK) SCK
Pin 20 GP15 (SPI1 TX) DI (MOSI)
Mapping between physical pin number, RP2040 pin, and SD Card breakout.

Once you’ve wired things up, pop your formatted microSD card into the breadboarded SD card breakout, and plug your Raspberry Pi Pico into USB power. FUZIX will boot automatically.

Connecting to FUZIX

If you’re connecting using a Raspberry Pi, the first thing you’ll need to do is enable UART serial communications using raspi-config.

$ sudo raspi-config

Go to Interfacing Options → Serial. Select “No” when asked “Would you like a login shell to be accessible over serial?” and “Yes” when asked “Would you like the serial port hardware to be enabled?”

Enabling a serial UART using raspi-config on the Raspberry Pi.
Enabling a serial UART using raspi-config on Raspberry Pi.

Leaving raspi-config you should choose “Yes” and reboot your Raspberry Pi to enable the serial port. More information about connecting via UART can be found in Section 4.5 of our Getting Started guide.

You can then connect to FUZIX using minicom:

$ sudo apt install minicom
$ minicom -b 115200 -o -D /dev/serial0

Alternatively, if you are working on a laptop from macOS or MS Windows you can use minicom, screen, or your usual Terminal program. If you’re unsure what to use, there are a number of options: for instance, a good option is CoolTerm, which is cross-platform and works on Linux, macOS, and Windows.

After connecting to the serial port you should see something like this:

FUZIX in Serial
Connected to FUZIX using Serial on Apple macOS.

If you don’t see anything, just unplug and replug your Pico to reset it and start FUZIX running again.

Finally, go ahead and enter the correct date and time, and when you get to the login prompt you can login as “root” with no password.

Welcome to FUZIX!

Wrapping up

While there are still a few problems, the port of FUZIX to Pico has been merged to the upstream repository, which means it’s now an official part of the operating system.

Support for developing for Pico can be found on the Raspberry Pi forums. There is also an (unofficial) Discord server where a lot of people active in the new community seem to be hanging out. Feedback on the documentation should be posted as an Issue to the pico-feedback repository on GitHub, or directly to the relevant repository it concerns.

All of the documentation, along with lots of other help and links, can be found on the Getting Started page. If you lose track of where that is in the future, you can always find it from your Pico: to access the page, just press and hold the BOOTSEL button on your Pico, plug it into your laptop or Raspberry Pi, then release the button. Go ahead and open the RPI-RP2 volume, and then click on the INDEX.HTM file.

That will always take you to the Getting Started page.

The post How to get started with FUZIX on Raspberry Pi Pico appeared first on Raspberry Pi.

Keeping secrets and writing about Raspberry silicon

In the latest issue of The MagPi Magazine, Alasdair Allan shares the secrets he had to keep while working behind the scenes to get Raspberry Pi’s RP2040 chip out into the world.

Alasdair Allen holding a Pico board
BEST friends

There is a new thing in the world, and I had a ringside seat for its creation. 

For me, it started just over a year ago with a phone call from Eben Upton. One week later I was sitting in a meeting room at Raspberry Pi Towers in Cambridge, my head tilted to one side while Eben scribbled on a whiteboard and waved his hands around. 

Eben had just told me that Raspberry Pi was designing its own silicon, and he was talking about the chip that would eventually be known as RP2040. Eben started out by drawing the bus fabric, which isn’t where you normally start when you talk about a new chip, but it turned out RP2040 was a rather unusual chip.

“I gradually drifted sideways into playing with the toys.”

I get bored easily. I started my career doing research into the high-energy physics of collision shocks in the accretion discs surrounding white dwarf stars, but I gradually drifted sideways into playing with the toys.

After spending some time working with agent-based systems to solve scheduling problems for robotic telescopes, I became interested in machine learning and what later became known as ‘big data’.

Meet Raspberry Pi Pico

From there, I spent time investigating the ‘data exhaust’ and data living outside the cloud in embedded and distributed devices, and as a consequence did a lot of work on mobile systems. Which led me to do some of the thinking, and work, on what’s now known as the Internet of Things. Which meant I had recently spent a lot of time writing and talking about embedded hardware. 

Eben was looking for someone to make sure the documentation around Raspberry Pi Pico, and RP2040 silicon itself, was going to measure up. I took the job.

Rumour mill

I had spent the previous six months benchmarking Machine Learning (ML) inferencing on embedded hardware, and a lot of time writing and talking about the trendy new world of Tiny ML.

What is a microcontroller?

The rumours of what I was going to be doing for Raspberry Pi started flying on social media almost immediately. The somewhat pervasive idea that I was there to help support putting a Coral Edge TPU onto Raspberry Pi 5 was a particularly good wheeze. 

Instead, I was going to spend the next year metaphorically locked in a room building a documentation toolchain around – and of course writing about – a totally secret product.

Screenshot of our Getting Started with Raspberry Pi Pico landing page
Alasdair’s work turned into this

I couldn’t talk about it in public, and I talk about things in public a lot. Only the fact that almost everyone else spent the next year locked indoors as well kept too many questions from being asked. I didn’t have to tell conference organisers that I couldn’t talk about what I was doing, because there weren’t any conferences to organise.

I’m rather pleased with what I’ve done with my first year at Raspberry Pi, and of course with how my work on RP2040 and Raspberry Pi Pico turned out.

Taken from our Getting Started with Raspberry Pi Pico page

Much like a Raspberry Pi is an accessible computer that gives you everything you need to learn to write a program, RP2040 is an accessible chip with everything you need to learn to build a product. It’s going to bring a big change to the microcontroller market, and I’m really rather pleased I got a ringside seat to its creation.

The post Keeping secrets and writing about Raspberry silicon appeared first on Raspberry Pi.

The journey to Raspberry Silicon

When I first joined Raspberry Pi as a software engineer four and a half years ago, I didn’t know anything about chip design. I thought it was magic. This blog post looks at the journey to Raspberry Silicon and the design process of RP2040.

RP2040 on a Raspberry Pi Pico
RP2040 – the heart of Raspberry Pi Pico

RP2040 has been in development since summer 2017. Chips are extremely complicated to design. In particular, the first chip you design requires you to design several fundamental components, which you can then reuse on future chips. The engineering effort was also diverted at some points in the project (for example to focus on the Raspberry Pi 4 launch).

Once the chip architecture is specified, the next stage of the project is the design and implementation, where hardware is described using a hardware description language such as Verilog. Verilog has been around since 1984 and, along with VHDL, has been used to design most chips in existence today. So what does Verilog look like, and how does it compare to writing software?

Suppose we have a C program that implements two wrapping counters:

void count_forever(void) {
    uint8_t i = 0;
    uint8_t j = 0;
    while (1) {
        i += 1;
        j += 1;
    }
}

This C program will execute sequentially line by line, and the processor won’t be able to do anything else (unless it is interrupted) while running this code. Let’s compare this with a Verilog implementation of the same counter:

module counter (
    input wire clk,
    input wire rst_n,
    output reg [7:0] i,
    output reg [7:0] j
);

always @ (posedge clk or negedge rst_n) begin
    if (~rst_n) begin
        // Counter is in reset so hold counter at 0
        i <= 8’d0;
        j <= 8’d0;
    end else begin
        i <= i + 8’d1;
        j <= j + 8’d1;
    end
end

endmodule

Verilog statements are executed in parallel on every clock cycle, so both i and j are updated at exactly the same time, whereas the C program increments i first, followed by j. Expanding on this idea, you can think of a chip as thousands of small Verilog modules like this, all executing in parallel.

A chip designer has several tools available to them to test the design. Testing/verification is the most important part of a chip design project: if a feature hasn’t been tested, then it probably doesn’t work. Two methods of testing used on RP2040 are simulators and FPGAs. 

A simulator lets you simulate the entire chip design, and also some additional components. In RP2040’s case, we simulated RP2040 and an external flash chip, allowing us to run code from SPI flash in the simulator. That is the beauty of hardware design: you can design some hardware, then write some C code to test it, and then watch it all run cycle by cycle in the simulator.

“ell” from the phrase “Hello World” from core0 of RP2040 in a simulator

The downside to simulators is that they are very slow. It can take several hours to simulate just one second of a chip. Simulation time can be reduced by testing blocks of hardware in isolation from the rest of the chip, but even then it is still slow. This is where FPGAs come in…

FPGAs (Field Programmable Gate Arrays) are chips that have reconfigurable logic, and can emulate the digital parts of a chip, allowing most of the logic in the chip to be tested. 

FPGAs can’t emulate the analogue parts of a design, such as the resistors that are built into RP2040’s USB PHY. However, this can be approximated by using external hardware to provide analogue functionality. FPGAs often can’t run a design at full speed. In RP2040’s case, the FPGA was able to run at 48MHz (compared to 133MHz for the fully fledged chip). This is still fast enough to test everything we wanted and also develop software on.

FPGAs also have debug logic built into them. This allows the hardware designer to probe signals in the FPGA, and view them in a waveform viewer similar to the simulator above, although visibility is limited compared to the simulator.

Graham’s tidy FPGA
Graham’s less tidy FPGA
Oh dear

The RP2040 bootrom was developed on FPGA, allowing us to test the USB boot mode, as well executing code from SPI flash. In the image above, the SD card slot on the FPGA is wired up to SPI flash using an SD card-shaped flash board designed by Luke Wren.

USB testing on FPGA

In parallel to Verilog development, the implementation team is busy making sure that the Verilog we write can actually be made into a real chip. Synthesis takes a Verilog description of the chip and converts the logic described into logic cells defined by your library choice. RP2040 is manufactured by TSMC, and we used their standard cell library.

RP2040 silicon in a DIL package!

Chip manufacturing isn’t perfect. So design for test (DFT) logic is inserted, allowing the logic in RP2040 to be tested during production to make sure there are no manufacturing defects (short or open circuit connections, for example). Chips that fail this production test are thrown away (this is a tiny percentage – the yield for RP2040 is particularly high due to the small die size).

After synthesis, the resulting netlist goes through a layout phase where the standard cells are physically placed and interconnect wires are routed. This is a synchronous design so clock trees are inserted, and timing is checked and fixed to make sure the design meets the clock speeds that we want. Once several design rules are checked, the layout can be exported to GDSII format, suitable for export to TSMC for manufacture.

RP2040 chips ready for a bring up board

(In reality, the process of synthesis, layout, and DFT insertion is extremely complicated and takes several months to get right, so the description here is just a highly abbreviated overview of the entire process.)

Once silicon wafers are manufactured at TSMC they need to be put into a package. After that, the first chips are sent to Pi Towers for bring-up!

The RP2040 bring-up board

A bring-up board typically has a socket (in the centre) so you can test several chips in a single board. It also separates each power supply on the chip, so you can limit the current on first power-up to check there are no shorts. You don’t want the magic smoke to escape!

The USB boot mode working straight out of the box on a bring-up board!

Once the initial bring-up was done, RP2040 was put through its paces in the lab. Characterising behaviour, seeing how it performs at temperature and voltage extremes.

Once the initial batch of RP2040s are signed off we give the signal for mass production, ready for them to be put onto Pico boards that you have in your hands today.

82K RP2040s ready for shipment to Sony

A chip is useless without detailed documentation. While RP2040 was making its way to mass production, we spent several months writing the SDK and excellent documentation you have available to you today.

The post The journey to Raspberry Silicon appeared first on Raspberry Pi.

Raspberry Pi Pico balloon tracker

Dave Akerman of High Altitude Ballooning came up with a stratospherically cool application for Raspberry Pi Pico. In this guest blog, he shows you how to build and code a weather balloon tracker.

Balloon tracking

My main hobby is flying weather balloons, using GPS/radio trackers to relay their position to the ground, so they can be tracked and hopefully recovered. Trackers minimally consist of a GPS receiver feeding the current position to a small computer, which in turn controls a radio transmitter to send that position to the ground. That position is then fed to a live map to aid chasing and recovering the flight.

system-1024x813-500x396
How it all works

This essential role of the tracker computer is thus a simple one, and those making their own trackers can choose from a variety of microcontrollers chips and boards, for example Arduino boards, PIC microcontrollers or the BBC Microbit. Anything with a modest amount of code memory, data memory, processor power and I/O (serial, SPI etc depending on choice of GPS and radio) will do. A popular choice is Raspberry Pi, which, whilst a sledgehammer to crack a nut for tracking, does make it easy to add a camera.

Raspberry Pi Pico

When I see a new type of processor board, I feel duty bound to make it into a balloon tracker, so when I was asked to help test the new Raspberry Pi Pico, doing so was my first thought. It has plenty of I/O – SPI ports, I2C and serial all available – plus a unique ability (not that I need it for now) to add extra peripherals using the programmable PIO modules, so there was no doubt that it would be very usable. Also, having much more memory than typical microcontrollers, it offers the ability to add functions that would normally need a full Raspberry Pi board – for example on-board landing prediction. More on that later.

Tracker components

So a basic tracker has a GPS receiver and radio transmitter. To connect these to the Raspberry Pi Pico, I used a prototyping board where I mounted a UBlox GPS receiver, LoRa radio transmitter, and sockets for the Pico itself.

I don’t use breadboards as they are prone to intermittent connections that then waste programming time chasing a “bug” that’s actually a hardware problem. Besides, trackers need to be robust so I would need to solder one together eventually anyway.

Pico top, GPS bottom-left; LoRa bottom-right

The particular UBlox GPS module I had handy only has a serial port brought out, so I couldn’t use I2C. No matter because, unlike most Arduino boards, the Raspberry Pi Pico isn’t limited to a single serial port.

The LoRa module connects via SPI and a single GPIO pin which the module uses to send its status (e.g. packet sent – ready to send next packet) to the Raspberry Pi Pico.

Finally, with the tracker working, I added an I2C environmental sensor to the board via a pin header, so the sensor can be placed in free air outside the tracker.

Development setup

I decided to use C for my tracker rather than Python, for a variety of reasons. The main one is that I have plenty of existing C tracker code to work from, for Arduino and Raspberry Pi, but not so much Python. Secondly, I figured that most of the testers would be using Python so there might be more of a need to test the C toolchain.

The easiest route to getting the C/C++ toolchain working is to install on a Raspberry Pi 4. I couldn’t quite get the VSCode integration working (finger trouble I think) but anyway I’m quite happy to code with an editor and separate build window. So what I ended up with was Notepadd++ on my Windows PC to edit the code, with the source on a Raspberry Pi 4. I then had an ssh window open to run the compile/link steps, and a separate one running the debugger. The debugger downloads the binary to the Raspberry Pi Pico via the latter’s debug port.

For regular debug output from the program I connected a Raspberry Pi Pico serial port to an FTDI USB Serial TTL adapter connected back to my PC – see the image below.

At some point I’ll revisit this setup. First, it’s now possible to printf to a virtual USB serial port, so that frees up that Raspberry Pi Pico serial port. Secondly, I need to get that VSCode integration working.

Tracker code

My Raspberry Pi and Arduino tracker programs work slightly differently. On the Raspberry Pi, to separate the code for the different functions (GPS, radio, sensors etc) I use a separate thread for each. That allows for example a new packet to be sent to the radio transmitter without delay, even if a slow operation is running concurrently elsewhere.

On the Arduino, with no threads available, the code is still split into separate modules but each one is coded to run quickly without waiting in a loop for a peripheral to respond. For example some temperature sensors can take a second or so to take a measurement, and it’s vital not to sit in a loop waiting for the result.

The C toolchain for Raspberry Pi Pico doesn’t, by default, support threaded code unfortunately. Rather than rebuild it with support added, I opted for the approach I use with Arduino. So the main code starts with initialising each module individually, and then sits in a tight loop calling each module once per loop. It’s then up to each module to return control swiftly so that the loop keeps running quickly and no module is kept waiting for long.

Code modules

The GPS code uses a serial port to receive NMEA data from the GPS. NMEA is the standard ASCII protocol used by pretty much every GPS module that exists, and includes the current date, time, latitude, longitude, altitude and other data. All we need to do is confirm that the data is valid, then read and store these key values. The other important function is to ensure that the GPS module is in the correct “flight mode” so that it works at high altitude – without this then it will stop providing new positions about 18km altitude.

View NMEA Data Log

The LoRa radio code checks to see when the module is not transmitting, then builds a new telemetry message containing the above GPS data plus the name of the balloon, any other sensor data, and the landing prediction (see later).

This message is passed to the LoRa chip via SPI, then the chip switches on its radio and modulates the radio signal with the telemetry data. Once the message has been sent then the chip switches on its DIO0 output which is connected to the Raspberry Pi Pico so it knows when it can send another message.

All messages are received on the ground (in this case by a Pi LoRa receiver) and then uploaded to an internet database that in turn drives a live Google map (see image below).

Sensors

Usefully for balloon trackers, the Raspberry Pi Pico can be powered directly from battery via an on-board buck-boost converter.

The input voltage connects through a potential divider to an analog sense input (ADC3) to allow for easy measurement of the battery voltage. Note that the ADC reference voltage is the 3.3V rail, which is noisy especially when used to power external devices such as the GPS and LoRa both of which have rather spiky power consumption requirements, so the code averages out many measurements.

An alternative would be to add a precise reference voltage to the ADC but I went for the zero cost software option.

The board temperature can also be measured, this time using ADC4. That’s less useful though for a tracker than an external temperature measurement, so I added a BME280 device for that. The Raspberry Pi Pico samples include code for the BME connected via SPI, but I chose I2C so I needed to replace the SPI calls with I2C calls. Pretty easy. The BME280 returns pressure – probably the most interesting environmental measurement for a balloon tracker – and humidity too.

Landing prediction

So far, everything I’ve done could also be done on a basic AVR chip e.g. the Arduino Mini Pro, with some spare room. However, one very useful extra is to add a prediction of the landing point.

We use online flight prediction prior to launch, to determine roughly where the balloon will land (within a few miles) so we know it’s safe to launch without landing near a city for example. This uses a global wind prediction database plus some flight parameters (e.g. ascent rate and burst altitude) to predict the path of the balloon from launch to landing. It can be very accurate if those parameters are followed through on the flight itself.

Of course the actual flight never quite follows the plan – for example the launch might be later than planned, and in changing wind conditions that itself can move the landing point by miles. So it’s useful to have a live prediction during that flight, and indeed we have that, using the same wind database.

However, since it’s online, and 3G/4G can be patchy when chasing a balloon, it’s useful to have an independent landing prediction. This can be done in the tracker itself, by storing the wind speed and direction (deduced from GPS positions) on the way up, measuring the descent rate after burst, applying that to an atmospheric density model to plot the future descent rate to the ground, and then calculating the effect of the wind during descent and finally producing a landing position.

Typical Arduino boards don’t have enough memory to store the measured wind data, but the Raspberry Pi Pico has more than enough. I ported my existing code which:

  1. During ascent, it splits the vertical range into 100 metres sections, into which it stores the latitude and longitude deltas as degrees per second.
  2. Every few seconds, it runs a prediction of the landing position based on the current position, the data in that array, and an estimated descent profile that uses a simple atmospheric model plus default values for payload weight and parachute effectiveness.
  3. During descent, the parachute effectiveness is measured, and the actual figure is used in the above calculation in (2).
  4. Calculates the time it will spend within each 100m section of air, then multiplies that by the stored wind speed to calculate the horizontal distance and direction it is expected to travel in that section.
  5. Adds all those sectional movements together, adds those to the current position, and produces the landing prediction.
  6. Sends that position down to the ground with the rest of the telemetry.

Phew. Now we know pretty much everything about how balloon trackers work. Thanks Dave! Also, if you want to go on your own near-space flight, check out High Altitude Ballooning.

The post Raspberry Pi Pico balloon tracker appeared first on Raspberry Pi.

How to add a reset button to your Raspberry Pi Pico

We’ve tried to make it as easy as possible for you to load your code onto your new Raspberry Pi Pico: press and hold the BOOTSEL button, plug your Pico into your computer, and it’ll mount as a mass storage volume. Then just drag and drop a UF2 file onto the board.

However, not everybody is keen to keep unplugging their micro USB cable every time they want to upload a UF2 onto the board. Don’t worry — there’s more than one way around that problem.

Raspberry Pi Pico with a reset button wired to the GND and RUN pins

Firstly, if you’re developing in MicroPython there isn’t any real need to unplug and replug Pico to write code. The only time you’ll need to do it is the initial upload of the MicroPython firmware, which comes as a UF2. From there on in, you’re talking to the board via the REPL and a serial connection, either in Thonny or some other editor.

However, if you’re developing using our C SDK, then to upload new code to your Pico you have to upload a new UF2. This means you’ll need to unplug and replug the board to put Pico into BOOTSEL mode each time you make a change in your code and want to test it.

No more unplugging with SWD?

The best way around this is to use SWD mode (see Chapter 5 of our C/C++ Getting Started book) to upload code using the debug port, instead of using mass storage (BOOTSEL) mode.

A Raspberry Pi 4 and Raspberry Pi Pico with UART and SWD ports connected together

This gets you debugger support, which is invaluable while developing, and involves adding just three more wires. Afterwards, you’ll never have to unplug your Pico again.

Keep on dragging and dropping

But if you want to stick with uploading by drag-and-drop, adding a reset button to your Raspberry Pi Pico is pretty easy.

Raspberry Pi Pico with a reset button wired to the GND and RUN pins

All you need to do is to wire the GND and RUN pins together and add an extra momentary contact button to your breadboard. Pushing the button will reset the board.

Then, instead of unplugging and replugging the USB cable when you want to load code onto Pico, you push and hold the RESET button, push the BOOTSEL button, release the RESET button, then release the BOOTSEL button.

Entering BOOTSEL mode without unplugging your Pico

If your board is in BOOTSEL mode and you want to start code you’ve already loaded running again, all you have to do now is briefly push the RESET button.

Leaving BOOTSEL mode without unplugging your Pico.

We’ve see some people use the 3V3_EN pin instead of the RUN pin. While it’ll work in a pinch, the problem with disabling 3.3V is that GPIOs that are driven from powered external devices will leak like crazy while 3.3V is disabled. There is even the possibility of damage to the chip. So it’s much better to use the RUN pin to make a reset button than the 3V3_EN pin.

What about the other button?

As an aside, if you want to break out the BOOTSEL button as well — perhaps you’re intending to bury your Pico inside an enclosure — you can use TP6 (that is, Test Point 6) on the rear of the board to do so. See Chapter 2 of the Pico Datasheet for details.

Where to find more help and information

Support for developing for Pico can be found on the Raspberry Pi forums. There is also an (unofficial) Discord server where a lot of people active in the new community seem to be hanging out. Feedback on the documentation should be posted as an issue to the pico-feedback repository on GitHub, or directly to the relevant repository it concerns.

All of the documentation, along with lots of other help and links, can be found on the same Getting Started page. If you lose track of where that is in the future, you can always find it from your Pico: to access the page, just press and hold the BOOTSEL button on your Pico, plug it into your laptop or Raspberry Pi, then release the button. Go ahead and open the RPI-RP2 volume, and then click on the INDEX.HTM file.

That will always take you to the Getting Started page.

The post How to add a reset button to your Raspberry Pi Pico appeared first on Raspberry Pi.

How to blink an LED with Raspberry Pi Pico in C

The new Raspberry Pi Pico is very different from a traditional Raspberry Pi. Pico is a microcontroller, rather than a microcomputer. Unlike a Raspberry Pi it’s a platform you develop for, not a platform you develop on.

Blinking the on-board LED
Blinking the onboard LED

But you still have choices if you want to develop for Pico, because there is both a C/C++ SDK and an official MicroPython port. Beyond that there are other options opening up, with a port of CircuitPython from Adafruit and the prospect of Arduino support, or even a Rust port.

Here I’m going to talk about how to get started with the C/C++ SDK, which lets you develop for Raspberry Pi Pico from your laptop or Raspberry Pi.

I’m going to assume you’re using a Raspberry Pi; after all, why wouldn’t you want to do that? But if you want to develop for Pico from your Windows or Mac laptop, you’ll find full instructions on how to do that in our Getting Started guide.

Blinking your first LED

When you’re writing software for hardware, the first program that gets run in a new programming environment is typically turning an LED on, off, and then on again. Learning how to blink an LED gets you halfway to anywhere. We’re going to go ahead and blink the onboard LED on Pico, which is connected to pin 25 of the RP2040 chip.

We’ve tried to make getting started with Raspberry Pi Pico as easy as possible. In fact, we’ve provided some pre-built binaries that you can just drag and drop onto your Raspberry Pi Pico to make sure everything is working even before you start writing your own code.

Go to the Getting Started page and click on the “Getting started with C/C++” tab, then the “Download UF2 file” button in the “Blink an LED” box.

Getting started with Raspberry Pi Pico

A file called blink.uf2 will be downloaded to your computer. Go grab your Raspberry Pi Pico board and a micro USB cable. Plug the cable into your Raspberry Pi or laptop, then press and hold the BOOTSEL button on your Pico while you plug the other end of the micro USB cable into the board. Then release the button after the board is plugged in.

A disk volume called RPI-RP2 should pop up on your desktop. Double-click to open it, and then drag and drop the UF2 file into it. The volume will automatically unmount and the light on your board should start blinking.

Blinking an LED

Congratulations! You’ve just put code onto your Raspberry Pi Pico for the first time. Now we’ve made sure that we can successfully get a program onto the board, let’s take a step back and look at how we’d write that program in the first place.

Getting the SDK

Somewhat unsurprisingly, we’ve gone to a lot of trouble to make installing the tools you’ll need to develop for Pico as easy as possible on a Raspberry Pi. We’re hoping to make things easier still in the future, but you should be able to install everything you need by running a setup script.

However, before we do anything, the first thing you’ll need to do is make sure your operating system is up to date.

$ sudo apt update
$ sudo apt full-upgrade

Once that’s complete you can grab the setup script directly from Github, and run it at the command line.

$ wget -O pico_setup.sh https://rptl.io/pico-setup-script
$ chmod +x pico_setup.sh
$ ./pico_setup.sh

The script will do a lot of things behind the scenes to configure your Raspberry Pi for development, including installing the C/C++ command line toolchain and Visual Studio Code. Once it has run, you will need to reboot your Raspberry Pi.

$ sudo reboot

The script has been tested and is known to work from a clean, up-to-date installation of Raspberry Pi OS. However, full instructions, along with instructions for manual installation of the toolchain if you prefer to do that, can be found in the “Getting Started” guide.

Once your Raspberry Pi has rebooted we can get started writing code.

Writing code for your Pico

There is a large amount of example code for Pico, and one of the things that the setup script will have done is to download the examples and build both the Blink and “Hello World” examples to verify that your toolchain is working.

But we’re going to go ahead and write our own.

We’re going to be working in the ~/pico directory created by the setup script, and the first thing we need to do is to create a directory to house our project.

$ cd pico
$ ls -la
total 59284
drwxr-xr-x  9 pi pi     4096 Jan 28 10:26 .
drwxr-xr-x 19 pi pi     4096 Jan 28 10:29 ..
drwxr-xr-x 12 pi pi     4096 Jan 28 10:24 openocd
drwxr-xr-x 28 pi pi     4096 Jan 28 10:20 pico-examples
drwxr-xr-x  7 pi pi     4096 Jan 28 10:20 pico-extras
drwxr-xr-x 10 pi pi     4096 Jan 28 10:20 pico-playground
drwxr-xr-x  5 pi pi     4096 Jan 28 10:21 picoprobe
drwxr-xr-x 10 pi pi     4096 Jan 28 10:19 pico-sdk
drwxr-xr-x  7 pi pi     4096 Jan 28 10:22 picotool
-rw-r--r--  1 pi pi 60667760 Dec 16 16:36 vscode.deb
$ mkdir blink
$ cd blink

Now open up your favourite editor and create a file called blink.c in the blink directory.

#include "pico/stdlib.h"
#include "pico/binary_info.h"

const uint LED_PIN = 25;

int main() {

    bi_decl(bi_program_description("First Blink"));
    bi_decl(bi_1pin_with_name(LED_PIN, "On-board LED"));

    gpio_init(LED_PIN);
    gpio_set_dir(LED_PIN, GPIO_OUT);
    while (1) {
        gpio_put(LED_PIN, 0);
        sleep_ms(250);
        gpio_put(LED_PIN, 1);
        sleep_ms(1000);
    }
}

Create a CMakeLists.txt file too.

cmake_minimum_required(VERSION 3.12)

include(pico_sdk_import.cmake)

project(blink)

pico_sdk_init()

add_executable(blink
    blink.c
)

pico_add_extra_outputs(blink)

target_link_libraries(blink pico_stdlib)

Then copy the pico_sdk_import.cmake file from the external folder in your pico-sdk installation to your test project folder.

$ cp ../pico-sdk/external/pico_sdk_import.cmake .

You should now have something that looks like this:

$ ls -la
total 20
drwxr-xr-x  2 pi pi 4096 Jan 28 11:32 .
drwxr-xr-x 10 pi pi 4096 Jan 28 11:01 ..
-rw-r--r--  1 pi pi  398 Jan 28 11:06 blink.c
-rw-r--r--  1 pi pi  211 Jan 28 11:32 CMakeLists.txt
-rw-r--r--  1 pi pi 2721 Jan 28 11:32 pico_sdk_import.cmake
$

We are ready to build our project using CMake.

$ mkdir build
$ cd build
$ export PICO_SDK_PATH=../../pico-sdk
$ cmake ..
$ make

If all goes well you should see a whole bunch of messages flash past in your Terminal window and a number of files will be generated in the build/ directory, including one called blink.uf2.

Just as we did before with the UF2 file we downloaded from the Getting Started page, we can now drag and drop this file on to our Pico.

Unplug the cable from your Pico, then press and hold the BOOTSEL button on your Pico and plug it back in. Then release the button after the board is plugged in.

The new Blink binary
The new blink.uf2 binary can be dragged and dropped on to our Pico

The RPI-RP2 disk volume should pop up on your desktop again. Double-click to open it, then open a file viewer in the pico/blink/build/ directory and drag and drop the UF2 file you’ll find there on to the RPI-RP2 volume. It will automatically unmount, and the light on your board should start blinking. But this time it will blink a little bit differently from before.

Try playing around with the sleep_ms( ) lines in our code to vary how much time there is between blinks. You could even take a peek at one of the examples, which shows you how to blink the onboard LED in Morse code.

Using Picotool

One way to convince yourself that the program running on your Pico is the one we just built is to use something called picotool. Picotool is a command line utility installed by the setup script that is a Swiss Army knife for all things Pico.

Go ahead and unplug your Pico from your Raspberry Pi, press and hold the BOOTSEL button, and plug it back in. Then run picotool.

$ sudo picotool info -a 
Program Information
 name:          blink
 description:   First Blink
 binary start:  0x10000000
 binary end:    0x10003344

Fixed Pin Information
 25:  On-board LED

Build Information
 sdk version:       1.0.0
 pico_board:        pico
 build date:        Jan 28 2021
 build attributes:  Release

Device Information
 flash size:   2048K
 ROM version:  1
$

You’ll see lots of information about the program currently on your Pico. Then if you want to start it blinking again, just unplug and replug Pico to leave BOOTSEL mode and start your program running once more.

Picotool can do a lot more than this, and you’ll find more information about it in Appendix B of the “Getting Started” guide.

Using Visual Studio Code

So far we’ve been building our Pico projects from the command line, but the setup script also installed and configured Visual Studio Code, and we can build the exact same CMake-based project in the Visual Studio Code environment. You can open it as below:

$ cd ~/pico
$ export PICO_SDK_PATH=/home/pi/pico/pico-sdk
$ code

Chapter 6 of the Getting Started guide has full details of how to load and compile a Pico project inside Visual Studio Code. If you’re used to Visual Studio Code, you might be able to make your way from here without much extra help, as the setup script has done most of the heavy lifting for you in configuring the IDE.

What’s left is to open the pico/blink folder and allow the CMake Tools extension to configure the project. After selecting arm-none-eabi as your compiler, just hit the “Build’ button in the blue bottom bar.

Building our blink project inside Visual Studio Code

While we recommend and support Visual Studio Code as the development environment of choice for developing for Pico — it works cross-platform under Linux, Windows, and macOS and has good plugin support for debugging — you can also take a look at Chapter 9 of the Getting Started guide. There we talk about how to use both Eclipse and CLion to develop for Pico, and if you’re more used to those environments you should be able to get up and running in either without much trouble.

Where now?

If you’ve got this far, you’ve built and deployed your very first C program to your Raspberry Pi Pico. Well done! The next step is probably going to be saying “Hello World!” over serial back to your Raspberry Pi.

From here, you probably want to sit down and read the Getting Started guide I’ve mentioned throughout the article, especially if you want to make use of SWD debugging, which is discussed at length in the guide. Beyond that I’d point you to the book on the C/C++ SDK which has the API-level documentation, as well as a high-level discussion of the design of the SDK.

Support for developing for Pico can be found on the Raspberry Pi forums. There is also an (unofficial) Discord server where a lot of people active in the new community seem to be hanging out. Feedback on the documentation should be posted as an Issue to the pico-feedback repository on Github, or directly to the relevant repository it concerns.

All of the documentation, along with lots of other help and links, can be found on the same Getting Started page from which we grabbed our original UF2 file.

If you lose track of where that is in the future, you can always find it from your Pico: to access the page, just press and hold the BOOTSEL button on your Pico, plug it into your laptop or Raspberry Pi, then release the button. Go ahead and open the RPI-RP2 volume, and then click on the INDEX.HTM file.

That will always take you to the Getting Started page.

The post How to blink an LED with Raspberry Pi Pico in C appeared first on Raspberry Pi.

Raspberry Pi engineers on the making of Raspberry Pi Pico | The MagPi 102

In the latest issue of The MagPi Magazine, on sale now, Gareth Halfacree asks what goes into making Raspberry Pi’s first in-house microcontroller and development board.

“It’s a flexible product and platform,” says Nick Francis, Senior Engineering Manager at Raspberry Pi, when discussing the work the Application-Specific Integrated Circuit (ASIC) team put into designing RP2040, the microcontroller at the heart of Raspberry Pi Pico

It would have been easy to have said, well, let’s do a purely educational microcontroller “quite low-level, quite limited performance,” he tells us. “But we’ve done the high-performance thing without forgetting about making it easy to use for beginners. To do that at this price point is really good.”

  • James Adams, Chief Operating Officer
  • Nick Francis, Senior Engineering Manager

“I think we’ve done a pretty good job,” agrees James Adams, Chief Operating Officer at Raspberry Pi. “We’ve obviously tossed around a lot of different ideas about what we could include along the way, and we’ve iterated quite a lot and got down to a good set of features.”

A board and chip

“The idea is it’s [Pico] a component in itself,” says James. “The intent was to expose as many of the I/O (input/output) pins for users as possible, and expose them in the DIP-like (Dual Inline Package) form factor, so you can use Raspberry Pi Pico as you might use an old 40-pin DIP chip. Now, Pico is 2.54 millimetres or 0.1 inch pitch wider than a ‘standard’ 40-pin DIP, so not exactly the same, but still very similar.

“After the first prototype, I changed the pins to be castellated so you can solder it down as a module, without needing to put any headers in. Which is, yes, another nod to using it as a component.”

Getting the price right

“One of the things that we’re very excited about is the price,” says James. “We’re able to make these available cheap as chips – for less than the price of a cup of coffee.”

“It’s extremely low-cost,” Nick agrees. “One of the driving requirements right at the start was to build a very low-cost chip, but which also had good performance. Typically, you’d expect a microcontroller with this specification to be more expensive, or one at this price to have a lower specification. We tried to push the performance and keep the cost down.”

“We’re able to make these available cheap as chips.”

James Adams

Raspberry Pi Pico also fits nicely into the Raspberry Pi ecosystem: “Most people are doing a lot of the software development for this, the SDK (software development kit) and all the rest of it, on Raspberry Pi 4 or Raspberry Pi 400,” James explains. “That’s our primary platform of choice. Of course, we’ll make it work on everything else as well. I would hope that it will be as easy to use as any other microcontroller platform out there.”

Eben Upton on RP2040

“RP2040 is an exciting development for Raspberry Pi because it’s Raspberry Pi people making silicon,” says Eben Upton, CEO and co-founder of Raspberry Pi. “I don’t think other people bring their A-game to making microcontrollers; this team really brought its A-game. I think it’s just beautiful.

Is Pico really that small, or is Eben a giant?

“What does Raspberry Pi do? Well, we make products which are high performance, which are cost-effective, and which are implemented with insanely high levels of engineering attention to detail – and this is that. This is that ethos, in the microcontroller space. And that couldn’t have been done with anyone else’s silicon.”

Issue #102 of The MagPi Magazine is out NOW

MagPi 102 cover

Never want to miss an issue? Subscribe to The MagPi and we’ll deliver every issue straight to your door. Also, if you’re a new subscriber and get the 12-month subscription, you’ll get a completely free Raspberry Pi Zero bundle with a Raspberry Pi Zero W and accessories.

The post Raspberry Pi engineers on the making of Raspberry Pi Pico | The MagPi 102 appeared first on Raspberry Pi.

New book: Get Started with MicroPython on Raspberry Pi Pico

Par : Phil King

So, you’ve got a brand new Raspberry Pi Pico and want to know how to get started with this tiny but powerful microcontroller? We’ve got just the book for you.

Get Started with Raspberry Pi Pico book

Beginner-friendly

In Get Started with MicroPython on Raspberry Pi Pico, you’ll learn how to use the beginner-friendly language MicroPython to write programs and connect hardware to make your Raspberry Pi Pico interact with the world around it. Using these skills, you can create your own electro-mechanical projects, whether for fun or to make your life easier.

Inside the pages of the Raspberry Pi Pico book

After taking you on a guided tour of Pico, the books shows you how to get it up and running with a step-by-step illustrated guide to soldering pin headers to the board and installing the MicroPython firmware via a computer.

Programming basics

Inside the pages of the Raspberry Pi Pico book 02

Next, we take you through the basics of programming in MicroPython, a Python-based programming language developed specifically for microcontrollers such as Pico. From there, we explore the wonderful world of physical computing and connect a variety of electronic components to Pico using a breadboard. Controlling LEDs and reading input from push buttons, you’ll start by creating a pedestrian crossing simulation, before moving on to projects such as a reaction game, burglar alarm, temperature gauge, and data logger.

Inside the pages of the Raspberry Pi Pico book

Raspberry Pi Pico also supports the I2C and SPI protocols for communicating with devices, which we explore by connecting it up to an LCD display. You can even use MicroPython to take advantage of one of Pico’s most powerful features, Programmable I/O (PIO), which we explore by controlling NeoPixel LED strips.

Get your copy today!

You can buy Get Started with MicroPython on Raspberry Pi Pico now really soon, the moment the second print edition is available, from the Raspberry Pi Press online store. If you don’t need the lovely new book, with its new-book smell, in your hands in real life, you can download a PDF version for free (or a small voluntary contribution).

STOP PRESS: we’ve spotted an error in the first print run of the book, affecting the code examples in Chapters 4 to 7. We’re sorry! Fortunately it’s easy for readers to correct in their own code; see here for everything you need to know.

We’ve corrected this in the PDF version, and we’re producing a corrected second print edition, which will be on sale soon.

What if I already bought a copy?

If you bought the first print edition from the Raspberry Pi Press Store or one of our fantastic Raspberry Pi Approved Resellers, a copy of the second edition will be on its way to you free of charge as soon as it’s available.

The post New book: Get Started with MicroPython on Raspberry Pi Pico appeared first on Raspberry Pi.

Raspberry Pi Pico – what did you think?

The best part of launching a new product is seeing the reaction of the Raspberry Pi community. When we released Raspberry Pi Pico into the world last Thursday, it didn’t take long for our curious, creative crew of hackers and tinkerers to share some brilliant videos, blogs and photos.

If you’ve spotted other cool stuff people have done with Raspberry Pi Pico, do comment with a link at the end of this post so we can check it out.

Graham Sanderson’s BBC Micro emulation

YouTube went wild for this Raspberry Pi Pico-powered BBC Micro and BBC Master emulation. Graham Sanderson‘s little bit of fun with our latest creation emulates the fine detail of the hardware required to get the best games and graphics demos to run.

He’s put together an entire playlist showing off the power of Raspberry Pi Pico, and it’s a retro gamer’s dream.

Alex Glow

Alex Glow went live for almost an hour unboxing our teeny tiny microcontroller, deep-diving into our getting started materials as well.

She has a good look around our launch blog post on camera too, unpacking some of the technical aspects of how Raspberry Pi Pico is powered, and also explaining why it’s so exciting that we’ve built this ourselves.

Jeff Geerling

Jeff Geerling has used his Pico for good, creating a baby-safe temperature monitor for his little one’s bedroom. In his video, he shows you around some of Raspberry Pi Pico’s “party tricks”, and includes the all-important build montage sequence.

If you prefer words to videos, Jeff has also put together a big ole blog post about our new microcontroller board.

Brian Corteil

Can not believe how popular this tweet has been nearly 100,000 impressions, 777 likes! Oh 😳 as pointed out by Sarah, Tom is 11 not 10. https://t.co/vpFYa1snoo

— Brian Corteil 🤖 (@CannonFodder) January 25, 2021

Brian Corteil took to Twitter to share his eleven-year-old’s pro soldering skills, proving that Raspberry Pi is for everyone, no matter how young, old, or inexperienced, or expert.

Extreme close-up!

Look at the finish on those pins!

16MB Pico modification

Daniel Green did what you were all thinking – desoldered the onboard 2MB QSPI flash chip and replaced it with a 16MB version. Say hello to the first Pico in the world with this special modification. 

Eben himself!

On top of all the brilliant comments, projects, and guidance our community has already shared, Raspberry Pi CEO Eben Upton will be joining the Digital Making at Home crew on Wednesday to show young coders around Raspberry Pi Pico.

Set a reminder for yourself (or your kids) to watch live on YouTube, or join in on Facebook, Twitter or Twitch at 7pm UK time.

The post Raspberry Pi Pico – what did you think? appeared first on Raspberry Pi.

NeoPixel dithering with Pico

In the extra special Raspberry Pi Pico launch issue of HackSpace magazine, editor Ben Everard shows you how to get extra levels of brightness out of your LEDs with our new board.

WS2812B LEDs, commonly known as NeoPixels, are cheap and widely available LEDs. They have red, green, and blue LEDs in a single package with a microcontroller that lets you control a whole string of them using just one pin on your microcontroller.

The three connections may be in a different order on your LED strip, so check the labels to make sure they’re connected correctly
The three connections may be in a different order on your LED strip, so check the labels to make sure they’re connected correctly

However, they do have a couple of disadvantages:

1) The protocol needed to control them is timing-dependent and often has to be bit-banged.

2) Each colour has 8 bits, so has 255 levels of brightness. However, these aren’t gamma-corrected, so the low levels of brightness have large steps between them. For small projects, we often find ourselves only using the lower levels of brightness, so often only have 10 or 20 usable levels of brightness.

There will usually be wires already connected to your strip, but if you cut it, you’ll need to solder new wires on
There will usually be wires already connected to your strip, but if you cut it, you’ll need to solder new wires on

We’re going to look at how two features of Pico help solve these problems. Firstly, Programmable I/O (PIO) lets us implement the control protocol on a state machine rather than the main processing cores. This means that we don’t have to dedicate any processor time to sending the data out. Secondly, having two cores means we can use one of the processing cores to dither the NeoPixels. This means shift them rapidly between different brightness levels to make pseudo-levels of brightness.

For example, if we wanted a brightness level halfway between levels 3 and 4, we’d flick the brightness back and forth between 3 and 4. If we can do this fast enough, our eyes blur this into a single brightness level and we don’t see the flicker. By varying the amount of time at levels 3 and 4, we can make many virtual levels of brightness. While one core is doing this, we still have a processing core completely free to manipulate the data we want to display.

First, we’ll need a PIO program to communicate with the WS2812B LEDs. The Pico development team have provided an example PIO program to work with – you can see the full details here, but we’ll cover the essentials here. The PIO code is:

.program ws2812
.side_set 1
.define public T1 2
.define public T2 5
.define public T3 3
bitloop:
    out x, 1.      side 0 [T3 - 1]
    jmp !x do_zero side 1 [T1 - 1]
 do_one:
 jmp bitloop       side 1 [T2 - 1]
 do_zero:
 nop               side 0 [T2 - 1]

We looked at the PIO syntax in the main cover feature, but it’s basically an assembly language for the PIO state machine. The WS2812B protocol uses pulses at a rate of 800kHz, but the length of the pulse determines if a 1 or a 0 is being sent. This code uses jumps to move through the loop to set the timings depending on whether the bit (stored in the register x) is 0 or 1. The T1, T2, and T3 variables hold the timings, so are used to calculate the delays (with 1 taken off as the instruction itself takes one clock cycle). There’s also a section in the pio file that links the PIO code and the C code:

% c-sdk {
#include "hardware/clocks.h"

static inline void ws2812_program_init(PIO pio,
uint sm, uint offset, uint pin, float freq, bool
rgbw) {

    pio_gpio_select(pio, pin);
    pio_sm_set_consecutive_pindirs(pio, sm, pin, 1,
true);
    pio_sm_config c = ws2812_program_get_default_
config(offset);
     sm_config_set_sideset_pins(&c, pin);
     sm_config_set_out_shift(&c, false, true, rgbw ?
32 : 24);
    sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);
 
    int cycles_per_bit = ws2812_T1 + ws2812_T2 +
ws2812_T3;
    float div = clock_get_hz(clk_sys) / (freq *
cycles_per_bit);

    sm_config_set_clkdiv(&c, div);
    pio_sm_init(pio, sm, offset, &c);
 
    pio_sm_set_enable(pio, sm, true);
}
%}

Most of this is setting the various PIO options – the full range is detailed in the Raspberry Pi Pico C/C++ SDK document.

 sm_config_set_out_shift(&c, false, true, rgbw ? 32
: 24);

This line sets up the output shift register which holds each 32 bits of data before it’s moved bit by bit into the PIO state machine. The parameters are the config (that we’re setting up and will use to initialise the state machine); a Boolean value for shifting right or left (false being left); and a Boolean value for autopull which we have set to true. This means that whenever the output shift register falls below a certain threshold (set in the next parameter), the PIO will automatically pull in the next 32 bits of data.

Using a text editor with programmer’s features such as syntax highlighting will make the job a lot easier
Using a text editor with programmer’s features such as syntax highlighting will make the job a lot easier

The final parameter is set using the expression rgbw ? 32 : 24. This means that if the variable rgbw is true, the value 32 is passed, otherwise 24 is passed. The rbgw variable is passed into this function when we create the PIO program from our C program and is used to specify whether we’re using an LED strip with four LEDs in each (using one red, one green, one blue, and one white) or three (red, green, and blue).

The PIO hardware works on 32-bit words, so each chunk of data we write with the values we want to send to the LEDs has to be 32 bits long. However, if we’re using RGB LED strips, we actually want to work in 24-bit lengths. By setting autopull to 24, we still pull in 32 bits each time, but once 24 bits have been read, another 32 bits are pulled in which overwrite the remaining 8 bits.

sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX);

Each state machine has two four-word FIFOs attached to it. These can be used for one going in and one coming out. However, as we only have data going into our state machine, we can join them together to form a single eight-word FIFO using the above line. This gives us a small buffer of time to write data to in order to avoid the state machine running out of data and execution stalling. The following three lines are used to set the speed the state machine runs at:

int cycles_per_bit = ws2812_T1 + ws2812_T2 +
ws2812_T3;
    float div = clock_get_hz(clk_sys) / (freq *
cycles_per_bit);
   sm_config_clkdiv(&c, div);

The WS2812B protocol demands that data is sent out at a rate of 800kHz. However, each bit of data requires a number of state machine cycles. In this case, they’re defined in the variables T1, T2, and T3. If you look back at the original PIO program, you’ll see that these are used in the delays (always with 1 taken off the value because the initial instruction takes one cycle before the delay kicks in). Every loop of the PIO program will take T1 + T2 + T3 cycles. We use these values to calculate the speed we want the state machine to run at, and from there we can work out the divider we need to slow the system clock down to the right speed for the state machine. The final two lines just initialise and enable the state machine.

The main processor

That’s the code that’s running on the state machine, so let’s now look at the code that’s running on our main processor cores. The full code is on github. Let’s first look at the code running on the second core (we’ll look at how to start this code running shortly), as this controls the light levels of the LEDs.

int bit_depth=12; 
const int PIN_TX = 0;

uint pixels[STRING_LEN]; 
uint errors[STRING_LEN];
 
static inline void put_pixel(uint32_t pixel_grb) {
    pio_sm_put_blocking(pio0, 0, pixel_grb << 8u);
}
static inline uint32_t urgb_u32(uint8_t r, uint8_t
g, uint8_t b) {
    return
            ((uint32_t) (r) << 8) |
            ((uint32_t) (g) << 16) |
            (uint32_t) (b);
}
void ws2812b_core() {
   int valuer, valueg, valueb;
   int shift = bit_depth-8;
 
    while (1){

     for(int i=0; i<STRING_LEN; i++) {
       valueb=(pixelsb[i] + errorsb[i]) >> shift;
       valuer=(pixelsr[i] + errorsr[i]) >> shift;
       valueg=(pixelsg[i] + errorsg[i]) >> shift;
       put_pixel(urgb_u32(valuer, valueg, valueb));
       errorsb[i] = (pixelsb[i] + errorsb[i]) -
(valueb << shift);
       errorsr[i] = (pixelsr[i] + errorsr[i]) -
(valuer << shift);
       errorsg[i] = (pixelsg[i] + errorsg[i]) -
(valueg << shift);
     }
     sleep_us(400);
   }
}

We start by defining a virtual bit depth. This is how many bits per pixel you can use. Our code will then attempt to create the necessary additional brightness levels. It will run as fast as it can drive the LED strip, but if you try to do too many brightness levels, you’ll start to notice flickering.

We found twelve to be about the best with strings up to around 100 LEDs, but you can experiment with others. Our code works with two arrays – pixels which holds the values that we want to display, and errors which holds the error in what we’ve displayed so far (there are three of each for the different colour channels).

If you just want to see this in action, you can download the UF2 file from hsmag.cc/orfgBD and flash it straight to your Pico
If you just want to see this in action, you can download the UF2 file from hsmag.cc/orfgBD and flash it straight to your Pico

To explain that latter point, let’s take a look at the algorithm for determining how to light the LED. We borrowed this from the source code of Fadecandy by Micah Scott, but it’s a well-used algorithm for calculating error rates. We have an outer while loop that just keeps pushing out data to the LEDs as fast as possible. We don’t care about precise timings and just want as much speed as possible. We then go through each pixel.

The corresponding item in the errors array holds the cumulative amount our LED has been underlit so far compared to what we want it to be. Initially, this will be zero, but with each loop (if there’s a difference between what we want to light the LED and what we can light the LED) this error value will increase. These two numbers (the closest light level and the error) added together give the brightness at the pseudo-level, so we need to bit-shift this by the difference between our virtual level and the 8-bit brightness levels that are available.

This gives us the value for this pixel which we write out. We then need to calculate the new error level. Let’s take a look at what this means in practice. Suppose we want a brightness level halfway between 1 and 2 in the 8-bit levels. To simplify things, we’ll use nine virtual bits. 1 and 2 in 8-bit is 2 and 4 in 9 bits (adding an extra 0 to the end multiplies everything by a power of 2), so halfway between these two is a 9-bit value of 3 (or 11 in binary, which we’ll use from now on).

In the first iteration of our loop, pixels is 11, errors is 0, and shift is 1.

value = 11 >> 1 = 1
errors = 11 – 10 = 1

So this time, the brightness level of 1 is written out. The second iteration, we have:

value = 100 >> 1 = 10
errors = 100 – 100 = 0

So this time, the brightness level of 10 (in binary, or 2 in base 10) is written out. This time, the errors go back to 0, so we’re in the same position as at the start of the first loop. In this case, the LED will flick between the two brightness levels each loop so you’ll have a brightness half way between the two.

Using this simple algorithm, we can experiment with different virtual bit-depths. The algorithm will always handle the calculations for us, but we just have to see what creates the most pleasing visual effect for the eye. The larger the virtual bit depth, the more potential iterations you have to go through before the error accumulates enough to create a correction, so the more likely you are to see flicker. The biggest blocker to increasing the virtual bit depth is the sleep_us(400). This is needed to reset the LED strip.

NeoPixels come in many different shapes and sizes

Essentially, we throw out bits at 800kHz, and each block of 24 bits is sent, in turn, to the next LED. However, once there’s a long enough pause, everything resets and it goes back to the first LED. How big that pause is can vary. The truth is that a huge proportion of WS2812B LEDs are clones rather than official parts – and even for official parts, the length of the pause needed to reset has changed over the years.

400 microseconds is conservative and should work, but you may be able to get away with less (possibly even as low as 50 microseconds for some LEDs). The urgb_u32 method simply amalgamates the red, blue, and green values into a single 32-bit string (well, a 24-bit string that’s held inside a 32-bit string), and put_pixel sends this to the state machine. The bit shift there is to make sure the data is in the right place so the state machine reads the correct 24 bits from the output shift register.

Getting it running

We’ve now dealt with all the mechanics of the code. The only bit left is to stitch it all together.

int main() {

   PIO pio = pio0;
   int sm = 0;
   uint offset = pio_add_program(pio, &ws2812_
program);
    ws2812_program_init(pio, sm, offset, PIN_TX,
1000000, false);
   multicore_launch_core1(ws2812b_core);

   while (1) {
       for (int i = 0; i < 30; ++i) {
        pixels[i] = i;

        for (int j=0;j<30;++j){
          pixels[0] = j;
            if(j%8 == 0) { pixels[1] = j; }
               sleep_ms(50);
            }
        for (int j=30;j>0;--j){
         pixels[0] = j;
            if(j%8 == 0) { pixels[1] = j; }
           sleep_ms(50);
         }
      }
   } 
}

The method ws2812_program_init calls the method created in the PIO program to set everything up. To launch the algorithm creating the virtual bit-depth, we just have to use multicore_launch_core1 to set a function running on the other core. Once that’s done, whatever we put in the pixels array will be reflected as accurately as possible in the WS2812B LEDs. In this case, we simply fade it in and out, but you could do any animation you like.

Get a free Raspberry Pi Pico

Would you like a free Raspberry Pi Pico? Subscribe to HackSpace magazine via your preferred option here, and you’ll receive your new microcontroller in the mail before the next issue arrives.

The post NeoPixel dithering with Pico appeared first on Raspberry Pi.

Meet Raspberry Silicon: Raspberry Pi Pico now on sale at $4

Today, we’re launching our first microcontroller-class product: Raspberry Pi Pico. Priced at just $4, it is built on RP2040, a brand-new chip developed right here at Raspberry Pi. Whether you’re looking for a standalone board for deep-embedded development or a companion to your Raspberry Pi computer, or you’re taking your first steps with a microcontroller, this is the board for you.

You can buy your Raspberry Pi Pico today online from one of our Approved Resellers. Or head to your local newsagent, where every copy of this month’s HackSpace magazine comes with a free Pico, as well as plenty of guides and tutorials to help you get started with it. If coronavirus restrictions mean that you can’t get to your newsagent right now, you can grab a subscription and get Pico delivered to your door.

Oops!… We Did It Again

Microcomputers and microcontrollers

Many of our favourite projects, from cucumber sorters to high altitude balloons, connect Raspberry Pi to the physical world: software running on the Raspberry Pi reads sensors, performs computations, talks to the network, and drives actuators. This ability to bridge the worlds of software and hardware has contributed to the enduring popularity of Raspberry Pi computers, with over 37 million units sold to date.

But there are limits: even in its lowest power mode a Raspberry Pi Zero will consume on the order of 100 milliwatts; Raspberry Pi on its own does not support analogue input; and while it is possible to run “bare metal” software on a Raspberry Pi, software running under a general-purpose operating system like Linux is not well suited to low-latency control of individual I/O pins.

Many hobbyist and industrial applications pair a Raspberry Pi with a microcontroller. The Raspberry Pi takes care of heavyweight computation, network access, and storage, while the microcontroller handles analogue input and low-latency I/O and, sometimes, provides a very low-power standby mode.

Until now, we’ve not been able to figure out a way to make a compelling microcontroller-class product of our own. To make the product we really wanted to make, first we had to learn to make our own chips.

Raspberry Si

It seems like every fruit company is making its own silicon these days, and we’re no exception. RP2040 builds on the lessons we’ve learned from using other microcontrollers in our products, from the Sense HAT to Raspberry Pi 400. It’s the result of many years of hard work by our in-house chip team.

RP2040 on a Raspberry Pi Pico

We had three principal design goals for RP2040: high performance, particularly for integer workloads; flexible I/O, to allow us to talk to almost any external device; and of course, low cost, to eliminate barriers to entry. We ended up with an incredibly powerful little chip, cramming all this into a 7 × 7 mm QFN-56 package containing just two square millimetres of 40 nm silicon. RP2040 has:

  • Dual-core Arm Cortex-M0+ @ 133MHz
  • 264KB (remember kilobytes?) of on-chip RAM
  • Support for up to 16MB of off-chip Flash memory via dedicated QSPI bus
  • DMA controller
  • Interpolator and integer divider peripherals
  • 30 GPIO pins, 4 of which can be used as analogue inputs
  • 2 × UARTs, 2 × SPI controllers, and 2 × I2C controllers
  • 16 × PWM channels
  • 1 × USB 1.1 controller and PHY, with host and device support
  • 8 × Raspberry Pi Programmable I/O (PIO) state machines
  • USB mass-storage boot mode with UF2 support, for drag-and-drop programming

And this isn’t just a powerful chip: it’s designed to help you bring every last drop of that power to bear. With six independent banks of RAM, and a fully connected switch at the heart of its bus fabric, you can easily arrange for the cores and DMA engines to run in parallel without contention.

For power users, we provide a complete C SDK, a GCC-based toolchain, and Visual Studio Code integration.

As Cortex-M0+ lacks a floating-point unit, we have commissioned optimised floating-point functions from Mark Owen, author of the popular Qfplib libraries; these are substantially faster than their GCC library equivalents, and are licensed for use on any RP2040-based product.

With two fast cores and and a large amount of on-chip RAM, RP2040 is a great platform for machine learning applications. You can find Pete Warden’s port of Google’s TensorFlow Lite framework here. Look out for more machine learning content over the coming months.

For beginners, and other users who prefer high-level languages, we’ve worked with Damien George, creator of MicroPython, to build a polished port for RP2040; it exposes all of the chip’s hardware features, including our innovative PIO subsystem. And our friend Aivar Annamaa has added RP2040 MicroPython support to the popular Thonny IDE.

Raspberry Pi Pico

Raspberry Pi Pico is designed as our low-cost breakout board for RP2040. It pairs RP2040 with 2MB of Flash memory, and a power supply chip supporting input voltages from 1.8-5.5V. This allows you to power your Pico from a wide variety of sources, including two or three AA cells in series, or a single lithium-ion cell.

Pico provides a single push button, which can be used to enter USB mass-storage mode at boot time and also as a general input, and a single LED. It exposes 26 of the 30 GPIO pins on RP2040, including three of the four analogue inputs, to 0.1”-pitch pads; you can solder headers to these pads or take advantage of their castellated edges to solder Pico directly to a carrier board. Volume customers will be able to buy pre-reeled Pico units: in fact we already supply Pico to our Approved Resellers in this format.

The Pico PCB layout was co-designed with the RP2040 silicon and package, and we’re really pleased with how it turned out: a two-layer PCB with a solid ground plane and a GPIO breakout that “just works”.

A reel of Raspberry Pi Pico boards
Reely good

Whether Raspberry Pi Pico is your first microcontroller or your fifty-first, we can’t wait to see what you do with it.

Raspberry Pi Pico documentation

Our ambition with RP2040 wasn’t just to produce the best chip, but to support that chip with the best documentation. Alasdair Allan, who joined us a year ago, has overseen a colossal effort on the part of the whole engineering team to document every aspect of the design, with simple, easy-to-understand examples to help you get the most out of your Raspberry Pi Pico.

You can find complete documentation for Raspberry Pi Pico, and for RP2040, its SDK and toolchain, here.

Get Started with Raspberry Pi Pico book

To help you get the most of your Pico, why not grab a copy of Get Started with MicroPython on Raspberry Pi Pico by Gareth Halfacree and our very own Ben Everard. It’s ideal for beginners who are new (or new-ish) to making with microcontrollers.

Our colleagues at the Raspberry Pi Foundation have also produced an educational project to help you get started with Raspberry Pi Pico. You can find it here.

Partners

Over the last couple of months, we’ve been working with our friends at Adafruit, Arduino, Pimoroni, and Sparkfun to create accessories for Raspberry Pi Pico, and a variety of other boards built on the RP2040 silicon platform. Here are just a few of the products that are available to buy or pre-order today.

Adafruit Feather RP 2040

RP2040 joins the hundreds of boards in the Feather ecosystem with the fully featured Feather RP 2040 board. The 2″ × 0.9″ dev board has USB C, Lipoly battery charging, 4MB of QSPI flash memory, a STEMMA QT I2C connector, and an optional SWD debug port. With plenty of GPIO for use with any FeatherWing, and hundreds of Qwiic/QT/Grove sensors that can plug and play, it’s the fast way to get started.

Feathery goodness

Adafruit ItsyBitsy RP 2040

Need a petite dev board for RP2040? The Itsy Bitsy RP 2040 is positively tiny, but it still has lots of GPIO, 4MB of QSPI flash, boot and reset buttons, a built-in RGB NeoPixel, and even a 5V output logic pin, so it’s perfect for NeoPixel projects!

Small is beautiful

Arduino Nano RP2040 Connect

Arduino joins the RP2040 family with one of its most popular formats: the Arduino Nano. The Arduino Nano RP2040 Connect combines the power of RP2040 with high-quality MEMS sensors (a 9-axis IMU and microphone), a highly efficient power section, a powerful WiFi/Bluetooth module, and the ECC608 crypto chip, enabling anybody to create secure IoT applications with this new microcontroller. The Arduino Nano RP2040 Connect will be available for pre-order in the next few weeks.

Get connected!

Pimoroni PicoSystem

PicoSystem is a tiny and delightful handheld game-making experience based on RP2040. It comes with a simple and fast software library, plus examples to make your mini-gaming dreams happen. Or just plug it into USB and drop the best creations from the Raspberry Pi-verse straight onto the flash drive.

Pixel-pushing pocket-sized playtime

Pimoroni Pico Explorer Base

Pico Explorer offers an embedded electronics environment for educators, engineers, and software people who want to learn hardware with less of the “hard” bit. It offers easy expansion and breakout along with a whole bunch of useful bits.

Go explore!

SparkFun Thing Plus – RP2040

The Thing Plus – RP2040 is a low-cost, high-performance board with flexible digital interfaces featuring Raspberry Pi’s RP2040 microcontroller. Within the Feather-compatible Thing Plus form factor with 18 GPIO pins, the board offers an SD card slot, 16MB (128Mbit) flash memory, a JST single-cell battery connector (with a charging circuit and fuel gauge sensor), an addressable WS2812 RGB LED, JTAG PTH pins, mounting holes, and a Qwiic connector to add devices from SparkFun’s quick-connect I2C ecosystem.

Thing One, or Thing Two?

SparkFun MicroMod RP2040 Processor

The MicroMod RP2040 Processor Board is part of SparkFun’s MicroMod modular interface system. The MicroMod M.2 connector makes it easy to connect your RP2040 Processor Board with the MicroMod carrier board that gives you the inputs and outputs you need for your project.

The Mighty Micro

SparkFun Pro Micro – RP2040

The Pro Micro RP2040 harnesses the capability of RP2040 on a compact development board with the USB functionality that is the hallmark of all SparkFun’s Pro Micro boards. It has a WS2812B addressable LED, boot button, reset button, Qwiic connector, USB-C, and castellated pads.

Go Pro

Credits

It’s fair to say we’ve taken the long road to creating Raspberry Pi Pico. Chip development is a complicated business, drawing on the talents of many different people. Here’s an incomplete list of those who have contributed to the RP2040 and Raspberry Pi Pico projects:

Dave Akerman, Sam Alder, Alasdair Allan, Aivar Annamaa, Jonathan Bell, Mike Buffham, Dom Cobley, Steve Cook, Phil Daniell, Russell Davis, Phil Elwell, Ben Everard, Andras Ferencz, Nick Francis, Liam Fraser, Damien George, Richard Gordon, F Trevor Gowen, Gareth Halfacree, David Henly, Kevin Hill, Nick Hollinghurst, Gordon Hollingworth, James Hughes, Tammy Julyan, Jason Julyan, Phil King, Stijn Kuipers, Lestin Liu, Simon Long, Roy Longbottom, Ian Macaulay, Terry Mackown, Simon Martin, Jon Matthews, Nellie McKesson, Rod Oldfield, Mark Owen, Mike Parker, David Plowman, Dominic Plunkett, Graham Sanderson, Andrew Scheller, Serge Schneider, Nathan Seidle, Vinaya Puthur Sekar, Mark Sherlock, Martin Sperl, Mike Stimson, Ha Thach, Roger Thornton, Jonathan Welch, Simon West, Jack Willis, Luke Wren, David Wright.

We’d also like to thank our friends at Sony Pencoed and Sony Inazawa, Microtest, and IMEC for their help in bringing these projects to fruition.

Buy your Raspberry Pi Pico from one of our Approved Resellers today, and let us know what you think!

FAQs

Are you planning to make RP2040 available to customers?

We hope to make RP2040 broadly available in the second quarter of 2021.

The post Meet Raspberry Silicon: Raspberry Pi Pico now on sale at $4 appeared first on Raspberry Pi.

❌