analogReference on ATTiny85

Just checking if I am reading the datasheet right. I am using I2C from an ATTiny85 to send data to an UNO, no problems there, and since I had an extra pin and some analog temperature sensors I thought I'd send that data too. OK, the Microchip MCP9700 has a straight analog output of 10mv/C degree, with a base of 500mv at 0 degrees C. Still no problem, reads and transmits the raw data fine, but I would like to use the internal 1.1V reference voltage to increase the sensitivity. Now the problem: page 62 "PBO = MOSI:: SPI Master Data Output / Slave Data Input AIN0: Analog Comparator, Positive Input OC0A: Timer/Counter0 Compare Match A output OC1A: Complementary Timer/Counter1 Compare Match A Output DI: USI Data Input (Three Wire Mode) SDA: USI Data Input (Two Wire Mode) AREF: External Analog Reference PCINT0: Pin Change Interrupt 0, Source 0"

AND page 64

" AREF: External Analog Reference for ADC. Pullup and output driver are disabled on PB0 when the pin is used as an external reference or Internal Voltage Reference with external capacitor at the AREF pin."

SO.... setting the internal analog reference will NOT work if I am using I2C, correct? Don't really need the accuracy, but it would be nice to get it to work. Thanks , TomJ

The external AREF bypass is optional. I'll be back in a few minutes with details.

If you are using the Tiny Core, INTERNAL enables the internal 1.1 volt reference without the external capacitor…

http://code.google.com/p/arduino-tiny/source/browse/trunk/hardware/tiny/cores/tiny/wiring.h#113

You should not have any problems using the 1.1 volt internal reference and I2C at the same time.

For the best results you should have a bypass capacitor between VCC and GND and you should use Noise Reduction.

Thanks CodingBadly, tried using analogReference(INTERNAL); but got 1023 on the output from the analog pin I am using, which works fine with the 5 volt internal reference. The temp sender puts out .93 volts directly hooked to a 5v supply , measured with a calibrated DMM, yet when I hook it to the 4.9volts feeding the attiny85 with the internal 1.1 reference set it puts out 1.2v, caps all over for decoupling. I even tried a 3v3 regulator on its power supply leg and got 3 on the serial output. Crazy Put everything back like it was, default internal aaref setting, 5 volt supply to the sensor, ect and all is well again, just have the 1.97/degree change on the analog reading still. Accurate enough for a freeze warning I guess, I am probably just reading the specs wrong on the datasheet for the temp sender. Thank you again for the help. TomJ

Just so you know, the ATtiny85 also has an internal 2.56 volt reference.

I saw that in the wiring.h file but I still have trouble reading those. Would this be the way to set the internal 2.56v aaref without the decoupling cap? "analogReference(INTERNAL2V56 (6));" Thanks again TomJ

You won't be able to use the named constant (or you will have to change the value).

I would do it like this...

#define INTERNAL2V56_NO_CAP (6)

void setup( void )
{
  analogReference( INTERNAL2V56_NO_CAP );
}

Thanks again CB, I would have never figured that out, will try it asap. I might have been doing the 1.1v declaration wrong too. TomJ

Codingbadly,
Thanks again, that worked great when I got the small reader I had coded to try this out written right.
Seems “data = (data1<<8 + data2);” will compile but not work. Duh, got to watch my semantics as well as my syntax.
Sorry to take so long to get back, had to take a few days off for DW’s chemo.
TomJ

Hi,
I’m having somewhat the same problem, an ATTiny85 with internal 2.56V reference and using I2C. Could you elaborate on the solution a bit, specifically:

#define INTERNAL2V56_NO_CAP (6)

void setup( void )
{
analogReference( INTERNAL2V56_NO_CAP );
}

and

I saw that in the wiring.h file

where are you guys looking to reference that code? I don’t have wiring.h anywhere I looked.
My chip seems to default to 1.1V internal when I put in the below code.

My code : (excuse the nested functions, sorry)

#include <TinyWireM.h>
#include <USI_TWI_Master.h>
#define INTERNAL2V56_NO_CAP (6)

int lcdAddress = 7;
int sensorPin = 2;
int sensorValue = 0;

void setup() {
  analogReference( INTERNAL2V56_NO_CAP );
  TinyWireM.begin();
  delay(1000);
  sendCommand(17);
}

void loop() {
  sendCommand(10);
  sendText(getTemp());
  TinyWireM.beginTransmission(lcdAddress);
  TinyWireM.send(128);//blank command
  TinyWireM.send(32);//space
  TinyWireM.send(223);//degree symbol
  TinyWireM.send(67);//capital C
  TinyWireM.endTransmission();  
  TinyWireM.beginTransmission(lcdAddress);
  TinyWireM.send(5);//capital C
  String test = "";
  test = test + analogRead(sensorPin);
  for (int x = 0; x<test.length(); x++){
    TinyWireM.send(test.charAt(x));
  }
  TinyWireM.endTransmission();  
  
  delay(500);  
}
String getTemp(){
  String text = "";
  float sensorValue = ((analogRead(sensorPin)*2.5)-500)/10;
  text = text + int(sensorValue);
  sensorValue = sensorValue - int(sensorValue);
  sensorValue = sensorValue * 10;
  text = text + ".";
  text = text + int(sensorValue);
  return text;  
}
void sendText(String text){
  TinyWireM.beginTransmission(lcdAddress);
  TinyWireM.send(0);
  for (int x = 0; x<text.length(); x++){
    TinyWireM.send(text.charAt(x));
  }
  TinyWireM.endTransmission();         
}

void sendCommand(int command){
  TinyWireM.beginTransmission(lcdAddress);
  TinyWireM.send(command);
  TinyWireM.endTransmission();         
}

String getTemp(){
String text = “”;

Are using the Standard Core with David Mellis’ variant?

Not sure, It's been awhile since I loaded firmware. Custom fuses, I think. I'll have to get back to you.

This might sound stupid, but I don't think there is any firmware. That is, any software loaded on the chip that helps with programming it. I alway program it using the usbtiny programmer from ladyAda, via the SPI pins (MOSI, MISO, etc). I may have loaded the firmware once to set fuses to get it running on the internal 8 MHz clock (I have also set fuses with AVRFuses.exe), but then once I programmed the chip with my own code, any firmware gets overwritten. That is my understanding, anyways. Please explain your question? :astonished:

I finally saw the link you posted to wiring.h. Think I'm a little slow on the uptake... :blush:

andstos: This might sound stupid, but I don't think there is any firmware.

I did not ask about "firmware" but about a "core".

That is, any software loaded on the chip that helps with programming it. I alway program it using the usbtiny programmer from ladyAda, via the SPI pins (MOSI, MISO, etc). I may have loaded the firmware once to set fuses to get it running on the internal 8 MHz clock (I have also set fuses with AVRFuses.exe), but then once I programmed the chip with my own code, any firmware gets overwritten. That is my understanding, anyways.

Correct.

Please explain your question?

A core is a set of source files under one of two "cores" directory. The source files implement the Arduino API.

This is the "Standard Core" that came with the Arduino IDE... https://github.com/arduino/Arduino/tree/master/hardware/arduino/cores/arduino

This is the "Tiny Core"... http://code.google.com/p/arduino-tiny/source/browse/#svn%2Ftrunk%2Fhardware%2Ftiny%2Fcores%2Ftiny

The "Standard Core" is already on your computer. The "Tiny Core" is something you would have downloaded and installed later.

Wow. Ok, downloaded and tried the Tiny core from Mellis, the analogReference is working now. Also, as an added bonus, compiling and uploading to the chip is at least three or four times faster. :astonished: Thank you!

Hello,

I understand that this is a very old thread but I am using the exact same method described in the above posts to set my attiny85 reference to 2.56 but it doesn't seem to work, all I am getting is 1.1 volts, I have the attiny by david a mellis installed in my board manager. Am I missing something here?

There's something wrong with the code that you haven't posted. If you posted it, we might be able to tell you what it is!

Also what version of the IDE, and what version of the Arduino AVR boards do you have installed? The david mellis core is very closely tied to the official AVR boards, so the version of the Arduino AVR boards can make a difference with his core. (I didn't like that approach - my attiny package brings it's own core, so that it can be optimized for the smaller micros and I don't have to worry about changes to the official package impacting the core)

#include "TinyWireS.h"
#define I2C_SLAVE_ADDR 0x26
#define INTERNAL2V56_NO_CAP (6)
int ON = 3;
int FB = 1;
float Actual, lastError = 0.0, Error = 0.0, Integral = 0.0, Derivative;
float Amp = 0.0;
float Output, Kp, Ki, Kd;
float setPOINT = 0.0;
void setup() 
{ 
  //ADMUX = B10010010;
  float num = 0.0;
  analogReference(INTERNAL2V56_NO_CAP);// set internal reference to 1.1 V
  pinMode(ON,OUTPUT); // ON/OFF signal for LM2576
  pinMode(FB, OUTPUT); //PWM for LM2576 Feedback
  digitalWrite(ON, HIGH);
  TinyWireS.begin(I2C_SLAVE_ADDR);
  while(1)
  {
    if(TinyWireS.available())
    {
      num = TinyWireS.receive();
      break;
    }
  }

  while(1)
  {
    if(TinyWireS.available())
    {
      Kp = TinyWireS.receive();
      break;
    }
  }

  while(1)
  {
    if(TinyWireS.available())
    {
      Ki = TinyWireS.receive();
      break;
    }
  }
  while(1)
  {
    if(TinyWireS.available())
    {
      Kd = TinyWireS.receive();
      break;
    }
  }
  Amp = num*0.1;
  setPOINT = Amp*1024; // with the amplification factor included
  setPOINT = setPOINT/2.56;
    Kp = Kp/100; //0.05 (send 5)
    Ki = Ki/10000; //0.0008 (send 8)
    Kd = Ki/10000;//0.0075 (send 75)
  analogWrite(FB,70);
  digitalWrite(ON,LOW);
  delay(5000);
}

void loop() 
{
  Actual = analogRead(A2);
  Error = setPOINT - Actual;
  Integral = Integral + Error;
  if(Integral > 100000)
  {
    Integral = 100000;
  }
  if(Integral < - 100000)
  {
    Integral = -100000;
  }
  Derivative = lastError - Error;
  Output = -Kp*(Error) -Ki*(Integral) -Kd*(Derivative) + 62;
 if(Output > 255)
 {
    Output = 255;
  }
  if(Output < 0)
  {
    Output = 10;
  }
  analogWrite(FB, Output);
  lastError = Error;
   }

This is my code, the approach is exactly same as described, I am using IDE version 1.6.6, when I open up board manager, I can it say Arduino AVR board built in by Arduino version 1.6.9, is this how you check the version of the Arduino avr boards?

Yes.

From the release notes for 1.6.14 avr boards (ships with 1.6.12 IDE) - this is what I was referring to about the core version making a difference.

[core] * avr: Add support for internal 2.56V and 2.56V ext. cap analog references on the ATtiny25/45/85. Thanks @mischnic

So you need the latest version of the avr boards package to make it work with the david mellis core.