# Raspberry Pi sensor

Hey I am reading the temperature of a sensor called 'DS18b20' and in the path /sys/bus/devices/[hardwareIDofTheSensor]/w1_slave, I can read the sensor.

Now I have following question, what does this string mean:

8d 01 4d 7f ff 03 10 03 : crc=03 YES

8d 01 4b 46 ff 03 10 03 t=24812

I know that t="..." is the temperature, but what does the rest of the string mean?

• t is the temperature? The temperature is 24812? What are the units for the temperature? Could you tell us the OS you are using and the version of the Pi, any instructions you followed online e.t.c... – Darth Vader May 30 '16 at 11:21
• Yes, this is the temperature. The units are degC x1000. – KDM May 30 '16 at 11:26

My output of the same device seems easy to interpret:

5e 01 ff ff 7f ff ff ff 52 : crc=52 YES
5e 01 ff ff 7f ff ff ff 52 t=21875

We know at least the first two bytes are the temperature, and the last one the CRC. I suspect there must be at least another temperature byte (7f?).

The first byte is the LS byte in the datasheet, and the 2nd byte the MS byte.

Coming back to your temperature, 8d 01 = 24812

LS= 1001 1101 MS= 0000 0001

So we know the MS byte has the upper bits zero, which mean temperature is positive. It also has the last bit 2^4, which is the first bit of temperature.

We also know the first 4 bits of MS are the rest of the temperature.

So, the real part of the temperature is 1 1001 = 21

It took me a while to notice there is an error in the datasheet. The last four bits in the LS for the fractional part are powers of 5, and not powers of two. However I do suspect our sensors are not in 12-bit mode as the example given in the datasheet, I think 16-bit mode, so the powers may be different.

I'm pretty sure that's not the ROM since they all start with `0x28`, so it's probably one of the registers on the device (probably the temperature register).

Here's the datasheet: http://neutrino.phys.ksu.edu/~gahs/doublechooz/DC_SlowMRS/DS/DS18B20.pdf

Remember that information is printed by the Linux kernel driver.

Here is the source code.

I had a quick look but I didn't find it very easy to read. The string is generated from line 311.