public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { Cls(nusbio); var sr = new ShiftRegister74HC595(nusbio, dataPin, latchPin, clockPin); sr.Send8BitValue(0); while (nusbio.Loop()) { if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { break; } if (k == ConsoleKey.A) { sr.AnimateOneLeftToRightAndRightToLeft(15); } } } } Console.Clear(); }
private static void Three5VoltDevicesDemos(Nusbio nusbio) { var waitTime0 = 500; var quit = false; var lampGpio = 0; var fiberOpticGpio = 1; var fanGpio = 2; while (!quit) { nusbio[lampGpio].DigitalWrite(PinState.High); for (var g = 0; g < 10; g++) { for (var gg = 0; gg < 10; gg++) { nusbio[fanGpio].DigitalWrite((gg % 3) == 0); nusbio[fiberOpticGpio].DigitalWrite(PinState.High); Thread.Sleep(waitTime0); nusbio[fiberOpticGpio].DigitalWrite(PinState.Low); Thread.Sleep(waitTime0); if (Console.KeyAvailable && Console.ReadKey(true).Key != ConsoleKey.Attention) { g = 11; quit = true; break; } } } } nusbio.SetAllGpioOutputState(PinState.Low); }
public static NusbioSevenSegmentDisplay Initialize8SevenSegmentDisplays(Nusbio nusbio) { // Using a breadboard and some wires var selectGpio = NusbioGpio.Gpio2; var mosiGpio = NusbioGpio.Gpio1; var clockGpio = NusbioGpio.Gpio0; // How to plug the 8 7Segment display directly into Nusbio // ----------------------------------------------------------------------- // NUSBIO : GND VCC 7 6 5 4 3 2 1 0 // 8x8 LED Matrix MAX7219 base : VCC GND DIN CS CLK // Gpio 7 act as ground #if PLUGGED_INTO_NUSBIO nusbio[NusbioGpio.Gpio7].Low(); // <- GROUND mosiGpio = NusbioGpio.Gpio6; selectGpio = NusbioGpio.Gpio5; clockGpio = NusbioGpio.Gpio4; #endif var sevenSegmentDisplay = NusbioSevenSegmentDisplay.Initialize( nusbio, 8, // 8 digits/7Segments on the device selectGpio, mosiGpio, clockGpio, deviceCount: 1 // 1 device with 8 7Segmens == 1 MAX7219 ); return(sevenSegmentDisplay); }
private static void CountFrom0To15InBinaryOnGpio0to3(Nusbio nusbio) { const int maxCounter = 10; Console.Clear(); ConsoleEx.TitleBar(0, "Count from 0 to 15 on GPIO 0..3"); ConsoleEx.WriteMenu(-1, 5, "Q)uit"); var counter = 0; while (true) { ConsoleEx.WriteLine(0, 3, string.Format("Counter {0:00}", counter), ConsoleColor.Cyan); // Clock chip 4017 or 74LS293 nusbio[0].DigitalWrite(((counter & 1) == 1)); nusbio[1].DigitalWrite(((counter & 2) == 2)); nusbio[2].DigitalWrite(((counter & 4) == 4)); nusbio[3].DigitalWrite(((counter & 8) == 8)); counter += 1; if (counter == maxCounter) { counter = 0; } if (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Q) { break; } } Thread.Sleep(500); } }
static void GestureMode(Nusbio nusbio, GY_9960LLC gy_9960LLC) { Console.Clear(); ConsoleEx.TitleBar(0, "Gesture Mode", ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 5, "Q)uit"); while (true) { Thread.Sleep(100); var isGestureAvailable = gy_9960LLC.isGestureAvailable(); //ConsoleEx.WriteMenu(-1, 2, string.Format("InterruptOn:{0}, isGestureAvailable:{1}", Console.WriteLine(string.Format("InterruptOn:{0}, isGestureAvailable:{1}", gy_9960LLC.InterruptOn(), isGestureAvailable )); if (isGestureAvailable) { var g = gy_9960LLC.readGesture(); if (g != GY_9960LLC.Direction.DIR_NONE) { Console.WriteLine(string.Format("Gest:{0}", g)); } } if (Console.KeyAvailable) { var k = Console.ReadKey(); if (k.Key == ConsoleKey.Q) { break; } } } }
public MCP41X1_Base(Nusbio nusbio, NusbioGpio selectGpio, NusbioGpio mosiGpio, NusbioGpio misoGpio, NusbioGpio clockGpio, NusbioGpio resetGpio = NusbioGpio.None, bool debug = false) { this._spiEngine = new SPIEngine(nusbio, selectGpio, mosiGpio, misoGpio, clockGpio, resetGpio, debug); this.Voltage = Nusbio.Voltage; // Nusbio is a 5 volt device this.MaxDigitalValue = 128; this.MinDigitalValue = 0; }
static void ShowNusbioState(Nusbio nusbio) { var b = new StringBuilder(100); b.AppendFormat("Gpios "); foreach (var g in nusbio.GPIOS) { if (g.Value.AsLed.ExecutionMode == ExecutionModeEnum.Blinking) { b.AppendFormat("{0}:Blinking, ", g.Value.Name); } else { b.AppendFormat("{0}:{1}, ", g.Value.Name.Substring(4), g.Value.State ? "High" : "Low "); } } ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 7, b.ToString().RemoveLastChar().RemoveLastChar(), ConsoleColor.Cyan, ConsoleColor.DarkCyan); var maskString = "Gpios Mask:{0} - {1}".FormatString(nusbio.GetGpioMask().ToString("000"), nusbio.GetGpioMaskAsBinary()); ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 8, maskString, ConsoleColor.Cyan, ConsoleColor.DarkCyan); ConsoleEx.Gotoxy(0, 24); }
/* * private SPIEngine.SPIResult SpiTransferBuffer__(List<byte> buffer, bool software = false) * { * var r = new SPIEngine.SPIResult(); * var shouldSelectUnSelect = _alreadySelected == false; * try * { * if(shouldSelectUnSelect) * this.SelectDevice(true); * * if (software) * { * for (var i = 0; i < buffer.Count; i++) * { * Shift.ShiftOut(this._nusbio, Nusbio.GetGpioIndex(this._spiEngine.MosiGpio), Nusbio.GetGpioIndex(this._spiEngine.ClockGpio), buffer[i]); * } * } * else * { * var gs = new GpioSequence((this._nusbio as Nusbio).GetGpioMask(), this._nusbio.GetTransferBufferSize()); * var i = 0; * while (i < buffer.Count) * { * if (gs.EmptySpace >= GpioSequence.BIT_PER_BYTE) * { * // Add one byte to the gpio sequence * gs.ShiftOut(this._nusbio as Nusbio, this._spiEngine.MosiGpio, this._spiEngine.ClockGpio, buffer[i], dataAndClockOptimized:false); * i += 1; * } * else * { * if (gs.Send(this._nusbio as Nusbio)) * { * var lastMaskValue = gs[gs.Count - 1]; * gs = new GpioSequence(lastMaskValue, this._nusbio.GetTransferBufferSize()); * } * else * { * r.Fail("SPI buffer was not sent"); * break; * } * } * } * if (gs.Count > 0) * { * if (gs.Send(this._nusbio as Nusbio)) * r.Succeeded = true; * else * r.Fail("SPI buffer was not sent"); * } * } * } * finally * { * if(shouldSelectUnSelect) * this.SelectDevice(false); * } * return r; * } */ private SPIEngine.SPIResult SpiTransferBuffer(List <byte> buffer, bool software = false) { var r = new SPIEngine.SPIResult(); var shouldSelectUnSelect = _alreadySelected == false; try { if (shouldSelectUnSelect) { this.SelectDevice(true); } if (software) { for (var i = 0; i < buffer.Count; i++) { Shift.ShiftOut(this._nusbio, Nusbio.GetGpioIndex(this._spiEngine.MosiGpio), Nusbio.GetGpioIndex(this._spiEngine.ClockGpio), buffer[i]); } } else { r = this._spiEngine.Transfer(buffer, select: false); } } finally { if (shouldSelectUnSelect) { this.SelectDevice(false); } } return(r); }
public Button(Nusbio nusbio, NusbioGpio gpioPin, bool inverse = false) { this._gpioPin = gpioPin; this._nusbio = nusbio; this.Inverse = inverse; this._nusbio.SetPinMode(gpioPin, PinMode.Input); }
public MCP4132(Nusbio nusbio, NusbioGpio selectGpio, NusbioGpio mosiGpio, NusbioGpio misoGpio, NusbioGpio clockGpio, bool debug = false) : base(nusbio, selectGpio, mosiGpio, misoGpio, clockGpio, NusbioGpio.None, debug) { base.MaxResistance = 100000; // 100k Ohm }
private static void SevenSegmentDisplaySequenceAll(Nusbio nusbio, List <NusbioGpio> seq) { var wait = 250; var seqReversed = new List <NusbioGpio>(); seqReversed.AddRange(seq); seqReversed.Reverse(); foreach (var g in seq) { nusbio[g].DigitalWrite(PinState.High); if (Console.KeyAvailable) { break; } Thread.Sleep(wait); } Thread.Sleep(wait * 2); foreach (var g in seqReversed) { nusbio[g].DigitalWrite(PinState.Low); if (Console.KeyAvailable) { break; } Thread.Sleep(wait); } Thread.Sleep(wait * 2); }
public BiColorLed(Nusbio nusbio, NusbioGpio led0GpioPin, NusbioGpio led1GpioPin) { this.Led0 = new Led(nusbio, led0GpioPin); this.Led1 = new Led(nusbio, led1GpioPin); this.State = BiColorLedState.Off; this.AllOff(); }
public static GpioSequence ShiftOutHardWare(Nusbio nusbio, int dataPin, int clockPin, int val, GpioSequence gs = null, bool send = true, BitOrder bitOrder = BitOrder.MSBFIRST) { if (gs == null) { gs = new GpioSequence(nusbio.GetGpioMask()); } for (var i = 0; i < 8; i++) { int a = 0; if (bitOrder == BitOrder.LSBFIRST) { a = (val & (1 << i)); } else { a = (val & (1 << (7 - i))); } gs.ClockBit(nusbio[clockPin], nusbio[dataPin], a > 0); } if (send) { nusbio.SetGpioMask(gs.ToArray()); } return(gs); }
public ShiftRegister74HC595(Nusbio nusbio, NusbioGpio dataPin, NusbioGpio latchPin, NusbioGpio clockPin) { this._dataPin = dataPin; this._latchPin = latchPin; this._clockPin = clockPin; this._nusbio = nusbio; }
public static void ShiftOut( IDigitalWriteRead dwr, int dataPin, int clockPin, int val, BitOrder bitOrder = BitOrder.MSBFIRST) { int i; System.Diagnostics.Debug.WriteLine("Shift {0}", val); for (i = 0; i < 8; i++) { if (bitOrder == BitOrder.LSBFIRST) { var a = (val & (1 << i)); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(a)); } else { var b = (val & (1 << (7 - i))); dwr.DigitalWrite(dataPin, Nusbio.ConvertToPinState(b)); } ClockIt(dwr, clockPin); } }
public static void GpioAnimatioOneAtTheTime(Nusbio nusbio, ShiftRegister74HC595 sr, int waitTime, bool demoGpio3to7Too = false) { // Gpio 0,1,2 are used to control the 2 shift register 74HC595, but we can use the other 5 sr.SetGpioMask(ShiftRegister74HC595.ExGpio.None); for (int i = 0; i < sr.MaxGpio; i++) { var g = sr.GetGpioFromIndex(i + sr.MinGpioIndex); Console.WriteLine(g); sr.SetGpioMask(g); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } for (int i = sr.MaxGpio - 1; i >= 0; i--) { var g = sr.GetGpioFromIndex(i + sr.MinGpioIndex); Console.WriteLine(g); sr.SetGpioMask(g); Thread.Sleep(waitTime); if (Console.KeyAvailable) { return; } } sr.SetGpioMask(0); Thread.Sleep(waitTime * 10); }
public static void Run(string[] args) { Console.WriteLine("Nusbio initialization"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("nusbio not detected"); return; } var outPin = 0; var inPin = 1; using (var nusbio = new Nusbio(serialNumber)) // , { var pot = new Potentiometer(nusbio, inPin, outPin, 23, 290, 500); // 50k Pot var ddd = pot.PercentValue; Cls(nusbio); while(nusbio.Loop()) { ConsoleEx.Write(0, 10, string.Format("[{0}] Value:{1,-4}, Percent:{2}% ", DateTime.Now, pot.Value, (int)pot.PercentValue), ConsoleColor.DarkCyan); if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) break; } } } Console.Clear(); }
public ShiftRegister74HC595(Nusbio nusbio, NusbioGpio dataPin,NusbioGpio latchPin,NusbioGpio clockPin) { this._dataPin = dataPin; this._latchPin = latchPin; this._clockPin = clockPin; this._nusbio = nusbio; }
private static void ClockGpio0(Nusbio nusbio) { const int maxLed = 10; Console.Clear(); ConsoleEx.TitleBar(0, "Clock Gpio0 for 10 LED control with a 4017 chip"); ConsoleEx.WriteMenu(-1, 5, "Q)uit"); int ledIndex = 0; var clockGpio = NusbioGpio.Gpio0; var resetGpio = NusbioGpio.Gpio0; ClockGpio(nusbio, resetGpio); // Reset Chip 4017 to index 0, LED 0 is on while (true) { ConsoleEx.WriteLine(0, 3, string.Format("Led {0} on", ledIndex), ConsoleColor.Cyan); ClockGpio(nusbio, clockGpio, 64); // Reset Chip 4017 to index 0, LED 0 is on ledIndex += 1; if (ledIndex == maxLed) { ledIndex = 0; } if (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Q) { break; } } } }
private static bool AnimateNonBlocking2(Nusbio nusbio) { if (nusbio.IsAsynchronousSequencerOn) { nusbio.CancelAsynchronousSequencer(); return(false); } else { nusbio.StartAsynchronousSequencer(100, seq: DS.List( NusbioGpio.Gpio0, NusbioGpio.Gpio1, NusbioGpio.Gpio2, NusbioGpio.Gpio3, NusbioGpio.Gpio4, NusbioGpio.Gpio5, NusbioGpio.Gpio6, NusbioGpio.Gpio7, NusbioGpio.Gpio6, NusbioGpio.Gpio5, NusbioGpio.Gpio4, NusbioGpio.Gpio3, NusbioGpio.Gpio2, NusbioGpio.Gpio1 )); return(true); } }
public static LiquidCrystal_I2C_PCF8574 Detect(Nusbio nusbio, int maxColumn, int maxRow, NusbioGpio sda = NusbioGpio.Gpio7, NusbioGpio scl = NusbioGpio.Gpio6, List <int> i2cIDs = null, bool displayMessage = true) { if (i2cIDs == null) { i2cIDs = I2C_IDS; } foreach (var lcdI2cId in i2cIDs) { var lcdI2C = new LiquidCrystal_I2C_PCF8574(nusbio, sda, scl, maxColumn, maxRow, deviceId: lcdI2cId); if (lcdI2C.Begin(maxColumn, maxRow)) { if (displayMessage) { Console.WriteLine("I2C LCD ID:0x{0:X} found", lcdI2cId); } System.Threading.Thread.Sleep(1000); return(lcdI2C); } else { if (displayMessage) { Console.WriteLine("I2C LCD ID:0x{0:X} not found", lcdI2cId); } } } return(null); }
private static void Demo2(Nusbio nusbio) { var title = "7 Segment Display Demo"; Console.Clear(); ConsoleEx.TitleBar(0, title, ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 2, "Q)uit"); ConsoleEx.Gotoxy(0, 4); var anim1 = new List <NusbioGpio>() { NusbioGpio.Gpio0, NusbioGpio.Gpio1, NusbioGpio.Gpio2, NusbioGpio.Gpio3, NusbioGpio.Gpio4, NusbioGpio.Gpio5, NusbioGpio.Gpio6, NusbioGpio.Gpio7, }; var anim3 = new List <TwoNusbioGpio>() { new TwoNusbioGpio { g1 = NusbioGpio.Gpio2, g2 = NusbioGpio.Gpio5 }, new TwoNusbioGpio { g1 = NusbioGpio.Gpio7, g2 = NusbioGpio.Gpio7 }, }; while (true) { SevenSegmentDisplaySequenceAll(nusbio, anim1); SevenSegmentDisplaySequence(nusbio, anim3, 4); //SevenSegmentDisplaySequenceOne(nusbio, anim1); if (Console.KeyAvailable && Console.ReadKey(true).Key != ConsoleKey.Attention) { break; } } }
public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } var halfSecondTimeOut = new TimeOut(500); using (var nusbio = new Nusbio(serialNumber)) { Cls(nusbio); // See web site page, for wiring // - http://www.madeintheusb.net/TutorialInput/Index/#InputButton // - http://www.madeintheusb.net/Images/Fritzing/Button%202%20Wires%20PullUp_bb.png var buttons = new List <Button>() { new Button(nusbio, NusbioGpio.Gpio6, inverse: true), new Button(nusbio, NusbioGpio.Gpio7, inverse: true) }; while (nusbio.Loop()) { //if(halfSecondTimeOut.IsTimeOut()) //{ // nusbio[2].DigitalWrite(!nusbio[2].State); //} for (var x = 0; x < buttons.Count; x++) { ConsoleEx.Write(0, 4 + x, string.Format("[{0}] Button {1} State:{2,-4}", DateTime.Now, x, buttons[x].GetButtonState()), ConsoleColor.DarkCyan); if (buttons[x].GetButtonUpState()) { ConsoleEx.Write(0, 6 + x, string.Format("[{0}] Button {1} {2} ", DateTime.Now, x, buttons[x].GetState()), ConsoleColor.DarkCyan); } else if (buttons[x].GetButtonDownState()) { ConsoleEx.Write(0, 6 + x, string.Format("[{0}] Button {1} {2} ", DateTime.Now, x, buttons[x].GetState()), ConsoleColor.DarkCyan); } } if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) { break; } } } } Console.Clear(); }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 4, "A)PI demo Custom cH)ar demo Nusbio R)ocks P)erformance Test Q)uit"); ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); }
/// <summary> /// SPI Constructor /// </summary> /// <param name="nusbio"></param> /// <param name="clockPin"></param> /// <param name="mosiPin"></param> /// <param name="misoPin"></param> /// <param name="selectPin"></param> /// <param name="kBit"></param> /// <param name="debug"></param> public EEPROM_25AA256(Nusbio nusbio, NusbioGpio clockPin, NusbioGpio mosiPin, NusbioGpio misoPin, NusbioGpio selectPin, bool debug = false) : base(nusbio, clockPin, mosiPin, misoPin, selectPin, 256, debug) { }
public JoyStick(Nusbio nusbio, MCP3008 adc, int xAdPort, int yAdPort, int buttonAdPort) { this._nusbio = nusbio; this._adc = adc; this.XSensor = new Sensor.AnalogSensor(nusbio, xAdPort); this.YSensor = new Sensor.AnalogSensor(nusbio, yAdPort); this.ButSensor = new Sensor.AnalogSensor(nusbio, buttonAdPort); }
private static void ReverseGpio(NusbioGpio gpio, Nusbio nusbio) { if (nusbio.GPIOS[gpio].Mode == PinMode.Output) { nusbio.GPIOS[gpio].State = !nusbio.GPIOS[gpio].State; nusbio.GPIOS[gpio].DigitalWrite(nusbio.GPIOS[gpio].State ? PinState.High : PinState.Low); } }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(ConsoleEx.WindowHeight - 2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight - 3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); }
public Button(Nusbio nusbio, NusbioGpio gpioPin, string name = null, bool inverse = false) { this.Name = name; this._gpioPin = gpioPin; this._nusbio = nusbio; this.Inverse = inverse; this._nusbio.SetPinMode(gpioPin, PinMode.Input); }
private void Experiment(Nusbio nusbio, NusbioGpio inPin, NusbioGpio outPin) { nusbio.SetPinMode(inPin, PinMode.Input); // Raise Voltage to 1v at the + of the capacitor nusbio[0].High(); // Raise Voltage to 5v at the + of the capacitor Thread.Sleep(1000); nusbio[0].Low(); nusbio.SetPinMode(inPin, PinMode.Output); // Raise Voltage to 1v at the + of the capacitor Thread.Sleep(500); }
public OLED(Nusbio nusbio, int width, int height, NusbioGpio clock, NusbioGpio mosi, NusbioGpio select, NusbioGpio dc, NusbioGpio reset, OledDriver driver = OledDriver.SH1106, bool debug = false) : base((Int16)width, (Int16)height) { this.Driver = driver; this.Width = width; this.Height = height; this._spiEngine = new spi.SPIEngine(nusbio, select, mosi, NusbioGpio.None, clock, reset, debug: debug); this._spiEngine.DCGpio = dc; this.PIN_DC = (nusbio[dc] as Gpio).Bit; }
public static void TestSetting16bitAtOnce(Nusbio nusbio, ShiftRegister74HC595 sr, int waitTime) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct() + " 16 bit value demo", ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.Gotoxy(0, 3); //sr.TestPins(); sr.Reset(); var p1 = 1; var p2 = 256; for (var i = 0; i < 8; i++) { sr.SetGpioMask(p1 + p2); //sr.SetDataLinesAndAddrLines((byte)p1, (byte)(p2 >> 8)); //sr.SetGpioMask((byte)p1, (byte)(p2 >> 8)); Console.WriteLine("16 bite value:{0:000000} - {1} {2}", p1 + p2, MadeInTheUSB.WinUtil.BitUtil.BitRpr(p1), MadeInTheUSB.WinUtil.BitUtil.BitRpr(p2 >> 8) ); Thread.Sleep(waitTime); p1 *= 2; p2 *= 2; } Console.WriteLine("---"); Thread.Sleep(waitTime); sr.SetGpioMask(0); p1 = 1; p2 = 256; var pp1 = p1; var pp2 = p2; for (var i = 0; i < 8; i++) { //sr.SetGpioMask(pp1 + pp2); sr.SetGpioMask((byte)pp1, (byte)(pp2 >> 8)); Console.WriteLine("16 bite value:{0:000000} - {1} {2}", pp1 + pp2, MadeInTheUSB.WinUtil.BitUtil.BitRpr(pp1), MadeInTheUSB.WinUtil.BitUtil.BitRpr(pp2 >> 8) ); Thread.Sleep(waitTime); p1 *= 2; p2 *= 2; pp1 += p1; pp2 += p2; } Console.WriteLine("Hit any key to continue"); Console.ReadKey(); sr.SetGpioMask(0); }
public TC77(Nusbio nusbio, NusbioGpio clockGpio, NusbioGpio mosiGpio, NusbioGpio misoGpio, NusbioGpio selectGpio, bool debug = false) : base(nusbio) { this._spi = new SPIEngine(nusbio, selectGpio, mosiGpio, misoGpio, clockGpio, NusbioGpio.None, false); }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 5, "R)ainbow Demo B)rightness Demo S)equence Demo RainboW) Demo + 4 LED" ); ConsoleEx.WriteMenu(-1, 9, "Q)uit"); ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); //ConsoleEx.WriteMenu(-1, 2, "Gpio/Led: 0) 1) 2) 3) 4) 5) 6) 7) On/Off"); ConsoleEx.WriteMenu(-1, 10, "O)ff All Q)uit"); }
public LEDBackpack Add(int16_t width, int16_t height, Nusbio nusbio, NusbioGpio sdaOutPin, NusbioGpio sclPin, byte addr) { var b = new LEDBackpack(width, height, nusbio, sdaOutPin, sclPin); if (b.Detect(addr)) { b.Begin(addr); this._backpacks.Add(b); return b; } else return null; }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 5, "B)rightness Demo R)GB Demo S)croll Demo SP)eed Demo"); ConsoleEx.WriteMenu(-1, 7, "A)mp Test RainboW) Demo L)ine Demo AlT)ernate Line Demo"); ConsoleEx.WriteMenu(-1, 9, "Q)uit"); ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(4, "0) 10k Pot, 1) 100k Pot, O)ther Api test ", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(5, "O)ther Api test L)ED test on 10k Pot", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(6, "Q)uit", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(4, "0) Loop through 10k Pot, O)ther Api test ", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(5, "B)iColor Led driven with 2 potentiometer (MCP4231)", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(6, "Q)uit", ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); }
private static void AnimateBlocking3(Nusbio nusbio) { var maxGpio = 8; var gpiosSequence = DS.List( NusbioGpio.Gpio0, NusbioGpio.Gpio1, NusbioGpio.Gpio3, NusbioGpio.Gpio2, NusbioGpio.Gpio4, NusbioGpio.Gpio5, NusbioGpio.Gpio7, NusbioGpio.Gpio6 ); int max = 36; int min = 4; int step = 2; int delay = min; bool on = true; while(true) { if (Console.KeyAvailable) { var k = Console.ReadKey(true); break; } for(var i=0; i<maxGpio; i++ ){ nusbio[gpiosSequence[i]].DigitalWrite(PinState.High); TimePeriod.Sleep(delay); nusbio[gpiosSequence[i]].DigitalWrite(PinState.Low); TimePeriod.Sleep(delay); delay += on ? (step) : (-step); if (delay > max) on = false; if (delay < min) on = true; if (delay < 0) delay = 0; } } }
public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { Cls(nusbio); // See web site page, for wiring // - http://www.madeintheusb.net/TutorialInput/Index/#InputButton // - http://www.madeintheusb.net/Images/Fritzing/Button%202%20Wires%20PullUp_bb.png var buttons = new List<Button>() { new Button(nusbio, NusbioGpio.Gpio0, inverse: true), new Button(nusbio, NusbioGpio.Gpio1, inverse: true) }; while(nusbio.Loop()) { for (var x = 0; x < buttons.Count; x++) { ConsoleEx.Write(0, 4+x, string.Format("[{0}] Button {1} State:{2,-4}", DateTime.Now, x, buttons[x].GetButtonState()), ConsoleColor.DarkCyan); if (buttons[x].GetButtonUpState()) { ConsoleEx.Write(0, 6+x, string.Format("[{0}] Button {1} {2} ", DateTime.Now, x, buttons[x].GetState()), ConsoleColor.DarkCyan); } else if (buttons[x].GetButtonDownState()) { ConsoleEx.Write(0, 6+x, string.Format("[{0}] Button {1} {2} ", DateTime.Now, x, buttons[x].GetState()), ConsoleColor.DarkCyan); } } if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) break; } } } Console.Clear(); }
public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } var motionSensorGpio = 0; var red = NusbioGpio.Gpio1; var green = NusbioGpio.Gpio2; using (var nusbio = new Nusbio(serialNumber)) { var motionSensor = new MotionSensorPIR(nusbio, motionSensorGpio, 3); var redLed = nusbio.GPIOS[red].AsLed; // Blink fast for 3 seconds when motion is detected var greenLed = nusbio.GPIOS[green].AsLed; // Blink every 1/2 second just to tell system is running and is ok greenLed.SetBlinkMode(500); Cls(nusbio); while (nusbio.Loop()) { var motionType = motionSensor.MotionDetected(); if (motionType == MotionSensorPIR.MotionDetectedType.MotionDetected) { ConsoleEx.Write(0, 8, string.Format("[{0}] MotionSensor:{1,-20}", DateTime.Now, motionType), ConsoleColor.DarkCyan); redLed.SetBlinkMode(200); } else if (motionType == MotionSensorPIR.MotionDetectedType.None) { ConsoleEx.Write(0, 8, string.Format("[{0}] MotionSensor:{1,-20}", DateTime.Now, motionType), ConsoleColor.DarkCyan); redLed.SetBlinkModeOff(); } if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) break; } } } Console.Clear(); }
public static GpioSequence ShiftOutHardWare(Nusbio nusbio, int dataPin , int clockPin, int val, GpioSequence gs = null, bool send = true, SB bitOrder = SB.MSBFIRST) { if(gs == null) gs = new GpioSequence(nusbio.GetGpioMask()); for (var i = 0; i < 8; i++) { int a = 0; if (bitOrder == SB.LSBFIRST) a = (val & (1 << i)); else a = (val & (1 << (7 - i))); gs.ClockBit(nusbio[clockPin], nusbio[dataPin], a > 0); } if(send) nusbio.SetGpioMask(gs.ToArray()); return gs; }
private static void ShiftOut(Nusbio nusbio, NusbioGpio dataPin , NusbioGpio clockPin , int bitOrder , int val) { int i; for (i = 0; i < 8; i++) { if (bitOrder == LSBFIRST) { var a = (val & (1 << i)); nusbio.GPIOS[dataPin].DigitalWrite(Nusbio.ConvertToPinState(a)); } else { var b = (val & (1 << (7 - i))); nusbio.GPIOS[dataPin].DigitalWrite(Nusbio.ConvertToPinState(b)); } nusbio.GPIOS[clockPin].DigitalWrite(PinState.High); nusbio.GPIOS[clockPin].DigitalWrite(PinState.Low); } }
public static void Run(string[] args) { Console.WriteLine("Nusbio initialization"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } var lightSensor = NusbioGpio.Gpio1; // Input using (var nusbio = new Nusbio(serialNumber)) // , inputGpios: new List<NusbioGpio>() {lightSensor} { var photocellResistor = new LightSensorWithCapacitor(nusbio, lightSensor); photocellResistor.AddCalibarationValue ("Bright" , 00, 10) .AddCalibarationValue("OfficeDay" , 10, 50) .AddCalibarationValue("OfficeNight" , 50, 100) .AddCalibarationValue("Darkish" , 100, 300) .AddCalibarationValue("CompleteDark", 300, LightSensorWithCapacitor.TimeOutMaxValue); Cls(nusbio); while(nusbio.Loop(2000)) { ConsoleEx.Write(0, 9, string.Format("[{0}] Value:{1,-4} Calibarated:{2,-15}", DateTime.Now, photocellResistor.Value, photocellResistor.CalibratedValue), ConsoleColor.DarkCyan); if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) break; } } } Console.Clear(); }
private static void AnimateBlocking4(Nusbio nusbio) { var maxGpio = 8; var gpiosSequence = DS.List( NusbioGpio.Gpio0, NusbioGpio.Gpio1, NusbioGpio.Gpio2, NusbioGpio.Gpio3, NusbioGpio.Gpio4, NusbioGpio.Gpio5, NusbioGpio.Gpio6, NusbioGpio.Gpio7, NusbioGpio.Gpio6, NusbioGpio.Gpio5, NusbioGpio.Gpio4, NusbioGpio.Gpio3, NusbioGpio.Gpio2, NusbioGpio.Gpio1 ); int delay = 100; while(true) { if (Console.KeyAvailable) { var k = Console.ReadKey(true); break; } foreach(var g in gpiosSequence) { nusbio[g].DigitalWrite(PinState.High); TimePeriod.Sleep(delay); nusbio[g].DigitalWrite(PinState.Low); } } }
static void Cls(Nusbio nusbio) { Console.Clear(); ConsoleEx.TitleBar(0, GetAssemblyProduct(), ConsoleColor.Yellow, ConsoleColor.DarkBlue); ConsoleEx.WriteMenu(-1, 5, "0) Read 10 pages A)ll read all pages"); ConsoleEx.WriteMenu(-1, 7, "Q)uit"); ConsoleEx.TitleBar(ConsoleEx.WindowHeight-2, Nusbio.GetAssemblyCopyright(), ConsoleColor.White, ConsoleColor.DarkBlue); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-3, string.Format("Nusbio SerialNumber:{0}, Description:{1}", nusbio.SerialNumber, nusbio.Description), ConsoleColor.Black, ConsoleColor.DarkCyan); ConsoleEx.Bar(0, ConsoleEx.WindowHeight-4, string.Format("EEPROM:{0}", _eeprom.ToString()), ConsoleColor.Black, ConsoleColor.DarkCyan); }
public MCP9808_TemperatureSensor(Nusbio nusbio, NusbioGpio sdaOutPin, NusbioGpio sclPin, byte deviceId = MCP9808_I2CADDR_DEFAULT, int waitTimeAfterWriteOperation = 5, bool debug = false) { this._i2c = new I2CEngine(nusbio, sdaOutPin, sclPin, deviceId, debug); this._nusbio = nusbio; }
public BiColorLedMCP4231Manager(Nusbio nusbio, NusbioGpio selectGpio, NusbioGpio mosiGpio, NusbioGpio misoGpio, NusbioGpio clockGpio, bool debug = false) : base(nusbio, selectGpio, mosiGpio, misoGpio, clockGpio, debug) { base.MaxResistance = 10000; // 10k Ohm }
public Tmp36AnalogTemperatureSensor(Nusbio nusbio) : base(nusbio) { }
void Init(IDigitalWriteRead digitalWriteRead, uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7) { // Detect if the digitalWriteRead implementation is a real Nusbio rather than an gpio extender for Nusbio. // With Nusbio we can use some of the hardware acceleration to send the data if(digitalWriteRead is Nusbio) { this.Nusbio = digitalWriteRead as Nusbio; } _rs_pin = rs; _rw_pin = rw; _enable_pin = enable; _data_pins[0] = d0; _data_pins[1] = d1; _data_pins[2] = d2; _data_pins[3] = d3; _data_pins[4] = d4; _data_pins[5] = d5; _data_pins[6] = d6; _data_pins[7] = d7; this.SetPinMode(_rs_pin, MadeInTheUSB.GPIO.PinMode.Output); // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# if (_rw_pin != 255) { SetPinMode(_rw_pin, MadeInTheUSB.GPIO.PinMode.Output); } SetPinMode(_enable_pin, MadeInTheUSB.GPIO.PinMode.Output); if (fourbitmode > 0) _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; else _displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; Begin(16, 1); }
public static int ShiftIn(Nusbio nusbio, NusbioGpio dataPin, NusbioGpio clockPin, int bitOrder) { int value = 0; int i; for (i = 0; i < 8; ++i) { nusbio.GPIOS[clockPin].DigitalWrite(PinState.High); if (bitOrder == LSBFIRST) value |= Nusbio.ConvertTo1Or0(nusbio.GPIOS[dataPin].DigitalRead()) << i; else value |= Nusbio.ConvertTo1Or0(nusbio.GPIOS[dataPin].DigitalRead()) << (7 - i); nusbio.GPIOS[clockPin].DigitalWrite(PinState.Low); } return value; }
static void ReadEEPromPerPage(int numberOfPageToRead, Nusbio nusbio) { Console.Clear(); var totalErrorCount = 0; var t = Stopwatch.StartNew(); byte [] buf; //nusbio.SetBaudRate(230400*8); for (var p = 0; p < numberOfPageToRead; p++) { if(p % 50 == 0 || p<5) Console.WriteLine("Reading page {0}", p); var r = _eeprom.ReadPage(p*EEPROM_24LC256.PAGE_SIZE, EEPROM_24LC256.PAGE_SIZE); if (r.Succeeded) { buf = r.Buffer; for (var i = 0; i < EEPROM_24LC256.PAGE_SIZE; i++) { var expected = i; if (p == 2) expected = NEW_WRITTEN_VALUE_1; if (p == 3) expected = NEW_WRITTEN_VALUE_2; if (buf[i] != expected) { Console.WriteLine("Failed Page:{0} [{1}] = {2}, expected {3}", p, i, buf[i], expected); totalErrorCount++; } } } else { Console.WriteLine("ReadBuffer failure"); } } t.Stop(); Console.WriteLine("{0} error(s), Time:{1}", totalErrorCount, t.ElapsedMilliseconds); Console.WriteLine("Hit enter key"); Console.ReadLine(); }
public LiquidCrystal_I2C(Nusbio nusbio, NusbioGpio sdaOutPin, NusbioGpio sclPin, int cols, int rows, byte deviceId = 0x27, bool debug = false) { this._cols = (uint8_t)cols; this._rows = (uint8_t)rows; this._nusbio = nusbio; this._i2c = new I2CEngine(nusbio, sdaOutPin, sdaOutPin, sclPin, 0, debug); this._backlightval = LCD_NOBACKLIGHT; this._i2c.DeviceId = deviceId; }
public static void Run(string[] args) { Console.WriteLine("Nusbio initialization"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("nusbio not detected"); return; } var sclPin = NusbioGpio.Gpio0; // White var sdaPin = NusbioGpio.Gpio1; // Green byte EEPROM_I2C_ADDR = 0x50; // Microship 24LC256 = 32k byte MCP23008_I2C_ADDR = 0x20; // Microship MCP 23008 = 8 gpios using (var nusbio = new Nusbio(serialNumber)) // , { _eeprom = new EEPROM_24LC256(nusbio, sdaPin, sclPin); _eeprom.Begin(EEPROM_I2C_ADDR); _mcp = new MCP23008(nusbio, sdaPin, sclPin, gpioStartIndex:9); _mcp.Begin(MCP23008_I2C_ADDR); Cls(nusbio); var standardsGpios = new List<NusbioGpio>() { NusbioGpio.Gpio2, NusbioGpio.Gpio3, NusbioGpio.Gpio4, NusbioGpio.Gpio5, NusbioGpio.Gpio6, NusbioGpio.Gpio7 }; var extendedGpios = new List<string>() { NusbioGpioEx.Gpio9 , NusbioGpioEx.Gpio10, NusbioGpioEx.Gpio11, NusbioGpioEx.Gpio12, NusbioGpioEx.Gpio13, NusbioGpioEx.Gpio14, NusbioGpioEx.Gpio15, NusbioGpioEx.Gpio16 }; var g = NusbioGpioEx.Gpio16; _mcp.SetPinMode(g, PinMode.Input); while(nusbio.Loop()) { //if (_mcp.GPIOS[g].DigitalRead() == PinState.High) //{ // ConsoleEx.Write(0, 10, string.Format("[{0}] Button Down", DateTime.Now), ConsoleColor.Cyan); //} //else //{ // ConsoleEx.Write(0, 10, string.Format("[{0}] Button Up ", DateTime.Now), ConsoleColor.Cyan); //} foreach (var eg in extendedGpios) { _mcp.GPIOS[eg].State = !_mcp.GPIOS[eg].State; _mcp.GPIOS[eg].DigitalWrite(_mcp.GPIOS[eg].State); } foreach (var sg in standardsGpios) { nusbio.GPIOS[sg].State = !nusbio.GPIOS[sg].State; nusbio.GPIOS[sg].DigitalWrite(nusbio.GPIOS[sg].State); } TimePeriod.Sleep(300); if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.D0) { ReadEEPromPerPage(10, nusbio); Cls(nusbio); } if (k == ConsoleKey.A) { ReadEEPromPerPage(512, nusbio); Cls(nusbio); } if (k == ConsoleKey.Q) { _mcp.AllOff(); break; } } } } Console.Clear(); }
public ArduinoClient(Nusbio nusbio, NusbioGpio gpio) { this._gpio = gpio; this._nusbio = nusbio; }
public AnalogLightSensor(Nusbio nusbio) : base(nusbio) { }
public static void Run(string[] args) { Console.WriteLine("Nusbio Initializing"); var serialNumber = Nusbio.Detect(); if (serialNumber == null) // Detect the first Nusbio available { Console.WriteLine("Nusbio not detected"); return; } using (var nusbio = new Nusbio(serialNumber)) { Cls(nusbio); var sr = new ShiftRegister74HC595(nusbio, dataPin, latchPin, clockPin); sr.Send8BitValue(0); while (nusbio.Loop()) { if (Console.KeyAvailable) { var k = Console.ReadKey(true).Key; if (k == ConsoleKey.Q) break; if (k == ConsoleKey.A) sr.AnimateOneLeftToRightAndRightToLeft(15); } } } Console.Clear(); }