static void Main(string[] args) { Console.WriteLine("Hello VL53L0X!"); Vl53L0X vL53L0X = new Vl53L0X(I2cDevice.Create(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); Console.WriteLine($"Rev: {vL53L0X.Information.Revision}, Prod: {vL53L0X.Information.ProductId}, Mod: {vL53L0X.Information.ModuleId}"); Console.WriteLine($"Offset in µm: {vL53L0X.Information.OffsetMicrometers}, Signal rate fixed 400 µm: {vL53L0X.Information.SignalRateMeasuementFixed400Micrometers}"); vL53L0X.MeasurementMode = MeasurementMode.Continuous; while (!Console.KeyAvailable) { try { var dist = vL53L0X.Distance; if (dist != (ushort)OperationRange.OutOfRange) { Console.WriteLine($"Distance: {dist}"); } else { Console.WriteLine("Invalid data"); } } catch (Exception ex) { Console.WriteLine($"Exception: {ex.Message}"); } Thread.Sleep(500); } }
public Result <Unit> Init() { _controller = new GpioController(PinNumberingScheme.Logical, new RaspberryPi3Driver()); _controller.OpenPin(Pin.HallBottom, PinMode.InputPullUp); _controller.OpenPin(Pin.HallTop, PinMode.InputPullUp); _controller.OpenPin(Pin.PhotoelectricBarrier, PinMode.InputPullUp); _controller.OpenPin(Pin.MotorEnable, PinMode.Output); _controller.OpenPin(Pin.MotorLeft, PinMode.Output); _controller.OpenPin(Pin.MotorRight, PinMode.Output); _controller.OpenPin(Pin.EmergencyTop, PinMode.InputPullUp); _controller.OpenPin(Pin.DC12_1, PinMode.Output); _controller.OpenPin(Pin.DC12_2, PinMode.Output); //_pwmMotor = new SoftwarePwmChannel(Pin.MotorEnable, 200, 0.1); //_pwmMotor.Start(); _controller.Write(Pin.MotorEnable, PinValue.High); _controller.Write(Pin.MotorLeft, PinValue.Low); _controller.Write(Pin.MotorRight, PinValue.Low); _controller.Write(Pin.DC12_1, PinValue.Low); _controller.Write(Pin.DC12_2, PinValue.Low); Console.WriteLine($"Init sensor"); _bh1750Fvi = new Bh1750fvi(I2cDevice.Create(new I2cConnectionSettings(1, Bh1750fviExtenstion.DefaultI2cAddress))); // 23 _vl53L0X = new Vl53L0X(I2cDevice.Create(new I2cConnectionSettings(1, Vl53L0X.DefaultI2cAddress))); // 29 _bme280 = new Bme280(I2cDevice.Create(new I2cConnectionSettings(1, Bmx280Base.SecondaryI2cAddress))); // 76 _measurementTime = _bme280.GetMeasurementDuration(); _bme280.SetPowerMode(Bmx280PowerMode.Normal); //Thread.Sleep(_measurementTime); //_bme280.TryReadTemperature(out var tempValue); //_bme280.TryReadPressure(out var preValue); //_bme280.TryReadHumidity(out var humValue); //_bme280.TryReadAltitude(out var altValue); //Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C"); //Console.WriteLine($"Pressure: {preValue.Hectopascals:#.##} hPa"); //Console.WriteLine($"Relative humidity: {humValue.Percent:#.##}%"); //Console.WriteLine($"Estimated altitude: {altValue.Meters:#} m"); _amg88xx = new Amg88xx(I2cDevice.Create(new I2cConnectionSettings(1, Amg88xx.AlternativeI2cAddress))); // 69 try { _mpu9250 = new Mpu9250(I2cDevice.Create(new I2cConnectionSettings(1, Mpu6500.DefaultI2cAddress))); // 68 } catch (IOException e) { Console.WriteLine("AK8963 is exposed, try to connect directly."); _mpu9250 = new Mpu9250(I2cDevice.Create(new I2cConnectionSettings(1, Mpu6500.DefaultI2cAddress)), i2CDeviceAk8963: I2cDevice.Create(new I2cConnectionSettings(1, Ak8963.DefaultI2cAddress))); } _mpu9250.MagnetometerMeasurementMode = MeasurementMode.ContinuousMeasurement100Hz; Thread.Sleep(100); Console.WriteLine($"Finished Init sensor"); Run(); Thread.Sleep(100); Calibrate(); return(Unit.Instance); }