DS1820 to USB connector

[..] [Introduction] [Unraveling DS18X20] [Hardware] [Software] [Downloads] [Acknowledgements] [Copyright/Disclaimers] [Similar projects] [Feedback]

Introduction / What is it

It is a little board with an Atmel AVR (ATtiny45/85) microcontroller that can be used to connect Dallas/Maxim 1wire temperature sensors like the DS18B20 to the USB port of a PC. Some linux software that allows reading the temperature data is included. The whole USB implementation is done in software, using the great AVR-USB library from Objective Development.
In theory, there is no limit on the number of probes that can be connected to the device, but see the software section for some more realism.

Unraveling DS18X20

When you try to get the parts for building this, you may note that Dallas/Maxim has quite a few very very similarily named parts. As I had the same problem, I have put together a little table that explains the differences. Please note that I'm not an expert here, and this table really comes without any warranty. Also, all these devices are 1wire devices, so you should be able to connect them, but to read useful data from them will probably require some minor software changes on the host side.
DS18B20 The one used here: TO-92 case, accuracy ±0.5 degrees (Celsius), user configurable resolution up to 12 bit (=0.0625°C)
DS18B20+ Exactly the same as DS18B20, the + denotes that the product is lead free (this is a requirement in all european countries now, the keyword is "ROHS")
DS18S20 resolution fixed at 9 bit (=0.5°C)
DS1820 resolution fixed at 9 bit, a little faster, but no longer available
DS1822 accuracy ±2 degrees (C)

The Hardware

Schematics and description

The hardware can easily be built on a perfboard / stripboard. A proper board has also been designed and the layout is included in the .tar.gz you find under software.
There aren't really many parts besides the ATtiny and the temperature probes (DS18B20): Only one crystal, two diodes, some resistors and a few capacitors.
The fuses of the ATtiny45/85 should be programmed for external crystal >8 MHz and BOD at 2.7 Volts. Running "make uploadfuses" will give you some hints for programming the fuses. Note that the ATtiny45/85 is run slightly out of spec here: Officially allowed are 10 MHz at 2.7 volts and 20 MHz at 4.5 volts. In this circuit it is run with 15 MHz at around 3.6 volts. AVR-USB can also handle some other clock rates and in the newest version even the internal oscillator, however from the description it seemed to me as if 15 MHz was the most stable option.
ds1820-top-view The DS18B20 supports a parasite power mode, where it only needs two wires instead of 3. In this mode it will draw the power it needs for operation from the data line. The software supports and detects this mode and will automatically power the probes through the data line when needed. To use this mode, connect the VCC pin of the DS18B20 to GND too. Parasite powered probes will show up with the "P" flag in the hostsoftware status output.

Part list

The main microcontroller doing all the work. You should get an ATtiny85 instead of the ATtiny45 I used originally to be on the safe side. See the remarks in the [Software] section. You will also need some programmer to flash the microcontroller with the firmware.
>=1DS18B20 At least one temperature probe would make sense for a device that is intended to be used for temperature measurement...
2Diode 1N4001 These are abused to bring the supply voltage down from 5 to 3.6 Volts. Other silicium diodes (e.g. 1N4004, 1N4148) can be used as well, as long as they cause 0.6-0.7 volts of voltage dropout each.
2Resistor 68Ω  
1Resistor 1MΩ  
1Resistor 1.5kΩ  
1Resistor (<=) 4.7kΩ This is the pullup for the 1wire bus. You might need to use a resistor with a smaller value for longer cables.
1Resistor 10kΩ This one is merely optional, it is a pullup resistor for the ATtinys !reset pin. The ATtiny has an internal pullup, so it's not strictly needed, but supposedly increases stability when the power supply is unstable.
2Capacitor 100nF These are used for stabilizing power. They can be larger than 100nF and there can be more than two. But you should put at least one close to the microcontroller and one close to the connection point for the probes.
2Capacitor 15pF according to the ATtiny datasheet, everything between 12 and 22 pF should be fine.
1Crystal 15 MHz 12 MHz can probably be used as well, but that requires a minimal firmware change and hasn't been tested.
1DIP 8 socket Recommended, else you would have to directly solder the ATtiny.
1USB connector Either use a proper USB jack like in the pictures, or just cut some USB cable open and directly solder the leads.


The Software

The Software was written in C. It uses avr-libc and AVR-USB.
Originally, an ATtiny45 was used. When compiled with the standard Ubuntu 8.04 AVR stuff (avr-libc 1.4.7, avr-gcc 4.2.2, and -Os as a compiler switch to optimize for size), the code used around 3900 of the 4096 bytes of flash the attiny45 has. However, other more recent avr-libc and avr-gcc versions generate much larger code, so that the code no longer fits into the ATtiny45. As the price difference is only a few cents, the obvious solution is to use an ATtiny85 instead, which has 8K flash instead of 4. Starting with software version 1.04, this is now the default, and you would have to find a really outdated system to be even able to compile the software for an ATtiny45 anymore.
In theory, you can connect an unlimited amount of temperature probes to the onewire-bus, and read them. However, in reality there are a few limitations: From some of the success supports I have got, it seems that you need to decrease the pull-up-resistor for the onewire bus in order to support longer cables, e.g. 2 KiloOhm instead of 4.7. This essentially pulls the bus back to its default state faster (sharper signal edges), but also wastes a little more power. There have been reports of a powered probe on 20 meters of cable, and a parasite powered probe on 8 meters - both with different pullup resistors (1kOhm).
The hostsoftware included allows you to query the status of the temperature sensors from the device. The software gets compiled with make hostsoftware - note that you will need libusb(-dev) to compile it. The software has been tested on linux and reported to work on Mac, but should compile/run on any platform where libusb is available, which includes windows.
If you call the hostsoftware with parameter --help it should tell you all you need to know. Here is a short introduction on how the software usually is used:
hostsoftware status - this will list all probes detected at poweron. Output should look something like this:

Device Version is 00.01 Device time is currently timestamp 60742 4 probes supported by device fa serial fl lastseen ticksago lastvalue 28 000001efea9d U 60574 168 22.06 28 000001efe323 U 60635 107 22.12 00 000000000000 0 60742 0.00 00 000000000000 0 60742 0.00

Here, the device has found two temperature sensors. It could handle two more, but only two have been detected.
If you want to make the data from a sensor available via network, you can use the command hostsoftware daemon which will fork a little server process into the background. For example, to serve the data from the probe with serial 000001efea9d on port 7337, you could run:
./hostsoftware daemon '000001efea9d:7337:%T'
The %T specifies the format of the output served on the network port - %T will only print the temperature, while the default is %S %T to print both serial number and temperature.


Current version:
Sourcecode v 1.03 (22. December 2011)
Previous versions:
Sourcecode v 1.02 (17. July 2010)
Sourcecode v 1.01 (23. March 2009)
A more recent development version may be available in this gitweb repository.


This would not have been possible without AVR-USB (nowadays renamed to V-USB).


All trademarks are property of their respective owners.
Should you try to rebuild anything shown or use anything offered here, you do so at your own risk.
Your mileage may vary.
All plans and the parts of the software that were written by me are released under the GNU GPL Version 2. For details on the licensing of the included AVR-USB library, see the files in directory usbdrv or their homepage.

Similar projects

I know of some projects, where the first one is really a product that is sold, not a project:


You can post feedback under the Blog Article referring to this.