Problem about get pressure data combines with GPS

Hi~

I'm trying to get data from two MS5611 pressure sensor using I2C & SPI communication protocols combined with GPS data. At first, the data fluctuates normally without connecting GPS. But the data of SPI fluctuates unusual(pressure change up to 30 pa).I use ublox neo 7m GPS modulus.

awaiting for your responses

two MS5611 pressure sensor using I2C & SPI

Does that mean that one sensor is on the I2C bus and the other on the SPI bus? Why not both on the same bus?

What is powering your circuit? Which Arduino are you using?

Please post a picture of your wiring or (preferably) a schematic and your code. Please read the "How to use the forum-Please read" stickies to see how to format and post code.

Yes, one sensor is on I2C bus, and the other is on SPI bus. I use mega 2560. Since there is only one pair of I2C communication pins, I use SPI to get data from the second sensor. The power is supplied by computer. The sketch, datasheet, and library(the link) I used is posted below. I connect pin 53 to CSB of sensor and use pin 10 and 11 as RX and TX connectes to GPS respectively.

The library:GitHub - vic320/Arduino-MS5803-14BA: An Arduino library for the MS5803-14BA pressure/temperature sensor. Works with SPI and i2C.

The performance of MS5803 is similar to MS5611.

The datasheet of MS5611:http://www.te.com/commerce/DocumentDelivery/DDEController?Action=srchrtrv&DocNm=MS5611-01BA03&DocType=Data+Sheet&DocLang=English

#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <Wire.h>
#include "MS5803_2.h"
#include "MS5803.h"
#include<Timer.h>

// Chip Select pin for SPI
#define SENSOR_CS_PIN_2 53

// Use this constructor for SPI
MS5803_2 sensor = MS5803_2(SENSOR_CS_PIN_2);

// Use this constructor for i2c - Address is set in the library implementation file. Default is 0x76.
MS5803 sensor2 = MS5803();

TinyGPSPlus gps;
SoftwareSerial ss(10,11);
Timer t,s;

float p1, p2, p3, p4;
float d, d1, d2;
static const uint32_t Baud = 9600;
int h, mi, sec, y, m, dat;

void setup() {
  // Start the serial ports.
  Serial.begin( Baud );
  delay(3000);

  ss.begin(9600);
  s.every(3000,getGPS);
  t.every(3000,getPressure);

  // Initialize the sensor which resets the sensor, downloads the needed coefficients.
  sensor.initalizeSensor();
  sensor2.initalizeSensor();
  
}

void loop() {
  
  // Call read sensor first, which downloads the sensor data and converts it to
  // mBars and Degrees C.
  sensor.readSensor();
  sensor2.readSensor();

  delay(5);

  while(ss.available() > 0)
  {
    if(gps.encode(ss.read()))
    {
      if(gps.date.isValid())
      {
        m = gps.date.month();
        dat = gps.date.day();
        y = gps.date.year();
      }
      else
      {
      Serial.print("INVALID");
      }
      if(gps.time.isValid())
      {
        h = gps.time.hour() + 8;
        m = gps.time.minute();
        sec = gps.time.second();
      }
      else
      {
        Serial.print("INVALID");
      }
    }
  }
      
  if(millis() > 5000 && gps.charsProcessed() < 10)
  {
    Serial.println("No GPS detected : check wiring.");
    while(true);
  }

  s.update();
  t.update();

  //Just to make it easier to read. 
  //The sensor can be read as fast as desired. 
}

void getPressure()
{
  p3 = sensor.pressure();
  d1 = p3 - p1;
  p4 = sensor2.pressure();
  d2 = p4 - p2;
  d = d2 - d1;

  Serial.print(",");
  Serial.print(p3);
  Serial.print("  ,  ");
  Serial.print(p4);

  Serial.print("  ,  ");
  Serial.print(d1);
  Serial.print(" , ");
  Serial.print(d2);
  Serial.print(" , ");
  Serial.println(d);

  p1 = p3;
  p2 = p4;
}

void getGPS()
{ 
  Serial.print(m);
  Serial.print("/");
  Serial.print(dat);
  Serial.print("/");
  Serial.print(y);

  Serial.print(" ");
    
  if(h > 24)
    h = h - 24;
  if(h < 10)
    Serial.print("0");
  Serial.print(h);
  Serial.print(":");
  if(gps.time.minute() < 10)
    Serial.print("0");
  Serial.print(m);
  Serial.print(":");
  if(gps.time.second() < 10)
    Serial.print("0");
  Serial.print(sec);   
}

I think that you don't understand the concept of the bus. The SPI and I2C busses are made to take multiple devices, on their respective bus, in parallel. The I2C bus distinguishes individual devices by their address. The SPI bus distinguishes individual devices by their chip select pin. So both of the pressure transducer modules can be on the same pins (with the exception of the CS pins for SPI). SPI has SCLK, MOSI, MISO in to each part plus a CS pin for each. I2C has SDA and SCL in parallel to each device (don't forget the pullups). The data sheet, on pages 6 and 7, tell how to set the device to use which bus (PS pin) and how to address 2 modules using I2C.

Thanks for your response. I'll modify the sketch and try to communicate with both the sensors using I2C. So the problem is that I shall use the same protocol?

Move your GPS to one of the hardware serial ports, your SoftwareSerial interrupts are breaking the comms
on the other bus(s) I think.

Thanks. I'll try to modify the connection about GPS.