Summary: The idea here was to create a temperature sensor that could easily be connected to an Apple Mac computer and have it display its readings inside an OSX application. More a demonstrator than anything someone might actually use in the real world, but who knows, maybe someone out there has a practical need for such a contraption…

 

Objective

Screenshot of the Mac OS application, TemperatureUSBThe objective here was to create a temperature sensor that connects to an Apple Mac over USB, and works within an Mac OSX application to display the temperature.

 

Background

There was not a lot of reasoning behind this project other than for it to act as a demonstrator for integrating various technologies, namely, the DS18S20 temperature sensor, a USB connection, and the Mac OS. I have thought long and hard for actual real-world uses for this device but, unfortunately, I have to conclude that there are few reasons for using it over existing temperature-measuring methods since using much simpler hardware (like a regular thermometer) would likely be the better way to go from a practical standpoint. However, for completeness and on the off-chance that someone might find this project useful or better still, some bright indivdual finds a practical use for it, here it is all the same.

 

Image of pre-wired, stainless steel-encased, DS18B20 temperature sensors

DS18B20 temperature sensor

Methods

Temperature Sensor:

One of the most versatile temperature sensors available to electronic tinkerers today is the Maxim DS18B20 which is a one-wire device (ie. it can be configured so that it needs only one wire to work) that has a working temperature range from -55℃ to +125℃ and its use in electronic projects is well-documented on the web. To increase the device’s usability, the DS18B20 sensor itself needed to be waterproof so that it also could be used to measure the temperature of liquids in addition to gases and solids, so it made sense to chose a pre-wired version of the sensor that had been packaged within a stainless steel enclosure.

PCB:

Board layout of the printed circuit board for the USB-connectable temperature-sensing device Schematic of the printed circuit board for the USB-connectable temperature-sensing device The circuit design was based around an ATmega168 microprocessor that polls the DS18B20 temperature sensor at regular intervals. The circuit was designed by Mathias Dalheimer and described on the Objective Development page for V-USB here. The original code is available on GitHub or a slightly modified version of it specific for this project can be downloaded below (see the File Downloads section). An LED flashes when a new temperature has been obtained and also shows the device is functioning normally. The AVR microprocessor, at the same time, runs code designed to mediate the USB functionality of the device which is based around the V-USB design by Objective Development described elsewhere. The home-made PCB was made using the photo-etch method and holds mosts of the components including the USB socket. Since the PCB was destined to be placed inside an enclosure, the LED position on the circuit board was populated with header pins instead of the LED itself, with the LED inserted into the enclosure housing and connected to the PCB using wires. The whole device derives its Image of the photo-etched printed circuit board for the USB-connectable temperature-sensing device power from the USB connection so it needs no external power source to operate it once it is plugged into a Mac.

Enclosure:

To be as unintrusive as possible, the enclosure housing the temperature sensor electronics was designed to be as small as possible and to just fit around the electronic parts of the USB temperature sensor circuit board. Consequently, although the PCB uses two size 4 pan-head screws to secure it to the enclosure at one end, the other end of the PCB uses the two enclosure-securing screws to hold the PCB as well as the enclosure. A cable gland appropriately size-matched to the DS18B20 sensor cable diameter was integrated into one end of the enclosure design to provide stain relief, while the USB port that provides the connection to the computer protruding from the other end.

Software:

Image of the 3D-modelled enclosure for the USB-connectable temperature-sensing device Since I am the owner of 4 Apple Macs and only 1 PC, the question of which operating system to make the software to operate the USB temperature sensor device seemed like a no-brainer. The software for the USB temperature sensor is written for the most part in C and Objective-C and runs on Mac OSX, having been tested on OSX Capitan, Yosemite and Mavericks. One important point to note here however, is that since we are using V-USB for the USB connection to the Mac, the free-to-download libusb library also needs to be installed on the Mac computer the temperature sensor is to be used with. What is the libusb library? Well it is best summed up by a line from the libusb Wiki on Wikipedia:

libusb is a library that provides applications with access for controlling data transfer to and from USB devices on Unix and non-Unix systems, without the need for kernel-mode drivers”Image of the PCB and 3D-printed enclosure for the USB-connectable temperature-sensing device

The easiest way to install the libusb library on a Mac is to use MacPorts (also free to download), which is like an installer for the Mac but implements software installations via the commandline, so MacPorts itself has to be installed if it is not already on your Mac. For one’s own piece of mind, when it comes to downloading unusual software and libraries on to one’s precious Mac, it’s always best to have a good read around the software you are about to install, especially if you haven’t heard of them or used them before. Therefore, for libusb and MacPorts, I won’t provide any detailed description of their installations but simply provide their links to more information & downloads (see the ‘Resource Links’ section below). Suffice it to say, they are trustworthy & legitimate open-source resources for the Mac, so you have nothing to fear by incorporating libusb and MacPorts into your Mac computers even if you decide later not to make use of them.

Update : Upon further investigation, I have realised that one does NOT need to install libusb (nor MacPorts) for the device to work. It appears the libusb library is automatically linked into the Mac Application when it is built in Xcode. Consequently, one just needs to download the temperature application below and connect the device, everything should work fine. I have tested everything out on 2 different Mac Minis, neither of which had libusb installed (although they did both have MacPorts installed for other projects), and the whole system has been very robust. This makes life a hell of a lot simpler!

 

Using the TemperatureUSB MacOS app:

Screenshot of the standard MacOS unsigned app warning when running the TemperatureUSB application for the first timeMost likely your Mac OS settings will be set to prevent apps from running if they have not been signed by the developer. Since I’m doubting this app is going to be much of a hit, and since I have not yet had the time to sort out my developer ID and figure out how to sign apps so that they don’t trigger the Mac OS warning, we will have to put up with this little inconvenience. This warning is easily circumvented by going into your Mac settings panel to the ‘Security & Privacy’ tab, where if you have tried opening the app for the first time, you should be presented with the following screen prompt and button to ‘open the app anyway’:

Screenshot of MacOS settings tab 'Security & Privacy'

 

 

Image of the completed USB-connectable temperature-sensing device File Downloads

 

 

Resource Links

 

Materials

TypeComponent No. of units
Temperature SensorDS18B20
1
USBUSB SocketUSBsocket
1
Rapid
Resistors:68 Ohm68R
2
120k Ohm 120K
1
1k5 Ohm 1K5
1
Capacitors: (electrolytic)10µFElectrolytic10uF
1
Capacitors: (ceramic)15pFceramic15pF
2
Rapid
Zener Diodes3v6Zener3V6
2
Farnell
Header4 single & 1 double pin (straight)
1
Photo Etch PCB Kitkit
1
Machine ScrewsM3 x 20mmM3x20machineScrew2
4
Hexagon NutM3 M3 nut1
4
Pan-head Screws4 x 3/8" 4xthreeEighthPanHead3
2
toolstation
Atmel AVRAtmega168AVR ATmega168
1
Rapid
Crystal15MHz 15MHzCystal
1
Farnell
LED3mm 3mmLED1
1
LED Holderfor 3mm LED3mmLEDHolder1
1
ebay
Cable GlandM12 x 1.53x1.5Cable Gland1
1
ebay