Linux Format

Welcome...

-

Recently, I wrote some code to use the DS18B20 temperatur­e sensor with Python via a function. The code was based on the code used with the Cam Jam Edu Kits, a code base that I’d used for nearly two years.

Now this code was quite large, and only printed the temperatur­e to the Python shell. But after a chance conversati­on with Ben Nuttall from the Raspberry Pi Foundation I learnt of a library called W1ThermSen­sor that handled all of the hard work! The library, written by Timo Furrer, is awesome and it helps abstract the steps necessary to read the one-wire sensor, which appears as a file in the Linux file system. Take a look at the library and try it out: https://github. com/timofurrer/w1thermsen­sor.

The next step for using this sensor is to connect a 4.7k Ohm resistor from the 3V (VCC) pin of the sensor, to the output pin, ensuring that the pin is always pulled high. I’ve built my own little jig that uses a terminal block to connect the pins. But another conversati­on with Dave Jones, creator of the Picamera Python library changed my setup. The output pin needs to connect to the GPIO, and that pin needs to be pulled high. Well, we can use the GPIO Zero and RPi.GPIO Python libraries to pull a pin high or low on command. Removing the need for the external resistor.

The motto of this tale? What you’re doing is right, but there’ll be other ways to tackle a project. Those ways may be better, so embrace them and learn from them. But if they don’t work for you, put them to one side and carry on with your project.

 ??  ?? Les Pounder is our regular pie expert. He also writes about the Raspberry Pi.
Les Pounder is our regular pie expert. He also writes about the Raspberry Pi.

Newspapers in English

Newspapers from Australia