core13: An Arduino core for the Attiny13 *testers wanted*

gizmoDave:
I managed to get to step 8 in the EZlab link before I got error "avrdude: please define PAGEL and BS2 signals in the configuration file for part ATtiny13
I searched and found this error can be ignored?

This "error" is totally irrelevant and must be ignored. For some odd reason AVRDUDE complains when you haven't defined the PAGEL and BS2 signals even though the attiny series processors do not support this. It will upload without issues regardless though.

Thanks I missed that one completely, reloaded with the correct directory structure and things seem to be working much better.

That it a good sign.

I changed the code above to something I think the ATtiny will be able to use
opened the new sketch and hit the verify icon and get the following error

C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13\main.cpp:8: error: expected constructor, destructor, or type conversion before '.' token

I don't even have a clue to search for an explanation for this error :blush: I looked for a misplaced . but don't see one.

That is a weird error. Can you post the file? (It shouldn't be very long) Also ensure the notice block at the top is commented out.

/*
  Blink
  Turns on an LED on for three 250 ms blinks, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 

// give it a name:
int led = PB3;
int ledpin = PB4;
int fadePin = PB1;
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(PB3, OUTPUT);  
  pinMode(PB4, OUTPUT);
  
}

// the loop routine runs over and over again forever:
void loop() {
 
  
  digitalWrite(PB3, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for a second
  digitalWrite(PB3, LOW); 
  digitalWrite(PB4, HIGH);  // turn the LED off by making the voltage LOW
  delay(100);       
  digitalWrite(PB4, LOW); 
  digitalWrite(PB3, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 14 second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);  // turn the LED off by making the voltage LOW
  delay(100); 
  digitalWrite(PB4, LOW); 
  digitalWrite(led, HIGH);     // turn the LED on (HIGH is the voltage level)
  delay(100);                  // wait for 1/4 second
  digitalWrite(PB3, LOW);
  digitalWrite(PB4, HIGH);
  delay(100);
  digitalWrite(PB4, LOW);   // turn the LED off by making the voltage LOW
                               // turn the LED off by making the voltage LOW
  delay(100);                 // wait for a second
  

 
 
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=10) { 
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(40);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(fadePin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(20);                            
  } 
}

Here is the file specifically called out in the error message:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13\main.cpp:8: error: expected constructor, destructor, or type conversion before '.' token

/*
*** Core13 ***
Arduino core designed for Attiny13 and similar devices
NO WARRANTEE OR GUARANTEES!
Written by John "smeezekitty" 
You are free to use, redistribute and modify at will EXCEPT IF MARKED OTHERWISE IN A PARTICULAR SOURCE FILE!
Version 0.14
*/Arduino.h
int main(){
	init(); //Call init routine 
	setup(); //Call user provided setup()
	while(1){loop();} //Continuiously call user provided loop()
}

Is ti possible that I have bricked the ATtiny and that is now causing strange errors?

/*
*** Core13 ***
Arduino core designed for Attiny13 and similar devices
NO WARRANTEE OR GUARANTEES!
Written by John "smeezekitty" 
You are free to use, redistribute and modify at will EXCEPT IF MARKED OTHERWISE IN A PARTICULAR SOURCE FILE!
Version 0.14
*/Arduino.h
int main(){
	 init(); //Call init routine 
	setup(); //Call user provided setup()
	 while(1){loop();} //Continuiously call user provided loop()
}

should be:

/*
*** Core13 ***
Arduino core designed for Attiny13 and similar devices
NO WARRANTEE OR GUARANTEES!
Written by John "smeezekitty" 
You are free to use, redistribute and modify at will EXCEPT IF MARKED OTHERWISE IN A PARTICULAR SOURCE FILE!
Version 0.14
*/
#include "Arduino.h"
int main(){
	 init(); //Call init routine 
	setup(); //Call user provided setup()
	 while(1){loop();} //Continuiously call user provided loop()
}

The error is essentially saying that it can't find a class named 'Arduino' with member 'h'. It is there because the line "*/Arduino.h" is not put inside the #include statement like it should be.

Thanks Tom,
Iwill make the required adjustment the code and program some chips when I get home :smiley:
Thanks to John "smeezekitty" for all the assistance and work on the code to allow us to program these chips.

Thanks again guys, I have my first ATtiny13 programmed and blinking away :smiley:

Version 0.16 released

Ver 16 downloaded, hopefully will have spare time soon to experiment with new code.

I noticed the clock seems to have changed on the last chip I programmed, fuses were burned, and it looked good on the bread board.
Once all the resistors/LEDs were soldered on the clock seems to be running faster by about 30%.

gizmoDave:
Ver 16 downloaded, hopefully will have spare time soon to experiment with new code.

I noticed the clock seems to have changed on the last chip I programmed, fuses were burned, and it looked good on the bread board.
Once all the resistors/LEDs were soldered on the clock seems to be running faster by about 30%.

Different power source? Which oscillator?

John, I'm back. A lot Arduino smarter and experienced but still short on both. I downloaded your latest cores (V16) and was able to get it installed fairly easily. I didn't see a boards.txt included with the cores so I created a new one using the text you posted in Reply #78 on: August 15, 2012, 12:33:07 PM.

Also, your page 1 post now says you "Support 128KHz, 600KHz, 1MHz, 1.2MHz, 4MHz, 4.8MHz, 8MHz, 9.6MHz, 10MHz, 12MHz and 16MHz clock speeds". Is there a place I can download a more complete boards.txt to get those different configs?

I have successfully uploaded a simple program that initializes three digital outputs and then reads an analog input and uses that analog value to select and then flash one of LEDS on the three digital outputs.

void setup() {
// verify all digital outputs are wired properly
pinMode (0, OUTPUT); pinMode (1, OUTPUT); pinMode (2, OUTPUT);
digitalWrite(0, HIGH); delay(1000) ; digitalWrite(0,LOW);
digitalWrite(1, HIGH); delay(1000) ; digitalWrite(1,LOW);
digitalWrite(2, HIGH); delay(1000) ; digitalWrite(2,LOW);
}

void loop() {
// read the value from the sensor:
int potValue = analogRead(3) ;

// select ledPin based upon analogRead value
int ledPin = 0;
if (potValue > 350) ledPin=1;
if (potValue > 700) ledPin=2;

// turn the selected ledPin on
digitalWrite(ledPin, HIGH); delay(500);
digitalWrite(ledPin, LOW); delay(500);
}

The program runs as expected on the Uno and a Tiny85 (@8Mhz) but on the Tiny13 with the boards.txt contents referenced above it had two oddities:
First, it runs about 50x slower than the Uno or Tiny85.
Second, the analogRead produces its full range (0 - 1023) in the first 1/4 turn of the POT. That is, potValue goes from 0 to 1023 with a very short amount of turn. It was very smooth and gradual on the Uno and took the complete turn to produce values from 0-1023. Any ideas what would be causing the analogRead to behave so weird?

malukens:
I didn't see a boards.txt included with the cores so I created a new one using the text you posted in Reply #78 on: August 15, 2012, 12:33:07 PM.

This is true, currently the core does not ship with a boards.txt.

Also, your page 1 post now says you "Support 128KHz, 600KHz, 1MHz, 1.2MHz, 4MHz, 4.8MHz, 8MHz, 9.6MHz, 10MHz, 12MHz and 16MHz clock speeds". Is there a place I can download a more complete boards.txt to get those different configs?

It is not quite that simple.
128KHz is set from the internal watchdog oscillator and is easily selected.
600KHz is the 4.8MHz clock with the /8 fuse set.
1 MHz must be created with an external clock on the '13
1.2MHz is the 9.6MHz clock with the /8 fuse set
4 MHz must be created with an external clock on the '13
4.8MHz is the 4.8MHz internal RC oscillator
8MHz must be created with an external clock on the '13
9.6 MHz is the 9.6MHz internal RC oscillatr
10,12,16 MHz all need to be created with external clocks.

I have successfully uploaded a simple program that initializes three digital outputs and then reads an analog input and uses that analog value to select and then flash one of LEDS on the three digital outputs.

void setup() {
// verify all digital outputs are wired properly
pinMode (0, OUTPUT); pinMode (1, OUTPUT); pinMode (2, OUTPUT);
digitalWrite(0, HIGH); delay(1000) ; digitalWrite(0,LOW);
digitalWrite(1, HIGH); delay(1000) ; digitalWrite(1,LOW);
digitalWrite(2, HIGH); delay(1000) ; digitalWrite(2,LOW);
}

void loop() {
// read the value from the sensor:
int potValue = analogRead(3) ;

// select ledPin based upon analogRead value
int ledPin = 0;
if (potValue > 350) ledPin=1;
if (potValue > 700) ledPin=2;

// turn the selected ledPin on
digitalWrite(ledPin, HIGH); delay(500);
digitalWrite(ledPin, LOW); delay(500);
}

The fuse on the section was wrong with the /8 fuse accidentally set
Change

attiny13.bootloader.low_fuses=0x6A

to

attiny13.bootloader.low_fuses=0x7A

The program runs as expected on the Uno and a Tiny85 (@8Mhz) but on the Tiny13 with the boards.txt contents referenced above it had two oddities:

First, it runs about 50x slower than the Uno or Tiny85.

It should be 8x too slow, I am not sure where 50x would come from?

Second, the analogRead produces its full range (0 - 1023) in the first 1/4 turn of the POT. That is, potValue goes from 0 to 1023 with a very short amount of turn. It was very smooth and gradual on the Uno and took the complete turn to produce values from 0-1023. Any ideas what would be causing the analogRead to behave so weird?

The ADC might be under-clocked from the bad fuse settings. Correct those and try again.
If it persists, I will test later.

smeezekitty:

gizmoDave:
Ver 16 downloaded, hopefully will have spare time soon to experiment with new code.

I noticed the clock seems to have changed on the last chip I programmed, fuses were burned, and it looked good on the bread board.
Once all the resistors/LEDs were soldered on the clock seems to be running faster by about 30%.

Different power source? Which oscillator?

#1 Yes Arduino power on the bread board vs voltage from the RC receiver on final install voltage is 3.8Vdc

#2 ATtiny13 @4.8MHz boards.txt located at:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino

attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock)
attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13

gizmoDave:
#1 Yes Arduino power on the bread board vs voltage from the RC receiver on final install voltage is 3.8Vdc

The voltage can cause the clock to change quite significantly but 30% seems excessive. 10-15% is common of the voltage range of 1.7-5.

#2 ATtiny13 @4.8MHz boards.txt located at:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino

attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock)

attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13

FWIW This has the clock/8 fuse set so it is running at 600KHz and not 4.8MHz.

smeezekitty:
10-15% is common of the voltage range of 1.7-5.

If the frequency of either internal oscillator varies by more than 3% over the voltage range the processor grossly violates the published specifications. In other words, your processor is defective.

Man! I'm going to demand my .99 cents back! For what we pay for these I am not surprised they don't perform to the specifications. This just a minor inconvenience for me as I am only driving lights for an RC toy.

smeezekitty:

gizmoDave:
#1 Yes Arduino power on the bread board vs voltage from the RC receiver on final install voltage is 3.8Vdc

The voltage can cause the clock to change quite significantly but 30% seems excessive. 10-15% is common of the voltage range of 1.7-5.

Would installing a transistor between VCC & Reset force the clock to run at the same on both voltages?

#2 ATtiny13 @4.8MHz boards.txt located at:
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino

attiny13at4.name=ATtiny13 @ 4.8MHz (internal 4.8 MHz clock)

attiny13at4.bootloader.low_fuses=0x69
attiny13at4.bootloader.high_fuses=0xff
attiny13at4.upload.maximum_size=1024
attiny13at4.build.mcu=attiny13
attiny13at4.build.f_cpu=600000
attiny13at4.build.core=core13

FWIW This has the clock/8 fuse set so it is running at 600KHz and not 4.8MHz.

Thanks, I will look up the proper fuse setting for the 4.8MHz setting

gizmoDave:
Would installing a transistor between VCC & Reset force the clock to run at the same on both voltages?

???

Thanks, I will look up the proper fuse setting for the 4.8MHz setting

http://www.engbedded.com/fusecalc/

smeezekitty:

gizmoDave:
Would installing a transistor between VCC & Reset force the clock to run at the same on both voltages?

???

Just asking as a light set I purchased using an ATtiny13 has a component resembling a resistor (SMD 0603 style ) with code E0l or E01 installed between VCC & reset pins. That number seems to belong to a transistor but my electronics searching often turn up bum results.

Thanks, I will look up the proper fuse setting for the 4.8MHz setting

AVR® Fuse Calculator – The Engbedded Blog

Thanks I will check out the link

Actually that is a resistor.
Some microcontrolers experience spurious resets without an external pull up resistor.
If it randomly resets, try a pull of resistor between 2k and 68k.

John, I changed the low fuse to 7A and now the timing is relatively close for both 9.6 MHz and 4.8MHz; it takes only 7 sec for a 10 sec delay to finish (approx 40% fast). The analogRead is still exhibiting the same end-biased behavior as before; the read goes from 0-1023 in approximately 25% of the rotation of the POT.

In an article on Instructables (Make an Attiny13 based IR proximity sensor for $2.42) the author says that you need the command:

analogReference(0);//analogread won't work on Atiny13 w/o this line. Won't work on others WITH it prob'ly.

The article references your core13 but I'm not sure how since the analogReference command is not supported in your core. I appreciate your interest in this platform. Let me know if there is anything else I can test.

Thanks, Mark

testing pulseIn this morning with Ver1.16 and getting error that I think states there is an argument in wiring.h it can't process

C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h: In function 'void loop()':
C:\arduino-1.0.1-windows\arduino-1.0.1\hardware\arduino\cores\core13/wiring.h:76: error: too few arguments to function 'long unsigned int pulseIn(unsigned char, unsigned char, long unsigned int)'
SwitchRC_AUX:10: error: at this point in file

Here is the sketch that generates the error during verification

int duration;

void setup()
{
  pinMode(PB2, INPUT);
  pinMode(PB0, OUTPUT);
}

void loop()
{
  duration = pulseIn(PB2, HIGH);
  digitalWrite(PB0, LOW);
  if (duration < 1300)
  {
    digitalWrite(PB0, HIGH);
  }
}