Go Down

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

PaulS

The square brackets define an array. The array can hold 10 elements, indexed from 0 to 9.

The statement says nothing about any pin numbers.

seanlangford


The square brackets define an array. The array can hold 10 elements, indexed from 0 to 9.

The statement says nothing about any pin numbers.


[] = array....

Sorry I'm just learning!

seanlangford

Code: [Select]
I would start at the line 2 output; the "Found 8 devices" text indicates this routine is broken. I can suggest debugging the 'find' routine, as a good place to start. (I do not see that source code.)[\code]

This is what I've been advised....!

Any ideas???

I have changed the array to [12] now aswell....

Nick Gammon


Well I'm actually registering 8 sensors now but basically I'm running the provided code by Nick Gammon that streamlines the serial print process. I've had a look at the array in the code but I still can't work out why it isn't registering the last 3 sensors....


I - perhaps foolishly - put the number 10 in my code as the size of the array. Although in my defence, I had only 5 sensors. Clearly if you have 8 working, and you add 3, you are using 11, so you are not going to fit 11 addresses into 10 array positions.

This is fundamental stuff, you might want to read up a C tutorial so you can spot an array when you see one.

Are you saying if you have 8 working, and you add a 9th, only the first 8 register? What if you remove the 9th and swap with one of the others? Are you absolutely sure the wiring for the 9th/10th/11th is correct?

Quote
I would start at the line 2 output; the "Found 8 devices" text indicates this routine is broken.


Not if there's a wiring problem it doesn't.
I don't have 11 sensors here so I can't test that one way or the other, but it seems to me the whole design idea is to run a lot of sensors over a long piece of wire. If you could only have 8 and the wire could only be a few meters long, well who would bother with it?
Please post technical questions on the forum, not by personal message. Thanks!

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

Nick Gammon

I just had a look at the code for the DallasTemperature library. I strongly recommend against using requestTemperaturesByIndex for the simple reason that it does a search of the entire bus, every time! So to get index 0 it searches the bus until it finds the first match, and then queries its temperature by address. Then for index 1 it searches the bus again, this time stopping after finding the second match, and then queries by address. So even a briefly malfunction sensor will make it disappear from the index list, giving you the reading for sensor 9 where you expect sensor 8. Plus, it would be quite slow.

What you need to do is find out the hex address of each sensor (eg. plugging one in at a time) and from then on query by address.

Please post technical questions on the forum, not by personal message. Thanks!

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

Nick Gammon

I would definitely re-read:

http://www.maxim-ic.com/app-notes/index.mvp/id/148

They seem to be saying fairly long runs should be possible. However there are quite a few caveats. In your shoes I would be doing a lot of testing. Say you have 11 devices plugged in (and assuming you have changed the array size) then try unplugging (say) the first four and see if the last 7 are detected now. If so, it is something to do with the number of them. If not, maybe there is a wiring issue for the last few.

You basically want to find if *any* 8 work, or a *particular group* work. You may also want to try decoupling capacitors (eg. a 0.1 uF capacitor between Vcc and Gnd), not data and Gnd.
Please post technical questions on the forum, not by personal message. Thanks!

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

seanlangford


I just had a look at the code for the DallasTemperature library. I strongly recommend against using requestTemperaturesByIndex for the simple reason that it does a search of the entire bus, every time! So to get index 0 it searches the bus until it finds the first match, and then queries its temperature by address. Then for index 1 it searches the bus again, this time stopping after finding the second match, and then queries by address. So even a briefly malfunction sensor will make it disappear from the index list, giving you the reading for sensor 9 where you expect sensor 8. Plus, it would be quite slow.

What you need to do is find out the hex address of each sensor (eg. plugging one in at a time) and from then on query by address.




Cheers and thanks for that again Nick.....

I am a noob at the coding and I downloaded and printed off the Arduino Language Reference manuel with all the code details.
I read through it but I find that I can learn better by trial and error.

I will definitely replace the requestTemperaturesByIndex as like you said it keeps doing the same request in the loop.

I did have a look at the array command a while ago as I thought that I could use it to array the pin selection but I found that it doesn't work like that and that I had to create an instance for each pin for each program....

Its tough but I think if I can keep it up eventually it will work how I would like it to...!

seanlangford

Quote
Are you saying if you have 8 working, and you add a 9th, only the first 8 register? What if you remove the 9th and swap with one of the others? Are you absolutely sure the wiring for the 9th/10th/11th is correct?


I just did another test.
I replaced all of the wiring that supplies the last 3 sensor (GD, DQ & VDD).
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, but change the position of the sensor ID on the bus with the index lol...

Quote
Not if there's a wiring problem it doesn't.
I don't have 11 sensors here so I can't test that one way or the other, but it seems to me the whole design idea is to run a lot of sensors over a long piece of wire. If you could only have 8 and the wire could only be a few meters long, well who would bother with it?

PeterH




I just did another test.
I replaced all of the wiring that supplies the last 3 sensor (GD, DQ & VDD).
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.


With what code? Without understanding the code, it's impossible to know what that means.
I only provide help via the forum - please do not contact me for private consultancy.

seanlangford





I just did another test.
I replaced all of the wiring that supplies the last 3 sensor (GD, DQ & VDD).
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.


With what code? Without understanding the code, it's impossible to know what that means.


You would have to follow the post then mate....
I can't write all the same stuff out again lol
If you read from the first post in the topic then you can follow whats going on....

Thanks!



PeterH

I have been following (yes, from the first post) but back then you were talking some weird stuff about sensor indexing that made no sense at all.

Are you saying you haven't changed your sketch at all since then?
I only provide help via the forum - please do not contact me for private consultancy.

seanlangford

I'm using Nicks example sketch now but I need to amend it lol...

Nick Gammon


I replaced all of the wiring that supplies the last 3 sensor (GD, DQ & VDD).


Photo please.
Please post technical questions on the forum, not by personal message. Thanks!

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

PeterH


I'm using Nicks example sketch now but I need to amend it lol...



Well, if you have a sketch that shows a problem I suggest you post the sketch that shows the problem and describe the problem it shows. Maybe then somebody will be able to advise why the problem is happening. Or, you could just leave us to guess and dig back through half a dozen pages and guess what you're talking about ...
I only provide help via the forum - please do not contact me for private consultancy.

seanlangford



Uploaded with ImageShack.us

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

// Data wire is plugged into port 10 on the Arduino
const byte ONE_WIRE_BUS = 10;
const byte TEMPERATURE_PRECISION = 10;

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

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// arrays to hold device addresses
DeviceAddress myThermometer [12];
int deviceCount;

void setup (void)
{

  // start serial port
  Serial.begin (115200);
  Serial << "Dallas Temperature IC Control Library Demo" << endl;

  // Start up the library
  sensors.begin();

  // locate devices on the bus
  Serial << "Locating devices..." << endl;
  deviceCount = sensors.getDeviceCount();

  Serial << "Found " << deviceCount << " devices." << endl;

  // report parasite power requirements
  Serial << "Parasite power is: " << (sensors.isParasitePowerMode() ? "ON" : "OFF") << endl;

  // method 1: by index

  for (int i = 0; i < deviceCount; i++)
  {
    if (sensors.getAddress(myThermometer [i], i))
    {
      Serial << "Device " << i << " Address: ";
      printAddress(myThermometer [i]);
      Serial << endl;
      sensors.setResolution(myThermometer [i], TEMPERATURE_PRECISION);
    }
    else
      Serial << "Unable to find address for Device " << i << endl;
  }  // end of for

} // end of setup

// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (uint8_t i = 0; i < 8; i++)
  {
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}  // end of printAddress

void loop(void)
{

  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  sensors.requestTemperatures();

  // now get all temperatures
  for (int i = 0; i < deviceCount; i++)
  {
    float tempC = sensors.getTempC(myThermometer [i]);
    if (tempC > -80)
    {
      Serial << "Device " << i << " Temperature: " << tempC << endl;
    }
    else
      Serial << "Unable to find temperature for Device " << i << endl;
  }  // end of for loop

  delay (1000);
}  // end of loop



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.

Go Up