Friday, May 16, 2025

Overclocking the Raspberry Pi Pico in MicroPython

For an index to all my stories click this text

This story is about overclocking (and underclocking) the Raspberry Pi Pico with MicroPython.

Sometimes you just want your program to run faster. Well you can gain speed by using C++ (Arduino language) in stead of MicroPython. But not everybody wants that as MicroPython is far easier to learn and use.

MicroPython runs on the ESP8266, ESP32 and of course on the Raspberry Pi Pico. And if you use the Picom or Pico W,  you are in luck: the Pico can be overclocked !!! And without altering anything or adding extra hardware !! The internal clock can be software wise altered !!

Overclocking

Overclocking means that you can alter the speed on which your microcontroller (or computer) works.

The documentation of the Raspberry Pi pico says that it runs normally on 133Mhz but the speed can be increased to 400Mhz.

There are two things to consider:
- The onboard SPI flash memory may give trouble when working above 260Mhz
- Overclocking might shorten the lifespan of the Pico

For most projects the Pico just runs fine. But there might be some time critical programs in which you could need a bit more speed. The lifespan shortening sounds troublesome, but until now I have not heard or read on the internet anyone who had a Pico giving up due to overclocking. Just be warned.

Overclocking in MicroPython

Overclocking is standard facilitated in MicroPython. You do not need to download extra libraries. You just need the machine library which is standard included in MicroPython.

So let's first start by examining the standard frequency. We just need two commands for that which you can put in Thonny's shell.

import machine
machine.freq()




And there it is. Standard sets MicroPython the clock-frequency to 125.000.000 which is 125Mhz. That is a bit lower as the 133Mhz the Raspberry documentation states.

Test program

Let's buid a small test program so we can see if overclocking has any effect at all.

import time

start = time.ticks_ms()
print("Micropython tips")
for x in range(1000000):
   x=x
end = time.ticks_ms()
print(end - start)

The program does nothing special. It puts the start time into a variable, then puts 1 million times the value of variable x into itself and then stores the end time. Lastly startime is subtracted from endtime and then we know how long it took.



And here is the result. our small program took about 8 and a half second to finish.

Now let us increase the clockspeed.



The command to alter the clock frequency is machine.freq(x) in which x is the frequency you need. I set the speed at 260000000 which is 260Mhz. Then I ran the program again.



And what an increase in speed !!! The program now just took 4 seconds.



The highest speed I could get was 285000000 Hz which is 285Mhz. Any higher speeds would block the communication between Thonny and the Pico. Like stated before, increasing the speed might affect your interfaces with I2C, SPI and UART. And here it shows that above 285 Mhz it definitely affects the UART communication.



At 285Mhz the program just needed a bit less than 4 seconds.

You could test if anything beyond 285Mhz might work as no Pico's is created 100% equal and you might get lucky.

I recommend not to go over 260Mhz.

Lowering the speed.

Next to increasing the speed you can also decrease the speed. Lowering the speed at which a program runs might prove usefull in debugging.



The lowest I could go was 20000000 Hz which is 20Mhz. Any lower and I lost contact with Thonny.



At 20Mhz the program took almost 53 seconds to finish.

Please test thorough !!!

Increasing the speed to the max or decreasing the speed to the minimum might influence communications with sensors and actuators working with I2C or SPI. It also may influece communication over the UART ports.

So if you need to permanently increase the speed for one of your projects please test thorough before putting it in a real life situation.

Till next time
Have fun


Luc Volders