Tuning ATTiny85 and ATTiny44A Internal Oscillator

Hello Everyone,

After weeks of frustration trying to get Serial Communication (I am getting a bunch of Garbage printed to the Serial Monitor) working with ATTiny85 and ATTiny44A I am feeling pretty Bummed :confused: I am at a lost trying to follow the instructions in the following link:

http://arduino.cc/forum/index.php/topic,8553.0.html

Can someone please make a step-by-step Documentation for Tuning the ATTiny45/ATTiny44A Internal Oscillator for a Derp like myself so I can stop pulling out my hair and finally (hopefully) get the Serial Communication working on the Tiny's.

Sincerly,
The Last few Strands of Hair on my Head.

I’ve never done the tiny tuning bit - but might I suggest the Tiny841/441? (See link in sig for core)

It’s pin-compatible with the 84 (or 44), but it’s got TWO hardware serials (all you get on the 84/44/85/etc is software serial, which can’t send and receive at the same time), and the internal oscillator is factory calibrated well enough that the serial works without tuning. Sadly, it’s available in the surface mount packages only, no DIP.

Are you able to upload a simple blink sketch to the ATtiny85 processor?

What did you use for a programmer?

This may help...
http://www.ernstc.dk/arduino/tinycom.html

Thank You DrAzzy! I will give that a shot.

Coding Badly…I am able to upload simple sketches to the ATTiny85 and 44A, such as Blinky etc…but when I upload a Sketch for Serial Communication using buolt in SoftwareSerial library that comes with the Arduino IDE, I am able to successfully able to upload the Sketch but only get Garbage printed when I open Serial Monitor.

[Serial Communication Sketch Example]

#include <SoftwareSerial.h>
int tx =3;
SoftwareSerial.mySerial(tx);
void setup(){
pinMode(tx, OUTPUT);
mySerial.begin(9600);
}
void loop(){
if (mySerial.available >0){
mySerial.println(“Hello”);
}
}

That code doesn’t even compile.

#include <SoftwareSerial.h>

int tx =3;
SoftwareSerial.mySerial(tx);

void setup(){
 pinMode(tx, OUTPUT);
 mySerial.begin(9600);
}

void loop(){
 if (mySerial.available >0){
 mySerial.println("Hello");
 }
}

babsndeep:

void loop(){

if (mySerial.available >0){
mySerial.println("Hello");
}
}

This is software serial.

That will not work (aside from whatever's keeping it from compiling, I don't see the error, but I just woke up, my brain is still sleeping) unless you receive a single character at a time (also, you never read from serial, so a single character will make it spew "hello" for eternity). Software serial cannot send and receive at the same time - if you get two characters sent, it'll start sending back Hello - and then the second character will start coming, and the whole thing will go to hell.

While I was trying to figure out why software serial wouldn't work on the tiny's in my core the other day (it works fine if you don't try to send and receive at once, of course,), I did something very similar (I think like void loop() {if (Serial.available > 0) {Serial.print(Serial.read());}} ), which doesn't work if you send multople characters to it - and it took me until the next evening to realize that I was sending while receiving, and that's why it spewed gibberish (behaved the same way with the normal SoftwareSerial library, as well as the builtin software serial in my ATTiny core, which is a somewhat different implementation)

Thanks for catching that jboyton.
I don't have the exact code that I was able to upload to the ATTiny85 and get it to send data to Serial Monitor (it wasn't printing anything readable, just a bunch of gibberish)

Thanks Again for the Input DeAzzy...I am leaning more towards the ATTiny841/441.

Maybe I should clarify what I am trying to do, perhaps that will help narrow down things to the right MCU.
I am basically trying to attach a sensor(Moisture sensor for example) to the MCU and have the MCU transmit that data to a Bluetooth module, via tx on MCU, and receive data from the BT module via rx on the MCU, so two way communication is needed, and since ATTiny841 seems to have tx and rx I think it will be a viable choice, I have the setup working with ArduinoMini but wanted something smaller and cheaper for the MCU instead of the ArduinoMini leading to try my luck with the Tiny's.

Please feel free to suggest a better alternative, I will need no more than 4-5 I/O pins (not counting rx,tx)

void setup(){
 pinMode(tx, OUTPUT);
 mySerial.begin(9600);
}

Per the instructions, after tuning, you will have an optimal OSCCAL value for that processor. You, and only you, are responsible for actually using that value. If you do not use that value, nothing has changed; the processor is still running with the value it was given at the factory.

In other words, your code has to be something like this…

void setup()
{
  OSCCAL = 0x31;  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

  // pinMode(tx, OUTPUT);  // NOTE: This is not necessary.  Remove it.
  mySerial.begin(9600);
}

As DrAzzy pointed out you can’t send/receive simultaneously with SoftwareSerial. Unless you can guarantee some time separation between transmitted and received data you’re far better off with a processor that has a UART, like the 841. As a bonus the 841’s internal oscillator calibration mechanism is superior and even includes temperature compensation. I’m not sure what the disadvantage is with the 841 vs the 84 or 85. Cost maybe? It can’t be much. DIP package?

If you can send/receive non-simultaneously you might still have to tune OSCCAL. I tested SoftwareSerial and at 9600 baud the clock had to be within 5% of 8MHz for it to work. For most of the AVR chips Atmel only guarantees ±10% out of the box. You can find details on ways to tune OSCCAL on the web. Atmel also has an app note on the subject.