Turai Botond
Created November 24, 2018

Single Line Communication

Arduins communicate through only one wire.

AdvancedFull instructions provided94
Single Line Communication

Things used in this project

Story

Read more

Schematics

Circuit

Code

Code

Arduino
Paste to Arduino editor
#define pin 2
byte data;

void setup()
{
  Serial.begin(9600);
  begin();
}
void loop()
{
  transmit(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);
}

Credits

Turai Botond
5 projects • 21 followers
Check out my youtube channel for exciting projects: www.youtube.com/@botondturai
Contact

Comments

Please log in or sign up to comment.