I'm experimenting with Serial communication with an ATtiny85 and the SoftwareSerial Library, this simple example kind of works but only after a few seconds. To begin with the ATtiny only seems to respond correctly around 50% of the time, but after a couple of seconds it functions correctly. Take this example code, which simply sends the character "a" to the Attiny, which echoes it back to the Mega, which then echos it to the PC:
#include <SoftwareSerial.h>
const int rx=2;
const int tx=3;
const int led=0;
SoftwareSerial mySerial(rx, tx);
void setup()
{
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
pinMode(led,OUTPUT);
mySerial.begin(4800);
delay(100);
}
void loop()
{
if (mySerial.available()>0)
{
digitalWrite(led, HIGH);
char c = mySerial.read();
mySerial.print(c);
}
digitalWrite(led, LOW);
}
Arduino Serial Monitor
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
¸
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
¸
±
½
ÿ
h
Ø
±
½
ÿ
h
?
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
½
ÿ
h
Ø
±
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
h
e
l
l
o
Yeah I'm selecting ATtiny85 (internal 8Mhz Clock) from the boards menu. Thanks for the link, although I would like a solution that will not involve so much calibration since I plan to use a lot of ATiny85's! (or similar)