diff --git a/src/devices/AD5328/README.md b/src/devices/AD5328/README.md index dbb7c759a5..11a5b91c5c 100755 --- a/src/devices/AD5328/README.md +++ b/src/devices/AD5328/README.md @@ -2,6 +2,10 @@ AD5328 is an Digital-to-Analog converter (DAC) with 12 bits of resolution. +## Documentation + +Product information and documentation can he found [here](https://www.analog.com/en/products/ad5328.html) + ## Usage ```csharp @@ -20,8 +24,3 @@ var dac = new AD5328(spidev, ElectricPotential.FromVolts(2.5), ElectricPotential Thread.Sleep(1000); dac.SetVoltage(0, ElectricPotential.FromVolts(1)); ``` - -## References - -https://www.analog.com/en/products/ad5328.html - diff --git a/src/devices/Ads1115/samples/ADS1115_circuit.fzz b/src/devices/Ads1115/ADS1115_circuit.fzz similarity index 100% rename from src/devices/Ads1115/samples/ADS1115_circuit.fzz rename to src/devices/Ads1115/ADS1115_circuit.fzz diff --git a/src/devices/Ads1115/samples/ADS1115_circuit_bb.png b/src/devices/Ads1115/ADS1115_circuit_bb.png similarity index 100% rename from src/devices/Ads1115/samples/ADS1115_circuit_bb.png rename to src/devices/Ads1115/ADS1115_circuit_bb.png diff --git a/src/devices/Ads1115/samples/InterruptResult.png b/src/devices/Ads1115/InterruptResult.png similarity index 100% rename from src/devices/Ads1115/samples/InterruptResult.png rename to src/devices/Ads1115/InterruptResult.png diff --git a/src/devices/Ads1115/README.md b/src/devices/Ads1115/README.md index d41efbddd9..68515479c5 100644 --- a/src/devices/Ads1115/README.md +++ b/src/devices/Ads1115/README.md @@ -1,10 +1,17 @@ # ADS1115 - Analog to Digital Converter + ADS1115 is an Analog-to-Digital converter (ADC) with 16 bits of resolution. +## Documentation + +Prodcut datasheet can be found [here](https://cdn-shop.adafruit.com/datasheets/ads1115.pdf) + ## Sensor Image -![](sensor.jpg) + +![ADS1115](sensor.jpg) ## Usage + ```C# // set I2C bus ID: 1 // ADS1115 Addr Pin connect to GND @@ -23,11 +30,69 @@ using (Ads1115 adc = new Ads1115(device, InputMultiplexer.AIN0, MeasuringRange.F } ``` -See the samples project for more examples and usage for different applications. +See the [samples project](https://github.com/dotnet/iot/tree/main/src/devices/Ads1115/samples) for more examples and usage for different applications. If you want to use the interrupt pin, the pulses generated by the ADS1115 might be to short to be properly recognized in the software, i.e. on a Raspberry Pi. The schematic below shows a way of increasing the pulse length so that it is properly recognized (from about 10us to 150us). This uses discrete electronics, but an implementation with an NE555 or equivalent would likely work as well (Just note that you need a type that works at 3.3V). -![](Pulse_lengthener_schema.png) +![Pulse_lengthener_schema](Pulse_lengthener_schema.png) + +## Example + +### Hardware Required + +* ADS1115 +* Rotary Potentiometer +* Male/Female Jumper Wires + +### Circuit + +![circuit](ADS1115_circuit_bb.png) + +ADS1115 +* ADDR - GND +* SCL - SCL +* SDA - SDA +* VCC - 5V +* GND - GND +* A0 - Rotary Potentiometer Pin 2 + +Rotary Potentiometer +* Pin 1 - 5V +* Pin 2 - ADS1115 Pin A0 +* Pin 3 - GND + +### Code + +```C# +// set I2C bus ID: 1 +// ADS1115 Addr Pin connect to GND +I2cConnectionSettings settings = new I2cConnectionSettings(1, (int)I2cAddress.GND); +I2cDevice device = I2cDevice.Create(settings); + +// pass in I2cDevice +// measure the voltage AIN0 +// set the maximum range to 6.144V +using (Ads1115 adc = new Ads1115(device, InputMultiplexer.AIN0, MeasuringRange.FS6144)) +{ + // loop + while (true) + { + // read raw data form the sensor + short raw = adc.ReadRaw(); + // raw data convert to voltage + double voltage = adc.RawToVoltage(raw); + + Console.WriteLine($"ADS1115 Raw Data: {raw}"); + Console.WriteLine($"Voltage: {voltage}"); + Console.WriteLine(); + + // wait for 2s + Thread.Sleep(2000); + } +} +``` + +### Results -## References -https://cdn-shop.adafruit.com/datasheets/ads1115.pdf +![run results](RunningResult.jpg) +![interupt result](InterruptResult.png) \ No newline at end of file diff --git a/src/devices/Ads1115/samples/RunningResult.jpg b/src/devices/Ads1115/RunningResult.jpg similarity index 100% rename from src/devices/Ads1115/samples/RunningResult.jpg rename to src/devices/Ads1115/RunningResult.jpg diff --git a/src/devices/Ads1115/samples/README.md b/src/devices/Ads1115/samples/README.md deleted file mode 100644 index 6732bc138d..0000000000 --- a/src/devices/Ads1115/samples/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# ADS1115 - Samples - -## Hardware Required -* ADS1115 -* Rotary Potentiometer -* Male/Female Jumper Wires - -## Circuit -![](ADS1115_circuit_bb.png) - -ADS1115 -* ADDR - GND -* SCL - SCL -* SDA - SDA -* VCC - 5V -* GND - GND -* A0 - Rotary Potentiometer Pin 2 - -Rotary Potentiometer -* Pin 1 - 5V -* Pin 2 - ADS1115 Pin A0 -* Pin 3 - GND - -## Code -```C# -// set I2C bus ID: 1 -// ADS1115 Addr Pin connect to GND -I2cConnectionSettings settings = new I2cConnectionSettings(1, (int)I2cAddress.GND); -I2cDevice device = I2cDevice.Create(settings); - -// pass in I2cDevice -// measure the voltage AIN0 -// set the maximum range to 6.144V -using (Ads1115 adc = new Ads1115(device, InputMultiplexer.AIN0, MeasuringRange.FS6144)) -{ - // loop - while (true) - { - // read raw data form the sensor - short raw = adc.ReadRaw(); - // raw data convert to voltage - double voltage = adc.RawToVoltage(raw); - - Console.WriteLine($"ADS1115 Raw Data: {raw}"); - Console.WriteLine($"Voltage: {voltage}"); - Console.WriteLine(); - - // wait for 2s - Thread.Sleep(2000); - } -} -``` - -## Results -![](RunningResult.jpg) -![](InterruptResult.png) \ No newline at end of file diff --git a/src/devices/Adxl345/samples/ADXL345_circuit.fzz b/src/devices/Adxl345/ADXL345_circuit.fzz similarity index 100% rename from src/devices/Adxl345/samples/ADXL345_circuit.fzz rename to src/devices/Adxl345/ADXL345_circuit.fzz diff --git a/src/devices/Adxl345/samples/ADXL345_circuit_bb.png b/src/devices/Adxl345/ADXL345_circuit_bb.png similarity index 100% rename from src/devices/Adxl345/samples/ADXL345_circuit_bb.png rename to src/devices/Adxl345/ADXL345_circuit_bb.png diff --git a/src/devices/Adxl345/README.md b/src/devices/Adxl345/README.md index 2196ab1f77..cfd09878f3 100644 --- a/src/devices/Adxl345/README.md +++ b/src/devices/Adxl345/README.md @@ -1,10 +1,20 @@ # ADXL345 - Accelerometer + ADXL345 is a small, thin, low power, 3-axis accelerometer with high resolution (13-bit) measurement at up to ±16g. +## Documentation + +In [Chinese](http://wenku.baidu.com/view/87a1cf5c312b3169a451a47e.html) + +In [English](https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf) + + ## Sensor Image -![](sensor.jpg) + +![sensor](sensor.jpg) ## Usage + ```C# SpiConnectionSettings settings = new SpiConnectionSettings(0, 0) { @@ -24,7 +34,54 @@ using (Adxl345 sensor = new Adxl345(device, GravityRange.Range04)) } ``` -## References -In Chinese : http://wenku.baidu.com/view/87a1cf5c312b3169a451a47e.html +## Example + +### Hardware Required + +* ADXL345 +* Male/Female Jumper Wires + +## Circuit + +![cicuit](ADXL345_circuit_bb.png) + +* VCC - 3.3 V +* GND - GND +* CS - CS0(Pin24) +* SDO - SPI0 MISO(Pin21) +* SDA - SPI0 MOSI (Pin19) +* SCL - SPI0 SCLK(Pin23) + +### Code + +```C# +SpiConnectionSettings settings = new SpiConnectionSettings(0, 0) +{ + ClockFrequency = Adxl345.SpiClockFrequency, + Mode = Adxl345.SpiMode +}; +var device = SpiDevice.Create(settings); + +// Set gravity measurement range ±4G +using (Adxl345 sensor = new Adxl345(device, GravityRange.Range04)) +{ + // loop + while (true) + { + // read data + Vector3 data = sensor.Acceleration; + + Console.WriteLine($"X: {data.X.ToString("0.00")} g"); + Console.WriteLine($"Y: {data.Y.ToString("0.00")} g"); + Console.WriteLine($"Z: {data.Z.ToString("0.00")} g"); + Console.WriteLine(); + + // wait for 500ms + Thread.Sleep(500); + } +} +``` + +### Result -In English : https://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf +![running result](RunningResult.jpg) diff --git a/src/devices/Adxl345/samples/RunningResult.jpg b/src/devices/Adxl345/RunningResult.jpg similarity index 100% rename from src/devices/Adxl345/samples/RunningResult.jpg rename to src/devices/Adxl345/RunningResult.jpg diff --git a/src/devices/Adxl345/samples/README.md b/src/devices/Adxl345/samples/README.md deleted file mode 100644 index 649379cfff..0000000000 --- a/src/devices/Adxl345/samples/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# ADXL345 - Samples - -## Hardware Required -* ADXL345 -* Male/Female Jumper Wires - -## Circuit -![](ADXL345_circuit_bb.png) - -* VCC - 3.3 V -* GND - GND -* CS - CS0(Pin24) -* SDO - SPI0 MISO(Pin21) -* SDA - SPI0 MOSI (Pin19) -* SCL - SPI0 SCLK(Pin23) - -## Code -```C# -SpiConnectionSettings settings = new SpiConnectionSettings(0, 0) -{ - ClockFrequency = Adxl345.SpiClockFrequency, - Mode = Adxl345.SpiMode -}; -var device = SpiDevice.Create(settings); - -// Set gravity measurement range ±4G -using (Adxl345 sensor = new Adxl345(device, GravityRange.Range04)) -{ - // loop - while (true) - { - // read data - Vector3 data = sensor.Acceleration; - - Console.WriteLine($"X: {data.X.ToString("0.00")} g"); - Console.WriteLine($"Y: {data.Y.ToString("0.00")} g"); - Console.WriteLine($"Z: {data.Z.ToString("0.00")} g"); - Console.WriteLine(); - - // wait for 500ms - Thread.Sleep(500); - } -} -``` - -## Result -![](RunningResult.jpg) diff --git a/src/devices/Adxl357/README.md b/src/devices/Adxl357/README.md index e114395cd8..6ad72dc6d5 100644 --- a/src/devices/Adxl357/README.md +++ b/src/devices/Adxl357/README.md @@ -4,6 +4,10 @@ ADXL357 is a 3-Axis digital accelerometer 40g with 20-bit resolution measurement Sensitivity is configurable (±10g, ±20g, ±40g). Has a built in temperature sensor. +## Documentation + +Product documentation can be found [here](https://www.analog.com/en/products/adxl357.html) + ## Sensor Image ![Source: https://wiki.seeedstudio.com/Grove-3-Axis_Digital_Accelerometer_40g-ADXL357/](sensor.png) @@ -32,7 +36,3 @@ while (true) Thread.Sleep(500); } ``` - -## References - -https://www.analog.com/en/products/adxl357.html diff --git a/src/devices/Adxl357/samples/README.md b/src/devices/Adxl357/samples/README.md deleted file mode 100644 index eda87881e6..0000000000 --- a/src/devices/Adxl357/samples/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# ADXL357 - Samples - -## Hardware Required - -* ADXL357 - -## Code - -```csharp -I2cConnectionSettings i2CConnectionSettings = new I2cConnectionSettings(1, Adxl357.DefaultI2CAddress); -I2cDevice device = I2cDevice.Create(i2CConnectionSettings); -using Adxl357 sensor = new Adxl357(device, AccelerometerRange.Range40G); -int calibrationBufferLength = 10; -int calibrationInterval = 100; -await sensor.CalibrateAccelerationSensor(calibrationBufferLength, calibrationInterval).ConfigureAwait(false); -while (true) -{ - // read data - Vector3 data = sensor.Acceleration; - - Console.WriteLine($"X: {data.X.ToString("0.00")} g"); - Console.WriteLine($"Y: {data.Y.ToString("0.00")} g"); - Console.WriteLine($"Z: {data.Z.ToString("0.00")} g"); - Console.WriteLine(); - - // wait for 500ms - Thread.Sleep(500); -} -``` diff --git a/src/devices/Ags01db/samples/AGS01DB_circuit.fzz b/src/devices/Ags01db/AGS01DB_circuit.fzz similarity index 100% rename from src/devices/Ags01db/samples/AGS01DB_circuit.fzz rename to src/devices/Ags01db/AGS01DB_circuit.fzz diff --git a/src/devices/Ags01db/samples/AGS01DB_circuit_bb.png b/src/devices/Ags01db/AGS01DB_circuit_bb.png similarity index 100% rename from src/devices/Ags01db/samples/AGS01DB_circuit_bb.png rename to src/devices/Ags01db/AGS01DB_circuit_bb.png diff --git a/src/devices/Ags01db/README.md b/src/devices/Ags01db/README.md index 066e65b422..65eb6aa061 100644 --- a/src/devices/Ags01db/README.md +++ b/src/devices/Ags01db/README.md @@ -1,10 +1,19 @@ # AGS01DB - MEMS VOC Gas Sensor + AGS01DB is a MEMS VOC gas sensor with calibrated digital signal output. It uses special digital module acquisition technology and gas sensing technology to ensure that the product has high reliability and excellent long-term stability. +## Documentation + +Products page in [English](http://www.aosong.com/en/products-33.html) + +Datasheet in [Chinese](http://www.aosong.com/userfiles/files/media/AGS01DB%E6%B0%94%E4%BD%93%E4%BC%A0%E6%84%9F%E5%99%A8%E6%A8%A1%E5%9D%97%E8%AF%B4%E6%98%8E%E4%B9%A6V10.pdf) + ## Sensor Image -![](sensor.jpg) + +![sensor](sensor.jpg) ## Usage + ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Ags01db.DefaultI2cAddress); I2cDevice device = I2cDevice.Create(settings); @@ -20,9 +29,48 @@ using (Ags01db sensor = new Ags01db(device)) ``` -## References -Products Page in English: http://www.aosong.com/en/products-33.html +## Example + +### Hardware Required + +* AGS01DB +* 4.7kΩ resistance × 2 +* Male/Female Jumper Wires + +### Circuit + +![circuit](AGS01DB_circuit_bb.png) + +* SCL - SCL +* SDA - SDA +* VCC - 5V +* GND - GND + +SDA, SCL need pull-up resistance. + +### Code + +```Csharp +I2cConnectionSettings settings = new I2cConnectionSettings(1, Ags01db.DefaultI2cAddress); +I2cDevice device = I2cDevice.Create(settings); + +using (Ags01db sensor = new Ags01db(device)) +{ + // read AGS01DB version + Console.WriteLine($"Version: {sensor.Version}"); + Console.WriteLine(); + + while (true) + { + // read concentration + Console.WriteLine($"VOC Gas Concentration: {sensor.Concentration}ppm"); + Console.WriteLine(); + + Thread.Sleep(3000); + } +} +``` -Datasheet in English: [To be supplemented]() +### Result -Datasheet in Chinese: http://www.aosong.com/userfiles/files/media/AGS01DB%E6%B0%94%E4%BD%93%E4%BC%A0%E6%84%9F%E5%99%A8%E6%A8%A1%E5%9D%97%E8%AF%B4%E6%98%8E%E4%B9%A6V10.pdf +![running result](RunningResult.jpg) \ No newline at end of file diff --git a/src/devices/Ags01db/samples/RunningResult.jpg b/src/devices/Ags01db/RunningResult.jpg similarity index 100% rename from src/devices/Ags01db/samples/RunningResult.jpg rename to src/devices/Ags01db/RunningResult.jpg diff --git a/src/devices/Ags01db/samples/README.md b/src/devices/Ags01db/samples/README.md deleted file mode 100644 index 89f9387571..0000000000 --- a/src/devices/Ags01db/samples/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# AGS01DB - Samples - -## Hardware Required -* AGS01DB -* 4.7kΩ resistance × 2 -* Male/Female Jumper Wires - -## Circuit -![](AGS01DB_circuit_bb.png) - -* SCL - SCL -* SDA - SDA -* VCC - 5V -* GND - GND - -SDA, SCL need pull-up resistance. - -## Code -```C# -I2cConnectionSettings settings = new I2cConnectionSettings(1, Ags01db.DefaultI2cAddress); -I2cDevice device = I2cDevice.Create(settings); - -using (Ags01db sensor = new Ags01db(device)) -{ - // read AGS01DB version - Console.WriteLine($"Version: {sensor.Version}"); - Console.WriteLine(); - - while (true) - { - // read concentration - Console.WriteLine($"VOC Gas Concentration: {sensor.Concentration}ppm"); - Console.WriteLine(); - - Thread.Sleep(3000); - } -} -``` - -## Result -![](RunningResult.jpg) diff --git a/src/devices/Ahtxx/samples/Ahtxx_sample.png b/src/devices/Ahtxx/Ahtxx_sample.png similarity index 100% rename from src/devices/Ahtxx/samples/Ahtxx_sample.png rename to src/devices/Ahtxx/Ahtxx_sample.png diff --git a/src/devices/Ahtxx/README.md b/src/devices/Ahtxx/README.md index 0e600443af..02f8cf178c 100644 --- a/src/devices/Ahtxx/README.md +++ b/src/devices/Ahtxx/README.md @@ -1,23 +1,28 @@ # AHT10/15/20 - Temperature and humidity sensor modules -## Summary The AHT10/15 and AHT20 sensors are high-precision, calibrated temperature and relative humidity sensor modules with an I2C digital interface. -## Binding Notes +## Documentation + ### Supported Devices + The binding supports the following types: -* AHT10 - http://www.aosong.com/en/products-40.html -* AHT15 - http://www.aosong.com/en/products-45.html -* AHT20 - http://www.aosong.com/en/products-32.html + +* [AHT10](http://www.aosong.com/en/products-40.html) +* [AHT15](http://www.aosong.com/en/products-45.html) +* [AHT20](http://www.aosong.com/en/products-32.html) ### Functions + The binding supports the following sensor functions: + * acquiring the temperature and relative humidty readings * reading status * issueing calibration and reset commands ### Sensor classes + You need to choose the class depending on the sensor type. |Sensor|Required class| @@ -26,13 +31,13 @@ You need to choose the class depending on the sensor type. |Aht15|Aht10 | |Aht20|Aht20 | +## Usage -### Basic Usage - -The binding gets instantiated using an existing ```I2cDevice`` instance. The AHT-sensor modules support only the default I2C address. +The binding gets instantiated using an existing `I2cDevice` instance. The AHT-sensor modules support only the default I2C address. Setup for an AHT20 sensor module: -``` + +```csharp const int I2cBus = 1; I2cConnectionSettings i2cSettings = new I2cConnectionSettings(I2cBus, Aht20.DefaultI2cAddress); I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); @@ -41,9 +46,15 @@ Aht20 sensor = new Aht20(i2cDevice); The temperature and humidity readings are acquired by using the following methods: -``` +```csharp public Temperature GetTemperature() public Ratio GetHumidity() ``` -Refer to the sample application for a complete example. +Refer to the [sample application](https://github.com/dotnet/iot/tree/main/src/devices/Ahtxx/samples) for a complete example. + +## Wiring + +The AHTxx sensor is wired to the I2C interface (SDC/SDA) of the Raspberry Pi. The sensor is supplied with 3.3V to comply with the 3.3V interface level of the RPi. + +![Sample wiring](./Ahtxx_sample.png) diff --git a/src/devices/Ahtxx/samples/README.md b/src/devices/Ahtxx/samples/README.md deleted file mode 100644 index 0f0003e95a..0000000000 --- a/src/devices/Ahtxx/samples/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Sample application for use the of Ahtxx binding - -## Summary -The sample application demonstrates how to setup the binding and retrieve the current readings. -It can be used with all three supported types by using the specific binding class (Aht10 / Aht20). - -## Wiring -The AHTxx sensor is wired to the I2C interface (SDC/SDA) of the Raspberry Pi. The sensor is supplied with 3.3V to comply with the 3.3V interface level of the RPi. - -![Sample wiring](./Ahtxx_sample.png) \ No newline at end of file diff --git a/src/devices/Ak8963/README.md b/src/devices/Ak8963/README.md index 015e23edc5..6e39dff22d 100644 --- a/src/devices/Ak8963/README.md +++ b/src/devices/Ak8963/README.md @@ -2,9 +2,13 @@ The AK8963 is a magnetometer that can be controlled either thru I2C either thru SPI. It is present in other sensors like the [MPU9250](../Mpu9250/README.md). This implementation fully supports the I2C mode and the usage thru the MPU9250. It does not support SPI. +## Documentation + +Documentation for the AK8963 can be found [here](https://www.akm.com/akm/en/file/datasheet/AK8963C.pdf) + ## Usage -You can find an example in the [sample](./samples/ak8963.sample.cs) directory. Usage is straight forward including the possibility to have a calibration. +You can find an example in the [sample](https://github.com/dotnet/iot/tree/main/src/devices/Ak8963/samples/ak8963.sample.cs) directory. Usage is straight forward including the possibility to have a calibration. ```csharp var mpui2CConnectionSettingmpus = new I2cConnectionSettings(1, Ak8963.Ak8963.DefaultI2cAddress); @@ -126,7 +130,3 @@ Only I2C is supported in this version. * GND - GND Depending on the version you have, you may have to select I2C over SPI. This is done in different way depending on the board you'll have. - -## Reference - -Documentation for the AK8963 can be found here: https://www.akm.com/akm/en/file/datasheet/AK8963C.pdf \ No newline at end of file diff --git a/src/devices/Amg88xx/samples/AMG88xxSample.png b/src/devices/Amg88xx/AMG88xxSample.png similarity index 100% rename from src/devices/Amg88xx/samples/AMG88xxSample.png rename to src/devices/Amg88xx/AMG88xxSample.png diff --git a/src/devices/Amg88xx/README.md b/src/devices/Amg88xx/README.md index 4fc95c45e5..36c3964962 100644 --- a/src/devices/Amg88xx/README.md +++ b/src/devices/Amg88xx/README.md @@ -1,6 +1,5 @@ # AMG88xx Infrared Array Sensor Family -## Summary The sensors of the AMG88xx family of infrared array sensors have 64 thermophile pixels arranged in an 8×8 matrix. The sensor works as a thermal infrared camera. It can detect objects (e.g. human bodies) from a distance of up 5-7m. A pixel can measure object temperatures in a range of 0 to 80°C / -20 to 100°C with a resolution of 0.25°C and an accuracy of ±2.5°C / ±4.5°C. The sensor has a view field angle of 60° and a 7.5° view angle per pixel. The manufacturer (Panasonic) names the following applications: home appliances (microwaves and air-conditioners), building automation (people counting, air conditioning control), home automation (people detection), factory automation (fault prevention). The sensor delivers a heat image through its digital interface (I2C) at a rate of 1 or 10 frames per second. @@ -10,10 +9,18 @@ Additionally an interrupt pin can raise an event when any individual pixel goes *Illustration of thermophile pixel array and heat map* -## Device Family -**AMG88**: https://industrial.panasonic.com/cdbs/www-data/pdf/ADI8000/ADI8000COL13.pdf +## Documentation + +- Product [homepage](https://industry.panasonic.eu/components/sensors/grid-eye) +- Product [flyer](https://eu.industrial.panasonic.com/sites/default/pidseu/files/downloads/files/)grid-eye_flyer_english_web.pdf +- Reference [Specification](https://mediap.industry.panasonic.eu/assets/custom-upload/Components/Sensors/Industrial%20Sensors/Infrared%20Array%20Sensor%20Grid-EYE/grid_eye_reference_specifications_160205.pdf) +- [FAQ](https://mediap.industry.panasonic.eu/assets/custom-upload/Components/Sensors/Industrial%20Sensors/Infrared%20Array%20Sensor%20Grid-EYE/faqs_grideye_v1.0.pdf) +- Application [note](https://mediap.industry.panasonic.eu/assets/custom-upload/Components/Sensors/Industrial%20Sensors/Infrared%20Array%20Sensor%20Grid-EYE/application_notes_grid-eye_0.pdf) + +### Device Family + +the [AMG88](https://industrial.panasonic.com/cdbs/www-data/pdf/ADI8000/ADI8000COL13.pdf) family consists of 4 members: -The family consists of 4 members: |Type |Resolution|Gain |Vcc|Obj. Temp. Range|Resolution|Accuracy| |-------|----------|-----|---|----------------|----------|--------| |AMG8833| 8x8 | High|3V3|0-80°C |0.25°C |±2.5°C | @@ -25,45 +32,54 @@ The sensor is equipped with an on-chip thermistor which can be read out. The thermistor has a measurement range of -20...80°C at a resolution of 0.0625°C. ## Binding Notes + The Amg88xx binding provides a lean interface to retrieve the pixel array and to control the sensor. All sensor functions are covered. Any further processing, e.g. pattern recognition, is beyond the scope of the binding. ### Thermal image / Pixel array + The temperature readings of the pixel array can be read as a thermal image with 64 pixels arranged in an 8x8 matrix. The pixel array can be read out at any time and speed. However, the sensor updates the corresponding registers depending on the configured frame rate. The sensor has an integrated thermistor which can be readout to get the chip temperature. -**Note:** The chip temperature does *not* equal to the environmental temeperature. +**Note:** The chip temperature does *not* equal to the environmental temperature. The current image can be read from the sensor into the binding by: -``` + +```csharp public void ReadImage() ``` The temperature of a pixel specified by its coordinates can be read using an indexer: -``` + +```csharp public Temperature this[int x, int y] ``` The whole temperature image can be read as a two-dimensional array: -``` + +```csharp public Temperature[,] TemperatureImage ``` The raw reading (12-bit two's complement format) of a pixel specified by its number can be read using an indexer: -``` + +```csharp public Int16 this[int n] ``` -**Note:** there is no statement in the reference specification regarding the synchronization between an update of the pixel registers and the readout operation. So, you may read out pixel data from two subsequent frames in one readout operation. However, for normal application this shouldn't be relevant. +**Note**: there is no statement in the reference specification regarding the synchronization between an update of the pixel registers and the readout operation. So, you may read out pixel data from two subsequent frames in one readout operation. However, for normal application this shouldn't be relevant. Property: -``` + +```csharp public Temperature SensorTemperature ``` + **Note**: the thermistor temperature is not equivalent to the ### Operating Mode / Power Control + The sensor supports four operating modes to control power consumption: * Normal * Sleep Mode @@ -71,53 +87,62 @@ The sensor supports four operating modes to control power consumption: * Stand-by with 10 seconds intermittence Property: -``` + +```csharp public OperatingMode OperatingMode ``` -*Note*: refer to the reference specification for further details on mode transitions and sensor behavior. +**Note**: refer to the reference specification for further details on mode transitions and sensor behavior. ### Reset + The sensor supports two types of resets. * **Reset:** Resets all flags and registers to default values * **Resetting all flags:** Resets all flags (status register, interrupt flag, interrupt table) -``` + +```csharp public void Reset() public void ResetAllFlags() ``` -*Note*: resetting the interrupt related flags is only required if you want to clear flags while the readings are still within the hysteresis span. See interrupts section for further details on interrupt behavior. + +**Note**: resetting the interrupt related flags is only required if you want to clear flags while the readings are still within the hysteresis span. See interrupts section for further details on interrupt behavior. ### Sensor Status The sensor status indicates if any pixel or the chip internal thermistor overran the upper or lower operating range limit. It also flags on the occurrence of an interrupt. The status can be read out and reset per flag: -``` -public bool HasTemperatureOverflow() -public void ClearTemperatureOverflow() -public bool HasThermistorOverflow() -public void ClearThermistorOverflow() +```csharp +public bool HasTemperatureOverflow(); +public void ClearTemperatureOverflow(); + +public bool HasThermistorOverflow(); +public void ClearThermistorOverflow(); -public bool HasInterrupt() -public void ClearInterrupt() +public bool HasInterrupt(); +public void ClearInterrupt(); -public void ClearAllFlags() +public void ClearAllFlags(); ``` -*Note*: resetting the interrupt flag is only required if you want to clear flags while the readings are still within the hysteresis span (but already within the lower-upper range). This method does not clear the interrupt flags of the individual pixels. + +**Note**: resetting the interrupt flag is only required if you want to clear flags while the readings are still within the hysteresis span (but already within the lower-upper range). This method does not clear the interrupt flags of the individual pixels. See interrupts section for further details on interrupt behavior. *Note*: the thermistor overflow flag is only menthioned in early versions of the reference specification. It is not clear whether this is a specification error or a change in a newer revision of the sensor. ### Frame Rate + **Default:** 10fps The sensor supports frame rates of 1fps and 10fps. The frame rate defines the update interval of the pixels. This is independent from the readout interval through the I2C interface. Property: -``` + +```csharp public FrameRate FrameRate ``` ### Moving average + **Default:** off The sensor supports a moving average mode. In this mode it builds the twice moving average for each pixel. @@ -132,29 +157,36 @@ The average of two averages of 10 readings is the resulting output. The noise per pixel will decrease to 1/sqrt2 when using the moving average mode. Property: -``` + +```csharp public bool UseMovingAverageMode ``` + ***Important***: the reference specification states that the current mode can be read, but it doesn't seem to work at the time being. In this case the property is always read as ```false```. ### Interrupt control, levels and pixel flags The sensor can raise an interrupt if any pixel passes a given value. The event is signaled by the interrupt flag of the status register. Additionally the INT pin of the sensor can be pulled low. Properties: -``` + +```csharp public InterruptMode PixelTemperatureInterruptMode public bool InterruptPinEnabled ``` + The interrupt levels can be configured. The lower and upper limit as well as the hysteresis level can be set and read. Initially the register is filled with zeros. The levels apply to all pixels equally. Properties: -``` + +```csharp public Temperature InterruptLowerLevel public Temperature InterruptUpperLevel public Temperature InterruptHysteresis ``` + After the sensor raised an interrupt the triggering pixels can be readout from the interrupt table register. -``` + +```csharp public bool[,] GetInterruptFlagTable() ``` @@ -167,13 +199,24 @@ Interrupt levels and hysteresis * any flag in the interrupt flag table is automatically reset if the corresponding pixel is no long exceed the lower or upper threshold. * if a hysteresis is applied and the reading of a pixel is not passing the threshold anymore, while at the same time the reading is still within the hysteresis span, the interrupt flag can be cleared by using the ```ResetAllFlags``` method. -## References -**Product Homepage**: https://industry.panasonic.eu/components/sensors/grid-eye +## Example + +### Overview + +The [sample application](https://github.com/dotnet/iot/tree/main/src/devices/Amg88xx/samples) demonstrates the key functions of the sensor and the binding: + +* thermal image readout +* interrupt triggering based on temperature levels incl. hysteresis +* sensor states +* noise reduction by using the sensor's moving average function + +There are AMG88xx breakout boards available from a variety of vendors. You can use any of them as long as it provides access to the I2C interface of the sensor. -**Product Flyer**: https://eu.industrial.panasonic.com/sites/default/pidseu/files/downloads/files/grid-eye_flyer_english_web.pdf +**Note:** There are also boards available with additional interfaces or even with an integrated Arduino or compatible circuit. You can use this binding only if the boards gives you access to the I2C interface only. -**Reference Specification**: https://mediap.industry.panasonic.eu/assets/custom-upload/Components/Sensors/Industrial%20Sensors/Infrared%20Array%20Sensor%20Grid-EYE/grid_eye_reference_specifications_160205.pdf +### Wiring -**FAQ**: https://mediap.industry.panasonic.eu/assets/custom-upload/Components/Sensors/Industrial%20Sensors/Infrared%20Array%20Sensor%20Grid-EYE/faqs_grideye_v1.0.pdf +For demonstration purpose the INT-pin of the sensor is connected to GPIO PIN 5 of the RPi. Additionally an LED is connected to GPIO PIN 6 of the RPi. The LED signals the occurrence of an interrupt. +The resistor depends on the LED type; however 150R-220R is a safe choice for a standard red LED. Or precisely: `R = (3,3V - U LED,forward) / I LED, forward` -**Application Note**: https://mediap.industry.panasonic.eu/assets/custom-upload/Components/Sensors/Industrial%20Sensors/Infrared%20Array%20Sensor%20Grid-EYE/application_notes_grid-eye_0.pdf +![Wiring of a sensor breakout and LED for the sample](./AMG88xxSample.png) diff --git a/src/devices/Apa102/README.md b/src/devices/Apa102/README.md index cce08f5b58..bf771ca6f8 100644 --- a/src/devices/Apa102/README.md +++ b/src/devices/Apa102/README.md @@ -13,14 +13,42 @@ APA107 | 30 MHz | 9 kHz HD107s | 40 MHz | 27 kHz SK9822 | 15 MHz | 4.7 kHz -# Datasheet - -[APA102](https://cdn.instructables.com/ORIG/FC0/UYH5/IOA9KN8K/FC0UYH5IOA9KN8K.pdf) - -[SK9822](https://cdn.instructables.com/ORIG/F66/Q8GE/IOA9KN8U/F66Q8GEIOA9KN8U.pdf) - -# References - -https://www.instructables.com/id/Compare-SK6822-WS2813-APA102-SK9822/ - -https://www.rose-lighting.com/the-difference-of-hd107s-apa107-sk9822led/ +## Documentation + +- [APA102](https://cdn.instructables.com/ORIG/FC0/UYH5/IOA9KN8K/FC0UYH5IOA9KN8K.pdf) +- [SK9822](https://cdn.instructables.com/ORIG/F66/Q8GE/IOA9KN8U/F66Q8GEIOA9KN8U.pdf) +- [Compare](https://www.instructables.com/id/Compare-SK6822-WS2813-APA102-SK9822/) SK6822 WS2813 APA102 SK9822 LED +- [Difference](https://www.rose-lighting.com/the-difference-of-hd107s-apa107-sk9822led/) between APA102, APA107,HD107s and SK9822 + +## Usage + +Here is an example how to use the APA102: + +```csharp +using System; +using System.Device.Spi; +using System.Drawing; +using System.Threading; +using Iot.Device.Apa102; + +var random = new Random(); + +using SpiDevice spiDevice = SpiDevice.Create(new SpiConnectionSettings(0, 0) +{ + ClockFrequency = 20_000_000, + DataFlow = DataFlow.MsbFirst, + Mode = SpiMode.Mode0 // ensure data is ready at clock rising edge +}); +using Apa102 apa102 = new Apa102(spiDevice, 16); + +while (true) +{ + for (var i = 0; i < apa102.Pixels.Length; i++) + { + apa102.Pixels[i] = Color.FromArgb(255, random.Next(256), random.Next(256), random.Next(256)); + } + + apa102.Flush(); + Thread.Sleep(1000); +} +``` \ No newline at end of file diff --git a/src/devices/Arduino/samples/ArduinoSample.fzz b/src/devices/Arduino/ArduinoSample.fzz similarity index 100% rename from src/devices/Arduino/samples/ArduinoSample.fzz rename to src/devices/Arduino/ArduinoSample.fzz diff --git a/src/devices/Arduino/samples/ArduinoSample_Monitor.png b/src/devices/Arduino/ArduinoSample_Monitor.png similarity index 100% rename from src/devices/Arduino/samples/ArduinoSample_Monitor.png rename to src/devices/Arduino/ArduinoSample_Monitor.png diff --git a/src/devices/Arduino/README.md b/src/devices/Arduino/README.md index 6c99f54b72..a5d9aa4ba4 100644 --- a/src/devices/Arduino/README.md +++ b/src/devices/Arduino/README.md @@ -11,10 +11,13 @@ This binding remotely controls Arduino boards directly from PC Software. It prov In order to get an Arduino board working with the PC, you need to Install the Arduino IDE together with the drivers for your board type. If you get a simple sketch uploaded and running (such as the blinking LED example) you are fine to start. If you're new to the Arduino world, read the introductions at https://www.arduino.cc/en/Guide for a quick start. The explanations below assume you have the Arduino board connected through an USB cable with your PC and you know how to upload a sketch. Once the sketch has been uploaded, the IDE is no longer required. ## Preparing your Arduino + ### Quick start -You need to upload a special sketch to the Arduino. This sketch implements the "Firmata-Protocol", a communication protocol that allows to remotely control all the inputs and outputs of the board. See https://github.com/firmata/protocol/blob/master/protocol.md for details. We call this sketch (or variants of it, see below) the Firmata firmware. -The binding requires Firmata Version 2.6, which is implemented i.e. by the ConfigurableFirmata project. +You need to upload a special sketch to the Arduino. This sketch implements the "Firmata-Protocol", a communication protocol that allows to remotely control all the inputs and outputs of the board. See [Firmata Protocol](https://github.com/firmata/protocol/blob/master/protocol.md) for details. We call this sketch (or variants of it, see below) the Firmata firmware. + +The binding requires Firmata Version 2.6, which is implemented i.e. by the ConfigurableFirmata project. + - Open the Arduino IDE - Go to the library manager and check that you have the "ConfigurableFirmata" library installed - Open "ConfigurableFirmata.ino" from the [device binding folder](./ConfigurableFirmata/ConfigurableFirmata.ino) or go to http://firmatabuilder.com/ to create your own custom firmata firmware. Make sure you have at least the features checked that you will need. @@ -25,14 +28,16 @@ After these steps, you can start coding with Iot.Devices.Arduino and make your A When the firmware starts, the on-board-LED flashes a few times, indicating the loaded firmware version (currently 2 + 11 blinks). After that, the board will enter idle state and wait for connections. ### Advanced features + Some of the features of this binding require extended features in the Arduino firmware. These include SPI support and DHT sensor support. These features didn't make it into the main Firmata branch yet, therefore these additional steps are required: -- Go to C:\users\\documents\arduino\libraries and delete the "ConfigurableFirmata" folder (save any work if you've changed anything there) -- Replace it with a clone of https://github.com/pgrawehr/ConfigurableFirmata and switch to branch "develop". +- Go to `C:\users\\documents\arduino\libraries` and delete the "ConfigurableFirmata" folder (save any work if you've changed anything there) +- Replace it with a clone of [Configurable Firmata](https://github.com/pgrawehr/ConfigurableFirmata) and switch to branch "develop". - Make sure you have the "DHT Sensor Library" from Adafruit installed (use the library manager for that). -- You can now enable the DHT and SPI features at the beginning of the ConfigurableFirmata.ino file. Because the new firmware will have additional features, it is recommended to use the .ino file from the examples folder of the repository. So the best start is to open the file that now lies in C:\users\\documents\arduino\libraries\ConfigurableFirmata\examples\ConfigurableFirmata\ConfigurableFirmata.ino. The file has some comments at the top to enable or disable certain modules. +- You can now enable the DHT and SPI features at the beginning of the ConfigurableFirmata.ino file. Because the new firmware will have additional features, it is recommended to use the .ino file from the examples folder of the repository. So the best start is to open the file that now lies in `C:\users\\documents\arduino\libraries\ConfigurableFirmata\examples\ConfigurableFirmata\ConfigurableFirmata.ino`. The file has some comments at the top to enable or disable certain modules. - Compile and re-upload the sketch. ## Usage + See the examples for some advanced use cases. Basic start: @@ -72,10 +77,12 @@ The samples were mostly tested using an Arduino Nano, but they will certainly al The image below shows the required hardware to run all the tests combined on a breadboard. -![select branch](./samples/ArduinoSample_Monitor.png) +![select branch](ArduinoSample_Monitor.png) ### Test code + The project "Arduino.sample" contains a console application that allows testing individual features, such as digital output (blinking LED), digital input (button), analog input or I2C communication. ### Monitor + The project "Arduino.Monitor" is a simple real-world example. The program can run in the background and shows current environment temperature, CPU usage, CPU temperature and many other data sets on an external display. With this, you can keep an eye on your CPU temperature or the current time while the screen is off or while you're running full-screen games. The prerequisites from the [Hardware Monitor](../HardwareMonitor/README.md) need to be installed as well. diff --git a/src/devices/Bh1745/README.md b/src/devices/Bh1745/README.md index 113c1657ca..c4efc5b101 100644 --- a/src/devices/Bh1745/README.md +++ b/src/devices/Bh1745/README.md @@ -1,11 +1,13 @@ # Bh1745 - RGB Sensor -## Summary - The Bh1745 is a digital color sensor able to detect 3 distinct channels of light (red, green, blue) and is most suitable to obtain the illuminance and color temperature of ambient light. The device can detect light intensity in a range of 0.005 to 40 000 lux. +## Documentation + +[Datasheet of the Bh1745](https://www.mouser.co.uk/datasheet/2/348/bh1745nuc-e-519994.pdf) + ## Usage 2 examples on how to use this device binding are available in the [samples folder](samples). @@ -16,6 +18,79 @@ The quality of the color measurements is very reliant on the lighting. For accur Some breakout boards come with built in LEDs for this purpose (some of the API functionality may also have been repurposed to control these LEDs). -## References +Basic usage: -[Datasheet of the Bh1745](https://www.mouser.co.uk/datasheet/2/348/bh1745nuc-e-519994.pdf) +```csharp +using System; +using System.Device.I2c; +using System.Threading; +using Iot.Device.Bh1745; + +// bus id on the raspberry pi 3 +const int busId = 1; + +// create device +I2cConnectionSettings i2cSettings = new(busId, Bh1745.DefaultI2cAddress); +using I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); +using Bh1745 i2cBh1745 = new Bh1745(i2cDevice); +// wait for first measurement +Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan()); + +while (true) +{ + var color = i2cBh1745.GetCompensatedColor(); + Console.WriteLine("RGB color read: #{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B); + Console.WriteLine($"Raw illumination value: {i2cBh1745.ReadClearDataRegister()}"); + + Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan()); +} +``` + +Advance usage with configuration: + +```csharp +// bus id on the raspberry pi 3 +const int busId = 1; + +// create device +var i2cSettings = new I2cConnectionSettings(busId, Bh1745.DefaultI2cAddress); +var i2cDevice = I2cDevice.Create(i2cSettings); + +using Bh1745 i2cBh1745 = new Bh1745(i2cDevice) +{ + // multipliers affect the compensated values + // ChannelCompensationMultipliers: Red, Green, Blue, Clear + ChannelCompensationMultipliers = new(2.5, 0.9, 1.9, 9.5), + + // set custom measurement time + MeasurementTime = MeasurementTime.Ms1280, + + // interrupt functionality is detailed in the datasheet + // Reference: https://www.mouser.co.uk/datasheet/2/348/bh1745nuc-e-519994.pdf (page 13) + LowerInterruptThreshold = 0xABFF, + HigherInterruptThreshold = 0x0A10, + + LatchBehavior = LatchBehavior.LatchEachMeasurement, + InterruptPersistence = InterruptPersistence.UpdateMeasurementEnd, + InterruptIsEnabled = true, +}; + +// wait for first measurement +Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan()); + +while (true) +{ + var color = i2cBh1745.GetCompensatedColor(); + + if (!i2cBh1745.ReadMeasurementIsValid()) + { + Console.WriteLine("Measurement was not valid!"); + continue; + } + + Console.WriteLine("RGB color read: #{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B); + Console.WriteLine($"Raw illumination value: {i2cBh1745.ReadClearDataRegister()}"); + + Thread.Sleep(i2cBh1745.MeasurementTimeAsTimeSpan()); +} +``` \ No newline at end of file diff --git a/src/devices/Bh1750fvi/samples/BH1750FVI_Circuit.fzz b/src/devices/Bh1750fvi/BH1750FVI_Circuit.fzz similarity index 100% rename from src/devices/Bh1750fvi/samples/BH1750FVI_Circuit.fzz rename to src/devices/Bh1750fvi/BH1750FVI_Circuit.fzz diff --git a/src/devices/Bh1750fvi/samples/BH1750FVI_Circuit_bb.png b/src/devices/Bh1750fvi/BH1750FVI_Circuit_bb.png similarity index 100% rename from src/devices/Bh1750fvi/samples/BH1750FVI_Circuit_bb.png rename to src/devices/Bh1750fvi/BH1750FVI_Circuit_bb.png diff --git a/src/devices/Bh1750fvi/README.md b/src/devices/Bh1750fvi/README.md index b8a45efd11..93b3d8fb5e 100644 --- a/src/devices/Bh1750fvi/README.md +++ b/src/devices/Bh1750fvi/README.md @@ -1,11 +1,18 @@ # BH1750FVI - Ambient Light Sensor + BH1750FVI is an digital Ambient Light Sensor IC for I2C bus interface. This IC is the most suitable to obtain the ambient light data for adjusting LCD and Keypad backlight power of Mobile phone. It is possible to detect wide range at High resolution. +## Documentation + +Product datasheet can be found [here](https://cdn.datasheetspdf.com/pdf-down/B/H/1/BH1750FVI_Rohm.pdf) + ## Sensor Image -![](sensor.jpg) + +![sensor](sensor.jpg) ## Usage -```C# + +```csharp I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow); I2cDevice device = I2cDevice.Create(settings); @@ -17,5 +24,16 @@ using (Bh1750fvi sensor = new Bh1750fvi(device)) ``` -## References -https://cdn.datasheetspdf.com/pdf-down/B/H/1/BH1750FVI_Rohm.pdf +## Circuit + +![circuit](BH1750FVI_Circuit_bb.png) + +* SCL - SCL +* SDA - SDA +* VCC - 5V +* GND - GND +* ADDR - GND + +Result of the sample: + +![running result](RunningResult.jpg) diff --git a/src/devices/Bh1750fvi/samples/RunningResult.jpg b/src/devices/Bh1750fvi/RunningResult.jpg similarity index 100% rename from src/devices/Bh1750fvi/samples/RunningResult.jpg rename to src/devices/Bh1750fvi/RunningResult.jpg diff --git a/src/devices/Bh1750fvi/samples/README.md b/src/devices/Bh1750fvi/samples/README.md deleted file mode 100644 index 368c55f179..0000000000 --- a/src/devices/Bh1750fvi/samples/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# BH1750FVI - Samples - -## Hardware Required -* BH1750FVI -* Male/Female Jumper Wires - -## Circuit -![](BH1750FVI_Circuit_bb.png) - -* SCL - SCL -* SDA - SDA -* VCC - 5V -* GND - GND -* ADDR - GND - -## Code -```C# -I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow); -I2cDevice device = I2cDevice.Create(settings); - -using (Bh1750fvi sensor = new Bh1750fvi(device)) -{ - while (true) - { - Console.WriteLine($"Illuminance: {sensor.Illuminance}Lux"); - - Thread.Sleep(1000); - } -} -``` - -## Result -![](RunningResult.jpg) diff --git a/src/devices/Bmp180/README.md b/src/devices/Bmp180/README.md index f5c89f7b63..9dab1b8ea0 100644 --- a/src/devices/Bmp180/README.md +++ b/src/devices/Bmp180/README.md @@ -1,11 +1,54 @@ # BMP180 - barometer, altitude and temperature sensor -BMP180 is a device that read barometic pressure, altitude and temperature. I2C can be used to communicate with the device. +BMP180 is a device that read barometric pressure, altitude and temperature. I2C can be used to communicate with the device. + +## Documentation [Datasheet](https://cdn-shop.adafruit.com/datasheets/BST-BMP180-DS000-09.pdf) for the BMP180. +## Usage + An example on how to use this device binding is available in the [samples](samples) folder. +```csharp +// bus id on the raspberry pi 3 +const int busId = 1; + +I2cConnectionSettings i2cSettings = new(busId, Bmp180.DefaultI2cAddress); +using I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); + +using Bmp180 i2cBmp280 = new(i2cDevice); +// set samplings +i2cBmp280.SetSampling(Sampling.Standard); + +// read values +Temperature tempValue = i2cBmp280.ReadTemperature(); +Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C"); +Pressure preValue = i2cBmp280.ReadPressure(); +Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa"); + +// Note that if you already have the pressure value and the temperature, you could also calculate altitude by +// calling WeatherHelper.CalculateAltitude(preValue, Pressure.MeanSeaLevel, tempValue) which would be more performant. +Length altValue = i2cBmp280.ReadAltitude(WeatherHelper.MeanSeaLevel); + +Console.WriteLine($"Altitude: {altValue:0.##}m"); +Thread.Sleep(1000); + +// set higher sampling +i2cBmp280.SetSampling(Sampling.UltraLowPower); + +// read values +tempValue = i2cBmp280.ReadTemperature(); +Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C"); +preValue = i2cBmp280.ReadPressure(); +Console.WriteLine($"Pressure: {preValue.Hectopascals:0.##}hPa"); + +// Note that if you already have the pressure value and the temperature, you could also calculate altitude by +// calling WeatherHelper.CalculateAltitude(preValue, Pressure.MeanSeaLevel, tempValue) which would be more performant. +altValue = i2cBmp280.ReadAltitude(WeatherHelper.MeanSeaLevel); +Console.WriteLine($"Altitude: {altValue:0.##}m"); +``` + The following fritzing diagram illustrates one way to wire up the BMP180 with a Raspberry Pi using I2C. -![Raspberry Pi Breadboard diagram](samples/rpi-bmp180_i2c_bb.png) +![Raspberry Pi Breadboard diagram](rpi-bmp180_i2c_bb.png) diff --git a/src/devices/Bmp180/samples/rpi-bmp180_i2c.fzz b/src/devices/Bmp180/rpi-bmp180_i2c.fzz similarity index 100% rename from src/devices/Bmp180/samples/rpi-bmp180_i2c.fzz rename to src/devices/Bmp180/rpi-bmp180_i2c.fzz diff --git a/src/devices/Bmp180/samples/rpi-bmp180_i2c_bb.png b/src/devices/Bmp180/rpi-bmp180_i2c_bb.png similarity index 100% rename from src/devices/Bmp180/samples/rpi-bmp180_i2c_bb.png rename to src/devices/Bmp180/rpi-bmp180_i2c_bb.png diff --git a/src/devices/Bmxx80/README.md b/src/devices/Bmxx80/README.md index 9fcf21e4ca..39bb5883b6 100644 --- a/src/devices/Bmxx80/README.md +++ b/src/devices/Bmxx80/README.md @@ -1,12 +1,11 @@ # BMxx80 Device Family -## Summary - BMxx80 is a device family that senses temperature, barometric pressure, altitude, humidity and VOC gas. SPI and I2C can be used to communicate with the device (only I2C implemented so far). -## Device Family +## Documentation + The implementation supports the following devices: - BMP280 temperature and barometric pressure sensor ([Datasheet](https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf)) @@ -15,7 +14,82 @@ The implementation supports the following devices: ## Usage -3 examples on how to use this device binding are available in the [samples](samples) folder. +### BME280 + +```csharp +// bus id on the raspberry pi 3 +const int busId = 1; +I2cConnectionSettings i2cSettings = new(busId, Bme280.DefaultI2cAddress); +using I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); +using Bme280 bme80 = new Bme280(i2cDevice) +{ + // set higher sampling + TemperatureSampling = Sampling.LowPower, + PressureSampling = Sampling.UltraHighResolution, + HumiditySampling = Sampling.Standard, + +}; + +// Perform a synchronous measurement +var readResult = bme80.Read(); + +// Note that if you already have the pressure value and the temperature, you could also calculate altitude by using +// var altValue = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue) which would be more performant. +bme80.TryReadAltitude(defaultSeaLevelPressure, out var altValue); + +Console.WriteLine($"Temperature: {readResult.Temperature?.DegreesCelsius:0.#}\u00B0C"); +Console.WriteLine($"Pressure: {readResult.Pressure?.Hectopascals:0.##}hPa"); +Console.WriteLine($"Altitude: {altValue.Meters:0.##}m"); +Console.WriteLine($"Relative humidity: {readResult.Humidity?.Percent:0.#}%"); +``` + +### BMP680 + +```csharp +// The I2C bus ID on the Raspberry Pi 3. +const int busId = 1; + +I2cConnectionSettings i2cSettings = new(busId, Bme680.DefaultI2cAddress); +I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); + +using Bme680 bme680 = new Bme680(i2cDevice, Temperature.FromDegreesCelsius(20.0)); + +// reset will change settings back to default +bme680.Reset(); + +// Perform a synchronous measurement +var readResult = bme680.Read(); + +// Print out the measured data +Console.WriteLine($"Gas resistance: {readResult.GasResistance?.Ohms:0.##}Ohm"); +Console.WriteLine($"Temperature: {readResult.Temperature?.DegreesCelsius:0.#}\u00B0C"); +Console.WriteLine($"Pressure: {readResult.Pressure?.Hectopascals:0.##}hPa"); +Console.WriteLine($"Relative humidity: {readResult.Humidity?.Percent:0.#}%"); +``` + +### BMP280 + +```csharp +// bus id on the raspberry pi 3 and 4 +const int busId = 1; + +I2cConnectionSettings i2cSettings = new(busId, Bmp280.DefaultI2cAddress); +I2cDevice i2cDevice = I2cDevice.Create(i2cSettings); +using var i2CBmp280 = new Bmp280(i2cDevice); + +// set higher sampling +i2CBmp280.TemperatureSampling = Sampling.LowPower; +i2CBmp280.PressureSampling = Sampling.UltraHighResolution; + +// Perform a synchronous measurement +var readResult = i2CBmp280.Read(); + +// Print out the measured data +Console.WriteLine($"Temperature: {readResult.Temperature?.DegreesCelsius:0.#}\u00B0C"); +Console.WriteLine($"Pressure: {readResult.Pressure?.Hectopascals:0.##}hPa"); +``` + +You also have 3 examples on how to use this device binding are available in the [samples](samples) folder. The following fritzing diagram illustrates one way to wire up the BMP280 with a Raspberry Pi using I2C: @@ -41,4 +115,3 @@ The following connection types are supported by this binding. - [X] I2C - [ ] SPI - diff --git a/src/devices/Bmxx80/samples/rpi-bmp280_i2c.fzz b/src/devices/Bmxx80/rpi-bmp280_i2c.fzz similarity index 100% rename from src/devices/Bmxx80/samples/rpi-bmp280_i2c.fzz rename to src/devices/Bmxx80/rpi-bmp280_i2c.fzz diff --git a/src/devices/Bmxx80/samples/rpi-bmp280_i2c.png b/src/devices/Bmxx80/rpi-bmp280_i2c.png similarity index 100% rename from src/devices/Bmxx80/samples/rpi-bmp280_i2c.png rename to src/devices/Bmxx80/rpi-bmp280_i2c.png diff --git a/src/devices/Bno055/README.md b/src/devices/Bno055/README.md index 585fb992ae..82fcf16b82 100644 --- a/src/devices/Bno055/README.md +++ b/src/devices/Bno055/README.md @@ -1,16 +1,14 @@ # BNO055 - inertial measurement unit -## Summary - Those sensors are intelligent 9-axis absolute orientation sensors. Most of the implementations are using I2C sensors but the sensor supports as well HID over I2C and serial port communication. This class only supports I2C. All operations for a current usage has been developed. The individual interruption level settings for each sensor has not been implemented. If needed, they are quite straight forward to implement. -## Device Family +## Documentation ![BNO055](./BNO055.jpg) -**BNO055** [datasheet](https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BNO055-DS000.pdf) +BNO055 [datasheet](https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BNO055-DS000.pdf) You will find this device as ["Inertial Measurement Unit"](https://www.dexterindustries.com/product/imu-sensor/) or ["Adafruit BNO055 Absolute Orientation Sensor"](https://learn.adafruit.com/adafruit-bno055-absolute-orientation-sensor/overview) @@ -27,13 +25,13 @@ Console.WriteLine($"Temperature source: {bno055Sensor.TemperatureSource}, Operat Console.WriteLine($"Powermode: {bno055Sensor.PowerMode}"); ``` -You can easilly access the sensor information and settings thru the properties. +You can easily access the sensor information and settings thru the properties. ## Calibration -To get accurate measurement, it is better to wait for the Magnetometer to calibrate. As in your phone, when the calibration is needed, it is necessary to move the sensor in the air to help for the qualibration. +To get accurate measurement, it is better to wait for the Magnetometer to calibrate. As in your phone, when the calibration is needed, it is necessary to move the sensor in the air to help for the calibration. -The following code shows how to check the qualibration: +The following code shows how to check the calibration: ```csharp Console.WriteLine("Checking the magnetometer calibration, move the sensor up to the calibration will be complete if needed"); @@ -49,18 +47,18 @@ Console.WriteLine(); Console.WriteLine("Calibration completed"); ``` -Please note that it is not really necessary to check the qualibration of the other senosors and the system. The qualibraiton is done all the time. The important one is the Magnetometer. +Please note that it is not really necessary to check the calibration of the other sensors and the system. The qualibraiton is done all the time. The important one is the Magnetometer. ## Accessing sensor data -Simply access the various sensor data thru their properties. Note that it is better to read at once the data and then display them, or manipulate them rather than acccessing the sub element everytime. The reason is because in the first case, you'll do 1 measurement and the data will be consistent, in the second case, you'll do 1 measurement every time you access 1 sub property which means, the data will be inconsistent. +Simply access the various sensor data thru their properties. Note that it is better to read at once the data and then display them, or manipulate them rather than accessing the sub element every time. The reason is because in the first case, you'll do 1 measurement and the data will be consistent, in the second case, you'll do 1 measurement every time you access 1 sub property which means, the data will be inconsistent. *Wrong way:* ```csharp // Data will be inconsistent in this case! // Do not access the data like this -Console.WriteLine($"Magnetomer X: {bno055Sensor.Magnetometer.X} Y: {bno055Sensor.Magnetometer.Y} Z: {bno055Sensor.Magnetometer.Z}"); +Console.WriteLine($"Magnetometer X: {bno055Sensor.Magnetometer.X} Y: {bno055Sensor.Magnetometer.Y} Z: {bno055Sensor.Magnetometer.Z}"); ``` **Good way:** @@ -69,7 +67,7 @@ Console.WriteLine($"Magnetomer X: {bno055Sensor.Magnetometer.X} Y: {bno055Sensor // First read and store the data var magneto = bno055Sensor.Magnetometer; // Then manipulate the data -Console.WriteLine($"Magnetomer X: {magneto.X} Y: {magneto.Y} Z: {magneto.Z}"); +Console.WriteLine($"Magnetometer X: {magneto.X} Y: {magneto.Y} Z: {magneto.Z}"); ``` The sensor offers 9-axis measurement. Here is an example showing all the sensor properties you can access: @@ -79,7 +77,7 @@ while(!Console.KeyAvailable) { Console.Clear(); var magneto = bno055Sensor.Magnetometer; - Console.WriteLine($"Magnetomer X: {magneto.X} Y: {magneto.Y} Z: {magneto.Z}"); + Console.WriteLine($"Magnetometer X: {magneto.X} Y: {magneto.Y} Z: {magneto.Z}"); var gyro = bno055Sensor.Gyroscope; Console.WriteLine($"Gyroscope X: {gyro.X} Y: {gyro.Y} Z: {gyro.Z}"); var accele = bno055Sensor.Accelerometer; diff --git a/src/devices/Bno055/samples/README.md b/src/devices/Bno055/samples/README.md deleted file mode 100644 index 7b8edba9e1..0000000000 --- a/src/devices/Bno055/samples/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Bno055 sensor example - -Please refer to [main documentation](../README.md) for more details. - -When using this sensor with an I2C board, just make sure you connect your I2C pins correctly as well as the VCC and ground. \ No newline at end of file diff --git a/src/devices/BrickPi3/README.md b/src/devices/BrickPi3/README.md index 580a6f8eed..02af2cf9d7 100644 --- a/src/devices/BrickPi3/README.md +++ b/src/devices/BrickPi3/README.md @@ -44,7 +44,7 @@ For I2C sensors, the code has been tested very little. Color sensors may return ## How to use the driver -The main [BrickPi3.samples](./samples) contains a series of test showing how to use every elements of the driver. +The main [BrickPi3.samples](https://github.com/dotnet/iot/tree/main/src/devices/BrickPi3/samples) contains a series of test showing how to use every elements of the driver. Create a ```Brick``` class. @@ -309,5 +309,49 @@ The only supported sensors in the GrovePi port present on BrickPi3 are I2C senso ## Tests -A series of hardware tests for motors and sensors are available in [BrickPi3.samples](./samples). Those hardware tests offers a variety of low level access to the Brick class as well as high level thru the Motor and Sensor classes. +A series of hardware tests for motors and sensors are available in [BrickPi3.samples](https://github.com/dotnet/iot/tree/main/src/devices/BrickPi3/samples). Those hardware tests offers a variety of low level access to the Brick class as well as high level thru the Motor and Sensor classes. +## Example + +Refer to the [sample code](https://github.com/dotnet/iot/tree/main/src/devices/BrickPi3/samples) to understand on which port you'll need to plug motors and sensors. The available tests are the following: + +``` +./BrickPiHardwareTest -arg1 - arg2 +where -arg1, arg2, etc are one of the following: +-nobrick: don't run the basic BrickPi tests. +-motor: run basic motor tests, motors need to be on port A and D. +-vehicle: run a vehicle test, motors need to be on port A and D. +-multi: run a multi sensor test + EV3TouchSensor on port 1 + NXTTouchSensor on port 2 + NXTColorSensor on port 3 + NXTSoundSensor on port 4 + Press the EV3TouchSensor sensor to finish +-color: run an EV3 color test + EV3TouchSensor on port 1 + EV3ColorSensor on port 2 +-touch: run touch sensor test + EV3TouchSensor on port 1 +-nxtlight: run the NXT light sensor tests + NXTLightSensor on port 4 +-nxtus: run NXT Ultrasonic test on port 4 +-nxtcolor: run NXT Color sensor test + EV3TouchSensor on port 1 + NXTColorSensor on port 4 +-irsensor: run EV3 IR sensor test on port 4 +``` + +You always have to create a brick and initialize it. Then you can run your code. In this example, reading a Touch sensor. +```csharp +Brick _brick = new Brick(); +Console.WriteLine("Running 100 reads on EV3 touch sensor on port 1."); +EV3TouchSensor touch = new EV3TouchSensor(_brick, BrickPortSensor.PortS1); +// Alternative to test NXT touch sensor +// NXTTouchSensor touch = new NXTTouchSensor(brick, BrickPortSensor.PORT_S2); +int count = 0; +while (count < 100) +{ + Console.WriteLine($"NXT Touch, IsPRessed: {touch.IsPressed()}, ReadAsString: {touch.ReadAsString()}, Selected mode: {touch.SelectedMode()}"); + Task.Delay(300).Wait(); ; +} +``` \ No newline at end of file diff --git a/src/devices/BrickPi3/samples/README.md b/src/devices/BrickPi3/samples/README.md deleted file mode 100644 index 526363fdc3..0000000000 --- a/src/devices/BrickPi3/samples/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# BrickPi3 - -The provided examples covers almost all high level sensor classes as well as motors and brick information. This is the code used to test the hardware. - -# Schematic - -Just plug your BrickPi3 shield on your Raspberry Pi. You can add multiple BrickPi3, up to 254. Please note that you'll have to setup individually each of them first by changing their address. - -If you are using another board with compatible pins with the Raspberry Pi, you will be able to use it as well without any change. If you are using a board with a different pin out, make sure you connect the SPI of your board to the SPI of BrickPi3. - -![image how it works](../BrickPi3-How-it-Works.jpg) - -More information on [Dexter Industries website](https://www.dexterindustries.com/BrickPi/brickpi3-technical-design-details/). - -# Code - -The code illustrate how to use most sensors as well as motors. It is the code used to test the hardware devices. As exampled in the main documentation, we do recommend to use the high level classes to access the sensors and the motors rather than the low level one. That said the example contains examples on how to use all of them. - -Refer to the code to understand on which port you'll need to plug motors and sensors. The available tests are the following: - -``` -./BrickPiHardwareTest -arg1 - arg2 -where -arg1, arg2, etc are one of the following: --nobrick: don't run the basic BrickPi tests. --motor: run basic motor tests, motors need to be on port A and D. --vehicle: run a vehicle test, motors need to be on port A and D. --multi: run a multi sensor test - EV3TouchSensor on port 1 - NXTTouchSensor on port 2 - NXTColorSensor on port 3 - NXTSoundSensor on port 4 - Press the EV3TouchSensor sensor to finish --color: run an EV3 color test - EV3TouchSensor on port 1 - EV3ColorSensor on port 2 --touch: run touch sensor test - EV3TouchSensor on port 1 --nxtlight: run the NXT light sensor tests - NXTLightSensor on port 4 --nxtus: run NXT Ultrasonic test on port 4 --nxtcolor: run NXT Color sensor test - EV3TouchSensor on port 1 - NXTColorSensor on port 4 --irsensor: run EV3 IR sensor test on port 4 -``` - -You always have to create a brick and initialize it. Then you can run your code. In this example, reading a Touch sensor. -```csharp -Brick _brick = new Brick(); -Console.WriteLine("Running 100 reads on EV3 touch sensor on port 1."); -EV3TouchSensor touch = new EV3TouchSensor(_brick, BrickPortSensor.PortS1); -// Alternative to test NXT touch sensor -// NXTTouchSensor touch = new NXTTouchSensor(brick, BrickPortSensor.PORT_S2); -int count = 0; -while (count < 100) -{ - Console.WriteLine($"NXT Touch, IsPRessed: {touch.IsPressed()}, ReadAsString: {touch.ReadAsString()}, Selected mode: {touch.SelectedMode()}"); - Task.Delay(300).Wait(); ; -} -``` diff --git a/src/devices/Buzzer/samples/Buzzer.Samples.wiring.fzz b/src/devices/Buzzer/Buzzer.Samples.wiring.fzz similarity index 100% rename from src/devices/Buzzer/samples/Buzzer.Samples.wiring.fzz rename to src/devices/Buzzer/Buzzer.Samples.wiring.fzz diff --git a/src/devices/Buzzer/samples/Buzzer.Samples.wiring.png b/src/devices/Buzzer/Buzzer.Samples.wiring.png similarity index 100% rename from src/devices/Buzzer/samples/Buzzer.Samples.wiring.png rename to src/devices/Buzzer/Buzzer.Samples.wiring.png diff --git a/src/devices/Buzzer/README.md b/src/devices/Buzzer/README.md index ef74b3e2c8..42eb88de76 100644 --- a/src/devices/Buzzer/README.md +++ b/src/devices/Buzzer/README.md @@ -1,7 +1,5 @@ # Buzzer - Piezo Buzzer Controller -## Summary - This device binding allows playing certain tones using piezo buzzer. It uses PWM with 50% duty cycle and various frequencies. Piezo buzzers with three pins supported as well as piezo buzzers with two pins. @@ -10,7 +8,7 @@ Piezo buzzers with three pins supported as well as piezo buzzers with two pins. This binding was tested on two types of piezo buzzers. First type of buzzer has two pins *vcc* and *gnd*. Second type of buzzers has addition *signal* pin. -## Binding Notes +## Usage The `Buzzer` class can use either software or hardware PWM. This is done fully transparently by the initialization. @@ -21,14 +19,17 @@ To use the hardware PWM, make sure you reference correctly the chip and channel Also you could explicitly pass a PwmChannel if you want to construct that yourself. Here's an example how you could use `Buzzer`. + ```csharp using (Buzzer buzzer = new Buzzer(21)); // Initialize buzzer with software PWM connected to pin 21. { buzzer.PlayTone(440, 1000); // Play tone with frequency 440 hertz for one second. } ``` + `Buzzer` allows to play tone for certain duration like in example above. Or you could start tone playing, perform some operation and then stop tone playing like in a following example. + ```csharp using (Buzzer buzzer = new Buzzer(21)); { @@ -37,9 +38,11 @@ using (Buzzer buzzer = new Buzzer(21)); buzzer.StopPlaying(); } ``` + The result will be the same as in previous example. `Buzzer` allows you to play only single tone at a single moment. If you will call `SetFrequency` sequentially with a different frequencies then the last call will override previous calls. Following example explains it. + ```csharp using (Buzzer buzzer = new Buzzer(21)); // Initialize buzzer with software PWM connected to pin 21. { @@ -50,4 +53,83 @@ using (Buzzer buzzer = new Buzzer(21)); // Initialize buzzer with software PWM c buzzer.StopPlaying(); } ``` -This example will play tone with frequency 440 for a second and then will play tone with a frequency 880 for a second. \ No newline at end of file + +This example will play tone with frequency 440 for a second and then will play tone with a frequency 880 for a second. + +## Example of Alphabet song played using Buzzer + +### Schematic + +This sample demonstrates using two types of buzzers. +For buzzer with 3 pins: simply connect *signal* pin of buzzer to commutation pin (GPIO26), *vcc* pin to *+5v*, *gnd* pin to ground. For buzzer with 2 pins: connect *vcc* pin of buzzer to commutation pin (GPIO21) and *gnd* to ground. + +You could use any types of buzzers in any order. No changes to code are required. + +![schema](./Buzzer.Samples.wiring.png) + +### Code + +This sample contains a wrapper on a Buzzer called `MelodyPlayer`. + +#### MelodyPlayer and MelodyElement + +To create an instance of a MelodyPlayer use following line: + +```csharp +MelodyPlayer player = new MelodyPlayer(new Buzzer(26)); +``` + +Constructor takes a single parameter type of `Buzzer`. + +After initialization MelodyPlayer allows playing melody represented by sequence of `MelodyElement` objects. +MelodyElement is a base class for two types of elements: +* `NoteElement` - It will be played. So in a constructor it accepts `Note` and `Octave` to determine frequency of the sound and `Duration` to determine duration of the sound. +* `PauseElement` - It's supposed to make a pause between two NoteElements so it's only have duration of pause as constructor parameter. + + +#### How to use + +Following example demonstrates how to create MelodyElement sequence and how to play it using MelodyPlayer: + +```csharp +IList sequence = new List() +{ + new NoteElement(Note.C, Octave.Fourth, Duration.Quarter), + new PauseElement(Duration.Quarter), + new NoteElement(Note.C, Octave.Fourth, Duration.Quarter) +}; + +using (var player = new MelodyPlayer(new Buzzer(21))) +{ + player.Play(sequence, 100); +} +``` + +`Play` method MelodyPlayer accepts a sequence of MelodyElements as the first parameter and a tempo as the second. +Tempo is an amount of quarter notes per minute. So the more tempo is the quicker melody will be played. + +Also there is an overload of `MelodyPlayer.Play` with 3 parameters: MelodyElement sequence, tempo and transposition value. Transposition increases or decreases every tone of melody sequence by desired amount of semitones. For example: following line will decrease every tone of sequence by one octave since octave consists of 12 semitones. + +```csharp +player.Play(sequence, 100, -12); +``` + +#### Parallel buzzer playing + +As far as `MelodyPlayer.Play` method is not asynchronous, calls of this method are wrapped by task like this: + +```csharp +using (var player1 = new MelodyPlayer(new Buzzer(21))) +using (var player2 = new MelodyPlayer(new Buzzer(26))) +{ + Task.WaitAll( + Task.Run(() => player1.Play(AlphabetSong, 100, -12)), + Task.Run(() => player2.Play(AlphabetSong, 100))); +} +``` + +This approach allows playing two melodies independently however example above plays a single melody in the same time using two different buzzers. + +#### Alphabet song + +Presented sample plays Alphabet song using two buzzers. The song is hardcoded in a `Buzzer.Sample.cs` file as a sequence of MelodyElements. Read more about Alphabet song on [Wikipedia](https://en.wikipedia.org/wiki/Alphabet_song) \ No newline at end of file diff --git a/src/devices/Card/CreditCard/README.md b/src/devices/Card/CreditCard/README.md index d46ac723f8..e01ebcf46f 100644 --- a/src/devices/Card/CreditCard/README.md +++ b/src/devices/Card/CreditCard/README.md @@ -10,6 +10,16 @@ You will need a reader with an implementation of a WriteRead function from the c This class has been tested with various American Express, Visa and Mastercard, mainly from Europe. +## Documentation + +Some resources to understand how to communicate with a Credit Card and how to get the data out of it: + +- [The EMV tutorial](https://www.openscdp.org/scripts/tutorial/emv/index.html) from the OpenSCDP web site +- [A good list of EMV & NFC Tags](https://www.eftlab.co.uk/knowledge-base/145-emv-nfc-tags/) from EFTLab +- [A complete list of APDU response](https://www.eftlab.co.uk/knowledge-base/complete-list-of-apdu-responses/) from EFTLab +- [A simple TLV parser](https://www.emvlab.org/tlvutils/) from emvlab.org +- [Book with all the contact card specifications](https://www.emvco.com/emv-technologies/contact/) and [contactless](https://www.emvco.com/emv-technologies/contactless/) from EMVCo. Note that those are the official specifications. Main book used for this decoder is the contactless EMV 4.3 book 3. + ## Usage Here is a full example on how to read a Credit Card using a PN532. As mention above, the quality of your antenna and gain of the antenna may not allow you to read your card even if it's compatible. @@ -143,13 +153,3 @@ Note as well that a ```ToString()``` converter has been implemented. The functio ## Limitations This Credit Card class allows you to gather all the public information present into your credit card. The class does not implement fully all what is necessary to initiate a payment. Nothing prevent it as all the primary elements are present but you'll need to implement the Authentication. - -## Resources - -Some resources to understand how to communicate with a Credit Card and how to get the data out of it: - -- [The EMV tutorial](https://www.openscdp.org/scripts/tutorial/emv/index.html) from the OpenSCDP web site -- [A good list of EMV & NFC Tags](https://www.eftlab.co.uk/knowledge-base/145-emv-nfc-tags/) from EFTLab -- [A complete list of APDU response](https://www.eftlab.co.uk/knowledge-base/complete-list-of-apdu-responses/) from EFTLab -- [A simple TLV parser](https://www.emvlab.org/tlvutils/) from emvlab.org -- [Book with all the contact card specifications](https://www.emvco.com/emv-technologies/contact/) and [contactless](https://www.emvco.com/emv-technologies/contactless/) from EMVCo. Note that those are the official specifications. Main book used for this decoder is the contactless EMV 4.3 book 3. \ No newline at end of file diff --git a/src/devices/Card/Mifare/README.md b/src/devices/Card/Mifare/README.md index db0d0eab61..9e45b80ce1 100644 --- a/src/devices/Card/Mifare/README.md +++ b/src/devices/Card/Mifare/README.md @@ -2,7 +2,7 @@ This class supports Mifare cards. They are RFID cards responding to ISO 14443 type A. You need a specific card reader like PN532, PN5180 to read, write those kind of cards. -## Creating a card and reading it +## Usage You'll need first to get the card from an RFID reader. The example below shows how to do it with a PN532 and read all the sectors and print all the sector data information. diff --git a/src/devices/Card/Ndef/README.md b/src/devices/Card/Ndef/README.md index 6a6e18520d..475e3c1362 100644 --- a/src/devices/Card/Ndef/README.md +++ b/src/devices/Card/Ndef/README.md @@ -4,7 +4,7 @@ This library supports [NDEF messages](https://nfc-forum.org/product/nfc-data-exc NDEF messages are used on Mifare Cards and is included into this library as well. You have a full example using 2 different NFC readers [PN532](../../Pn532/README.md) and [PN1850](../../Pn1850/README.md) build in. -## Reading NDEF from a card +## Usage This operation only require a valid NFC reader which implement `CardTransceiver`, see [the class](../CardTransceiver.cs). @@ -124,7 +124,7 @@ foreach (var msg in message.Records) } ``` -## Writing NDEF to a card +### Writing NDEF to a card From the previous example, you will still need to get a card. From there, to create and write messages, it's quite straight forward: @@ -160,7 +160,7 @@ mifareCard.KeyB = new byte[6] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; var res = mifareCard.WriteNdefMessage(message, false); ``` -## Format a card to NDEF +### Format a card to NDEF You can format a card, this will be done using Key B, by default it will use the Default Key B. You can pass as well the Key B in the parameters. @@ -170,7 +170,7 @@ string msg = ret ? "Formatting successful." : "Error formatting card."; Console.WriteLine(msg); ``` -## Check if the card is NDEF formatted +### Check if the card is NDEF formatted You can as well check is properly NDEF formatted: @@ -182,4 +182,4 @@ Console.WriteLine($"This card is{isForm} NDEF formatted"); ## Card type supported -NDEF per se is fully independent of cards, so the class can be used independently. A Mifare implementation has been done. All Mifare 1K, 2K and 4K are supported. The Mifare 300 are not. +NDEF per se is fully independent of cards, so the class can be used independently. A [Mifare implementation](../Mifare) has been done. All Mifare 1K, 2K and 4K are supported. The Mifare 300 are not. Also all [Ultralight cards](../Utralight) are supported as well. diff --git a/src/devices/Card/Ultralight/README.md b/src/devices/Card/Ultralight/README.md index d229e6a3e9..6fffdc6693 100644 --- a/src/devices/Card/Ultralight/README.md +++ b/src/devices/Card/Ultralight/README.md @@ -2,7 +2,7 @@ This class supports Ultralight cards. They are RFID cards responding to ISO 14443 type A. You need a specific card reader like PN532, PN5180 or MFRC522 to read, write those kind of cards. -## Creating a card and reading it +## Usage You will find detailed examples for PN532 [here](../../Pn532/samples), for MFRC522 [here](../../Mfrc522/samples) and for PN5180 [here](../../Pn5180/samples). diff --git a/src/devices/Ccs811/README.md b/src/devices/Ccs811/README.md index 8f54e06bba..c79c7edb50 100644 --- a/src/devices/Ccs811/README.md +++ b/src/devices/Ccs811/README.md @@ -1,13 +1,12 @@ # CCS811 Gas sensor -## Summary - CCS811 is an ultra-low power digital gas sensor solution for monitoring indoor air quality. CCS811 integrates a gas sensor solution for detecting low levels of Volatile Organic Compounds typically found indoors, with a microcontroller unit (MCU) and an Analog-to-Digital converter to monitor the local environment and provide an indication of the indoor air quality via an equivalent CO2 or Total Volatile Organic Compounds output over a standard I2C digital interface. -## Device family +## Documentation -This device can be found in multiple places like the [Adafruit](https://www.adafruit.com/product/3566) or [Sparkfun](https://www.sparkfun.com/products/14193) and a lot of different implementations on sites like [Banggood](https://www.banggood.com/search/ccs811.html?from=nav). +- This device can be found in multiple places like the [Adafruit](https://www.adafruit.com/product/3566) or [Sparkfun](https://www.sparkfun.com/products/14193) and a lot of different implementations on sites like [Banggood](https://www.banggood.com/search/ccs811.html?from=nav). +- Device [documentation](https://www.sciosense.com/products/environmental-sensors/ccs811-gas-sensor-solution/) ## Device information @@ -22,7 +21,7 @@ CCS811 exposes 3 pins, here is a short information on every one: - The Address pins allows you to select the first of second I2C address. Place it to the ground to select the first one (0x5A) or to VCC to select the second one (0x5B). - The Reset pin is sometime present. If present and you want to use it, this will perform a full hard reset. - The Wake pin is used to select the chip and wake it up. If you don't want to use it, just put it to the ground. -- The Interupt pin allows interruption, if used, the interupt mode and events will be activated. This needs to be activated to be able to use the embedded Threshold feature. +- The Interrupt pin allows interruption, if used, the interrupt mode and events will be activated. This needs to be activated to be able to use the embedded Threshold feature. Understanding the measurement: @@ -77,7 +76,7 @@ sudo reboot ## Usage -You'll find below how to use the sensor. A full example covering in details all the usage can be found in the [samples directory](./samples). +You'll find below how to use the sensor. A full example covering in details all the usage can be found in the [samples directory](https://github.com/dotnet/iot/tree/main/src/devices/Ccs811/samples). ### Create the device @@ -165,7 +164,7 @@ private static void Ccs811MeasurementReady(object sender, MeasurementThresholdAr ### Setting a threshold -This feature is only available if the interruption pin is used. Events needs to be activated as well. This is an example of setting up a threadhold between 400 and 600 ppm for the eCO2. Note that the threshold needs to have at least 50 of difference between the minimum and maximum values. +This feature is only available if the interruption pin is used. Events needs to be activated as well. This is an example of setting up a threshold between 400 and 600 ppm for the eCO2. Note that the threshold needs to have at least 50 of difference between the minimum and maximum values. ```csharp ccs811.MeasurementReady += Ccs811MeasurementReady; @@ -196,6 +195,36 @@ ccs811.BaselineAlgorithmCalculation = baseline; Console.WriteLine($"Baseline calculation value: {ccs811.BaselineAlgorithmCalculation}"); ``` -## References +## CCS811 Samples + +This [sample application](https://github.com/dotnet/iot/tree/main/src/devices/Ccs811/samples) contains flow and menus allowing you to test easily all the feature of the CSS811 and also show how to implement properly all readings. + +You can test it thru: + +- A native platform like a Raspberry PI +- A chip set providing GPIO and I2C like the FT4222 + +You can use the native GPIO support for the following pins or not: + +- The address pin is used to select primary (0x5A) or secondary (0x5B) I2C device address. +- The Reset pin is sometime present or not. If present and you want to use it, this will perform a full hard reset. +- The Wake pin is used to select the chip and wake it up. If you don't want to use it, just put it to the ground. +- The Interrupt pin allows interruption, if used, the interrupt mode and events will be activated. This needs to be activated to be able to use the embedded Threshold feature. + +You can select any of the mode. + +A variety of tests and reading, including changing the temperature and humidity correction is proposed. + +You can log the date an nicely import them later on in Excel. The following example shows a measurement over time. In blue, the equivalent CO2 in ppm and in orange the equivalent TVOC in ppb. Note that the measurement started to be accurate around 11:35 on this graph. + +![Graph](graph.png) + +### Sample wiring + +**Important** + +In order to have this sensor working on a Raspberry Pi, you need to lower the bus speed. This sensor uses a mode called I2C stretching and it is not supported natively on Raspberry Pi. So you **must** lower the I2C clock to the minimum to make it working properly or use a software I2C with a low clock as well. See the section above. + +This example uses the software I2C with GPIO 17 and 27 as explained in the previous section on a Raspberry Pi, Wake pin on GPIO 23 and Interrupt on GPIO 22. -- Device documentation: https://www.sciosense.com/products/environmental-sensors/ccs811-gas-sensor-solution/ +![Wiring sample](ccs811_bb.png) \ No newline at end of file diff --git a/src/devices/Ccs811/samples/ccs811.fzz b/src/devices/Ccs811/ccs811.fzz similarity index 100% rename from src/devices/Ccs811/samples/ccs811.fzz rename to src/devices/Ccs811/ccs811.fzz diff --git a/src/devices/Ccs811/samples/ccs811_bb.png b/src/devices/Ccs811/ccs811_bb.png similarity index 100% rename from src/devices/Ccs811/samples/ccs811_bb.png rename to src/devices/Ccs811/ccs811_bb.png diff --git a/src/devices/Ccs811/samples/graph.png b/src/devices/Ccs811/graph.png similarity index 100% rename from src/devices/Ccs811/samples/graph.png rename to src/devices/Ccs811/graph.png diff --git a/src/devices/Ccs811/samples/README.md b/src/devices/Ccs811/samples/README.md deleted file mode 100644 index 64322106d0..0000000000 --- a/src/devices/Ccs811/samples/README.md +++ /dev/null @@ -1,75 +0,0 @@ -# CCS811 Samples - -This sample applicaiton contains flow and menus allowing you to test easilly all the feature of the CSS811 and also show how to implement properly all readings. - -You can test it thru: - -- A native platform like a Raspberry PI -- A chip set providing GPIO and I2C like the FT4222 - -You can use the native GPIO support for the following pins or not: - -- The address pin is used to select primary (0x5A) or secondary (0x5B) I2C device address. -- The Reset pin is sometime present or not. If present and you want to use it, this will perform a full hard reset. -- The Wake pin is used to select the chip and wake it up. If you don't want to use it, just put it to the ground. -- The Interupt pin allows interruption, if used, the interupt mode and events will be activated. This needs to be activated to be able to use the embedded Threshold feature. - -You can select any of the mode. - -A variety of tests and reading, including changing the temperature and humidity correction is proposed. - -You can log the date an nicely import them later on in Excel. The following example shows a measurement over time. In blue, the equivalent CO2 in ppm and in orange the equivalent TVOC in ppb. Note that the measurement started to be accurate around 11:35 on this graph. - -![Graph](graph.png) - -# Sample wiring - -**Important** - -In order to have this sensor working on a Raspberry Pi, you need to lower the bus speed. This sensor uses a mode called I2C stretching and it is not supported natively on Raspberry Pi. So you **must** lower the I2C clock to the minimum to make it working properly or use a software I2C with a low clock as well. - -In order to do so, open a ssh session with your Raspberry and edit the /boot/config.txt file: - -```bash -sudo nano /boot/config.txt -``` - -## Lowering the hardware I2C clock - -Locate the line where you have ```dtparam=i2c_arm=on```, make sure you'll remove any # which can be in front and add ```,i2c_arm_baudrate=10000``` so the line will now bocome: ```dtparam=i2c_arm=on,i2c_arm_baudrate=10000``` - -Reboot: - -```bash -sudo reboot -``` - -*Notes* - -- This has an impact on the all bus! So if you are using other sensors, this will decrease the speed of all other sensors. -- Even with the bus speed reduced, you may have issues. - -## Activating the Sofware I2C - -Add the following line to use GPIO 17 for SCA and GPIO 27 for SCL: - -``` -dtoverlay=i2c-gpio,i2c_gpio_sda=17,i2c_gpio_scl=27,bus=3,i2c_gpio_delay_us=20 -``` - -You can of course adjust the GPIO you want to use. The delay os 20 micro seconds correspond to about 10000 Hz. - -Reboot: - -```bash -sudo reboot -``` - -*Notes* - -- This uses 2 extra GPIO -- This is the best solution especially if you are using extra I2C devices - -This example uses the sofware I2C with GPIO 17 and 27 as explained in the previous section on a Raspberry Pi, Wake pin on GPIO 23 and Interrupt on GPIO 22. - -![Wiring sample](ccs811_bb.png) \ No newline at end of file diff --git a/src/devices/CharacterLcd/README.md b/src/devices/CharacterLcd/README.md index 1733d443aa..b6ddeedd0d 100644 --- a/src/devices/CharacterLcd/README.md +++ b/src/devices/CharacterLcd/README.md @@ -1,18 +1,19 @@ # Character LCD (Liquid Crystal Display) -## Summary - This device binding is meant to work with character LCD displays which use a HD44780 compatible controller. Almost all character LCDs fall into this category. Simple wrappers for 16x2 and 20x4 variants are included. Please make sure you are using the [latest Bindings nuget](https://github.com/dotnet/iot#how-to-install). -## Device Family +## Documentation -This binding has been tested with a variety of 16x2 and 20x4 displays both in 4bit and 8bit mode and via i2C adapters (such as on the CrowPi). It should work with any character LCD with a 5x8 size character. Common names are 1602LCD and 2004LCD. +This binding has been tested with a variety of 16x2 and 20x4 displays both in 4bit and 8bit mode and via i2C adapters (such as on the CrowPi). It should work with any character LCD with a 5x8 size character. Common names are 1602LCD and 2004LCD. Also supports [Grove - LCD RGB Backlight](http://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/). -Also supports [Grove - LCD RGB Backlight](http://wiki.seeedstudio.com/Grove-LCD_RGB_Backlight/). +- [Very complete tutorial]https://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/overview() on how to connect and work with one of these displays. +- [Good guide](http://www.site2241.net/november2014.htm) explaining how the device works internally +- Seeedstudio, Grove - [LCD RGB Backlight library](https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight) +- [PCF8574T information](https://alselectro.wordpress.com/2016/05/12/serial-lcd-i2c-module-pcf8574/) -## Binding Notes +## Usage These devices are controlled purely by GPIO (except Grove LCD RGB Backlight). There are two different types of GPIO pins that are used, the control pins, and the data pins. The data pins are the ones that will send out the text that should be printed out on the LCD screen. This binding supports two different configurations for the data pins: using 4 data pins, and using 8 data pins. When using only 4 data pins, we will require two send two messages to the controller, each sending half of the byte that should be printed. @@ -55,9 +56,32 @@ var lcd = new Lcd1602(registerSelectPin: 0, enablePin: 2, dataPins: new int[] { there is a full working example in the samples directory called Pcf8574tSample.cs For PCF8574T i2c addresses can be between 0x27 and 0x20 depending on bridged solder jumpers and for PCF8574AT i2c addresses can be between 0x3f and 0x38 depending on bridged solder jumpers -## References +## Character LCD display Samples + +[Different samples](https://github.com/dotnet/iot/tree/main/src/devices/CharacterLcd/samples) are provided. The main method will use the Board's Gpio pins to drive the LCD display. The second example will instead use an MCP Gpio extender backpack to drive the LCD display. Also the second example can use Grove RGB LCD Backlight via i2c bus. This second example has been tested on a CrowPi device and Grove LCD RGB Backlight device. + +### Build configuration + +Please build the samples project with configuration key depending on connected devices: + +- For GPIO connection you don't have to use any configuration keys. Example: + +```shell +dotnet publish -o C:\DeviceApiTester -r linux-arm +``` + +- For MCP GPIO extender backpack please use *USEI2C* key. Example: + +```shell +dotnet publish -c USEI2C -o C:\DeviceApiTester -r linux-arm +``` + +- For Grove RGB LCD Backlight please use *USERGB* key. Example: + +```shell +dotnet publish -c USERGB -o C:\DeviceApiTester -r linux-arm +``` + +### Sample wiring -- Very complete tutorial on how to connect and work with one of these displays: https://learn.adafruit.com/drive-a-16x2-lcd-directly-with-a-raspberry-pi/overview -- Good guide explaining how the device works internally: http://www.site2241.net/november2014.htm -- Seeedstudio, Grove - LCD RGB Backlight library: https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight -- PCF8574T information https://alselectro.wordpress.com/2016/05/12/serial-lcd-i2c-module-pcf8574/ +![wiring](lcmWiringExample.jpg) diff --git a/src/devices/CharacterLcd/samples/lcmWiringExample.jpg b/src/devices/CharacterLcd/lcmWiringExample.jpg similarity index 100% rename from src/devices/CharacterLcd/samples/lcmWiringExample.jpg rename to src/devices/CharacterLcd/lcmWiringExample.jpg diff --git a/src/devices/CharacterLcd/samples/README.md b/src/devices/CharacterLcd/samples/README.md deleted file mode 100644 index ea0bb80f82..0000000000 --- a/src/devices/CharacterLcd/samples/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Character LCD display Samples - -Two different samples are provided. The main method will use the Board's Gpio pins to drive the LCD display. The second example will instead use an MCP Gpio extender backpack to drive the LCD display. Also the second example can use Grove RGB LCD Backlight via i2c bus. This second example has been tested on a CrowPi device and Grove LCD RGB Backlight device. - -### Build configuration - -Please build the samples project with configuration key depending on connected devices: - -- For GPIO connection you don't have to use any configuration keys. Example: - -``` -dotnet publish -o C:\DeviceApiTester -r linux-arm -``` - -- For MCP GPIO extender backpack please use *USEI2C* key. Example: - -``` -dotnet publish -c USEI2C -o C:\DeviceApiTester -r linux-arm -``` - -- For Grove RGB LCD Backlight please use *USERGB* key. Example: - -``` -dotnet publish -c USERGB -o C:\DeviceApiTester -r linux-arm -``` - -### Sample wiring - -![](lcmWiringExample.jpg) diff --git a/src/devices/Charlieplex/samples/README.md b/src/devices/Charlieplex/samples/README.md deleted file mode 100644 index 633e1f06a8..0000000000 --- a/src/devices/Charlieplex/samples/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Charlieplexing -- test application - -This [test application](Program.cs) tests the [Charieplexing binding](../README.md). - -The test app can be modified to support any number of LEDs or other load. diff --git a/src/devices/CpuTemperature/README.md b/src/devices/CpuTemperature/README.md index 645c5bf130..f9eeca937b 100755 --- a/src/devices/CpuTemperature/README.md +++ b/src/devices/CpuTemperature/README.md @@ -1,14 +1,44 @@ # Cpu Temperature -Device bindings for the CPU Temperature Sensor +Device bindings for the CPU Temperature Sensor. Returns the current temperature of the CPU Temperature Sensor. Useful telemetry in its own right, but also useful for calibrating the Raspberry Pi Sense HAT. -## Summary - -Returns the current temperature of the CPU Temperature Sensor. Useful telemetry in its own right, but also useful for calibrating the Raspberry Pi Sense HAT. - -## Binding Notes +## Usage On Windows, this tries to use the OpenHardwareMonitor binding (see there for details). If it is not available, some guesswork is done to get a temperature sensor. However, the temperature returned by this binding may not be the actual CPU temperature, but one of the mainboard sensors instead. Therefore, depending on the mainboard, no data may be available. Unless OpenHardwareMonitor can be used, elevated permissions ("Admin rights") are required. -## References +```csharp +sing System; +using System.Threading; +using Iot.Device.CpuTemperature; + +CpuTemperature cpuTemperature = new CpuTemperature(); +Console.WriteLine("Press any key to quit"); + +while (!Console.KeyAvailable) +{ + if (cpuTemperature.IsAvailable) + { + var temperature = cpuTemperature.ReadTemperatures(); + foreach (var entry in temperature) + { + if (!double.IsNaN(entry.Temperature.DegreesCelsius)) + { + Console.WriteLine($"Temperature from {entry.Sensor.ToString()}: {entry.Temperature.DegreesCelsius} °C"); + } + else + { + Console.WriteLine("Unable to read Temperature."); + } + } + } + else + { + Console.WriteLine($"CPU temperature is not available"); + } + + Thread.Sleep(1000); +} + +cpuTemperature.Dispose(); +``` diff --git a/src/devices/DCMotor/samples/DCMotor2pinWithBiDirectionalPin.fzz b/src/devices/DCMotor/DCMotor2pinWithBiDirectionalPin.fzz similarity index 100% rename from src/devices/DCMotor/samples/DCMotor2pinWithBiDirectionalPin.fzz rename to src/devices/DCMotor/DCMotor2pinWithBiDirectionalPin.fzz diff --git a/src/devices/DCMotor/samples/DCMotor2pinWithBiDirectionalPin_bb.png b/src/devices/DCMotor/DCMotor2pinWithBiDirectionalPin_bb.png similarity index 100% rename from src/devices/DCMotor/samples/DCMotor2pinWithBiDirectionalPin_bb.png rename to src/devices/DCMotor/DCMotor2pinWithBiDirectionalPin_bb.png diff --git a/src/devices/DCMotor/README.md b/src/devices/DCMotor/README.md index 4621348e20..39ccc01ece 100644 --- a/src/devices/DCMotor/README.md +++ b/src/devices/DCMotor/README.md @@ -1,7 +1,5 @@ # DC Motor Controller -## Summary - This is a generic class to control any DC motor. DC motors are controlled by simply providing voltage on the inputs (inverted voltage inverts the direction). @@ -15,4 +13,64 @@ Please refer to the [sample](samples/README.md) to see how to connect it. 2/1-pin mode should be used only if H-bridge allows the inputs to be changed frequently otherwise excessive heat or damage may occur which may reduce life-time of the H-bridge. -It may also cause increased energy consumption due to energy being converted into heat. \ No newline at end of file +It may also cause increased energy consumption due to energy being converted into heat. + +## Usage + +[See full sample](Program.cs) for more details. + +```csharp +static void Main(string[] args) +{ + const double Period = 10.0; + Stopwatch sw = Stopwatch.StartNew(); + // 1 pin mode + // using (DCMotor motor = DCMotor.Create(6)) + // using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 0, frequency: 50))) + // 2 pin mode + // using (DCMotor motor = DCMotor.Create(27, 22)) + // using (DCMotor motor = DCMotor.Create(new SoftwarePwmChannel(27, frequency: 50), 22)) + // 2 pin mode with BiDirectional Pin + // using (DCMotor motor = DCMotor.Create(19, 26, null, true, true)) + // using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 1, 100, 0.0), 26, null, true, true)) + // 3 pin mode + // using (DCMotor motor = DCMotor.Create(PwmChannel.Create(0, 0, frequency: 50), 23, 24)) + // Start Stop mode - wrapper with additional methods to disable/enable output regardless of the Speed value + // using (DCMotorWithStartStop motor = new DCMotorWithStartStop(DCMotor.Create( _any version above_ ))) + using (DCMotor motor = DCMotor.Create(6, 27, 22)) + { + bool done = false; + Console.CancelKeyPress += (o, e) => + { + done = true; + e.Cancel = true; + }; + + string lastSpeedDisp = null; + while (!done) + { + double time = sw.ElapsedMilliseconds / 1000.0; + + // Note: range is from -1 .. 1 (for 1 pin setup 0 .. 1) + motor.Speed = Math.Sin(2.0 * Math.PI * time / Period); + string disp = $"Speed = {motor.Speed:0.00}"; + if (disp != lastSpeedDisp) + { + lastSpeedDisp = disp; + Console.WriteLine(disp); + } + + Thread.Sleep(1); + } + } +} +``` + +![schematics](dcmotor_bb.png) + +![BiDirectional Pin schematics](DCMotor2pinWithBiDirectionalPin_bb.png) + +Additional elements: + +- [Fritzing diagram](dcmotor.fzz) +- [BiDirectional Pin Fritzing diagram](DCMotor2pinWithBiDirectionalPin.fzz) \ No newline at end of file diff --git a/src/devices/DCMotor/samples/dcmotor.fzz b/src/devices/DCMotor/dcmotor.fzz similarity index 100% rename from src/devices/DCMotor/samples/dcmotor.fzz rename to src/devices/DCMotor/dcmotor.fzz diff --git a/src/devices/DCMotor/samples/dcmotor_bb.png b/src/devices/DCMotor/dcmotor_bb.png similarity index 100% rename from src/devices/DCMotor/samples/dcmotor_bb.png rename to src/devices/DCMotor/dcmotor_bb.png diff --git a/src/devices/Dhtxx/samples/DHT12_circuit.fzz b/src/devices/Dhtxx/DHT12_circuit.fzz similarity index 100% rename from src/devices/Dhtxx/samples/DHT12_circuit.fzz rename to src/devices/Dhtxx/DHT12_circuit.fzz diff --git a/src/devices/Dhtxx/samples/DHT12_circuit_bb.png b/src/devices/Dhtxx/DHT12_circuit_bb.png similarity index 100% rename from src/devices/Dhtxx/samples/DHT12_circuit_bb.png rename to src/devices/Dhtxx/DHT12_circuit_bb.png diff --git a/src/devices/Dhtxx/README.md b/src/devices/Dhtxx/README.md index 50e217967d..4458b6d16f 100644 --- a/src/devices/Dhtxx/README.md +++ b/src/devices/Dhtxx/README.md @@ -2,7 +2,7 @@ The DHT temperature and humidity sensors are very popular. This projects support DHT10, DHT11, DHT12, DHT21(AM2301), DHT22(AM2302). -## Comparison +## Documentation | | DHT10 | DHT11 | DHT12 | DHT21 | DHT22 | | :------: | :------: | :------: | :------: | :------: | :------: | @@ -13,6 +13,12 @@ The DHT temperature and humidity sensors are very popular. This projects support | Humidity Accuracy | ±3 % | ±5 % | ±4 % | ±3 % | ±2 % | | Protocol | I2C | 1-Wire | I2C, 1-Wire | 1-Wire | 1-Wire | +* **DHT10** [datasheet (Currently only Chinese)](http://www.aosong.com/userfiles/files/media/DHT10%E8%A7%84%E6%A0%BC%E4%B9%A6.pdf) +* **DHT11** [datasheet](https://cdn.datasheetspdf.com/pdf-down/D/H/T/DHT11-Aosong.pdf) +* **DHT12** [datasheet](https://cdn.datasheetspdf.com/pdf-down/D/H/T/DHT12-Aosong.pdf) +* **DHT21** [datasheet](https://cdn.datasheetspdf.com/pdf-down/A/M/2/AM2301-Aosong.pdf) +* **DHT22** [datasheet](https://cdn-shop.adafruit.com/datasheets/DHT22.pdf) + ## Usage ### 1-Wire Protocol @@ -133,10 +139,89 @@ On the RPi with any of the DHT sensor, 1-Wire works using Raspian but not with W Now if your sensor is an I2C sensor, it should just work perfectly on Windows 10 IoT Core. -## References +## Example of DHTxx + +### Hardware Required + +* DHT10/DHT11/DHT12/DHT21/DHT22 +* Male/Female Jumper Wires + +### Circuit + +#### 1-Wire Protocol + +Simply connect your DHTxx data pin to GPIO26 (physical pin 37), the ground to the ground (physical pin 6) and the VCC to +5V (physical pin 2). + +![schema](./dht22.png) + +Some sensors are already sold with the 10K resistor. Connect the GPIO26 to the *data* pin, its position can vary depending on the integrator. + +#### I2C Protocol + +![schematics](DHT12_circuit_bb.png) + +* SCL - SCL +* SDA - SDA +* VCC - 5V +* GND - GND + +### Code + +```csharp +// GPIO Pin +using (Dht11 dht = new Dht11(26)) +{ + var temperature = dht.Temperature; + var humidity = dht.Humidity; + // You can only display temperature and humidity if the read is successful otherwise, this will raise an exception as + // both temperature and humidity are NAN + if (dht.IsLastReadSuccessful) + { + Console.WriteLine($"Temperature: {temperature.DegreesCelsius} \u00B0C, Humidity: {humidity.Percent} %"); + + // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. + Console.WriteLine( + $"Heat index: {WeatherHelper.CalculateHeatIndex(temperature, humidity).Celsius:0.#}\u00B0C"); + Console.WriteLine( + $"Dew point: {WeatherHelper.CalculateDewPoint(temperature, humidity).Celsius:0.#}\u00B0C"); + } + else + { + Console.WriteLine("Error reading DHT sensor"); + } +} +``` + +### Sample application navigation + +This sample application allows you to select either a DHT10 through I2C either any other supported DHT through GPIO: + +```text +Select the DHT sensor you want to use: + 1. DHT10 on I2C + 2. DHT11 on GPIO + 3. DHT12 on GPIO + 4. DHT21 on GPIO + 5. DHT22 on GPIO +``` + +Just select the sensor you want to test and use by typing the number. For example, if you want to test a DHT22, type 5. + +Then, you are prompted to type the pin number in the logical schema: + +```text +Which pin do you want to use in the logical pin schema? +``` + +If you want to use the pin 26, then type 26 and enter. This will then create a DHT22 sensor attached to pin 26 and start the measurement. + +Please note that the few first measurements won't be correct, that's totally normal and related to the fact the sensor needs a bit of time to warm up and give data. Those sensors are very sensitive and too long wires, many perturbations, code compile as debug will increase the numbers of bad readings. + + +### Result + +![dht22 output](./dht22ex.jpg) + +Note: reading this sensor is sensitive, if you can't read anything, make sure you have it correctly cabled. Also note you'll get better results when running in ```Release``` mode. + -* **DHT10** [datasheet (Currently only Chinese)](http://www.aosong.com/userfiles/files/media/DHT10%E8%A7%84%E6%A0%BC%E4%B9%A6.pdf) -* **DHT11** [datasheet](https://cdn.datasheetspdf.com/pdf-down/D/H/T/DHT11-Aosong.pdf) -* **DHT12** [datasheet](https://cdn.datasheetspdf.com/pdf-down/D/H/T/DHT12-Aosong.pdf) -* **DHT21** [datasheet](https://cdn.datasheetspdf.com/pdf-down/A/M/2/AM2301-Aosong.pdf) -* **DHT22** [datasheet](https://cdn-shop.adafruit.com/datasheets/DHT22.pdf) diff --git a/src/devices/Dhtxx/samples/dht22.fzz b/src/devices/Dhtxx/dht22.fzz similarity index 100% rename from src/devices/Dhtxx/samples/dht22.fzz rename to src/devices/Dhtxx/dht22.fzz diff --git a/src/devices/Dhtxx/samples/dht22.png b/src/devices/Dhtxx/dht22.png similarity index 100% rename from src/devices/Dhtxx/samples/dht22.png rename to src/devices/Dhtxx/dht22.png diff --git a/src/devices/Dhtxx/samples/dht22ex.jpg b/src/devices/Dhtxx/dht22ex.jpg similarity index 100% rename from src/devices/Dhtxx/samples/dht22ex.jpg rename to src/devices/Dhtxx/dht22ex.jpg diff --git a/src/devices/Dhtxx/samples/README.md b/src/devices/Dhtxx/samples/README.md deleted file mode 100644 index 59bf4a6780..0000000000 --- a/src/devices/Dhtxx/samples/README.md +++ /dev/null @@ -1,86 +0,0 @@ -# Example of DHTxx - -## Hardware Required - -* DHT10/DHT11/DHT12/DHT21/DHT22 -* Male/Female Jumper Wires - -## Circuit - -### 1-Wire Protocol - -Simply connect your DHTxx data pin to GPIO26 (physical pin 37), the ground to the ground (physical pin 6) and the VCC to +5V (physical pin 2). - -![schema](./dht22.png) - -Some sensors are already sold with the 10K resistor. Connect the GPIO26 to the *data* pin, its position can vary depending on the integrator. - -### I2C Protocol - -![](DHT12_circuit_bb.png) - -* SCL - SCL -* SDA - SDA -* VCC - 5V -* GND - GND - -## Code - -```csharp -// GPIO Pin -using (Dht11 dht = new Dht11(26)) -{ - var temperature = dht.Temperature; - var humidity = dht.Humidity; - // You can only display temperature and humidity if the read is successful otherwise, this will raise an exception as - // both temperature and humidity are NAN - if (dht.IsLastReadSuccessful) - { - Console.WriteLine($"Temperature: {temperature.DegreesCelsius} \u00B0C, Humidity: {humidity.Percent} %"); - - // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. - Console.WriteLine( - $"Heat index: {WeatherHelper.CalculateHeatIndex(temperature, humidity).Celsius:0.#}\u00B0C"); - Console.WriteLine( - $"Dew point: {WeatherHelper.CalculateDewPoint(temperature, humidity).Celsius:0.#}\u00B0C"); - } - else - { - Console.WriteLine("Error reading DHT sensor"); - } -} -``` - -## Sample application navigation - -This sample application allows you to select either a DHT10 through I2C either any other supported DHT through GPIO: - -``` -Select the DHT sensor you want to use: - 1. DHT10 on I2C - 2. DHT11 on GPIO - 3. DHT12 on GPIO - 4. DHT21 on GPIO - 5. DHT22 on GPIO -``` - -Just select the sensor you want to test and use by typing the number. For example, if you want to test a DHT22, type 5. - -Then, you are prompted to type the pin number in the logical schema: - -``` -Which pin do you want to use in the logical pin schema? -``` - -If you want to use the pin 26, then type 26 and enter. This will then create a DHT22 sensor attached to pin 26 and start the measurement. - -Please note that the few first measurements won't be correct, that's totally normal and related to the fact the sensor needs a bit of time to warm up and give data. Those sensors are very sensitive and too long wires, many perturbations, code compile as debug will increase the numbers of bad readings. - - -## Result - -![dht22 output](./dht22ex.jpg) - -Note: reading this sensor is sensitive, if you can't read anything, make sure you have it correctly cabled. Also note you'll get better results when running in ```Release``` mode. - - diff --git a/src/devices/Display/README.md b/src/devices/Display/README.md index c081879920..f7e5f68962 100644 --- a/src/devices/Display/README.md +++ b/src/devices/Display/README.md @@ -2,21 +2,18 @@ This project contains multipurpose LED display drivers and binding implementations for concrete display configurations. -## Device family +## Documentation The **HT16K33** is LED display driver that supports multiple LED configurations and I2C communication. Adafruit sells multiple display backpacks built upon this driver: -[Adafruit LED / SEGMENTED category](https://www.adafruit.com/category/103) - -**Large4Digit7SegmentDisplay** is a binding that supports the **Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack** that comes in 3 colors: - -[Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Yellow](https://www.adafruit.com/product/1268) - -[Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Green](https://www.adafruit.com/product/1269) - -[Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red](https://www.adafruit.com/product/1270) +- [Adafruit LED / SEGMENTED category](https://www.adafruit.com/category/103) +- **Large4Digit7SegmentDisplay** is a binding that supports the **Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack** that comes in 3 colors: +- [Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Yellow](https://www.adafruit.com/product/1268) +- [Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Green](https://www.adafruit.com/product/1269) +- [Adafruit 1.2" 4-Digit 7-Segment Display w/I2C Backpack - Red](https://www.adafruit.com/product/1270) +- [HT16K33 datasheet](https://cdn-shop.adafruit.com/datasheets/ht16K33v110.pdf) More information on wiring can be found on the respective product pages. @@ -38,7 +35,7 @@ Thread.Sleep(5000); // Turn on buffering display.BufferingEnabled = true; -// Write -42°C to display using "decimal point" between 3rd and 4th digit as the ° character +// Write -42°C to display using "decimal point" between 3rd and 4th digit as the ° character display.Write("-42C"); display.Dots = Dot.DecimalPoint; @@ -48,7 +45,3 @@ display.Flush(); // Dispose display object (the device itself will not be turned off until powered down) display.Dispose(); ``` - -## Documentation - -[HT16K33 datasheet](https://cdn-shop.adafruit.com/datasheets/ht16K33v110.pdf) diff --git a/src/devices/ExplorerHat/README.md b/src/devices/ExplorerHat/README.md index 8ec0365661..9afab481d1 100644 --- a/src/devices/ExplorerHat/README.md +++ b/src/devices/ExplorerHat/README.md @@ -1,9 +1,12 @@ # Explorer HAT Pro (Pimoroni) -## Summary - [Explorer HAT Pro](https://shop.pimoroni.com/products/explorer-hat) is an add-on board for Raspberry Pi. +## Documentation + +* [Explorer HAT Technical Reference](https://github.com/pimoroni/explorer-hat/blob/master/documentation/Technical-reference.md) + + ![Explorer HAT Pro](https://user-images.githubusercontent.com/10654401/63101233-e88c4b80-bf78-11e9-87ff-20e7a2809c40.png) It consists of multiple devices. Currently supported devices: @@ -15,6 +18,110 @@ It consists of multiple devices. Currently supported devices: Capacitive touchpad, inputs, outputs, and 3.3v breakout not supported... Working on them. -## References +## Usage -* [Explorer HAT Technical Reference](https://github.com/pimoroni/explorer-hat/blob/master/documentation/Technical-reference.md) +Hat initialization: + +```csharp +using (var hat = new ExplorerHat()) +{ + // Your code here +} +``` + +### Leds + +```csharp +// All lights on +hat.Lights.On(); +Thread.Sleep(1000); +// All lights off +hat.Lights.Off(); +Thread.Sleep(500); + +// By color +hat.Lights.Blue.On(); +Thread.Sleep(1000); +hat.Lights.Blue.Off(); +Thread.Sleep(500); +hat.Lights.Yellow.On(); +Thread.Sleep(1000); +hat.Lights.Yellow.Off(); +Thread.Sleep(500); +hat.Lights.Red.On(); +Thread.Sleep(1000); +hat.Lights.Red.Off(); +Thread.Sleep(500); +hat.Lights.Green.On(); +Thread.Sleep(1000); +hat.Lights.Green.Off(); +Thread.Sleep(500); + +// By number +hat.Lights.One.On(); +Thread.Sleep(1000); +hat.Lights.One.Off(); +Thread.Sleep(500); +hat.Lights.Two.On(); +Thread.Sleep(1000); +hat.Lights.Two.Off(); +Thread.Sleep(500); +hat.Lights.Three.On(); +Thread.Sleep(1000); +hat.Lights.Three.Off(); +Thread.Sleep(500); +hat.Lights.Four.On(); +Thread.Sleep(1000); +hat.Lights.Four.Off(); +Thread.Sleep(500); + +// Iterate through led array +int i = 0; +foreach (var led in hat.Lights) +{ + i++; + Console.WriteLine($"Led #{i} is {(led.IsOn ? "ON" : "OFF")}"); +} +``` + +### Motors + +```csharp +// Forwards full speed +hat.Motors.Forwards(1); +Thread.Sleep(2000); + +// Backwards full speed +hat.Motors.Backwards(1); +Thread.Sleep(2000); + +// Manage one motor at a time +hat.Motors.One.Forwards(1); +Thread.Sleep(2000); +hat.Motors.One.Backwards(0.6); +Thread.Sleep(2000); +hat.Motors.Two.Forwards(1); +Thread.Sleep(2000); +hat.Motors.Two.Backwards(0.6); +Thread.Sleep(2000); + +// Set motors speed +hat.Motors.One.Speed = 1; +Thread.Sleep(2000); +hat.Motors.One.Speed = -0.6; +Thread.Sleep(2000); +hat.Motors.Two.Speed = 0.8; +Thread.Sleep(2000); +hat.Motors.Two.Speed = -0.75; +Thread.Sleep(2000); + +// Stop motors +hat.Motors.Stop(); + +// Stop motors one at a time +hat.Motors.Forwards(1); +Thread.Sleep(2000); +hat.Motors.One.Stop(); +Thread.Sleep(2000); +hat.Motors.Two.Stop(); +``` diff --git a/src/devices/ExplorerHat/samples/README.md b/src/devices/ExplorerHat/samples/README.md deleted file mode 100644 index 18fb8a7158..0000000000 --- a/src/devices/ExplorerHat/samples/README.md +++ /dev/null @@ -1,108 +0,0 @@ -# Explorer HAT Pro (Pimoroni) basic sample - -Demonstrates how to manage leds and motors - -## Hat initialization - -```csharp -using (var hat = new ExplorerHat()) -{ - // Your code here -} -``` - -## Leds - -```csharp -// All lights on -hat.Lights.On(); -Thread.Sleep(1000); -// All lights off -hat.Lights.Off(); -Thread.Sleep(500); - -// By color -hat.Lights.Blue.On(); -Thread.Sleep(1000); -hat.Lights.Blue.Off(); -Thread.Sleep(500); -hat.Lights.Yellow.On(); -Thread.Sleep(1000); -hat.Lights.Yellow.Off(); -Thread.Sleep(500); -hat.Lights.Red.On(); -Thread.Sleep(1000); -hat.Lights.Red.Off(); -Thread.Sleep(500); -hat.Lights.Green.On(); -Thread.Sleep(1000); -hat.Lights.Green.Off(); -Thread.Sleep(500); - -// By number -hat.Lights.One.On(); -Thread.Sleep(1000); -hat.Lights.One.Off(); -Thread.Sleep(500); -hat.Lights.Two.On(); -Thread.Sleep(1000); -hat.Lights.Two.Off(); -Thread.Sleep(500); -hat.Lights.Three.On(); -Thread.Sleep(1000); -hat.Lights.Three.Off(); -Thread.Sleep(500); -hat.Lights.Four.On(); -Thread.Sleep(1000); -hat.Lights.Four.Off(); -Thread.Sleep(500); - -// Iterate through led array -int i = 0; -foreach (var led in hat.Lights) -{ - i++; - Console.WriteLine($"Led #{i} is {(led.IsOn ? "ON" : "OFF")}"); -} -``` - -## Motors -```csharp -// Forwards full speed -hat.Motors.Forwards(1); -Thread.Sleep(2000); - -// Backwards full speed -hat.Motors.Backwards(1); -Thread.Sleep(2000); - -// Manage one motor at a time -hat.Motors.One.Forwards(1); -Thread.Sleep(2000); -hat.Motors.One.Backwards(0.6); -Thread.Sleep(2000); -hat.Motors.Two.Forwards(1); -Thread.Sleep(2000); -hat.Motors.Two.Backwards(0.6); -Thread.Sleep(2000); - -// Set motors speed -hat.Motors.One.Speed = 1; -Thread.Sleep(2000); -hat.Motors.One.Speed = -0.6; -Thread.Sleep(2000); -hat.Motors.Two.Speed = 0.8; -Thread.Sleep(2000); -hat.Motors.Two.Speed = -0.75; -Thread.Sleep(2000); - -// Stop motors -hat.Motors.Stop(); - -// Stop motors one at a time -hat.Motors.Forwards(1); -Thread.Sleep(2000); -hat.Motors.One.Stop(); -Thread.Sleep(2000); -hat.Motors.Two.Stop(); -``` diff --git a/src/devices/Ft4222/README.md b/src/devices/Ft4222/README.md index be1c8a9136..0ef4c54628 100644 --- a/src/devices/Ft4222/README.md +++ b/src/devices/Ft4222/README.md @@ -2,7 +2,7 @@ This project support SPI, GPIO and I2C into a normal Windows 64 bits or Windows 32 bits environment thru FT4222 chipset. MacOS and Linux 64 bits can be added as well. -## Device family +## Documentation This device supports multiple SPI as well as GPIO and I2C. It is a [FT4222](https://www.ftdichip.com/Products/ICs/FT4222H.html) from FTDI Chip. diff --git a/src/devices/GoPiGo3/README.md b/src/devices/GoPiGo3/README.md index 33d55294ae..ec84e83de6 100644 --- a/src/devices/GoPiGo3/README.md +++ b/src/devices/GoPiGo3/README.md @@ -42,7 +42,7 @@ For I2C sensors, the code has been tested very little. And no high level classes ## How to use the driver -The main [GoPiGo3.samples](./samples) contains a series of test showing how to use every elements of the driver. +The main [GoPiGo3.samples](https://github.com/dotnet/iot/tree/main/src/devices/GoPiGo3/samples) contains a series of test showing how to use every elements of the driver. Create a ```GoPiGo``` class. @@ -300,7 +300,7 @@ The ```Vehicle``` class offers functions with timeout allowing to drive for a ce ## Tests -A series of hardware tests for motors and sensors are available in [GoPiGo3.samples](./samples). Those hardware tests offers a variety of low level access to the Brick class as well as high level thru the Motor and Sensor classes. +A series of hardware tests for motors and sensors are available in [GoPiGo3.samples](https://github.com/dotnet/iot/tree/main/src/devices/GoPiGo3/samples). Those hardware tests offers a variety of low level access to the Brick class as well as high level thru the Motor and Sensor classes. You can select the tests you want to run: diff --git a/src/devices/GoPiGo3/samples/README.md b/src/devices/GoPiGo3/samples/README.md deleted file mode 100644 index 540092322e..0000000000 --- a/src/devices/GoPiGo3/samples/README.md +++ /dev/null @@ -1,62 +0,0 @@ -# GoPiGo3 - -The provided examples covers almost all high level sensor classes as well as motors and GoPiGo3 information. This is the code used to test the hardware. - -# Schematic - -Just plug your GoPiGo3 shield on your Raspberry Pi. - -If you are using another board with compatible pins with the Raspberry Pi, you will be able to use it as well without any change. If you are using a board with a different pin out, make sure you connect the SPI of your board to the SPI of GoPiGo3. - -This is the list of tested and fully supported sensors. They are all either analogic either digital, input or output, PWM or not sensors. Generic sensors can be found in the ```Sensors``` folder of the main GoPiGo3 class. - -![image how it works](../gopigosensors.png) - -More information on [Dexter Industries website](https://www.dexterindustries.com/GoPiGo3Pi//). - -Please note the for analogic sensors the ADC is 4095 (12 bits). - -# Code - -The code illustrate how to use most sensors as well as motors. It is the code used to test the hardware devices. As explained in the main documentation, we do recommend to use the high level classes to access the sensors and the motors rather than the low level one. That said the example contains examples on how to use all of them. - -Refer to the code to understand on which port you'll need to plug motors and sensors. The available tests are the following: - -``` -Choose a test by entering the number and press enter: - 1. Basic GoPiGo3 info and embedded led test - 2. Control left motor from motor right position - 3. Read encoder of right motor - 4. Test both servo motors - 5. Test Ultrasonic sensor on Grove1 - 6. Test buzzer on Grove1 - 7. Change buzzer tone on Grove1 with a potentiometer on Grove2 - 8. Test sound sensor on Grove1 - 9. Test a relay on Grove1 - 10. Test a button on Grove1 - 11. Control a led light on Grove2 from a light sensor on Grove1 - 12. Test MotorLeft speed based on encoder - 13. Test driving the vehicle -``` - -You always have to create a GoPiGo3 and initialize it. Then you can run your code. In this example, reading an analogic sound sensor. - -```csharp -var settings = new SpiConnectionSettings(0, 1) -{ - // 500K is the SPI communication with GoPiGo - ClockFrequency = 500000, - Mode = SpiMode.Mode0, - DataBitLength = 8 -}; -GoPiGo _goPiGo3 = new GoPiGo(SpiDevice.Create(settings)); -SoundSensor soundSensor = new SoundSensor(_goPiGo3, GrovePort.Grove1); -Console.WriteLine($"Test {soundSensor.SensorName} on port {soundSensor.Port}. Press a key to finish the test"); -while (!Console.KeyAvailable) -{ - Console.Write($"{soundSensor.SensorName}: {soundSensor.ValueAsString} which is {soundSensor.ValueAsPercent} %"); - Thread.Sleep(100); -} -``` - -Please keep in mind that default behavior when GoPiGo is disposed, the SpiDevice as well. You can override this default behavior by changing ```shouldDispose``` to false. diff --git a/src/devices/Gpio/README.md b/src/devices/Gpio/README.md index 50dc21aa4c..b7ae6e7548 100644 --- a/src/devices/Gpio/README.md +++ b/src/devices/Gpio/README.md @@ -2,7 +2,7 @@ This project contains some **full function(PULL-UP, PULL-DOWN)** generic GPIO drivers, and it can provide faster GPIO access. -## Catalogue +## Documentation * For Allwinner SoCs: [SunxiDriver](Drivers/Sunxi/README.md) * For Rockchip SoCs: [RockchipDriver](Drivers/Rockchip/README.md) @@ -32,3 +32,82 @@ Benchmarking with **Orange Pi 4**, select GPIO 150 (Logical). The operating syst | SysFsDriver | C# | System.Device.Gpio 1.3.0 | 2020-02-22 | 4.27 KHz | | | LibGpiodDriver | C# | System.Device.Gpio 1.3.0
libgpiod 1.2-3 | 2020-02-22 | 174 KHz | | | [wiringOP](https://github.com/orangepi-xunlong/wiringOP) | C | 35de015 | 2020-02-22 | 584 KHz | | + +## Usage + +### Hardware required + +* Orange Pi Zero +* Switch +* Male/Female Jumper Wires + +### Circuit + +![circuit](opi_circuit.png) + +* Switch 1 - Board Pin7 (GPIO 6) +* Switch 2 - GND + +### Code + +```csharp +using System; +using System.Device.Gpio; +using Iot.Device.BoardLed; +using Iot.Device.Gpio.Drivers; + +// Set debounce delay to 5ms +int debounceDelay = 50000; +int pin = 7; + +Console.WriteLine($"Let's blink an on-board LED!"); + +using GpioController controller = new GpioController(PinNumberingScheme.Board, new OrangePiZeroDriver()); +using BoardLed led = new BoardLed("orangepi:red:status"); + +controller.OpenPin(pin, PinMode.InputPullUp); +led.Trigger = "none"; +Console.WriteLine($"GPIO pin enabled for use: {pin}."); +Console.WriteLine("Press any key to exit."); + +while (!Console.KeyAvailable) +{ + if (Debounce()) + { + // Button is pressed + led.Brightness = 1; + } + else + { + // Button is unpressed + led.Brightness = 0; + } +} + +bool Debounce() +{ + long debounceTick = DateTime.Now.Ticks; + PinValue buttonState = controller.Read(pin); + + do + { + PinValue currentState = controller.Read(pin); + + if (currentState != buttonState) + { + debounceTick = DateTime.Now.Ticks; + buttonState = currentState; + } + } + while (DateTime.Now.Ticks - debounceTick < debounceDelay); + + if (buttonState == PinValue.Low) + { + return true; + } + else + { + return false; + } +} +``` \ No newline at end of file diff --git a/src/devices/Gpio/samples/opi_circuit.fzz b/src/devices/Gpio/opi_circuit.fzz similarity index 100% rename from src/devices/Gpio/samples/opi_circuit.fzz rename to src/devices/Gpio/opi_circuit.fzz diff --git a/src/devices/Gpio/samples/opi_circuit.png b/src/devices/Gpio/opi_circuit.png similarity index 100% rename from src/devices/Gpio/samples/opi_circuit.png rename to src/devices/Gpio/opi_circuit.png diff --git a/src/devices/Gpio/samples/README.md b/src/devices/Gpio/samples/README.md deleted file mode 100644 index bc22c0a23f..0000000000 --- a/src/devices/Gpio/samples/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Sunxi GPIO Driver‘s Sample - -### Hardware required - -* Orange Pi Zero -* Switch -* Male/Female Jumper Wires - -## Circuit - -![](opi_circuit.png) - -* Switch 1 - Board Pin7 (GPIO 6) -* Switch 2 - GND \ No newline at end of file diff --git a/src/devices/GrovePi/README.md b/src/devices/GrovePi/README.md index 367445e454..efb0d438b4 100644 --- a/src/devices/GrovePi/README.md +++ b/src/devices/GrovePi/README.md @@ -39,7 +39,7 @@ More sensors are supported and being tested like the Grove Led Bar. Note that th ## How to use the driver -The main [GrovePi samples](./samples) contains a series of test showing how to use some of the classes. +The main [GrovePi samples](https://github.com/dotnet/iot/tree/main/src/devices/GrovePi/samples) contains a series of test showing how to use some of the classes. Create a ```GrovePi``` class. @@ -117,7 +117,7 @@ while (!Console.KeyAvailable) ## Tests -A series of hardware tests for sensors are available in [GrovePi.samples](./samples). Those hardware tests offers a variety of sensors. +A series of hardware tests for sensors are available in [GrovePi.samples](https://github.com/dotnet/iot/tree/main/src/devices/GrovePi/samples). Those hardware tests offers a variety of sensors. ```csharp Console.WriteLine("Hello GrovePi!"); @@ -152,3 +152,7 @@ while (!Console.KeyAvailable) Console.CursorTop += 5; ``` + +Once you have GrovePi on a Raspberry Pi, it looks like this: + +![sample](sample.jpg) diff --git a/src/devices/GrovePi/samples/sample.jpg b/src/devices/GrovePi/sample.jpg similarity index 100% rename from src/devices/GrovePi/samples/sample.jpg rename to src/devices/GrovePi/sample.jpg diff --git a/src/devices/GrovePi/samples/README.md b/src/devices/GrovePi/samples/README.md deleted file mode 100644 index dbc542a91d..0000000000 --- a/src/devices/GrovePi/samples/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# GrovePi sample - -You can refer to the main documentation to understand how to use GrovePi. This example uses multiple sensors. All of them can be foun d in the basic Grove Start Kit. - -Once you have GrovePi on a Raspberry Pi, it looks like this: - -![sample](sample.jpg) - -See the GRovePi binding [documentation ](../README.md) for more information and how to use GrovePi. \ No newline at end of file diff --git a/src/devices/HardwareMonitor/README.md b/src/devices/HardwareMonitor/README.md index 7bdb3198aa..0cac8f5cdb 100644 --- a/src/devices/HardwareMonitor/README.md +++ b/src/devices/HardwareMonitor/README.md @@ -1,12 +1,8 @@ # OpenHardwareMonitor client library -Client binding for OpenHardwareMonitor. +Client binding for OpenHardwareMonitor. Returns a set of sensor measurements for the current hardware. The values include CPU temperature(s), Fan Speed(s), GPU Temperature(s) and Hard Disk states. The set of values is hardware dependent. -## Summary - -Returns a set of sensor measurements for the current hardware. The values include CPU temperature(s), Fan Speed(s), GPU Temperature(s) and Hard Disk states. The set of values is hardware dependent. - -## Binding Notes +## Documentation This binding works on Windows only. It requires that OpenHardwareMonitor (https://openhardwaremonitor.org/) is running in the background. While that tool requires elevated permissions to work, the binding (and the application using it) does not. Check out https://github.com/hexagon-oss/openhardwaremonitor for an improved fork with some additional features. @@ -16,4 +12,56 @@ The binding supports some additional, "virtual" sensor measuments that are deriv - From the CPU Package power sensor, the CPU heat flux is calculated (estimating the size of the die). - If both a power and a voltage sensor are available for CPU Package, the current is calculated. -## References +## Usage + +```csharp +using System; +using System.Globalization; +using System.Threading; +using Iot.Device.HardwareMonitor; +using UnitsNet; + +Console.WriteLine("Press any key to quit"); + +OpenHardwareMonitor hw = new OpenHardwareMonitor(); +if (hw.GetSensorList().Count == 0) +{ + Console.WriteLine("OpenHardwareMonitor is not running"); + return; +} + +hw.EnableDerivedSensors(); + +while (!Console.KeyAvailable) +{ + Console.Clear(); + Console.WriteLine("Showing all available sensors (press any key to quit)"); + var components = hw.GetHardwareComponents(); + foreach (var component in components) + { + Console.WriteLine("--------------------------------------------------------------------"); + Console.WriteLine($"{component.Name} Type {component.Type}, Path {component.Identifier}"); + Console.WriteLine("--------------------------------------------------------------------"); + foreach (var sensor in hw.GetSensorList(component)) + { + Console.Write($"{sensor.Name}: Path {sensor.Identifier}, Parent {sensor.Parent} "); + if (sensor.TryGetValue(out IQuantity? quantity)) + { + Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}: {1:g}", quantity!.Type, quantity)); + } + else + { + Console.WriteLine($"No data"); + } + } + } + + if (hw.TryGetAverageGpuTemperature(out Temperature gpuTemp) && + hw.TryGetAverageCpuTemperature(out Temperature cpuTemp)) + { + Console.WriteLine($"Averages: CPU temp {cpuTemp:s2}, GPU temp {gpuTemp:s2}, CPU Load {hw.GetCpuLoad()}"); + } + + Thread.Sleep(1000); +} +``` diff --git a/src/devices/Hcsr04/README.md b/src/devices/Hcsr04/README.md index 5bab099547..cb6bb0a55f 100644 --- a/src/devices/Hcsr04/README.md +++ b/src/devices/Hcsr04/README.md @@ -1,15 +1,41 @@ # HC-SR04 - Ultrasonic Ranging Module -Device bindings for the HC-SR04 sonar distance sensor. +Device bindings for the HC-SR04 sonar distance sensor. Calculates the distance from an object by using the HC-SR04 distance sensor. -## Summary +## Documentation -Calculates the distance from an object by using the HC-SR04 distance sensor. +* [HC-SR04 data sheet](https://components101.com/sites/default/files/component_datasheet/HCSR04%20Datasheet.pdf) -## Binding Notes +## Usage -Provide any specifics related to binding API. This could include how to configure component for particular functions and example code. +```C# +using (var sonar = new Hcsr04(4, 17)) +{ + if (sonar.TryGetDistance(out Length distance)) + { + Console.WriteLine($"Distance: {distance.Centimeters} cm"); + } + else + { + Console.WriteLine("Error reading sensor"); + } -## References + Thread.Sleep(1000); +} +``` -* [HC-SR04 data sheet](https://components101.com/sites/default/files/component_datasheet/HCSR04%20Datasheet.pdf) +### Hardware Required + +* HC-SR04 +* Male/Female Jumper Wires + +### Circuit + +![Fritz diagram](raspberry_hc-sr04.png) + +* VCC - 5V +* GND - GND +* Trig - GPIO 4 +* Echo - GPIO 17 + +The fritz diagram above depicts how you should wire your RPi in order to run the program, the resistance for R1 is 1kOhm. (Optional). diff --git a/src/devices/Hcsr04/samples/raspberry_hc-sr04.png b/src/devices/Hcsr04/raspberry_hc-sr04.png similarity index 100% rename from src/devices/Hcsr04/samples/raspberry_hc-sr04.png rename to src/devices/Hcsr04/raspberry_hc-sr04.png diff --git a/src/devices/Hcsr04/samples/README.md b/src/devices/Hcsr04/samples/README.md deleted file mode 100644 index 2c3b9c8f31..0000000000 --- a/src/devices/Hcsr04/samples/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# HC-SR04 - Samples - -## Hardware Required -* HC-SR04 -* Male/Female Jumper Wires - -## Circuit -![Fritz diagram](raspberry_hc-sr04.png) - -* VCC - 5V -* GND - GND -* Trig - GPIO 4 -* Echo - GPIO 17 - -The fritz diagram above depicts how you should wire your RPi in order to run the program, the resistance for R1 is 1kOhm. (Optional). - -## Code -```C# -using (var sonar = new Hcsr04(4, 17)) -{ - if (sonar.TryGetDistance(out Length distance)) - { - Console.WriteLine($"Distance: {distance.Centimeters} cm"); - } - else - { - Console.WriteLine("Error reading sensor"); - } - - Thread.Sleep(1000); -} -``` diff --git a/src/devices/Hcsr501/samples/Hcsr501Setting.png b/src/devices/Hcsr501/Hcsr501Setting.png similarity index 100% rename from src/devices/Hcsr501/samples/Hcsr501Setting.png rename to src/devices/Hcsr501/Hcsr501Setting.png diff --git a/src/devices/Hcsr501/README.md b/src/devices/Hcsr501/README.md index 2624cdea52..c171d8a125 100644 --- a/src/devices/Hcsr501/README.md +++ b/src/devices/Hcsr501/README.md @@ -1,10 +1,16 @@ # HC-SR501 - PIR Motion Sensor + HC-SR501 is used to detect motion based on the infrared heat in the surrounding area. -## Sensor Image -![](sensor.jpg) +## Documentation + +- In [Chinese](http://wenku.baidu.com/view/26ef5a9c49649b6648d747b2.html) +- In [English](https://cdn.datasheetspdf.com/pdf-down/H/C/-/HC-SR501-1-ETC.pdf) + +![sensor](sensor.jpg) ## Usage + ```C# using(Hcsr501 sensor = new Hcsr501(hcsr501Pin, PinNumberingScheme.Logical)) { @@ -13,7 +19,60 @@ using(Hcsr501 sensor = new Hcsr501(hcsr501Pin, PinNumberingScheme.Logical)) } ``` -## References -In Chinese : http://wenku.baidu.com/view/26ef5a9c49649b6648d747b2.html +From the [HC-SR501 sample](https://github.com/dotnet/iot/tree/main/src/devices/Hcsr501/samples), we can do comething more complete: + +```C# +GpioController ledController = new GpioController(); +ledController.OpenPin(27, PinMode.Output); + +using (Iot.Device.Hcsr501.Hcsr501 sensor = + new Iot.Device.Hcsr501.Hcsr501(17)) +{ + while (true) + { + // adjusting the detection distance and time by rotating the potentiometer on the sensor + if (sensor.IsMotionDetected) + { + // turn the led on when the sensor detected infrared heat + ledController.Write(27, PinValue.High); + Console.WriteLine("Detected! Turn the LED on."); + } + else + { + // turn the led off when the sensor undetected infrared heat + ledController.Write(27, PinValue.Low); + Console.WriteLine("Undetected! Turn the LED off."); + } + + Thread.Sleep(1000); + } +} +``` + +### Hardware Required + +* PIR Motion Sensor - HC-SR501 +* LED +* 220 Ω resistor +* Male/Female Jumper Wires + +### Circuit + +![circuit](circuit_bb.png) + +### HC-SR501 + +![settings](Hcsr501Setting.png) + +* VCC - 5V +* GND - GND +* OUT - GPIO 17 + +### LED + +* VCC & 220 Ω resistor - GPIO 27 +* GND - GND + +### Result -In English : https://cdn.datasheetspdf.com/pdf-down/H/C/-/HC-SR501-1-ETC.pdf +![result ](RunningResult.gif) diff --git a/src/devices/Hcsr501/samples/RunningResult.gif b/src/devices/Hcsr501/RunningResult.gif similarity index 100% rename from src/devices/Hcsr501/samples/RunningResult.gif rename to src/devices/Hcsr501/RunningResult.gif diff --git a/src/devices/Hcsr501/samples/circuit.fzz b/src/devices/Hcsr501/circuit.fzz similarity index 100% rename from src/devices/Hcsr501/samples/circuit.fzz rename to src/devices/Hcsr501/circuit.fzz diff --git a/src/devices/Hcsr501/samples/circuit_bb.png b/src/devices/Hcsr501/circuit_bb.png similarity index 100% rename from src/devices/Hcsr501/samples/circuit_bb.png rename to src/devices/Hcsr501/circuit_bb.png diff --git a/src/devices/Hcsr501/samples/README.md b/src/devices/Hcsr501/samples/README.md deleted file mode 100644 index de1c87a6c1..0000000000 --- a/src/devices/Hcsr501/samples/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# HC-SR501 - Samples - -## Hardware Required -* PIR Motion Sensor - HC-SR501 -* LED -* 220 Ω resistor -* Male/Female Jumper Wires - -## Circuit -![](circuit_bb.png) - -### HC-SR501 - -![](Hcsr501Setting.png) - -* VCC - 5V -* GND - GND -* OUT - GPIO 17 - -### LED -* VCC & 220 Ω resistor - GPIO 27 -* GND - GND - -## Code -```C# -GpioController ledController = new GpioController(); -ledController.OpenPin(27, PinMode.Output); - -using (Iot.Device.Hcsr501.Hcsr501 sensor = - new Iot.Device.Hcsr501.Hcsr501(17)) -{ - while (true) - { - // adjusting the detection distance and time by rotating the potentiometer on the sensor - if (sensor.IsMotionDetected) - { - // turn the led on when the sensor detected infrared heat - ledController.Write(27, PinValue.High); - Console.WriteLine("Detected! Turn the LED on."); - } - else - { - // turn the led off when the sensor undetected infrared heat - ledController.Write(27, PinValue.Low); - Console.WriteLine("Undetected! Turn the LED off."); - } - - Thread.Sleep(1000); - } -} -``` - - - -## Result -![](RunningResult.gif) diff --git a/src/devices/Hmc5883l/samples/HMC5883L_circuit.fzz b/src/devices/Hmc5883l/HMC5883L_circuit.fzz similarity index 100% rename from src/devices/Hmc5883l/samples/HMC5883L_circuit.fzz rename to src/devices/Hmc5883l/HMC5883L_circuit.fzz diff --git a/src/devices/Hmc5883l/samples/HMC5883L_circuit_bb.png b/src/devices/Hmc5883l/HMC5883L_circuit_bb.png similarity index 100% rename from src/devices/Hmc5883l/samples/HMC5883L_circuit_bb.png rename to src/devices/Hmc5883l/HMC5883L_circuit_bb.png diff --git a/src/devices/Hmc5883l/README.md b/src/devices/Hmc5883l/README.md index 2d9eb1b51c..90afa15d87 100644 --- a/src/devices/Hmc5883l/README.md +++ b/src/devices/Hmc5883l/README.md @@ -1,10 +1,15 @@ # HMC5883L - 3 Axis Digital Compass + HMC5883L is a surface-mount, multi-chip module designed for low-field magnetic sensing with a digital interface for applications such as lowcost compassing and magnetometry. -## Sensor Image -![](sensor.jpg) +## Documentation + +- HMC5883L [datasheet](https://cdn.datasheetspdf.com/pdf-down/H/M/C/HMC5883L-Honeywell.pdf) + +![sensor](sensor.jpg) ## Usage + ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.DefaultI2cAddress); I2cDevice device = I2cDevice.Create(settings); @@ -21,5 +26,41 @@ using (Hmc5883l sensor = new Hmc5883l(device)) ``` -## References -https://cdn.datasheetspdf.com/pdf-down/H/M/C/HMC5883L-Honeywell.pdf +From the [HMC5883L sample](https://github.com/dotnet/iot/tree/main/src/devices/Hmc5883l/samples), you can go further with the following: + +```C# +I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.DefaultI2cAddress); +I2cDevice device = I2cDevice.Create(settings); + +using (Hmc5883l sensor = new Hmc5883l(device)) +{ + while (true) + { + // read heading + Console.WriteLine($"Heading: {sensor.Heading.ToString("0.00")} °"); + Console.WriteLine(); + + // wait for a second + Thread.Sleep(1000); + } +} + +``` + +### Hardware Required + +* HMC5883L +* Male/Female Jumper Wires + +### Circuit + +![circuit](HMC5883L_circuit_bb.png) + +* SCL - SCL +* SDA - SDA +* VCC - 5V +* GND - GND + +### Result + +![running result](RunningResult.jpg) diff --git a/src/devices/Hmc5883l/samples/RunningResult.jpg b/src/devices/Hmc5883l/RunningResult.jpg similarity index 100% rename from src/devices/Hmc5883l/samples/RunningResult.jpg rename to src/devices/Hmc5883l/RunningResult.jpg diff --git a/src/devices/Hts221/README.md b/src/devices/Hts221/README.md index 573fd83b31..f74b83613f 100644 --- a/src/devices/Hts221/README.md +++ b/src/devices/Hts221/README.md @@ -1,6 +1,7 @@ # HTS221 - Capacitive digital sensor for relative humidity and temperature Some of the applications mentioned by the datasheet: + - Air conditioning, heating and ventilation - Air humidifiers - Refrigerators @@ -10,8 +11,43 @@ Some of the applications mentioned by the datasheet: - Respiratory equipment - Asset and goods tracking -See [samples](samples/README.md) for information about usage. - -## References +## Documentation - https://www.st.com/resource/en/datasheet/hts221.pdf + +## Usage + + +```csharp +using System; +using System.Threading; +using System.Device.I2c; +using Iot.Device.Common; +using Iot.Device.Hts221; +using UnitsNet; + +// I2C address on SenseHat board +const int I2cAddress = 0x5F; + +using Hts221 th = new(CreateI2cDevice()); +while (true) +{ + var tempValue = th.Temperature; + var humValue = th.Humidity; + + Console.WriteLine($"Temperature: {tempValue.DegreesCelsius:0.#}\u00B0C"); + Console.WriteLine($"Relative humidity: {humValue:0.#}%"); + + // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. + Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).DegreesCelsius:0.#}\u00B0C"); + Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).DegreesCelsius:0.#}\u00B0C"); + Thread.Sleep(1000); +} + +I2cDevice CreateI2cDevice() +{ + I2cConnectionSettings settings = new(1, I2cAddress); + return I2cDevice.Create(settings); +} + +``` diff --git a/src/devices/Hts221/samples/README.md b/src/devices/Hts221/samples/README.md deleted file mode 100644 index 17b3d03bae..0000000000 --- a/src/devices/Hts221/samples/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# HTS221 - Capacitive digital sensor for relative humidity and temperature - -```csharp -class Program -{ - // I2C address on SenseHat board - public const int I2cAddress = 0x5F; - static void Main(string[] args) - { - using (var th = new Hts221(CreateI2cDevice())) - { - while (true) - { - var tempValue = th.Temperature; - var humValue = th.Humidity; - - Console.WriteLine($"Temperature: {tempValue.Celsius:0.#}\u00B0C"); - Console.WriteLine($"Relative humidity: {humValue:0.#}%"); - - // WeatherHelper supports more calculations, such as saturated vapor pressure, actual vapor pressure and absolute humidity. - Console.WriteLine($"Heat index: {WeatherHelper.CalculateHeatIndex(tempValue, humValue).Celsius:0.#}\u00B0C"); - Console.WriteLine($"Dew point: {WeatherHelper.CalculateDewPoint(tempValue, humValue).Celsius:0.#}\u00B0C"); - - Thread.Sleep(1000); - } - } - } - private static I2cDevice CreateI2cDevice() - { - var settings = new I2cConnectionSettings(1, I2cAddress); - return I2cDevice.Create(settings); - } -} -``` diff --git a/src/devices/Ina219/samples/Ina219.Sample.fzz b/src/devices/Ina219/Ina219.Sample.fzz similarity index 100% rename from src/devices/Ina219/samples/Ina219.Sample.fzz rename to src/devices/Ina219/Ina219.Sample.fzz diff --git a/src/devices/Ina219/samples/Ina219.Sample_bb.png b/src/devices/Ina219/Ina219.Sample_bb.png similarity index 100% rename from src/devices/Ina219/samples/Ina219.Sample_bb.png rename to src/devices/Ina219/Ina219.Sample_bb.png diff --git a/src/devices/Ina219/README.md b/src/devices/Ina219/README.md index 91b02b60f7..065be6543f 100644 --- a/src/devices/Ina219/README.md +++ b/src/devices/Ina219/README.md @@ -1,7 +1,5 @@ # INA219 - Bidirectional Current/Power Monitor -## Summary - The INA219 is a current shunt and power monitor with an I2C- or SMBUS-compatible interface. The device monitors both shunt voltage drop and bus supply voltage, with programmable conversion times and filtering. A programmable calibration value, combined with an internal multiplier, enables direct readouts of current in amperes. An additional multiplying register calculates power in watts. The I2C- or SMBUS-compatible interface features 16 programmable addresses * Senses Bus Voltages from 0 to 26 V @@ -11,10 +9,49 @@ The INA219 is a current shunt and power monitor with an I2C- or SMBUS-compatible * Filtering Options * Calibration Registers -## Device Family +## Documentation This binding is intended to support both the A and B grades of the INA219. The grades differ only in the accuracy and precision specifications. -## References +- [INA219 Datasheet](http://www.ti.com/lit/ds/symlink/ina219.pdf) + +## Usage + +```csharp +const byte Adafruit_Ina219_I2cAddress = 0x40; +const byte Adafruit_Ina219_I2cBus = 0x1; + +// create an INA219 device on I2C bus 1 addressing channel 64 +using (Ina219 device = new Ina219(new I2cConnectionSettings(Adafruit_Ina219_I2cBus, Adafruit_Ina219_I2cAddress))) +{ + // reset the device + device.Reset(); + + // set up the bus and shunt voltage ranges and the calibration. Other values left at default. + device.BusVoltageRange = Ina219BusVoltageRange.Range16v; + device.PgaSensitivity = Ina219PgaSensitivity.PlusOrMinus40mv; + device.SetCalibration(33574, (float)12.2e-6); + + while (true) + { + // write out the current values from the INA219 device. + System.Console.WriteLine($"Bus Voltage {device.ReadBusVoltage()}V Shunt Voltage {device.ReadShuntVoltage() * 1000}mV Current {device.ReadCurrent() * 1000}mA Power {device.ReadPower() * 1000}mW"); + System.Threading.Thread.Sleep(1000); + } +} +``` + +### Notes + +This sample uses an Adafruit INA219 breakout board and monitors a LED wired into the 3.3 volts supply with a 150 ohm current limiting resistor. It prints the bus voltage, shunt voltage, current and power every second. + +The configuration and calibration is determinined as follows. + +* The bus voltage range can be either 16v or 32v. As this example uses a 3.3v supply then the 16v bus voltage range is chosen +* The current through the LED is in the low tens of milliamps. If we take 50mA as a reasonable maximum current that we may want to see then the maximum voltage accross the shunt resistor is 0.1 Ohms x 50mA which works out +at 5mV. Given this we can use a shunt voltage range of +/- 40mV +* The maximum possible current would then be 40mV / 0.1 = 400mA +* With a 400mA maximum current and a range of the ADC of 15bits then the LSB of the current would be 400mA/32767 = 12.2207 microamps. We will chose 12.2uA as a round number. +* From the [INA219 Datasheet](http://www.ti.com/lit/ds/symlink/ina219.pdf) the calibration register should be set at 0.04096/(currentLSB * shunt resistance) = 33574 = 0x8326 -[INA219 Datasheet](http://www.ti.com/lit/ds/symlink/ina219.pdf) +![circuit](Ina219.Sample_bb.png) \ No newline at end of file diff --git a/src/devices/Ina219/samples/README.md b/src/devices/Ina219/samples/README.md deleted file mode 100644 index b76da0b884..0000000000 --- a/src/devices/Ina219/samples/README.md +++ /dev/null @@ -1,39 +0,0 @@ -# INA219 Sample - Measuring the voltage current and power of a light emitting diode. - -This sample uses an Adafruit INA219 breakout board and monitors a LED wired into the 3.3 volts supply with a 150 ohm current limiting resistor. It prints the bus voltage, shunt voltage, current and power every second. - -The configuration and calibration is determinined as follows. - -* The bus voltage range can be either 16v or 32v. As this example uses a 3.3v supply then the 16v bus voltage range is chosen -* The current through the LED is in the low tens of milliamps. If we take 50mA as a reasonable maximum current that we may want to see then the maximum voltage accross the shunt resistor is 0.1 Ohms x 50mA which works out -at 5mV. Given this we can use a shunt voltage range of +/- 40mV -* The maximum possible current would then be 40mV / 0.1 = 400mA -* With a 400mA maximum current and a range of the ADC of 15bits then the LSB of the current would be 400mA/32767 = 12.2207 microamps. We will chose 12.2uA as a round number. -* From the [INA219 Datasheet](http://www.ti.com/lit/ds/symlink/ina219.pdf) the calibration register should be set at 0.04096/(currentLSB * shunt resistance) = 33574 = 0x8326 - -![](Ina219.Sample_bb.png) - -```csharp -const byte Adafruit_Ina219_I2cAddress = 0x40; -const byte Adafruit_Ina219_I2cBus = 0x1; - -// create an INA219 device on I2C bus 1 addressing channel 64 -using (Ina219 device = new Ina219(new I2cConnectionSettings(Adafruit_Ina219_I2cBus, Adafruit_Ina219_I2cAddress))) -{ - // reset the device - device.Reset(); - - // set up the bus and shunt voltage ranges and the calibration. Other values left at default. - device.BusVoltageRange = Ina219BusVoltageRange.Range16v; - device.PgaSensitivity = Ina219PgaSensitivity.PlusOrMinus40mv; - device.SetCalibration(33574, (float)12.2e-6); - - while (true) - { - // write out the current values from the INA219 device. - System.Console.WriteLine($"Bus Voltage {device.ReadBusVoltage()}V Shunt Voltage {device.ReadShuntVoltage() * 1000}mV Current {device.ReadCurrent() * 1000}mA Power {device.ReadPower() * 1000}mW"); - System.Threading.Thread.Sleep(1000); - } -} -``` - diff --git a/src/devices/KeyMatrix/samples/4x4kb.fzz b/src/devices/KeyMatrix/4x4kb.fzz similarity index 100% rename from src/devices/KeyMatrix/samples/4x4kb.fzz rename to src/devices/KeyMatrix/4x4kb.fzz diff --git a/src/devices/KeyMatrix/samples/4x4kb.png b/src/devices/KeyMatrix/4x4kb.png similarity index 100% rename from src/devices/KeyMatrix/samples/4x4kb.png rename to src/devices/KeyMatrix/4x4kb.png diff --git a/src/devices/KeyMatrix/samples/4x4kb_via_mcp23017.fzz b/src/devices/KeyMatrix/4x4kb_via_mcp23017.fzz similarity index 100% rename from src/devices/KeyMatrix/samples/4x4kb_via_mcp23017.fzz rename to src/devices/KeyMatrix/4x4kb_via_mcp23017.fzz diff --git a/src/devices/KeyMatrix/samples/4x4kb_via_mcp23017.png b/src/devices/KeyMatrix/4x4kb_via_mcp23017.png similarity index 100% rename from src/devices/KeyMatrix/samples/4x4kb_via_mcp23017.png rename to src/devices/KeyMatrix/4x4kb_via_mcp23017.png diff --git a/src/devices/KeyMatrix/README.md b/src/devices/KeyMatrix/README.md index b9d0f5422d..d7925f5b40 100644 --- a/src/devices/KeyMatrix/README.md +++ b/src/devices/KeyMatrix/README.md @@ -4,7 +4,7 @@ An M×N key matrix driver. (M is number of output pins and N is number of input pins.) -## Summary +## Documentation These key matrices look like this: @@ -16,6 +16,9 @@ You can connect any M×N key matrix, theoretically, by using M+N GPIO pins. You can also use any compatible GPIO controller like [Mcp23xxx](../Mcp23xxx) instead of native controller. +- [How Key Matrices works](http://pcbheaven.com/wikipages/How_Key_Matrices_Works/) +- [4x4 Keypad](https://www.waveshare.com/wiki/4x4_Keypad) + ## Usage You need to create 2 lists of int, one for the input and one for the output. @@ -75,7 +78,16 @@ void KeyMatrixEventReceived(object sender, KeyMatrixEvent keyMatrixEvent) - Input pins need pull-down resistors connect to ground if your MCU doesn't have it. So you need to have a pull-down on a Raspberry Pi for example. - If your key matrix doesn't work well, try to swap output and input pins. Some includes diodes and if they are used the reverse way won't work properly. -## References +## Key Matrix Samples + +This shows how to connect the matrix. + +**Important**: Please make you don't forget to place a pull down on the input matrix. + +## Connection using on-board GPIO + +![Connection using Raspberry Pi](4x4kb.png) + +## Connection using MCP23017 -- http://pcbheaven.com/wikipages/How_Key_Matrices_Works/ -- https://www.waveshare.com/wiki/4x4_Keypad +![Connection using a MCP23017](4x4kb_via_mcp23017.png) \ No newline at end of file diff --git a/src/devices/LidarLiteV3/README.md b/src/devices/LidarLiteV3/README.md index 20b953e1ce..9465a648d3 100644 --- a/src/devices/LidarLiteV3/README.md +++ b/src/devices/LidarLiteV3/README.md @@ -1,12 +1,188 @@ # LidarLiteV3 - LIDAR Time of Flight Sensor -## Summary - This device belongs to a class of sensors known as time-of-flight, which measures distances by calculating the time delay between signal transmission and reception of the signal as it bounces off the subject. Unlike the popular sonar-based HC-SR04, this device uses a low-power laser. The advantage is longer distances (up to 40m) but more prone to errors when the subject is reflective. -## Reference +## Documentation [Official Manual and Technical Spec](http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf) + +## Usage + +Simple usage: + +```csharp +using (var llv3 = new LidarLiteV3(CreateI2cDevice())) +{ + // Take 10 measurements, each one second apart. + for (int i = 0; i < 10; i++) + { + Length currentDistance = llv3.MeasureDistance(); + Console.WriteLine($"Current Distance: {currentDistance.Centimeters} cm"); + Thread.Sleep(1000); + } +} + +I2cDevice CreateI2cDevice() +{ + var settings = new I2cConnectionSettings(1, LidarLiteV3.DefaultI2cAddress); + return I2cDevice.Create(settings); +} + +``` + +### Power Modes + +Power can be controlled to the device via a GPIO pin. Use the optional constructor parameters to +specify the GPIO controller and a power enable pin number (numbering scheme depends on GpioController). + +```csharp +int powerEnablePin = 13; +using (var llv3 = new LidarLiteV3(CreateI2cDevice(), new GpioController(), powerEnablePin)) +{ + // Power off the device. + llv3.PowerOff(); + // Device is completely turned off. + Console.WriteLine("Device is off."); + Thread.Sleep(5000); + // Power on the device, device is ready in ~22ms. + Console.WriteLine("Device is on."); + llv3.PowerOn(); + // Sleep 50ms. + Thread.Sleep(50); + // Get a reading. + Length currentDistance = llv3.MeasureDistance(); + Console.WriteLine($"Current Distance: {currentDistance.Centimeters} cm"); +} +``` + +It's also possible to disable the receiver circuit (saving 40 mA) or put the device to sleep +(saving 20 mA). However, it's recommended to use the power enable pin instead +since the initialization time is only 2 ms shorter. + +```csharp +using (var llv3 = new LidarLiteV3(CreateI2cDevice())) +{ + llv3.PowerMode = PowerMode.Sleep; +} +``` + +### Repetition Mode + +Instead of getting measurements on-demand, the device can be configure to repeat n number of +times, or infinitely. + +This is configured via `SetMeasurementRepetitionMode` passing in a mode (`Off`, `Repeat`, or +`RepeatInfinitely`), a loop count (if mode is `Repeat`), and a delay between measurements (default to +10 hz). A delay of `20` is about `100 hz`. + +With a repetition mode set, use `Distance` to retrieve the current readings in `Length`. +Use `DifferenceBetweenLastTwoDistances` to get a velocity reading. Negative values +indicate that the object is moving toward the device, positive indicates it's moving away. The value +is dependent on the delay, and the default 10 hz is about 0.1 m/s. + +```csharp +using (var llv3 = new LidarLiteV3(CreateI2cDevice())) +{ + llv3.SetMeasurementRepetitionMode(MeasurementRepetitionMode.RepeatIndefinitely); + + while(true) + { + Thread.Sleep(5); + Length currentDistance = llv3.Distance; + Length currentVelocity = llv3.DifferenceBetweenLastTwoDistances; + } +} +``` + +### Change the I2C Address + +By default, the device has an address of `0x62`. It's possible to change this address to +resolve a conflict with another device or to run multiple devices. + +Available addresses are 7-bit values with a 0 in the LSB order. + +```csharp +using (var llv3 = new LidarLiteV3(CreateI2cDevice())) +{ + // Set device from default `0x62` to `0x68` + llv3.SetI2cAddressAndDispose(0x68); +} + +// Connect to the device again with the new address. +var settings = new I2cConnectionSettings(1, 0x68); +var i2cDevice = I2cDevice.Create(settings); + +using (var llv3 = new LidarLiteV3(i2cDevice)) +{ + // ... +} + +``` + +### Optimization + +The default settings should work well, but several tweaks can be made to adjust the device. +See the manual for more details. + +#### Change Acquistion Count + +To isolate the signal from the noise, the device performs a series of acquisitions and sums up the +result until a peak is found. The number of acquistions can be configured via +`MaximumAcquisitionCount` (default: 128). + +Less acquisitions result in faster measurements, but limits the max range and produces more +erroneous readings. The number roughly correlates to an acquistion rate of n/count and n^(1/4). + +```csharp +using (var llv3 = new LidarLiteV3(CreateI2cDevice())) +{ + llv3.MaximumAcquisitionCount = 100 +} +``` + +#### Quick Termination Mode + +Faster acquisition readings, but with slightly more chance of erroneous readings. + +```csharp +using (var llv3 = new LidarLiteV3(CreateI2cDevice())) +{ + llv3.AcquistionMode |= AcquistionMode.EnableQuickTermination; +} +``` + +#### Detection Sensitivity + +The threshold when a peak is found can be configured via `AlgorithmByPassThreshold`. By default, +this is 0 which uses an internal algorithm to determine the threshold. + +Recommended non-default values are 32 for higher sensitivity but higher erronenous readings +and 96 for reduced sensitivity with fewer erroneous readings. + +```csharp +using (var llv3 = new LidarLiteV3(CreateI2cDevice())) +{ + llv3.AlgorithmBypassThreshold = 32 +} +``` + +## Raspberry PI Wiring + +The device communicates over I2C and while there's a PWN mode supported by the device, it is not +implemented. + +I2C Wiring on the Raspberry PI: + +| LidarLiteV3 Wire | Raspberry PI GPIO Pin (Physical Numbering) | +|-----------------------|--------------------------------------------| +| 5V (red) | 5V (pin 2) | +| Ground (black) | Ground (pin 6) | +| Power enable (orange) | Optional, an available IO pin (pin 33) | +| Mode control (yellow) | Not used | +| I2C SCL (green) | SCL (pin 5) | +| I2C SDA (blue) | SDA (pin 3) | + +> Important! Don't forget to enable I2C via `raspi-config`. diff --git a/src/devices/LidarLiteV3/samples/README.md b/src/devices/LidarLiteV3/samples/README.md deleted file mode 100644 index 756b64f98c..0000000000 --- a/src/devices/LidarLiteV3/samples/README.md +++ /dev/null @@ -1,191 +0,0 @@ -# LidarLiteV3 LIDAR ToF Sensor by Garmin - -# Summary - -This device belongs to a class of sensors known as time-of-flight, which measures distances by -calculating the time delay between signal transmission and reception of the signal as it bounces -off the subject. Unlike the popular sonar-based HC-SR04, this device uses a low-power laser. The -advantage is longer distances (up to 40m) but more prone to errors when the subject is reflective. - -# Raspberry PI Wiring - -The device communicates over I2C and while there's a PWN mode supported by the device, it is not -implemented. - -I2C Wiring on the Raspberry PI: - -| LidarLiteV3 Wire | Raspberry PI GPIO Pin (Physical Numbering) | -|-----------------------|--------------------------------------------| -| 5V (red) | 5V (pin 2) | -| Ground (black) | Ground (pin 6) | -| Power enable (orange) | Optional, an available IO pin (pin 33) | -| Mode control (yellow) | Not used | -| I2C SCL (green) | SCL (pin 5) | -| I2C SDA (blue) | SDA (pin 3) | - -> Important! Don't forget to enable I2C via `raspi-config`. - -# Simple Example - -```csharp - -using (var llv3 = new LidarLiteV3(CreateI2cDevice())) -{ - // Take 10 measurements, each one second apart. - for (int i = 0; i < 10; i++) - { - Length currentDistance = llv3.MeasureDistance(); - Console.WriteLine($"Current Distance: {currentDistance.Centimeters} cm"); - Thread.Sleep(1000); - } -} - -I2cDevice CreateI2cDevice() -{ - var settings = new I2cConnectionSettings(1, LidarLiteV3.DefaultI2cAddress); - return I2cDevice.Create(settings); -} - -``` - -# Advance Usage - -## Power Modes - -Power can be controlled to the device via a GPIO pin. Use the optional constructor parameters to -specify the GPIO controller and a power enable pin number (numbering scheme depends on GpioController). - -```csharp -int powerEnablePin = 13; -using (var llv3 = new LidarLiteV3(CreateI2cDevice(), new GpioController(), powerEnablePin)) -{ - // Power off the device. - llv3.PowerOff(); - // Device is completely turned off. - Console.WriteLine("Device is off."); - Thread.Sleep(5000); - // Power on the device, device is ready in ~22ms. - Console.WriteLine("Device is on."); - llv3.PowerOn(); - // Sleep 50ms. - Thread.Sleep(50); - // Get a reading. - Length currentDistance = llv3.MeasureDistance(); - Console.WriteLine($"Current Distance: {currentDistance.Centimeters} cm"); -} -``` - -It's also possible to disable the receiver circuit (saving 40 mA) or put the device to sleep -(saving 20 mA). However, it's recommended to use the power enable pin instead -since the initialization time is only 2 ms shorter. - -```csharp -using (var llv3 = new LidarLiteV3(CreateI2cDevice())) -{ - llv3.PowerMode = PowerMode.Sleep; -} -``` - -# Repetition Mode - -Instead of getting measurements on-demand, the device can be configure to repeat n number of -times, or infinitely. - -This is configured via `SetMeasurementRepetitionMode` passing in a mode (`Off`, `Repeat`, or -`RepeatInfinitely`), a loop count (if mode is `Repeat`), and a delay between measurements (default to -10 hz). A delay of `20` is about `100 hz`. - -With a repetition mode set, use `Distance` to retrieve the current readings in `Length`. -Use `DifferenceBetweenLastTwoDistances` to get a velocity reading. Negative values -indicate that the object is moving toward the device, positive indicates it's moving away. The value -is dependent on the delay, and the default 10 hz is about 0.1 m/s. - -```csharp -using (var llv3 = new LidarLiteV3(CreateI2cDevice())) -{ - llv3.SetMeasurementRepetitionMode(MeasurementRepetitionMode.RepeatIndefinitely); - - while(true) - { - Thread.Sleep(5); - Length currentDistance = llv3.Distance; - Length currentVelocity = llv3.DifferenceBetweenLastTwoDistances; - } -} -``` - -# Change the I2C Address - -By default, the device has an address of `0x62`. It's possible to change this address to -resolve a conflict with another device or to run multiple devices. - -Available addresses are 7-bit values with a 0 in the LSB order. - -```csharp -using (var llv3 = new LidarLiteV3(CreateI2cDevice())) -{ - // Set device from default `0x62` to `0x68` - llv3.SetI2cAddressAndDispose(0x68); -} - -// Connect to the device again with the new address. -var settings = new I2cConnectionSettings(1, 0x68); -var i2cDevice = I2cDevice.Create(settings); - -using (var llv3 = new LidarLiteV3(i2cDevice)) -{ - // ... -} - -``` - -# Optimization - -The default settings should work well, but several tweaks can be made to adjust the device. -See the manual for more details. - -## Change Acquistion Count - -To isolate the signal from the noise, the device performs a series of acquisitions and sums up the -result until a peak is found. The number of acquistions can be configured via -`MaximumAcquisitionCount` (default: 128). - -Less acquisitions result in faster measurements, but limits the max range and produces more -erroneous readings. The number roughly correlates to an acquistion rate of n/count and n^(1/4). - -```csharp -using (var llv3 = new LidarLiteV3(CreateI2cDevice())) -{ - llv3.MaximumAcquisitionCount = 100 -} -``` - -## Quick Termination Mode - -Faster acquisition readings, but with slightly more chance of erroneous readings. - -```csharp -using (var llv3 = new LidarLiteV3(CreateI2cDevice())) -{ - llv3.AcquistionMode |= AcquistionMode.EnableQuickTermination; -} -``` - -## Detection Sensitivity - -The threshold when a peak is found can be configured via `AlgorithmByPassThreshold`. By default, -this is 0 which uses an internal algorithm to determine the threshold. - -Recommended non-default values are 32 for higher sensitivity but higher erronenous readings -and 96 for reduced sensitivity with fewer erroneous readings. - -```csharp -using (var llv3 = new LidarLiteV3(CreateI2cDevice())) -{ - llv3.AlgorithmBypassThreshold = 32 -} -``` - -# Reference - -[Official Manual and Technical Spec](http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf) diff --git a/src/devices/LiquidLevel/README.md b/src/devices/LiquidLevel/README.md index 406df9c0f7..f177fd6c82 100644 --- a/src/devices/LiquidLevel/README.md +++ b/src/devices/LiquidLevel/README.md @@ -2,11 +2,17 @@ Digital liquid level switches are devices that can detect the presence of liquid/water. GPIO can be used to communicate with the devices. -## Device Family +## Documentation The implementation supports any single pin output digital liquid level switch. +- LLC200D3SH sensor [datasheet](https://cdn-shop.adafruit.com/product-files/3397/3397_datasheet_actual.pdf) + + ## Usage + +Define the LLC200D3SH sensor using the LiquidLevelSwitch class. + ```c# using (LiquidLevelSwitch sensor = new LiquidLevelSwitch(23, PinValue.Low)) { @@ -22,3 +28,9 @@ using (LiquidLevelSwitch sensor = new LiquidLevelSwitch(23, PinValue.Low)) ``` An example on how to use the specific LLC200D3SH device binding is available in the [samples](samples) folder. + +## LLC200D3SH Circuit + +The following fritzing diagram illustrates one way to wire up the Optomax LLC200D3SH digital liquid level switch with a Raspberry Pi. + +![Raspberry Pi Breadboard diagram](rpi-llc200d3sh_bb.png) diff --git a/src/devices/LiquidLevel/samples/rpi-llc200d3sh.fzz b/src/devices/LiquidLevel/rpi-llc200d3sh.fzz similarity index 100% rename from src/devices/LiquidLevel/samples/rpi-llc200d3sh.fzz rename to src/devices/LiquidLevel/rpi-llc200d3sh.fzz diff --git a/src/devices/LiquidLevel/samples/README.md b/src/devices/LiquidLevel/samples/README.md deleted file mode 100644 index 93eb5aa4f0..0000000000 --- a/src/devices/LiquidLevel/samples/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Digital liquid level switch Samples - -## LLC200D3SH Circuit - -The following fritzing diagram illustrates one way to wire up the Optomax LLC200D3SH digital liquid level switch with a Raspberry Pi. - -![Raspberry Pi Breadboard diagram](rpi-llc200d3sh_bb.png) - -## Code - -Define the LLC200D3SH sensor using the LiquidLevelSwitch class. - -```C# -using (Llc200d3sh sensor = new Llc200d3sh(23)) -{ - while (true) - { - // read liquid level switch - Console.WriteLine($"Detected: {sensor.IsLiquidPresent()}"); - Console.WriteLine(); - - Thread.Sleep(1000); - } -} -``` - -## References - -- LLC200D3SH sensor ([Datasheet](https://cdn-shop.adafruit.com/product-files/3397/3397_datasheet_actual.pdf)) diff --git a/src/devices/LiquidLevel/samples/rpi-llc200d3sh_bb.png b/src/devices/LiquidLevel/samples/rpi-llc200d3sh_bb.png deleted file mode 100644 index a04e31d4b2..0000000000 Binary files a/src/devices/LiquidLevel/samples/rpi-llc200d3sh_bb.png and /dev/null differ diff --git a/src/devices/Lm75/samples/LM75_circuit.fzz b/src/devices/Lm75/LM75_circuit.fzz similarity index 100% rename from src/devices/Lm75/samples/LM75_circuit.fzz rename to src/devices/Lm75/LM75_circuit.fzz diff --git a/src/devices/Lm75/samples/LM75_circuit_bb.png b/src/devices/Lm75/LM75_circuit_bb.png similarity index 100% rename from src/devices/Lm75/samples/LM75_circuit_bb.png rename to src/devices/Lm75/LM75_circuit_bb.png diff --git a/src/devices/Lm75/README.md b/src/devices/Lm75/README.md index 5f35815670..1b785d9e4e 100644 --- a/src/devices/Lm75/README.md +++ b/src/devices/Lm75/README.md @@ -1,10 +1,15 @@ # LM75 - Digital Temperature Sensor + The LM75 is a temperature sensor, Delta-Sigma analog-to-digital converter, and digital over-temperature detector with I2C interface. -## Sensor Image -![](sensor.jpg) +## Documentation + +- LM75 [datasheet](https://cdn.datasheetspdf.com/pdf-down/L/M/7/LM75_NationalSemiconductor.pdf) + +![sensor](sensor.jpg) ## Usage + ```C# I2cConnectionSettings settings = new I2cConnectionSettings(1, Lm75.DefaultI2cAddress); I2cDevice device = I2cDevice.Create(settings); @@ -15,5 +20,35 @@ using(Lm75 sensor = new Lm75(device)) } ``` -## References -https://cdn.datasheetspdf.com/pdf-down/L/M/7/LM75_NationalSemiconductor.pdf +## LM75 Example + +### Circuit + +![circuit](LM75_circuit_bb.png) + +* SCL - SCL +* SDA - SDA +* VCC - 5V +* GND - GND + +### Code + +```C# +I2cConnectionSettings settings = new I2cConnectionSettings(1, Lm75.DefaultI2cAddress); +I2cDevice device = I2cDevice.Create(settings); + +using(Lm75 sensor = new Lm75(device)) +{ + while (true) + { + Console.WriteLine($"Temperature: {sensor.Temperature.Celsius} ℃"); + Console.WriteLine(); + + Thread.Sleep(1000); + } +} +``` + +### Result + +![running result](RunningResult.jpg) diff --git a/src/devices/Lm75/samples/RunningResult.jpg b/src/devices/Lm75/RunningResult.jpg similarity index 100% rename from src/devices/Lm75/samples/RunningResult.jpg rename to src/devices/Lm75/RunningResult.jpg