unosquare / raspberryio

The Raspberry Pi's IO Functionality in an easy-to-use API for Mono/.NET/C#
https://unosquare.github.io/raspberryio
Other
672 stars 104 forks source link

Raw Values of ADS1015 via I2C wrong scaling #237

Closed Scantraxxx closed 2 years ago

Scantraxxx commented 3 years ago

I connected an ADS1015 to my Raspberry Pi 4B like this: image But VDD is 5 V in this case.

I got a stable connection via I2C and can read and write to the registers.

I am trying to use the Unosquare Libs like this:

using System;
using System.Threading;
using Unosquare.RaspberryIO;
using Unosquare.WiringPi;
using Unosquare.RaspberryIO.Abstractions;

namespace TestBasysPiCSharp
{
    class Program
    {

        static void Main(string[] args)
        {
            Console.WriteLine("Starte Lesezyklen Analogwerte...!");

            Pi.Init<BootstrapWiringPi>();

            var myDevice = Pi.I2C.AddDevice(0x48);
            var a = new ADS1015(myDevice)
            {
                Gain = ADS1x15.AdsGain.GAINTWOTHIRDS
            };

            while (true)
            {
                Console.WriteLine("READING...");
                Console.WriteLine(a.ReadChannel(1));
                Console.WriteLine("READING DONE");
                Thread.Sleep(500);
            }
        }
    }
}

The problem is that a.ReadChannel(1) gives back totally wrong values. I can't properly scale them. If i change the gain, the values change, but still make no sense:

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">

Gain | 6144 |   -- | -- | -- Input voltage | Raw (expected) | Raw (real) 4.811 | 3207 | 1734 4.095 | 2730 | 1476 2.984 | 1989 | 1067 2.149 | 1432 | 775 1.019 | 679 | 367 0 | 0 | 0

The outputvalues look like the raw, unscaled output to me. But still they are not what they are supposed to be... The highest output is 1735, but it is supposed to be 4096, right?

I installed the latest versions via NuGet.

Is there something i'm missing?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.