Ejemplo n.º 1
0
        /// <summary>
        ///     Force the sensor to make a reading and update the relevanyt properties.
        /// </summary>
        /// <param name="startAddress">Start address for the read operation.</param>
        /// <param name="amount">Amount of data to read from the EEPROM.</param>
        public byte[] Read(ushort startAddress, ushort amount)
        {
            CheckAddress(startAddress, amount);
            var address = new byte[2];

            address[0] = (byte)((startAddress >> 8) & 0xff);
            address[1] = (byte)(startAddress & 0xff);
            _eeprom.WriteBytes(address);
            return(_eeprom.ReadBytes(amount));
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Send a command to the display.
 /// </summary>
 /// <param name="command">Command byte to send to the display.</param>
 private void SendCommand(byte command)
 {
     if (connectionType == ConnectionType.SPI)
     {
         dataCommandPort.Write(Command);
         spi.Write(new byte[] { command });
     }
     else
     {
         _I2CBus.WriteBytes(new byte[] { 0x00, command });
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Create a new ADXL362 object using the specified SPI module.
 /// </summary>
 /// <param name="module">SPI module to use.</param>
 /// <param name="chipSelect">Chip select pin.</param>
 /// <param name="speed">Speed of the SPI bus.</param>
 public ADXL362(SPI.SPI_module module, Cpu.Pin chipSelect, ushort speed = 10)
 {
     //
     //  ADXL362 works in SPI mode 0 (CPOL = 0, CPHA = 0).
     //
     _adxl362 = new SPIBus(module, chipSelect, speed);
     //
     //  Firstly, reset the sensor.
     //
     _adxl362.WriteBytes(new byte[] { Command.WriteRegister, Registers.SoftReset, 0x52 });
     Thread.Sleep(10);
     //
     //  Now start the sensor measurements.
     //
     _adxl362.WriteBytes(new byte[] { Command.WriteRegister, Registers.PowerControl, 0x02 });
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     Update the temperature and pressure from the sensor and set the Pressure property.
        /// </summary>
        public void Update()
        {
            //
            //  Tell the sensor to take a temperature and pressure reading, wait for
            //  3ms (see section 2.2 of the datasheet) and then read the ADC values.
            //
            _mpl115a2.WriteBytes(new byte[] { Registers.StartConversion, 0x00 });
            Thread.Sleep(5);
            var data = _mpl115a2.ReadRegisters(Registers.PressureMSB, 4);
            //
            //  Extract the sensor data, note that this is a 10-bit reading so move
            //  the data right 6 bits (see section 3.1 of the datasheet).
            //
            var pressure    = (ushort)(((data[0] << 8) + data[1]) >> 6);
            var temperature = (ushort)(((data[2] << 8) + data[3]) >> 6);

            Temperature = (float)((temperature - 498.0) / -5.35) + 25;
            //
            //  Now use the calculations in section 3.2 to determine the
            //  current pressure reading.
            //
            const double PRESSURE_CONSTANT   = 65.0 / 1023.0;
            var          compensatedPressure = _coefficients.A0 + ((_coefficients.B1 + (_coefficients.C12 * temperature))
                                                                   * pressure) + (_coefficients.B2 * temperature);

            Pressure = (float)(PRESSURE_CONSTANT * compensatedPressure) + 50;
        }
        /// <summary>
        ///     Send the data to the SPI interface.
        /// </summary>
        public void LatchData()
        {
            var data = new byte[_numberOfChips];

            for (var chip = 0; chip < _numberOfChips; chip++)
            {
                data[chip] = 0;
                byte bitValue = 1;
                var  offset   = chip * 8;
                for (var bit = 0; bit < 8; bit++)
                {
                    if (_bits[offset + bit])
                    {
                        data[chip] |= bitValue;
                    }
                    bitValue <<= 1;
                }
            }
            _spi.WriteBytes(data);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Send the data to the SPI interface.
        /// </summary>
        protected void LatchData()
        {
            var data = new byte[_numberOfChips];

            for (var chip = 0; chip < _numberOfChips; chip++)
            {
                var dataByte = _numberOfChips - chip - 1;
                data[dataByte] = 0;
                byte bitValue = 1;
                var  offset   = chip * 8;
                for (var bit = 0; bit < 8; bit++)
                {
                    if (_pins[offset + bit])
                    {
                        data[dataByte] |= bitValue;
                    }
                    bitValue <<= 1;
                }
            }
            _spi.WriteBytes(data);
        }
Ejemplo n.º 7
0
 /// <summary>
 ///     Reset the sensor.
 /// </summary>
 public void Reset()
 {
     _adxl362.WriteBytes(new byte[] { Command.WriteRegister, Registers.SoftReset, 0x52 });
     Thread.Sleep(10);
 }
Ejemplo n.º 8
0
 /// <summary>
 ///     Send a command to the display.
 /// </summary>
 /// <param name="command">Command byte to send to the display.</param>
 private void SendCommand(byte command)
 {
     _ssd1306.WriteBytes(new byte[] { 0x00, command });
 }
Ejemplo n.º 9
0
        void TransmitData()
        {
            _I2CBus.WriteBytes(transmissionData);

            Thread.Sleep(100);
        }