Here is a description how to work with it.
Before trying to connect new devices to Raspberry Pi with FreeBSD it’s a good idea to check that this devices work.
Let’s connect this temperature sensor to the Arduino first. On the next pictures we can see a connection of the DS18B20 to the Arduino:
I connected Data pin from DS18B20 to digital pin 10 on Arduino, Vdd pin to +5V, GND to GND and put 4k7 resistor between Data and Vdd pins.
To work with 1-wire in Arduino we need to install OneWire library. We can do it from Arduino IDE. After that we can load example sketch “DS18x20_Temperature”.
On the next picture we can see the result:
We can see chip name, id and current temperature. It works!
Connecting DS18B20 to the Raspberry Pi
FreeBSD supports for 1-Wire hardware through GPIO. FreeBSD doesn’t support “parasite power” mode for DS18B20 sensors. This mean that we should powered it by an external supply on the VDD pin. But GPIO pins in the Raspberry Pi are 3V3 not 5V like Arduino. That’s why we should connect Vdd pin to 3v3, not to 5V.
On the next pictures we can see a connection of the DS18B20 to the Raspberry Pi:
I connected Data pin from DS18B20 to pin 4 on Raspberry Pi, Vdd pin to +3V3, GND to GND and put 4k7 resistor between Data and Vdd pins.
How to setup software
Physical connection is a small part of the deal. We need to setup software. But the first step is getting source code. After that we can change kernel config and FDT description.
For Raspberry Pi Model B we need to modify file /usr/src/sys/boot/fdt/dts/arm/rpi.dts:
4 in the third string is a number of pin we will use for connecting 1-wire devices.
After changing this file we need to build and install new FDT file:
For Raspberry Pi Model B we need to modify kernel file /usr/src/sys/arm/conf/RPI-B:
We need to add devices owc, ow and ow_temp into our kernel.
After that we can compile and install new kernel:
Checking the result
After reboot we can check the result.
We see our devices. System detected our DS18B20 sensor and added device for it.
Without 1-wire devices connected or with incorrectly connected we can see other result:
Working with the sensor
To get information from the sensor we should use sysctl utility:
When we connect two sensor to our one-wire bus we will see them both:
The Raspberry Pi Model B with two DS18B20 connected to it is on the next picture:
That’s all folks!