Go Down

Topic: compiling error with attiny45 (Read 972 times) previous topic - next topic

jeffreyvisser

Hello,
I want to test my attiny45 with softserial but it won't work. Could somebody see what i have done wrong? Thanks.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 1);
int sensorValue = 0;
int sensor = 3;
float var = 0.0;
float temp = 0.0;
void setup() 
{
    mySerial.begin(4800);
  mySerial.println("Hello, world?");
  pinMode(sensor, INPUT);
}
void loop()
{
  sensorValue = analogRead(sensor);
var = (sensorValue * 5.00) / 1024.00;
temp = var * 52.0833 - 20.833;                     
mySerial.print(temp);
delay(5000);
}

Nick Gammon

http://www.gammon.com.au/electronics

Nick Gammon

Quote
... compiling error ...


What error?

Read this before posting a programming question

Point 6: "If you get an error, post the error (copy and paste). Not just "I got an error"."
http://www.gammon.com.au/electronics

AWOL

Nope, no error here. (IDE 1.0)

Edit: oops missed the "tiny" bit.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

jeffreyvisser

the error:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn45.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o)

there is no hardware serial at an attiny45, isn't it?
Maybe the file is too big?

Nick Gammon

What version of the IDE are you using? I'm getting different errors to you, so we need to work out your environment.

Quote
Maybe the file is too big?


The source file? All 21 lines of it?

http://www.gammon.com.au/electronics

AWOL

Quote
All 21 lines of it?

Yes, at least three lines too many
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

jeffreyvisser

when i delete mySerial.print(temp);
the sketch work! What would be the problem?

Nick Gammon

Just as a hypothesis ...

The Attiny45 has 4 Kb of program memory. Asking it to print a float is probably loading in more libraries than will fit.

Quote
Maybe the file is too big?


Yes, maybe you asked too much of a processor with 4096 bytes of program space.

This doesn't totally prove it, but if you set the board to Uno, the space needed is:

Code: [Select]
Binary sketch size: 5528 bytes (of a 32256 byte maximum)

That's more than 4 Kb.
http://www.gammon.com.au/electronics

jeffreyvisser

i use now serial.write instead of serial.print. But i retrieve '??øfxfx??'. Could i translate that into the right data ?

michael_x

mySerial.print(sensorValue);

Amazing how tiny the attiny is !

Nick Gammon

It's not called the "tiny" for nothing!

But really, floating point numbers are traditionally pretty code and computation expensive.
http://www.gammon.com.au/electronics

Erni

#12
May 03, 2012, 02:43 pm Last Edit: May 03, 2012, 02:47 pm by Erni Reason: 1
Quote
i use now serial.write instead of serial.print. But i retrieve '??øfxfx??'. Could i translate that into the right data ?


I think you use the wrong baudrate.

If you are using TinyDebugSerial you can only use 9600, 38400 or 115000

The outputpin used by TinyDebugSerial is PB3, so if you move the sensorpin to PB4, you have a working sketch.

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

Code: [Select]
int sensorValue = 0;
int sensor = 4;
float var = 0.0;
float temp = 0.0;
void setup()  
{
   Serial.begin(9600);
 Serial.println("Hello, world?");
 pinMode(sensor, INPUT);
}
void loop()
{
sensorValue = analogRead(sensor);
var = (sensorValue * 5.00) / 1024.00;
temp = var * 52.0833 - 20.833;                    
Serial.print("Temp ");
Serial.println(temp);
delay(1000);
}


Go Up