I am wondering whether any model of the Raspberry Pi can reliably output an 8-bit 20mhz signal into 8 GPIO pins at the same time. Basically I am trying to read 8-bits from a file at a time out to 8 pins of a raspberry pi, at 20mhz (my purpose is to feed those 8 bits into a current-output DAC).

I am not sure which model of Raspberry Pi would be best for this. I'd also love to know if there are some C/C++ code examples that do this already.

Any insight or advice on this would be greatly appreciated — thanks!


3 Answers 3



The benchmarks you see showing impressive Pi GPIO speeds in the multi megahertz region are for simply toggling a single pin. I.e. a loop writing 0 then 1. Once you add logic in that loop the speed drops. Once you try to time the loop the speed will drop by several orders of magnitude.

I suggest you do your own experiments reading from a file and writing to GPIO.

If you don't mind timing jitter you might reach something like 20 thousand Hz in Python (not the 20 million Hz you want).


Here's an answer of sorts:

According to hzeller's GitHub repo, GPIO switching speeds of up to 131 MHz were measured on an RPi4. Based on data provided in that post, your 25 MHz requirement could be met by a Raspberry Pi 2.

It should be noted that these speeds were achieved using C code and DMA techniques. I have not tried this myself; the repo is a bit long in the tooth now, and I do not know if these sources still compile/run on more modern systems, and esp under more modern kernels. IOW, actually achieving the same speeds as under hzeller's testing may require a fair amount of work.

I would also suggest that you strongly consider using a hardware platform other than the Raspberry Pi for your laser project. The RPi, its hardware and software, were not designed to provide 25MHz outputs suitable for controlling a laser. Consider an FPGA or a special-purpose microcontroller.

  • FPGAs were recommended to me as well. I am trying to set up a system that will stream data to the laser in 8-bit bursts, at 10-20mhz. For 10mhz, that would mean that every 10 millionth of a second, the laser is at a specific brightness level defined by that particular byte. I don't know how to articulate that in the "correct" terminology, but that's my goal. A DAC was suggested as a means of achieving this, since what i'm trying to do is analogous to what a DAC does. What rate of data stream would a pi be capable of? Let's pretend I don't have a target frequency. Commented Apr 25 at 4:57

I seriously doubt that you could output data at that speed; the fastest code I have used can (just) exceed 20Mbps on a Pi4 (just toggling a pin). (Outputting multiple bits with custom code is just as fast or faster than most single bit writes.)

Maybe with DMA BUT you couldn't even read data from a file at that speed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.