Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set voltage references to report actual Battery and Solar voltages on Clima V4.b inputs #54

Merged
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
24 changes: 22 additions & 2 deletions Source/Meadow.Clima/ClimaHardwareV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Meadow.Foundation.Sensors.Weather;
using Meadow.Hardware;
using Meadow.Logging;
using Meadow.Units;
using System;

#nullable enable
Expand Down Expand Up @@ -79,6 +80,20 @@
/// </summary>
protected Logger? Logger { get; } = Resolver.Log;

/// <summary>
/// Analog inputs to measure Solar voltage has Resistor Divider with R1 = 1000 Ohm, R2 = 680 Ohm
/// Measured analogue voltage needs to be scaled to RETURN actual input voltage
/// Input Voltage = AIN / Resistor Divider
/// </summary>
protected const double SolarVoltageResistorDivider = 680 / (1000 + 680);

/// <summary>
/// Analog inputs to measure Solar voltage has Resistor Divider with R1 = 1000 Ohm, R2 = 680 Ohm
/// Measured analogue voltage needs to be scaled to RETURN actual input voltage
/// Input Voltage = AIN / Resistor Divider
/// </summary>
protected const double BatteryVoltageResistorDivider = 2000 / (1000 + 2000);

/// <summary>
/// Create a new ClimaHardwareV3 object
/// </summary>
Expand Down Expand Up @@ -109,7 +124,7 @@
Logger?.Info("Mcp Version up");
}
catch (Exception e)
{

Check warning on line 127 in Source/Meadow.Clima/ClimaHardwareV3.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'serialPortName' in 'NeoM8.NeoM8(IMeadowDevice device, SerialPortName serialPortName, IPin? resetPin, IPin? ppsPin = null)'.
Logger?.Trace($"ERR creating the MCP that has version information: {e.Message}");
}

Expand Down Expand Up @@ -182,7 +197,9 @@
try
{
Logger?.Trace("Instantiating Solar Voltage Input");
SolarVoltageInput = device.Pins.A02.CreateAnalogInputPort(5);
SolarVoltageInput = device.Pins.A02.CreateAnalogInputPort(5,
AnalogInputPort.DefaultSampleInterval,
AnalogInputPort.DefaultReferenceVoltage / SolarVoltageResistorDivider);
Logger?.Trace("Solar Voltage Input up");
}
catch (Exception ex)
Expand All @@ -193,7 +210,10 @@
try
{
Logger?.Trace("Instantiating Battery Voltage Input");
BatteryVoltageInput = device.Pins.A04.CreateAnalogInputPort(5);
BatteryVoltageInput = device.Pins.A04.CreateAnalogInputPort(5,
AnalogInputPort.DefaultSampleInterval,
AnalogInputPort.DefaultReferenceVoltage / BatteryVoltageResistorDivider);

Logger?.Trace("Battery Voltage Input up");
}
catch (Exception ex)
Expand Down
Loading