/// <summary>Creates an analog input on the given pin.</summary> /// <param name="AnalogPin">The pin to create the interface on.</param> /// <returns>The new interface.</returns> public AdcChannel CreateAnalogInput(int AnalogPin) { var AnalogController = AdcController.GetDefault(); var ThisAnalogPin = AnalogController.OpenChannel(AnalogPin); return(ThisAnalogPin); }
/// <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; }
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); } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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); }
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); }
public static void Main() { try { // See if any analog stuff is still out there Console.WriteLine(AdcController.GetDeviceSelector()); // Assign first ADC AdcController _ctl1 = AdcController.GetDefault(); // Some stats to see we are alive Console.WriteLine("Channels : " + _ctl1.ChannelCount.ToString()); Console.WriteLine("Active mode : " + _ctl1.ChannelMode.ToString()); // 0=SingleEnded, 1=Differential Console.WriteLine("Resolution : " + _ctl1.ResolutionInBits.ToString() + " bits"); Console.WriteLine("Min value : " + _ctl1.MinValue); Console.WriteLine("Max value : " + _ctl1.MaxValue); // Now open a channel. // We don't need additional HW to test ADC. // if we use the internal temp sensor AdcChannel _ac0 = _ctl1.OpenChannel(AdcChannels.Channel_0); int _val1 = -1; // Loopie for (; ;) { _val1 = _ac0.ReadValue(); Console.WriteLine("Value read from ADC = " + _val1); Thread.Sleep(1000); } } catch (Exception ex) { // Do whatever please you with the exception caught Console.WriteLine(ex.ToString()); // Loopie for (; ;) { Thread.Sleep(1000); } } }
public float GetMcuTemperature() { AdcController adc1 = AdcController.GetDefault(); adcTemp = adc1.OpenChannel(Pinout.AdcChannel.ADC_CHANNEL_SENSOR); return(adcTemp.ReadValue() / 100.00f); //https://www.st.com/resource/en/datasheet/stm32f769ni.pdf //https://electronics.stackexchange.com/questions/324321/reading-internal-temperature-sensor-stm32 //const int ADC_TEMP_3V3_30C = 0x1FF0F44C //0x1FFF7A2C; //const int ADC_TEMP_3V3_110C = 0x1FF0 F44E //0x1FFF7A2E; //const float CALIBRATION_REFERENCE_VOLTAGE = 3.3F; //const float REFERENCE_VOLTAGE = 3.0F; // supplied with Vref+ or VDDA // scale constants to current reference voltage //float adcCalTemp30C = getRegisterValue(ADC_TEMP_3V3_30C) * (REFERENCE_VOLTAGE / CALIBRATION_REFERENCE_VOLTAGE); //float adcCalTemp110C = getRegisterValue(ADC_TEMP_3V3_110C) * (REFERENCE_VOLTAGE / CALIBRATION_REFERENCE_VOLTAGE); // return (adcTemp.ReadValue() - adcCalTemp30C)/(adcCalTemp110C - adcCalTemp30C) *(110.0F - 30.0F) + 30.0F); }
public double GetTemperatureOnBoard() { AdcController adc1 = AdcController.GetDefault(); adcTemp = adc1.OpenChannel(Pinout.AdcChannel.ADC1_IN13_TEMP); double tempInCent = 0; try { var maximumValue = 4095; var analogReference = 3300; double adcTempCalcValue = (analogReference * adcTemp.ReadValue()) / maximumValue; tempInCent = ((13.582f - Math.Sqrt(184.470724f + (0.01732f * (2230.8f - adcTempCalcValue)))) / (-0.00866f)) + 30; // double tempInF = ((9f / 5f) * tempInCent) + 32f; } catch { } return(tempInCent); }
public DfRobotLcdShield(byte columns = 16, byte rows = 2) : base(new GpioLcdTransferProvider( FEZ.GpioPin.D8, FEZ.GpioPin.D9, FEZ.GpioPin.D4, FEZ.GpioPin.D5, FEZ.GpioPin.D6, FEZ.GpioPin.D7 )) { var adcController = AdcController.GetDefault(); analog = adcController.OpenChannel(FEZ.AdcChannel.A0); Begin(columns, rows); Clear(); var buttonReader = new Thread(ReadButtons); buttonReader.Start(); }
public static void Main() { Debug.WriteLine("devMobile.Longboard.ServoTest starting"); try { AdcController adc = AdcController.GetDefault(); AdcChannel adcChannel = adc.OpenChannel(0); #if POSITIONAL ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Positional, PinNumber('A', 0)); servo.ConfigurePulseParameters(0.1, 2.3); #endif #if CONTINUOUS ServoMotor servo = new ServoMotor("TIM5", ServoMotor.ServoType.Continuous, PinNumber('A', 0)); servo.ConfigurePulseParameters(0.1, 2.3); #endif while (true) { double value = adcChannel.ReadRatio(); #if POSITIONAL double position = Map(value, 0.0, 1.0, 0.0, 180); #endif #if CONTINUOUS double position = Map(value, 0.0, 1.0, -100.0, 100.0); #endif Debug.WriteLine($"Value: {value:F2} Position: {position:F1}"); servo.Set(position); Thread.Sleep(100); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
//private AdcChannel adc420mA; /// <summary> /// Returns the value of the 12V battery voltage coming in the system /// </summary> /// <returns></returns> public double GetBatteryUnregulatedVoltage() { float voltage = 0; if (adcVBAT == null) { AdcController adc1 = AdcController.GetDefault(); adcVBAT = adc1.OpenChannel(Pinout.AdcChannel.ADC1_IN8_VBAT); } var average = 0; for (byte i = 0; i < 5; i++) { average += adcVBAT.ReadValue(); Thread.Sleep(50);//pause to stabilize } try { average /= 5; //maximumValue = 4095; //analogReference = 3300; //VBat = 0.25 x VIN adc count //float voltage = ((3300 * average) / 4096)* 4; voltage = ((3300 * average) / 4096) * 0.004f; voltage += 0.25f;//small offset calibration factor for board to even drop on measure } catch { } return(voltage); }
public static void Main() { string devs = AdcController.GetDeviceSelector(); Console.WriteLine("devs=" + devs); AdcController adc1 = AdcController.GetDefault(); int max1 = adc1.MaxValue; int min1 = adc1.MinValue; Console.WriteLine("min1=" + min1.ToString() + " max1=" + max1.ToString()); AdcChannel ac0 = adc1.OpenChannel(0); // the following indexes are valid for STM32F769I-DISCO board AdcChannel vref = adc1.OpenChannel(0); AdcChannel vbat = adc1.OpenChannel(8); // VP //AdcChannel ac3 = adc1.OpenChannel(3); // VN while (true) { int value = ac0.ReadValue(); int valueVref = vref.ReadValue(); int valueVbat = vbat.ReadValue(); double percent = ac0.ReadRatio(); Console.WriteLine("value0=" + value.ToString() + " ratio=" + percent.ToString()); Console.WriteLine("verf" + valueVref.ToString() + " ratio=" + percent.ToString()); Console.WriteLine("vbat" + valueVbat.ToString() + " ratio=" + percent.ToString()); Thread.Sleep(1000); } }
public static void Main() { Debug.WriteLine("devMobile.Longboard.AdcTest starting"); Debug.WriteLine(AdcController.GetDeviceSelector()); try { AdcController adc = AdcController.GetDefault(); AdcChannel adcChannel = adc.OpenChannel(0); while (true) { double value = adcChannel.ReadRatio(); Debug.WriteLine($"Value: {value:F2}"); Thread.Sleep(100); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary>Constructs a new instance.</summary> /// <param name="channelNumber">pin 3 of A socket</param> public Potentiometer(int channelNumber) { _input = AdcController.GetDefault().OpenChannel(channelNumber); }
/// <summary> /// Constructor of Grove TemperatureSensor module /// </summary> /// <param name="adcPinNumber">Adc pin of board</param> public TemperatureSensor(int adcPinNumber) { _channel = AdcController.GetDefault().OpenChannel(adcPinNumber); }
public RotaryAngleSensor(int ChannelNumber) { var AdcCtl = AdcController.GetDefault(); Channel = AdcCtl.OpenChannel(ChannelNumber); }
/// <summary> /// Creates an instance. /// </summary> /// <param name="pin">The ADC input pin to be read by this object.</param> public AnalogAdcInput(AnalogInputPin pin) { _channel = AdcController.GetDefault().OpenChannel((int)pin); }
public SparkFunWindVaneDriver(ushort adcChannel) { var adc = AdcController.GetDefault(); _adcChannel = adc.OpenChannel(adcChannel); }
public LightSensor(int AdcPinNumber) { Channel = AdcController.GetDefault().OpenChannel(AdcPinNumber); }
public DfrobotSoilMoistureSensor(short adcChannel) { var adc1 = AdcController.GetDefault(); _adcChannel = adc1.OpenChannel(adcChannel); }
public RotaryAngleSensor(int AdcPinNumber) { Channel = AdcController.GetDefault().OpenChannel(AdcPinNumber); }
/// <summary> /// Ctor of module /// </summary> /// <param name="adcSocket">pin of adc channel (usually pin3 on A socket)</param> public LightSense(int adcSocket) { _adc = AdcController.GetDefault().OpenChannel(adcSocket); }
/// <summary> /// Constructor of Grove SoundSensor module /// </summary> /// <param name="adcPinNumber">Adc pin of board</param> public SoundSensor(int adcPinNumber) { _channel = AdcController.GetDefault().OpenChannel(adcPinNumber); }