Skip to content

Commit

Permalink
Documentation changes (second half): Use only a single README.md per …
Browse files Browse the repository at this point in the history
…device (#1610)
  • Loading branch information
krwq authored Aug 2, 2021
1 parent b467f71 commit 148fc42
Show file tree
Hide file tree
Showing 174 changed files with 2,180 additions and 2,329 deletions.
39 changes: 36 additions & 3 deletions src/devices/Lps25h/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,46 @@
# LPS25H - Piezoresistive pressure and thermometer sensor

Some of the applications mentioned by the datasheet:

- Altimeter and barometer for portable devices
- GPS applications
- Weather station equipment
- Sport watches

See [samples](samples/README.md) for information about usage.
## Documentation

- You can find the datasheet [here](https://www.st.com/resource/en/datasheet/lps25h.pdf)

## Usage

```csharp
class Program
{
// I2C address on SenseHat board
public const int I2cAddress = 0x5c;

static void Main(string[] args)
{
using (var th = new Lps25h(CreateI2cDevice()))
{
while (true)
{
var tempValue = th.Temperature;
var preValue = th.Pressure;
var altValue = WeatherHelper.CalculateAltitude(preValue, defaultSeaLevelPressure, tempValue);

## References
Console.WriteLine($"Temperature: {tempValue.Celsius:0.#}\u00B0C");
Console.WriteLine($"Pressure: {preValue.Hectopascal:0.##}hPa");
Console.WriteLine($"Altitude: {altValue:0.##}m");
Thread.Sleep(1000);
}
}
}

- https://www.st.com/resource/en/datasheet/lps25h.pdf
private static I2cDevice CreateI2cDevice()
{
var settings = new I2cConnectionSettings(1, I2cAddress);
return I2cDevice.Create(settings);
}
}
```
33 changes: 0 additions & 33 deletions src/devices/Lps25h/samples/README.md

This file was deleted.

107 changes: 104 additions & 3 deletions src/devices/Lsm9Ds1/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,114 @@
# LSM9DS1 - 3D accelerometer, gyroscope and magnetometer

LSM9DS1 internally uses 2 buses:

- Accelerometer and gyroscope
- Magnetometer

and therefore functionality has been split into 2 classes which allows using them independently.

See [samples](samples/README.md) for information about usage.
## Documentation

- You can find the datasheet [here](https://www.st.com/resource/en/datasheet/lsm9ds1.pdf)

## Usage

### Accelerometer and gyroscope

```csharp
class Program
{
public const int I2cAddress = 0x6A;

static void Main(string[] args)
{
using (var ag = new Lsm9Ds1AccelerometerAndGyroscope(CreateI2cDevice()))
{
while (true)
{
Console.WriteLine($"Acceleration={ag.Acceleration}");
Console.WriteLine($"AngularRate={ag.AngularRate}");
Thread.Sleep(100);
}
}
}

private static I2cDevice CreateI2cDevice()
{
var settings = new I2cConnectionSettings(1, I2cAddress);
return I2cDevice.Create(settings);
}
}
```

### Magnetometer

```csharp
class Magnetometer
{
public const int I2cAddress = 0x1C;

## References
public static void Run()
{
using (var m = new Lsm9Ds1Magnetometer(CreateI2cDevice()))
{
Console.WriteLine("Calibrating...");
Console.WriteLine("Move the sensor around Z for the next 20 seconds, try covering every angle");
Stopwatch sw = Stopwatch.StartNew();
Vector3 min = m.MagneticInduction;
Vector3 max = m.MagneticInduction;
while (sw.ElapsedMilliseconds < 20 * 1000)
{
Vector3 sample = m.MagneticInduction;
min = Vector3.Min(min, sample);
max = Vector3.Max(max, sample);
Thread.Sleep(50);
}
Console.WriteLine("Stop moving for some time...");
Thread.Sleep(3000);
const int intervals = 32;
bool[,] data = new bool[32,32];
Vector3 size = max - min;
int n = 0;
while (true)
{
n++;
Vector3 sample = m.MagneticInduction;
Vector3 pos = Vector3.Divide(Vector3.Multiply((sample - min), intervals - 1), size);
int x = Math.Clamp((int)pos.X, 0, intervals - 1);
int y = Math.Clamp((int)pos.Y, 0, intervals - 1);
data[x, y] = true;
if (n % 10 == 0)
{
Console.Clear();
Console.WriteLine("Now move the sensor around again but slower...");
for (int i = 0; i < intervals; i++)
{
for (int j = 0; j < intervals; j++)
{
if (i == x && y == j)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write('#');
Console.ResetColor();
}
else
{
Console.Write(data[i, j] ? '#' : ' ');
}
}
Console.WriteLine();
}
}
Thread.Sleep(50);
}
}
}

- https://www.st.com/resource/en/datasheet/lsm9ds1.pdf
private static I2cDevice CreateI2cDevice()
{
var settings = new I2cConnectionSettings(1, I2cAddress);
return I2cDevice.Create(settings);
}
}
```
101 changes: 0 additions & 101 deletions src/devices/Lsm9Ds1/samples/README.md

This file was deleted.

38 changes: 34 additions & 4 deletions src/devices/Max31856/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
# Max31856 - cold-junction compensated thermocouple to digital converter

## Summary
The Max31856 device is a SPI interface cold-junction compensated thermocouple to digital converter.

## Sensor Image
![Illustration of wiring from a Raspberry Pi device](device.jpg)

**Note:** _ThermocoupleType.K is configured for a K type thermocouple if you want to use a B,E,J,K,N,R,S, or T simply change the K to the thermocouple type of your choosing._

## References
## Documentation

**Max31856** [datasheet](https://datasheets.maximintegrated.com/en/ds/Max31856.pdf)
* Max31856 [datasheet](https://datasheets.maximintegrated.com/en/ds/Max31856.pdf)

## Usage

The Max31856.samples file contains a sample usage of the device. Note that this reads two temperatures. One is a connected thermocouple reading which can be read using the ```TryGetTemperature``` command and the other is the temperature of the device itself which can be read using the ```GetColdJunctionTemperature``` command. The Cold Junction Temperature is used internally to increase the accuracy of the thermocouple but can also be read if you find a use for it.

Create a new ```SpiConnectionSettings``` Class if using a Raspberry Pi do not change these settings.

```csharp
SpiConnectionSettings settings = new(0, 0)
{
ClockFrequency = Max31856.SpiClockFrequency,
Mode = Max31856.SpiMode,
DataFlow = 0
};
```

Create a new ```SpiDevice``` with the settings from above. Then create a new Max31856 device with the ```SpiDevice``` as well as the correct ```ThermocoupleType``` (see note below)
```csharp
using SpiDevice device = SpiDevice.Create(settings);
using Max31856 sensor = new(device, ThermocoupleType.K);
```

Now read the temperature from the device. Using the UnitsNet nuget you can see the units of your choosing. In this example you chan change```DegreesFahrenheit``` to ```DegreesCelsius``` or any other unit by changing ```.GetTemperature().DegreesFahrenheit``` to another unit of your choice.

```csharp
while (true)
{
Temperature tempColdJunction = sensor.GetColdJunctionTemperature();
Console.WriteLine($"Temperature: {tempColdJunction} ℃");
Thread.Sleep(2000);
}
```
30 changes: 0 additions & 30 deletions src/devices/Max31856/samples/README.md

This file was deleted.

File renamed without changes.
Loading

0 comments on commit 148fc42

Please sign in to comment.