Articles Hierarchy

Articles Home » RPI » Raspberry Pi PICO

Raspberry Pi PICO

here now 'my two worlds' come closer together..
Raspberry Pi has a little brother, a arduino like development board
the PICO




its a 6$ board but i will play with it for month to come..
and also BLOG it in several articles, so here the SUMMARY MENU
PICO : development environments
PICO_W 1: development environments
PICO_W 2: CP advanced web server
PICO_W 3: CP advanced web server 2, MQTT
PICO_W 4: RPI3 MQTT broker, Node-Red setup
PICO_W 5: more hardware for MQTT project
PICO_W 6: NR MQTT Local & Remote SQLite DB



info links
setup C++ SDK and IDE
setup Micro Python
setup Circuit Python
online BLOCKs over python
Arduino IDE



info links



https://www.raspberrypi.org/documentation/pico/getting-started/
also see
https://hackaday.com/2021/01/20/raspberry-pi-enters-microcontroller-game-with-4-pico/
and more
https://www.raspberrypi.org/blog/raspberry-pi-pico-what-did-you-think/
the data sheet for the board
https://datasheets.raspberrypi.org/pico/pico_datasheet.pdf


setup C++ SDK and IDE



https://datasheets.raspberrypi.org/pico/getting_started_with_pico.pdf
you might try
https://raw.githubusercontent.com/raspberrypi/pico-setup/master/pico_setup.sh or
https://github.com/raspberrypi/pico-setup/blob/master/pico_setup.sh

touch pico_setup.sh
nano pico_setup.sh
copy paste raw code into
chmod +x pico_setup.sh
./pico_setup.sh





ok, today 22.02.2021 i see that one shop has now boards available and i ordered / only one to see how that works out about payment on delivery / here
for 209 THB ( incl. transport, no pins ) about 5.7 Euro, and delivery took 6 days.

well, already had following question in my mind:
if i install microPython on it, how to UNDO?



ok, lets get a micro USB cable from an old phone
++ connect board to cable,
++ cable to USB of RPI4 ++ while press board "bootsel" button until see

now drag drop (copy) downloaded "blink.uf2" file ( using the file-manager in 2 window mode )
the USB connection drops & board reboots & executes blink.uf2 & LED blinks.

for verify that it also blinks again after cable ( power ) reconnected,
ok, that means it is "installed" as "main"
when you connect with bootsel button pressed you see same 2 files from first connection

INFO_UF2.TXT:
UF2 Bootloader v1.0
Model: Raspberry Pi RP2
Board-ID: RPI-RP2


INDEX.HTM:
Redirecting to https://www.raspberrypi.org/documentation/rp2040/getting-started/


now follow the getting started, "hallo world.uf2"
and use terminal minicom


and best do
nano /home/pi/.bash_aliases
and add line
alias PICO='minicom -b 115200 -o -D /dev/ttyACM0'
and remember:
help [ctrl][a][z]
end [ctrl][a][x]



rerun my Arduino IDE install-script on this RPI4
and start it just to use the "monitor" instead the minicom

but for programming the PICO today we can not use the Arduino IDE
i hope that will come soon.


so now is it the situation to learn how to use the above by the script installed tools to make our first own PICO C++ code
let us build one of the examples:
( i use /home/pi/projects/pico/blink/ ) and there have 3 files:
pico_sdk_import.cmake
blink.c
CMakeLists.txt

the first 2 i copy
the
CMakeLists.txtcmake_minimum_required(VERSION 3.12)

include(pico_sdk_import.cmake)

project(blink)

pico_sdk_init()

add_executable(blink blink.c )

# Pull in our pico_stdlib which pulls in commonly used features
target_link_libraries(blink pico_stdlib)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(blink)

now use following commands:
mkdir build
cd build
cmake ..
make blink

and find ... blink.uf2 what you can copy to the PICO board


and make a new project where you really start to code ..
i try first a combination of BLINK and Hallo_World_USB


with this we have lots of the prior installed tool tested already, only the big thing:
Visual Studio Code IDE test ( microsoft free ware ) is open:
cd /home/pi/projects/pico/blink/
code

this should open the VSC window and now do:
/open folder / ( like select: projects/pico/blink/ ) OK
/open file /blink/blink.c
but for the line:
#include "pico/stdlib.h"
i get a ERROR ( path / file not found )

here i need to find how to adjust that IDE
i try to follow https://www.youtube.com/watch?v=Q1Kfg8k54jM
the point was i needed to select the correct compiler ( tool button )
GCC for arm non-eabi 7.3.1 and build again.

++ and just to be sure all works, i deleted the old /build/ directory

and load it to PICO for test.


as the PICO has 2 core that concept might be new if you come from old Arduino boards
https://www.youtube.com/watch?v=9vvobRfFOwk


here i will start with Raspberry Pi PICO C++ code projects but use a extra
BLOG


a top level example project NEO PIXEL ( C++ & 2 core & inline machine code )
https://www.raspberrypi.org/blog/neopixel-dithering-with-pico/


esp in the VNC window i feel that the VSC IDE is a ugly unreadable thing,
but it is possibly the best environment for deep controller programming / with debugging / machine code...


setup Micro Python



for a easy start with PYTHON get/download the free book
RPi_Pi Pico_Digital Edition.pdf
that helps to setup the PICO for Micro Python ( download and flash )
and use Thonny Python IDE ( like from a Raspbery Pi desktop or install from thonny.org )
a nice video tutorial here


-1- i start with a update of the RPI4 to be sure i have the latest Thonny version
-2- download the uf2 file
rp2-pico-20210222-unstable-v1.14-80-g75db0b907.uf2
and copy to [bootsel]ected PICO
-3- start Thonny Python IDE and select ( right bottom )
Micro Python (Raspberry Pi Pico)
-4- write your first test code
and save as "test1.py" to PICO
-5- press the RUN button.


please note that when you are in this MICRO PYTHON environment
++ you can save files to PC or board
++ you can load ( save ) and execute without the USB cable disconnect & [bootsel] button
++ must call it "main.py" to have it autostart at power / boot.


and to my above first question, after i loaded the micro python environment to PICO
i can go back to C++ just by loading my old blink.uf2
or do a flash clean first by download this see here
what reboots also, but brings you back to the USB file window for loading something else.
well, would be nice to know how to check what is loaded / how much space is free ...
i miss the Arduino IDE...
funny just today find that IDE new v2.0:
https://blog.arduino.cc/2021/03/01/announcing-the-arduino-ide-2-0-beta/
i install on win10 PC:

( bad, in terminal ( monitor ) now need to press [space][ctrl][enter] instead [space] like in minicom )
and still not find info about new PICO board


setup Circuit Python


follow a good YOUTUBE video
see also here

-a- download adafruit-circuitpython-raspberry_pi_pico-en_US-6.2.0-beta.3.uf2
from here
-b- PICO [bootsel] load it
-c- find USB drive
/media/pi/CIRCUITPY
-d- start minicom
and try a python command at the >>> REPL prompt like
print("i am PICO")
-e- install MU ( other python IDE for test )
-f- play some code

on Rapberry Pi 4 use browser and filemanager ( 2 window mode )

after flash UF2 see the mapped USB drive, a local workpath
and a minicom REPL console

after install MU python editor select adafruit circuit python

edit the PICO USB drive file 'code.py' and see its execution in serial terminal at SAVE


first_test: code.py
now why use circuit python and NOT micro python?
looks like the big advantage is the adafruit libraries you can use with circuit python,
you download the whole thing, unzip, and take out the one lib you want use and copy it down into the boards lib folder:
/media/pi/CIRCUITPY/lib/
like adafruit_dht.mpy from adafruit-circuitpython-bundle-6.x-mpy-20210403.zip from here
so here i want play ( first time using ) this 3 pin DHT22 AM3202 module ( 3$ )

where above library is needed ( how is that called? ONE WIRE with puls_io )
what according GIT should work now already with the PICO and circuit python dht lib



this code


also got a new little OLED display "white" ( 2$ )

now it was not any info provided, but when i compare the front/back picture with other shops,
there i found info that the SSD1306 chip might be used.
so search library pack again and copy to PICO board

not need to pay for FRITZING, use Google sheets (excel) with integrated (draw) lines for wiring.



after some time / a break / i read about new Circuit Python version "6.3"
and think about to make a fast test from win10 PC...

-a1- from here download
adafruit-circuitpython-raspberry_pi_pico-en_US-6.3.0.uf2

-a2- but also prepare a cleanup: get flash_nuke.uf2

-b- from MU editor get Mu-Editor-Win64-1.1.0b4.msi , the 64bit version for win10 and install, start ( takes very long ) and select "write Circuit Python directly on your boards "

-c- connect the RP2040 board and backup the old ( circuit python ) code i was working on...
( /lib/... and code.py )
windows complain about that "drive" at connection.. but that backup worked

-d- when i try to load the new circuitpython there i get error "disk is full"
but that was anyhow a mistake...ok:
++ restart board with 'bootsel"
++ copy nuke
wait board comes back
++ copy circuitpython
wait board comes back with "circuitpy" drive
++ copy back project and libs ( or need to update libs also? )
++ start MU editor
restart serial & [ctrl][d]
soft reboot

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.

code.py output:
adafruit_displayio_ssd1306 library loaded
Traceback (most recent call last):
File "code.py", line 54, in
RuntimeError: No pull up found on SDA or SCL; check your wiring

Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.



update: 22.8.2021
just for recheck ( and i not play RPI PICO some time )
on Win 10 PC:
get:
+ + Mu-Editor-Win64-1.1.0b5.msi and install
( install normal, first start long setup)

+ + adafruit-circuitpython-raspberry_pi_pico-en_US-7.0.0-alpha.6.uf2
( just to be sure could use flash_nuke.uf2 first )
remember? press the reset button and connect USB... so see the USB drive where you can put the UF2 file to.

now i get ( like on REPL [ctrl][d] ) a error about incompatible "mpy" files...
means i must update the libs too? get
adafruit-circuitpython-bundle-7.x-mpy-20210822.zip
and load / overwrite in board / libs / all old files.
also download
adafruit-circuitpython-bundle-examples-20210822.zip
but first start with a new
code.pyimport time
import board
import digitalio

print(help("modules"))
print(dir(board))
print("\n\nrestart with new circuit python 7.0.0alpha6 22.8.2021 ")
print("\n\nHallo world, this is RPI-RP2")

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
print("\n\nnow blinking the LED")

while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)




follow here to use micro python with circuit python libraries...


online BLOCKs over micro python


but for beginner & using the micro python environment:
can create block based programs for Raspberry Pi Pico in minutes using BIPES !
on Chrome with chrome://flags/ Experimental Web Platform features [enabled]
select board [Raspberry Pi PICO]
connect to USB port and
test micro python in console

create blocks code and press RUN

go back CONSOLE to see what code was loaded



Arduino IDE


UPDATE 25.3.2021:
well, as expected they work on the arduino IDE about the tool chain and board-manager for Raspberry Pi PICO ( or other RP2040 boards )
Github
-1-
goto preferences and add there ( if not empty after a ',' )
https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
-2-
goto Board Manager and search 'rasp', find Raspberry Pi Pico/RP2040 and press [install] ( download board and tools ( about 170-MB ))

-3-
select the board
-4-
find already examples ( eeprom / led fade / servo sweep )

little bit more on the new Arduino IDE also here but use for ESP
but restart for use with RP2040 here


info on use DEBUG


PICO W