(Translated by https://www.hiragana.jp/)
GitHub - nanoframework/nanoFramework.Device.OneWire: :package: nanoFramework 1-Wire Class Library
Skip to content

nanoframework/nanoFramework.Device.OneWire

Repository files navigation

Quality Gate Status Reliability Rating NuGet #yourfirstpr Discord

nanoFramework logo


Welcome to the .NET nanoFramework 1-Wire® Class Library repository

Build status

Component Build Status NuGet Package
nanoFramework.Device.OneWire Build Status NuGet

1-Wire® bus

1-Wire® it's a communication protocol, property of Maxim Semiconductor. You can read the technical details about it on this guide.

.NET nanoFramework implementation

Our low level implementation of the 1-Wire communication uses an UART to achieve precise timing with the less possible burden on the MCU. For that reason it requires an UART and shunting together it's RX and TX pins. Depending on the bus length and impedance it may be required connecting an external pull-up resistor to provide the necessary signalling for 1-Wire communication.

Important: If you're using an ESP32 device it's mandatory to configure the UART2 pins before creating the OneWireHost. To do that, you have to add a reference to nanoFramework.Hardware.ESP32. In the code snippet below we're assigning GPIOs 21 and 22 to UART2. Also note that UART2 it's referred as COM3 in C#.

////////////////////////////////////////////////////////////////////////
// Configure pins 21 and 22 to be used in UART2 (that's refered as COM3)
Configuration.SetPinFunction(21, DeviceFunction.COM3_RX);
Configuration.SetPinFunction(22, DeviceFunction.COM3_TX);

Take note, on some ESP32 development kits, the pins you're planning on using for UART2 could be used for internal purposes. For example, development kits based on either ESP32-WROOM-32 or ESP32-WROVER-E can have the same pinouts and silkscreen. If the kit is based on ESP32-WROVER-E the GPIOs 17 and 16 are used to address its extended memory (PSRAM), and cannot be used for other purposes, event though they are present as external pins. You can use any other GPIO pins that's free for UART2 pins using Configuration.SetPinFunction.

For other devices, like STM32 ones, there is no need to configure the GPIO pins. You have to find in the respective device documentation what are the UART pins used for 1-Wire.

Usage examples

To connect to a 1-Wire bus and perform operations with the connected devices, one has to first instantiate the OneWireHost.

OneWireHost _OneWireHost = new OneWireHost();

To find the first device connected to the 1-Wire bus, and perform a reset on the bus before performing the search, the following call should be made:

_OneWireHost.FindFirstDevice(true, false);

To write a byte with the value 0x44 to the connected device:

_OneWireHost.WriteByte(0x44);

To get a list with the serial number of all the 1-Wire devices connected to the bus:

var deviceList = _OneWireHost.FindAllDevices();

foreach(byte[] device in deviceList)
{
    string serial = "";

    foreach (byte b in device)
    {
        serial += b.ToString("X2");
    }

    Console.WriteLine($"{serial}");
}

Feedback and documentation

For documentation, providing feedback, issues and finding out how to contribute please refer to the Home repo.

Join our Discord community here.

Credits

The list of contributors to this project can be found at CONTRIBUTORS.

License

The nanoFramework Class Libraries are licensed under the MIT license.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behaviour in our community. For more information see the .NET Foundation Code of Conduct.

.NET Foundation

This project is supported by the .NET Foundation.