Arduino Tiny

Dear Coding Badly
I've now run into another problem.
After studying the Attiny85 datasheet I'm tryin to utilize timer1 for precise pulse control.
I freed timer1 by modifying wiring.c (as you wrote earlier).
My intent is to be able to set precise pause length and pulse length of aech indiviual pulse.
I use following setup:

void setup() {
  pinMode(4,OUTPUT);  //needed for OC1B
  digitalWrite(4,LOW);  
  pinMode(3,OUTPUT); //needed for myself
  digitalWrite(3,LOW);  

  TCCR1 = 0b1000; // clock ck/128
  GTCCR =
    (1<<PWM1B) |  
    (1<<COM1B1) | (1<<COM1B0) ;  // <<PROBLEM HERE
  OCR1B = 41;
  OCR1C = 100;
}

I need the pin to go low on OCR1C compare match and then go high on OCR1B compare match.
So according to above code I should get a pause of 41 ticks and then a pulse of 59 ticks and so on.
But something goes wrong. I get only a constant HIGH state on pin4.
I tried to use (1<<COM1B1) | (0<<COM1B0) instead, and it works ok (!), but the signal gets actually inverted, that's not what I need.
(0<<COM1B1) | (1<<COM1B0) also works ok, I get signal on two pins and one of them (pin 3) is "inverted inverted", thus suitable for me, but that wastes one pin (pin4), which I need to use as I/O, so that's not ok for me also.
Could you give a hint?

I'll try to look more closely at it tomorrow but I believe you have to set CTC1 in TCCR1...

TCCR1 =
(1 << CTC1)
| (0 << PWM1A)
| (0 << COM1A1) | (0 << COM1A0)
| (1 << CS13) | (0 << CS12) | (0 << CS11) | (0 << CS10);

The datasheet says that in PWM mode the counter is reset on OCR1C compare match regardless of CTC1 bit state. Anyway I already tried setting CTC1, that didn't help.

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 :

int value = analogRead(2);

but if I wanted to use it as a digital input I would use

int value = digitalRead(4);

The arduino standard pin has alias constants A0=14 so you use:

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

tatagatha:
I'm enjoying Arduino Tiny.

Excellent. I'm glad.

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

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

but if I wanted to use it as a digital input I would use
int value = digitalRead( ?4? );

PB?4?

Open the datasheet...

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

This is such a cool set of cores,

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

you should have your own forum instead of this thread

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

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.

raises hand for wiki edit

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.

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.

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

Osgeld:
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.

tatagatha:
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.

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

Correct.

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

Yup. It's a gnarly mess.

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. :wink:

That would be great.

See the post above.

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.

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: SB-FireFly - Solarbotics Ltd.

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?

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

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

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.

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.

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));
}

I cannot get "analogRead" to function properly.

** ? **

reading = analogRead(1);

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

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?

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?

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));
}

(deleted)

Try to check your LM35 with a multimeter

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