What you need?
- minumum 2 Arduinos
- Jumper wires
The code is so short that I did not make a library. Interruption ensures that messages are read. Reading does not work while sending. I will continue to develop, this is just a demo. The bits are sent every 50 microseconds. In front of it, a bit of signal prepares for the reading of the arduino. The data can be read from the variable "data". And messaging is possible as follows.
transmit(val); //val is a byte-type variable
The default communication pin is pin 2 because most Arduino board pin 2 supports interruption.
It is important that the ground is connected to the Aruinos.
Circuit
Arduino 1 Arduino 2
pin 2------------pin 2
GND------------GND
If you are interested in more interesting projects, then follow me and see my previous projects.
#define pin 2
byte data;
void setup()
{
Serial.begin(9600);
begin(); //prep. the comm.
}
void loop()
{
transmit(42); //send number 42
delay(500);
}
/*
############################
# ##### # ##### #
# ## # # #
# #### # # #
# ## # # #
# ##### ##### ##### #
############################
by Turai Botond
*/
void begin()
{
pinMode(pin, INPUT);
attachInterrupt(digitalPinToInterrupt(pin), _inmsg, RISING);
}
void _inmsg()
{
detachInterrupt(digitalPinToInterrupt(pin));
if (digitalRead(pin) == 1)
{
while (digitalRead(pin) == 1)
{}
delayMicroseconds(75);
for (int i = 0; i < 8; i++)
{
bitWrite(data, i, digitalRead(pin));
delayMicroseconds(50);
}
}
attachInterrupt(digitalPinToInterrupt(pin), _inmsg, RISING);
}
void transmit(byte dat)
{
detachInterrupt(digitalPinToInterrupt(pin));
pinMode(pin, OUTPUT);
digitalWrite(pin, 1);
delayMicroseconds(50);
digitalWrite(pin, 0);
delayMicroseconds(50);
for (int i = 0; i < 8; i++)
{
digitalWrite(pin, bitRead(dat, i));
delayMicroseconds(50);
}
delayMicroseconds(200);
pinMode(pin, INPUT);
attachInterrupt(digitalPinToInterrupt(pin), _inmsg, RISING);
}
Have fun :)
Comments
Please log in or sign up to comment.