Hey, just a few quick questions,
- Can the ATtiny85 or 84 receive Serial input?
- If so, how?
I have tried both chips, Tx works fine, Rx never does.
I have tried both regular serial and softwareserial.
Thanks
Hey, just a few quick questions,
I have tried both chips, Tx works fine, Rx never does.
I have tried both regular serial and softwareserial.
Thanks
SoftwareSerial should be possible. But you probably need a tiny-specific version of the library, which may or may not be present or enabled in your particular implementation of "tiny." (which one are you using?)
For example Google Code Archive - Long-term storage for Google Code Project Hosting. defaults to using "tinydebugserial", which is tx only.
That's the one I'm using, arduino tiny. Any other ideas?
Also, why is receiving so hard? Does it have to do with clock speed? For example, would it work running at 20mHz?
SoftwareSerial sort of does work. Clock speed and baud rates will affect the reliability a lot. If you are just receiving one character at a time then it seems to work. But for multiple characters it seems some baud rates work better than others depending on the clock speed. Interestingly I tested a t85 with 16MHz external crystal and it worked best at 115200 baud. Slower baud rates caused more garbage received.
The SoftwareSerial receive is supposed to be based on a 64 byte buffer and interrupt driven, using Pin Change interrupts. So there can be some factors that affect the reliability if it misses any interrupts.
To receive without a hardware uart (which the 84/85 lack), you have to either continuously watch the rx pin for data to be received, or use "pin change interrupts" (SoftwareSerial does this.) I don't see anything in the SoftwareSerial library that would cause it to fail on a Tiny, but the PCINT stuff is pretty chip-specific.
(Definitely focus your attempts on SoftwareSerial, though.)
So here's this code from here:
#include <ctype.h>
#define bit9600Delay 84
#define halfBit9600Delay 42
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6;
byte tx = 7;
byte SWval;
void setup() {
Serial.begin(9600);
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
digitalWrite(13,HIGH); //turn on debugging LED
SWprint('h'); //debugging hello
SWprint('i');
SWprint(10); //carriage return
}
void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit9600Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit9600Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit9600Delay);
}
int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}
void loop()
{
SWval = SWread();
SWprint(toupper(SWval));
}
I can't get it to work on any board, I'd imagine this is because it's outdated.
If I can get it to work, I can have the receiver listen and synchronize with the transmitter.
Does this code have any special requirements? Like, mHz or different baud delays?
Thanks much
When you said "SoftwareSerial didn't work", were you talking compile failures or runtime failures? And about the standard SoftwareSerial Library, or something else you had downloaded? If I try to compile the "SoftwareSerialExample" for ATtiny84, using 1.6.4 and the arduino-tiny distribution, I get errors because it can't find the SoftwareSerial library at all (it's off in the "arduino platform", and the "tiny platform" doesn't have a libraries directory at all.) I made a symbolic link from sketchbook/hardware/tiny/avr/libraries to the arduino dir, and it DOES compile after that (but I have no actual tiny84 to try it on.)
Runtime failures. I also had to add SoftwareSerial to my Tiny libraries. It loaded up just fine, but when actually running, it only sent.
That SoftwareSerial tutorial example of how it works has the timing a bit off.
Try these settings (for an UNO R3 at 9600 baud):
#define bit9600Delay 97
#define halfBit9600Delay 44
I tested SoftwareSerial on an attiny84 @1MHz internal at 9600 baud. Using the dmellis attiny core with IDE 1.6.4. It worked flawlessly without any issues!
Strange when I tried the t84 @8MHz internal at 9600 baud, it didn't work properly. It was dropping bits and characters when Receiving.
When I tested SoftwareSerial on an attiny84 @1MHz internal at 9600 baud. Using the codingbadly tiny core. It was not consistent and dropping bits at certain times.
Ok, good news, I got SoftwareSerial working on the 84 at 1mHz, like hiduino suggested, but it is dropping characters. How reliable are the dmellis cores?
Actually, just tried the dmellis cores at 1mHz, and it's dropping more characters than arduino tiny. Guess that's gonna be the one. Thanks for your help, everyone!