Beispiel #1
0
        public Rfm9XDevice(int spiBusId, int chipSelectPin, int resetPin, int interruptPin)
        {
            var settings = new SpiConnectionSettings(spiBusId, chipSelectPin)
            {
                ClockFrequency = 500000,
                //DataBitLength = 8,
                Mode        = SpiMode.Mode0,// From SemTech docs pg 80 CPOL=0, CPHA=0
                SharingMode = SpiSharingMode.Shared,
            };

            rfm9XLoraModem = new SpiDevice(settings);

            gpioController = new GpioController();

            // Factory reset pin configuration
            GpioPin resetGpioPin = gpioController.OpenPin(resetPin);

            resetGpioPin.SetPinMode(PinMode.Output);
            resetGpioPin.Write(PinValue.Low);
            Thread.Sleep(10);
            resetGpioPin.Write(PinValue.High);
            Thread.Sleep(10);

            // Interrupt pin for RX message & TX done notification
            gpioController.OpenPin(interruptPin, PinMode.InputPullDown);

            gpioController.RegisterCallbackForPinValueChangedEvent(interruptPin, PinEventTypes.Rising, InterruptGpioPin_ValueChanged);
        }
        /// <summary>
        /// Add a GPIO pin as a specific Button
        /// </summary>
        /// <param name="gpioPinNumber">GPIO pin number</param>
        /// <param name="button">Button that this pin represents</param>
        /// <param name="internalPullup">If true will enable the internal pull up on pin ( SetDriveMode = InputPullUp )
        public void AddButton(int gpioPinNumber, Button button, bool internalPullup)
        {
            GpioPin pin = Gpio.OpenPin(gpioPinNumber);


            pin.SetPinMode(internalPullup ? PinMode.InputPullUp : PinMode.Input);
            pin.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 50);

            this.buttons.Add(new ButtonPad(this, button, pin));
        }
Beispiel #3
0
        // TODO: is loader button a thing?



        public Buttons()
        {
            //// the buttons are multiplexed so that the board can be woken up by user, or by the RTC
            //// so to get that interrupt to fire you need to do this:
            //// TODO: work out which buttons and why!
            _muxWakeButtonFlowControl = new GpioController().OpenPin(Pinout.GpioPin.MUX_EXT_BUTTON_WAKE_PE4);
            _muxWakeButtonFlowControl.SetPinMode(PinMode.Output);
            _muxWakeButtonFlowControl.Write(PinValue.High);
            //_muxWakeButtonFlowControl.ValueChanged += MuxWakeButtonFlowControl_ValueChanged;

            _userButton        = new GpioButton(buttonPin: Pinout.GpioPin.BUTTON_USER_BOOT1_PK7);
            _userButton.Press += _userButton_Press;

            _wakeButton        = new GpioButton(buttonPin: Pinout.GpioPin.BUTTON_WAKE_PA0);
            _wakeButton.Press += WakeButton_Press;

            _diagnosticButton        = new GpioButton(buttonPin: Pinout.GpioPin.BUTTON_DIAGNOSTIC_PB7);
            _diagnosticButton.Press += DiagnosticButton_Press;
        }
Beispiel #4
0
        public Rfm9XDevice(int spiBusId, int chipSelectPin, int resetPin)
        {
            var settings = new SpiConnectionSettings(spiBusId, chipSelectPin)
            {
                ClockFrequency = 1000000,
                Mode           = SpiMode.Mode0,// From SemTech docs pg 80 CPOL=0, CPHA=0
                SharingMode    = SpiSharingMode.Shared
            };

            rfm9XLoraModem = new SpiDevice(settings);

            // Factory reset pin configuration
            GpioController gpioController = new GpioController();
            GpioPin        resetGpioPin   = gpioController.OpenPin(resetPin);

            resetGpioPin.SetPinMode(PinMode.Output);
            resetGpioPin.Write(PinValue.Low);
            Thread.Sleep(10);
            resetGpioPin.Write(PinValue.High);
            Thread.Sleep(10);
        }
Beispiel #5
0
 public LedBlinker(int PinNumber)
 {
     _ledPin = Default.OpenPin(PinNumber);
     _ledPin.SetPinMode(PinMode.Output);
     _onboardBlinkTimer = new Timer(ShutdownTimerCallback, _ledPin, Timeout.Infinite, Timeout.Infinite);
 }
Beispiel #6
0
        static void Main()
        {
            byte MessageCount = System.Byte.MaxValue;

#if ST_STM32F429I_DISCOVERY
            int ledPinNumber        = PinNumber('G', 14);
            int chipSelectPinNumber = PinNumber('C', 2);
            int resetPinNumber      = PinNumber('C', 3);
            int interruptPinNumber  = PinNumber('A', 4);
#endif
#if ESP32_WROOM_32_LORA_1_CHANNEL
            int ledPinNumber        = Gpio.IO17;
            int chipSelectPinNumber = Gpio.IO16;
            int interruptPinNumber  = Gpio.IO26;

            Configuration.SetPinFunction(Gpio.IO12, DeviceFunction.SPI1_MISO);
            Configuration.SetPinFunction(Gpio.IO13, DeviceFunction.SPI1_MOSI);
            Configuration.SetPinFunction(Gpio.IO14, DeviceFunction.SPI1_CLOCK);

            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, interruptPinNumber);
#endif
#if NETDUINO3_WIFI
            int ledPinNumber = PinNumber('A', 10);
            // Arduino D10->PB10
            int chipSelectPinNumber = PinNumber('B', 10);
            // Arduino D9->PE5
            int resetPinNumber = PinNumber('E', 5);
            // Arduino D2->PA3
            int interruptPinNumber = PinNumber('A', 3);
#endif
            Debug.WriteLine("devMobile.IoT.Rfm9x.LoRaDeviceClient starting");

            GpioController gpioController = new GpioController();

            led = gpioController.OpenPin(ledPinNumber);
            led.SetPinMode(PinMode.Output);
            led.Write(PinValue.Low);

#if ST_STM32F429I_DISCOVERY || NETDUINO3_WIFI
            Rfm9XDevice rfm9XDevice = new Rfm9XDevice(SpiBusId, chipSelectPinNumber, resetPinNumber, interruptPinNumber);
#endif
            rfm9XDevice.Initialise(Frequency
                                   , rxPayloadCrcOn: true
                                   );

#if DEBUG
            rfm9XDevice.RegisterDump();
#endif

            rfm9XDevice.OnReceive += Rfm9XDevice_OnReceive;
#if ADDRESSED_MESSAGES_PAYLOAD
            rfm9XDevice.Receive(UTF8Encoding.UTF8.GetBytes(DeviceName));
#else
            rfm9XDevice.Receive();
#endif
            rfm9XDevice.OnTransmit += Rfm9XDevice_OnTransmit;

            Thread.Sleep(10000);

            while (true)
            {
                string messageText = string.Format("Hello from {0} ! {1}", DeviceName, MessageCount);
                MessageCount -= 1;

                byte[] messageBytes = UTF8Encoding.UTF8.GetBytes(messageText);
                Debug.WriteLine(string.Format("{0}-TX {1} byte message {2}", DateTime.UtcNow.ToString("HH:mm:ss"), messageBytes.Length, messageText));
#if ADDRESSED_MESSAGES_PAYLOAD
                rfm9XDevice.Send(UTF8Encoding.UTF8.GetBytes(HostName), messageBytes);
#else
                rfm9XDevice.Send(messageBytes);
#endif
                Thread.Sleep(10000);
            }
        }
Beispiel #7
0
        public static void Main()
        {
            GpioController gpioController = new GpioController();

#if ESP32_WROOM_32_LORA_1_CHANNEL // No reset line for this device as it isn't connected on SX127X
            int ledPinNumber        = Gpio.IO17;
            int chipSelectPinNumber = Gpio.IO16;
#endif
#if NETDUINO3_WIFI
            int ledPinNumber = PinNumber('A', 10);
            // Arduino D10->PB10
            int chipSelectPinNumber = PinNumber('B', 10);
            // Arduino D9->PE5
            int resetPinNumber = PinNumber('E', 5);
#endif
#if MBN_QUAIL
            int ledPinNumber = PinNumber('E', 15);
#if MBN_QUAIL_SOCKET1
            // CS on socket 1
            int chipSelectPinNumber = PinNumber('A', 3);
            // RST on socket 1
            int resetPinNumber = PinNumber('A', 2);
#endif
#if MBN_QUAIL_SOCKET2
            // CS on socket 2
            int chipSelectPinNumber = PinNumber('E', 0);

            // RST on socket 2
            int resetPinNumber = PinNumber('E', 1);
#endif
#if MBN_QUAIL_SOCKET3
            // CS on socket 3
            int chipSelectPinNumber = PinNumber('D', 11);

            // RST on socket 3
            int resetPinNumber = PinNumber('D', 12);
#endif
#if MBN_QUAIL_SOCKET4
            // CS on socket 4
            int chipSelectPinNumber = PinNumber('D', 1);

            // RST on socket 4
            int resetPinNumber = PinNumber('D', 0);
#endif
#endif
#if ST_NUCLEO64_F091RC // No LED for this device as driven by D13 the SPI CLK line
            // Arduino D10->PB6
            int chipSelectPinNumber = PinNumber('B', 6);
            // Arduino D9->PC7
            int resetPinNumber = PinNumber('C', 7);
#endif
#if ST_STM32F429I_DISCOVERY // No reset line for this device as I didn't bother with jumper to SX127X pin
            int ledPinNumber        = PinNumber('G', 14);
            int chipSelectPinNumber = PinNumber('C', 2);
#endif
#if ST_NUCLEO144_F746ZG
            int ledPinNumber = PinNumber('B', 7);
            // Arduino D10->PD14
            int chipSelectPinNumber = PinNumber('D', 14);
            // Arduino D9->PD15
            int resetPinNumber = PinNumber('D', 15);
#endif
#if ST_STM32F769I_DISCOVERY
            int ledPinNumber = PinNumber('J', 5);
            // Arduino D10->PA11
            int chipSelectPinNumber = PinNumber('A', 11);
            // Arduino D9->PH6
            int resetPinNumber = PinNumber('H', 6);
#endif
            Debug.WriteLine("devMobile.IoT.Rfm9x.ShieldSPI starting");

            try
            {
#if NETDUINO3_WIFI || MBN_QUAIL || ST_NUCLEO64_F091RC || ST_NUCLEO144_F746ZG || ST_STM32F769I_DISCOVERY
                // Setup the reset pin
                GpioPin resetGpioPin = gpioController.OpenPin(resetPinNumber);
                resetGpioPin.SetPinMode(PinMode.Output);
                resetGpioPin.Write(PinValue.High);
#endif

#if ESP32_WROOM_32_LORA_1_CHANNEL || MBN_QUAIL || NETDUINO3_WIFI || ST_NUCLEO144_F746ZG || ST_STM32F429I_DISCOVERY || ST_STM32F769I_DISCOVERY
                // Setup the onboard LED
                GpioPin led = gpioController.OpenPin(ledPinNumber);
                led.SetPinMode(PinMode.Output);
#endif

#if ESP32_WROOM_32_LORA_1_CHANNEL
                Configuration.SetPinFunction(nanoFramework.Hardware.Esp32.Gpio.IO12, DeviceFunction.SPI1_MISO);
                Configuration.SetPinFunction(nanoFramework.Hardware.Esp32.Gpio.IO13, DeviceFunction.SPI1_MOSI);
                Configuration.SetPinFunction(nanoFramework.Hardware.Esp32.Gpio.IO14, DeviceFunction.SPI1_CLOCK);
#endif

                var settings = new SpiConnectionSettings(SpiBusId, chipSelectPinNumber)
                {
                    ClockFrequency = 500000,
                    Mode           = SpiMode.Mode0,// From SemTech docs pg 80 CPOL=0, CPHA=0
                    SharingMode    = SpiSharingMode.Shared,
                };

                using (SpiDevice device = SpiDevice.Create(settings))
                {
                    Thread.Sleep(500);

                    while (true)
                    {
                        byte[] writeBuffer = new byte[] { RegVersion, 0x0 };
                        byte[] readBuffer  = new byte[writeBuffer.Length];

                        device.TransferFullDuplex(writeBuffer, readBuffer);

                        Debug.WriteLine(String.Format("Register 0x{0:x2} - Value 0X{1:x2}", RegVersion, readBuffer[1]));

#if ESP32_WROOM_32_LORA_1_CHANNEL || MBN_QUAIL || NETDUINO3_WIFI || ST_NUCLEO144_F746ZG || ST_STM32F429I_DISCOVERY || ST_STM32F769I_DISCOVERY
                        led.Toggle();
#endif
                        Thread.Sleep(10000);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }