Pages: [1]   Go Down
Author Topic: compiling error with attiny45  (Read 909 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why not use hardware serial?
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope, no error here. (IDE 1.0)

Edit: oops missed the "tiny" bit.
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged


Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26332
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
All 21 lines of it?
Yes, at least three lines too many
Logged

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

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Binary sketch size: 5528 bytes (of a 32256 byte maximum)

That's more than 4 Kb.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Germany
Offline Offline
Faraday Member
**
Karma: 59
Posts: 3056
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

mySerial.print(sensorValue);

Amazing how tiny the attiny is !
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18807
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

But really, floating point numbers are traditionally pretty code and computation expensive.
Logged


Denmark
Offline Offline
Edison Member
*
Karma: 35
Posts: 1073
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
« Last Edit: May 03, 2012, 07:47:21 am by Erni » Logged

Pages: [1]   Go Up
Jump to: