Ejemplo n.º 1
0
 protected override void Write(Stm32Command command, ushort data, bool dataAvailable)
 {
     if (dataAvailable)
     {
         _gpioExpander.WriteAddressWord(Unsafe.As <Stm32Command, byte>(ref command), data);
     }
     else
     {
         _gpioExpander.Write(Unsafe.As <Stm32Command, byte>(ref command));
     }
 }
Ejemplo n.º 2
0
        private void ADS1115ReadValuesWiringPi(byte busId, byte i2cAddress, byte[] configDataChunk, byte[] convertDataChunk)
        {
            Pi.Init <BootstrapWiringPi>();

            II2CDevice ads1115 = Pi.I2C.AddDevice(i2cAddress);

            var configWord = (ushort)((configDataChunk[2] << 8) + configDataChunk[1]);

            // Write config register to the ADC
            //var currentConfig = ads1115.ReadAddressWord(ADS1115.ADS1115_REG_POINTER_CONFIG);
            //Console.WriteLine($"Setting original configuration ({currentConfig.ToString("X")}) to {config.ToString("X")}");

            ads1115.WriteAddressWord(configDataChunk[0], configWord);

            //currentConfig = ads1115.ReadAddressWord(ADS1115.ADS1115_REG_POINTER_CONFIG);
            //Console.WriteLine($"New configuration: {currentConfig.ToString("X")}");

            DateTime firstDataRead = DateTime.UtcNow;

            while (true)
            {
                // Read the conversion results
                ushort result  = (ushort)(ads1115.ReadAddressWord(convertDataChunk[0]));
                float  voltage = (float)(result < 32768 ? result : -(65536 - result)) * 2.048f / 65536.0f;

                j++;
                if (j % 1000 == 0)
                {
                    Console.WriteLine(String.Format("| ADC value: {0,5} V | sample rate: {1,7} SPS |", voltage.ToString("N", CultureInfo.InvariantCulture), ((double)j / (DateTime.UtcNow - firstDataRead).TotalSeconds).ToString("N")));
                }
            }
        }
Ejemplo n.º 3
0
 public void Write(int adress, ushort command) //for leds
 {
     try
     {
         _device.WriteAddressWord(adress, command);
         I2CGlobalError = false;
     }
     catch (Unosquare.RaspberryIO.Abstractions.Native.HardwareException)
     {
         I2CGlobalError = true;
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Write to the I2C register, ADS1x15 is byte swapped.
 /// </summary>
 /// <param name="registery">register address to write to</param>
 /// <param name="value">value to set</param>
 private void WriteRegister(byte registery, ushort value)
 {
     device.WriteAddressWord(registery, SwapWord(value));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Write to the I2C register, ADS1x15 is byte swapped.
 /// </summary>
 /// <param name="registery">register address to write to</param>
 /// <param name="value">value to set</param>
 public static void WriteAddressWordSwapped(this II2CDevice device, byte registery, ushort value)
 {
     device.WriteAddressWord(registery, SwapWord(value));
 }