Using a OneWire device with a ATtiny85

So I have a ATtiny85 running my sketch which currently just displays data on a LCD and I wanted to see if I can get my OneWire DS18B20 temperature sensor to show the current temp. I have this sketch running on my Uno (and other devices) and so I changed the IO pin config to match with how I've wired the ATtiny85 (using pin0 for OneWire) and uploaded it. The LCD works fine but it doesn't pick up the data from the DS18B20.

I've read online that it might be because the ATtiny85 cannot keep up with the OneWire device and that I will need to program the ATtiny85 to have a clock speed of 16MHz (it currently has a clock speed of 8MHz using the internal oscillator). To do this, it looks like I have to set a fuse (which is something I've only read about up until now).

Firstly, does it sound like I'm looking to do this for the right reason... or could it be something else? And secondly, would it be easier to use an external crystal instead (running at 20MHz)? I know this would also involve setting fuses, but I'm just curious as to how best to approach this problem.

You have an error somewhere… Attached is an unusual sketch, drives a Bluetooth device from an ATtiny 85 @ 8 MHz Int RC oscillator and DHT22 / Bluetoothcombination
The attached version of the datasheet states that the DHT22 uses a DS18B20 as the temp sensor This si why I posted the code to begin with… An example of a DS18B20 on a Tiny… and the library that supports it…
The lib is in the same folder because I had a conflict with the Adafruit library… I used Rob Tillaarts very fine library available from the playground and an older version at that. The link is to the newest version.
There are better versions for the searching… But I know this works with a DHT22, A Tiny85 an HC05/06 BT pair to a Mega2560.
Just make a folder in the sketch folder, copy the contents of the attached file to the folder, compile and load it… to an '85… Works very well @ 3V3… did have more errors @ 5V though… 3V3 was fine W/me as it was to be used W a 2032 coin cell reporting every 10 minutes…
I had this one on my desk working for about 4 months…
Because I left out the error checking it will put out bad data once in a while… Really Obviously bad data. For program size considerations I decided it was better to eliminate anything that was more than 2 points different in the receiver code than it was worth to include the error checking… as it was connected to a Mega 2560… Just checked it again and it’s still working quite well on the original breadboard…
Compiled with ERW 1.05 r2 IDE

Binary sketch size: 5,340 bytes (of a 8,192 byte maximum)

Estimated used SRAM memory: 184 bytes
Hint: You can set the maximum SRAM memory of your board directly in the boards.txt file



ATtiny_DHT22_BT_2.rar (2.8 KB)

DHT22.pdf (897 KB)

Hey, thanks for that! I'll try getting it programmed to an ATtiny85 tonight after work. I think you're right about the error as I was suspicious that the chip was that limited (but I've never used one so I didn't really know).

I'm starting to wonder if I've caused some errors with library changes I've used with a previous (3rd party) arduino. I think I'll also try a fresh arduino app install today on my mac.

So after a bit of debugging it turns out that it’s not finding the device as it return from the loop in this (pretty standard I think) search for the one wire device:

#include <OneWire.h>

OneWire ds(1);

void setup(void)
  // ...

void loop()
  int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];

  if ( ! // is always false when running on ATtiny85

  // ...

With a fresh install of Arduino 1.0.5 (and the OneWire library) I’ve tried running it at 3.3v and 5v and I’ve also tried running it at 5v with the sensor in parasitic mode, however they all produce the same results. It’s weird how the exact same setup works on my uno and other devices though.

I’ve also tried using all pins available for the OneWire input which also didn’t help.

I have used the latest version from the playground

I have the DS18B20 connected to pin 3 on the ATtiny85, and a 4.7kohm pullup resistor

This is the output

ROM = 28 B0 CE AF 2 0 0 E5
  Chip = DS18B20
  Data = 1 2E 1 4B 46 7F FF 2 10 38  CRC=38
  Temperature = 18.87 Celsius, 65.97 Fahrenheit
No more addresses.

Edit: I used the DS18x20_Temperature sketch from the examples that comes width the library

Yea I'm using the same OneWire library version as you. Are you programming your ATtiny85 using the Arduino as your in-system programmer?

Yes I am using an Arduino as programmer, with TinyISP

It makes debugging very easy

And I am using this core

Ah I've not tried that yet. I've been using the Arduino as ISP sketch. I'll try it now.

So I built it with the latest version of and still no joy! :( The sketch still builds and runs, it just doesn't find any OneWire device.

That is strange !

I don't know if it matters but I run the ATtiny85 @ 8MHz.

This is how I define the pin connected to the sensor

OneWire  ds(3);  // on pin PB3 (a 4.7K resistor is necessary)

Same, I've been selecting Tools > Board > ATtiny85 @ 8 MHz. Obviously I have Tools > Programmer > Arduino as ISP and the serial port setup also.

I read that you need to then Tools > Burn Bootloader and then upload the script by going File > Upload Using Programmer. Everytime I upload the sketch I know it's working as I can change the LCD values and they appear, but like I said previously the OneWire device is never found.

I also know the OneWire device isn't faulty (and that the sketch should work) as I have all this running on an Uno fine.

Erni: This is how I define the pin connected to the sensor

OneWire  ds(3);  // on pin PB3 (a 4.7K resistor is necessary)

I'm doing the same, and I have the 4.7k resistor going from +5v to the input pin defined here.

Well, I've solved this one. Sort of...

I've been using the mac version of Arduino so I thought I'd give it a go on Windows (fresh install) and it worked first time without any changes to the sketch or process I was doing when building. So, does anyone know what's different might be between the two versions? Anyone else had this working on Mac?