I want a Digispark clone (ATtiny85) to send data to a Teensy 3.2. On the Digispark, I use the SoftSerial library. On the Teensy, I use one of the hardware serial interfaces. The problem is that the Teensy outputs:
Expected is:
This looks like a timing problem to me, especially considering the randomness. But how do I resolve it?
What I already tried is playing with the communication speed. At 9600, 4800, 2400, and 1200 baud I got the above garbage. At 300 baud there was nothing received at all.
sender.ino compiled and uploaded with Digispark (16 Mhz - No USB) selected in the Arduino IDE:
received.ino, compiled and uploaded to the Teensy 3.2:
Circuit:
(Next step is using half-duplex communication, to get rid of one wire.)
Code:
DD�D�D�D�D�D�ÔÔD�DÔÔÔÔÔD�ÔÔDD�D�D�ÔD�DÔÔ…
Expected is:
Code:
Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi!Hi!…
This looks like a timing problem to me, especially considering the randomness. But how do I resolve it?
What I already tried is playing with the communication speed. At 9600, 4800, 2400, and 1200 baud I got the above garbage. At 300 baud there was nothing received at all.
sender.ino compiled and uploaded with Digispark (16 Mhz - No USB) selected in the Arduino IDE:
Code:
#include <SoftSerial.h>
#include <TinyPinChange.h>
const uint8_t ledPin = 1;
const uint8_t rxPin = 0;
const uint8_t txPin = 2;
SoftSerial mySerial(rxPin, txPin); // RX, TX
void setup() {
mySerial.begin(4800);
mySerial.txMode();
pinMode(ledPin, OUTPUT);
}
void flashLed() {
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
}
void loop() {
mySerial.write("Hi!");
flashLed();
delay(1000);
}
received.ino, compiled and uploaded to the Teensy 3.2:
Code:
const uint8_t ledPin = 13;
void setup() {
Serial.begin(9600);
Serial1.begin(4800);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
void flashLed() {
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
}
void loop() {
char c;
if (Serial1.available()) {
c = Serial1.read();
Serial.print(c);
flashLed();
}
}
Circuit:
(Next step is using half-duplex communication, to get rid of one wire.)