Go Down

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

PaulS

Quote
The problem that I'm having is that I can only get it to show 8 sensors on the serial monitor and I need to serial print each temperature from the unique sensor ID instead of the index value to stop any misleading temperature readings if a sensor malfunctions on the bus.

What serial output does that produce? Only YOU can see that, so far.

seanlangford


Quote
The problem that I'm having is that I can only get it to show 8 sensors on the serial monitor and I need to serial print each temperature from the unique sensor ID instead of the index value to stop any misleading temperature readings if a sensor malfunctions on the bus.

What serial output does that produce? Only YOU can see that, so far.


Dallas Temperature IC Control Library Demo
Locating devices...
Found 8 devices.
Parasite power is: OFF
Device 0 Address: 28184D640300009B
Device 1 Address: 28789364030000A4
Device 2 Address: 28341E640300008B
Device 3 Address: 2892375B030000BC
Device 4 Address: 28BA515703000034
Device 5 Address: 28864C64030000F4
Device 6 Address: 28CE455B03000001
Device 7 Address: 28BEF263030000D3
Device 0 Temperature: 19.25
Device 1 Temperature: 19.25
Device 2 Temperature: 19.25
Device 3 Temperature: 19.25
Device 4 Temperature: 19.50
Device 5 Temperature: 19.50
Device 6 Temperature: 19.75
Device 7 Temperature: 19.75

PaulS

I think that your biggest clue is here:
Code: [Select]
Found 8 devices.
You obviously can't make it deal with more devices than it knows about.

Whether that value is a limit of the bus, or of the Dallas library, or a wiring issue is something you should be able to work out.

Randomly disconnect devices. If the count remains 8 until you have disconnected 4 or more tells you one thing. If disconnecting 3 makes no change, but disconnecting the 4th one does, and it does not matter which 4 you disconnect, you will have learned something.

Let us know what you learn, and perhaps we can suggest something else.

seanlangford

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


Its not a hardware issue, but here's the DallasTemperature.h that its running!

PaulS

Code: [Select]
typedef uint8_t DeviceAddress[8];
Oh, look, a clue!

seanlangford

typedef uint8_t DeviceAddress[8];

Does this mean that the device address in the dallastemperature.h is limited to [8] devices in the array?

I think it is and will change it to see what the craic is!

seanlangford

Hey I just saw that as I went through it at the same time lol....

PeterH


The problem that I'm having is that I can only get it to show 8 sensors on the serial monitor


Suggest you start with one sensor, note the serial number and add the next one. Carry on until you see the problem.

If you add a sensor and the number detected doesn't increase, which one has it missed? Is the new one, or one of the previous ones? If you disconnect one of the other sensors does the 'missing' sensor get detected OK?


I need to serial print each temperature from the unique sensor ID instead of the index value.


Yes, you do. (That isn't a problem, it's just the sensible way to read sensors on a bus.)
I only provide help via the forum - please do not contact me for private consultancy.

PeterH


Code: [Select]
typedef uint8_t DeviceAddress[8];
Oh, look, a clue!


Isn't that declaring the DeviceAddress typedef as an array of eight uint8_t?

Anyway, it's declaring a typedef for a sensor ID, not the array variable holding sensor IDs.
I only provide help via the forum - please do not contact me for private consultancy.

sync

Hummm, is breadboard needs bridge leads where "W" marks are?





Nick Gammon

Some breadboards have a break in the bottom part (where the W is). Can you confirm that the Gnd wire is continuous from the first chip to the last one? Or are the last 3 not connected?

If it passes that test, can you post what you see on the serial monitor?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon


Code: [Select]
typedef uint8_t DeviceAddress[8];
Oh, look, a clue!


Yeah I thought that too Paul, but it is 8 bytes, not 8 device addresses. After lengthy reading of the way the searching works I think that is just the last bit pattern it searched for so it can resume next time. There is nowhere in the code where it holds 8 x 8-byte addresses.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon


Hummm, is breadboard needs bridge leads where "W" marks are?


Oops, sorry sync. Didn't notice the next page of the thread. :)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon


Its not a hardware issue, but here's the DallasTemperature.h that its running!


Apart from the Gnds not being connected, lol. (maybe)
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon


I removed the first 3 hoping that it would register the last 8 but it just had a gap of 3 registering 0.00C at the begining of the serial print on the serial monitor.
I swapped each of the sensors with the 1st sensor on the bus and they work fine,


It's nothing to do with 8 sensors, I strongly guess the wiring. The last 3 never register but if he removes the first 3 he only gets 5.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up