/// <summary> /// Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters. /// </summary> /// <param name="fourBitMode"></param> /// <param name="rs">The number of the CPU pin that is connected to the RS (register select) pin on the LCD.</param> /// <param name="rw">The number of the CPU pin that is connected to the RW (Read/Write) pin on the LCD (optional).</param> /// <param name="enable">the number of the CPU pin that is connected to the enable pin on the LCD.</param> /// <param name="d0"></param> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="d4"></param> /// <param name="d5"></param> /// <param name="d6"></param> /// <param name="d7"></param> public RaspPiGPIOMemLcdTransferProvider(bool fourBitMode, GPIOMem.GPIOPins rs, GPIOMem.GPIOPins rw, GPIOMem.GPIOPins enable, GPIOMem.GPIOPins d0, GPIOMem.GPIOPins d1, GPIOMem.GPIOPins d2, GPIOMem.GPIOPins d3, GPIOMem.GPIOPins d4, GPIOMem.GPIOPins d5, GPIOMem.GPIOPins d6, GPIOMem.GPIOPins d7) { _fourBitMode = fourBitMode; if (rs == GPIOMem.GPIOPins.GPIO_NONE) { throw new ArgumentException("rs"); } _rsPort = new GPIOMem(rs); // we can save 1 pin by not using RW. Indicate by passing GPIO.GPIOPins.GPIO_NONE instead of pin# if (rw != GPIOMem.GPIOPins.GPIO_NONE) // (RW is optional) { _rwPort = new GPIOMem(rw); } if (enable == GPIOMem.GPIOPins.GPIO_NONE) { throw new ArgumentException("enable"); } _enablePort = new GPIOMem(enable); var dataPins = new[] { d0, d1, d2, d3, d4, d5, d6, d7 }; _dataPorts = new GPIOMem[8]; for (int i = 0; i < 8; i++) { if (dataPins[i] != GPIOMem.GPIOPins.GPIO_NONE) { _dataPorts[i] = new GPIOMem(dataPins[i]); } } }
static void Main(string[] args) { Console.WriteLine("Hello Raspberry Pi"); GPIOMem button = new GPIOMem(GPIOPins.V2_Pin_P1_16); while (true) { Console.WriteLine(button.Read().ToString()); } }
public void OneLed(int dauer) { GPIOMem led = new GPIOMem(GPIOPins.GPIO_18, GPIODirection.Out); while (true) { led.Write(PinState.High); System.Threading.Thread.Sleep(dauer); led.Write(PinState.Low); System.Threading.Thread.Sleep(dauer); } }
public double readRawData() { GPIOMem SPICLK = new GPIOMem(GPIOPins.Pin_P1_18, GPIODirection.Out); GPIOMem SPIMISO = new GPIOMem(GPIOPins.Pin_P1_23, GPIODirection.In); GPIOMem SPIMOSI = new GPIOMem(GPIOPins.Pin_P1_24, GPIODirection.Out); GPIOMem SPICS = new GPIOMem(GPIOPins.Pin_P1_22, GPIODirection.Out); int adcnum = 0; double read_adc0 = 0.0; MCP3008 MCP3008 = new MCP3008(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS); read_adc0 = MCP3008.AnalogToDigital; return(read_adc0); }
public void InitializeGPIO() { //IN if (new GPIOMem(GPIOPins.V2_GPIO_24).IsDisposed) { in_gpio24 = new GPIOMem(GPIOPins.V2_GPIO_24, GPIODirection.In); } else { } //Out# out_gpio17 = new GPIOMem(GPIOPins.V2_GPIO_17); }
public string RequestListener(HttpListenerRequest request) { GPIOMem gpio = null; string rtnValue = null; try { // log out requests for debugging Console.WriteLine(request.Url); // set pin direction via "dir" argument GPIODirection dir = (GPIODirection)((new[] { "OUT", "TRUE", "1" }).Contains(request.QueryString["dir"].ToUpper()) ? 1 : 0); // set pin number via "pin" argument GPIOPins pin = (GPIOPins)int.Parse(request.QueryString["pin"]); gpio = new GPIOMem((GPIOPins)pin, dir); if (dir == GPIODirection.Out) { // set pin state via "state" argument bool state = (new[] { "HIGH", "1", "TRUE", "T" }).Contains(request.QueryString["state"].ToUpper()); gpio.Write(state); rtnValue = state.ToString(); } else { rtnValue = (gpio.Read() == PinState.High).ToString(); } } catch (Exception ex) { Console.WriteLine("ERROR:"); Console.WriteLine(ex.Message); Console.WriteLine(ex.Source); Console.WriteLine(ex.StackTrace); rtnValue = "ERROR"; } finally { gpio.Dispose(); } return(rtnValue); }
public static string GetStatus(HttpListenerRequest request) { bool occupied = false; GPIOMem gpio = null; try { gpio = new GPIOMem((GPIOPins)DOOR_SENSOR_PIN, GPIODirection.In, true); occupied = gpio.Read() == PinState.Low; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { gpio.Dispose(); } // if the restroom is now occupied where it previously was not // update the status object by moving a user out of the queue if (occupied && !Status.Occupied) { if (Status.Queue.Count > 0) { Status.OccupiedBy = Status.Queue.Dequeue(); } else { Status.OccupiedBy = "?"; // unknown user (user not using queue?) } Status.Occupied = true; Status.OccupiedOn = DateTime.UtcNow; // this isn't meant to be exact } // otherwise if the restroom is no longer occupied where previously it was // update the status object to reflect this else if (!occupied && Status.Occupied) { Status.Occupied = false; Status.OccupiedBy = null; // not occupied } return(JsonConvert.SerializeObject(Status)); }
public void BlinkyMain() { //display.Write ("Hallo"); //GPIOPins.GPIO_17 = GPIO17 auf PIN11 GPIOMem pin11 = new GPIOMem(GPIOPins.GPIO_17); GPIOMem button = new GPIOMem(GPIOPins.GPIO_18, GPIODirection.In); button.Write(PinState.High); pin11.Write(PinState.Low); int power = 1; int pause = 1; bool toggle = true; while (true) { if (button.Read() == PinState.Low) { //test (); if (toggle) { power++; } else { power--; }; Console.WriteLine("Power;{0} Pause:{1}", power.ToString(), pause.ToString()); pause = power / 2; if (power == 20 || power == 0) { toggle = !toggle; Console.Write(toggle.ToString()); } System.Threading.Thread.Sleep(5); } pin11.Write(PinState.High); System.Threading.Thread.Sleep(pause); pin11.Write(PinState.Low); System.Threading.Thread.Sleep(power); } }
public void StartMe() { Console.WriteLine("Tempertur:"); //# set up the SPI interface pins //# SPI port on the ADC to the Cobbler GPIOMem SPICLK = new GPIOMem(GPIOPins.GPIO_11, GPIODirection.Out); GPIOMem SPIMISO = new GPIOMem(GPIOPins.GPIO_09, GPIODirection.In); GPIOMem SPIMOSI = new GPIOMem(GPIOPins.GPIO_10, GPIODirection.Out); GPIOMem SPICS = new GPIOMem(GPIOPins.GPIO_08, GPIODirection.Out); int adcum = 1; double read_adc0 = 1; while (true) { MCP3008 ADChip = new MCP3008(adcum, SPICLK, SPIMOSI, SPIMISO, SPICS); read_adc0 = ADChip.AnalogToDigital; double millivolts = Convert.ToDouble(read_adc0) * (3300 / 1024); double temp_C = ((millivolts - 100) / 10) - 40; Console.WriteLine("read_adc0:{0}", read_adc0); Thread.Sleep(3000); } }
/// <summary> /// Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters. /// </summary> /// <param name="fourBitMode"></param> /// <param name="rs">The number of the CPU pin that is connected to the RS (register select) pin on the LCD.</param> /// <param name="rw">The number of the CPU pin that is connected to the RW (Read/Write) pin on the LCD (optional).</param> /// <param name="enable">the number of the CPU pin that is connected to the enable pin on the LCD.</param> /// <param name="d0"></param> /// <param name="d1"></param> /// <param name="d2"></param> /// <param name="d3"></param> /// <param name="d4"></param> /// <param name="d5"></param> /// <param name="d6"></param> /// <param name="d7"></param> public RaspPiGPIOMemLcdTransferProvider(bool fourBitMode, GPIOPins rs, GPIOPins rw, GPIOPins enable, GPIOPins d0, GPIOPins d1, GPIOPins d2, GPIOPins d3, GPIOPins d4, GPIOPins d5, GPIOPins d6, GPIOPins d7) { _fourBitMode = fourBitMode; if (rs == GPIOPins.GPIO_NONE) throw new ArgumentException("rs"); _rsPort = new GPIOMem(rs); // we can save 1 pin by not using RW. Indicate by passing GPIO.GPIOPins.GPIO_NONE instead of pin# if (rw != GPIOPins.GPIO_NONE) // (RW is optional) _rwPort = new GPIOMem(rw); if (enable == GPIOPins.GPIO_NONE) throw new ArgumentException("enable"); _enablePort = new GPIOMem(enable); var dataPins = new[] { d0, d1, d2, d3, d4, d5, d6, d7}; _dataPorts = new GPIOMem[8]; for (int i = 0; i < 8; i++) { if (dataPins[i] != GPIOPins.GPIO_NONE) _dataPorts[i] = new GPIOMem(dataPins[i]); } }
static void Main(string [] args) { /*string assemblyFolder = Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location); * NLog.LogManager.Configuration = new NLog.Config.XmlLoggingConfiguration (assemblyFolder + "/NLog/NLog.config", true);*/ Console.Title = "Trigger Device By Ali Deym and Biftor (C) 2017-2018"; WriteLineNoLog("Creating logger instance..."); logger = new FileLogger() { FileNameTemplate = "main-########.log" }; WriteLine("Logger instance created."); WriteLine("Trigger device (C) 2017 - 2018 by:"); WriteLine("Ali Deym, Biftor (Parham Abedi)."); WriteLine(""); WriteLine(""); WriteLine("Initializing device..."); WriteLine(""); WriteLine(""); WriteLine("Trigger Program v" + triggerDeviceVersion.X + "." + triggerDeviceVersion.Y + "." + triggerDeviceVersion.Z); WriteLine(""); WriteLine("Device info: "); var OS = Environment.OSVersion; WriteLine("Device: " + Environment.MachineName); WriteLine("Username: "******"OS: " + OS.VersionString + " (" + Enum.GetName(typeof(PlatformID), OS.Platform) + ")"); WriteLine("CPU Cores: " + Environment.ProcessorCount + " Cores."); WriteLine(""); WriteLine(""); WriteLine("Checking for GPIO config..."); try { if (File.Exists(".gpio")) { var content = File.ReadAllText(".gpio").Trim(); //if (int.TryParse (content, out int result)) { if (Enum.TryParse(content, out GPIOPins configuredPin)) { interruptPin = configuredPin; WriteLine("Changing GPIO pin to: " + content + "."); } //} } else { WriteLine("Creating default GPIO configuration..."); File.WriteAllText(".gpio", "GPIO_17"); } if (File.Exists(".ledgpio")) { var content = File.ReadAllText(".ledgpio").Trim(); if (Enum.TryParse(content, out GPIOPins configuredPin)) { ledPin = configuredPin; WriteLine("Changing LED GPIO pin to: " + content + "."); } } else { WriteLine("Creating default LED GPIO configuration..."); File.WriteAllText(".ledgpio", "GPIO_23"); } if (File.Exists(".flashgpio")) { var content = File.ReadAllText(".flashgpio").Trim(); if (Enum.TryParse(content, out GPIOPins configuredPin)) { flashPin = configuredPin; WriteLine("Changing Flash GPIO pin to: " + content + "."); } } else { WriteLine("Creating default Flash GPIO configuration..."); File.WriteAllText(".flashgpio", "GPIO_21"); } } catch (Exception ex) { WriteLine("GPIO config ERROR: " + ex.ToString()); } WriteLine("Initializing GPIO Pin: " + Enum.GetName(typeof(GPIOPins), interruptPin) + "..."); LEDTimer = DateTime.Now; /* Initialize GPIO Pin: */ pin = new GPIOMem(interruptPin, GPIODirection.In); flash = new GPIOMem(flashPin, GPIODirection.Out); led = new GPIOMem(ledPin, GPIODirection.Out); lastInterruptState = PinState.High; interruptThread = new Thread(interruptCheck); interruptThread.Priority = ThreadPriority.AboveNormal; /* Network manager */ WriteLine("Listening network on IP: (" + IPAddress + ")"); /* Bifler listener */ WriteLine("Starting libBifler listener..."); netManager = new NetworkManager(IPAddress, true); netManager.Initialize(triggerDeviceVersion); WriteLine("Successfully listening libBifler."); /* Radio listener */ WriteLine("Starting radio listener..."); radioManager = new NetworkManager(IPAddress, true, true); radioManager.Initialize(triggerDeviceVersion); WriteLine("Successfully listening radio."); WriteLine("Registering methods..."); /* Register netManager packet's read methods into their origins. */ RegisterMethods(); RegisterRadioMethods(); WriteLine("Started listening network successfully."); WriteLine("Initializing GPS Device..."); /*var ports = SerialPort.GetPortNames (); * WriteLine ("COM Ports (" + ports.Length + "): "); * * foreach (var port in ports) { * WriteLine ("\t" + port); * } * * * if (ports.Length == 1) { * WriteLine ("Creating GPS device on Port: " + ports [0] + "..."); * * gpsDevice = new GPSHandler (ports [0], sendGPSData); * * WriteLine ("SerialPort running for GPS."); * } */ /* Run GPIO Scheduler. */ WriteLine("Starting GPIO Interrupt."); interruptThread.Start(); }
public void Execute(params object[] list) { string MType = ((string)list [0]); switch (MType) { case "READ_TEMPERATURE": GPIOPins X1 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor1 = new GPIOFile(X1); break; case "READ_LUMINANCE": GPIOPins X2 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor2 = new GPIOFile(X2); break; case "READ_HUMIDITY": GPIOPins X3 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor3 = new GPIOFile(X3); break; case "READ_PRESSURE": GPIOPins X4 = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOFile Sensor4 = new GPIOFile(X4); break; case "LEDON": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); led.Write(PinState.High); }).Start(); break; case "LEDOFF": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); led.Write(PinState.Low); }).Start(); break; case "LEDBLINK_SLOW": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(500); led.Write(PinState.Low); System.Threading.Thread.Sleep(500); } }).Start(); break; case "LEDBLINK_FAST": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(250); led.Write(PinState.Low); System.Threading.Thread.Sleep(250); led.Write(PinState.High); System.Threading.Thread.Sleep(250); led.Write(PinState.Low); System.Threading.Thread.Sleep(250); } }).Start(); break; case "LEDBLINK_UFAST": new System.Threading.Thread(delegate() { GPIOPins X = (GPIOPins)Enum.Parse(typeof(GPIOPins), (string)list [1], true); GPIOMem led = new GPIOMem(X); for (int i = 0; i < (int.Parse((string)list [2])); i++) { led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); led.Write(PinState.High); System.Threading.Thread.Sleep(125); led.Write(PinState.Low); System.Threading.Thread.Sleep(125); } }).Start(); break; } }
public RaspPiGPIOMemLcdTransferProvider(GPIOMem.GPIOPins rs, GPIOMem.GPIOPins rw, GPIOMem.GPIOPins enable, GPIOMem.GPIOPins d0, GPIOMem.GPIOPins d1, GPIOMem.GPIOPins d2, GPIOMem.GPIOPins d3, GPIOMem.GPIOPins d4, GPIOMem.GPIOPins d5, GPIOMem.GPIOPins d6, GPIOMem.GPIOPins d7) : this(false, rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) { }
public RaspPiGPIOMemLcdTransferProvider(GPIOMem.GPIOPins rs, GPIOMem.GPIOPins rw, GPIOMem.GPIOPins enable, GPIOMem.GPIOPins d4, GPIOMem.GPIOPins d5, GPIOMem.GPIOPins d6, GPIOMem.GPIOPins d7) : this(true, rs, rw, enable, GPIOMem.GPIOPins.GPIO_NONE, GPIOMem.GPIOPins.GPIO_NONE, GPIOMem.GPIOPins.GPIO_NONE, GPIOMem.GPIOPins.GPIO_NONE, d4, d5, d6, d7) { }
/// <summary> /// Called when GPIO-Pin selection changed. Sets up GPIOMem variables. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GPIO_SettingsChanged(object sender, EventArgs e) { try { // stop running run1 = false; cb_Run1.Checked = false; cb_Run1_CheckedChanged(sender, e); // run2 = false; cb_Run2.Checked = false; cb_Run2_CheckedChanged(sender, e); // set gpio pins Control ctrl = (Control)sender; // Control is rotation sensor 1 if (ctrl.Name == ddl_GPIO1.Name) { // reset old Pin if (!(rotationSensor1_1 is null)) { rotationSensor1_1.Dispose(); rotationSensor1_1 = null; } // set new pin GPIOPins pin = (GPIOPins)Enum.Parse(typeof(GPIOPins), ddl_GPIO1.SelectedItem.ToString()); if (pin != GPIOPins.GPIO_NONE) { rotationSensor1_1 = new GPIOMem(pin, GPIODirection.Out); } } // Control is rotation sensor 2 else if (ctrl.Name == ddl_GPIO2.Name) { if (!(rotationSensor1_2 is null)) { rotationSensor1_2.Dispose(); rotationSensor1_2 = null; } GPIOPins pin = (GPIOPins)Enum.Parse(typeof(GPIOPins), ddl_GPIO2.SelectedItem.ToString()); if (pin != GPIOPins.GPIO_NONE) { rotationSensor1_2 = new GPIOMem(pin, GPIODirection.Out); } } // Control is power sensor else if (ctrl.Name == ddl_GPIO_PWR.Name) { if (!(powerSensor is null)) { powerSensor.Dispose(); powerSensor = null; } GPIOPins pin = (GPIOPins)Enum.Parse(typeof(GPIOPins), ddl_GPIO_PWR.SelectedItem.ToString()); if (pin != GPIOPins.GPIO_NONE) { powerSensor = new GPIOMem(pin, GPIODirection.Out); } } else if (ctrl.Name == ddl_GPIO3.Name) { if (!(rotationSensor2_1 is null)) { rotationSensor2_1.Dispose(); rotationSensor2_1 = null; } GPIOPins pin = (GPIOPins)Enum.Parse(typeof(GPIOPins), ddl_GPIO3.SelectedItem.ToString()); if (pin != GPIOPins.GPIO_NONE) { rotationSensor2_1 = new GPIOMem(pin, GPIODirection.Out); } } else if (ctrl.Name == ddl_GPIO4.Name) { if (!(powerSensor is null)) { rotationSensor2_2.Dispose(); rotationSensor2_2 = null; } GPIOPins pin = (GPIOPins)Enum.Parse(typeof(GPIOPins), ddl_GPIO4.SelectedItem.ToString()); if (pin != GPIOPins.GPIO_NONE) { rotationSensor2_2 = new GPIOMem(pin, GPIODirection.Out); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } }