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!
![10 Tips For Raspberry Pi-Pico Coding](/content/images/size/w2000/2024/05/rect1159.png)
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.
![](https://www.hotconfig.com/content/images/2024/05/image-70.png)
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.
![](https://www.hotconfig.com/content/images/2024/05/rect3012-1.png)
![](https://www.hotconfig.com/content/images/2024/05/image-71.png)
The wiring setup is just this easy.
![](https://www.hotconfig.com/content/images/2024/05/rect4627.png)
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"
![](https://www.hotconfig.com/content/images/2024/05/image-72.png)
If your programming is good you will see:
![](https://www.hotconfig.com/content/images/2024/05/image-73.png)
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)
![](https://www.hotconfig.com/content/images/2024/05/image-74.png)
8. Need a free pulse plotting software? Install sigrok! It is free software that works with your analyzer.
![](https://www.sigrok.org/wimg/5/55/Sigrok_stone.png)
9. Keep organized - assemble the whole thing into a 'lab-in-a-box.' It makes for a clean installation:
![](https://www.hotconfig.com/content/images/2024/05/rect568d4.png)
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.
![](https://www.hotconfig.com/content/images/2023/07/rect24257-6.png)