Pages: 1 ... 12 13 [14] 15 16 ... 22   Go Down
Author Topic: Arduino Tiny  (Read 50076 times)
0 Members and 1 Guest are viewing this topic.
Scotland
Offline Offline
God Member
*****
Karma: 11
Posts: 988
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

((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?
Logged

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1029
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try to check your LM35 with a multimeter

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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(" ");
}
Logged

London
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Ugi was not declared in this scope
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: June 23, 2012, 03:39:51 am by Dr_Ugi » Logged

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 176
Posts: 12286
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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

  analogReference( 6 );


...should do the trick.  Do you have a preference for the name of the constant (other than INTERNAL2V56)?
Logged

London
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Ugi was not declared in this scope
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Wisconsin
Offline Offline
Edison Member
*
Karma: 4
Posts: 1000
I LOVE THIS STUFF!!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Accelerate to 88 miles per hour.

Dallas, Texas
Offline Offline
God Member
*****
Karma: 3
Posts: 717
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Current version 0.7.2

Wisconsin
Offline Offline
Edison Member
*
Karma: 4
Posts: 1000
I LOVE THIS STUFF!!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Accelerate to 88 miles per hour.

Dallas, Texas
Offline Offline
God Member
*****
Karma: 3
Posts: 717
Old, decrepit curmugeon
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Verbose programming can be turned on use File | Preferences
Logged

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

Current version 0.7.2

Wisconsin
Offline Offline
Edison Member
*
Karma: 4
Posts: 1000
I LOVE THIS STUFF!!!!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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.
Logged

Accelerate to 88 miles per hour.

California
Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Leeds, UK
Offline Offline
Edison Member
*
Karma: 72
Posts: 1642
Once the magic blue smoke is released, it won't go back in!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

~Tom~

Global Moderator
Italy
Offline Offline
Brattain Member
*****
Karma: 313
Posts: 21650
Logic is my way
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I've noticed that digitalWrite isn't available inside the setup(). Why?

EDIT:
forget about it
« Last Edit: September 24, 2012, 04:57:48 am by leo72 » Logged


Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1029
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Pages: 1 ... 12 13 [14] 15 16 ... 22   Go Up
Jump to: