Digital data read using GPIOs

I have a circuit board which generates 32 parallel bits, the fastest the bits will change is 5 us. I would like to read these 32 bits using GPIOs on ARDUINO.

Is it possible to read these bits every 5 us at the quickest?


Yes. Do you have an Arduino with 32 I/O pins available?

Where will you put the data, at 800,000 bytes/second?

Yes, Arduino Mega 2560 has 54 digital I/Os. I want to send the data to a PC using USB.

Sorry, I am not well verse with Arduino. Is it possible to send data using USB 2.0 from an Arduino to PC?

You will need a clock pulse as well, otherwise the Arduino won't be able to detect when two identical 32-bit words are sent.
I think the Mega's USB has the same limitation as the Nano/UNO. They can only transfer serially at speeds up to on-the-order of 100kbits/sec. That will be the bottleneck which will prevent this working on a Mega.


whatever the hardware , 32 bits at 5uS/ read -> 6.4Mbits/s ignoring signalling overhead.

Can't be done over standard 2MB/s USB


You can transfer consecutive buffers of 512 bytes (or more) via the DUE native USB port using SerialUSB.write.

The speed of the native USB port depends of many factors, including the PC side, although the maximum speed is around 849 KB/s.

Welcome to the forum.

What is the device sending the parallel data to the Arduino that you want to capture?

Thanks… Tom… :slight_smile:

Hi Tom,


Basically I have designed a circuit board to detect current pulses, and generate information such as the time of event (16 bits from counters), pulse width (4 bits from a counter) and energy of pulse (12 bits from an ADC). The fastest rate of pulse event is every 5 us, so new 32 bits will be available every 5 us.

I want to use Arduino Mega 2560, to read these 32 bits using GPIOS, there will be a trigger indicating a new set of 32 bits are available.

My questions:

  1. Is it possible to read these 32 bits every 5 us and then keep storing it on flash?
  2. Based on the flash storage space, transfer these bits to a PC using USB?



Tom.. :slight_smile:

16 MHz Arduino - 16 clock ticks per us, 80 clock ticks - 80 instructions - in 5 us. Run it at 20 MHz and you get 100 instructions to play with.

That's an awfully small number of instructions in which to read 32 pins (even if you have selected the pins properly so you can directly read four complete PIN registers), write it out over SPI to MicroSD, and wait for the next incoming clock pulse telling the next 32-bit word is available.

I don't know of a faster microprocessor that could do this easily. The 160 MHz Teensy has only 21 IO pins, the 240 MHz ESP32 has 34 but not all digital IO and you're still short of pins getting your data out.

So anyway, as #4 already pointed out, we may have an XY problem here.

What is is that you really try to accomplish here? Aren't there better ways to do this?

For starters, why this time signal? That's half your signal already. The Arduino also has built in timers, you can simply record the TCNT1 register and you have actual clock pulse, should be accurate enough (way more precise than 5 us as you have 80 clock pulses per us) - in post processing you can calculate back to actual time. This assuming you don't need wall clock time, just time between events. That brings down your data width to 16 bit plus clock = 17 bit, which is something a Teensy can easily handle. The Teensy then even has four pins left for SPI to write it to a MicroSD card.

Too bad that you are stuck with a 2560, because a DUE can do that job easily:

Receive 32 bits on two PIO (e.g. 16 on PIOA and 16 on PIOC), then every 5 us, read and log the status of these 32 pins (thru PIOA->PIO_PDSR and PIOC->PIO_PDSR) in RAM, then every 128 32_bit samples logged in RAM, send them to a PC via a SerialUSB.write.

5 us equal to 420 clock cycles, much more than necessary to log two 32_bit samples.

Thanks for your replies.
Hi Tom,

I can't use a logic analyzer as I want to build this as one system, initial arduino use is just to test functionality.

Hi ard_newbie,

What's DUE?

Hi wvmarle,

Thanks for your suggestion. I will check the feasibility of using Arduino Counters.


I can’t use a logic analyzer as I want to build this as one system, initial arduino use is just to test functionality.

No, It sounds like you are building a Logic Analyser.

Tom… :slight_smile: