Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w1: add ability to change temperature sensor precision #1412

Closed
wants to merge 4 commits into from

Conversation

x29a
Copy link
Contributor

@x29a x29a commented Apr 16, 2016

The DS18B20 temperature sensor is quite popular with the rpi and yet it is not possible to change the precision with which the sensors are converting their temperature values.

Since some sensors come preconfigured with a low precision, people are stuck to e.g. 9bit when using the rpi when 12bit are possible.

This has been tested on an rpi1 running at 4.1.13+ with a DS18B20 sensor. Other sensors support the commands as well but are disabled for now because of lack of testability.

0day-ci pushed a commit to 0day-ci/linux that referenced this pull request Apr 16, 2016
…mp sensors like DS18B20

based on the PR (raspberrypi/linux#1412) for the raspberry pi kernel, i would like to propose my changes upstream as well.

The changes entitle basic write operations for the 1Wire driver which are needed to change e.g. the precision of temperature sensors like the very popular DS18B20. Writing to SRAM and commiting the values to EEPROM is possible.

Since many sensors come "preconfigured" with a lower precision, people are stuck that precision when running on a kernel based device (unlike the Dallas 1Wire library for e.g. Arduino, which supports writing the configuration/scratchpad).

Signed-off-by: x29a <0.x29a.0@gmail.com>
@popcornmix
Copy link
Collaborator

The 4.1 kernel tree is not longer used.
rpi-update and future apt-get updates will come from 4.4.
Please create a new PR for 4.4 branch.

@popcornmix popcornmix closed this Apr 17, 2016
@flaggz
Copy link

flaggz commented Oct 22, 2016

how exactly do I write the resolution bit in the w1_slave after the x29a commits?

@x29a
Copy link
Contributor Author

x29a commented Oct 22, 2016

Note, this change got accepted upstream with 4.7, i also updated the docs, so its basically:
echo 12 > w1_slave
for 12 bits, same for 9, 10 and 11. Other values are not supported.

@flaggz
Copy link

flaggz commented Oct 26, 2016

i have changed to 11bit precision by plugging the sensor on arduino and when plugged on raspberry the resolution is still 12bit.
does the RPI writes EEPROM on each boot?

@x29a
Copy link
Contributor Author

x29a commented Oct 26, 2016

im not sure if the arduino method writes the precision to SRAM or EEPROM, you would have to elaborate but that is out of the scope of this PR.

In order to save the precision of 11bit permanently with the w1 changes, you would have to write a 0 to the w1_slave, so something like
echo 11 > w1_slave && echo 0 > w1_slave

then check again with arduino and after unplugging the sensor/reboot the device.

Please note again, the changes were introduced with 4.7, which version are you running? self compiled with the patch applied?

@x29a x29a deleted the rpi-4.1.y branch October 26, 2016 13:14
@flaggz
Copy link

flaggz commented Oct 26, 2016

It can write both SRAM and EEPROM. This is the important instruction:
reg_cmd = 0x5F; // Configuration Register (resolution) 7F=12bits 5F=11bits 3F=10bits 1F=9bits
ds.reset();
ds.select(addr);
ds.write(0x4E); // Write scratchpad command
ds.write(0);// TL data
ds.write(0);// TH data
ds.write(reg_cmd);
ds.reset(); // This "reset" sequence is mandatory
ds.select(addr);// it allows the DS18B20 to understand the copy scratchpad to EEPROM command
ds.write(0x48); // Copy Scratchpad command

Right now I’m using standard 4.4. I would prefer to not use dev version if I can.
Just asking if before the patch Raspberry is doing anything at SRAM or EEPROM level when plugging devices.

Il giorno 26 ott 2016, alle ore 15:14, x29a notifications@github.com ha scritto:

im not sure if the arduino method writes the precision to SRAM or EEPROM, you would have to elaborate but that is out of the scope of this PR.

In order to save the precision of 11bit permanently with the w1 changes, you would have to write a 0 to the w1_slave, so something like
echo 11 > w1_slave && echo 0 > w1_slave

then check again with arduino and after unplugging the sensor.

Please note again, the changes were introduced with 4.7, which version are you running? self compiled with the patch applied?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub #1412 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AHTQpSHAhwQds2xoLbg_o6aJmR1n_en9ks5q31JKgaJpZM4IJBlA.

@flaggz
Copy link

flaggz commented Feb 2, 2017

updated to 4.9 with $ sudo rpi-update BRANCH=next
rebooted
/sys/bus/w1/devices/28-80000008152c $ sudo echo 11 > w1_slave
-bash: w1_slave: Permission denied

@pelwell
Copy link
Contributor

pelwell commented Feb 2, 2017

The output of the echo command running as root is received by the shell running as user pi, and the shell is trying to write it to w1_slave. You need the whole pipeline run as root:

sudo sh -c "echo 11 > w1_slave"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants