您的位置:首页 > 大数据 > 物联网

张高兴的 Windows 10 IoT 开发笔记:无线收发芯片 nRF24L01

2020-01-15 09:32 1166 查看

This is a Windows 10 IoT Core project on the Raspberry Pi 2/3, coded by C#.

GitHub:https://github.com/ZhangGaoxing/windows-iot-demo/tree/master/NRF24L01

Image

Connect

nRF1

  • VCC - 3.3V (Best)
  • GND - GND
  • MOSI - SPI0 MOSI (GPIO 10)
  • MISO - SPI0 MISO (GPIO 9)
  • SCK - SPI0 SCLK (GPIO 11)
  • CSN - SPI0 CS0 (GPIO 8)
  • CE - GPIO 23
  • IRQ - GPIO 24
  • nRF2
  • VCC - 3.3V (Best)
  • GND - GND
  • MOSI - SPI1 MOSI (GPIO 20)
  • MISO - SPI1 MISO (GPIO 19)
  • SCK - SPI1 SCLK (GPIO 21)
  • CSN - SPI1 CS0 (GPIO 16)
  • CE - GPIO 5
  • IRQ - GPIO 6

What Contains

In NRF24L01.cs file

/// <summary>
/// Initialize
/// </summary>
public async Task InitializeAsync();

/// <summary>
/// Send
/// </summary>
/// <param name="data">Data</param>
public async void Send(byte[] data);

/// <summary>
/// Receive
/// </summary>
/// <param name="length">Packet Size</param>
/// <returns>Data</returns>
public byte[] Receive(byte length);

......

How to Use

  • First, you need to create a NRF24L01 object. After that you should call InitializeAsync() to initialize.
// Create and Initialize
// CSN Pin, CE Pin, IRQ Pin, SPI Friendly Name, Receive Packet Size
NRF24L01 sender = new NRF24L01(0, 23, 24, "SPI0", 12);
NRF24L01 receiver = new NRF24L01(0, 5, 6, "SPI1", 12);

await sender.InitializeAsync();
await receiver.InitializeAsync();
  • Secondly
sender.Send(Encoding.UTF8.GetBytes("ZhangGaoxing"));
receiver.ReceivedData += Receiver_ReceivedData;

private void Receiver_ReceivedData(object sender, ReceivedDataEventArgs e)
{
var raw = e.Data.Skip(1).ToArray();
var res = Encoding.UTF8.GetString(raw);

Debug.Write("Received Raw Data : ");
foreach (var item in raw)
{
Debug.Write($"{item} ");
}
Debug.WriteLine("");
Debug.WriteLine($"Received Data : {res}");
}
  • If you want to close the sensor, call Dispose().
sender.Dispose();
receiver.Dispose();

转载于:https://www.cnblogs.com/zhanggaoxing/p/8444673.html

  • 点赞
  • 收藏
  • 分享
  • 文章举报
ahuihun5901 发布了0 篇原创文章 · 获赞 0 · 访问量 767 私信 关注
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: