public MeadowApp() { led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue); led.SetColor(RgbLed.Colors.Red); var config = new SpiClockConfiguration(10000000, SpiClockConfiguration.Mode.Mode0); ISpiBus spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); radio = new Nrf24l01( device: Device, spiBus: spiBus, chipEnablePin: Device.Pins.D13, chipSelectLine: Device.Pins.D12, interruptPin: Device.Pins.D00); radio.SetChannel(76); radio.OpenWritingPipe(Encoding.UTF8.GetBytes(address)); radio.SetPALevel(0); radio.StopListening(); led.SetColor(RgbLed.Colors.Green); while (true) { string helloWorld = "Hello World"; radio.Write(Encoding.UTF8.GetBytes(helloWorld), (byte)(helloWorld.Length)); Console.WriteLine($"Sending: {helloWorld} \n"); Thread.Sleep(1000); } }
static async Task TxApp() { var board = await ConnectionService.Instance.GetFirstDeviceAsync(); await board.ConnectAsync(); var rf = new Nrf24l01(board.Spi, board.Pins[3], board.Pins[4], board.Pins[5]); rf.TxAddress = 0xC2C2C2; rf.Pipes[0].Address = 0xC2C2C2; rf.AddressWidth = 3; rf.RetryCount = 5; rf.RetryDelayUs = 1500; rf.Channel = 9; rf.Rate = Nrf24l01.DataRate.Rate_250kbps; while (true) { for (int i = 0; i < 255; i++) { await rf.Transmit(new byte[] { (byte)i, 0x00, 0x23, 0x37, 0x37, 0x13 }, false); await Task.Delay(100); } } }
public MeadowApp() { led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue); led.SetColor(RgbLed.Colors.Red); var config = new SpiClockConfiguration(10000000, SpiClockConfiguration.Mode.Mode0); ISpiBus spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); radio = new Nrf24l01( device: Device, spiBus: spiBus, chipEnablePin: Device.Pins.D13, chipSelectLine: Device.Pins.D12, interruptPin: Device.Pins.D00); radio.SetChannel(76); radio.OpenReadingPipe(0, Encoding.UTF8.GetBytes(address)); radio.SetPALevel(0); radio.StartListening(); led.SetColor(RgbLed.Colors.Green); byte[] text = new byte[32]; while (true) { if (radio.IsAvailable()) { radio.Read(text, (byte)text.Length); Thread.Sleep(1000); } } }
static void Main(string[] args) { // SPI0 CS0 SpiConnectionSettings senderSettings = new SpiConnectionSettings(0, 0) { ClockFrequency = Nrf24l01.SpiClockFrequency, Mode = Nrf24l01.SpiMode }; // SPI1 CS0 SpiConnectionSettings receiverSettings = new SpiConnectionSettings(1, 2) { ClockFrequency = Nrf24l01.SpiClockFrequency, Mode = Nrf24l01.SpiMode }; var senderDevice = SpiDevice.Create(senderSettings); var receiverDevice = SpiDevice.Create(receiverSettings); // SPI Device, CE Pin, IRQ Pin, Receive Packet Size using (Nrf24l01 sender = new Nrf24l01(senderDevice, 23, 24, 20)) { using (Nrf24l01 receiver = new Nrf24l01(receiverDevice, 5, 6, 20)) { // Set sender send address, receiver pipe0 address (Optional) byte[] receiverAddress = Encoding.UTF8.GetBytes("NRF24"); sender.Address = receiverAddress; receiver.Pipe0.Address = receiverAddress; // Binding DataReceived event receiver.DataReceived += Receiver_ReceivedData; // Loop while (true) { sender.Send(Encoding.UTF8.GetBytes("Hello! .NET Core IoT")); Thread.Sleep(2000); } } } }
static async Task RxApp() { var board = await ConnectionService.Instance.GetFirstDeviceAsync(); await board.ConnectAsync(); var rf = new Nrf24l01(board.Spi, board.Pins[3], board.Pins[4], board.Pins[5]); rf.AddressWidth = 3; rf.TxAddress = 0xC2C2C2; rf.Pipes[0].Address = 0xC2C2C2; rf.Pipes[0].EnablePipe = true; rf.Pipes[1].Address = 0xC2C2C3; rf.Pipes[1].EnablePipe = true; rf.Pipes[2].Address = 0xC2C2C4; rf.Pipes[2].EnablePipe = true; rf.Pipes[3].Address = 0xC2C2C5; rf.Pipes[3].EnablePipe = true; rf.RetryCount = 5; rf.RetryDelayUs = 1500; rf.Channel = 9; rf.Rate = Nrf24l01.DataRate.Rate_250kbps; rf.RxEnable = true; rf.Pipes[1].DataReceived += Program_DataReceived1; rf.Pipes[2].DataReceived += Program_DataReceived2; rf.Pipes[3].DataReceived += Program_DataReceived3; while (true) { for (int i = 0; i < 255; i++) { await Task.Delay(100); } } }