ATTiny85 Issue

I am trying to set up a TMP36 with my ATTiny85 that I am programmer through my Arduino Uno. I can successfully program the ATTiny85 and make an LED light up and all of that good stuff. I am trying to pass the analog input directly to another pin just to make sure that the ATTiny is reading the input from the TMP36 sensor..

The code for the ATTiny85 is basically this:

loop{

analogWrite(3, analogRead(4));
}

I am reading .5 volts coming in to pin 4 on my volt meter but .07volts coming out on pin 3.

I know I have it hooked up to the right pins because I tested each pin individually by lighting up an LED...

Anyone have any ideas as to why I can't read the analog value right from the TMP36?

Thanks

analogWrite() outputs PWM, and accepts an argument as an integer from 0 to 255. You cannot measure PWM duty cycle with a multimeter.

analogRead() reads the analog voltage on a pin, returning a value from 0 to 1023.

You can analogRead on A1, A2, or A3 (physical pins 7, 3 and 2, respectively.)
(Physical pin 1 is "available" as A0, but...)
analogRead returns a 10bit value
analogWrite is an 8bit value
I think that you may have to analogRead into a variable and then map that to an 8bit value.

Thanks for the fast responses and information! drAzzy what you are saying makes sense, and pancake I guess I could try mapping it if ATtiny has that functionality.

Does the ATtiny and arduino uno analog read functions have the same bounds? I get the correct temperature on the arduino with the TMP36 and am able to light an LED when the temperature is between 60-75 degrees. If I take the same code to the ATtiny the light doesn't work and most of the time the temperature is 0. Any ideas? The code is just applying math to the analog input and checking the temperature with an if statement

Oh! Yeah, that.

You're using the wrong pin analogRead() - they don't map to physical pins the way any sane person would expect.

Google ATTiny85 Pinout (note some of these images erroneously indicate that physical pin 3 (mapped to god knows what arduino pin number) is not capable of PWM; it is).

Failing that, generally make sure the pins are mapped how you think they are. Dig up arduino_wiring.c from the tiny cores you're using - these typically have ascii art showing the pinout. There are, unfortunately, several versions of many of the tiny cores people are using, and there are a few schools of thought for how to map the pins.

You're looking for the images that have the analog channel listed, or the one from the datasheet, which lists ADC followed by a number next to the analog pins. Use the number from either of those sources, not the arduino pin number or the physical pin number.

I am using analogRead(4); which is the third pin from the reset which should be correct? Using the image below it is physical pin 3.

And I am powering the TMP36 from the 5V arduino out in both cases..

image.jpg

stjohnr:
I am using analogRead(4); which is the third pin from the reset which should be correct? Using the image below it is physical pin 3.

If you look closely at that diagram you will see that physical pin 3 has been labelled (Analog Input 2) - so it is A2.

A2 isn't defined apparently. I kind of rememeber hearing that this is fixed on the 1.5version of the arduino IDE which I don't have. I guess I will try and download it and see if that does the job! Thanks for all the help it is greatly appreciated !

stjohnr:
A2 isn't defined apparently.

Explain.

I accidentally had A0 instead of A2 which is why it wasn't working. Everything seems to be working now because I am getting a temperature (lower than its supposed to be but that is probably just on the math side!). Thanks again for the help!

Here is my function for getting the temperature if anyone cares:

//Function to compute temperature 
void computeTemp()
{
  if(tick == 90){

    //Store the average temperature
    Temperature = degreeList / 90.0;

    //Reset the tick count and list to start again
    tick = 0;
    degreeList = 0;
  }
  //Read the TMP sensor
  sensorIn = analogRead(temperaturePin);
  //sensorIn = digitalRead(A4);

  //Convert the reading from the tmp sensor to voltage
  Voltage = ((sensorIn / 1024.0) * 5.0);

  //Convert the voltage to a temperature
  rawTemperature = ((Voltage - 0.5) * 100.0);

  //Convert to degrees F
  rawTemperature = ((rawTemperature * 9.0)/5.0) + 32.0;

  //Add the new temperature reading to our list to be averaged
  degreeList = degreeList + rawTemperature;

  //Increase the tick count
  tick = tick + 1; 
}