0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C#でIoTプログラミング on ESP32 #11 - BMP280

Posted at

気圧・温度センサーBMP280のサンプルプログラムの紹介です。

ハードウェア

・Freenove ESP32-S3-WROOM Board or Espressif ESP32-S3-DevKitC
・Adafruit Pressure Sensor BMP280

配線

BMP280.PNG

導入パッケージ

・nanoFramework.Hardware.Esp32
・nanoFramework.System.Device.I2c
・nanoFramework.Iot.Device.Bmxx80

プログラミング

Program.cs
using Iot.Device.Bmxx80;
using nanoFramework.Hardware.Esp32;
using System;
using System.Device.I2c;
using System.Threading;

namespace ESP32S3_BMP280
{
    public class Program
    {
        public static void Main()
        {
            Configuration.SetPinFunction(8, DeviceFunction.I2C1_DATA);
            Configuration.SetPinFunction(9, DeviceFunction.I2C1_CLOCK);

            I2cConnectionSettings settings = new(1, 0x76, I2cBusSpeed.FastMode);
            I2cDevice device = I2cDevice.Create(settings);
            using var bmp280 = new Bmp280(device);

            while (true)
            {
                bmp280.TemperatureSampling = Sampling.HighResolution;
                bmp280.PressureSampling = Sampling.HighResolution;
                var readResult = bmp280.Read();

                Console.WriteLine($"Temp: {readResult.Temperature.DegreesCelsius.ToString("F2")}℃, Pres: {readResult.Pressure.Hectopascals.ToString("F2")} hPs");

                Thread.Sleep(1000);
            }
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?