Go Down

Topic: DS18B20 & onewire.h (Read 16 times) previous topic - next topic

seanlangford

Please can anyone help me with my project because its driving me nuts.

I've created a program that uses pins 2 - 12 with a OneWire.h & DallasTemperature.h for each pin to read the temperature of the x11 DS18B20's where I can bus more on each pin if needed.

The problem that I have is that it doesn't read the temperature from pin 10 upwards.
I swapped the wires around from pin 2 to pin 10, 11 & 12 consecutively to see if I had a faulty Arduino and sensors which wasn't the case.

I've had a look at the program OneWire.h and it says that pin 10 is used in that program and I think that this maybe the problem but I don't know how to debug it.

I assume that I write a program that uses #include to reference the pins under the onewire protocol that keeps the RAM usage down when compiling....

I'm using OneWire 2.1 that I downloaded from
http://www.pjrc.com/teensy/td_libs_OneWire.html
and the DallasTemperature.h which is from T L C 3.6.0

I've tried to use the upgraded Arduino software but I got that many bugs come up I reverted back to the old version lol.

dxw00d

Post what you have so far. It's easier help if we can see the code.

technobabologist

umm, pins 10,11,12,13 are used for the hardware SPI, maybe that's got something to do with it, also pin 10 is often user for chip select, do you have any other devices connected

seanlangford

No I don't have any other devices connected yet but I will add a temp/humidity sensor at a later date. I will test the sensors and program on my other Arduino just incase its the hardware SPI. I do think its something to do with the onewire.h because it uses pin 10 in the instance (But I think I've been looking at the example program so I'm not sure as I just copied the OneWire2 folder into the Library folder of the compiler) and then I'm using pin 10 from my setup program.


Code: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into these pins on the Arduino
#define A_TEMP 2
#define B_TEMP 3
#define C_TEMP 4
#define D_TEMP 5
#define E_TEMP 6
#define F_TEMP 7
#define G_TEMP 8
#define H_TEMP 9
#define I_TEMP 11
#define J_TEMP 12
#define K_TEMP 13

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire1(A_TEMP);
OneWire onewire2(B_TEMP);
OneWire onewire3(C_TEMP);
OneWire onewire4(D_TEMP);
OneWire onewire5(E_TEMP);
OneWire onewire6(F_TEMP);
OneWire onewire7(G_TEMP);
OneWire onewire8(H_TEMP);
OneWire onewire9(I_TEMP);
OneWire onewire10(J_TEMP);
OneWire onewire11(K_TEMP);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors1(&oneWire1);
DallasTemperature sensors2(&onewire2);
DallasTemperature sensors3(&onewire3);
DallasTemperature sensors4(&onewire4);
DallasTemperature sensors5(&onewire5);
DallasTemperature sensors6(&onewire6);
DallasTemperature sensors7(&onewire7);
DallasTemperature sensors8(&onewire8);
DallasTemperature sensors9(&onewire9);
DallasTemperature sensors10(&onewire10);
DallasTemperature sensors11(&onewire11);

void setup(void)
{   
// start serial port
Serial.begin(9600);
Serial.println("Sean's Program");

// Start up the library
sensors1.begin();
sensors2.begin();
sensors3.begin();
sensors4.begin();
sensors5.begin();
sensors6.begin();
sensors7.begin();
sensors8.begin();
sensors9.begin();
sensors10.begin();
sensors11.begin();
}

void loop(void)
{   
// call sensors.requestTemperatures() to issue a global temperature 
// request to all devices on the bus
Serial.println("Requesting temperatures...");
sensors1.requestTemperatures(); // Send the command to get temperatures from sensor1
sensors2.requestTemperatures();
sensors3.requestTemperatures();
sensors4.requestTemperatures();
sensors5.requestTemperatures();
sensors6.requestTemperatures();
sensors7.requestTemperatures();
sensors8.requestTemperatures();
sensors9.requestTemperatures();
sensors10.requestTemperatures();
sensors11.requestTemperatures();
Serial.println(""); // Creates a line of space

Serial.print("A = ");
Serial.println(sensors1.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print("B = ");
Serial.println(sensors2.getTempCByIndex(0));
Serial.print(" C = ");
Serial.println(sensors3.getTempCByIndex(0));
Serial.print("D = ");
Serial.println(sensors4.getTempCByIndex(0));
Serial.print("E = ");
Serial.println(sensors5.getTempCByIndex(0));
Serial.print("F = ");
Serial.println(sensors6.getTempCByIndex(0));
Serial.print("G = ");
Serial.println(sensors7.getTempCByIndex(0));
Serial.print("H = ");
Serial.println(sensors8.getTempCByIndex(0));
Serial.print("I = ");
Serial.println(sensors9.getTempCByIndex(0));
Serial.print("J = ");
Serial.println(sensors10.getTempCByIndex(0));
Serial.print("K = ");
Serial.println(sensors11.getTempCByIndex(0));

Serial.println(""); //creates a line of space
Serial.println(""); //creates a line of space
}



I downloaded the DallasTemperature.h & OneWire.h from this site
http://milesburton.com/Dallas_Temperature_Control_Library

OneWire2 & DallasTemperature 3.6.0
I renamed OneWire2 to OneWire and if you have a look at my code you will notice that  I'm not using pin 10.
I did change the code to use pin10 and it didn't work (So I changed it back)but my program either uses a DS18B20 on pin 9 OR a RHT-22 Humidity/Temperature sensor on pin 9 and pin 10. In this instance I only have the DS18B20 so pin10 isn't used.
I'm hoping that the program will either pick up the DS18B20 or the RHT-22 without me having to reprogram it each time.

If you need any more clarification then let me know!

Is there also a way of naming each index instead of having them numbered as 0,1,2,3,4(etc) where the likelyhood of more than one DS18B20 would be used on the bus?

Would you help me through guidance with adding different kind of sensors to my arduino and inserting the various .h programs for the pins?

strykeroz

Hi,

My understanding of the Dallas 1-wire comms bus is that by name and nature you should be able to hook all your sensors up on just one Arduino pin.  Each of the temperature sensors has its own unique factory-provided ID, akin to a mac address (this is my analogy, so don't shoot me if that's off the mark).

For this reason I wonder if you're not just running out of memory on the Arduino initiating so many instances of the 1-wire protocol.

From the example provided in the link you gave above, it appears a single instance of the Dallas temperature control library is all you need too...
Code: [Select]
void loop(void) {
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.print("Temperature for Device 1 is: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire

}
So the getTempCByIndex() method just needs to be called for each of the sensors in turn.

Not only will this simplify your code a lot, but you'll be only using one Arduino pin, and it might just free up the RAM enough so your code executes (at least that's my theory as to what's going wrong).

Hope this helps.  I have my first Dallas temp sensors just arrived so about to embark on a similar journey  :)

Cheers !
Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

dc42

I was also about to suggest wiring up all the sensors to a single pin and using a single instance of OneWire and DallasTemperature.

Pin 13 of the Uno won't work with OneWire because of the LED attached to that pin.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

seanlangford

If its a case of RAM then surely the same amount of RAM is used to register 11 sensors on one pin as it is to register 11 sensors on 11 pins (but maybe with a little bit more because of identifying the pin). I do have a 750 ms delay for each of the pins because of the bit rate but I can sort that out quite easily in the OneWire.h program.
If I do bus them then I would like to be able to bus them where each sensor comes up in the index as a location name rather than an index number.

What I will do is try the same program with the same setup on another Arduino and then bring the temperature reading to one decimal place and see what that does.

If I am limited by the RAM with using 11 pins for each sensor then I'm going to be really stuck as I will be using the 6 analogue input pins also for other things in this project.

I will have to see how the AVR scratchpad works and maybe see if thats the problem.

dc42

#7
Jan 21, 2012, 08:08 pm Last Edit: Jan 21, 2012, 08:10 pm by dc42 Reason: 1
1. What hardware are you using, an Arduino or a Teensy?

2. What value pullup resistors are you using?

3. Are you powering the Vdd pins of the DS18B20s from +5v or are you trying to use parasite power?

I doubt that you are running out of RAM, the per-instance memory requirements for OneWire and DallasTemperature appear to be modest.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

seanlangford

I think that aswell DC42....
The sensors are only sending one value thats between 0 and 1024 or 0 and 1023 with the pin location in the AVR and an input reference.
The program I'm using only comes to 7000 bits and there's 30000 bits left. I'm not sure how big the scratchpad is (if that is even the place where the RAM is that receives the information from the sensors used by the program)...

I'm using a DFRduino Romeo thats used for robotics. I'm practicing on this one incase I make a mistake and its cheaper to replace than my other one...
I'm using 4.7k resistors and I'm not using parasitic mode because its disadvantageous for my application!

tochinet

I didn't use OneWire lately, but I remember that the OneWire library I used is using C++ objects for each pin. So if you create 10 objects, it surely will take more RAM than if you create one (with separation of the sensors using the address code).

strykeroz


If its a case of RAM then surely the same amount of RAM is used to register 11 sensors on one pin as it is to register 11 sensors on 11 pins (but maybe with a little bit more because of identifying the pin).
Normally, yes.  But not the way it's been done in the code above.  You don't need to register each sensor with 1-wire, but each bus.  The DallasTemperature class searches for and 'registers' each sensor on the bus (which in our case is an Arduino pin).

The way this project is setup with one sensor per wire you'll be instantiating whatever is required for the OneWire and DallasTemperature class in memory multiple times, therefore whatever the overhead of the class has in RAM will be multiplied accordingly.  I don't know how much memory that will use, but it's more than it needs to and we don't have that much to work with on the Arduino.  I've come unstuck working with the String library for example in a very short number of lines, and I see others who have had issues instantiating just a few libraries.

Do you see that in the DallasTemperature example there is a comment in the loop() function to call that reporting code multiple times?  I think that if you put all your sensors on the one pin, your code would become something like (untested of course):
Code: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 10 on the Arduino
#define TEMPWIRE 10 // just one wire

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire1(TEMPWIRE); // just one instance

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors1(&oneWire1); // just one instance

void setup(void) {   
// start serial port
Serial.begin(9600);
Serial.println("Sean's Program");

// Start up comms with our Dallas one wire temperature sensors on pin 10
sensors1.begin();
}

void loop(void) {   
// call sensors.requestTemperatures() to issue a global temperature 
// request to all devices on the bus
Serial.println("Requesting temperatures...");
sensors1.requestTemperatures(); // Send the command to get temperatures from sensor1 ALL OF THEM

Serial.println(""); // Creates a line of space

// Now we run through every temperature sensor found on the 1wire bus on pin 10
Serial.print("A = ");
Serial.println(sensors1.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print("B = ");
Serial.println(sensors1.getTempCByIndex(1));
Serial.print(" C = ");
Serial.println(sensors1.getTempCByIndex(2));
Serial.print("D = ");
Serial.println(sensors1.getTempCByIndex(3));
Serial.print("E = ");
Serial.println(sensors1.getTempCByIndex(4));
Serial.print("F = ");
Serial.println(sensors1.getTempCByIndex(5));
Serial.print("G = ");
Serial.println(sensors1.getTempCByIndex(6));
Serial.print("H = ");
Serial.println(sensors1.getTempCByIndex(7));
Serial.print("I = ");
Serial.println(sensors1.getTempCByIndex(8));
Serial.print("J = ");
Serial.println(sensors1.getTempCByIndex(9));
Serial.print("K = ");
Serial.println(sensors1.getTempCByIndex(10));

Serial.println(""); //creates a line of space
Serial.println(""); //creates a line of space
}


HTH, Geoff
"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

dc42

By my calculation, each instance of OneWire uses 14 bytes of RAM and each instance of DallasTemperature uses 28 bytes. That's 42 bytes per sensor using Seans's program, so that's 154 bytes for 11 instances, plus about 100 bytes in string literals. Rather excessive perhaps, but not enough to account for the problem, assuming Sean has posted the entire sketch and there isn't something else using up the remaining RAM.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

seanlangford

Strykeroz...

Mate thanks... I can't believe that its just that simple to name each index reference on the serial print and something I missed.

I thought that it would be easier to name each pin and do it that way. I can now see what I have to do to bus the sensors easily too...
I know that in the DallasTemperature.h program there is a lot of stuff in there that I don't really need apart from registering that it is a DS18B20 and the temperature Celcius/Farenheit calculation.

I wanted to use the OneWire.h program as a bus because you don't have to put all of the serial numbers of the DS18B20's manually in the program. I just need to plug and play as they say!

I've learnt what can max out the RAM on the Arduino now so I can hopefully guestimate the other programs to finish the project.

DC42

So how many bytes can the AVR chip cope with?
I should do some research as its a really important thing to know....

Here's the DallasTemperature.h and the OneWire.h programs that I'm using.

Code: [Select]
#ifndef DallasTemperature_h
#define DallasTemperature_h

// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.

// set to true to include code for new and delete operators
#ifndef REQUIRESNEW
#define REQUIRESNEW false
#endif

// set to true to include code implementing alarm search functions
#ifndef REQUIRESALARMS
#define REQUIRESALARMS true
#endif

#include <inttypes.h>
#include <OneWire.h>

// Model IDs
#define DS18S20MODEL 0x10
#define DS18B20MODEL 0x28
#define DS1822MODEL  0x22

// OneWire commands
#define STARTCONVO      0x44  // Tells device to take a temperature reading and put it on the scratchpad
#define COPYSCRATCH     0x48  // Copy EEPROM
#define READSCRATCH     0xBE  // Read EEPROM
#define WRITESCRATCH    0x4E  // Write to EEPROM
#define RECALLSCRATCH   0xB8  // Reload from last known
#define READPOWERSUPPLY 0xB4  // Determine if device needs parasite power
#define ALARMSEARCH     0xEC  // Query bus for devices with an alarm condition

// Scratchpad locations
#define TEMP_LSB        0
#define TEMP_MSB        1
#define HIGH_ALARM_TEMP 2
#define LOW_ALARM_TEMP  3
#define CONFIGURATION   4
#define INTERNAL_BYTE   5
#define COUNT_REMAIN    6
#define COUNT_PER_C     7
#define SCRATCHPAD_CRC  8

// Device resolution
#define TEMP_9_BIT  0x1F //  9 bit
#define TEMP_10_BIT 0x3F // 10 bit
#define TEMP_11_BIT 0x5F // 11 bit
#define TEMP_12_BIT 0x7F // 12 bit

// Error Codes
#define DEVICE_DISCONNECTED -127

typedef uint8_t DeviceAddress[8];

class DallasTemperature
{
  public:

  DallasTemperature(OneWire*);

  // initalize bus
  void begin(void);

  // returns the number of devices found on the bus
  uint8_t getDeviceCount(void);
 
  // returns true if address is valid
  bool validAddress(uint8_t*);

  // finds an address at a given index on the bus
  bool getAddress(uint8_t*, const uint8_t);
 
  // attempt to determine if the device at the given address is connected to the bus
  bool isConnected(uint8_t*);

  // attempt to determine if the device at the given address is connected to the bus
  // also allows for updating the read scratchpad
  bool isConnected(uint8_t*, uint8_t*);

  // read device's scratchpad
  void readScratchPad(uint8_t*, uint8_t*);

  // write device's scratchpad
  void writeScratchPad(uint8_t*, const uint8_t*);

  // read device's power requirements
  bool readPowerSupply(uint8_t*);

  // returns the current resolution, 9-12
  uint8_t getResolution(uint8_t*);

  // set resolution of a device to 9, 10, 11, or 12 bits
  void setResolution(uint8_t*, uint8_t);

  // sends command for all devices on the bus to perform a temperature conversion
  void requestTemperatures(void);
   
  // sends command for one device to perform a temperature conversion by address
  void requestTemperaturesByAddress(uint8_t*);

  // sends command for one device to perform a temperature conversion by index
  void requestTemperaturesByIndex(uint8_t);

  // returns temperature in degrees C
  float getTempC(uint8_t*);

  // returns temperature in degrees F
  float getTempF(uint8_t*);

  // Get temperature for device index (slow)
  float getTempCByIndex(uint8_t);
 
  // Get temperature for device index (slow)
  float getTempFByIndex(uint8_t);
 
  // returns true if the bus requires parasite power
  bool isParasitePowerMode(void);

  #if REQUIRESALARMS
 
  typedef void AlarmHandler(uint8_t*);

  // sets the high alarm temperature for a device
  // accepts a char.  valid range is -55C - 125C
  void setHighAlarmTemp(uint8_t*, const char);

  // sets the low alarm temperature for a device
  // accepts a char.  valid range is -55C - 125C
  void setLowAlarmTemp(uint8_t*, const char);

  // returns a signed char with the current high alarm temperature for a device
  // in the range -55C - 125C
  char getHighAlarmTemp(uint8_t*);

  // returns a signed char with the current low alarm temperature for a device
  // in the range -55C - 125C
  char getLowAlarmTemp(uint8_t*);
 
  // resets internal variables used for the alarm search
  void resetAlarmSearch(void);

  // search the wire for devices with active alarms
  bool alarmSearch(uint8_t*);

  // returns true if ia specific device has an alarm
  bool hasAlarm(uint8_t*);

  // returns true if any device is reporting an alarm on the bus
  bool hasAlarm(void);

  // runs the alarm handler for all devices returned by alarmSearch()
  void processAlarms(void);
 
  // sets the alarm handler
  void setAlarmHandler(AlarmHandler *);
 
  // The default alarm handler
  static void defaultAlarmHandler(uint8_t*);

  #endif

  // convert from celcius to farenheit
  static float toFahrenheit(const float);

  // convert from farenheit to celsius
  static float toCelsius(const float);

  #if REQUIRESNEW

  // initalize memory area
  void* operator new (unsigned int);

  // delete memory reference
  void operator delete(void*);
 
  #endif

  private:
  typedef uint8_t ScratchPad[9];
 
  // parasite power on or off
  bool parasite;

  // used to determine the delay amount needed to allow for the
  // temperature conversion to take place
  int conversionDelay;

  // count of devices on the bus
  uint8_t devices;
 
  // Take a pointer to one wire instance
  OneWire* _wire;

  // reads scratchpad and returns the temperature in degrees C
  float calculateTemperature(uint8_t*, uint8_t*);
 
  #if REQUIRESALARMS

  // required for alarmSearch
  uint8_t alarmSearchAddress[8];
  char alarmSearchJunction;
  uint8_t alarmSearchExhausted;

  // the alarm handler function pointer
  AlarmHandler *_AlarmHandler;

  #endif
 
};
#endif


And the OneWire(2.1).h as follows......

seanlangford

Code: [Select]
#ifndef OneWire_h
#define OneWire_h

#include <inttypes.h>

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

// You can exclude certain features from OneWire.  In theory, this
// might save some space.  In practice, the compiler automatically
// removes unused code (technically, the linker, using -fdata-sections
// and -ffunction-sections when compiling, and Wl,--gc-sections
// when linking), so most of these will not result in any code size
// reduction.  Well, unless you try to use the missing features
// and redesign your program to not need them!  ONEWIRE_CRC8_TABLE
// is the exception, because it selects a fast but large algorithm
// or a small but slow algorithm.

// you can exclude onewire_search by defining that to 0
#ifndef ONEWIRE_SEARCH
#define ONEWIRE_SEARCH 1
#endif

// You can exclude CRC checks altogether by defining this to 0
#ifndef ONEWIRE_CRC
#define ONEWIRE_CRC 1
#endif

// Select the table-lookup method of computing the 8-bit CRC
// by setting this to 1.  The lookup table enlarges code size by
// about 250 bytes.  It does NOT consume RAM (but did in very
// old versions of OneWire).  If you disable this, a slower
// but very compact algorithm is used.
#ifndef ONEWIRE_CRC8_TABLE
#define ONEWIRE_CRC8_TABLE 1
#endif

// You can allow 16-bit CRC checks by defining this to 1
// (Note that ONEWIRE_CRC must also be 1.)
#ifndef ONEWIRE_CRC16
#define ONEWIRE_CRC16 1
#endif

#define FALSE 0
#define TRUE  1

// Platform specific I/O definitions

#if defined(__AVR__)
#define PIN_TO_BASEREG(pin)             (portInputRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint8_t
#define IO_REG_ASM asm("r30")
#define DIRECT_READ(base, mask)         (((*(base)) & (mask)) ? 1 : 0)
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+1)) &= ~(mask))
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) |= (mask))
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+2)) &= ~(mask))
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+2)) |= (mask))

#elif defined(__PIC32MX__)
#include <plib.h>  // is this necessary?
#define PIN_TO_BASEREG(pin)             (portModeRegister(digitalPinToPort(pin)))
#define PIN_TO_BITMASK(pin)             (digitalPinToBitMask(pin))
#define IO_REG_TYPE uint32_t
#define IO_REG_ASM
#define DIRECT_READ(base, mask)         (((*(base+4)) & (mask)) ? 1 : 0)  //PORTX + 0x10
#define DIRECT_MODE_INPUT(base, mask)   ((*(base+2)) = (mask))            //TRISXSET + 0x08
#define DIRECT_MODE_OUTPUT(base, mask)  ((*(base+1)) = (mask))            //TRISXCLR + 0x04
#define DIRECT_WRITE_LOW(base, mask)    ((*(base+8+1)) = (mask))          //LATXCLR  + 0x24
#define DIRECT_WRITE_HIGH(base, mask)   ((*(base+8+2)) = (mask))          //LATXSET + 0x28

#else
#error "Please define I/O register types here"
#endif


class OneWire
{
  private:
    IO_REG_TYPE bitmask;
    volatile IO_REG_TYPE *baseReg;

#if ONEWIRE_SEARCH
    // global search state
    unsigned char ROM_NO[8];
    uint8_t LastDiscrepancy;
    uint8_t LastFamilyDiscrepancy;
    uint8_t LastDeviceFlag;
#endif

  public:
    OneWire( uint8_t pin);

    // Perform a 1-Wire reset cycle. Returns 1 if a device responds
    // with a presence pulse.  Returns 0 if there is no device or the
    // bus is shorted or otherwise held low for more than 250uS
    uint8_t reset(void);

    // Issue a 1-Wire rom select command, you do the reset first.
    void select( uint8_t rom[8]);

    // Issue a 1-Wire rom skip command, to address all on bus.
    void skip(void);

    // Write a byte. If 'power' is one then the wire is held high at
    // the end for parasitically powered devices. You are responsible
    // for eventually depowering it by calling depower() or doing
    // another read or write.
    void write(uint8_t v, uint8_t power = 0);

    void write_bytes(const uint8_t *buf, uint16_t count, bool power = 0);

    // Read a byte.
    uint8_t read(void);

    void read_bytes(uint8_t *buf, uint16_t count);

    // Write a bit. The bus is always left powered at the end, see
    // note in write() about that.
    void write_bit(uint8_t v);

    // Read a bit.
    uint8_t read_bit(void);

    // Stop forcing power onto the bus. You only need to do this if
    // you used the 'power' flag to write() or used a write_bit() call
    // and aren't about to do another read or write. You would rather
    // not leave this powered if you don't have to, just in case
    // someone shorts your bus.
    void depower(void);

#if ONEWIRE_SEARCH
    // Clear the search state so that if will start from the beginning again.
    void reset_search();

    // Look for the next device. Returns 1 if a new address has been
    // returned. A zero might mean that the bus is shorted, there are
    // no devices, or you have already retrieved all of them.  It
    // might be a good idea to check the CRC to make sure you didn't
    // get garbage.  The order is deterministic. You will always get
    // the same devices in the same order.
    uint8_t search(uint8_t *newAddr);
#endif

#if ONEWIRE_CRC
    // Compute a Dallas Semiconductor 8 bit CRC, these are used in the
    // ROM and scratchpad registers.
    static uint8_t crc8( uint8_t *addr, uint8_t len);

#if ONEWIRE_CRC16
    // Compute the 1-Wire CRC16 and compare it against the received CRC.
    // Example usage (reading a DS2408):
    //    // Put everything in a buffer so we can compute the CRC easily.
    //    uint8_t buf[13];
    //    buf[0] = 0xF0;    // Read PIO Registers
    //    buf[1] = 0x88;    // LSB address
    //    buf[2] = 0x00;    // MSB address
    //    WriteBytes(net, buf, 3);    // Write 3 cmd bytes
    //    ReadBytes(net, buf+3, 10);  // Read 6 data bytes, 2 0xFF, 2 CRC16
    //    if (!CheckCRC16(buf, 11, &buf[11])) {
    //        // Handle error.
    //    }     
    //         
    // @param input - Array of bytes to checksum.
    // @param len - How many bytes to use.
    // @param inverted_crc - The two CRC16 bytes in the received data.
    //                       This should just point into the received data,
    //                       *not* at a 16-bit integer.
    // @return True, iff the CRC matches.
    static bool check_crc16(uint8_t* input, uint16_t len, uint8_t* inverted_crc);

    // Compute a Dallas Semiconductor 16 bit CRC.  This is required to check
    // the integrity of data received from many 1-Wire devices.  Note that the
    // CRC computed here is *not* what you'll get from the 1-Wire network,
    // for two reasons:
    //   1) The CRC is transmitted bitwise inverted.
    //   2) Depending on the endian-ness of your processor, the binary
    //      representation of the two-byte return value may have a different
    //      byte order than the two bytes you get from 1-Wire.
    // @param input - Array of bytes to checksum.
    // @param len - How many bytes to use.
    // @return The CRC16, as defined by Dallas Semiconductor.
    static uint16_t crc16(uint8_t* input, uint16_t len);
#endif
#endif
};

#endif


I really should go through these and try and understand what they're doing....!

Nick Gammon


Would you help me through guidance with adding different kind of sensors to my arduino and inserting the various .h programs for the pins?


Look, I don't wanted to dampen your enthusiasm, but this is completely the wrong way of using the 1-wire system. It is designed for, well, one wire. Not 10 wires.

Before we work out what is wrong with pins 10 to 13, why not use it the way it was designed to be used? You drop multiple sensors of a pair of wires: the "active" wire and ground.

You work out, once off, the serial number of each device, and then get the temperature from that as required. Or, you get the program to scan for active devices, and "discover" them. That's in the 1-wire code.

Quote
The program I'm using only comes to 7000 bits and there's 30000 bits left. I'm not sure how big the scratchpad is (if that is even the place where the RAM is that receives the information from the sensors used by the program)...


What are you referring to here? Bits? Bytes? What scratchpad? The processor's RAM?
http://www.gammon.com.au/electronics

Go Up