Get all your news in one place.
100’s of premium titles.
One app.
Start reading
Tom’s Hardware
Tom’s Hardware
Technology
Les Pounder

How to Overclock and Underclock a Raspberry Pi Pico

How to Overclock and Underclock a Raspberry Pi Pico

Overclocking any model of Raspberry Pi is really simple. But overclocking the Raspberry Pi Pico is even simpler. All it takes is two lines of MicroPython and your Pico can easily run at double its normal speed, and without the need for the best CPU coolers.

In this how to we will overclock a Raspberry Pi Pico to 270 MHz, double the base speed of 133 MHz. Then we will write a script to test how far we can overclock, and then how low we can underclock the CPU.

You might be thinking “Why overclock a Raspberry Pi Pico?”Using a low level language, such as C, the Pico is capable of being used to play games such as Doom (the full game) using an HDMI output board. It can emulate retro computers such as the ZX Spectrum and Commodore 64. With MicroPython, overclocking will give us a noticeable speed boost, and underclocking may provide us with longer battery life if we’re using it in a battery-powered project.

This how to will work with the Raspberry Pi Pico, Pico W and many other of the best RP2040 based boards when using MicroPython. There are other methods for changing the frequency when programming the boards in other languages.

For This Project You Will Need

A Raspberry Pi Pico or Pico W or any other RP2040 based board that’s running MicroPython.

Overclocking the Raspberry Pi Pico With MicroPython

1.  Install the latest version of MicroPython on your Pico. If you haven’t already done this, follow up to step three of this guide to learn how.

2. In the REPL, import the machine module and check the current speed of the Raspberry Pi Pico. The returned value will probably be 125000000 Hertz (125 MHz). Some boards or versions of MicroPython may have it set a little higher by default.

import machine
machine.freq()
(Image credit: Tom's Hardware)

3. Using the same command, set the CPU speed to 270 MHz.

machine.freq(270000000)

4. Check the CPU speed to ensure that the overclock has worked. The returned value should be 270000000 Hertz (270 MHz).

machine.freq()
(Image credit: Tom's Hardware)

Right now this speed boost is temporary. When the Pico is rebooted, it will return to its default speed (usually 125 MHz). In order to retain the overclock, it must be set each time the Pico boots. Adding these two lines to the start 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 are always looking to go just that little bit faster but how can we determine our luck in the silicon lottery? For that we automated the process with a little Python code. 

1. In Thonny start a new file by first importing two modules. Machine is used to change the CPU speed, and time is used to pace the code.

import machine
import time

2. Create a variable, freq and store 270 MHz as Hertz. We know that 270 MHz works well, so we start from a known working speed. If your goal is to underclock the RP2040, reduce the value accordingly.

freq = 270000000

3. Create an object, speed, and in there store the current speed of the RP2040. Using 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))

4. Print the current CPU speed as part of a message. We needed to convert the speed to a string in order to place it in the message.

print("The starting speed is",speed,"MHz")

5. Print a message to the user, informing them that the test starts in five seconds, then wait for five seconds.

print("Starting the test in five seconds")
time.sleep(5)

6. Create a loop to continually run the code. We could use a for loop, but a while True loop will crash when it hits a bad frequency, so we gain nothing from a for loop.

while True:

7. Set the CPU speed using the freq variable.

   machine.freq(freq)

8. Create an object, speed, and in there store the current speed of the RP2040. Using 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. Print the current CPU speed as part of a message. We needed to convert the speed to a string in order to place it in the message.

   print("The starting speed is",speed,"MHz")

10. Increment the speed by 10 MHz and save the value to freq. The += operator translates to freq = freq + 10000000. It is shorter and neater in the code. Both work equally as well, and can be interchanged for clarity. The += can be swapped for -= so that the values count down to find the lowest CPU speed.

   freq += 10000000

11. Pause the code for two seconds. This will give us time to read the values before the loop repeats.

   time.sleep(2)

12. Save the code to the Raspberry Pi Pico as speedtest.py and click run. Our best speed was 280 MHz, but you may get lucky.

(Image credit: Tom's Hardware)

We also tested an underclock (reducing the speed by 10 MHz each loop) and managed to get it down to 10 MHz, which should significantly reduce the amount of power draw for projects that require a long battery life. We were unable to capture any data due to the level of precision equipment required.

Complete Code Listing

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)
Sign up to read this article
Read news from 100’s of titles, curated specifically for you.
Already a member? Sign in here
Related Stories
Top stories on inkl right now
One subscription that gives you access to news from hundreds of sites
Already a member? Sign in here
Our Picks
Fourteen days free
Download the app
One app. One membership.
100+ trusted global sources.