Pages

Friday, February 5, 2021

Raspberry Pico a first look

For an index to all my stories click this text

I bet you heard by now there is a new kid in town: the Rapsberry Pico

For those who already have one or have been reading about it: see you next time. For those who have no clue what it is a bout: read on.

The Raspberry Pi company is well-known for its small Linux computers. I have used them myself in several projects on this weblog. I made an internet radio with it. My home automation system Domoticz runs on a Raspberry Pi and I did some experiments with the Raspberry camera. You can find these stories by clicking on the top red text on this page that brings you to the index.

However the Raspberry Pico is something completely different. It is not a computer but it is a microcontroller just like the Arduino or the ESP8266 and ESP32. You can use it instead of an Arduino and in certain circumstances also as a replacement for an ESP.

There are a few differences with the establishment of the microcontrollers.
- The Raspberry Pico has no wifi or other wireless communication.
- The Pico can be programmed in C and in Python.

Here is the obvious difference with a controller from the ESP series: no wifi. So no internet communications and no web-pages running on the controller. In this view it is more as an Arduino.

But then the specs are impressive:

- Dual Core Arm Cortex MO processor running up to 133 Mhz
- 264Kb Ram
- 2 Mb Flash
- 26 Multifunction IO pins
- 3 Analog input pins
- 2 UART, 2 SPI controllers, 2 I2C controllers, 16 PWM channels
- 1 USB port with Host and Device support.
- Build in temperature sensor
- 8 Programmable I/O (PIO) state machines

You get all this for about 4 euro !!!
So that's an European product running about 10 times the speed of an Arduino and with loads of IO ports for a ridiculous price.



Above you can see from left to right the ESP8266 (Wemos D1 version) the ESP32 (Devkit 1 version) and the new Pico. The Pico is as tall as the ESP32 but not as wide.



The small width makes it possible to fit the Pico seemless on a breadboard. So no hassle like the ESP32 Devkit has.

Software ??

The Pico can run C and Python programs at the moment. Unfortunately not the Arduino C++ version. Arduino corporation is at this moment developing some boards useing the same processor as the Pico and have annlounced that the Arduino IDE will be developed for the Pico. Just a matter of time.

At this moment I am focussing on Python.
I already did several projects with Python on the 'normal' Raspberries like the internet radio on the humble Raspberry Zero: https://lucstechblog.blogspot.com/2018/10/raspberry-pi-internet-radio-part-3.html
Next to that I must be proud about Python as it is invented by a fellow Dutchman: Guido van Rossum

There are two variations of Python available for the Pico: MicroPython and CircuitPython both have their pro's and cons. At this moment I stick to MicroPython as that is supported by the Raspberry foundation. However I will look into Circuitpython in the next weeks as there might be some interesting libraries available only for MicroPython. By the way, CircuitPython is a fork of MicroPython and supported by Adafruit.

The Pico can be programmed from The Raspberry Pi computers, Linux machines, Apple Mac's and Windows.
For programming with Python the Thonny IDE is recommended and has a special connection to the Pico. Thonny is devellopped at the university of Tartu in Estonia and supported by the Raspberry Pi foundation.

Thonny can be downloaded here: https://thonny.org/

I am not delving to deep into this at the moment as there is very good documentation available on the Raspberry Pi's website: https://www.raspberrypi.org/documentation/pico/getting-started/

I was just amazed how simple it was to get the Pico up and running. So I'll show how to do that briefly here. This is Windows based.

After I downloaded Thonny on my PC it looked like this.



The arrow points to the version of Python you are currently using. When I started it pointed at Python 3.7.9 which is installed on my PC.
Now plug in the Raspberry Pico in a USB port on your computer and wait a few seconds.



Thonny just recognised the Raspberry Pico.


Click on the Raspberry Pico line



A new small window opens. The Pico is already recognised so press the boot-selector on the Pico, hold it and click on Install.

import machine
import utime
led = machine.Pin(25, machine.Pin.OUT)
while True:
    led.value(1)
    utime.sleep(.5)
    led.value(0)
    utime.sleep(.5)

Write the above program in Thonny, save it as hello.py, and press the small green run button and your on-board led should start blinking.

Done !!!

My first program running on the Raspberry Pico in no time.

The program which you just named is saved on the Pico itself in its flash memory. Save it again with the name main.py and you can attach the Pico to a USB power supply or powerbank and it runs automatically. Just like any program saved to an Arduino or ESP would run.



A disadvantage is that the pin layout is only printed on the backside of the Pico. Therefore the pin-numbers are not easily recognisable when the Pico is put on a breadboard.



A nice feature is that the IO pins have rounded connectors and the GND pins have square ends. And they are put at opposite sides on the development board.



To solder the headers on easily, first plug them into a breadboard at the right distance.



Next put the Pico on the headers and solder them.



And here is my first working project. A thermometer with a TM1637 display. Installing the software, soldering the headers and getting my first project up and running is all done in a few hours.

Concluding

Getting the Raspberry Pico up and running is a piece of cake and getting my forst test project up and running was equally easy.
Check the Rapsberry Pico out. It is worth the few euro's and for the price a great competition to the Arduino's. It even is a good replacement for the ESP's as long as you do not need Wifi.

Til next time
Have fun

Luc Volders