[solved] Need help porting OneWire.h to ATtiny84

Hi,

I just registered to this forum but I already know the Arduino platform, C and some hardware stuff. I'm working on a small project where I have to read one analog sensor and a 1wire device (DS18B20). The data has to be sent using a RFM12B module. Looks like my only problem is the OneWire library…

I'm using Arduino 1.0 on OS X and have installed the latest version of the arduino-tiny library from Google Code Archive - Long-term storage for Google Code Project Hosting.

When I try to compile the code I get these errors:

Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp: In constructor 'OneWire::OneWire(uint8_t)':
Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp:105: error: 'digitalPinToBitMask' was not declared in this scope
Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp:106: error: 'digitalPinToPort' was not declared in this scope
Documents/Arduino_1.0/libraries/OneWire/OneWire.cpp:106: error: 'portInputRegister' was not declared in this scope

I'm a bit confused because all these functions are defined in Arduino_1.0/hardware/tiny/cores/tiny/pins_arduino.h. Actually these are not functions but preprocessor macros but why doesn't this work?

I'm planning to make some custom pcb's and don't like the idea to go to a ATmega only because of this 1wire library… Any ideas? I could provide some demo-code if needed.

Thanks!

Which OneWire library are you using?

I got version 2.1 from here:
http://www.pjrc.com/teensy/td_libs_OneWire.html

Good idea, I wasn't looking for another library (until now…).

I suggest using Paul Stoffregen's library. You can get it working by...

• Locate and open OneWire.h

• Locate this section of code towards the top...

#if ARDUINO >= 100
#include "Arduino.h"       // for delayMicroseconds, digitalPinToBitMask, etc
#else
#include "WProgram.h"      // for delayMicroseconds
#include "pins_arduino.h"  // for digitalPinToBitMask, etc
#endif

• Change it to this...

#if ARDUINO >= 100
#include "Arduino.h"       // for delayMicroseconds, digitalPinToBitMask, etc
#include "pins_arduino.h"  // for digitalPinToBitMask, etc
#else
#include "WProgram.h"      // for delayMicroseconds
#include "pins_arduino.h"  // for digitalPinToBitMask, etc
#endif

• Save and close OneWire.h

• It is not necessary to restart the Arduino IDE

To be quite clear about the matter: This is not a problem with the OneWire library but rather a deficiency in the Tiny Core. Essentially, Paul has made OneWire compatible with Arduino 1.0 while the Tiny Core is only partial compatible.

Works great, thank you!

Next problem already arrived…

hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o:(.init9+0x0): relocation truncated to fit: R_AVR_13_PCREL against symbol `main' defined in .text.main section in core.a(main.cpp.o)
hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr25/crttn84.o:(.init9+0x2): relocation truncated to fit: R_AVR_13_PCREL against symbol `exit' defined in .fini9 section in hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/avr25/libgcc.a(_exit.o)

The problem goes away when I remove all references to OneWire OR rfm12b. Looks like some kind of resource problem. It's not the sketch-size, it has to be something else… I'll try to restructure my code.

You are welcome.

R_AVR_13_PCREL ... It's not the sketch-size...

Actually, in a complicated way, the symptom is triggered by sketch size. I can also help with that problem...

I actually did hope for one more reply from you :slight_smile:

It's not the first time I run into a problem with the Arduino 1.0 toolchain. It's a 1.0 - there have to be problems XD

Thanks for the links, google actually wasn't really useful on this problem. Too bad I can't use your install instructions as I'm running Arduino on OS X, not Windows. WinAVR sounds a little bit like a Windows application…

I just found a nice OS X package with all the required files. Here's how to install it:

cd /Applications/Arduino.app/Contents/Resources/Java/hardware/tools
mv avr avr-old
ln -s /usr/local/CrossPack-AVR avr

For me it works perfect (until now…)

Done compiling.
Binary sketch size: 4966 bytes (of a 8192 byte maximum)

tht:
I actually did hope for one more reply from you :slight_smile:

This will probably be the last for a while. It's about :sleeping:...

Thanks for the links, google actually wasn't really useful on this problem.

You aren't kidding!

Too bad I can't use your install instructions as I'm running Arduino on OS X, not Windows.

Sorry about that. I missed the "OS X" in your original post. Yes, the instructions are for Windows.

I just found a nice OS X package with all the required files. Here's how to install it:

Thank you for posting the follow-up with instructions.