-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
360 additions
and
0 deletions.
There are no files selected for viewing
Binary file added
BIN
+499 KB
Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Datasheet/PCT2075.pdf
Binary file not shown.
150 changes: 150 additions & 0 deletions
150
Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Driver/Pct2075.Enums.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
namespace Meadow.Foundation.Sensors.Temperature; | ||
|
||
public partial class Pct2075 | ||
{ | ||
/// <summary> | ||
/// Valid I2C addresses for the PCT2075 sensor. | ||
/// </summary> | ||
public enum Addresses : byte | ||
{ | ||
/// <summary> | ||
/// I2C address: 0x48 (1001000) | ||
/// </summary> | ||
Address_0x48 = 0b1001000, | ||
|
||
/// <summary> | ||
/// I2C address: 0x49 (1001001) | ||
/// </summary> | ||
Address_0x49 = 0b1001001, | ||
|
||
/// <summary> | ||
/// I2C address: 0x4A (1001010) | ||
/// </summary> | ||
Address_0x4A = 0b1001010, | ||
|
||
/// <summary> | ||
/// I2C address: 0x4B (1001011) | ||
/// </summary> | ||
Address_0x4B = 0b1001011, | ||
|
||
/// <summary> | ||
/// I2C address: 0x4C (1001100) | ||
/// </summary> | ||
Address_0x4C = 0b1001100, | ||
|
||
/// <summary> | ||
/// I2C address: 0x4D (1001101) | ||
/// </summary> | ||
Address_0x4D = 0b1001101, | ||
|
||
/// <summary> | ||
/// I2C address: 0x4E (1001110) | ||
/// </summary> | ||
Address_0x4E = 0b1001110, | ||
|
||
/// <summary> | ||
/// I2C address: 0x4F (1001111) | ||
/// </summary> | ||
Address_0x4F = 0b1001111, | ||
|
||
/// <summary> | ||
/// I2C address: 0x70 (1110000) | ||
/// </summary> | ||
Address_0x70 = 0b1110000, | ||
|
||
/// <summary> | ||
/// I2C address: 0x71 (1110001) | ||
/// </summary> | ||
Address_0x71 = 0b1110001, | ||
|
||
/// <summary> | ||
/// I2C address: 0x72 (1110010) | ||
/// </summary> | ||
Address_0x72 = 0b1110010, | ||
|
||
/// <summary> | ||
/// I2C address: 0x73 (1110011) | ||
/// </summary> | ||
Address_0x73 = 0b1110011, | ||
|
||
/// <summary> | ||
/// I2C address: 0x74 (1110100) | ||
/// </summary> | ||
Address_0x74 = 0b1110100, | ||
|
||
/// <summary> | ||
/// I2C address: 0x75 (1110101) | ||
/// </summary> | ||
Address_0x75 = 0b1110101, | ||
|
||
/// <summary> | ||
/// I2C address: 0x76 (1110110) | ||
/// </summary> | ||
Address_0x76 = 0b1110110, | ||
|
||
/// <summary> | ||
/// I2C address: 0x77 (1110111) | ||
/// </summary> | ||
Address_0x77 = 0b1110111, | ||
|
||
/// <summary> | ||
/// I2C address: 0x28 (0101000) | ||
/// </summary> | ||
Address_0x28 = 0b0101000, | ||
|
||
/// <summary> | ||
/// I2C address: 0x29 (0101001) | ||
/// </summary> | ||
Address_0x29 = 0b0101001, | ||
|
||
/// <summary> | ||
/// I2C address: 0x2A (0101010) | ||
/// </summary> | ||
Address_0x2A = 0b0101010, | ||
|
||
/// <summary> | ||
/// I2C address: 0x2B (0101011) | ||
/// </summary> | ||
Address_0x2B = 0b0101011, | ||
|
||
/// <summary> | ||
/// I2C address: 0x2C (0101100) | ||
/// </summary> | ||
Address_0x2C = 0b0101100, | ||
|
||
/// <summary> | ||
/// I2C address: 0x2D (0101101) | ||
/// </summary> | ||
Address_0x2D = 0b0101101, | ||
|
||
/// <summary> | ||
/// I2C address: 0x2E (0101110) | ||
/// </summary> | ||
Address_0x2E = 0b0101110, | ||
|
||
/// <summary> | ||
/// I2C address: 0x2F (0101111) | ||
/// </summary> | ||
Address_0x2F = 0b0101111, | ||
|
||
/// <summary> | ||
/// I2C address: 0x35 (0110101) | ||
/// </summary> | ||
Address_0x35 = 0b0110101, | ||
|
||
/// <summary> | ||
/// I2C address: 0x36 (0110110) | ||
/// </summary> | ||
Address_0x36 = 0b0110110, | ||
|
||
/// <summary> | ||
/// I2C address: 0x37 (0110111) | ||
/// </summary> | ||
Address_0x37 = 0b0110111, | ||
|
||
/// <summary> | ||
/// Default I2C address: 0x37 (0110111) | ||
/// </summary> | ||
Default = Address_0x37 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Driver/Pct2075.Registers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Meadow.Foundation.Sensors.Temperature; | ||
|
||
public partial class Pct2075 | ||
{ | ||
internal enum Registers | ||
{ | ||
Temp = 0x00, | ||
Conf = 0x01, | ||
Thyst = 0x02, | ||
Tos = 0x03, | ||
Tidle = 0x04 | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
Source/Meadow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Driver/Pct2075.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using Meadow.Hardware; | ||
using Meadow.Peripherals.Sensors; | ||
using Meadow.Units; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Meadow.Foundation.Sensors.Temperature; | ||
|
||
/// <summary> | ||
/// Represents a PCT2075 temperature sensor, implementing the ITemperatureSensor and II2cPeripheral interfaces. | ||
/// </summary> | ||
public partial class Pct2075 : PollingSensorBase<Units.Temperature>, | ||
ITemperatureSensor, II2cPeripheral | ||
{ | ||
private II2cCommunications _comms; | ||
|
||
/// <inheritdoc/> | ||
public Units.Temperature? Temperature { get; private set; } | ||
/// <inheritdoc/> | ||
public byte DefaultI2cAddress => (byte)Addresses.Default; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the Pct2075 class. | ||
/// </summary> | ||
/// <param name="bus">The I2C bus to which the sensor is connected.</param> | ||
/// <param name="address">The I2C address of the sensor (optional, default is Addresses.Default).</param> | ||
public Pct2075(II2cBus bus, Addresses address = Addresses.Default) | ||
{ | ||
_comms = new I2cCommunications(bus, (byte)address); | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override Task<Units.Temperature> ReadSensor() | ||
{ | ||
var tempRegister = _comms.ReadRegisterAsUShort((byte)Registers.Temp, ByteOrder.BigEndian); | ||
Units.Temperature result; | ||
if ((tempRegister & (1 << 15)) != 0) | ||
{ | ||
// negative temp | ||
var t = (tempRegister >> 5); // shift | ||
t = (~t & 0b111111111) + 1; // invert, mask to 9-bits, add 1 (9-bit twos complement) | ||
result = (-1 * t * 0.125).Celsius(); | ||
} | ||
else | ||
{ | ||
result = ((tempRegister >> 5) * 0.125).Celsius(); | ||
} | ||
Temperature = result; | ||
return Task.FromResult(result); | ||
} | ||
|
||
/// <summary> | ||
/// Sets the interrupt temperatures for the PCT2075 sensor. | ||
/// </summary> | ||
/// <param name="interruptOnTemperature">The temperature threshold that triggers the interrupt.</param> | ||
/// <param name="interruptOffTemperature">The temperature threshold that deactivates the interrupt.</param> | ||
/// <param name="interruptActiveHigh"> | ||
/// Indicates whether the interrupt is active-high (true) or active-low (false). | ||
/// Default is active-high. | ||
/// </param> | ||
public void SetInterruptTemperatures(Units.Temperature interruptOnTemperature, Units.Temperature interruptOffTemperature, bool interruptActiveHigh = true) | ||
{ | ||
if (interruptOffTemperature > interruptOnTemperature) throw new ArgumentException("Off temperature must be below On temeprature"); | ||
|
||
// require 6 readings to exceed the interrupt temp to trigger | ||
byte cfg = 0b00011000; | ||
if (interruptActiveHigh) cfg |= 1 << 2; // interrupt polarity bit | ||
_comms.WriteRegister((byte)Registers.Conf, cfg); | ||
|
||
// on temp | ||
var tos = (ushort)(((short)interruptOnTemperature.Celsius / 2) << 7); | ||
_comms.WriteRegister((byte)Registers.Tos, tos); | ||
|
||
// off temp | ||
var thyst = (ushort)(((short)interruptOnTemperature.Celsius / 2) << 7); | ||
_comms.WriteRegister((byte)Registers.Thyst, thyst); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...ndation.Peripherals/Sensors.Temperature.Pct2075/Driver/Sensors.Temperature.Pct2075.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<Project Sdk="Meadow.Sdk/1.1.0"> | ||
<PropertyGroup> | ||
<Version>1.8.0</Version> | ||
<GenerateDocumentationFile>true</GenerateDocumentationFile> | ||
<PackageIcon>icon.png</PackageIcon> | ||
<Authors>Wilderness Labs, Inc</Authors> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<OutputType>Library</OutputType> | ||
<AssemblyName>Pct2075</AssemblyName> | ||
<Company>Wilderness Labs, Inc</Company> | ||
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/</PackageProjectUrl> | ||
<PackageId>Meadow.Foundation.Sensors.Temperature.Mcp960x</PackageId> | ||
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.Foundation</RepositoryUrl> | ||
<PackageTags>Meadow.Foundation,Temperature,PCT2075</PackageTags> | ||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> | ||
<Description>Pct2075 I2C temperature sensor</Description> | ||
<Nullable>enable</Nullable> | ||
<RootNamespace>Meadow.Foundation.Sensors.Temperature</RootNamespace> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression> | ||
<LangVersion>10.0</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<None Include="..\..\..\icon.png" Pack="true" PackagePath="" /> | ||
<ProjectReference Include="..\..\..\Meadow.Foundation.Core\Meadow.Foundation.Core.csproj" /> | ||
</ItemGroup> | ||
</Project> |
38 changes: 38 additions & 0 deletions
38
...ow.Foundation.Peripherals/Sensors.Temperature.Pct2075/Samples/Pct2075_Sample/MeadowApp.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using Meadow; | ||
using Meadow.Foundation.ICs.IOExpanders; | ||
using Meadow.Foundation.Sensors.Temperature; | ||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
|
||
namespace Sensors.Temperature.Pct2075_Sample; | ||
|
||
public class MeadowApp : App<Windows> | ||
{ | ||
//<!=SNIP=> | ||
private Ft232h _expander; | ||
private Pct2075 _sensor; | ||
|
||
public override Task Initialize() | ||
{ | ||
_expander = new Ft232h(false); | ||
_sensor = new Pct2075(_expander.CreateI2cBus()); | ||
|
||
_sensor.Updated += OnUpdated; | ||
_sensor.StartUpdating(TimeSpan.FromSeconds(1)); | ||
|
||
return base.Initialize(); | ||
} | ||
|
||
private void OnUpdated(object sender, IChangeResult<Meadow.Units.Temperature> e) | ||
{ | ||
Debug.WriteLine($"Temp: {e.New.Celsius:n1}C {e.New.Fahrenheit:n1}F"); | ||
} | ||
|
||
//<!=SNOP=> | ||
|
||
public static async Task Main(string[] args) | ||
{ | ||
await MeadowOS.Start(args); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...tion.Peripherals/Sensors.Temperature.Pct2075/Samples/Pct2075_Sample/Pct2075_Sample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.Foundation</RepositoryUrl> | ||
<Company>Wilderness Labs, Inc</Company> | ||
<Authors>Wilderness Labs, Inc</Authors> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
<TargetFramework>net7</TargetFramework> | ||
<OutputType>Exe</OutputType> | ||
<AssemblyName>App</AssemblyName> | ||
<LangVersion>10</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\..\..\..\Meadow.Contracts\Source\Meadow.Contracts\Meadow.Contracts.csproj" /> | ||
<ProjectReference Include="..\..\..\..\..\..\Meadow.Core\source\implementations\windows\Meadow.Windows\Meadow.Windows.csproj" /> | ||
<ProjectReference Include="..\..\..\..\..\..\Meadow.Core\source\Meadow.Core\Meadow.Core.csproj" /> | ||
<ProjectReference Include="..\..\..\..\..\..\Meadow.Logging\Source\Meadow.Logging\lib\Meadow.Logging.csproj" /> | ||
<ProjectReference Include="..\..\..\..\..\..\Meadow.Units\Source\Meadow.Units\Meadow.Units.csproj" /> | ||
<ProjectReference Include="..\..\..\ICs.IOExpanders.Ft232h\Driver\ICs.IOExpanders.Ft232h.csproj" /> | ||
<ProjectReference Include="..\..\Driver\Sensors.Temperature.Pct2075.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Update="meadow.config.yaml"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
2 changes: 2 additions & 0 deletions
2
...ndation.Peripherals/Sensors.Temperature.Pct2075/Samples/Pct2075_Sample/meadow.config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
MonoControl: | ||
Options: --jit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters