Exemplo n.º 1
0
        public static void Main()
        {
            // mind to set a pin that exists on the board being tested
            // PJ5 is LD2 in STM32F769I_DISCO
            GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('J', 5));

            // PD15 is LED6 in DISCOVERY4
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('D', 15));
            // PG14 is LEDLD4 in F429I_DISCO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));
            // PE15 is LED1 in QUAIL
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('E', 15));
            // PB75 is LED2 in STM32F746_NUCLEO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('B', 7));
            // 4 is a valid GPIO pin in ESP32 DevKit
            //GpioPin led = GpioController.GetDefault().OpenPin(4);
            // PA5 is LED_GREEN in STM32F091RC
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));
            // PA5 is LD2 in STM32L072Z_LRWAN1
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));

            led.SetDriveMode(GpioPinDriveMode.Output);

            while (true)
            {
                led.Write(GpioPinValue.High);
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(525);
            }
        }
Exemplo n.º 2
0
        public static void Main()
        {
            s_GpioController = new GpioController();

            // pick a board, uncomment one line for GpioPin; default is STM32F769I_DISCO

            // DISCOVERY4: PD15 is LED6
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('D', 15));

            // ESP32 DevKit: 4 is a valid GPIO pin in, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
            //GpioPin led = GpioController.GetDefault().OpenPin(4);

            // F429I_DISCO: PG14 is LEDLD4
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));

            // NETDUINO 3 Wifi: A10 is LED onboard blue
            // GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 10));

            // QUAIL: PE15 is LED1
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('E', 15));

            // STM32F091RC: PA5 is LED_GREEN
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));

            // STM32F746_NUCLEO: PB75 is LED2
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('B', 7));

            // STM32F769I_DISCO: PJ5 is LD2
            GpioPin led = s_GpioController.OpenPin(
                PinNumber('J', 5),
                PinMode.Output);

            // STM32L072Z_LRWAN1: PA5 is LD2
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));

            // TI CC13x2 Launchpad: DIO_07 it's the green LED
            //GpioPin led = GpioController.GetDefault().OpenPin(7);

            // TI CC13x2 Launchpad: DIO_06 it's the red LED
            //GpioPin led = GpioController.GetDefault().OpenPin(6);

            // ULX3S FPGA board: for the red D22 LED from the ESP32-WROOM32, GPIO5
            //GpioPin led = GpioController.GetDefault().OpenPin(5);


            led.Write(PinValue.Low);

            while (true)
            {
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(525);
            }
        }
Exemplo n.º 3
0
        public static void Main()
        {
            // mind to set a pin that exists on the board being tested
            // PJ5 is LD2 in STM32F769I_DISCO
            GpioPin led = GpioController.GetDefault().OpenPin(Boards.Netduino3.GpioPin.Led);
            // PD15 is LED6 in DISCOVERY4
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('D', 15));
            // PG14 is LEDLD4 in F429I_DISCO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));
            // PE15 is LED1 in QUAIL
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('E', 15));
            // PB75 is LED2 in STM32F746_NUCLEO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('B', 7));
            // 4 is a valid GPIO pin in ESP32 DevKit
            //GpioPin led = GpioController.GetDefault().OpenPin(Boards.Espectro32.GpioPin.BoardLed);
            // PA5 is LED_GREEN in STM32F091RC
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));
            // PA5 is LD2 in STM32L072Z_LRWAN1
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));
            RotaryAngleSensor rotary = new RotaryAngleSensor(1);

            led.SetDriveMode(GpioPinDriveMode.Output);
            Button btn = new Button(Boards.Netduino3.GpioPin.D4);

            btn.ButtonReleased += Btn_ButtonReleased;
            while (true)
            {
                if (btn.IsPressed())
                {
                    Console.WriteLine("button di tekan");
                }
                else
                {
                    Console.WriteLine("button di lepas");
                }
                var angle = rotary.GetAngle();
                Console.WriteLine("angle :" + angle);
                led.Write(GpioPinValue.High);
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(525);

                Console.WriteLine("Hello from nanoFramework!");
            }
        }
        private static void Dth12Test()
        {
            Dht12       dht = new Dht12(19);
            Temperature temp;
            Ratio       hum;
            GpioPin     led = GpioController.GetDefault().OpenPin(2);

            led.SetDriveMode(GpioPinDriveMode.Output);
            led.Write(GpioPinValue.High);

            while (true)
            {
                hum  = dht.Humidity;
                temp = dht.Temperature;
                if (dht.IsLastReadSuccessful)
                {
                    Debug.WriteLine($"Hum: {hum.Percent} %, Temp: {temp.DegreesCelsius} °C");

                    for (int i = 0; i < 5; i++)
                    {
                        Thread.Sleep(500);
                        led.Toggle();
                    }
                }
                else
                {
                    Debug.WriteLine("error reading dht");
                    led.Write(GpioPinValue.High);
                }

                Thread.Sleep(1000);
            }
        }
        private static void HscGpioCore()
        {
            Hcsr04GpioCore sonar = new Hcsr04GpioCore(16, 17);
            GpioPin        led   = GpioController.GetDefault().OpenPin(2);

            led.SetDriveMode(GpioPinDriveMode.Output);
            led.Write(GpioPinValue.High);
            double dist;

            while (true)
            {
                try
                {
                    dist = sonar.Distance.Centimeters;
                    Debug.WriteLine($"Distance: {dist} cm");
                    if (dist < 5)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            Thread.Sleep(500);
                            led.Toggle();
                        }
                    }
                }
                catch (Exception)
                {
                    Debug.WriteLine($"Exception");
                }
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 6
0
        private static void Rfm9XDevice_OnReceive(object sender, Rfm9XDevice.OnDataReceivedEventArgs e)
        {
            led.Toggle();

            try
            {
                // Remove unprintable characters from messages
                for (int index = 0; index < e.Data.Length; index++)
                {
                    if ((e.Data[index] < 0x20) || (e.Data[index] > 0x7E))
                    {
                        e.Data[index] = 0x20;
                    }
                }

                string messageText = UTF8Encoding.UTF8.GetString(e.Data, 0, e.Data.Length);

#if ADDRESSED_MESSAGES_PAYLOAD
                string addressText = UTF8Encoding.UTF8.GetString(e.Address, 0, e.Address.Length);

                Debug.WriteLine(string.Format(@"{0}-RX From {1} PacketSnr {2} Packet RSSI {3}dBm RSSI {4}dBm ={5} ""{6}""", DateTime.UtcNow.ToString("HH:mm:ss"), addressText, e.PacketSnr, e.PacketRssi, e.Rssi, e.Data.Length, messageText));
#else
                Debug.WriteLine(string.Format(@"{0}-RX PacketSnr {1} Packet RSSI {2}dBm RSSI {3}dBm ={4} ""{5}""", DateTime.UtcNow.ToString("HH:mm:ss"), e.PacketSnr, e.PacketRssi, e.Rssi, e.Data.Length, messageText));
#endif
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Exemplo n.º 7
0
 static void BlinkLED()
 {
     // blink led for each message received
     _led.Write(GpioPinValue.High);
     Thread.Sleep(500);
     _led.Toggle();
 }
Exemplo n.º 8
0
        public static void Main()
        {
            _randomizer = new Random();

            // timer start times (all timers are due to start in the first 2 seconds)
            int start0 = _randomizer.Next(1000 * 2);
            int start1 = _randomizer.Next(1000 * 2);
            int start2 = _randomizer.Next(1000 * 2);
            int start3 = _randomizer.Next(1000 * 2);
            int start4 = _randomizer.Next(1000 * 2);
            int start5 = _randomizer.Next(1000 * 2);


            // timer intervals
            // half of the timers will have a short period
            int period0 = _randomizer.Next(1000);
            int period1 = _randomizer.Next(1000);
            int period2 = _randomizer.Next(1000);

            // the other half of the timers will have a long period
            int period3 = _randomizer.Next(1000 * 3);
            int period4 = _randomizer.Next(1000 * 3);
            int period5 = _randomizer.Next(1000 * 3);

            _led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));
            _led.SetDriveMode(GpioPinDriveMode.Output);

            // quick timers

            Console.WriteLine("Starting timer 0 with " + period0 + "ms period, due in " + start0 + "ms.");
            _timer0 = new Timer(new TimerCallback(TimerHandler0), null, start0, period0);
            Thread.Sleep(1);

            Console.WriteLine("Starting timer 1 with " + period1 + "ms period, due in " + start1 + "ms.");
            _timer1 = new Timer(new TimerCallback(TimerHandler1), null, start1, period1);
            Thread.Sleep(1);

            Console.WriteLine("Starting timer 2 with " + period2 + "ms period, due in " + start2 + "ms.");
            _timer2 = new Timer(new TimerCallback(TimerHandler2), null, start2, period2);
            Thread.Sleep(1);

            // long timers
            Console.WriteLine("Starting timer 3 with " + period3 + "ms period, due in " + start3 + "ms.");
            _timer3 = new Timer(new TimerCallback(TimerHandler0), null, start3, period3);
            Thread.Sleep(1);

            Console.WriteLine("Starting timer 4 with " + period4 + "ms period, due in " + start4 + "ms.");
            _timer4 = new Timer(new TimerCallback(TimerHandler1), null, start4, period4);
            Thread.Sleep(1);

            Console.WriteLine("Starting timer 5 with " + period5 + "ms period, due in " + start5 + "ms.");
            _timer5 = new Timer(new TimerCallback(TimerHandler2), null, start5, period5);
            Thread.Sleep(1);

            for (; ;)
            {
                Thread.Sleep(100);
                _led.Toggle();
            }
        }
Exemplo n.º 9
0
        public static void Main()
        {
            // How to set Alternate pins for Devices ( COM1/2/3, SPI1/2, I2C, PWM ) then open device as normal
            //UART1
            //Configuration.SetPinFunction(9, DeviceFunction.COM1_RX);
            //Configuration.SetPinFunction(10, DeviceFunction.COM1_TX);
            //I2C
            //Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK); //I2C1 SCL
            //Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);  //I2C1 SDA
            //SPI1
            //Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
            //Configuration.SetPinFunction(19, DeviceFunction.SPI1_MISI);
            //Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
            //PWM
            //Configuration.SetPinFunction(36, DeviceFunction.PWM1);

            //======================================================//
            // 2 is a valid LED GPIO pin in ESP32S NodeMCU v1.1 DoIt
            //======================================================//

            GpioPin led = GpioController.GetDefault().OpenPin(2);

            led.SetDriveMode(GpioPinDriveMode.Output);

            int cnt = 0;

            while (true)
            {
                cnt++;

                led.Write(GpioPinValue.High);

                Thread.Sleep(300);
                led.Toggle();

                Thread.Sleep(100);
                led.Toggle();

                Thread.Sleep(300);
                led.Toggle();

                Thread.Sleep(300);
                Console.WriteLine("Counter = " + cnt.ToString());
            }
        }
Exemplo n.º 10
0
        public static void Main()
        {
            // F429I_DISCO: PG14 is LEDLD4
            GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));

            led.SetDriveMode(GpioPinDriveMode.Output);

            // create the event NOT signalled
            _touchEvent = new ManualResetEvent(false);

            // STMPE811 touchscreen controller in STM32F429 DISCOVERY board has default I2C address 1000001 = 0x41 ...
            // ... and it's connected to I2C3 bus
            _touchController = new STMPE811(0x41, "I2C3");

            // ... INT signal is connected to PA15 with a pull-up, setup the GPIO and an event handler to handle the device interrupt requests
            var gpioController = GpioController.GetDefault();

            _touchInterrupt = gpioController.OpenPin(PinNumber('A', 15));
            _touchInterrupt.SetDriveMode(GpioPinDriveMode.Input);
            _touchInterrupt.ValueChanged += TouchScreenInterruptRequest;

            // initialize STMPE811
            if (_touchController.Initialize())
            {
                // start the touch screen controller
                _touchController.Start();

                // in the F429I DISCOVERY the INT signal has a pull-up so we need to configure the interrupt polarity to active low
                _touchController.SetInterruptPolarity(InterruptPolarity.Low);
                // as for the type better use level to improve detection
                _touchController.SetInterruptType(InterruptType.Level);

                // enable interrupts from the FIFO and the touch controller
                _touchController.EnableInterruptSource(InterruptSource.FifoAboveThreshold | InterruptSource.Touch);
                _touchController.EnableGlobalInterrupt();

                // output the ID and revision of the device
                Debug.WriteLine("ChipID " + _touchController.ChipID.ToString("X4"));
                Debug.WriteLine("Rev " + _touchController.RevisionNumber.ToString());

                // launch touch tracking thread
                new Thread(new ThreadStart(TouchTracking)).Start();
            }
            else
            {
                // failed to init the device
                Debug.WriteLine("***** FATAL ERROR: failed to initialise the touch screen controller *****");
            }

            // infinite loop to keep main thread active
            for (; ;)
            {
                led.Toggle();

                Thread.Sleep(1000);
            }
        }
Exemplo n.º 11
0
        public static void Main()
        {
            // mind to set a pin that exists on the board being tested
            // PJ5 is LD2 in STM32F769I_DISCO
            GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('J', 5));

            // PD15 is LED6 in DISCOVERY4
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('D', 15));
            // PG14 is LEDLD4 in F429I_DISCO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));
            // PE15 is LED1 in QUAIL
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('E', 15));
            // PB75 is LED2 in STM32F746_NUCLEO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('B', 7));
            // 4 is a valid GPIO pin in ESP32 DevKit, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
            //GpioPin led = GpioController.GetDefault().OpenPin(4);
            // PA5 is LED_GREEN in STM32F091RC
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));
            // PA5 is LD2 in STM32L072Z_LRWAN1
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));
            // A10 is LED onboard blue in NETDUINO 3 Wifi
            // GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 10));
            // pin 4 it's the green LED in TI CC13x2 Launchpad boards
            // pin 5 it's the read LED in TI CC13x2 Launchpad boards
            //GpioPin led = GpioController.GetDefault().OpenPin(4);

            led.SetDriveMode(GpioPinDriveMode.Output);

            led.Write(GpioPinValue.Low);

            while (true)
            {
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(525);
            }
        }
Exemplo n.º 12
0
        static void ListenTest(GpioPin pin)
        {
            PinPulse(pin, 2000);

            using (Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IPv4))
            {
                IPEndPoint ep = new IPEndPoint(IPAddress.Any, 6501);

                soc.Bind(ep);

                soc.Listen(1);

                while (true)
                {
                    Socket client = null;

                    int BytesRead;
                    try
                    {
                        Console.WriteLine(DateTime.UtcNow.ToString() + "Accept client");
                        client = soc.Accept();
                        Console.WriteLine(DateTime.UtcNow.ToString() + "Accepted");

                        PinPulse(pin, 500);

                        client.ReceiveTimeout = 10000;

                        NetworkStream stream = new NetworkStream(client);

                        byte[] buffer = new byte[100];

                        // Echo back everything we receive and toggle Led
                        while ((BytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            stream.Write(buffer, 0, BytesRead);
                            Console.WriteLine(DateTime.UtcNow.ToString() + "Read/Write " + BytesRead.ToString());
                            pin.Toggle();
                        }

                        Console.WriteLine(DateTime.UtcNow.ToString() + "connection ending");
                    }
                    catch (Exception ex) {
                        Console.WriteLine(DateTime.UtcNow.ToString() + "Ex " + ex.Message);
                    };

                    if (client != null)
                    {
                        client.Close();
                    }
                    break;
                }
            }
        }
Exemplo n.º 13
0
        public static void Main()
        {
            Debug.EnableGCMessages(true);

            Console.WriteLine($"{ SystemInfo.TargetName } running on { SystemInfo.Platform }.");

            Debug.GC(false);

            // mind to set a pin that exists on the board being tested
            // PJ5 is LD2 in STM32F769I_DISCO
            GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('J', 5));

            // PD15 is LED6 in DISCOVERY4
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('D', 15));
            // PE15 is LED1 in QUAIL
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('E', 15));
            // PG13 is LD3 in F429I-DISCO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));
            //GpioPin led = GpioController.GetDefault().OpenPin(4);

            led.SetDriveMode(GpioPinDriveMode.Output);

            int i = 0;

            for (; ;)
            {
                i++;

                int[] array = new int[8192];

                led.Toggle();
                Thread.Sleep(100);
                led.Toggle();
                Thread.Sleep(400);

                Console.WriteLine(">> " + i.ToString() + " free memory: " + Debug.GC(false) + " bytes");

                Thread.Sleep(1000);
            }
        }
Exemplo n.º 14
0
        public static void Main()
        {
            GC.EnableGCMessages(true);

            Debug.WriteLine($"{ SystemInfo.TargetName } running on { SystemInfo.Platform }.");

            Debug.WriteLine($"Initial managed heap size: {GC.Run(false)} bytes");

            GpioController gpioController = new();

            // mind to set a pin that exists on the board being tested
            // PJ5 is LD2 in STM32F769I_DISCO
            //GpioPin led = gpioController.OpenPin(PinNumber('J', 5), PinMode.Output);
            // PD15 is LED6 in DISCOVERY4
            //GpioPin led = gpioController.OpenPin(PinNumber('D', 15), PinMode.Output);
            // PE15 is LED1 in QUAIL
            //GpioPin led = gpioController.OpenPin(PinNumber('E', 15), PinMode.Output);
            // PG13 is LD3 in F429I-DISCO
            //GpioPin led = gpioController.OpenPin(PinNumber('G', 14), PinMode.Output);
            // ESP32
            GpioPin led = gpioController.OpenPin(4, PinMode.Output);

            int i = 0;

            for (; ;)
            {
                i++;

                int[] array = new int[4096];

                led.Toggle();
                Thread.Sleep(100);
                led.Toggle();
                Thread.Sleep(400);

                Debug.WriteLine(">> " + i.ToString() + " free memory: " + GC.Run(true) + " bytes");

                Thread.Sleep(1000);
            }
        }
Exemplo n.º 15
0
        private static void Blink()
        {
            GpioPin led = GpioController.GetDefault().OpenPin(2);

            led.SetDriveMode(GpioPinDriveMode.Output);

            led.Write(GpioPinValue.Low);
            while (true)
            {
                Thread.Sleep(500);
                led.Toggle();
            }
        }
Exemplo n.º 16
0
        public static void Main()
        {
            s_GpioController = new GpioController();

            // ESP32 DevKit: 4 is a valid GPIO pin in, some boards like Xiuxin ESP32 may require GPIO Pin 2 instead.
            GpioPin led = s_GpioController.OpenPin(
                2,
                PinMode.Output);

            led.Write(PinValue.Low);

            while (true)
            {
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(125);
                led.Toggle();
                Thread.Sleep(525);
            }
        }
Exemplo n.º 17
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();
            }
        }
Exemplo n.º 18
0
        public static void Main()
        {
            /////////////////////////////////////////////////////////////
            // mind to set a pin that exists on the board being tested //
            /////////////////////////////////////////////////////////////

            // PJ5 is LD2 in STM32F769I_DISCO
            GpioPin led = GpioController.GetDefault().OpenStm32Pin('J', 5);

            // PD15 is LED6 in DISCOVERY4
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('D', 15));
            // PG14 is LEDLD4 in F429I_DISCO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('G', 14));
            // PE15 is LED1 in QUAIL
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('E', 15));
            // PB75 is LED2 in STM32F746_NUCLEO
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('B', 7));
            // PA5 is LED_GREEN in STM32F091RC
            //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));

            led.SetDriveMode(GpioPinDriveMode.Output);
            led.Write(GpioPinValue.High);

            // start a thread blinking the LED to check that something is happening
            new Thread(() => {
                while (true)
                {
                    Thread.Sleep(125);
                    led.Toggle();
                }
            }).Start();

            // set alarm time for 30 seconds from now
            DateTime alarmTime = DateTime.UtcNow.AddSeconds(30);

            //STM32.RTC.SetAlarm(alarmTime);

            Console.WriteLine($"Alarm was set to {alarmTime.ToString("u")}");

            // sleep here for 10 seconds to allow the LED to blink after wakeup
            Thread.Sleep(10000);

            // this call never returns
            // after this the target will enter SMT32 CPU standby mode and will be waked by the RTC alarm in 30 - 10 seconds
            STM32.Power.EnterStandbyMode();

            Thread.Sleep(Timeout.Infinite);
        }
Exemplo n.º 19
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard starting");
            Debug.WriteLine($"I2C:{I2cDevice.GetDeviceSelector()}");
            Debug.WriteLine($"PWM:{PwmController.GetDeviceSelector()}");

            try
            {
                Debug.WriteLine("LED Starting");
                GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 10));
                led.SetDriveMode(GpioPinDriveMode.Output);
                led.Write(GpioPinValue.Low);

                Debug.WriteLine("LED Starting");
                WiiNunchuk nunchuk = new WiiNunchuk("I2C1");

                Debug.WriteLine("ESC Starting");
                PwmController pwm    = PwmController.FromId("TIM5");
                PwmPin        pwmPin = pwm.OpenPin(PinNumber('A', 1));
                pwmPin.Controller.SetDesiredFrequency(PulseFrequency);
                pwmPin.Start();

                Debug.WriteLine("Thread.Sleep Starting");
                Thread.Sleep(2000);

                Debug.WriteLine("Mainloop Starting");
                while (true)
                {
                    nunchuk.Read();

                    double duration = Map(nunchuk.AnalogStickY, WiiNunchukYMinimum, WiiNunchukYMaximum, PulseDurationMinimum, PulseDurationMaximum);
                    Debug.WriteLine($"Value:{nunchuk.AnalogStickY} Duration:{duration:F3}");

                    pwmPin.SetActiveDutyCyclePercentage(duration);

                    led.Toggle();
                    Thread.Sleep(ThrottleUpdatePeriod);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Exemplo n.º 20
0
        public static void Main()
        {
            try
            {
                Debug.WriteLine("devMobile.SiliconLabsSI7005TestHarness starting");

                // STM32F091RC: PA5 is LED_GREEN
                // nanoff --target ST_NUCLEO64_F091RC --update
                //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 5));

                // nanoff --target NETDUINO3_WIFI --update
                GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('A', 10));

                // nanoff --target ST_STM32F769I_DISCOVERY --update
                //GpioPin led = GpioController.GetDefault().OpenPin(PinNumber('J', 5));

                led.SetDriveMode(GpioPinDriveMode.Output);

                Debug.WriteLine(I2cDevice.GetDeviceSelector());

                SiliconLabsSI7005 sensor = new SiliconLabsSI7005("I2C1");
                Debug.WriteLine(" while starting");

                while (true)
                {
                    double humidity    = sensor.Humidity();
                    double temperature = sensor.Temperature();

                    Debug.WriteLine($"{DateTime.UtcNow:hh:mm:ss} H:{humidity:f0} % T:{temperature:f1}°");

                    led.Toggle();

                    Thread.Sleep(10000);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }

            Debug.WriteLine("Terminated");
            Thread.Sleep(Timeout.Infinite);
        }
Exemplo n.º 21
0
        public static void Main()
        {
            Debug.WriteLine("WifiKit32 NF Blinky");
            int counter = 0;

            GpioController gpioc = new GpioController();
            GpioPin        led   = gpioc.OpenPin(WifiKit32Common.OnBoardDevicePortNumber.Led, PinMode.Output);

            led.Write(PinValue.Low);

            while (true)
            {
                led.Toggle();
                if (counter > 10000)
                {
                    counter = 0;
                }

                Debug.WriteLine(counter.ToString());
                Thread.Sleep(1000);
                counter++;
            }
        }
Exemplo n.º 22
0
        public static void Main()
        {
            Debug.WriteLine("[HellOled] : a advanced hello word with the embedded OLED screen.");

            var heltec = new HeltecOled();

            heltec.Begin();
            heltec.Display.SetBrightness(180);
            heltec.Display.FlipScreenVertically();
            heltec.Display.CurrentColor = OledColor.White;


            int            counter = 0;
            GpioController gpioc   = new GpioController();
            GpioPin        led     = gpioc.OpenPin(OnBoardDevicePortNumber.Led, PinMode.Output);

            led.Write(PinValue.Low);

            wifiLogo  = XBMSamples.GetWifiLogoXBM();
            nanofLogo = XBMSamples.GetNanoFrameworkXBM();

            heltec.Display.CurrentFont = FontArialMTPlain10.GetFont();

            while (true)
            {
                switch (counter)
                {
                case 0:
                    heltec.Display.Clear();
                    heltec.Display.TestFill(0);
                    break;

                case 1:
                    heltec.Display.Clear();
                    DemoGeometry(heltec.Display);
                    break;

                case 2:
                    heltec.Display.Clear();
                    DemoScreen2(heltec.Display);
                    break;

                case 3:
                    DemoScreen3(heltec.Display);
                    break;

                case 4:
                    DemoScreen4(heltec.Display);
                    break;

                default:
                    counter = -1;     // there is the ++ at the end of loop
                    break;
                }

                heltec.Display.RefreshDisplay();
                led.Toggle();
                Thread.Sleep(1000);
                counter++;
            }
        }
Exemplo n.º 23
0
        public static void Main()
        {
            var gpioController = new GpioController();

            /////////////////////
            // setup green LED //
            /////////////////////

            // F4-Discovery -> LD4 LED is @ PD12
            // F429I-Discovery -> LD3 is @ PG13
            //_greenLED = gpioController.OpenPin(PinNumber('G', 13));
            // F769I-DISCO -> LED2_GREEN is @ PJ5
            //_greenLED = gpioController.OpenPin(PinNumber('J', 5));
            // F746ZG-NUCLEO -> Off board LED is @ PC10
            // TI CC13x2 Launchpad: DIO_07 it's the green LED
            _greenLED = gpioController.OpenPin(7);

            _greenLED.SetDriveMode(PinMode.Output);

            ///////////////////
            // setup red LED //
            ///////////////////

            // F4-Discovery -> LD5 is @ PD14
            // F429I-Discovery -> LD4 is @ PG14
            //_redLED = gpioController.OpenPin(PinNumber('G', 14));
            // F769I-DISCO -> LED2_RED is @ PJ13
            //_redLED = gpioController.OpenPin(PinNumber('J', 13));
            // TI CC13x2 Launchpad: DIO_06 it's the red LED
            _redLED = gpioController.OpenPin(6);

            _redLED.SetDriveMode(PinMode.Output);

            ///////////////////////
            // setup user button //
            ///////////////////////

            // F4-Discovery -> USER_BUTTON is @ PA0 (input only)
            // F769I-DISCO -> USER_BUTTON is @ PA0 (input only)
            //_userButton = gpioController.OpenPin(PinNumber('A', 0));
            //_userButton.SetDriveMode(PinMode.Input);

            // TI CC13x2 Launchpad: DIO_15 it's BTN-1 (input requiring pull-up)
            _userButton = gpioController.OpenPin(15);
            _userButton.SetDriveMode(PinMode.InputPullUp);

            _userButton.ValueChanged += UserButton_ValueChanged;

            //////////////////////
            // setup other GPIO //
            //////////////////////

            // F769I-DISCO -> using PA7 (input only)
            //_exposedPad = gpioController.OpenPin(PinNumber('A', 7));
            //_exposedPad.SetDriveMode(PinMode.InputPullUp);

            // TI CC13x2 Launchpad: DIO_14 it's BTN-2 (input requiring pull-up)
            _exposedPad = gpioController.OpenPin(14);
            _exposedPad.SetDriveMode(PinMode.InputPullUp);

            // add a debounce timeout
            _exposedPad.DebounceTimeout = new TimeSpan(0, 0, 0, 0, 100);
            _exposedPad.ValueChanged   += ExposedPad_ValueChanged;

            for (; ;)
            {
                _redLED.Toggle();
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 24
0
        public static void Main()
        {
#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);
            // CS on socket 1
            int chipSelectPinNumber = PinNumber('A', 3);
            // CS on socket 2
            //int chipSelectPinNumber = PinNumber('E', 0);
            // RST on socket 1
            int resetPinNumber = PinNumber('A', 2);
            // RST on socket 2
            //int resetPinNumber = PinNumber('E', 1);
#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");

            Debug.WriteLine(Windows.Devices.Spi.SpiDevice.GetDeviceSelector());

            try
            {
                GpioController gpioController = GpioController.GetDefault();

#if NETDUINO3_WIFI || MBN_QUAIL || ST_NUCLEO64_F091RC || ST_NUCLEO144_F746ZG || ST_STM32F769I_DISCOVERY
                // Setup the reset pin
                GpioPin resetGpioPin = gpioController.OpenPin(resetPinNumber);
                resetGpioPin.SetDriveMode(GpioPinDriveMode.Output);
                resetGpioPin.Write(GpioPinValue.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.SetDriveMode(GpioPinDriveMode.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(chipSelectPinNumber)
                {
                    ClockFrequency = 500000,
                    Mode           = SpiMode.Mode0,// From SemTech docs pg 80 CPOL=0, CPHA=0
                    SharingMode    = SpiSharingMode.Shared,
                };

                using (SpiDevice device = SpiDevice.FromId(SpiBusId, 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);
            }
        }
Exemplo n.º 25
0
        public static void Main()
        {
            /////////////////////////////////////////////////////////////
            // mind to set a pin that exists on the board being tested //
            /////////////////////////////////////////////////////////////

            // PJ5 is LD2 in STM32F769I_DISCO
            GpioPin led = GpioController.GetDefault().OpenStm32Pin('J', 5);

            // PD15 is LED6 in DISCOVERY4
            //GpioPin led = GpioController.GetDefault().OpenStm32Pin('D', 15);
            // PG14 is LEDLD4 in F429I_DISCO
            //GpioPin led = GpioController.GetDefault().OpenStm32Pin('G', 6);
            // PE15 is LED1 in QUAIL
            //GpioPin led = GpioController.GetDefault().OpenStm32Pin('E', 15);
            // PB75 is LED2 in STM32F746_NUCLEO
            //GpioPin led = GpioController.GetDefault().OpenStm32Pin('B', 7);
            // PA5 is LED_GREEN in STM32F091RC
            //GpioPin led = GpioController.GetDefault().OpenStm32Pin('A', 5);

            led.SetDriveMode(GpioPinDriveMode.Output);
            led.Write(GpioPinValue.High);

            // query target about wake-up reason
            switch (STM32.Power.WakeupReason)
            {
            case STM32.Power.WakeupReasonType.FromPin:
                Debug.WriteLine("[INFO] Device woke-up on GPIO event.");
                break;

            case STM32.Power.WakeupReasonType.FromStandby:
                Debug.WriteLine("[INFO] Device woke-up from standby (possibly from alarm).");
                break;

            case STM32.Power.WakeupReasonType.Undetermined:
                Debug.WriteLine("[INFO] Couldn't determine woke-up reason.");
                break;
            }

            // enable wake-up from GPIO pin
            STM32.Power.EnableWakeupPin(STM32.Power.WakeupPin.Pin1);

            // start a thread blinking the LED to check that something is happening
            new Thread(() => {
                while (true)
                {
                    Thread.Sleep(125);
                    led.Toggle();
                }
            }).Start();

            // set alarm time for 30 seconds from now
            DateTime alarmTime = DateTime.UtcNow.AddSeconds(30);

            STM32.RTC.SetAlarm(alarmTime);

            Debug.WriteLine($"Setting alarm to {alarmTime.ToString("u")}");

            // read back alarm setting, just to be sure
            var alarmTimeCheck = STM32.RTC.GetAlarm();

            if ((alarmTimeCheck.Year != alarmTime.Year) ||
                (alarmTimeCheck.Month != alarmTime.Month) ||
                (alarmTimeCheck.Day != alarmTime.Day) ||
                (alarmTimeCheck.Hour != alarmTime.Hour) ||
                (alarmTimeCheck.Minute != alarmTime.Minute) ||
                (alarmTimeCheck.Second != alarmTime.Second))
            {
                Debug.WriteLine($"!!!! ERROR: alarm time read from target is different from the set one: {alarmTimeCheck.ToString("u")}");
            }
            else
            {
                Debug.WriteLine($"Alarm was set to {alarmTime.ToString("u")}");

                // sleep here for 10 seconds to allow the LED to blink after wakeup
                Thread.Sleep(10000);

                Debug.WriteLine($"Going to standby mode now...");

                // this call never returns
                // after this the target will enter SMT32 CPU standby mode and will be waked by the RTC alarm in 30 - 10 seconds
                STM32.Power.EnterStandbyMode();
            }

            Thread.Sleep(Timeout.Infinite);
        }
Exemplo n.º 26
0
        public static void Main()
        {
            // TI CC13x2 Launchpad: DIO_07 it's the green LED
            GpioPin led = GpioController.GetDefault().OpenPin(7);

            led.SetDriveMode(GpioPinDriveMode.Output);
            led.Write(GpioPinValue.High);

            // query target about wake-up reason
            switch (nanoFramework.Hardware.TI.Power.SourceOfReset)
            {
            case TIPower.ResetSource.ResetPin:
                Debug.WriteLine("[INFO] Boot following reset pin hit.");
                break;

            case TIPower.ResetSource.WarmReset:
                Debug.WriteLine("[INFO] Boot following warm reset.");
                break;

            case TIPower.ResetSource.SoftwareReset:
                Debug.WriteLine("[INFO] Boot following software reset.");
                break;

            case TIPower.ResetSource.WakeupFromShutdown:
                Debug.WriteLine("[INFO] Boot following wake-up from shutdown.");
                break;

            case TIPower.ResetSource.PowerOn:
                Debug.WriteLine("[INFO] Boot following regular power on.");
                break;
            }

            //////////////////////////////////////////////////////////////////////////////////////////////
            // shutdown: lowest power mode, CPU completely stopped, wake-up on hard reset or GPIO event //
            //////////////////////////////////////////////////////////////////////////////////////////////

            // enable wake-up from BTN1 GPIO pin (DIO15)
            // need to enable internal pull-up
            // sensitive to transition to negative
            TIPower.ConfigureWakeupFromGpioPin(
                new TIPower.PinWakeupConfig[] {
                new TIPower.PinWakeupConfig(
                    15,
                    TIPower.PinWakeupEdge.NegativeEdge,
                    TIPower.PinPullUpDown.PullUp)
            });

            // start a thread blinking the LED to check that something is happening
            new Thread(() => {
                while (true)
                {
                    Thread.Sleep(125);
                    led.Toggle();
                }
            }).Start();

            // sleep here for 5 seconds to allow the LED to blink after wakeup
            Thread.Sleep(5000);

            Debug.WriteLine($"Going to shutdown mode now...");

            TIPower.EnterStandbyMode(TimeSpan.FromSeconds(5));

            // this call never returns
            // after this the target will enter "TI shutdown" mode and will be waked by a push on the BTN1 switch
            TIPower.EnterShutdownMode();

            /////////////////////////////////////////////////////////////////////////////////////////
            // standby: second lowest power mode, CPU stopped depending on power mangement policy, //
            // wake-up after specified time lapsed                                                 //
            /////////////////////////////////////////////////////////////////////////////////////////

            Debug.WriteLine($"Going to standby mode now...");

            // going to standby mode and wake up in 10 seconds
            TIPower.EnterStandbyMode(TimeSpan.FromSeconds(10));

            Thread.Sleep(Timeout.Infinite);
        }