Firmware: 4.2.0.0
Board: Netduino plus
The rgb schield work on 5 voltage
The temperature sensor works on 3,3 voltage
I am using Stefan's Toolbox for the rgb lcd schield. the example code works fine for the display.
I am using the BMP085 class for the sensor this class calls this constructor which makes a new instance of I2CDevice.Configuration
public BMP085(byte address, DeviceMode deviceMode)
{
Address = address;
_slaveConfig = new I2CDevice.Configuration(address, ClockRateKHz);
_oversamplingSetting = (byte)deviceMode;
// Get calibration data that will be used for future measurement taking.
GetCalibrationData();
// Take initial measurements.
TakeMeasurements();
// Take new measurements every 30 seconds.
_sensorTimer = new Timer(TakeMeasurements, null, 200, 30000);
}
The constructor of the pin extender on the shield is this constuctor calls a instance of Multi2C:
public Mcp23017(ushort Address = 0x20, int ClockRateKhz = 200)
{
// Initialises the device
this._Device = new MultiI2C(Address, ClockRateKhz);
// Set all pins to input by default
this._Device.Write(new byte[] { _IODIRA, 0xff }); // All pins on port A
this._Device.Write(new byte[] { _IODIRB, 0xff }); // All pins on port B
// Prepares all pins
this.Pins = new Mcp23017Port[16];
for (int PinNo = 0; PinNo < this.Pins.Length; ++PinNo)
this.Pins[PinNo] = new Mcp23017Port(this, PinNo);
}
The bmp085 sensor is called by (this code address is 0x77):
// Create instance of temp and pressure sensor
BMP085 tempAndPressureSensor = new BMP085(0x77, BMP085.DeviceMode.UltraLowPower);
The rgb lcd schield contrusctor is called by (this code address is 0x20)
public Mcp23017(ushort Address = 0x20, int ClockRateKhz = 200)
What i was trying to do is read the temperature and pressure from the bmp085 and write it to the rgb lcd shield. so both must work independantly.
in my main code i declared both devices as following:
[font="arial, helvetica, sans-serif;"]BMP085 tempAndPressureSensor = new BMP085(0x77, BMP085.DeviceMode.UltraLowPower);
string temperature = tempAndPressureSensor.Celsius.ToString("F2");
string pressure = tempAndPressureSensor.Pascal.ToString();
Debug.Print("'The temperature is: " + temperature + " degrees and pressure is " + pressure +" Pascal.'");
// The Adafruit LCD Shield uses a MCP23017 IC as multiplex chip
Mcp23017 Mux = new Mcp23017();
// Pins 0 to 4 on the Mux-chip are connected to the buttons
IGPIPort ButtonSelect = Mux.Pins[0];
IGPIPort ButtonRight = Mux.Pins[1];[/font]
etc...
When i debug/execute this code it makes a instance of the sensor and prints the debug text. When it makes a instance of the mcp23017 i get an exception in the Multi2C class in the constructor:
public MultiI2C(ushort Address, int ClockRateKhz = 100)
{
// Sets the configuration in a local value
this._Configuration = new I2CDevice.Configuration(Address, ClockRateKhz);
// Sets the default timeout
this.Timeout = 100;
// If no I2C Device exists yet, we create it's first instance
if (_I2CDevice == null)
{
// Creates the SPI Device
_I2CDevice = new I2CDevice(this._Configuration); <-- error message
}
}
Error message is:
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
My guess is that Multi2C class and the BMP085 class both try to make a new instance of the I2CDevice configuration.
i am not a expert on i2c how can i make this work? refactor the bmp085 class in specific how to instance of i2c? saw a few examples on this forum but did not worked for me.
Thanks for the help