Go Down

Topic: core13: An Arduino core for the Attiny13 *testers wanted* (Read 158070 times) previous topic - next topic

hiduino

A closer look at wiring.h show that analogReference() has been commented out for some reason?

Also the INTERNAL and EXTERNAL definitions are both defined as zero for some reason?

According to the datasheet, the INTERNAL 1.1V reference  is REFS0 = 1.  And the EXTERNAL Vcc reference is REFS0 = 0.


hiduino

I tested uncommenting the analogReference() and corrected the definitions in the core13\wiring.h file:

Code: [Select]

#define INTERNAL 1
#define EXTERNAL 0

void analogReference(uint8_t mode);



Seems to work reasonably well between INTERNAL and EXTERNAL settings.
Test code:
Code: [Select]


int led = 3;
const int inPin = 2;    // analog in, to ADC2 for temp sensor TMP36, pin 3 on ATtiny13

void setup() {               
  pinMode(led, OUTPUT);

  // initialize the ADC voltage reference
  analogReference(EXTERNAL);    // Vref = Vcc
//  analogReference(INTERNAL);    // Vref = 1.1V
}

void loop() {
  // Read temperature sensor
  int value = analogRead(inPin);
//  float millivolts = (value / 1024.0) * 1100;  // Internal 1.1V
//  float millivolts = (value / 1024.0) * 4800;  // External VCC 4.8V
//  float celsius = (millivolts / 10.0) - 50;    // TMP 36 offset
//  float fahrenheit = (celsius *9)/5 + 32;

//  if ( value > 692) {  // Internal threshold for temp 76 deg
  if ( value > 158) {  // External theshold for temp 76 deg
     digitalWrite(led, HIGH);   // temp above threshold
  } else {
     digitalWrite(led, LOW);    // temp equal or below threshold
  }
  delay(1000);
}



smeezekitty

Quote

This is very strange. I am using version 18. The same code can be compiled for Attint85, but it does not work for Attiny13. That means that it is correctly spelled. The code that fails follows:

void setup() {
analogReference(INTERNAL);
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);

time = millis();
memooculto = EEPROM.read(0); delay(80);
if (memooculto == 0) { maxmodereal = maxoculto;}
else  {maxmodereal = maxmode;}

mode = EEPROM.read(1);
delay(80);
if (mode == 0) {mode = 1;}
if (mode > maxmodereal) {mode = maxmodereal;}
}

I confirmed there is a problem with wiring.h. You need to uncomment analogReference() and change #define INTERNAL to something other then zero.

But unless you have another library, EEPROM functions won't work.
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

ProfePaco

Thanks a lot hiduino...

Now i can compile the code.

ProfePaco


I confirmed there is a problem with wiring.h. You need to uncomment analogReference() and change #define INTERNAL to something other then zero.

But unless you have another library, EEPROM functions won't work.


Oh My God. I need both... EEPROM and analogReference()  :~

ProfePaco

is there any way to solve this issue?  =(

can I write the code that correspond to analogReference() directly in the Arduino sketch?

Thanks in advance

smeezekitty


is there any way to solve this issue?  =(

can I write the code that correspond to analogReference() directly in the Arduino sketch?

Thanks in advance

No need. After you make the minor corrections in the wiring.h it will work. Will be fixed in version 0.19
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

ProfePaco



is there any way to solve this issue?  =(

can I write the code that correspond to analogReference() directly in the Arduino sketch?

Thanks in advance

No need. After you make the minor corrections in the wiring.h it will work. Will be fixed in version 0.19


However, you said that EEPROM will not work. My need  is to use EEPROM library and analogReference() at the same time...

is it possible with 0.18 or I have to wait to 0.19?

Thanks in advance

Erni

#158
May 19, 2013, 12:00 pm Last Edit: May 19, 2013, 12:26 pm by Erni Reason: 1
I am not sure what I do.
I just tryed this sketch on an ATtiny13

Code: [Select]

#include <TinyDebugKnockBang.h>
#include <EEPROM.h>


void setup( void )
{
 EEPROM.write( 0, 127 );
 EEPROM.write( 1, 23 );
 Debug.begin( 250000 );
}

void loop( void )
{
 Debug.print("EEPROM (0)= ");
 Debug.println( EEPROM.read( 0 ), DEC );
 Debug.print("EEPROM (1)= ");
 Debug.println( EEPROM.read( 1 ), DEC );
 delay( 1000 );
}


And get this result:

Code: [Select]
EEPROM (0)= 127
EEPROM (1)= 23
EEPROM (0)= 127
EEPROM (1)= 23
EEPROM (0)= 127


So the EEPROM lib seems to work on a t13

I can see from the verbose output that the EEPROM library from the Arduino core is used:

Code: [Select]
D:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\hardware\tools\avr\bin\avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=attiny13 -DF_CPU=4800000 -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=101 -ID:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\hardware\tiny\cores\core13 -ID:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\libraries\TinyDebugKnockBang -ID:\arduino-1.01\arduino-1.0.1-windows (1)\arduino-1.0.1\libraries\EEPROM C:\Users\EC\AppData\Local\Temp\build8446476430265160657.tmp\tiny13_eeprom.cpp -o C:\Users\EC\AppData\Local\Temp\build8446476430265160657.tmp\tiny13_eeprom.cpp.o

ProfePaco

the problems seems to use at the same time EEPROM and analogReference()...

smeezekitty

#160
May 19, 2013, 07:13 pm Last Edit: May 19, 2013, 07:16 pm by smeezekitty Reason: 1
Replace wiring.h with:
Code: [Select]

/*
*** 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.19
*/
#ifndef Wiring_h
#define Wiring_h
#include <avr/io.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C"{
#endif
#define HIGH 1
#define LOW 0
#define INPUT 0
#define OUTPUT 1
#define false 0
#define FALSE 0
#define TRUE 1
#define true 1
#define PI 3.1416
#define HALF_PI 1.57
#define TWO_PI 6.283
#define DEG_TO_RAD 0.0174533
#define RAD_TO_DEG 57.2958
#define SERIAL 0
#define DISPLAY 1 //WTF are these?
#define LSBFIRST 0
#define MSBFIRST 1
#define CHANGE 1
#define FALLING 2
#define RISING 3
#define INTERNAL 1
#define EXTERNAL 0
#define DEFAULT 0
#ifdef abs
#undef abs
#endif
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define round(x)     ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define interrupts() sei()
#define noInterrupts() cli()
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
#define lowByte(w) ((uint8_t) ((w) & 0xff))
#define highByte(w) ((uint8_t) ((w) >> 8))
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
typedef unsigned int word;
#define bit(b) (1UL << (b))
typedef uint8_t boolean;
typedef uint8_t byte;
void init(void);
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
uint8_t digitalRead(uint8_t);
int analogRead(uint8_t);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, uint8_t);
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned ms);
void delayMicroseconds(unsigned int us);
void shiftOut(uint8_t, uint8_t, uint8_t, uint8_t);
uint8_t shiftIn(uint8_t, uint8_t, uint8_t);
unsigned long pulseIn(unsigned char pin, unsigned char stat, unsigned long timeout);
//void attachInterrupt(uint8_t, void (*)(void), int mode);
//void detachInterrupt(uint8_t);
void setup(void);
void loop(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif


The EEPROM library is just a thin wrapper around avr-libc so it should work but could be large.
Avoid throwing electronics out as you or someone else might need them for parts or use.
Solid state rectifiers are the only REAL rectifiers.
Resistors for LEDS!

Erni

That seems to do the trick.
Using the new wiring.h I get theese result, when using analogReference(INTERNAL);
and 0,53V on ADC(2)


Quote

EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23



ProfePaco


That seems to do the trick.
Using the new wiring.h I get theese result, when using analogReference(INTERNAL);
and 0,53V on ADC(2)


Quote

EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23
513
EEPROM (0)= 127
EEPROM (1)= 23





That's good news... thanks for sharing

I will check it up

ProfePaco

#163
May 24, 2013, 10:36 am Last Edit: May 24, 2013, 11:21 am by ProfePaco Reason: 1
I have problems with analogRead, using analogRerefence(INTERNAL).

The reading does not seem to be a function of the applied voltage.

has anybody the same problem?

EDIT:  I solved this problem adding delay(50) before each reading. It seems that if the reads are taking very closely the value from analogRead is not accurate

dwhacks

First off, this is awesome. Check out what I've made using it at dwhacks.blogspot.ca

Second, I have a question about PWM. I know theres 2 dedicated PWM pins, 0 and 1, but I've also read that pin 4 (actual pin 3) can be used as PWM without "software PWM". Does this work with your core? I havent been able to figure it out, but I was trying to make a simple code to fade through colors with an RGB LED. Anyone done this that I've missed?

And finally, why not include a "boards.txt" and the proper folder structure in the download?

Go Up