10 Tips For Raspberry Pi-Pico Coding
In this guide we go over 10 power tips for getting yourself going programming the raspberry pi-pico ecosystem. It can be very challenging when you leave the 'pin flipping' python basics!
1. Get a 'Sacrifice Hub.' If you are plugging/unplugging your raspberry pi-pico dozens of times - eventually (as I found out) you will damage the port on your laptop / PC. Instead get a hub with power switches. Preferably - get a powered one that does not tax your internal motherboard of a laptop.
2. Get a raspberry pi pico-probe. You can program your raspberry pi-pico without having to mount it / power it / drag your file cycles. Also - you no longer need to unplug and plug it in all the time.
The wiring setup is just this easy.
Some example program commands to get you going with what the output looks like.
- Note send the .elf file (not the .uf2 file)
3. Make a programming script that calls openocd and programs it.
make -j 4
sudo openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 500" -c "program ./hello_world.elf verify" -c "shutdown"
If your programming is good you will see:
5. Need some random numbers here is one method to accomplish this on a pico:
#include "hardware/regs/rosc.h"
#include "hardware/regs/addressmap.h"
typedef unsigned int u16;
u16 rnd(void)
{
u16 k, random=0;
volatile u16 *rnd_reg=(u16 *)(ROSC_BASE + ROSC_RANDOMBIT_OFFSET);
for(k=0;k<32;k++)
{
random = random << 1;
random=random + (0x00000001 & (*rnd_reg));
}
return random;
}
6. Need to add object-oriented class programming?. You will need to add the following includes to your source code. After that .cpp type object-oriented programming will work automatically!
#include <cstdlib>
#include <cstring>
#include <cstdint>
7. Need to inspect your pulses? Consider a very inexpensive 24 Mhz Analyzer (they start at $14 and work)
8. Need a free pulse plotting software? Install sigrok! It is free software that works with your analyzer.
9. Keep organized - assemble the whole thing into a 'lab-in-a-box.' It makes for a clean installation:
10. Don't give up! Don't kid yourself for such small chips there is a LOT of moving parts and pieces. Consider:
- A raspberry pi pico has more processing power and speed than a 1980 XT computer by orders of magnitude!
- Some engineers spend weeks trying to learn the arm eco-system (they just don't want to admit it!)
Check out our other guides. We wrote them as simple as possible and deliberately over documented them on purpose.