Skip to content

mcsakoff/go-digitemp

Repository files navigation

1-Wire protocol implementation in Go

License: MIT Go Report Card

This is a Go port of pyDigiTemp.

Originally written in Python to replace digitemp utility in my pet project and get direct access to 1-wire devices. It was created for reading DS1820 temperature sensor connected to RS232 serial port through DS9097 adapter.

Supported Hardware

Bus Driver

  • DS9097 - COM port adapter which performs RS-232C level conversion.

  • Custom 1-wire serial port interface (see below).

1-Wire Devices Supported

Usage

💡
See detailed examples in examples directory.
Find ROM codes for all connected devices:
import "github.com/mcsakoff/go-digitemp"

uart, _ := digitemp.NewUartAdapter("/dev/cu.usbserial-1410")
roms, _ := uart.GetConnectedROMs()
for n, rom := range roms {
    log.Printf("%d: %s\n", n, rom)
}
Get temperature from single sensor:
import "github.com/mcsakoff/go-digitemp"

uart, _ := digitemp.NewUartAdapter("/dev/cu.usbserial-1410")
sensor, _ := digitemp.NewTemperatureSensor(uart, nil, true)
temp, _ := sensor.GetTemperatureFloat()

log.Printf("%.02fºC\n", temp)
Get temperature from specific sensor:
import "github.com/mcsakoff/go-digitemp"

rom, _ := digitemp.NewROMFromString("10A75CA80208001A")
uart, _ := digitemp.NewUartAdapter("/dev/cu.usbserial-1410")
sensor, _ := digitemp.NewTemperatureSensor(uart, rom, true)
temp, _ := sensor.GetTemperatureFloat()

log.Printf("%.02fºC\n", temp)

Schematics

⚠️

IMPORTANT DISCLAIMER:

All circuits presented here are collected from different sources on the Internet and thus are provided on an entirely "as-is and no guarantees" basis. I do not provide a warranty of any kind and cannot be held responsible in any manner.

1-wire serial port interface

USB/UART adapter

These are tested:

Not all schematics work in all cases, depending on an adapter and cable length.

Kudos To

  • Slavko for SVG schematics and testing python version.

License

Copyright © 2020 Alexey McSakoff
Free use of this software is granted under the terms of the MIT License.

See the LICENSE file for details.

About

Go implementation of 1-Wire protocol.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages