Go Down

Topic: Arduino Tiny (Read 80036 times) previous topic - next topic

spycatcher2k

((reading / 1024) * 5);

reading is 0 ->1024
therefor reading/1024 will be 1 or less (Probably rounded to 1) * 5 = 5,
what value range are you trying to get?
Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Erni

Try to check your LM35 with a multimeter

http://www.ladyada.net/learn/sensors/tmp36.html

lightningserpent

Thanks for the link to the tmp36 code. I originally used that code and from project to project it has evolved. My issues, for a reason I am not too sure of, stemmed from not using "float". I toyed with code straight from adafruit's page and found that it broke if I did not float my values. Thank you for your help. I am finished with the coding. Because the "arduino tiny" core was so easy to implement I no longer need to embed 328's for simple projects like this. One final question:

Is there an easy way to use the ATtiny85's internal temperature sensor through ArduinoISP?

Here is the current completed code (when I embed this I will remove the "serial" functions).
Code: [Select]

const int r = 4;//red
const int b = 0;//blue
const int g = 1;//green
const int s = 1;//sensor *ANALOG

int temp, currentTemp;
int previousTemp=0;

long previousMillisTIME= 0;
unsigned long intervalTIME = 1000;

void setup(){
  Serial.begin(9600);
  pinMode(r, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(b, OUTPUT);
}

void loop(){

  unsigned long currentMillisTIME = millis(); 
  if(currentMillisTIME - previousMillisTIME > intervalTIME) { 
    sense();
    previousMillisTIME = currentMillisTIME;
  }       

  int flick = random(120)+135;//candle like effect

  if (temp < 68){//only show blue
    digitalWrite(r, LOW);
    digitalWrite(g, LOW);
    analogWrite(b, flick);
  }
  else {
    if (temp > 72){//only show red
      digitalWrite(b, LOW);
      digitalWrite(g, LOW);
      analogWrite(r, flick);
    }
    else {//only show green
      digitalWrite(b, LOW);
      digitalWrite(r, LOW);
      analogWrite(g, flick);
    }
  }
  delay(random(150));
}

void sense(){
  delay(10);
  int reading0 = analogRead(s);
  delay(10);
  int reading1 = analogRead(s);
  delay(10);
  int reading2 = analogRead(s);
  delay(10);
  int reading = ((reading0+reading1+reading2)/3);//average readings
  float voltage = reading * 3.3;//voltage reference
  voltage /= 1024.0;
  float temperatureC = (voltage - 0.5) * 100;
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  currentTemp = temperatureF;

  if(currentTemp - previousTemp >= 3) {//hysteresis forward
    temp = temperatureF;
    Serial.print("Changed From ");
    Serial.print(previousTemp);
    Serial.print(" to ");
    Serial.println(currentTemp);
    previousTemp = currentTemp;
  }
  else {
    if(currentTemp - previousTemp <= -3) {//hysteresis backward
      temp = temperatureF;
      Serial.print("Changed From ");
      Serial.print(previousTemp);
      Serial.print(" to ");
      Serial.println(currentTemp);
      previousTemp = currentTemp;
    }
  }
    //debugging
  Serial.print(voltage);
  Serial.println(" volts");
  Serial.print(temperatureC);
  Serial.println(" degrees C");
  Serial.print(temperatureF);
  Serial.println(" degrees F");
  Serial.print("current reading ");
  Serial.println(temp);
  Serial.println(" ");
}

Dr_Ugi

#198
Jun 23, 2012, 10:31 am Last Edit: Jun 23, 2012, 10:39 am by Dr_Ugi Reason: 1
I'm trying to use the ATtiny85 Arduino Tiny core in a project where I need to use the 2.56v internal reference for the ADC - not least because I need the ARef pin for other things, but also so that the reading is not directly dependent upon VCC, which in a battery powered situation is not very uniform. I appreciate that we need to use the non-decoupled 2.56v to avoid connecting pin 5 to that voltage.

I have tried poking at ADMUX without success and wondered:

Does analogRead always use the external Vref?
If so, can I read ADCL & ADCH directly?  I have tried but seem to be getting zeros.

Any thoughts appreciated.

Edit - it appears that by poking ADMUX I can alter the reference voltage (I can set it so that the 2.5v appears at PB0) but as soon as I call AnalogRead it reverts to the external ref.

Coding Badly


Huh.  Looks like the coin flip had me pick the wrong one to include...
http://code.google.com/p/arduino-tiny/source/browse/trunk/hardware/tiny/cores/tiny/wiring.h#105
[font=Courier New]
  analogReference( 6 );[/font]

...should do the trick.  Do you have a preference for the name of the constant (other than [font=Courier New]INTERNAL2V56[/font])?

Dr_Ugi

That's fantastic - I would not have believed that I could have learned quite so much from such a short reply!

I did have a hunt through the source code for the tiny core but didn't find anytihng, but it would have taken me a while to get around to looking in wiring.h

I suppose INTERNAL2v56NB (for no bypass) is as logical as anything but you will have a much better feel for that than me.  

I do think this is a useful reference to have because, with so few pins, if you want an absolute measurement but are not too worried about accuracy then you might prefer to avoid giving a pin up to a capacitor.

Thanks again

funkyguy4000

unfortunately I'm getting a not in sync error when using these cores when trying to bootload.  resp 0x00

Accelerate to 88 miles per hour.

wanderson


unfortunately I'm getting a not in sync error when using these cores when trying to bootload.  resp 0x00



In order to help, you will need to supply some more information.


  • What version of the IDE are you using?

  • What chip are you attempting to program?

  • What device are you using to do the programming?

  • Turn on verbose programming and provide a complete copy of the output

  • How are you connecting the device to the programmer? Picture helpful.

New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

funkyguy4000

I'm using Arduino IDE 1.0.1
ATtiny45 @ 8
ArduinoISP (Arduino Duemilanove)
I don't know how to turn on verbose programming
Here is a video of the whole deal,  It starts out dark so you can see the TX and RX leds and then it shows my setup
http://www.youtube.com/watch?v=s0gnL0HnbKU&list=UUfjRGtXoqzGDd_e_d6GS0TQ&index=1&feature=plcp
Accelerate to 88 miles per hour.

wanderson

Verbose programming can be turned on use File | Preferences
New true random number library available at: http://code.google.com/p/avr-hardware-random-number-generation/

Current version 1.0.1

funkyguy4000

Code: [Select]
C:\Users\shannon\Desktop\arduino-1.0.1\hardware/tools/avr/bin/avrdude -CC:\Users\shannon\Desktop\arduino-1.0.1\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pattiny45 -cstk500v1 -P\\.\COM6 -b19200 -e -Uefuse:w:0xFF:m -Uhfuse:w:0xD7:m -Ulfuse:w:0xE2:m

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\Users\shannon\Desktop\arduino-1.0.1\hardware/tools/avr/etc/avrdude.conf"

         Using Port                    : \\.\COM6
         Using Programmer              : stk500v1
         Overriding Baud Rate          : 19200
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Recv:
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.
Accelerate to 88 miles per hour.

stoopkid

I want to use an attiny84 for some speed/timing stuff at 3v. The internal oscillator is pretty lousy, can I use a 1MHz external crystal? And if so, what pins are for the crystal on the 84?

Thanks

Tom Carpenter

The XTAL pins are on physical pins 2 and 3 (PB0 and PB1). You would have to change the boards.txt file to use the correct freqency. There is an entry for 84 with a 16MHz external crystal, just copy and paste this, change the name and set the freqency to 1000000
~Tom~

leo72

#208
Sep 24, 2012, 11:17 am Last Edit: Sep 24, 2012, 11:57 am by leo72 Reason: 1
I've noticed that digitalWrite isn't available inside the setup(). Why?

EDIT:
forget about it

Erni

Code: [Select]
for (byte temp = 0; temp++; temp < 4) {

should be:
Code: [Select]
for (byte temp = 0; temp < 4;temp++) {

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy