Tag Archives: Raspberry Pi Pico

Automatically tune your guitar with Raspberry Pi Pico

via Raspberry Pi

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

via Raspberry Pi

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

via Raspberry Pi

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

via Raspberry Pi

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

via Raspberry Pi

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.

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

via Raspberry Pi

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.