Analogread() on attiny85 (arduino tiny core) problem

Hi buddy! I am trying programming from arduino to attiny85 via arduino as ISP using newest version of arduino tiny core. I attemped to read analog value from connected button. (Reason for this is that I connect 2 buttons via one analog pin-each button has different resistor attached to it, allowing me to know which button is pressed by reading analog value. So I have to do initial calibration) BUT! When my Attiny attemps to read the value, it showed gibberish in the serial monitor.
Thank you so much!

#include <SoftwareSerial.h>
SoftwareSerial serial(5, 4);
int value;

void setup() {
  serial.begin(9600);
  pinMode( 0, OUTPUT);
  pinMode( 5, INPUT);
  pinMode( 4, OUTPUT);
  pinMode( 3, INPUT);  
}

void loop() {
  value=analogRead(3);
  if(value>10){
    delay(100);//debounce
    digitalWrite(0, HIGH);
    serial.println(value);
    delay(1000);
    }
 else {
    digitalWrite(0, LOW);
    }
}

2018-09-09 18.45.00.png

A3

Mark

Sorry, I don't quite understand, What is A3 meaning?

holmes4:
A3

Mark

Please post a schematic and the Uno (receiver) code. Does the serial monitor baud rate match the Uno baud rate?

What is A3 meaning?

When using analogRead(), use the A# constant to refer to the pin, not the digital pin number.

From the Attiny core docs.

You might want to look at the serial support section on that page, too.

groundFungus:
Please post a schematic and the Uno (receiver) code. Does the serial monitor baud rate match the Uno baud rate?
From the Attiny core docs.

You might want to look at the serial support section on that page, too.

Thank you for helping!
I tried analogRead(A3) instead of analogRead(3), but still gibberish(pls see attachment screenshot).
And I struggled to draw the scheme, please see attachment Attiny_button_serial_com.
I was following the youtuber Video when I did this project.

Do not post screen shots you can just copy and paste the test from the serial monitor.

Mark

   digitalWrite(0, HIGH);

Stupid stupid, stupid, stupid!

leave pins 0+1 alone

Mark

holmes4:

   digitalWrite(0, HIGH);

Stupid stupid, stupid, stupid!

leave pins 0+1 alone

Mark

...

...

SoftwareSerial serial(5, 4);
...

Why?

I wonder about using the tiny85 reset pin (pin 5) as software serial RX.

Now that could be a problem. I have used the reset pin as an analog pin, but it needs to be kept above 0.4Vcc in order not to cause a reset.

That's some seriously messed up circuit diagram. Almost as bad as Fritzing's breadboard view.

Your LED misses a current limiting resistor. That's bad news for the pin it's connected to.

Also you're using two I/O pins to read two buttons. Why even bother with those resistors and analog readings? Or why is pin 2 connected at all?

HA! I just looked at the schematic (it's not called a scheme) and I can't figure out why the tiny is even in there. Why not just do all of that on the uno?

I agree that the scheme looks shabby.╮(╯▽╰)╭
I think I can simplify it later this evening and get it uploaded then.
My goal is to set up a project only using Tiny85 as microcontroller. The reason for connecting UNO is that-- I think UNO only works as a usb/serial converter. Otherwise I have no solution to conect Tiny85 directly to USB port.

ChrisTenone:
HA! I just looked at the schematic (it's not called a scheme) and I can't figure out why the tiny is even in there. Why not just do all of that on the uno?

Is the communication 2 way or do you want to just transmit from the tiny85?

I just want to transmit from the tiny85.
I updated the circuit scheme in the attachment(notice that "pullup" resistor is a mistake, it should be labelled as pulldown instead.).

The sketches below was uploaded to Attiny85 beforehand.
Then I connected as the scheme shows. Reset and GND on UNO were short by jumpwire.

#include <SoftwareSerial.h>
SoftwareSerial serial(5, 4);
int value;

void setup() {
  serial.begin(9600);
  pinMode( 0, OUTPUT);
  pinMode( 5, INPUT);
  pinMode( 4, OUTPUT);
  pinMode( 3, INPUT);  
}

void loop() {
  value=analogRead(3);
  if(value>10){
    delay(100);//debounce
    digitalWrite(0, HIGH);
    serial.println(value);
    delay(1000);
    }
 else {
    digitalWrite(0, LOW);
    }
}

groundFungus:
Is the communication 2 way or do you want to just transmit from the tiny85?

If I keep pressing button S2, on the serial monitor I can see " LC Lc 5 LC 5 C l H LC" or so.

As ChrisTenone pointed out, I changed the pins as described below to avoid using P5 and P0.
I tried setting P2 as RX, P1 as TX, P3 as button input, P4 as LED. Unfortunately the same stuff showed on monitor.

I just now tried supplying the power to ATtiny85 with 5V battery. Then nothing showed on monitor, but as indicator, the LED worked.

Problem solved——I put a 10 μF( 0.1 μF recommended but I don't have at hand) between VCC pin and GND pin. And 3.3 V is favored as VCC rather than 5 V.