c# .net iot树莓派(进口,贵)/香橙派(国产,功能相同,性价比高)用到物联网包Iot.Device.bindings 支持设备说明文档

我们c# .net iot开发树莓派/香橙派都需要用到Iot.Device.bindings、System.Device.Gpio和IotDeviceToolHepler这个包,c# .net 开发嵌入式 esp32 或者smt32就用nanoframework扩展,调用很简单方便,支持的硬件很多,用来做我们项目的产品完全没问题,所以这个包支持哪些设备我们先了解清楚,才进行下一步开发

nuget iot包:

e896f598c4594b51a8be00aab680ce92.png

Iot.Device.Bindings 支持的设备如下:

Iot.Device.xx

模拟/数字转换器

数字/模拟转换器

加速计

气体传感器

GNSS卫星接收器和导航设备

液体传感器

光敏感元件

气压计

高度计

温度计

红外传感器

陀螺仪

罗盘

乐高相关设备

电机控制器/驱动器

惯性测量单元

磁力计

湿度计

时钟

奏鸣曲

距离传感器

被动红外(运动)传感器

运动传感器

显示

GPIO扩展器

CAN总线库/模块

近程传感器

触摸传感器

无线通信模块

操纵杆

颜色传感器

LED驱动器

RFID/NFC模块

媒体库

USB设备

GPIO或bit操作设备

多设备或机器人套件

协议提供商/库

电源监视器和相关设备

挥发性有机化合物传感器

热电偶设备

重量传感器

 更详更新细见官网:iot/src/devices at main · dotnet/iot · GitHub

使用很简单---下面举个例子

演示一段 树莓派/香橙派Orange pi 通过i2c读取sht30温湿器的代码 

下载nuget包:Iot.Device.bindings

       using Iot.Device.Sht3x;
       using System.Device.I2c;        
        public void GetSht30()
        {

            I2cConnectionSettings set = new(1, (byte)OverWriteI2cAddress.AddrLow);
            I2cDevice dev = I2cDevice.Create(set);
            using Sht3x sht = new Sht3x(dev);       
            Console.WriteLine("温度:{0:N1} ℃\n湿度:{1:N1} %RH", sht.Temperature.DegreesCelsius, sht.Humidity.Percent);
           
        }
        enum OverWriteI2cAddress : byte
        {
            AddrLow = 0x44
        }
  

演示一段树莓派控制引脚代码:

下载nuget包:System.Device.Gpio

using System.Device.Gpio;      
public static void PinHightLow()
{   
        GpioController gpioController = new GpioController();           
        gpioController.OpenPin(8, PinMode.Output);//引脚8,设为输出模式
        gpioController.Write(8, PinValue.High); //引脚8,高电平
        Thread.Sleep(10000);
        gpioController.Write(8, PinValue.Low);//引脚8,低电平
        Thread.Sleep(10000);
}

演示一段香橙派控制引脚代码:

nuget安装包:IotDeviceToolHepler

开源地址:https://gitee.com/yihong-lin/IotDeviceForCsharp 

香橙派装好 wiringOp安装方法 看我之前发的安装教程文章

94a774ba1d904d05899a9e45d85b727f.png

 代码:

using IotDeviceToolHepler.WiringOPSharp;
public static string setGpioOutputMode()
        {

            Setup.WiringPiPiSetup();
            GPIO.PinMode(8, WiringPi.Output);//设置8引脚为输出模式
            GPIO.DigitalWrite(8, WiringPi.High);//8引脚高电平
            Thread.Sleep(10000);
            GPIO.DigitalWrite(8, WiringPi.Low);//8引脚低电平
            Thread.Sleep(10000);
          
        }

案例:

c# .net 6 香橙派orange pi读取温湿传感器 芯片sht30 I2C 代码实例代码

更多推荐