Exemplo n.º 1
0
        public PIManager()
        {
            i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress);
            grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));

            try
            {
                i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E));
                i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62));
                lcd          = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice);
            }
            catch (Exception e)
            {
                Console.WriteLine("Lcd device not found.");
            }


            Info        = new List <string>();
            greenPulse  = 0;
            orangePulse = 0;
            redPulse    = 0;

            grovePi.PinMode(GrovePort.DigitalPin4, PinMode.Output);
            grovePi.PinMode(GrovePort.DigitalPin3, PinMode.Output);
            grovePi.PinMode(GrovePort.DigitalPin2, PinMode.Output);
        }
Exemplo n.º 2
0
 internal RotaryAngleSensor(GrovePi device, Pin pin)
 {
     if (device == null) throw new ArgumentNullException(nameof(device));
     device.PinMode(_pin, PinMode.Input);
     _device = device;
     _pin = pin;
 }
 internal DHTTemperatureAndHumiditySensor(GrovePi device, Pin pin, DHTModel model)
 {
     if (device == null) throw new ArgumentNullException(nameof(device));
     _device = device;
     _pin = pin;
     _model = model;
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress);
            GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));

            WriteLine($"Manufacturer: {grovePi.GrovePiInfo.Manufacturer}");
            WriteLine($"Board: {grovePi.GrovePiInfo.Board}");
            WriteLine($"Firmware version: {grovePi.GrovePiInfo.SoftwareVersion}");
        }
Exemplo n.º 5
0
 internal RealTimeClock(GrovePi device, Pin pin)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     _device = device;
     _pin    = pin;
 }
Exemplo n.º 6
0
 public static GrovePi GrovePi(byte address)
 {
     if (device_ == null)
     {
         I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, address);
         GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));
     }
     return(device_);
 }
Exemplo n.º 7
0
 internal RotaryEncoder(GrovePi device, Pin pin)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     _device = device;
     _pin    = pin;
 }
Exemplo n.º 8
0
 /// <summary>
 /// UltrasonicSensor constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public UltrasonicSensor(GrovePi grovePi, GrovePort port)
 {
     if (!SupportedPorts.Contains(port))
     {
         throw new ArgumentException($"Grove port {port} not supported.", nameof(port));
     }
     _grovePi = grovePi;
     _port    = port;
 }
Exemplo n.º 9
0
 internal ChainableRgbLed(GrovePi device, Pin pin)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     _device = device;
     _pin    = pin;
 }
Exemplo n.º 10
0
 internal FourDigitDisplay(GrovePi device, Pin pin)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     _device = device;
     _pin    = pin;
 }
Exemplo n.º 11
0
 internal AccelerometerSensor(GrovePi device, Pin pin)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     _device = device;
     _pin    = pin;
 }
Exemplo n.º 12
0
 internal AirQualitySensor(GrovePi device, Pin pin)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     device.PinMode(_pin, PinMode.Input);
     _device = device;
     _pin    = pin;
 }
Exemplo n.º 13
0
 /// <summary>
 /// AnalogSensor constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public AnalogSensor(GrovePi grovePi, GrovePort port)
 {
     if (!SupportedPorts.Contains(port))
     {
         throw new ArgumentException($"Grove port {port} not supported.", nameof(port));
     }
     _grovePi = grovePi;
     _port    = port;
     _grovePi.PinMode(_port, PinMode.Input);
 }
Exemplo n.º 14
0
 internal TemperatureAndHumiditySensor(GrovePi device, Pin pin, TemperatureAndHumiditySensorModel model)
 {
     if (device == null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     _device = device;
     _pin    = pin;
     _model  = model;
 }
Exemplo n.º 15
0
        /// <summary>
        /// DigitalInput constructor
        /// </summary>
        /// <param name="grovePi">The GrovePi class</param>
        /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
        public DigitalInput(GrovePi grovePi, GrovePort port)
        {
            if (!SupportedPorts.Contains(port))
            {
                throw new ArgumentException(nameof(port), "Grove port not supported");
            }

            _grovePi = grovePi;
            Port     = port;
            _grovePi.PinMode(Port, PinMode.Input);
        }
Exemplo n.º 16
0
 /// <summary>
 /// PwmOutput constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public PwmOutput(GrovePi grovePi, GrovePort port)
 {
     if (!SupportedPorts.Contains(port))
     {
         throw new ArgumentException($"Grove port {port} not supported.", nameof(port));
     }
     _grovePi = grovePi;
     _port    = port;
     _grovePi.PinMode(_port, PinMode.Output);
     Value = 0;
 }
Exemplo n.º 17
0
 /// <summary>
 /// LedBar constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 /// <param name="orientation">Orientation, Green to red is default</param>
 public LedBar(GrovePi grovePi, GrovePort port, LedBarOrientation orientation)
 {
     if (!SupportedPorts.Contains(port))
     {
         throw new ArgumentException($"Grove port {port} not supported.", nameof(port));
     }
     _grovePi     = grovePi;
     _port        = port;
     _orientation = orientation;
     _grovePi.WriteCommand(GrovePiCommand.LedBarInitialization, port, (byte)_orientation, 0);
     _level = 0;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initialize the DHT Sensor class
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 /// <param name="dhtType">The DHT type</param>
 public DhtSensor(GrovePi grovePi, GrovePort port, DhtType dhtType)
 {
     if (!SupportedPorts.Contains(port))
     {
         throw new ArgumentException($"Grove port {port} not supported.", nameof(port));
     }
     _grovePi = grovePi;
     DhtType  = dhtType;
     _port    = port;
     // Ask for the temperature so we will have one in cache
     _grovePi.WriteCommand(GrovePiCommand.DhtTemp, _port, (byte)DhtType, 0);
 }
        static void Main(string[] args)
        {
            I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress);
            GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));

            UltrasonicSensor sensor = new UltrasonicSensor(grovePi, Iot.Device.GrovePiDevice.Models.GrovePort.DigitalPin7);

            while (true)
            {
                Console.WriteLine(sensor.Value);
                Thread.Sleep(200);
            }
        }
Exemplo n.º 20
0
        static void Main(string[] args)
        {
            I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress);

            using GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));

            Iot.Device.GrovePiDevice.Sensors.LedBar bar = new Iot.Device.GrovePiDevice.Sensors.LedBar(grovePi, GrovePort.DigitalPin7);

            for (byte i = 1; i <= 10; ++i)
            {
                bar.SetOneLed(i, true);
                Console.WriteLine($"{i}\t{bar.Value}");
                Thread.Sleep(1000);
            }

            bar.SetAllLeds(0);
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress);
            GrovePi grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));

            grovePi.PinMode(GrovePort.DigitalPin5, PinMode.Output);

            Led led = new Led(grovePi, GrovePort.DigitalPin5);

            for (int i = 0; i < 25; ++i)
            {
                Console.WriteLine($"Blink no {i}");

                led.Value = PinValue.High;
                Thread.Sleep(500);
                led.Value = PinValue.Low;
                Thread.Sleep(500);
            }
        }
Exemplo n.º 22
0
        public GrovePiService()
        {
            I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress);

            GrovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));

            // Lights
            KitchenLight    = new Led(GrovePi, GrovePort.DigitalPin2);
            LivingRoomLight = new Led(GrovePi, GrovePort.DigitalPin3);
            BathroomLight   = new Led(GrovePi, GrovePort.DigitalPin4);

            // Sensors
            TempHumid = new DhtSensor(GrovePi, GrovePort.DigitalPin8, DhtType.Dht11);

            // Display
            var i2cLcdDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x3E));
            var i2cRgbDevice = I2cDevice.Create(new I2cConnectionSettings(busId: 1, deviceAddress: 0x62));

            Display = new LcdRgb1602(i2cLcdDevice, i2cRgbDevice);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Main entry point
        /// </summary>
        /// <param name="args">unused</param>
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello GrovePi!");
            PinValue relay = PinValue.Low;
            I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, GrovePi.DefaultI2cAddress);

            _grovePi = new GrovePi(I2cDevice.Create(i2CConnectionSettings));
            Console.WriteLine($"Manufacturer :{_grovePi.GrovePiInfo.Manufacturer}");
            Console.WriteLine($"Board: {_grovePi.GrovePiInfo.Board}");
            Console.WriteLine($"Firmware version: {_grovePi.GrovePiInfo.SoftwareVersion}");
            // Specific example to show how to read directly a pin without a high level class
            _grovePi.PinMode(GrovePort.AnalogPin0, PinMode.Input);
            _grovePi.PinMode(GrovePort.DigitalPin2, PinMode.Output);
            _grovePi.PinMode(GrovePort.DigitalPin3, PinMode.Output);
            _grovePi.PinMode(GrovePort.DigitalPin4, PinMode.Input);
            // 2 high level classes
            UltrasonicSensor ultrasonic = new UltrasonicSensor(_grovePi, GrovePort.DigitalPin6);
            DhtSensor        dhtSensor  = new DhtSensor(_grovePi, GrovePort.DigitalPin7, DhtType.Dht11);
            int poten = 0;

            while (!Console.KeyAvailable)
            {
                Console.Clear();
                poten = _grovePi.AnalogRead(GrovePort.AnalogPin0);
                Console.WriteLine($"Potentiometer: {poten}");
                relay = (relay == PinValue.Low) ? PinValue.High : PinValue.Low;
                _grovePi.DigitalWrite(GrovePort.DigitalPin2, relay);
                Console.WriteLine($"Relay: {relay}");
                _grovePi.AnalogWrite(GrovePort.DigitalPin3, (byte)(poten * 100 / 1023));
                Console.WriteLine($"Button: {_grovePi.DigitalRead(GrovePort.DigitalPin4)}");
                Console.WriteLine($"Ultrasonic: {ultrasonic}");
                dhtSensor.Read();
                Console.WriteLine($"{dhtSensor.DhtType}: {dhtSensor}");
                Thread.Sleep(2000);
            }
        }
Exemplo n.º 24
0
 /// <summary>
 /// Grove temperature sensor constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public GroveTemperatureSensor(GrovePi grovePi, GrovePort port)
     : base(grovePi, port)
 {
 }
Exemplo n.º 25
0
 internal ChainableRgbLed(GrovePi device, Pin pin)
 {
     if (device == null) throw new ArgumentNullException(nameof(device));
     _device = device;
     _pin = pin;
 }
Exemplo n.º 26
0
 internal RealTimeClock(GrovePi device, Pin pin)
 {
     if (device == null) throw new ArgumentNullException(nameof(device));
     _device = device;
     _pin = pin;
 }
Exemplo n.º 27
0
 /// <summary>
 /// LedBar constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public LedBar(GrovePi grovePi, GrovePort port) : this(grovePi, port, LedBarOrientation.GreenToRed)
 {
 }
Exemplo n.º 28
0
 /// <summary>
 /// Relay constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 /// <param name="inverted">If inverted, the relay is on when output is low and off when output is high</param>
 public Relay(GrovePi grovePi, GrovePort port, bool inverted) : base(grovePi, port)
 {
     IsInverted = inverted;
 }
Exemplo n.º 29
0
 internal AccelerometerSensor(GrovePi device, Pin pin)
 {
     if (device == null) throw new ArgumentNullException(nameof(device));
     _device = device;
     _pin = pin;
 }
 internal UltrasonicRangerSensor(GrovePi device, Pin pin)
 {
     _device = device;
     _pin = pin;
 }
Exemplo n.º 31
0
 /// <summary>
 /// Potentiometer sensor constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public PotentiometerSensor(GrovePi grovePi, GrovePort port) : base(grovePi, port)
 {
 }
Exemplo n.º 32
0
 /// <summary>
 /// Button constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public Button(GrovePi grovePi, GrovePort port)
     : base(grovePi, port)
 {
 }
Exemplo n.º 33
0
 /// <summary>
 /// Light sensor constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public LightSensor(GrovePi grovePi, GrovePort port)
     : base(grovePi, port)
 {
 }
Exemplo n.º 34
0
 /// <summary>
 /// Relay constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public Relay(GrovePi grovePi, GrovePort port) : this(grovePi, port, false)
 {
 }
Exemplo n.º 35
0
 /// <summary>
 /// SoundSensor constructor
 /// </summary>
 /// <param name="grovePi">The GoPiGo3 class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public SoundSensor(GrovePi grovePi, GrovePort port) : base(grovePi, port)
 {
 }
Exemplo n.º 36
0
 /// <summary>
 /// Led constructor
 /// </summary>
 /// <param name="grovePi">The GrovePi class</param>
 /// <param name="port">The grove Port, need to be in the list of SupportedPorts</param>
 public Led(GrovePi grovePi, GrovePort port)
     : base(grovePi, port)
 {
 }
Exemplo n.º 37
0
 internal FourDigitDisplay(GrovePi device, Pin pin)
 {
     if (device == null) throw new ArgumentNullException(nameof(device));
     _device = device;
     _pin = pin;
 }