DS18B20 "No more adresses" sketch issue

Hi all,

I’m mounting a system which, upon the pressure of a button, senses and stores the temperature, takes 2 different pictures (with 2 different cameras), and stores everything on a SD card.

Everything works fine, but… Something very weird is happening with the temperature sensor, which is a DS18B20. The message “No more adresses” pops up on all even clicks! So I click once for the first measurement, everything runs fine. Then, for the second measurement, everything runs fine except the temperature sensor which give me the “No more adresses” error. The 3rd time, it will work again, but the 4th no, etc.

As an example, this is the terminal output for 4 consecutive clicks (and it consistently follows that pattern):

-------------------------------------------------------------------
Measurement started for following cell:
Set: 2  Cell: 2

CSV File created.
Sky capture Done! Image saved in: /261016/Sky0202.jpg
Pyranometer capture Done! Image saved in: /261016/Pyr0202.jpg
Logging to: /261016/02021531.CSV

ROM = 28 FF 23 55 80 16 4 E2
Chip = DS18B20
Data = 1 80 1 4B 46 7F FF C 10 67  CRC=67
Temperature = 24.00 Celsius, 75.20 Fahrenheit

Temperature,date,time,picture_sky,picture_pyranometer
24.00, 26/10/2016, 15:31:31, /261016/Sky0202.jpg, /261016/Pyr0202.jpg

-------------------------------------------------------------------
Measurement started for following cell:
Set: 2  Cell: 3

CSV File created.
Sky capture Done! Image saved in: /261016/Sky0302.jpg
Pyranometer capture Done! Image saved in: /261016/Pyr0302.jpg
Logging to: /261016/03021531.CSV

Temperature,date,time,picture_sky,picture_pyranometer
No more addresses.

-------------------------------------------------------------------
Measurement started for following cell:
Set: 2  Cell: 4

CSV File created.
Sky capture Done! Image saved in: /261016/Sky0402.jpg
Pyranometer capture Done! Image saved in: /261016/Pyr0402.jpg
Logging to: /261016/04021531.CSV


ROM = 28 FF 23 55 80 16 4 E2
Chip = DS18B20
Data = 1 7C 1 4B 46 7F FF C 10 7F  CRC=7F
Temperature = 23.75 Celsius, 74.75 Fahrenheit

Temperature,date,time,picture_sky,picture_pyranometer
23.75, 26/10/2016, 15:31:51, /261016/Sky0402.jpg, /261016/Pyr0402.jpg

-------------------------------------------------------------------
Measurement started for following cell:
Set: 2  Cell: 5

CSV File created.
Sky capture Done! Image saved in: /261016/Sky0502.jpg
Pyranometer capture Done! Image saved in: /261016/Pyr0502.jpg
Logging to: /261016/05021532.CSV

Temperature,date,time,picture_sky,picture_pyranometer
No more addresses.

Isn’t this weird?
I would like to paste my code here but it is quite long. If I should, please mention it. For now, I will attach it to this post.

Thanks a lot for any hints!

sketch_sep30a_pressbuttons_LCD_SD_RTC_CAM_DS18B20.ino (20.5 KB)

How far from the board are the DS18B20? What resistor value did you use?

Are you using parasite mode or normal power mode?

Hi,

Thank you for the reply. The sensor is very close to the board: I am using the waterproof version which comes with a cable of about 80cm, but I connected that cable directly to the board.

I am running normal power mode, with a resistor value of 4.7KOhm.

The weird thing is really that it detects the sensor every odd time I push the button, which is why I suspect the sketch somehow.

Thanks!

I had a quick look:

lastDebounceTime should be declared as unsigned long but I don't think you are running this long enough to get in trouble (but still worth fixing)

So you actually have only 1 DS18B20 to read from, right? so the behavior you see is totally what you told your code to do :slight_smile:

the first time you press on the button you enter the if part

  //Check whether start button is pressed.
  if ( (millis() - lastDebounceTime) > debounceDelay) {    //filter out any noise by setting a time buffer (debounce)
    if (digitalRead(startPin) == HIGH) {                   // check if start button was pressed

(I would argue that the if (digitalRead(startPin) == HIGH) { is useless because if you get there it means it's HIGH because otherwise you would still be in the while loop before, unless you have been super fast and pressed and released the button in microseconds. I would also argue that your denounce code of 1 second is useless because the execution time of taking the 2 pictures, storing and delays you have in the code is probably longer than 1 second anyway - but it does not hurt).

in there you do some camera recording stuff and after you do this

      if ( !ds.search(addr)) {
        Serial.println("No more addresses.");
        Serial.println();
        ds.reset_search();
        delay(250);
        return;
      }

ds.search(addrArray) Search for the next device. The addrArray is an 8 byte array. If a device is found, addrArray is filled with the device's address and true is returned. If no more devices are found, false is returned. This is because multiple sensors can be on that bus and that's a way to scan what is on the bus. but as you have only one, the first time you enter the if, you find your sensor and read it and then the next time you come back and try to go to the next sensor, that fails because there is no next sensor. so you print "No more addresses" and call ds.reset_search(); which allows to find your unique sensor again at the next ds.search and thus only one out of two request works.

So you should put the ds.search(addr) thingy in the setup to populate the address buffer of your temperature sensor and then in the loop just request from that address, but not try to look for the next one - there won't be a next one

makes sense?

hope this helps

Thank you so much! This completely solved my issue!

I have to admit that I didn’t understand that part of the code (which I had taken from the library example), and I now realize that one should understand every line of a code one runs.

I also made the changes you suggested, thanks for these as well.

You really helped me out here.

Great news ! Have fun