/// <summary>Constructs a new instance.</summary> /// <param name="DataReadyIntPin">The GPIO pin on the FEZ board that will connect to the DRDY (Data Ready, Interupt) pin on the slave device.</param> public Compass(int DataReadyIntPin) { this.writeBuffer1 = new byte[1]; this.readBuffer6 = new byte[6]; // Device I2C1 Slave address I2cConnectionSettings Setting = new I2cConnectionSettings(I2C_SLAVE_ADDRESS); Setting.BusSpeed = I2cBusSpeed.StandardMode; // 100kHz var ctrler = I2cController.FromName(FEZ.I2cBus.I2c1); var device = ctrler.GetDevice(Setting); i2c = device; TimerInterval = new TimeSpan(0, 0, 0, 0, 200); autoEvent = new AutoResetEvent(false); var controller = GpioController.GetDefault(); this.dataReady = controller.OpenPin(DataReadyIntPin);//GTI.InterruptdataReadyFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingAndFallingEdge, this); if (dataReady.IsDriveModeSupported(DataReadyIntPin, GpioPinDriveMode.InputPullUp)) { dataReady.SetDriveMode(GpioPinDriveMode.InputPullUp); } else { dataReady.SetDriveMode(GpioPinDriveMode.Input); } dataReady.ValueChanged += OnInterrupt; }
static void TestCuteBot() { var buzzerController = PwmController.FromName(FEZBit.Timer.Pwm.Controller3.Id); var buzzerChannel = buzzerController.OpenChannel(FEZBit.Timer.Pwm.Controller3.P0); var lineDetectLeft = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P13); var lineDetectRight = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P14); var bot = new GHIElectronics.TinyCLR.Elecfreaks.TinyBit.CuteBotController( I2cController.FromName(FEZBit.I2cBus.Edge), buzzerChannel, lineDetectLeft, lineDetectRight, GpioController.GetDefault().OpenPin(FEZBit.GpioPin.P15) ); bot.Beep(); bot.SetColorLeds(1, 100, 0, 0); bot.SetColorLeds(0, 0, 50, 100); bot.SetHeadlight(true, 30, 100, 100); bot.SetHeadlight(false, 30, 0, 200); bot.SetMotorSpeed(0.5, 0.5); bot.SetMotorSpeed(0.5, -0.5); bot.SetMotorSpeed(-0.5, 0.5); bot.SetMotorSpeed(0, 0); while (true) { var l = bot.ReadLineSensor(true); var r = bot.ReadLineSensor(false); Thread.Sleep(50); bot.Beep(); } }
/// <summary> /// Create a new instance of the TSL2561 class with the specified I2C address. /// </summary> /// <remarks> /// By default the sensor will be set to low gain. /// <remarks> /// <param name="address">I2C address of the TSL2561</param> /// <param name="i2cBus">I2C bus (default = 100 KHz).</param> /// <param name="updateInterval">Update interval for the sensor (in milliseconds).</param> /// <param name="lightLevelChangeNotificationThreshold">Changes in light level greater than this value will generate an interrupt in auto-update mode.</param> public Tsl2561(string i2cBus, byte address = (byte)Addresses.Default, ushort updateInterval = MinimumPollingPeriod, float lightLevelChangeNotificationThreshold = 10.0F) { if (lightLevelChangeNotificationThreshold < 0) { throw new ArgumentOutOfRangeException(nameof(lightLevelChangeNotificationThreshold), "Light level threshold change values should be >= 0"); } LightLevelChangeNotificationThreshold = lightLevelChangeNotificationThreshold; this.updateInterval = updateInterval; var settings = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); var device = controller.GetDevice(settings); //var device = new I2cPeripheral(i2cBus, address); tsl2561 = device; // // Wait for the sensor to prepare the first reading (402ms after power on). // Thread.Sleep(410); if (updateInterval > 0) { StartUpdating(); } else { Update(); } }
/// <summary> /// Initializes a new instance of the <see cref="TempHum6Click" /> class. /// </summary> /// <param name="socket">The socket on which the TempHum6Click module is plugged on MikroBus.Net board</param> public TempHum6Click(Hardware.Socket socket) { _socket = socket; _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(0x43, 100000)); // Reset device Reset(ResetModes.Soft); // Deactivate Low Power to be able to read the PartID and UID registers. PowerMode = PowerModes.On; PartID = BitConverter.ToUInt16(ReadRegister(ENS210_REG_PART_ID, 2), 0); if (PartID != 0x210) { throw new DeviceInitialisationException("TempHum6 Click not found on I2C Bus."); } UniqueID = BitConverter.ToInt64(ReadRegister(ENS210_REG_UID, 8), 0); ConfigureSensor(new SensorConfiguration( true, true, MeasurementMode.Continuous, MeasurementMode.Continuous, false)); }
static void TestMaqueen() { var buzzerController = PwmController.FromName(FEZBit.PwmChannel.Controller3.Id); var buzzerChannel = buzzerController.OpenChannel(FEZBit.PwmChannel.Controller3.EdgeP0Channel); var lineDetectLeft = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP13); var lineDetectRight = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP14); var leftHeadlight = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP8); var rightHeadight = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP12); var bot = new GHIElectronics.TinyCLR.Dfrobot.MicroMaqueen.MaqueenController( I2cController.FromName(FEZBit.I2cBus.Edge), buzzerChannel, leftHeadlight, rightHeadight, lineDetectLeft, lineDetectRight, GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP15) ); bot.Beep(); bot.SetColorLeds(1, 100, 0, 0); bot.SetColorLeds(0, 0, 50, 100); bot.SetHeadlight(true, true); bot.SetHeadlight(false, true); bot.SetMotorSpeed(0.5, 0.5); bot.SetMotorSpeed(0.5, -0.5); bot.SetMotorSpeed(-0.5, 0.5); bot.SetMotorSpeed(0, 0); while (true) { var l = bot.ReadLineSensor(true); var r = bot.ReadLineSensor(false); Thread.Sleep(50); bot.Beep(); } }
private void ThreadTest() { this.isRuning = true; try { var i2cController = I2cController.FromName("GHIElectronics.TinyCLR.NativeApis.STM32H7.I2cController\\0"); var lis2hh12 = new LIS2HH12Controller(i2cController); while (this.isRuning) { var x = (int)lis2hh12.X; var y = (int)lis2hh12.Y; var z = (int)lis2hh12.Z; this.UpdateStatusText("X = " + x + ", Y = " + y + ", Z = " + z, true); Thread.Sleep(1); } } catch { } this.isRuning = false; return; }
/// <summary>Initializes a new instance of the <see cref="Proximity3Click" /> class.</summary> /// <param name="socket">The socket on which the ADC3 Click board is plugged on MikroBus.Net</param> /// <param name="address">The I2C address of the module</param> public Proximity3Click(Hardware.Socket socket, Byte address = 0x51) { _prox = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000)); if (ChipRevision.Major == 0x10 & ChipRevision.Minor == 0x58) { _prox.Write(new Byte[] { ALS_CONF_REG, _alsConf, 0b00000000 });
private void ThreadTest() { this.isRunning = true; var i2cController = I2cController.FromName(SC20260.I2cBus.I2c1); try { var ov9655 = new Ov9655Controller(i2cController); read_id: try { var id = ov9655.ReadId(); } catch { goto read_id; } byte[] data = null; UnmanagedBuffer unmangedBuffer = null; if (Memory.UnmanagedMemory.FreeBytes != 0) { unmangedBuffer = new UnmanagedBuffer(640 * 480 * 2); data = unmangedBuffer.Bytes; } else { data = new byte[640 * 480 * 2]; } ov9655.SetResolution(Ov9655Controller.Resolution.Vga); var displayController = Display.DisplayController; while (this.isRunning) { try { ov9655.Capture(data, 500); displayController.DrawBuffer(0, this.TopBar.ActualHeight, 0, 0, 480, 272 - this.TopBar.ActualHeight, 640, data, 0); } catch { } Thread.Sleep(10); } if (unmangedBuffer != null) { unmangedBuffer.Dispose(); } } catch { } this.isRunning = false; return; }
private bool DoTestI2c() { this.UpdateStatusText("Reading LIS2HH12 sensor...", true); try { var i2cController = I2cController.FromName("GHIElectronics.TinyCLR.NativeApis.STM32H7.I2cController\\0"); var lis2hh12 = new LIS2HH12Controller(i2cController); while (this.isRunning) { var x = (int)lis2hh12.X; var y = (int)lis2hh12.Y; var z = (int)lis2hh12.Z; if (x != y && x != z && y != z && x != 0 && y != 0 && z != 0 && x != double.MaxValue && y != double.MaxValue && z != double.MaxValue) { break; } Thread.Sleep(20); } } catch { } return(true); }
public static void Main() { var settings = BME280Driver.GetI2CConnectionSettings(BME280Address.Primary); var controller = I2cController.FromName(G120E.I2cBus.I2c0); var device = controller.GetDevice(settings); var driver = new BME280Driver(device); driver.Initialize(); driver.ChangeSettings( BME280SensorMode.Forced, BME280OverSample.X1, BME280OverSample.X1, BME280OverSample.X1, BME280Filter.Off); while (true) { driver.Read(); Debug.WriteLine("Pressure: " + driver.Pressure); Debug.WriteLine("Humidity: " + driver.Humidity); Debug.WriteLine("Temperature:" + driver.Temperature); Thread.Sleep(1000); } }
public ArducamMini(string spiBus, int chipSelectPin, string i2cBus, byte address = 0x30) { //i2cDevice = new I2cPeripheral(i2cBus, address); var settings = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); i2cDevice = controller.GetDevice(settings); //chipSelectPort = device.CreateDigitalOutputPort(chipSelectPin); var gpio = GpioController.GetDefault(); chipSelectPort = gpio.OpenPin(chipSelectPin); chipSelectPort.SetDriveMode(GpioPinDriveMode.Output); chipSelectPort.Write(GpioPinValue.Low); var settingsSpi = new SpiConnectionSettings() { ChipSelectType = SpiChipSelectType.Gpio, ChipSelectLine = chipSelectPort, Mode = SpiMode.Mode1, ClockFrequency = 4_000_000, }; var Spicontroller = SpiController.FromName(spiBus); spiDevice = Spicontroller.GetDevice(settingsSpi); //spiDevice = new SpiPeripheral(spiBus, chipSelectPort); Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="JoystickClick"/> class. /// </summary> /// <param name="socket">The socket on which the JoystickClick module is plugged on MikroBus.Net board</param> /// <param name="address">The address of the module.</param> public JoystickClick(Hardware.Socket socket, Byte address = 0x40) { // Create the driver's I²C configuration _joystick = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000)); WriteRegister(Registers.CONTROL1, 0b11110000); _reset = GpioController.GetDefault().OpenPin(socket.PwmPin); _reset.SetDriveMode(GpioPinDriveMode.Output); Reset(ResetModes.Hard); Sensitivity = 0x3F; // Max sensitivity Scaling = 0x09; // 100% scaling Button = GpioController.GetDefault().OpenPin(socket.Cs); Button.SetDriveMode(GpioPinDriveMode.Input); PowerMode = PowerModes.On; // Interrupt mode InterruptLine = GpioController.GetDefault().OpenPin(socket.Int); InterruptLine.SetDriveMode(GpioPinDriveMode.InputPullUp); TimeBase = 3; ReadRegister(0x11); // Don't care about the first data available }
static void InitBot() { var chip = new GHIElectronics.TinyCLR.Drivers.Nxp.PCA9685.PCA9685Controller( I2cController.FromName(FEZBit.I2cBus.Edge)); var gpioController = GpioController.GetDefault(); var buzzerController = PwmController.FromName(FEZBit.PwmChannel.Controller3.Id); var buzzerChannel = buzzerController.OpenChannel(FEZBit.PwmChannel.Controller3.EdgeP0Channel); var frontsensorenable = gpioController.OpenPin(FEZBit.GpioPin.EdgeP9); var frontsensorvaluecontroller = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id); var frontvalue = frontsensorvaluecontroller.OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP3); var lineDetectLeft = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id).OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP2); var lineDetectRight = AdcController.FromName(FEZBit.AdcChannel.Controller1.Id).OpenChannel(FEZBit.AdcChannel.Controller1.EdgeP1); var p2remove = GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP1); p2remove.SetDriveMode(GpioPinDriveMode.Input); bot = new BitBotController( chip, buzzerChannel, lineDetectLeft, lineDetectRight, gpioController.OpenPin(FEZBit.GpioPin.EdgeP14), gpioController.OpenPin(FEZBit.GpioPin.EdgeP15), frontsensorenable, frontvalue, gpioController.OpenPin(FEZBit.GpioPin.EdgeP16)); bot.SetHeadlight(200, 50, 0); bot.SetStatusLeds(false, true, false); bot.SetColorLeds(0, 0xff, 0, 0); bot.SetColorLeds(1, 0, 0xff, 0); bot.SetColorLeds(2, 0, 0, 0xff); bot.Beep(); }
/// <summary> /// Initializes a new instance of the <see cref="CapSenseClick"/> class. /// </summary> /// <param name="socket">The socket on which the CapSense Click board is plugged on MikroBus.Net</param> /// <param name="address">Address of the I²C device.</param> public CapSenseClick(Hardware.Socket socket, Byte address = 0x00) { _socket = socket; // Create the driver's I²C configuration _cap = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000)); Init(); }
static void DisplayConfigWPF() { var backlight = GpioController.GetDefault().OpenPin(BACKLIGHT); backlight.SetDriveMode(GpioPinDriveMode.Output); backlight.Write(GpioPinValue.High); var displayController = GHIElectronics.TinyCLR.Devices.Display.DisplayController.GetDefault(); var controllerSetting = new GHIElectronics.TinyCLR.Devices.Display.ParallelDisplayControllerSettings { // 480x272 Width = SCREEN_WIDTH, Height = SCREEN_HEIGHT, DataFormat = GHIElectronics.TinyCLR.Devices.Display.DisplayDataFormat.Rgb565, PixelClockRate = 10000000, PixelPolarity = false, DataEnablePolarity = false, DataEnableIsFixed = false, HorizontalFrontPorch = 2, HorizontalBackPorch = 2, HorizontalSyncPulseWidth = 41, HorizontalSyncPolarity = false, VerticalFrontPorch = 2, VerticalBackPorch = 2, VerticalSyncPulseWidth = 10, VerticalSyncPolarity = false, }; displayController.SetConfiguration(controllerSetting); displayController.Enable(); var i2cController = I2cController.FromName(SC20260.I2cBus.I2c1); var settings = new I2cConnectionSettings(0x38) // the slave's address { BusSpeed = 100000, AddressFormat = I2cAddressFormat.SevenBit, }; var i2cDevice = i2cController.GetDevice(settings); var interrupt = GpioController.GetDefault().OpenPin(TOUCH_IRQ); touch = new FT5xx6Controller(i2cDevice, interrupt); touch.TouchDown += Touch_TouchDown; touch.TouchUp += Touch_TouchUp; // Create WPF window app = new Program(displayController); SelectPage = new SelectPage(); ConnectPage = new ConnectPage(""); SplashPage = new SplashPage(); WpfWindow = Program.CreateWindow(displayController); WpfWindow.Child = SplashPage.Elements; WpfWindow.Visibility = Visibility.Visible; app.Run(WpfWindow); }
/// <summary> /// Initializes a new instance of the <see cref="Pressure4Click" /> class using the I2C interface. /// </summary> /// <param name="socket">The virtual socket on which the Pressure4Click module is connected to on the MikroBus.Net board</param> /// <param name="slaveAddress">The I2C Slave Address <see cref="I2CAddress"/> to use.</param> public Pressure4Click(Hardware.Socket socket, I2CAddress slaveAddress) { _interface = Interface.I2C; _sensorI2C = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings((Int32)slaveAddress, 400000)); Initialize(); }
public I2cMcpDeviceComms(string bus, byte peripheralAddress) { var settings = new I2cConnectionSettings(peripheralAddress, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(bus); device = controller.GetDevice(settings); }
public Ds1307(string i2cBus) { var settings = new I2cConnectionSettings(Address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); _bus = controller.GetDevice(settings); //_bus = bus; }
/// <summary> /// Initializes a new instance of the <see cref="HTU21DClick"/> class. /// </summary> /// <param name="socket">The socket on which the HTU21DClick module is plugged on MikroBus.Net board</param> public HTU21DClick(Hardware.Socket socket) { _socket = socket; _htu = I2cController.FromName(socket.I2cBus) .GetDevice(new I2cConnectionSettings(HTDU21D_WRITE_ADDRESS, 400000)); Reset(ResetModes.Soft); }
/// <summary> /// Create a new GroveTH02 object using the default parameters for the component. /// </summary> /// <param name="address">Address of the Grove TH02 (default = 0x4-).</param> /// <param name="i2cBus">I2C bus (default = 100 KHz).</param> public GroveTh02(string i2cBus, byte address = 0x40) { var settings = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); groveTH02 = controller.GetDevice(settings); //groveTH02 = new I2cPeripheral(i2cBus, address); }
/// <summary> /// Create a new HIH6130 object using the default parameters for the component. /// </summary> /// <param name="address">Address of the HIH6130 (default = 0x27).</param> /// <param name="i2cBus">I2C bus (default = 100 KHz).</param> public Hih6130(string i2cBus, byte address = 0x27) { var settings = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); hih6130 = controller.GetDevice(settings); //hih6130 = new I2cPeripheral(i2cBus, address); }
public Ags01Db(string i2cBus, byte address = 0x11) { var settings = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); sensor = controller.GetDevice(settings); //sensor = new I2cPeripheral(i2cBus, address); }
/// <summary> /// Create a new SHT31D object. /// </summary> /// <param name="address">Sensor address (should be 0x44 or 0x45).</param> /// <param name="i2cBus">I2cBus (0-1000 KHz).</param> public Sht31D(string i2cBus, byte address = 0x44) { var settings = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); sht31d = controller.GetDevice(settings); //sht31d = new I2cPeripheral(i2cBus, address); }
/// <summary> /// A TinyCLR driver for the MikroE TempHum 8 Click. /// </summary> /// <param name="socket"> /// The socket that TempHum 8 Click is plugged into. /// </param> public TempHum8Click(Hardware.Socket socket) { _socket = socket; _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(0x40, 100000)); Reset(); Resolution = SensorResolution.Resolution_12RH_14T; }
public Is31fl3731(string i2cBus, byte address) { var settings = new I2cConnectionSettings(address, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); i2cPeripheral = controller.GetDevice(settings); Frame = 0; }
/// <summary> /// Initializes a new instance of the <see cref="PressureClick"/> class. /// </summary> /// <param name="socket">The socket on which the Pressure Click board is plugged on MikroBus.Net</param> /// <param name="address">Address of the I²C device.</param> /// <exception cref="DeviceInitialisationException">Thrown if device failed to initialize.</exception> public PressureClick(Hardware.Socket socket, Byte address = 0xBA >> 1) { // Create the driver's I²C configuration _pres = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000)); if (!Init()) { throw new DeviceInitialisationException("Device failed to initialize"); } }
/// <summary> /// Initializes a new instance of the TempHum 7 Click class /// </summary> /// <param name="socket"> /// The socket that TempHum 7 Click is plugged into. /// </param> public TempHum7Click(Hardware.Socket socket) { _socket = socket; _sensor = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(0x40, 400000)); Thread.Sleep(50); // Time from VDD >= 1.64V until ready for a full conversion. HumidityMeasurementMode = MeasurementMode.NoHold; }
/// <summary> /// Constructor of Rtc component /// </summary> /// <param name="i2C">String that represent i2c bus</param> public Rtc(string i2C) { var settings = new I2cConnectionSettings(0x68) { BusSpeed = I2cBusSpeed.FastMode }; _rtcDevice = I2cController.FromName(i2C).GetDevice(settings); }
/// <summary> /// Initializes a new instance of the <see cref="T:Meadow.TinyCLR.Sensors.Barometric.BME280" /> class. /// </summary> /// <param name="i2c">I2C Bus to use for communicating with the sensor</param> /// <param name="busAddress">I2C address of the sensor (default = 0x77).</param> public Bme280(string i2cBus, I2cAddress busAddress = I2cAddress.Adddress0x77) { var settings = new I2cConnectionSettings((byte)busAddress, 100_000); //The slave's address and the bus speed. var controller = I2cController.FromName(i2cBus); var i2c = controller.GetDevice(settings); _bme280 = new Bme280I2C(i2c, (byte)busAddress); Init(); }
/// <summary> /// Initializes a new instance of the <see cref="EEpromClick"/> class. /// </summary> /// <param name="socket">The socket on which the EEpromClick module is plugged on MikroBus.Net board</param> /// <param name="address">The address of the module.</param> /// <param name="memorySize">Optionnal size of the memory chip, in KB. Default to 8KB, as sold by MikroElektronika.</param> public EEpromClick(Hardware.Socket socket, Byte address, Int32 memorySize = 8) { // Create the driver's I²C configuration _eeprom = I2cController.FromName(socket.I2cBus).GetDevice(new I2cConnectionSettings(address, 100000)); _memorysize = memorySize * 1024; gpio.GpioPin _wp = gpio.GpioController.GetDefault().OpenPin(socket.PwmPin); _wp.SetDriveMode(gpio.GpioPinDriveMode.Output); _wp.Write(gpio.GpioPinValue.Low); }