Ejemplo n.º 1
0
        public static void Main()
        {
            SoftPwm _pwm = new SoftPwm(N.Pins.GPIO_PIN_D12);

            while (true)
            {
                // start our PWM with defaults (50% duty cycle, 1hz) and run for
                // 5 seconds
                Debug.Print("Start @ 1hz, 50% dutycycle.");
                _pwm.Start();
                Thread.Sleep(5000);

                // manually stop/start at 4hz fequency and a 25% dutycycle
                Debug.Print("4hz, 25% dutycycle");
                _pwm.Stop();
                _pwm.Frequency = 4;
                _pwm.DutyCycle = 0.25f;
                _pwm.Start();
                Thread.Sleep(5000);

                // change it up again, while it's still running
                Debug.Print("8hz, 50% dutycycle");
                _pwm.Frequency = 8;
                _pwm.DutyCycle = 0.5f;
                Thread.Sleep(5000);

                // stop and reset to defaults
                _pwm.Stop();
                _pwm.Frequency = 1.0f;
                _pwm.DutyCycle = 0.5f;
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //int ret = Init.WiringPiSetup();
            int ret = Init.WiringPiSetupGpio();

            if (ret == -1)
            {
                Console.WriteLine("Init failed: {0}", ret);
                return;
            }
            int range = -1;
            int value = -1;
            int pin   = 0;

            try {
                pin   = Int32.Parse(args[0]);
                range = Int32.Parse(args[1]);
                value = Int32.Parse(args[2]);
            } catch {
                Console.WriteLine("Parse Error");
                return;
            }
            Console.WriteLine("range:{0}, value:{1}", range, value);
            SoftPwm.Create(pin, value, range);
            Console.WriteLine("Init succeeded");

            SoftPwm.Write(pin, value);
            Console.ReadKey(true);
            SoftPwm.Stop(pin);
            Thread.Sleep(100);
        }
Ejemplo n.º 3
0
 public HobbyServo(SoftPwm pwm, double minPulseWidth = 0.8, double maxPulseWidth = 2.8)
 {
     this.Pwm = pwm;
     this.Pwm.Period = 25;
     MinPulseWidth = minPulseWidth;
     MaxPulseWidth = maxPulseWidth;
     Angle = 90;
 }
Ejemplo n.º 4
0
 public HobbyServo(SoftPwm pwm, double minPulseWidth = 0.8, double maxPulseWidth = 2.8)
 {
     this.Pwm        = pwm;
     this.Pwm.Period = 25;
     MinPulseWidth   = minPulseWidth;
     MaxPulseWidth   = maxPulseWidth;
     Angle           = 90;
 }
Ejemplo n.º 5
0
        public DehydratorController(AnalogTemperature tempSensor, SoftPwm heater, Relay fan, ITextDisplay display)
        {
            _tempSensor     = tempSensor;
            _heaterRelayPwm = heater;
            _fanRelay       = fan;
            _display        = display;

            _pidController = new StandardPidController();
            _pidController.ProportionalComponent   = .5f;  // proportional
            _pidController.IntegralComponent       = .55f; // integral time minutes
            _pidController.DerivativeComponent     = 0f;   // derivative time in minutes
            _pidController.OutputMin               = 0.0f; // 0% power minimum
            _pidController.OutputMax               = 1.0f; // 100% power max
            _pidController.OutputTuningInformation = false;
        }
        public TemperatureController(SoftPwm heatLampRelay, AnalogTemperature tempSensor)
        {
            // store references to the peripherals
            _heatLampRelay = heatLampRelay;
            _tempSensor    = tempSensor;

            // configure our PID controller
            _pidController = new StandardPidController();
            _pidController.ProportionalComponent   = .5f;  // proportional
            _pidController.IntegralComponent       = .55f; // integral time minutes
            _pidController.DerivativeComponent     = 0f;   // derivative time in minutes
            _pidController.OutputMin               = 0.0f; // 0% power minimum
            _pidController.OutputMax               = 1.0f; // 100% power max
            _pidController.OutputTuningInformation = true;
        }
Ejemplo n.º 7
0
        protected void InitializePeripherals()
        {
            // display
            //_display = new Lcd2004(new MCP23008());
            _display = new Lcd2004(N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D13);
            _display.Clear();
            _display.WriteLine("Display up!", 0);

            // rotary encoder
            _encoder = new RotaryEncoderWithButton(N.Pins.GPIO_PIN_D4, N.Pins.GPIO_PIN_D5, N.Pins.GPIO_PIN_D7, CircuitTerminationType.CommonGround);

            // door stuff
            _doorServo          = new ContinuousRotationServo(N.PWMChannels.PWM_PIN_D6, NamedServoConfigs.IdealContinuousRotationServo);
            _openEndStopSwitch  = new PushButton(N.Pins.GPIO_PIN_D2, CircuitTerminationType.CommonGround);
            _closeEndStopSwitch = new PushButton(N.Pins.GPIO_PIN_D3, CircuitTerminationType.CommonGround);
            _display.WriteLine("Door stuff up!", 1);

            // temp stuff
            _heatLampRelay = new SoftPwm(N.Pins.GPIO_PIN_D0, 0, 1f / 60f);
            _tempSensor    = new AnalogTemperature(N.AnalogChannels.ANALOG_PIN_A0, AnalogTemperature.KnownSensorType.LM35, updateInterval: 5000, temperatureChangeNotificationThreshold: 1.0f);
            _display.WriteLine("Temp stuff up!", 2);

            //==== now wire up all the peripheral events
            // Analog Temp Sensor. Setup to notify at half a degree changes
            _tempSensor.TemperatureChanged += (object sender, SensorFloatEventArgs e) => {
                _currentTemp = e.CurrentValue;
                Debug.Print("Current Temp: " + _currentTemp.ToString("N1"));
                UpdateInfoScreen();
            };

            _encoder.Clicked += (s, e) =>
            {
                // if the menu isn't displayed, display it. otherwise
                // encoder click events are handled by menu
                if (!_inMenu)
                {
                    this.DisplayMenu();
                }
            };


            Debug.Print("Peripherals initialized.");
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Configures the hardware perihperals (LCD, temp sensor, relays, etc.)
        /// so they can be used by the application.
        /// </summary>
        protected void InitializePeripherals()
        {
            // pushbutton (for testing)
            _pushButton = new PushButton(
                (H.Cpu.Pin) 0x15, CircuitTerminationType.Floating);

            // Rotary Encoder
            _encoder = new RotaryEncoderWithButton(
                N.Pins.GPIO_PIN_D7, N.Pins.GPIO_PIN_D6, N.Pins.GPIO_PIN_D5,
                CircuitTerminationType.CommonGround);

            // LCD
            //_display = new Lcd2004(new MCP23008());
            _display = new Lcd2004(N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D9, N.Pins.GPIO_PIN_D10, N.Pins.GPIO_PIN_D11, N.Pins.GPIO_PIN_D12, N.Pins.GPIO_PIN_D13);
            _display.Clear();
            Debug.Print("Display up.");
            _display.WriteLine("Display up!", 0);

            // Analog Temp Sensor. Setup to notify at half a degree changes
            _tempSensor = new AnalogTemperature(N.AnalogChannels.ANALOG_PIN_A0,
                                                AnalogTemperature.KnownSensorType.LM35, temperatureChangeNotificationThreshold: 0.5F);
            Debug.Print("TempSensor up.");
            _display.WriteLine("Temp Sensor up!", 1);

            // Heater driven by Software PWM
            _heaterRelayPwm = new SoftPwm(N.Pins.GPIO_PIN_D2, 0.5f, 1.0f / 30.0f);
            Debug.Print("Heater PWM up.");
            _display.WriteLine("Heater PWM up!", 2);

            // Fan Relay
            _fanRelay = new Relay(N.Pins.GPIO_PIN_D3);
            Debug.Print("Fan up.");
            _display.WriteLine("Fan up!", 3);

            // output status
            Debug.Print("Peripherals up");
            _display.WriteLine("Peripherals online!", 0);
        }