Skip to content

Instantly share code, notes, and snippets.

@hatsunea
Created June 25, 2022 12:22
Show Gist options
  • Save hatsunea/a8e5e1445efdbf65f4a00a8e6637f10a to your computer and use it in GitHub Desktop.
Save hatsunea/a8e5e1445efdbf65f4a00a8e6637f10a to your computer and use it in GitHub Desktop.
using Iot.Device.Bmxx80;
using nanoFramework.M5Stack;
using nanoFramework.Presentation.Media;
using System;
using System.Threading;
using Console = nanoFramework.M5Stack.Console;
namespace BMP280Sample
{
public class Program
{
private static Bmp280 Bmp;
public static void Main()
{
try
{
Setup();
Loop();
}
catch (Exception ex)
{
Console.WriteLine($"Could not find a valid BMP280 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 Bmp280(M5Core2.GetI2cDevice(0x76))
{
TemperatureSampling = Sampling.LowPower,
PressureSampling = Sampling.UltraHighResolution,
};
}
private static void Loop()
{
while (true)
{
UnitsNet.Pressure pressure;
if (Bmp.TryReadPressure(out pressure))
{
Console.CursorTop = 0;
Console.CursorLeft = 0;
Console.ForegroundColor = Color.White;
Console.BackgroundColor = Color.Black;
Console.WriteLine($"DateTime:{DateTime.UtcNow:yyyyMMdd HHmmss}");
Console.WriteLine($"Pressure:{pressure.Hectopascals:F}hPa");
Thread.Sleep(1000);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment