How can I read a byte from a digital pin 2

Evening,

I'm working on a university project which is sending data using LASER as our medium. The description of the project is that we have 2 arduino's one for sending and other for receiving, we are sending 8 bit array and have tested and used oscilloscope to make sure our signal is sent and received correctly. We are receiving the bits by using a mechanism of interrupts: start interrupt to detect the start bit which is a falling edge in our case, and a counter that interrupts the first time after 150ms and then interrupts at every 100ms to read the bits (we are sending the bits at 100ms), the idea from this is creating something similar to UART protocol.
So far our signal is being sent and received just fine, our start interrupt is being initiated and 8 interrupts from the counter are also happening this happens ofcourse when we send our array from the sender LASER.
Our problem is that we are not able to read the bits sent correctly.

volatile uint8_t a[8];

if( i < 8 ){
a = digitalRead(DATA);

  • i++;*
  • Serial.print("Interrupt executed \n");*
    _ Serial.print(a );_
    This is the chunk of code we are using to read the signal but we are not getting the right output.
    The output we get is 00000008 for some reason we are sending 00110010. We are still trying to use different techniques to read the bits but we are kinda of beginners.
    Any help, suggestions or tips are very much appreciated. Thank you.

Please post a complete program rather than a snippet, but read this first and follow the advice given about posting code
read this before posting a programming question

Any help, suggestions or tips are very much appreciated. Thank you.

Post your code.

Use code tags this time

Use CTRL T to format your code.

Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.

[code]Paste your sketch here[/code]

Maybe just use serial to modulate the laser beam then the encoding/decoding is done for you. Here is something similar but with IR. (horrible video but you get the idea) Arduino Serial Communication Over Infrared (with no TSOP) - YouTube

volatile uint8_t a[8];

The above is an array of 8 unsigned 8-bit values...

  if(  i < 8 ){
  a = digitalRead(DATA);

Which of the 8 unsigned bytes that comprise array a do you believe the above code is actually writing to?

Have you read any articles or tutorials about how to use arrays in c?

Regards,
Ray L.

@RayL - you may have noticed the presence of italics . . .

How is the interrupt set to trigger. It looks like your interrupt is set for rising edge?

I think you may want consider including a start character and a stop character.

6v6gt:
Maybe just use serial to modulate the laser beam then the encoding/decoding is done for you.

That's the way I'd go. Use a board with an extra hardware Serial port (aka a real UART).

AWOL:
@RayL - you may have noticed the presence of italics . . .

I always forget that....

Regards,
Ray L.