SoftI2C with Sparkfun MS5803

Hello, I am using the Sparkfun MS5803 in a project, it needs the I2C pins of the Arduino Uno, but I am already using those with a datalogger shield. My goal is to use I2C with other pins, I tried getting the SoftWire code from the SoftI2CMaster. to work with Sparkfun's library. The Sparkfun library uses Wire.h, i changed it to use SoftWire.h. But I am getting multiple defition errors. I Changed both the original .ino code and the .cpp code like this:

Before(.cpp) ->

#include <Wire.h> // Wire library is used for I2C
#include "SparkFun_MS5803_I2C.h"

After(.cpp) ->

#define SDA_PORT PORTC
#define SDA_PIN 4 // = A4
#define SCL_PORT PORTC
#define SCL_PIN 5 // = A5
#include <SoftWire.h> // Wire library is used for I2C
SoftWire Wire = SoftWire();

Before(.ino) ->

#include <Wire.h>
#include <SparkFun_MS5803_I2C.h>

After(.ino) ->

#define SDA_PORT PORTC
#define SDA_PIN 4 // = A4
#define SCL_PORT PORTC
#define SCL_PIN 5 // = A5
#include <Wire.h>
SoftWire Wire = SoftWire();

And get errors like this one:

libraries\SparkFun_MS5803-14BA_Breakout_Arduino_Library-master\SparkFun_MS5803_I2C.cpp.o (symbol from plugin): In function `ass_i2c_delay_half':

(.text+0x0): multiple definition of `Wire'

sketch\SparkFun_MS5803_Demo.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

I have tried multiple things, but if I do not change the cpp file I get an error, if I change the .cpp and the .ino file as I showed i get multiple definition errors, then tried not declaring the cosntants in the .ino file or the .cpp file and got different errors. What can I do to make Sparkfun's MS5803 to work with the SoftI2CMaster library?

The name "Wire" is already in use by Arduino. That is the "Wire" object of the "Wire" library.

Why is your goal to use the I2C bus with other pins ?
The I2C bus is a bus, you can add many sensors and chips to that bus. But they do require to use the same voltage levels and they all must have different I2C addresses.

Do you use this one ? SparkFun Pressure Sensor Breakout - MS5803-14BA - SEN-12909 - SparkFun Electronics.
That is a 3.3V sensor with 3.3V signals. You can damage the sensor when you connect it to an Arduino Uno, because the internal pullup resistors can leak current from the 5V to the sensor via SDA and SCL.

I am getting other errors most of them about a function declared in the .h file of SoftI2CMaster. I don't know how to fix that.

The datalogger shield uses SPI communication and when I had both libraries for i2c and spi running, the arduino program would just stop. Seems like they are not compatible.

Yes I am using that sensor. And I didn't know that about that voltage problem when changing the board to other pin. What can I do? Should I buy a datalogger that doesn't use those pins?

Thanks for the response Koepel :slight_smile:

This is a XY-problem :o
It is not a good idea to solve a problem by adding more problems :confused: You really have to fix the cause.

The hardware of SPI and I2C are seperate parts of the microcontroller and the libraries for SPI and I2C work very well in the same sketch. That means that something else is going on.

Tell us what you have and how it is connected. Please give links to where you bought it. Do you use long cables ? Can you show a photo of your project ? The I2C bus can be up to 50 cm.

Can you show the sketch ? Perhaps there is a problem with the used pins.

When the voltage levels of the I2C bus do not match, then you can use a voltage level shifter. Or you can use a newer 3.3V Arduino board.

When you say that the Arduino program would just stop, then that is not enough information for us. Can you add more Serial.println() messages and try to find where it stops ?
If it stops at Serial.begin() or SD.begin() or Wire.begin(), then you might have a conflict with pins.
If it stops at Wire.endTransmission(), then there is something wrong with the I2C bus.
If it stops when moving a motor, then there might be a power problem.

Okay I tried putting them together some while ago: MS5803 + Datalogger Shield Communication problem - Programming Questions - Arduino Forum..
The datalogger shield is this one . Its communication pins are fixed. The datalogger is inserted directly above the Arduino Uno. I connect the pressure sensor in the pins of the datalogger with short jumpers.

I am still testing. Here's a photo:

64894883_569885816868397_6908342075415068672_n.jpg

That is a clone of the Adafruit Data Logging Shield: Adafruit Assembled Data Logging shield for Arduino : ID 1141 : $13.95 : Adafruit Industries, Unique & fun DIY electronics and kits.
It's schematic is here: Adafruit Learning System.

It has the PCF8523 or DS1307 as RTC. They both have I2C address 0x68, so that address has been taken. The MS5803 has I2C address 0x76 or 0x77, so that is no problem.

It also has 10k pullup resistors from SDA to 5V and from SCL to 5V.
That is one more reason to use I2C level shifters for the pressure sensor. The pressure sensor may already be damaged by now.
Sparkfun says that the MS5803 had open drain drivers and therefor the SDA and SCL are compatible with 5V levels. I seriously doubt that. It is not specifically mentioned in the datasheet, that means those pins are not 5v tolerant and Sparkfun made a big mistake.

After fixing the 3.3V / 5V voltage levels, can you run a I2C Scanner ? It should detect both chips. After that you can move on and run a library for the sensor. Do not try to combine everything at once, make small steps.

Hi, everything works now! Looks like there was an issue with the compiler.

First I ran the I2C Scanner on both of them as in the photo and the shields got detected in their respective addresses, when i ran the sketches uploaded in my previous post the connections were the same, so something was pretty strange. Now I tested both shields separately and they worked fine, tried the same sketch from the other post when both had to work together and now it didn't even compile, it returned an error saying something about a compiler bug, searched for it and found a solution here. Now that the compiler issue was solved I compiled the program again and had no error. Then I uploaded the sketch and everything functioned fine.

Thank you! Now everything works and I understand better how it works.