attiny85 with ds1820

Hi, I am trying to read a ds1820 and send it with virtualwire, I have this working with a 328 but with the attiny85, It always reads -16.19 ? I have a 4.7k resistor from 5v to data on the ds1820

any ideas? thanks

#include<stdlib.h>
#include <VirtualWire.h>
#include <OneWire.h>
  byte addr[8];
  float celsius;
OneWire ds(1);  // on pin 10
String tempstr[10];

int RF_TX_PIN = 2;
 
void setup()
{
  vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
  vw_setup(2000); // Transmission speed in bits per second.
}
 
void loop()
{
  const char *msg = "hello";
  char cc1[10];
  vw_send((uint8_t *)msg, strlen(msg));  // Send 'hello' every 400ms.
  delay(400);
  


  byte i,present =0, data[12];
  ds.reset();
  ds.select(addr);
  ds.write(0x44,1);         // start conversion, with parasite power on at the end
  delay(1500);     // maybe 750ms is enough, maybe not
  ds.reset();
  ds.select(addr);    
  ds.write(0xBE);         // Read Scratchpad
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
  }
  int16_t raw = (data[1] << 8) | data[0];
  raw = raw << 3; // 9 bit resolution default
  raw = (raw & 0xFFF0) + 12 - data[6];  
  celsius = (float)raw / 16.0; 
  
  dtostrf(celsius,5,2,cc1);

  vw_send((uint8_t *)cc1, strlen(cc1));
  vw_send((uint8_t *)"t", 1);  //send a t after the temp
  delay(1000);               // wait for a second
 
  
 
}

It may be to do with the way you're powering the sensor - the parasitic power mode seems a bit temperamental to me. You could try with external power to see whether you have more success. What voltage are you running the attiny at? The sensor and the attiny will run at a wind range of voltages, but perhaps the supply voltage will affect how reliably parasitic mode works.

hi pete,

I have tried powering the ds1820 both ways and it is the same.

I am running it off 5v.

You haven't set the device's address in addr. You either need to add code to scan for the device and set addr or use a separate I2C program to find the address and then hardcode that into your code.

Pete

hey el_supremo! i just realised that myself and came back to say :slight_smile:

i missed out

ds.search(addr);

in setup, I had it when I was using the 328 but forgot to add it to the attiny code :slight_smile:

thanks for your replies! :slight_smile: