ATTiny85 garbled output on Serial Monitor

I have hooked up my Sparkfun AVR programmer with a ATTiny85, connected a LCD display and a USB-TTL cable to my PC. I’m trying to debug a problem with my LCD but the monitor shows just reversed question marks. Both the tiny85 and monitor are set at 9600 bauds. Do I have to tune the tiny oscillator to make it work?

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <SoftwareSerial.h>

const int LCD_COLS = 16;
const int LCD_ROWS = 2;
const int Rx = 3;
const int Tx = 4;

hd44780_I2Cexp LCD;
SoftwareSerial SSerial(Rx, Tx);

void setup()
{
  pinMode(Rx, INPUT);
  pinMode(Tx, OUTPUT);
  SSerial.begin(9600);

  Wire.begin();
  SSerial.println("LCD.init starts");
  LCD.init();

  SSerial.println("LCD.begin starts");
  LCD.begin(LCD_COLS, LCD_ROWS);

  SSerial.println("LCD 3 blinks");
  for (int i = 0; i < 3; i++) // --- 3 blinks of backlight  ---
  {
    LCD.backlight();
    delay(250);
    LCD.noBacklight();
    delay(250);
  }
  LCD.backlight();
}
void loop()
{
  SSerial.println("0123456789 ");
  delay(500);
}

Which core are you using for the Tiny85? Which pins for the LCD?

@OP

Please, provide a link to the Tiny AVR Programmer that you are using for the ATtiny85.

I wired up the circuit as shown below and modified your code to add a couple of LCD prints. I loaded the code to a Tiny85 bootloaded to run at 8MHz on the internal oscillator. I use the ATTinyCore core (available here). and the avr as isp sketch loaded to and Uno with my homemade programmer.

I realize that my setup is different than yours, but the code functions as expected with no glitching of the LCD nor garbled Serial output. So it is not the code that is at fault.

#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#include <SoftwareSerial.h>

const int LCD_COLS = 16;
const int LCD_ROWS = 2;
const int Rx = 3;
const int Tx = 4;

hd44780_I2Cexp LCD;
SoftwareSerial SSerial(Rx, Tx);

void setup()
{
  pinMode(Rx, INPUT);
  pinMode(Tx, OUTPUT);
  SSerial.begin(9600);

  Wire.begin();
  SSerial.println("LCD.init starts");
  //LCD.init();

  SSerial.println("LCD.begin starts");
  LCD.begin(LCD_COLS, LCD_ROWS);

  SSerial.println("LCD 3 blinks");
  LCD.print("LCD 3 blinks");
  for (int i = 0; i < 3; i++) // --- 3 blinks of backlight  ---
  {
    LCD.backlight();
    delay(250);
    LCD.noBacklight();
    delay(250);
  }
  LCD.backlight();
}
void loop()
{
  SSerial.print("0123456789   millis = ");
  SSerial.println(millis());
  
  LCD.setCursor(0,0);
  LCD.print("millis =        ");
  LCD.setCursor(9,0);
  LCD.print(millis());

  delay(500);
}

TINY_LCD_SS.jpg

GroundFungus

I'm using ATTinyCore, SCL > pin 7 & SDA > pin 5.
I've wired it the same way as you have but for the 10k resistor and the 0.01uF capacitor. Is that the reason?

GolamMostafa

Here's the link: Tiny AVR Programmer Hookup Guide - learn.sparkfun.com

The 10K resistor should be there. The processor may run without it but can be unstable. The resistor pulls the reset input HIGH. The 0.01 cap should be 0.1uf (typo on my part) and should go from 5V to ground as close to the processor as possible.

I just tested the circuit without the 10K resistor and the cap and the circuit still works fine (although I would not leave it like that).

I have never used the programmer that you have so really can't offer any advice on that.

@groundFungus

A little bit confusion on the schematic of your Post#3. Should not the active level of the RST pin of ATtiny85 be LOW? If so, then the signal name RST should be changed to RST/ (/ means var at the top = active Low).

GolamMostafa

I tried with grounding the RST and then I got " avrdude: Device signature = 0x000000" so that was no good..

Tying reset to ground holds the processor in reset. When the processor is held in reset it is virtually dead, it cannot do anything. Pulse reset low then high and the processor is reset to its default initial state and is ready to run your code. The reset pin is normally held high (with a pullup resistor) for normal operation.

groundFungus

I tried your config. I moved the Tiny to a breadboard and connected everything with the resistor and capacitorand I got " avrdude: Device signature = 0x000000". I checked everything over and over but the same result. I suppose I've made a wiring mistake after all but I can't see it now. I'll go over it again in the morning.

groundFungus:
The 10K resistor should be there. The processor may run without it but can be unstable. The resistor pulls the reset input HIGH. The 0.01 cap should be 0.1uf (typo on my part) and should go from 5V to ground as close to the processor as possible.

I just tested the circuit without the 10K resistor and the cap and the circuit still works fine (although I would not leave it like that).

I have never used the programmer that you have so really can't offer any advice on that.

goundFungus

According to VR042 no resistor or capacitor is really needed unless there is a noisy environment.

"The reset line has an internal pull-up resistor. If the environment is noisy, it can be insufficient and reset
may occur sporadically."

"To protect the RESET line from further noise, connect a capacitor from the RESET pin to ground. This is
not directly required since the AVR internally have a low-pass filter to eliminate spikes and noise that
could cause reset."

So, the garbled output in the Serial Monitor is probably not caused by the absence of the resistor but what is it? Do I have to tune the internal oscillator ?


I did some more testing. Garbled output on 9600 baud. I changed to 19200, 4800, 2400 and for every change the output became more and more like readable characters. Finally, at 1200 baud everything came out perfectly. I DID set my SSerial.begin to 9600 what is this all about?????