How to Overclock and Underclock a Raspberry Pi Pico

Overclock any model of Raspberry Pi is really easy. But overclocking the Raspberry Pi Pico is even easier. All you need is two lines of MicroPython and your Pico can easily run at twice normal speed without the need for the The best CPU coolers.
In this guide we overclock a Raspberry Pi Pico to 270MHz, double the base speed of 133MHz. Then we write a script to test how far we can overclock and how far we can underclock the CPU.
You might be thinking, “Why overclock a Raspberry Pi Pico?” With a low-level language like C, the Pico can be used to play games like Doom (the full game) via an HDMI output card. It can emulate retro computers like the ZX Spectrum and the Commodore 64. With MicroPython, overclocking will give us a noticeable speed boost, and underclocking can give us longer battery life if we use it in a battery-powered project.
How it works with the Raspberry Pi Pico, Pico W and many others of best RP2040 based boards when using MicroPython. There are other methods of changing the frequency when programming the cards in other languages.
For this project you will need
A Raspberry Pi Pico or Pico W or other RP2040 based board running MicroPython.
Overclocking the Raspberry Pi Pico with MicroPython
1. Install the latest version of MicroPython on your pico. If you haven’t already, follow up Step three of this guide to learn how.
2. Import the machine module into the REPL And Check the current speed of the Raspberry Pi Pico. The value returned will likely be 125000000 Hertz (125 MHz). Some boards or versions of MicroPython may have it set slightly higher by default.
import machine
machine.freq()
3. Use the same command, Set the CPU speed to 270MHz.
machine.freq(270000000)
4. Check the CPU speed to make sure the overclock worked. The value returned should be 270000000 Hertz (270 MHz).
machine.freq()
For now, this speed boost is only temporary. When the Pico restarts, it will return to its default speed (typically 125MHz). In order to maintain the overclock, it must be set every time the Pico starts up. Adding these two lines at the beginning of any MicroPython code will overclock the RP2040 to the desired speed when the code is run.
import machine
machine.freq(SPEED IN HERTZ)
How far can the RP2040 be pushed?
Overclockers always want to get that little bit faster, but how do we determine our luck in the silicon lottery? To do this, we automated the process with a bit of Python code.
1. In Thonny start a new file from first import two modules. Machine is used to change CPU speed and time is used to speed up code.
import machine
import time
2. Create a variable, freq and store 270MHz as Hertz. We know 270MHz works well, so let’s assume a known operating speed. If you want to underclock the RP2040, reduce the value accordingly.
freq = 270000000
3. Create an object, Speed, and store the current speed of the RP2040 there. With a little math, the returned value in hertz is converted to megahertz, then rounded to one decimal place, and finally converted to a string.
speed = str(round(machine.freq()/1000000,1))
4. Returns the current CPU speed as part of a message. We had to convert the speed to a string to include in the message.
print("The starting speed is",speed,"MHz")
5. Print a message to the user informing them that the test will start in five seconds, and then wait five seconds.
print("Starting the test in five seconds")
time.sleep(5)
6. Create a loop to run the code continuously. We could use a for loop, but a while true loop will crash if it hits a bad frequency, so we don’t gain anything from a for loop.
while True:
7. Set the CPU speed with the freq variable.
machine.freq(freq)
8th. Create an object, Speed, and store the current speed of the RP2040 there. With a little math, the returned value in hertz is converted to megahertz, then rounded to one decimal place before finally being converted to a string.
speed = str(round(machine.freq()/1000000,1))
9. Returns the current CPU speed as part of a message. We had to convert the speed to a string to include in the message.
print("The starting speed is",speed,"MHz")
10 Increase the speed by 10MHz and store the value in freq. The += operator translates to freq = freq + 10000000. It’s shorter and clearer in code. Both work equally and can be swapped out for clarity. The += can be swapped for -= so the values count down to find the lowest CPU speed.
freq += 10000000
11. Hold the code for two seconds. This gives us time to read the values before the loop repeats.
time.sleep(2)
12. Save the code on the Raspberry Pi Pico as speedtest.py and click Run. Our best speed was 280MHz, but you may be lucky.
We also tested an underclock (reducing the speed by 10MHz on each loop) and managed to drop it down to 10MHz, which should significantly reduce power consumption for projects that require long battery life. Due to the precision equipment required, we were unable to collect any data.
Complete code list
import machine
import time
freq = 270000000
speed = str(round(machine.freq()/1000000,1))
print("The starting speed is",speed,"MHz")
print("Starting the test in five seconds")
time.sleep(5)
while True:
machine.freq(freq)
speed = str(round(machine.freq()/1000000,1))
print("The current speed is",speed,"MHz")
freq += 10000000
time.sleep(2)