Example #1
0
        public BitBotController(PCA9685Controller pcaController,
                                PwmChannel buzzer,
                                AdcChannel leftLineSensor,
                                AdcChannel rightLineSensor,
                                GpioPin distanceTrigPin,
                                GpioPin distanceEchoPin,
                                GpioPin frontSensorEnable,
                                AdcChannel frontSensorValue,
                                GpioPin colorLedPin)
        {
            this.pcaController = pcaController;
            this.buzzer        = buzzer;
            this.pcaController.SetFrequency(50);
            this.frontSensorEnable = frontSensorEnable;
            this.frontSensorValue  = frontSensorValue;
            this.leftLineSensor    = leftLineSensor;
            this.rightLineSensor   = rightLineSensor;

            this.pulseFeedback = new PulseFeedback(distanceTrigPin, distanceEchoPin, PulseFeedbackMode.EchoDuration)
            {
                DisableInterrupts = false,
                Timeout           = TimeSpan.FromSeconds(1),
                PulseLength       = TimeSpan.FromTicks(100),
                PulseValue        = GpioPinValue.High,
                EchoValue         = GpioPinValue.High,
            };

            this.frontSensorEnable.SetDriveMode(GpioPinDriveMode.Output);
            this.frontSensorEnable.Write(GpioPinValue.High);
            var sg = new SignalGenerator(colorLedPin);

            this.ws2812 = new WS2812Controller(sg, 3);
        }
Example #2
0
        void Setup(AdcChannel analogPort,
                   float minimumVoltageCalibration = 0f,
                   float maximumVoltageCalibration = 3.3f)
        {
            samplingSetting           = new AnalogSamplingSetting();
            AnalogInputPort           = analogPort;
            MinimumVoltageCalibration = minimumVoltageCalibration;
            MaximumVoltageCalibration = maximumVoltageCalibration;

            /*
             * // wire up our observable
             * // have to convert from voltage to temp units for our consumers
             * // this is where the magic is: this allows us to extend the IObservable
             * // pattern through the sensor driver
             * AnalogInputPort.Subscribe(
             *  new FilterableChangeObserver<FloatChangeResult, float>(
             *      h => {
             *          var newMoisture = VoltageToMoisture(h.New);
             *          var oldMoisture = VoltageToMoisture(h.Old);
             *          Moisture = newMoisture; // save state
             *          RaiseChangedAndNotify(new FloatChangeResult(
             *              newMoisture,
             *              oldMoisture));
             *      })
             *  );*/
        }
Example #3
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param>
        public Joystick(int AnalogPin4, int AnalogPin5, int DigitalPin3)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported('A', this);
            var controller = AdcController.GetDefault();

            this.inputX = controller.OpenChannel(AnalogPin4); //GTI.AnalogInputFactory.Create(socket, Socket.Pin.Four, this);
            this.inputY = controller.OpenChannel(AnalogPin5); //GTI.AnalogInputFactory.Create(socket, Socket.Pin.Five, this);
            var DigitalController = GpioController.GetDefault();

            this.input = DigitalController.OpenPin(DigitalPin3);//GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            if (input.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
            {
                input.SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
            else
            {
                input.SetDriveMode(GpioPinDriveMode.Input);
            }
            input.ValueChanged += Input_ValueChanged;
            //this.input = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this);
            //this.input.Interrupt += (a, b) => this.OnJoystickEvent(this, b ? ButtonState.Released : ButtonState.Pressed);

            this.offsetX = 0;
            this.offsetY = 0;
            this.samples = 5;
        }
Example #4
0
        /// <summary>
        ///     Create a new light sensor object using a static reference voltage.
        /// </summary>
        /// <param name="pin">AnalogChannel connected to the sensor.</param>
        public Temt6000(string AnalogControllerName, int pin)
        {
            var adc = AdcController.FromName(AnalogControllerName);

            sensor = adc.OpenChannel(pin);
            //sensor = device.CreateAnalogInputPort(pin);
        }
Example #5
0
        public static void Main()
        {
            Debug.WriteLine("devMobile.Longboard.PwmTest starting");
            Debug.WriteLine(PwmController.GetDeviceSelector());

            try
            {
                PwmController pwm        = PwmController.FromId("TIM5");
                AdcController adc        = AdcController.GetDefault();
                AdcChannel    adcChannel = adc.OpenChannel(0);

                PwmPin pwmPin = pwm.OpenPin(PinNumber('A', 0));
                pwmPin.Controller.SetDesiredFrequency(1000);
                pwmPin.Start();

                while (true)
                {
                    double value = adcChannel.ReadRatio();

                    Debug.WriteLine(value.ToString("F2"));

                    pwmPin.SetActiveDutyCyclePercentage(value);

                    Thread.Sleep(100);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Example #6
0
 public AnalogTemperature(AdcChannel analogInputPort,
                          KnownSensorType sensorType,
                          Calibration calibration = null)
 {
     SetAnalogPort(analogInputPort,
                   sensorType,
                   calibration);
 }
Example #7
0
 /// <summary>
 /// Disposes the underlying objects. This method will be called automatically and should not be called by user
 /// code.
 /// </summary>
 protected override void DisposeResource()
 {
     if (_channel != null)
     {
         _channel.Dispose();
         _channel = null;
     }
 }
Example #8
0
 public MCP970XBase(AdcChannel channel, int referenceMilliVolts, double zeroDegreeOffset, double millivoltsPerDegree, double calibrationOffset)
 {
     this.channel             = channel;
     this.ReferenceMilliVolts = referenceMilliVolts;
     this.ZeroDegreeOffset    = zeroDegreeOffset;
     this.MillivoltsPerDegree = millivoltsPerDegree;
     this.CalibrationOffset   = calibrationOffset;
 }
Example #9
0
 /// <summary>
 /// Creates a Capacitive soil moisture sensor object with the especified AnalogInputPort.
 /// </summary>
 /// <param name="analogPort"></param>
 public Capacitive(
     AdcChannel analogPort,
     float minimumVoltageCalibration = 0f,
     float maximumVoltageCalibration = 3.3f)
 {
     Setup(analogPort,
           minimumVoltageCalibration,
           maximumVoltageCalibration);
 }
Example #10
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public CurrentACS712(int AnalogPin5)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported('A', this);
            var controller = AdcController.GetDefault();

            this.input = controller.OpenChannel(AnalogPin5);
            //this.input = AdcChannelFactory.Create(socket, Socket.Pin.Five, this);
        }
Example #11
0
        private async Task InitAdc()
        {
            var list = await AdcController.GetControllersAsync(PicAdcProvider.Instance);

            var controller = list[0];

            _channel = controller.OpenChannel(0);
            _timer.Start();
        }
Example #12
0
 public float GetVoltage(AdcChannel channel)
 {
     this.writeBuffer[0] = (ushort)channel; //select ADC channel
     this.readBuffer[0] = 0; //reset buffer for safety
     spi.WriteRead(writeBuffer, readBuffer); //trigger conversion and read result
     //raw value is 12 Bit the 4 most significant bits of the ushort are zero
     ushort rawValue = readBuffer[0];
     return rawValue / 4096.0f * this.supplyVoltage; //smallest change is 1/4096 of supply voltage
 }
Example #13
0
        public Gp2D12(string AnalogControllerName, int analogInputPin)
        {
            var adc = AdcController.FromName(AnalogControllerName);

            analogInputPort = adc.OpenChannel(analogInputPin);
            //analogInputPort = device.CreateAnalogInputPort(analogInputPin);
            Thread task1 = new Thread(new ThreadStart(ReadLoop));

            task1.Start();
        }
Example #14
0
 /// <summary>Returns the measured voltage in Volt of the specified ADC channel.</summary>
 public float this[AdcChannel channel]
 {
     get { return this.voltages[(int)channel]; }
     set
     {
         if (value < 0 || value >= this.supplyVoltage / 1000.0f)
             throw new ArgumentOutOfRangeException("value", value, null);
         this.voltages[(int)channel] = value;
     }
 }
Example #15
0
        public float GetVoltage(AdcChannel channel)
        {
            this.writeBuffer[0] = (ushort)channel;  //select ADC channel
            this.readBuffer[0]  = 0;                //reset buffer for safety
            spi.WriteRead(writeBuffer, readBuffer); //trigger conversion and read result
            //raw value is 12 Bit the 4 most significant bits of the ushort are zero
            ushort rawValue = readBuffer[0];

            return(rawValue / 4096.0f * this.supplyVoltage); //smallest change is 1/4096 of supply voltage
        }
Example #16
0
 void Setup(AdcChannel analogPort,
            GpioPin digitalPort,
            float minimumVoltageCalibration = 0f,
            float maximumVoltageCalibration = 3.3f)
 {
     AnalogInputPort           = analogPort;
     DigitalPort               = digitalPort;
     MinimumVoltageCalibration = minimumVoltageCalibration;
     MaximumVoltageCalibration = maximumVoltageCalibration;
 }
Example #17
0
        private double Read(AdcChannel input)
        {
            double total = 0;

            for (int i = 0; i < this.samples; i++)
            {
                total += input.ReadRatio();
            }

            return(total / this.samples);
        }
Example #18
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="AnalogPin3">The socket that has analog pin.</param>
        public LightSense(int AnalogPin3)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported('A', this);

            var controller = AdcController.GetDefault();

            this.input = controller.OpenChannel(AnalogPin3);

            //this.input = GTI.AnalogInputFactory.Create(socket, Socket.Pin.Three, this);
        }
Example #19
0
 /// <summary>
 /// Creates a FC28 soil moisture sensor object with the especified analog pin and digital pin.
 /// </summary>
 /// <param name="analogPort"></param>
 /// <param name="digitalPort"></param>
 public Fc28(
     AdcChannel analogPort,
     GpioPin digitalPort,
     float minimumVoltageCalibration = 0f,
     float maximumVoltageCalibration = 3.3f)
 {
     Setup(analogPort,
           digitalPort,
           minimumVoltageCalibration,
           maximumVoltageCalibration);
 }
Example #20
0
 /// <summary>Returns the measured voltage in Volt of the specified ADC channel.</summary>
 public float this[AdcChannel channel]
 {
     get { return(this.voltages[(int)channel]); }
     set
     {
         if (value < 0 || value >= this.supplyVoltage / 1000.0f)
         {
             throw new ArgumentOutOfRangeException("value", value, null);
         }
         this.voltages[(int)channel] = value;
     }
 }
Example #21
0
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="xChannelPin">Pin of adc channel to read x(yellow wire)</param>
        /// <param name="yChannelPin">Pin of adc channel to read y(white wire)</param>
        public ThumbJoystick(int xChannelPin, int yChannelPin)
        {
            SetDeadZone(2050, 2025, 50);
            _bReadButtonClick = true;
            _bReadButtonDown  = true;
            _bReadButtonLeft  = true;
            _bReadButtonRight = true;
            _bReadButtonUp    = true;
            var adcCtl = AdcController.GetDefault();

            _xChannel = adcCtl.OpenChannel(xChannelPin);
            _yChannel = adcCtl.OpenChannel(yChannelPin);
        }
        public MainPage()
        {
            this.InitializeComponent();

            // Create a new SpeechSynthesizer instance for later use.
            synthesizer = new SpeechSynthesizer();

            // Initialize the ADC chip for use
            adcController     = (await AdcController.GetControllersAsync(AdcMcp3008Provider.GetAdcProvider()))[0];
            LowPotAdcChannel  = adcController.OpenChannel(LowPotentiometerADCChannel);
            HighPotAdcChannel = adcController.OpenChannel(HighPotentiometerADCChannel);
            CdsAdcChannel     = adcController.OpenChannel(CDSADCChannel);
        }
Example #23
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="socketNumber">The socket that this module is plugged in to.</param>
        public Moisture(int DigitalPin6, int AnalogPin3)
        {
            var controller = GpioController.GetDefault();

            this.enable = controller.OpenPin(DigitalPin6);
            this.enable.SetDriveMode(GpioPinDriveMode.Output);
            var AnalogController = AdcController.GetDefault();

            this.input = AnalogController.OpenChannel(AnalogPin3);
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported('A', this);

            //this.input = AdcChannelFactory.Create(socket, Socket.Pin.Three, this);
            //this.enable = GpioPinFactory.Create(socket, Socket.Pin.Six, true, this);
        }
Example #24
0
        static async Task adc(int channelint)
        {
            try
            {
                UpBridge.Up   upb        = new UpBridge.Up();
                AdcController controller = await AdcController.GetDefaultAsync();

                AdcChannel channel = controller.OpenChannel(channelint);
                Console.WriteLine(channel.ReadValue());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Example #25
0
        /// <summary>Constructs a new instance.</summary>
        /// <param name="AnalogPin3">The socket that has analog pin.</param>
        public GasSense(int AnalogPin3, int DigitalPin4)
        {
            //Socket socket = Socket.GetSocket(socketNumber, true, this, null);
            //socket.EnsureTypeIsSupported('A', this);
            var controller = GpioController.GetDefault();

            this.enable = controller.OpenPin(DigitalPin4);
            this.enable.SetDriveMode(GpioPinDriveMode.Output);

            var AnalogController = AdcController.GetDefault();

            this.input = AnalogController.OpenChannel(AnalogPin3);
            //this.input = GTI.AnalogInputFactory.Create(socket, Socket.Pin.Three, this);
            //this.enable = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Four, false, this);
        }
Example #26
0
        void Setup(AdcChannel analogPort, GpioPin digitalInputPort)
        {
            this.analogPort       = analogPort;
            this.digitalInputPort = digitalInputPort;

            digitalInputPort.ValueChanged += DigitalInputPort_ValueChanged;

            //analogPort.StartSampling();

            while (true)
            {
                Debug.WriteLine($"Analog: {analogPort.ReadValue()}");
                Thread.Sleep(250);
            }
        }
Example #27
0
        /// <inheritdoc/>
        public void Dispose()
        {
            if (updater != null)
            {
                updater.Dispose();
                updater = null;
            }

            if (adcChannel != null)
            {
                adcChannel.Dispose();
                adcChannel = null;
            }

            isInitialized = false;
        }
Example #28
0
        /// <summary>
        ///     Create a new ADXL335 sensor object.
        /// </summary>
        /// <param name="xPin">Analog pin connected to the X axis output from the ADXL335 sensor.</param>
        /// <param name="yPin">Analog pin connected to the Y axis output from the ADXL335 sensor.</param>
        /// <param name="zPin">Analog pin connected to the Z axis output from the ADXL335 sensor.</param>
        public Adxl335(string AnalogControllerName, int xPin, int yPin, int zPin)
        {
            var adc = AdcController.FromName(AnalogControllerName);

            _xPort = adc.OpenChannel(xPin);
            _yPort = adc.OpenChannel(yPin);
            _zPort = adc.OpenChannel(zPin);

            //
            //  Now set the default calibration data.
            //
            XVoltsPerG    = 0.325f;
            YVoltsPerG    = 0.325f;
            ZVoltsPerG    = 0.550f;
            SupplyVoltage = 3.3f;
        }
        static ZumoBot()
        {
            led = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D13);
            led.SetDriveMode(GpioPinDriveMode.Output);

            button = GpioController.GetDefault().OpenPin(FEZ.GpioPin.D12);
            button.SetDriveMode(GpioPinDriveMode.InputPullUp);

            var pwm = PwmController.FromName(FEZ.PwmChannel.Controller3.Id);

            pwm.SetDesiredFrequency(4 * 1000);
            Buzzer = pwm.OpenChannel(FEZ.PwmChannel.Controller3.D6); // D3 or D6
            Buzzer.Stop();
            Buzzer.SetActiveDutyCyclePercentage(0.5);

            voltage = AdcController.GetDefault().OpenChannel(FEZ.AdcChannel.A1);
        }
Example #30
0
        static ZumoBot()
        {
            SetDefaultPin();
            led = GpioController.GetDefault().OpenPin(PinD13);
            led.SetDriveMode(GpioPinDriveMode.Output);

            button = GpioController.GetDefault().OpenPin(PinD12);
            button.SetDriveMode(GpioPinDriveMode.InputPullUp);

            PwmController pwm = PwmController.FromId(PWMController3Id);

            pwm.SetDesiredFrequency(4 * 1000);
            Buzzer = pwm.OpenPin(PinD6); // D3 or D6
            Buzzer.Stop();
            Buzzer.SetActiveDutyCyclePercentage(0.5);

            voltage = AdcController.GetDefault().OpenChannel(PinA1);
        }
Example #31
0
        void SetAnalogPort(AdcChannel horizontalInputPort, AdcChannel verticalInputPort,
                           JoystickCalibration calibration = null, bool isInverted = false)
        {
            HorizontalInputPort = horizontalInputPort;
            VerticalInputPort   = verticalInputPort;
            IsInverted          = isInverted;

            if (calibration == null)
            {
                Calibration = new JoystickCalibration(3.3f);
            }
            else
            {
                Calibration = calibration;
            }

            InitSubscriptions();
        }
Example #32
0
        /// <summary>
        ///     Create a new ADXL337 sensor object.
        /// </summary>
        /// <param name="xPin">Analog pin connected to the X axis output from the ADXL335 sensor.</param>
        /// <param name="yPin">Analog pin connected to the Y axis output from the ADXL335 sensor.</param>
        /// <param name="zPin">Analog pin connected to the Z axis output from the ADXL335 sensor.</param>
        public Adxl377(string AnalogControllerName, int xPin, int yPin, int zPin)
        {
            var adc = AdcController.FromName(AnalogControllerName);

            _xPort = adc.OpenChannel(xPin);
            _yPort = adc.OpenChannel(yPin);
            _zPort = adc.OpenChannel(zPin);
            //_xPort = device.CreateAnalogInputPort(xPin);
            //_yPort = device.CreateAnalogInputPort(yPin);
            //_zPort = device.CreateAnalogInputPort(zPin);
            //
            //  Now set the default calibration data.
            //
            XVoltsPerG    = 0.00825f;
            YVoltsPerG    = 0.00825f;
            ZVoltsPerG    = 0.00825f;
            SupplyVoltage = 3.3f;
        }