static void Main(string[] args) { ArgumentParser pp = new ArgumentParser(args); pp.AddExpanded("-l", "--light"); pp.AddExpanded("-nl", "--no-light"); pp.Parse(); var lcdProvider = new RaspPiGPIOMemLcdTransferProvider(GPIOPins.GPIO_07, GPIOPins.GPIO_08, GPIOPins.GPIO_25, GPIOPins.GPIO_24, GPIOPins.GPIO_23, GPIOPins.GPIO_18); var lcd = new Lcd(lcdProvider); GPIOMem backlit = new GPIOMem(GPIOPins.GPIO_15, GPIODirection.Out); //backlit.Write(false); lcd.Begin(16, 2); lcd.Clear(); lcd.SetCursorPosition(0, 0); if (pp.SwitchExists("--light")) { backlit.Write(true); } if (pp.SwitchExists("--no-light")) { backlit.Write(false); } string text = String.Empty; try { var isKey = System.Console.KeyAvailable; text = Console.ReadLine(); } catch (InvalidOperationException) { // when we're in piped output, InvalidOperationException is thrown for KeyAvaliable // and we're using it here to check... dirty, dirty hack! text = Console.In.ReadToEnd(); } //Console.WriteLine(text); text = text.Replace("\r\n", "\n"); if (text.Length > 32) text = text.Substring(0, 32); if (text.Length > 16) text = text.Insert(16, "\n"); if (text.IndexOf('\n') > -1) { lcd.Write(text.Substring(0, text.IndexOf('\n'))); lcd.SetCursorPosition(0, 1); lcd.Write(text.Substring(text.IndexOf('\n') +1)); } else lcd.Write(text); }
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); }
/// <summary> /// Connect MCP3008 with clock, Serial Peripheral Interface(SPI) and channel /// </summary> /// <param name="adc_channel">MCP3008 channel number 0-7 (pin 1-8 on chip).</param> /// <param name="SPICLK">Clock pin</param> /// <param name="SPIMOSI">SPI Master Output, Slave Input (MOSI)</param> /// <param name="SPIMISO">SPI Master Input, Slave Output (MISO)</param> /// <param name="SPICS">SPI Chip Select</param> public MCP3008(int adc_channel, GPIOMem SPICLK, GPIOMem SPIMOSI, GPIOMem SPIMISO, GPIOMem SPICS) { adcnum = adc_channel; clockpin = SPICLK; mosipin = SPIMOSI; misopin = SPIMISO; cspin = SPICS; // if (adc_channel >= 0 && adc_channel <= 7) { //This is the range we are looking for, from CH0 to CH7. } else { throw new IndexOutOfRangeException("MCP3008 Channel Input is out of range, Channel input should be from 0-7 (8-Channel)."); } }
static void Main(string[] args) { //# set up the Serial Peripheral Interface(SPI) interface pins //# SPI port on the ADC to the Cobbler //clock pin GPIOMem SPICLK = new GPIOMem(GPIO.GPIOPins.GPIO18, GPIO.DirectionEnum.OUT); //SPI Master Output, Slave Input (MOSI) GPIOMem SPIMISO = new GPIOMem(GPIO.GPIOPins.GPIO23, GPIO.DirectionEnum.IN); //SPI Master Input, Slave Output (MISO) GPIOMem SPIMOSI = new GPIOMem(GPIO.GPIOPins.GPIO24, GPIO.DirectionEnum.OUT); //SPI Chip Select GPIOMem SPICS = new GPIOMem(GPIO.GPIOPins.GPIO25, GPIO.DirectionEnum.OUT); // temperature sensor connected to channel 0 of mcp3008 int adcnum = 0; double read_adc0 = 0.0; while (true) { DateTime now = DateTime.Now; MCP3008 MCP3008 = new MCP3008(adcnum, SPICLK, SPIMOSI, SPIMISO, SPICS); // read the analog pin (temperature sensor LM35) read_adc0 = MCP3008.AnalogToDigital; double millivolts = Convert.ToDouble(read_adc0) * (3300.0 / 1024); double volts = (Convert.ToDouble(read_adc0) / 1024.0f) * 3.3f; double temp_C = ((millivolts - 100.0) / 10.0) - 40.0; double temp_F = (temp_C * 9.0 / 5.0) + 32; #if DEBUG Console.WriteLine("MCP3008_Channel: " + adcnum); Console.WriteLine("read_adc0: " + read_adc0); Console.WriteLine("millivolts: " + (float)millivolts); Console.WriteLine("tempC: " + (float)temp_C); Console.WriteLine("tempF: " + (float)temp_F); Console.WriteLine("volts: " + (float)volts); //The following line makes the trick on Raspberry Pi for displaying DateTime.Now //equivalent. Console.WriteLine("Date time stamp: {0}/{1}/{2} {3}:{4}:{5}",now.Month,now.Day,now.Year, now.Hour,now.Minute,now.Second); System.Console.WriteLine("\n"); #endif Thread.Sleep(3000); } }
static void SetHeatingPin(PinState state) { GPIOMem heatingPin = new GPIOMem(GPIOPins.GPIO_14); heatingPin.PinDirection = GPIODirection.Out; heatingPin.Write(state); }
public void init() { var device = new RPI(); var namedPins = new TNamedPins(); //namedPins.Add("LOW", device.createPin(GPIOPins.V2_GPIO_03, GPIODirection.Out, false)); //namedPins.Add("HI", device.createPin(GPIOPins.V2_GPIO_27, GPIODirection.Out, true)); //namedPins.Add("SER", device.createPin(GPIOPins.V2_GPIO_02, GPIODirection.Out, false)); //namedPins.Add("OE", null); //namedPins.Add("RCLK", device.createPin(GPIOPins.V2_GPIO_04, GPIODirection.Out, false)); //namedPins.Add("SRCLK", device.createPin(GPIOPins.V2_GPIO_17, GPIODirection.Out, false)); //namedPins.Add("SRCLR", null); //namedPins.Add("O7", device.createPin(GPIOPins.V2_GPIO_10, GPIODirection.In)); //namedPins.Add("CP", device.createPin(GPIOPins.V2_GPIO_09, GPIODirection.Out, false)); //namedPins.Add("PL", device.createPin(GPIOPins.V2_GPIO_11, GPIODirection.Out, false)); //--- namedPins.Add("SER", device.createPin(GPIOPins.V2_GPIO_17, GPIODirection.Out, false)); namedPins.Add("OE", null); namedPins.Add("RCLK", device.createPin(GPIOPins.V2_GPIO_22, GPIODirection.Out, false)); namedPins.Add("SRCLK", device.createPin(GPIOPins.V2_GPIO_27, GPIODirection.Out, false)); namedPins.Add("SRCLR", null); namedPins.Add("O7", device.createPin(GPIOPins.V2_GPIO_23, GPIODirection.In)); namedPins.Add("CP", device.createPin(GPIOPins.V2_GPIO_24, GPIODirection.Out, false)); namedPins.Add("PL", device.createPin(GPIOPins.V2_GPIO_25, GPIODirection.Out, false)); sipo = new TSIPO(namedPins["SER"], namedPins["OE"], namedPins["RCLK"], namedPins["SRCLK"], namedPins["SRCLR"]); //sipo.setBits(new int[200]); //clear all //WARNING: CAN DESTROY SCREEN! USE POWER UP / DOWN SEQUENCE!! piso = new TPISO(namedPins["O7"], namedPins["PL"], namedPins["CP"]); ledMapping = new TBitMapping(8); ledMapping.setMapping(0, 1, 2, 3, 7, 6, 5, 4); ledMappingBottom = new TBitMapping(8); ledMappingBottom.setMapping(0, 1, 2, 3, 7, 6, 5, 4); //OK? ledMappingRight = new TBitMapping(8); ledMappingRight.setMapping(0, 1, 2, 3, 7, 6, 5, 4); //OK //1000 0000 ledMappingSpecial = new TBitMapping(8); ledMappingSpecial.setMapping(0, 1, 2, 3, 7, 6, 5, 4); //CHECK outMapping = new TBitMapping(8); //outMapping.setMapping(4, 0, 1, 2, 5, 6, 7, 3); //outMapping.setMapping(3, 7, 6, 5, 2, 1, 0, 4); outMapping.setMapping(7, 6, 5, 4, 3, 2, 1, 0); //0000 //0001 //outMappingBugFix = new TBitMapping(8); //outMappingBugFix.setMapping(4, 0, 1, 2, 5, 7, 6, 3); sideMapping = new TBitMapping(8); //sideMapping.setMapping(7, 0, 1, 2, 3, 4, 5, 6); sideMapping.setMapping(0, 1, 2, 3, 4, 5, 6, 7); sideSwitchesOld = new bool[sideSwitchCount]; sideSwitchesNew = new bool[sideSwitchCount]; sideSwitchesOldDelay = new bool[sideSwitchCount]; sideSwitchesNewDelay = new bool[sideSwitchCount]; //screen var D16_SDI = new GPIOMem(GPIOPins.V2_GPIO_10, GPIODirection.Out, false); var D17_CLK = new GPIOMem(GPIOPins.V2_GPIO_11, GPIODirection.Out, false); var CS = new GPIOMem(GPIOPins.V2_GPIO_08, GPIODirection.Out, false); var RST = device.createPin(GPIOPins.V2_GPIO_18, GPIODirection.Out, false); var RS = new GPIOMem(GPIOPins.V2_GPIO_04, GPIODirection.Out, false); var spi = new TSPIEmulator(D16_SDI, null, D17_CLK, CS); var watch = new System.Diagnostics.Stopwatch(); var bus = new TOLEDSPIFastDataBus(spi, RST, RS); lcd = new TOLEDDisplay(bus, this); lcd.orientation(3); lcd.background(Color.Black); displayPowerOff(); }