5

I've got my 4 Maxim DS18B20 devices up and working using the w1-gpio and w1-therm modules.

I would however like to change the temperature resolution by writing to the config register of the devices, as described on page 8 of the Maxim spec here

Is there a way to achieve this using the file system interface? I don't really fancy having to recompile the driver to do this. I've searched high and low but can't find anything.

Thanks in advance for any help.

  • Welcome to Raspberry Pi Stack Exchange! Could you include some of what you've tried already? – RPiAwesomeness Mar 9 '14 at 1:10
4

On Raspberry Pi 1

(ignore any errors:)

wget https://raw.githubusercontent.com/blogmotion/BitBangingDS18B20/master/configDS18B20.c
gcc -o configDS18B20 configDS18B20.c
sudo ./configDS18B20

Now type 9,10,11, or 12 to change resolution:

  • 9 bit : 0.5°c
  • 10 bit : 0.25°c
  • 11 bit : 0.125°c
  • 12 bit : 0.0625°c

On Raspberry Pi 2

(ignore any errors:)

wget https://raw.githubusercontent.com/blogmotion/BitBangingDS18B20/master/configDS18B20.c
sudo nano configDS18B20.c

Change "BCM2708_PERI_BASE "0x20000000" to BCM2708_PERI_BASE "0x3F000000" (ignore any errors)
Save (Ctrl+X, Y, ENTER)

gcc -o configDS18B20 configDS18B20.c
sudo ./configDS18B20

Now type 9,10,11, or 12 to change resolution:

  • 9 bit : 0.5°c
  • 10 bit : 0.25°c
  • 11 bit : 0.125°c
  • 12 bit : 0.0625°c
  • This does change the resolution correctly(tried&confirmed on 1st gen model B), but it doesn't speed up the process, sadly... – Kraay89 Nov 8 '16 at 21:25
3

This isn't the right answer to my original question, however, it does solve the original problem.

There are two reasons why one would want to change the DS18B20 resolution: 1. To read a single device much more quickly than 750ms 2. To read a bunch of devices more frequently than (#devices * 750ms)

If you want to do 1, then you're stuck - as far as I can tell from the w1_therm source code here there is no support for writing to the config register, and in any case the w1_therm driver has the 750ms wait value hard coded in it.

However, it appears that the w1_therm driver does support multiple calls to devices concurrently. As a read operation is really three steps:

  1. Issue read command to device
  2. Wait 750ms
  3. Read temperature reading

it is actually possible to issue a read command to all your devices, and provided you're not using parasitic power mode there should be enough juice for all your devices to do the temperature conversion concurrently.

How does this work?

readAllSlow looks like this - this is the slow way of reading your devices.

tN is a symbolic link to the file you'd normally read the temperature from the command line.

#!/bin/bash                                                                             
cat t1
cat t2
cat t3
cat t4

If we run this with time command, on my Pi it takes 3s+ - this is 750ms for each device plus overhead.

However, if we do the reads concurrently like this:

#!/bin/bash

cat t1 &
PID1=$!

cat t2 &
PID2=$!

cat t3 &
PID3=$!

cat t4 &
PID4=$!

wait $PID1
wait $PID2
wait $PID3
wait $PID4

Then timing the script using time takes only 900ms - 1s.

Some caveats - I can't see how w1_therm achieves this as as far as I can see it goes to sleep with the mutex held (so I'm surprised this works).

And an apology for the formatting - I've spent 20 mins trying to figure out how to do formatted code and failed. Hope this helps.

  • You can write code by making a new paragraph and then adding four spaces to the beginning of each line. – LuWi Apr 7 '14 at 9:54
  • 1
    There is a lot of other things that are hardcoded in the w1-gpio and w1-therm drivers that really limit the use of 1-wire for some particular applications. – Marco Poli Apr 8 '14 at 17:36
0

Some folks have mentioned in the comments that w1-gpio and w1-therm limit that range of applications for your ds18b20. It's not clear whether that's due to not being able to change the resolution or because they only support one resolution. But let me add that I came here with the same problem - I need to change some ds18b20s. I'm running w1-gpio and w1-therm and some of my sensors (one brand) was set to 12-bit default, and some of them (another brand) was set to 9-bit default, which is too imprecise for my application.

So, I can at least confirm that w1-gpio and w1-therm not only support various resolutions, but can support using multiple resolutions at the same time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.