Offline
Newbie
Karma: 0
Posts: 4
|
 |
« on: May 03, 2012, 04:33:11 am » |
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
Melbourne, Australia
Online
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #1 on: May 03, 2012, 04:49:25 am » |
Why not use hardware serial?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Online
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #2 on: May 03, 2012, 04:51:30 am » |
... compiling error ... What error? Read this before posting a programming questionPoint 6: "If you get an error, post the error (copy and paste). Not just "I got an error"."
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #3 on: May 03, 2012, 04:52:46 am » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #4 on: May 03, 2012, 04:56:41 am » |
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
Melbourne, Australia
Online
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #5 on: May 03, 2012, 05:05:46 am » |
What version of the IDE are you using? I'm getting different errors to you, so we need to work out your environment. Maybe the file is too big? The source file? All 21 lines of it?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
|
 |
« Reply #6 on: May 03, 2012, 05:08:09 am » |
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.
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #7 on: May 03, 2012, 05:17:42 am » |
when i delete mySerial.print(temp); the sketch work! What would be the problem?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Online
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #8 on: May 03, 2012, 05:33:37 am » |
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. 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: Binary sketch size: 5528 bytes (of a 32256 byte maximum) That's more than 4 Kb.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #9 on: May 03, 2012, 06:05:18 am » |
i use now serial.write instead of serial.print. But i retrieve 'øfxfx'. Could i translate that into the right data ?
|
|
|
|
|
Logged
|
|
|
|
|
Germany
Offline
Edison Member
Karma: 27
Posts: 1502
|
 |
« Reply #10 on: May 03, 2012, 06:32:37 am » |
mySerial.print(sensorValue);
Amazing how tiny the attiny is !
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Melbourne, Australia
Online
Shannon Member
Karma: 219
Posts: 13896
Lua rocks!
|
 |
« Reply #11 on: May 03, 2012, 07:03:19 am » |
It's not called the "tiny" for nothing!
But really, floating point numbers are traditionally pretty code and computation expensive.
|
|
|
|
|
Logged
|
|
|
|
|
Denmark
Offline
God Member
Karma: 19
Posts: 683
|
 |
« Reply #12 on: May 03, 2012, 07:43:01 am » |
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.htmlint 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
|
|
|
|
|
|