I was wondering if Arduino digital pin can receive binary data. For example, I might want one Arduino to send another Arduino a binary code. If the code is 01
it would turn a red led on, if it was 11
it would turn green on, etc. I would like to do this so that I don't have to use a lot of digital pins. Is this possible with Arduino or not?
2 Answers
Pretty much anything is possible.
There is a method known as bit banging which toggles a generic IO pin to create a protocol, and read changes on another generic IO pin to read in the data of a protocol.
The trick is in creating a protocol.
Fortunately that has all been done for you - the SoftwareSerial library. It will create a bit banged version of the RS232 serial protocol using any combination of IO pins to transfer data between devices.
As Majenko says, it is easily possible to implement using bit banging. Assuming that you want to write your own protocol, you need to distinguish between the end of one data packet and the start of another. This could be done by having all of the packets the same length (as in your example with length 2) or using a form of Huffman coding where only the external nodes of the state tree are results so you know when a full packet has been received.
Using a standard serial or I2C protocol would also work. With serial you would be able to communicate via a serial emulator on a USB port so you could test with a computer.