static void Main() { Console.WriteLine("DS1307 I2C Test"); Console.WriteLine("==============="); Console.WriteLine("Opening Connection..."); try { _driver = new I2cDriver(ProcessorPin.Gpio02, ProcessorPin.Gpio03); _i2CConnection = _driver.Connect(0x68); _clock = new Ds1307_I2C(_i2CConnection); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to open connection."); Console.WriteLine(ex); Console.WriteLine("Press any key to close."); Console.Read(); Environment.Exit(1); } Console.WriteLine("Connection open!"); AskForKey(); }
/// <summary> /// Initializes a new instance of the <see cref="Ssd1306Connection"/> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="displayWidth">The display displayWidth.</param> /// <param name="displayHeight">The display displayHeight.</param> public Ssd1306Connection(I2cDeviceConnection connection, int displayWidth = 128, int displayHeight = 64) { this.connection = connection; this.displayWidth = displayWidth; this.displayHeight = displayHeight; Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Pca9685Connection"/> class. /// </summary> /// <param name="connection">The I2C connection.</param> public Pca9685Connection(I2cDeviceConnection connection) { this.connection = connection; log.Info(m => m("Resetting PCA9685")); WriteRegister(Register.MODE1, 0x00); }
internal GoPiGo() { this.Driver = new I2cDriver(ProcessorPin.Pin2, ProcessorPin.Pin3); this.I2CController = Driver.Connect(GoPiGoAddress); _motorController = new MotorController(this); _encoderController = new EncoderController(this); }
/// <summary> /// Constructor /// </summary> /// <param name="driver">The I2cDriver instance</param> /// <param name="deviceAddress">The device address on the i2c bus (usually 0x77)</param> /// <param name="mode">The sensor resolution mode</param> public BMP180PressureTempSensor(I2cDriver driver, int deviceAddress, BMP085Mode mode = BMP085Mode.UltraLowPower) { _device = driver.Connect(deviceAddress); _mode = mode; TestConnection(); LoadCalibration(); }
static void Main(string[] args) { Console.WriteLine("LTC2943 Test"); Console.WriteLine("==========="); Console.WriteLine("Opening Connection..."); try { driver = new I2cDriver(ProcessorPin.Gpio02, ProcessorPin.Gpio03); i2cConnection = driver.Connect(0x64); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Unable to open connection."); Console.WriteLine(ex); Console.WriteLine("Press any key to close."); Console.Read(); Environment.Exit(1); } Console.WriteLine("Connection open!"); AskForKey(); }
public void Dispose() { if (!_cancellationTokenSource.IsCancellationRequested) { Stop(); } _deviceConnection = null; _constants = null; }
public void Dispose() { if (_doWork) { Stop(); } _deviceConnection = null; _constants = null; }
/// <summary> /// Initializes a new instance of the <see cref="Pca9685Connection"/> class. /// </summary> /// <param name="serviceProvider">IServiceProvider</param> /// <param name="connection">The I2C connection.</param> public Pca9685Connection(IServiceProvider serviceProvider, I2cDeviceConnection connection) { this.connection = connection; log = serviceProvider.GetRequiredService <ILogger <Pca9685Connection> >(); log.LogInformation("Resetting PCA9685"); WriteRegister(Register.MODE1, 0x00); }
/// <summary> /// Initializes a new instance of the <see cref="Pca9685Device" /> class. /// </summary> /// <param name="connection">The I2C connection.</param> /// <param name="threadFactory">The thread factory.</param> /// <param name="pca9685DeviceReporter">The pca9685 device reporter.</param> public Pca9685Device(I2cDeviceConnection connection, IThreadFactory threadFactory = null, IPca9685DeviceReporter pca9685DeviceReporter = null) { this.connection = connection; this.pca9685DeviceReporter = pca9685DeviceReporter; this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); this.pca9685DeviceReporter?.Resetting(); this.WriteRegister(Register.Mode1, 0x00); }
public void Action(ActionBase baseAction, CancellationToken cancelToken, dynamic config) { TMP102SimpleAction action = (TMP102SimpleAction)baseAction; // note that config is dynamic so we cast the pin values to integer _state = new { state = "setup" }; _state = new { state = "preDelay" }; if (cancelToken.WaitHandle.WaitOne(action.PreDelayMs)) { return; } DateTime startTime = DateTime.Now; int i2cAddress = config.i2cAddress; ProcessorPin sda = config.i2cSdaBcmPin; ProcessorPin scl = config.i2cSclBcmPin; using (var driver = new I2cDriver(sda, scl)) { I2cDeviceConnection connection = driver.Connect(i2cAddress); while (true) { if (cancelToken.IsCancellationRequested) { break; } // read temperature and set state (json) _state = ReadTemperature(connection); // don't change state here since we want to keep the last temp reading in our state if (cancelToken.WaitHandle.WaitOne(action.ReadDelayMs)) { break; } // time to quit? if (action.DurationMs > 0) { TimeSpan duration = DateTime.Now - startTime; if (duration.TotalMilliseconds > action.DurationMs) { break; } } } } _state = new { state = "postDelay" }; if (cancelToken.WaitHandle.WaitOne(action.PostDelayMs)) { return; } }
/// <summary> /// Initializes a new instance of the <see cref="Pca9685Connection"/> class. /// </summary> /// <param name="connection">The I2C connection.</param> public Pca9685Connection(I2cDeviceConnection connection) { this.connection = connection; ILoggerFactory loggerFactory = new LoggerFactory().AddConsole().AddDebug(); log = loggerFactory.CreateLogger <Pca9685Connection>(); log.LogInformation("Resetting PCA9685"); WriteRegister(Register.MODE1, 0x00); }
/// <summary> /// Initializes a new instance of the <see cref="Motor_Hat"/> class. /// </summary> /// <param name="addr">I2C address default is 0x60</param> /// <param name="freq">Frequency</param> public Motor_Hat(I2cDriver driver, int addr = 0x60, int freq = 1600) { for (int i = 0; i < 4; i++) { motors.Add(new DC_Motor(this, i)); // Creates 4 DC Motors and adds them to the list } steppers.Add(new Stepper_Motor(this, 1)); // Creates Stepper Motor 1 steppers.Add(new Stepper_Motor(this, 2)); // Creates Stepper Motor 2 connection = driver.Connect(addr); _pwm = new Pca9685Connection(connection); // Connects to the Motor Hat _pwm.SetPwmUpdateRate(freq); // Sets the frequency }
} //Max 16 rows, 8 bits (leds) /// <summary> /// Initializes a new instance of the /// <see cref="Pi.IO.Components.Controllers.HT16K33.HT16K33Connection"/> class. /// </summary> /// <param name="connection">I2c connection.</param> /// <param name="RowCount">Rows in use (1 to 16) </param> public HT16K33Connection(I2cDeviceConnection connection, int RowCount) { LEDBuffer = new byte[RowCount]; this.connection = connection; log.Info(m => m("Resetting HT16K33")); connection.Write((byte)Command.System_Setup | (byte)HT16K33_Oscillator); //Turn on the oscillator. connection.Write((byte)Command.Flash | (byte)HT16K33_DisplayOn | (byte)Flash.Off); connection.Write((byte)Command.DimmingSet | (byte)15); // connection.Write(SetupSequence); }
/// <summary> /// Reads sleep date from board. /// </summary> /// <param name="conn"></param> /// <returns></returns> public static SleepDateTime ReadSleepDate(I2cDeviceConnection conn) { conn.WriteByte(0x0B); var bytes = conn.Read(3); var piDate = new SleepDateTime ( min: GetByte(bytes[0]).Value, hour: GetByte(bytes[1]).Value, day: GetByte(bytes[2]).Value ); return(piDate); }
/// <summary> /// Reads wake up date from board. /// </summary> /// <param name="conn"></param> /// <returns></returns> public static WakeUpDateTime ReadWakeUpDate(I2cDeviceConnection conn) { conn.WriteByte(0x07); var bytes = conn.Read(4); var piDate = new WakeUpDateTime ( GetByte(bytes[3]), GetByte(bytes[2]), GetByte(bytes[1]), GetByte(bytes[0]).Value ); return(piDate); }
/// <summary> /// Initializes a new instance of the /// <see cref="Ht16K33Device" /> class. /// </summary> /// <param name="connection">I2c connection.</param> /// <param name="rowCount">Rows in use (1 to 16).</param> /// <param name="ht16K33DeviceReporter">The HT16 K33 device reporter.</param> public Ht16K33Device(I2cDeviceConnection connection, int rowCount, IHt16K33DeviceReporter ht16K33DeviceReporter = null) { this.LedBuffer = new byte[rowCount]; this.connection = connection; this.ht16K33DeviceReporter = ht16K33DeviceReporter; this.ht16K33DeviceReporter?.Resetting(); connection.Write((byte)Command.SystemSetup | (byte)Ht16K33Oscillator); //// Turn on the oscillator. connection.Write((byte)Command.Flash | (byte)Ht16K33DisplayOn | (byte)Flash.Off); connection.Write((byte)Command.DimmingSet | (byte)15); //// connection.Write(SetupSequence); }
} //Max 16 rows, 8 bits (leds) /// <summary> /// Initializes a new instance of the /// <see cref="Raspberry.IO.Components.Controllers.HT16K33.HT16K33Connection"/> class. /// </summary> /// <param name="serviceProvider">IServiceProvider</param> /// <param name="connection">I2c connection.</param> /// <param name="RowCount">Rows in use (1 to 16) </param> public HT16K33Connection(IServiceProvider serviceProvider, I2cDeviceConnection connection, int RowCount) { LEDBuffer = new byte[RowCount]; this.connection = connection; log = serviceProvider.GetRequiredService <ILogger <HT16K33Connection> >(); log.LogInformation("Resetting HT16K33"); connection.Write((byte)Command.System_Setup | (byte)HT16K33_Oscillator); //Turn on the oscillator. connection.Write((byte)Command.Flash | (byte)HT16K33_DisplayOn | (byte)Flash.Off); connection.Write((byte)Command.DimmingSet | (byte)15); // connection.Write(SetupSequence); }
public PHComponent(Settings.PHEZOItem item) : this() { mode = 1; ID = item.ID; phdownHeaderPinNumber = item.phDownPin; phupHeaderPinNumber = item.phUpPin; try { GpioPin p1 = Pi.Gpio.Pins.FirstOrDefault(i => i.HeaderPinNumber == phupHeaderPinNumber); if (p1 != null) { p1.PinMode = GpioPinDriveMode.Output; } GpioPin p2 = Pi.Gpio.Pins.FirstOrDefault(i => i.HeaderPinNumber == phdownHeaderPinNumber); if (p2 != null) { p2.PinMode = GpioPinDriveMode.Output; } } catch { } if (item.autoPHOn) { EnableAutoOn(); } else { DisableAutoOn(); } try { driver = new I2cDriver(ProcessorPin.Gpio02, ProcessorPin.Gpio03);//standard ports on raspi i2cConnection = driver.Connect(item.I2cAddress); } catch { } }
internal virtual bool InitSensor() { try { if (_deviceConnection == null) { _deviceConnection = I2CConnectorDriver.Driver.Connect(_deviceId); } return(_deviceConnection != null); } catch (Exception e) { CommonHelper.Logger.Error(e, string.Format("Error during Init I2C {0}:{1}", _deviceId, e.Message)); } return(false); }
} //Max 16 rows, 8 bits (leds) /// <summary> /// Initializes a new instance of the /// <see cref="Raspberry.IO.Components.Controllers.HT16K33.HT16K33Connection"/> class. /// </summary> /// <param name="connection">I2c connection.</param> /// <param name="RowCount">Rows in use (1 to 16) </param> public HT16K33Connection(I2cDeviceConnection connection, int RowCount) { LEDBuffer = new byte[RowCount]; this.connection = connection; ILoggerFactory loggerFactory = new LoggerFactory() .AddConsole() .AddDebug(); log = loggerFactory.CreateLogger <HT16K33Connection>(); log.LogInformation("Resetting HT16K33"); connection.Write((byte)Command.System_Setup | (byte)HT16K33_Oscillator); //Turn on the oscillator. connection.Write((byte)Command.Flash | (byte)HT16K33_DisplayOn | (byte)Flash.Off); connection.Write((byte)Command.DimmingSet | (byte)15); // connection.Write(SetupSequence); }
/// <summary> /// Initializes a new instance of the <see cref="Max9744Device" /> class. /// </summary> /// <param name="i2cAddress">The i2c address.</param> /// <param name="mutePin">The mute pin.</param> /// <param name="shutdownPin">The shutdown pin.</param> /// <param name="sdaPin">The sda pin.</param> /// <param name="sclPin">The SCL pin.</param> /// <param name="gpioConnectionDriverFactory">The gpio connection driver factory.</param> /// <param name="i2CDeviceConnectionReporter">The i2 c device connection reporter.</param> public Max9744Device( byte i2cAddress, ConnectorPin mutePin, ConnectorPin shutdownPin, ProcessorPin sdaPin, ProcessorPin sclPin, IGpioConnectionDriverFactory? gpioConnectionDriverFactory, II2cDeviceConnectionReporter? i2CDeviceConnectionReporter = null) { this.gpioConnectionDriverFactory = GpioConnectionDriverFactory.EnsureGpioConnectionDriverFactory(gpioConnectionDriverFactory); this.gpioConnectionDriver = this.gpioConnectionDriverFactory.Get(); // connect volume via i2c this.i2CDriver = new I2cDriver(sdaPin, sclPin); this.connection = this.i2CDriver.Connect(i2cAddress, i2CDeviceConnectionReporter); // connect shutdown via gpio this.mutePin = mutePin.Output().Revert(); this.shutdownPin = shutdownPin.Output().Revert(); this.gpioConnection = new GpioConnection(this.gpioConnectionDriverFactory, this.shutdownPin, this.mutePin); }
private void Run(string[] args) { // // see the end of this file more information on reading the TMP102 // Console.WriteLine("Press any key to exit...\n"); int seconds = 3; Console.WriteLine("TMP102 (Model: SEN-11931): Measure temperature"); Console.WriteLine($"Measure: I2C every {seconds} second(s)"); int i2cAddress = 0x48; using (var driver = new I2cDriver(ProcessorPin.Pin2, ProcessorPin.Pin3)) { I2cDeviceConnection connection = driver.Connect(i2cAddress); while (!Console.KeyAvailable) { byte[] data = connection.Read(2); // the msb is the first byte on linux byte msb = data[0]; // the lsb is the second byte on linux byte lsb = data[1]; // now combine then back together with msb first int temperature = ((msb << 8) | lsb) >> 4; Console.WriteLine( "Temperature is {0}°C, {1}°F", temperature * .0625, (temperature * .0625 * 1.8) + 32); System.Threading.Thread.Sleep(seconds * 1000); } } }
private object ReadTemperature(I2cDeviceConnection connection) { byte[] data = connection.Read(2); // the msb is the first byte on linux byte msb = data[0]; // the lsb is the second byte on linux byte lsb = data[1]; // now combine then back together with msb first int temperature = ((msb << 8) | lsb) >> 4; object temps = new { date = DateTime.UtcNow.ToString("o"), temperatureF = (temperature * .0625 * 1.8) + 32, temperatureC = temperature * .0625, }; return(temps); }
public static void Main(string[] args) { using (var i2cDriver = new I2cDriver(ProcessorPin.Pin2, ProcessorPin.Pin3)) { I2cDeviceConnection i2c = i2cDriver.Connect(0x70); var bargraph = new BiColor24Bargraph(i2c); bargraph.Clear(); while (true) { foreach (BiColor24Bargraph.LEDState state in Enum.GetValues(typeof(BiColor24Bargraph.LEDState))) { for (int i = 0; i < 24; i++) { bargraph.SetLed((uint)i, state); Thread.Sleep(50); } } } } }
//Method to initialize the BME280 sensor public void Initialize() { Debug.WriteLine("BME280::Initialize"); try { var driver = new I2cDriver(ProcessorPin.Pin02, ProcessorPin.Pin03); bme280 = driver.Connect(BME280_Address); //Check if device was found if (bme280 == null) { Debug.WriteLine("Device not found"); } else { try { //Make sure the I2C device is initialized if (!init) { Begin(); } } catch (Exception e) { init = false; Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace); } } } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message + "\n" + e.StackTrace); throw; } }
/// <summary> /// Creates a new instance of the class using the provided I2C Connection. /// </summary> /// <param name="connection">I2C Connection to the Clock.</param> public Ds1307Connection(I2cDeviceConnection connection) { Connection = connection; }
/// <summary> /// Initializes a new instance of the <see cref="Bmp085Device" /> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="thread">The thread.</param> public Bmp085Device(I2cDeviceConnection connection, ICurrentThread thread) { this.connection = connection; this.thread = thread; this.Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="Mcp23017I2cConnection"/> class. /// </summary> /// <param name="connection">The connection.</param> public Mcp23017I2cConnection(I2cDeviceConnection connection) { this.connection = connection; }
public BH1750Connection(I2cDeviceConnection connection) { Connection = connection; }