Skip to content

Instantly share code, notes, and snippets.

@pharzan
Last active January 8, 2022 17:28
Show Gist options
  • Save pharzan/fc50fa3297c59ac60274465db301f755 to your computer and use it in GitHub Desktop.
Save pharzan/fc50fa3297c59ac60274465db301f755 to your computer and use it in GitHub Desktop.
ATTINY13 communication with ESP-01
/*
using software serial and GPIO 0 as recieve pin.
PIN 6 (ATTINY13) is connected and transmitting a number.
PIN 6 (ATTINY) --> GPIO ESP8266-01
When ESP-01 see's a new line the string is completed and printed to the Serial output of the arduino IDE.
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 2); // RX, TX
String inputString = ""; // a String to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(19200);
mySerial.begin(19200);
// reserve 200 bytes for the inputString:
Serial.println("ok! ");
inputString.reserve(200);
}
void loop() {
serialEvent();
// print the string when a newline arrives:
if (stringComplete) {
Serial.print("String:");
Serial.print(inputString);
Serial.print(" Integer: ");
Serial.println(inputString.toInt());
// clear the string:
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the hardware serial RX. This
routine is run between each time loop() runs, so using delay inside loop can
delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (mySerial.available()) {
// get the new byte:
char inChar = (char)mySerial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag so the main loop can
// do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment