Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Introduction
A powerful library for a simple and easy to use API when communicating with One Wire devices via I2C on Raspberry Pi.

using (var ds2482_800 = await _dS2482DeviceFactory.CreateDS2482_800(false, false, false))
using (var ds2482_100 = await _dS2482DeviceFactory.CreateDS2482_100(true, true))
using (var ds2482_100 = await _dS2482DeviceFactory.CreateDS2482_100(1, true, true))
{
while (true)
{
Expand Down Expand Up @@ -49,16 +49,29 @@ A powerful library for a simple and easy to use API when communicating with One
// Insert code to log result in some way
}

foreach (Rinsen.IoT.OneWire.MAX31850 device in ds2482_100.GetDevices<Rinsen.IoT.OneWire.MAX31850>())
{
MAX31850.TemperatureConversionResult tcr = device.GetTemperature();
Console.WriteLine("DS2482-100, MAX31850 :");
Console.WriteLine(tcr.TemperatureConversionResultNarrative);

// Insert code to log result in some way
}

await Task.Delay(5000);
}
}

And thats all you need to get started with measuring temperatures with a DS18B20 from .NET and C# on Raspberry Pi.
And thats all you need to get started with measuring temperatures with a DS18B20 or MAX31850 from .NET and C# on Raspberry Pi.

Headed apps
-----------
Headed apps do not currently support disposing the DS2482 devices. The instance MUST be reused between measurements.

I2C Bus
-------
CreateDS2482_100(int busId, bool ad0, bool ad1) allows the I2C bus to be selected in the case you are either not using the default I2C bus 1, or your project has multiple I2C busses.

I2C Address
-----------

Expand All @@ -72,6 +85,7 @@ Built in One Wire Device Support
## Today:
1. DS18B20
2. DS18S20
3. MAX31850

## Extend with your own device

Expand Down
1 change: 1 addition & 0 deletions src/Rinsen.IoT.OneWire/DS2482.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public DS2482(I2cDevice i2cDevice, bool disposeI2cDevice)

AddDeviceType<DS18S20>(0x10);
AddDeviceType<DS18B20>(0x28);
AddDeviceType<MAX31850>(0x3B);
}

public abstract bool IsCorrectChannelSelected(OneWireChannel channel);
Expand Down
26 changes: 26 additions & 0 deletions src/Rinsen.IoT.OneWire/DS2482DeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ namespace Rinsen.IoT.OneWire
{
public class DS2482DeviceFactory : IDS2482DeviceFactory
{
/// <summary>
/// Instantiate a DS2482 on the specified port
/// To use I2C port 0 : (1) Enable I2C using raspi-config, (2) modify /boot/config.txt to include :
/// dtparam=i2c_arm=on
/// dtoverlay=i2c-gpio,bus=0,i2c_gpio_sda=0,i2c_gpio_scl=1 #this is a software i2c on pins 27 and 28
/// #dtoverlay=vc4-kms-v3d (comment this line out)
/// </summary>
/// <param name="busId">busID = 0 : SDA on pin 27, SCL on pin 28 ; busID = 1 : SDA on pin 3, SCL on pin 5 </param>
/// <param name="ad0">AD0 on the DS2482-100</param>
/// <param name="ad1">AD1 on the DS2482-100</param>
/// <returns></returns>
public DS2482_100 CreateDS2482_100(int busId, bool ad0, bool ad1)
{
byte address = 0x18;
if (ad0)
{
address |= 1 << 0;
}
if (ad1)
{
address |= 1 << 1;
}

return CreateDS2482_100(busId, address);
}

public DS2482_100 CreateDS2482_100(bool ad0, bool ad1)
{
byte address = 0x18;
Expand Down
5 changes: 5 additions & 0 deletions src/Rinsen.IoT.OneWire/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ public static bool GetBit(this byte b, int bitNumber)
{
return (b & (1 << bitNumber)) != 0;
}

public static bool GetBit(this ushort b, int bitNumber)
{
return (b & (1 << bitNumber)) != 0;
}
}
}
1 change: 1 addition & 0 deletions src/Rinsen.IoT.OneWire/IDS2482DeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Rinsen.IoT.OneWire
{
public interface IDS2482DeviceFactory
{
DS2482_100 CreateDS2482_100(int busId, bool ad0, bool ad1);
DS2482_100 CreateDS2482_100(int busId, int address);
DS2482_100 CreateDS2482_100(bool ad0, bool ad1);
DS2482_100 CreateDS2482_100(I2cDevice i2cDevice);
Expand Down
Loading