Go Down

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

tatagatha

I'm enjoying Arduino Tiny.  Thanks alot for this cool set of cores. I'm only using the ATTiny85 right now, but look forward to trying out others.
There is one thing I can't wrap my head around. I am trying to read a voltage from ADC2 /PB4 / IC pin #3. To read the value I use :
Code: [Select]
int value = analogRead(2);
but if I wanted to use it as a digital input I would use
Code: [Select]
int value = digitalRead(4);
The arduino standard pin has alias constants A0=14 so you use:
Code: [Select]
int value = analogRead(A0);
But behind the scenes the pin number is different since A0 is really 14.  Why is the pin number "2" overloaded in this case?

This is such a cool set of cores, you should have your own forum instead of this thread. Also, opening that wiki a little might be nice. There are some basic head slap errors that could be put in a frequent problems.

Thanks alot,
Marc

Coding Badly

I'm enjoying Arduino Tiny.


Excellent.  I'm glad.

Quote
I am trying to read a voltage from ADC?2? /PB4 / IC pin #3. To read the value I use :
[font=Courier New]int value = analogRead( ?2? );[/font]


The Uno and boards like it have the same numbering pattern for analog inputs.

Quote
but if I wanted to use it as a digital input I would use
[font=Courier New]int value = digitalRead( ?4? );[/font]


PB?4?

Open the datasheet...
http://www.atmel.com/devices/attiny85.aspx?tab=documents
...navigate to...
1. Pin Configurations

"ADC" for analog "pins".  "PB" for digital "pins".  The numbering pattern makes it much easier to go from functional descriptions in the datasheet to code.

Quote
This is such a cool set of cores,


Thanks.  The next version will be much better (if I ever finish it).

Quote
you should have your own forum instead of this thread


That is very unlikely to happen.  Moderating one forum is enough.

Quote
Also, opening that wiki a little might be nice.


That wiki irritates me to no end.  What is there is probably all that will ever be there.  I have another one started at another location that will eventually be made available to the public.

I am certainly will to give you (or anyone else) wiki edit permission if you'd like.

Osgeld

raises hand for wiki edit
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

tatagatha


"ADC" for analog "pins".  "PB" for digital "pins".  The numbering pattern makes it much easier to go from functional descriptions in the datasheet to code.


I think I see your point.  I understand the pin diagram and that in this case a better description of the two functions in this core might be analogRead(ADC#) and digitalRead(port B position). I just want to know if understand that this scheme is different than how the arduino code base identifies "pins". As far as I can tell each physical pin is always identified using the same integer regardless of if it is a digit read from the port, or an analog read from the ADC. Whereas, this core distinguishes port positions from the ADCs uses the integer value 2 for two different physical pins.

Quote
That is very unlikely to happen.  Moderating one forum is enough.

I just mean that there are several troubleshooting topics interwoven in this one thread. It might be nice to have a sub category to Microcontrollers, which you are already moderating, just for Tiny Arduino. It might encourage questions to be broken up into individual threads. There is clearly a lot of interest.

Quote
I am certainly will to give you (or anyone else) wiki edit permission if you'd like.

That would be great. Most of my inclusions would just be the simple mistakes I was having using the Arduino as programmer. MISO/MOSI wired wrong etc...

Coding Badly

raises hand for wiki edit


Excellent.  Looks like you will need a "Google Account".  I think that just means signing up for a GMail.com email address.  Personal Message me the email address and I'll set you up.

Coding Badly

I just want to know if understand that this scheme is different than how the arduino code base identifies "pins". As far as I can tell each physical pin is always identified using the same integer regardless of if it is a digit read from the port, or an analog read from the ADC.


That is not correct.  On the Uno, digital pins 14 through 19 correspond to analog pins 0 through 5.  The A* constants hide that fact.

Quote
Whereas, this core distinguishes port positions from the ADCs uses the integer value 2 for two different physical pins.


Correct.

Quote
I just mean that there are several troubleshooting topics interwoven in this one thread.


Yup.  It's a gnarly mess.

Quote
It might be nice to have a sub category to Microcontrollers, which you are already moderating, just for Tiny Arduino.


That is very unlikely to happen.  The moderators do not have the power to create subcategories and I doubt the administrators will have much interest.  This is an Arduino forum.   ;)

Quote
That would be great.


See the post above.

stoopkid

#186
May 13, 2012, 08:40 am Last Edit: May 13, 2012, 08:50 am by stoopkid Reason: 1
After I upload my sketch to the attiny85 everything works fine until I disconnect the attiny from the arduino pin 13. Then it stops and when I plug it back in it acts all nutty. I tried powering everything down, unplugging then powering up and I got the same thing. What could be going on here? Same thing with a few different attinys.

nevermind sorry, wiring issue.

skater_j10

Hello All,

Just wanted to thank everyone in this thread for the useful tidbits of info.

Solarbotics has just released an ATtiny85 application board that takes advantage of all this good stuff.

The SB-Firefly can be found here: http://www.solarbotics.com/product/60140/

Dr_Ugi

Not sure if this is the place to ask, but I have been programing my ATtiny85s with the Arduino Tiny core using my nano as ISP.  All works great.

However, I only have one "real" Arduino and so I thought I would make a small programmer using a '328 breakout board and an 8-pin DIL socket.  I have checked the connections loads of times and I see the heartbeat from the Arduino ISP sketch but for some reason I get this error when I program using my stand-alone clone:

avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64

I can only think of two possibly significant differences between my clone and a "real" arduino:  

I am using an ATMega328 not a '328P (it is bootloaded correctly with the Duemilanove bootloader).
I am using a CP2102 type USB to serial converter.

There is no auto-reset capacitor on my clone board so disabling auto-reset should not be an issue.

Anyone have any ideas why I'm getting this problem?

Erni

Coud it be the different device signature in P vs non P

http://arduino.cc/forum/index.php/topic,98956.0.html

Dr_Ugi

You could be right, and certainly in order to bootload the '328 I needed to tweak the .config file for AVRdude.  However, once the bootloader is installed they usually function in the same way.

I do have a '328P knocking around somewhere but I need to bootload that before I can try it out.  Ho Hum.

lightningserpent

I have been banging my head into the wall tying to make a temperature candle out of the Tiny85. I originally tried using the MIT core, but was unable to use PB4 as a PWM.  Changing to the "arduino tiny" library enable the use of PB4 as a PWM. I am also trying to use a TMP36 sensor to adjust an RGB led based on the temperature. I am not committed to using this sensor; I chose it because of size (smt) and cost (around $1). I have searched high and low on how to make the tiny read this sensor. I cannot get "analogRead" to function properly. If someone can point me in the right direction. I would be grateful. I would really like to try using the internal temperature sensor, but could find no code examples I could understand. Here is my code. Suggestions appreciated.

Code: [Select]

const int REDLITE = 0;
const int BLUELITE = 4;
const int GREENLITE = 1;

int flick, temp, tempC, voltage, reading;

void setup(){
  Serial.begin(9600);
  pinMode(REDLITE, OUTPUT);
  pinMode(GREENLITE, OUTPUT);
  pinMode(BLUELITE, OUTPUT);
}

void loop(){
     reading = analogRead(1); 
     voltage = ((reading / 1024) * 5);
     tempC = (voltage - 0.5) * 100 ;
     temp = tempC;
     Serial.println(temp);

  flick = random(120)+135;

  if (temp < 23){
    digitalWrite(REDLITE, LOW);
    digitalWrite(GREENLITE, LOW);
    analogWrite(BLUELITE, flick);
  }
  else {
    if (temp > 30){
      digitalWrite(BLUELITE, LOW);
      digitalWrite(GREENLITE, LOW);
      analogWrite(REDLITE, flick);
    }
    else {
      digitalWrite(BLUELITE, LOW);
      analogWrite(REDLITE, flick);
      analogWrite(GREENLITE, flick);
    }
  }
  delay(random(100));
}

Coding Badly

Quote
I cannot get "analogRead" to function properly.


 ?  


Quote
reading = analogRead(1);  


...is PB2.  Is the sensor connected to the second pin down on the right side?

lightningserpent

The sensor is hooked up to the second pin down on the right side (pin #7). The attiny85 does not respond to the tmp36. When the chip is powered up the blue led flickers. Assuming I have the serial function set correctly the pin continuously resturns "-50" regardless of the conditions I place upon the sensor; breathing on the sensor, pulling the sensor out, or using a potientiometer/voltage divider offers no reaction. I even tried using using a different sensor, with no change in behavior. I do not know what is going on because even changing to a different pin does not fix this. Any suggestions?

lightningserpent

#194
Jun 13, 2012, 05:22 pm Last Edit: Jun 14, 2012, 02:46 am by lightningserpent Reason: 1
After removing all of the temperature calculation and substituting the sensor for a 10k pot I am able to affect the color of the LED. Is there something wrong with my temp formula? The serial returns values from 0-1023 when I am not using the formula. When I try and calculate the temperature the serial port always returns -50. I have used the temp code on the 328's without issue. Any idea what is going on?

Code: [Select]

const int REDLITE = 4;
const int BLUELITE = 0;
const int GREENLITE = 1;

int flick, reading;

void setup(){
 Serial.begin(9600);
 pinMode(REDLITE, OUTPUT);
 pinMode(GREENLITE, OUTPUT);
 pinMode(BLUELITE, OUTPUT);
}

void loop(){
 reading = analogRead(1);  
 Serial.println(reading);
 flick = random(120)+135;

 if (reading < 235){
   digitalWrite(REDLITE, LOW);
   digitalWrite(GREENLITE, LOW);
   analogWrite(BLUELITE, flick);
 }
 else {
   if (reading > 280){
     digitalWrite(BLUELITE, LOW);
     digitalWrite(GREENLITE, LOW);
     analogWrite(REDLITE, flick);
   }
   else {
     digitalWrite(BLUELITE, LOW);
     analogWrite(REDLITE, flick);
     analogWrite(GREENLITE, flick);
   }
 }
 delay(random(100));
}

Go Up