Can you read the state of a pin with in microseconds?

Hey,

For my project I need my Arduino mega to read the state of one of its pins every microsecond (or as low as it can). anyone have any ideas or links to further information on this topic?

thanks

Reading an I/O pin every microsecond may be possible, but there is not much use reading a pin and ignoring the data. I suspect it will be difficult to do anything useful with the data and still be able to read an I/O pin every microsecond on a 16 MHz Arduino.

However this is a typical XY Problem. You need to explain what you are trying to achieve.

...R

I am attempting to set up a wired network between two different boards. The plan was they would be sending data over 1 wire each way to each other at a fixed rate, for example 1 bit every microsecond. Not that it has to be a microsecond, but the smaller the interval the quicker the data is sent. A better question would be what is the smallest interval I could set it to?

Why the speed requirement? Using one of the mega's serial ports at e.g 115200 can send/receive 10 bytes per millisecond. I2C and SPI can go faster.

But you still need to do something with that data and that might take more time than the receiving.

I'm not trying to send data back to my computer, I'm trying to send data from one Arduino mega
to a second Arduino mega with the GPIO pins. A pin on board A will go HIGH to send a "1" and go LOW to send a "0". I need board A to send data at the same speed that board B will read the data. The speed requirement is so the one board doesn't send or read data quicker then the other, for example if board B (the receiver) was reading twice as fast as board A was sending the data, instead of getting lets say a two, which is "10" in binary, board B would read it as 1100 since it's reading twice as fast. So if I put a fixed speed on both of them I don't think this is be a problem anymore.

That's literally the whole purpose of the serial port. It isn't made only to send info the the serial monitor on your PC

If board A is toggling the line once a microsecond, unless you have a second clock line, board B is going to have to sample the line much faster than once a microsecond.

Someone mentioned an XY problem . . .

loadingo:
I'm trying to send data from one Arduino mega to a second Arduino mega with the GPIO pins.

Just use one of the spare HardwareSerial ports on each Mega. They will work very happily at 500,000 baud and I believe they will work at 1,000,000 baud.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

loadingo:
I'm not trying to send data back to my computer, I'm trying to send data from one Arduino mega

Your megas have 3 serial ports extra; and I was talking about using them to communicate between megas, not to a PC.