Carte Raspberry Pi Pico H RP2040 ( avec connecteurs pré-soudés) programmable en C/C++ et MicroPython
Le premier microcontrôleur Raspberry Pi en silicium avec Puce RP2040
- Programmation en C / C ++ et MicroPython
- Processeur ARM Cortex M0 + double cœur - 133 MHz avec 264 Ko de SRAM et 2 Mo de mémoire Flash intégrée
- 26 broches GPIO multifonction
- 2 × SPI, 2 × I2C, 2 × UART, 3 × ADC 12 bits, 16 × canaux PWM contrôlables
Raspberry Pi PICO
Caractéristiques :
| |
---|---|
Premiers pas avec Raspberry Pi Pico
Quelle heure, hein ? Après un tourbillon absolu de lancement, Raspberry Pi Picos commence à atterrir dans les boîtes aux lettres des gens et beaucoup de gens qui n'ont pas eu grand-chose à voir avec les microcontrôleurs auparavant recherchent un endroit pour commencer à comprendre quoi faire avec eux. Bienvenue! C'est le moment idéal pour monter à bord du train de microcontrôleurs - vous allez l'adorer.
Quel est ce guide ?
Dans ce guide, nous allons donner une brève introduction conviviale aux débutants sur le Pico et vous montrer les étapes nécessaires pour le configurer et le préparer pour la programmation avec MicroPython. Nous couvrirons également ce que vous devez faire pour pouvoir jouer avec diverses cartes d'extension Pimoroni. Nous aurons du contenu plus spécifique pour les cartes individuelles à l'avenir, mais j'espère que ce guide sera juste suffisant pour vous permettre de commencer à expérimenter avec votre Pico.
Nous n'allons pas entrer dans les détails de tout ce que le Pico peut faire ici - pour un guide complet et convivial pour les débutants avec de nombreuses expériences amusantes à faire avec du matériel physique, nous recommandons l'excellent Premiers pas avec MicroPython sur le Raspberry Pi Pico livre. Si vous recherchez des détails techniques, nous vous suggérons de consulter les ressources sur le site Raspberry Pi, y compris la fiche technique complète de Pico. Si vous savez déjà programmer un microcontrôleur, vous pouvez trouver des références de fonctions pour nos cartes et autres dans notre référentiel Pico Github.
About Raspberry Pi Pico
Raspberry Pi Pico is Raspberry Pi's first microcontroller board, designed around their very own microcontroller chip - the RP2040. A Pico is not a replacement or upgrade for a Raspberry Pi - they're very different beasts! A Raspberry Pi is a Single Board Computer that runs Linux, to which you can connect a monitor, keyboard and mouse and interact with via a terminal prompt or a graphical user interface such as the Raspberry Pi OS desktop. You can run many different Linux applications on a Raspberry Pi and it has a ton of processing power and RAM.
While Raspberry Pis are champion multi-taskers, microcontrollers shine in projects where they have one job and need to do it well. Because they're programmed from another computer and don't need to run a full OS, they have greatly reduced power consumption compared to SBCs and are ideal for powering from batteries. Programs on microcontrollers just start running once they're powered up, so there's no boot up time, and you usually don't need to shut them down safely. Focusing on just one thing means that microcontrollers are typically more stable and predictable, making them perfect for using as the brains of projects that need to Just Work, like industrial machines, coffee makers or emergency zombie defence turrets.
Interfacing with hardware is also more straightforward with microcontrollers, and Raspberry Pi Pico is specifically geared towards physical computing (AKA connecting it to interesting stuff that lights up, moves or makes noise). Unlike a Pi, Pico has inbuilt Analog to Digital Convertors (ADCs) so you can connect it to a wider range of sensors and inputs. It also has Programmable IOs (PIOs) which are used behind the scenes in our libraries, outsourcing simple bits of programs to run in the background and freeing up the majority of the Pico's CPU to concentrate on the trickier parts. If you're interested in the possibilities of PIOs check out our Unicorn Pack page, where we describe how we managed to get 14 bits of resolution from the LED drivers on the Pico version (meaning improved rainbows!)
What you'll need
-
A USB cable - you'll need a microB USB cable to plug your Pico into your computer to be able to program it. You may well have one already, from an old phone, a Pi Zero or a micro:bit but you'll need it to be capable of transmitting data over USB as well as power. All the cables we sell are data-capable.
-
Header pins - to be able to plug your Pico into our Packs and Bases (or a breadboard) it will need to be equipped with header pins. We'll cover how to solder them to your Pico later in this guide. You'll also need soldering supplies - a soldering iron, solder and tip cleaner. A breadboard is handy for keeping your pins in place while you solder.
-
A computer to program your Pico from (the software you'll need, Thonny, is free and available for Raspberry Pi, PC, Mac or Linux).
-
One (or more!) of our Pico addons - you can browse them all here.
MicroPython or C/C++?
You can program Pico with MicroPython (a version of Python especially for microcontrollers) or the C/C++ SDK (you might be familiar with C/C++ if you've had anything to do with Arduinos) - we have code examples and libraries for both! It's also possible to use CircuitPython (Adafruit's version of MicroPython) on the Pico but Pimoroni boards may not currently be easily compatible if you go down this route.
This guide is going to use MicroPython as it's super simple to get going with our custom firmware, and you can use Thonny to program your Pico from a PC, Mac or even a Raspberry Pi.
Installing the custom firmware
If you're planning on using one of our Pico addons, you'll need our custom build of MicroPython which comes with our libraries baked in. You can find it in our Pico Github repository, on the releases page - make sure to download the most recent version of the .uf2 file.
To be able to copy this file on to your Pico, you'll need to put it into bootloader mode. To do this, hold down the BOOTSEL button whilst plugging the USB cable into your computer - it should now show up as a drive called RPI-RP2. Here's what it looks like in Windows:
Copy the downloaded .uf2 file across to this new drive. Your Pico will now reboot, and after a few seconds it will be running pirate-brand MicroPython (you probably won't notice any difference, but it's actually singing sea shanties very quietly to itself).
Installing Thonny
Thonny is a Python IDE (an Integrated Development Environment). It's the software you'll install on your computer to program your Pico.
If you're programming your Pico from a Raspberry Pi running the desktop version of Raspberry Pi OS, Thonny should be installed already. You may need to update it to the most recent version to get the Pico specific options, you can do this by opening up a terminal (find it in the menus, or hit Ctrl-Alt-T) and typing
sudo apt update && sudo apt upgrade -y
and pressing enter.
You can download Thonny in Windows, Mac or Linux flavours here. Once it's installed, open it up!
You'll need to select 'MicroPython (Raspberry Pi Pico)' as your interpreter - you can do that by clicking on the box at the bottom right. Thonny might offer to install MicroPython for you, you don't need to do this as you should already have our variant of MicroPython installed.
Using Thonny (Hello World and Blink)
With your Pico connected to your computer with the USB cable (no need to hold down the button this time, you don't want to be in bootloader mode), click on the bottom 'Shell' box, so you get a flashing cursor. By typing instructions into this box you can give commands to your Pico directly, one command at a time (this is called REPL, or Read-Eval-Print Loop).
Try typing
print("hello world")
and pressing enter. See how it parrots hello world
right back at you? Your Pico is talking back to you via the serial console and it can tell you all sorts of useful things - error messages and anything you print
(such as sensor readings) will show up in this box. This can be very handy for debugging your code!
Of course, you will probably want to queue up more than one line of instructions to make up a program- that's what the top box is for. Here's a basic program you can try to test out your Pico is working properly, before soldering anything to it. You can either copy and paste it into Thonny or type it in. If you're typing it in, make sure the bottom two lines have four spaces in front of them to indent them (indents are used here to denote when code is part of a loop).
import machine
import utime
led = machine.Pin(25, machine.Pin.OUT)
while True:
led.toggle()
utime.sleep(2)
This program
- imports the modules necessary to let your Pico interact with basic hardware and know about the concept of time
- gives the Pico's onboard LED a friendly name (led) so it's easy to refer to in code, and sets it as an OUTput.
- sets up a simple loop, which turns the onboard LED on or off, waits two seconds, and then repeats.
Once you're ready to transfer the program to your Pico, press the green 'run current script' button in the top toolbar. You'll be prompted to give it a name - you can use any name you like, but if you save the file to your Pico as main.py
it will run automatically when the Pico is connected to power, you won't need to start it in Thonny. This is useful if you want to make a battery powered project that won't be connected to a PC!
Note that when using MicroPython you won't be able to copy code that you've written to your Pico by holding the button down to put it into bootloader mode and copying the file across - you'll always need to transfer it using Thonny.
Soldering the headers
To plug in our addon boards or to plug your Pico into a breadboard, your Pico will need to have headers soldered to it, with the pins sticking out of the back. Soldering headers is not hard with modern PCBs and we'd encourage you to give it a go (but if you'd rather skip the soldering, we should have pre-soldered Picos available very shortly).
Your headers might come pre-separated into two 20 pin lengths, or in one long length. If it's the latter, you can separate them in to two lengths with side cutters (it's also possible to break them apart with sturdy scissors, or even your thumbnail).
You'll need to solder your headers so that the pins are sticking out of the back of the Pico, with the long pins sticking out of the side with the labels and the soldering itself on the side with the button. The pins should be at right angles to the Pico so that they can plug into things nicely. Using a breadboard to hold the pins in place while you solder is a good way of making sure things remain square while soldering, but you can also use a large blob of blu-tack or similar to hold things together (or even a helping hand, if you're fancy).
Poke the long ends of your two lengths of header into your breadboard, the same width apart as the two rows of holes on your Pico.
Place your Pico on top of the short ends with the button and the raspberry facing upwards.
Make sure your workspace has adequate ventilation and consider wearing eye protection as solder can sometimes behave unexpectedly. Once you're ready to start soldering, make sure to tin the end of your iron - wait until it's up to temperature, melt a little bit of solder onto the tip and then clean off the excess using your tip cleaner. You're ready to go!
You'll want to position your soldering iron so it's applying heat evenly to the header pin and the pad on the board, and then hold it in place for a few seconds. You can then feed a little bit of solder into the place where the pad, the iron and the header pin meet - don't go overboard with the solder, you only need a tiny bit and you can always add more later. The solder should flow satisfyingly down the iron and form a joint between the pad and the pin.
We'd suggest soldering one pin at each end, and then checking again to make sure the headers are square. You can adjust them at this point if you need to, but you won't be able to later. Once you're satisfied that everything is 90°, go ahead and solder the rest of the pins.
When you're done, check your solder joints from all angles. A good joint should surround the pin on all sides, and ideally should be shaped like a squat little cone. If you have joints that don't quite surround the pin, heat up the solder again to reflow it, and hopefully it will fill the gaps. If it doesn't, you can add a bit more solder (but try reflowing the solder on its own first). You'll also want to check for solder joints that touch and bridge two pins - if you have any of these you can fix them by holding your iron to the middle of the unwanted join for a second or two, which should make the two blobs separate.
When removing your Pico from the breadboard we'd suggest holding on to the long edges and rocking it gently from side to side whilst pulling upwards slowly - try to avoid putting too much pressure on the pins at the ends as these are most liable to bend. If they do get bent you can bend them back, but doing this too many times can cause metal fatigue.
Using Pimoroni Bases and Packs
Once your Pico has headers attached, it's fully equipped for plugging into one of our Packs or Bases. All our Pico addons have markings that should make it obvious which way round you need to plug it in - here is a upside down Display Pack, ready for plugging in to a Pico (the surfaces shown in the photo below will be on the inside of the Pico+Pack sandwich).
Double check you've got the male and female headers lined up, and push on the edges of the board to join them together (if you're using a Display Pack, take care not to apply pressure to the screen).
Pico landing areas on Bases are similarly marked, just match up the markings on the PCB to figure out which way round the Pico should go.
Vous aimerez aussi