示例#1
0
        static void initRadio(SSD1306Driver oledScreen)
        {
            //Set LoRa Pins
            byte MessageCount        = System.Byte.MaxValue;
            int  chipSelectPinNumber = Gpio.IO18;
            int  interruptPinNumber  = Gpio.IO26;
            int  resetPinNumber      = Gpio.IO14;

            Configuration.SetPinFunction(Gpio.IO19, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(Gpio.IO27, DeviceFunction.SPI1_MOSI);
            Configuration.SetPinFunction(Gpio.IO05, DeviceFunction.SPI1_CLOCK);

            //Initialize Modem - BEEEEEEEEEEEEEEEEEEEEEEP.......BUUUUUUUUUUUUUUUUUUUUUR....................WEEEEDOOOOWEEEEEDOOO.................SKRRRRRRRRRRRRRRRRRR
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, resetPinNumber, interruptPinNumber);

            oledScreen.DrawString(0, 20, "Success.......");
            oledScreen.RefreshDisplay();
            rfm9XDevice.Initialise(Frequency, paBoost: true);
            oledScreen.DrawString(0, 30, "Powering Radio On.......");
            oledScreen.RefreshDisplay();
            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
            rfm9XDevice.Receive();
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            //LED INIT - Not required, just gave me something to see in my peripheral so I did not have to read the OLED all the time
            GpioController gpioc = new GpioController();
            GpioPin        led   = gpioc.OpenPin(OnBoardDevicePortNumber.Led, PinMode.Output);

            led.Write(PinValue.High);

            Thread.Sleep(5000); //Too fast and we reset

            int count = 0;

            while (true) //Send a message and update the OLED
            {
                string messageText = $"Hello from {DeviceName} ! {MessageCount}";
                MessageCount -= 1;
                count++;
                oledScreen.Clear();
                oledScreen.DrawString(0, 0, "Transmitting....");
                oledScreen.DrawString(0, 10, "Messages Sent: " + count.ToString());
                oledScreen.RefreshDisplay();
                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss}-TX {messageBytes.Length} byte message {messageText}");
                rfm9XDevice.Send(messageBytes);
                Thread.Sleep(1000);
                led.Toggle();
            }
        }
示例#2
0
        public void Begin()
        {
            this.PowerON();
            this.Reset();

            // Configuration of I2C1 bus for onboard LED
            Configuration.SetPinFunction(OnBoardOled.Data, DeviceFunction.I2C1_DATA);
            Configuration.SetPinFunction(OnBoardOled.Clock, DeviceFunction.I2C1_CLOCK);

            i2cBusSSD1306 = I2cDevice.Create(new I2cConnectionSettings(1, OnBoardOled.I2CAddress, I2cBusSpeed.FastMode));

            ssd1306 = new SSD1306Driver(i2cBusSSD1306, oledReset, 50 /* Heltec onboard oled support 0ms */);

            ssd1306.Init();
            //ssd1306.FlipScreenVertically();
            ssd1306.RefreshDisplay();
        }