Skip to content

Instantly share code, notes, and snippets.

@hatsunea
Last active June 26, 2022 05:24
Show Gist options
  • Save hatsunea/972797f2c87727505cda533ac3a1d7f8 to your computer and use it in GitHub Desktop.
Save hatsunea/972797f2c87727505cda533ac3a1d7f8 to your computer and use it in GitHub Desktop.
using Iot.Device.Bmxx80;
using Iot.Device.Sht3x;
using nanoFramework.M5Stack;
using nanoFramework.Presentation.Media;
using System;
using System.Threading;
using Console = nanoFramework.M5Stack.Console;
namespace ENV2Sample
{
public class Program
{
private static Bmp280 Bmp;
private static Sht3x Sht;
public static void Main()
{
try
{
Setup();
Loop();
}
catch (Exception ex)
{
Console.WriteLine($"Could not find a valid ENV-II sensor, check wiring! {ex.Message}");
}
}
private static void Setup()
{
M5Core2.InitializeScreen();
Console.Clear();
Console.ForegroundColor = Color.White;
Console.WriteLine("ENV.II Unit test...");
// PORT A (i2C)
Bmp = new(M5Core2.GetI2cDevice(0x76))
{
TemperatureSampling = Sampling.LowPower,
PressureSampling = Sampling.UltraHighResolution,
};
Bmp.SetPowerMode(Iot.Device.Bmxx80.PowerMode.Bmx280PowerMode.Normal);
Sht = new(M5Core2.GetI2cDevice(0x44))
{
Resolution = Resolution.High,
};
}
private static void Loop()
{
Console.ForegroundColor = Color.White;
Console.BackgroundColor = Color.Black;
UnitsNet.Pressure pressure;
while (true)
{
try
{
Console.CursorTop = 0;
Console.CursorLeft = 0;
Console.WriteLine($"DateTime:{DateTime.UtcNow:yyyyMMdd HHmmss}");
if (Bmp.TryReadPressure(out pressure))
{
Console.WriteLine($"Pressure:{pressure.Hectopascals:F} hPa");
}
Console.WriteLine($"Temperature:{Sht.Temperature.DegreesCelsius:F} C");
Console.WriteLine($"Humidity:{Sht.Humidity.Percent:F} %");
Thread.Sleep(1000);
}
catch
{ }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment