Read MS5611 i2c sensor?

Hi.

I’m working into a project and I need to read info from a i2c sensor…

Datasheet says there are 5 commands:

I’m very new to this commands so Could anyone explain me on to use the commands and receive press info from sensor?

Info from datasheet(page 6) - http://www.daedalus.ei.tum.de/attachments/article/61/MS5611-01BA01.pdf

COMMANDS 
The MS5611-01BA has only five basic commands: 
1. Reset 
2. Read PROM (128 bit of calibration words) 
3. D1 conversion 
4. D2 conversion 
5. Read ADC result (24 bit pressure / temperature)

I know there are some libraries on internet but I just wanted to know the basics

I’ll apreciate ANY help!

tks

moderator - updated title

nobody?

Hi.. Could anybody answer some questions about i2c devices?

I'm trying to make a sensor works.. but I'm kind of confused about which command send etc..

Hello there!

Thats the sensor

http://www.daedalus.ei.tum.de/attachments/article/61/MS5611-01BA01.pdf

I've checked page 6 and there are 5 comands.. I just wanted to receive the pressure all commands are mandatory?

Could you hep me on that?

Tks a lot

There is a very good tutorial about I2C here - http://tronixstuff.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/ -

It has code , do's and dont's , and a lot of information that should help you to get started.

Hello there!

Tks for the link Its so helpful!

But for some reason I need to to some additional settings to my Device that is not working at all…

If you have an Idea about ow to deal with the registers in my sensor I would appreciate.

I have just looked at the datasheet and it says the command 0x00 returns the "Read ADC result (24 bit pressure / temperature) "

It just returns -1

#include <Wire.h>


byte address = 0x77;

void setup()
{
	Serial.begin(115200);
	Wire.begin();

	Wire.beginTransmission(address);
	Wire.write(0x00);
	Wire.endTransmission();
}
int tempreg;

void loop() {

	Wire.requestFrom(address, byte(1));
	tempreg = Wire.read();
	Serial.println(tempreg);
}

Any idea?

Regards

Still not working.. Always returns -1

Any Idea?

putting the relevant code to read register 0 in one function, and include an error status

so please try this (code is not tested)

#include <Wire.h>

int tempreg;

void setup()
{
  Wire.begin();
  Serial.begin(115200);
  Serial.println("demo v0.01");
}


void loop() 
{
  tempreg = getTemperature(0x77);  // fill in the right address here
  Serial.println(tempreg);

  delay(1000);
}

int getTemperature(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x00);
  int result = Wire.endTransmission();  // if I2C fails 
  if (result == 0)
  {
    Wire.requestFrom(address, 1);
    return Wire.read();
   }
  Serial.print("Error:\t");
  Serial.println(result);
  return -999;  // to indicate an error value
}

Hello there!

First of all, THANK you very much for the help!

The community keep growing with people like you. tks

Using this code I found the device address is 0x77

	for (int i = 0; i < 120; i++)
	{
		Wire.beginTransmission(i);
		if (Wire.endTransmission() == 0)
		{
			Serial.print("Adsress Found: ");
			Serial.println(i);
			Serial.print(" (0x");
			Serial.print(i, HEX);
			Serial.println(")");
		}
		delay(5);
	}

using the address, I have tested your code but it returned:

demo v0.01
0
0
0
0
0
0
0

its like… there are no errors but only returns… 0…

Maybe some parameter is needed?

please check the attachment about parameters

Capture.PNG

Still trying to get it working… I have tested using te commands ( as datasheet) and doesn’t matter what I change… I keep receiving
:

-1
-1
-1
-1
-1
-1
-1

To be honest, I didn’t understand how to understand this datasheet command table…

Any help will be appreciated…

#include <Wire.h>

int tempreg;
byte vaddress = 0x77;

void setup()
{
	Serial.begin(115200);

	Wire.begin();

	Wire.beginTransmission(vaddress);
	Wire.write(0x00);
	Wire.endTransmission();

	Wire.beginTransmission(vaddress);
	Wire.write(0xA0);
	Wire.endTransmission();

	Wire.beginTransmission(vaddress);
	Wire.write(0x50);
	Wire.endTransmission();

	Wire.beginTransmission(vaddress);
	Wire.write(0x58);
	Wire.endTransmission();

	Wire.beginTransmission(vaddress);
	Wire.write(0x00);
	Wire.endTransmission();
}

void loop()
{
	Wire.requestFrom(0x77, 1);
	Serial.println(Wire.read());

	delay(500);
}

You sent a bunch of requests. Then, every time through loop() you request 1 byte. Then, regardless of whether or not there is anything to read, you read it. Why?

PaulS:
You sent a bunch of requests. Then, every time through loop() you request 1 byte. Then, regardless of whether or not there is anything to read, you read it. Why?

Hi!

Sorry… Could you explain more about this, paulS?

What you are doing is like going to someone's house, knocking on the door, and going in even if they are not home.

The Wire.requestFrom() method tells you how many bytes it got. Quit throwing that value away, and quit reading if there is nothing to read. Look at Rob's code.

PaulS:
What you are doing is like going to someone’s house, knocking on the door, and going in even if they are not home.

The Wire.requestFrom() method tells you how many bytes it got. Quit throwing that value away, and quit reading if there is nothing to read. Look at Rob’s code.

Hi PaulS.

Yes I was doing tons of tests here and still don’t know how to solve my problem.

I wish I had 10% of knowledge you have. Maybe someday…:slight_smile:

What I know is that I just can’t read this sensor(even using rob’s code) that returns only “0”

Maybe I’m missing some command or something.

Well if you have some free time and give me a small sample code with the commands that datasheet provides, I would appreciate it very much…

Thank you so much.

Can you do a scan of the I2C - http://forum.arduino.cc/index.php?topic=197360.0 -
to see if the sensor can be reached at all?

Please post the output.

just a thought: did you swap SDA and SCL line?

Hi,Rob.

Just did the test and the address in my case was right..(address: 0x77)

I think my problem is still passing the commands to the device..

te datasheet says there are 5 basic commands...

COMMANDS 
The MS5611-01BA has only five basic commands: 
1. Reset 
2. Read PROM (128 bit of calibration words) 
3. D1 conversion 
4. D2 conversion 
5. Read ADC result (24 bit pressure / temperature)

Here's the result of scanning.

TIME	DEC	HEX		50	100	200	250	400	500	800	[KHz]
------------------------------------------------------------------------------------------------
51224	8	0x8		.	.	.	.	.	.	.
51228	9	0x9		.	.	.	.	.	.	.
51232	10	0xA		.	.	.	.	.	.	.
51236	11	0xB		.	.	.	.	.	.	.
51240	12	0xC		.	.	.	.	.	.	.
51247	13	0xD		.	.	.	.	.	.	.
51251	14	0xE		.	.	.	.	.	.	.
51255	15	0xF		.	.	.	.	.	.	.
51259	16	0x10		.	.	.	.	.	.	.
51263	17	0x11		.	.	.	.	.	.	.
51267	18	0x12		.	.	.	.	.	.	.
51271	19	0x13		.	.	.	.	.	.	.
51277	20	0x14		.	.	.	.	.	.	.
51281	21	0x15		.	.	.	.	.	.	.
51286	22	0x16		.	.	.	.	.	.	.
51290	23	0x17		.	.	.	.	.	.	.
51294	24	0x18		.	.	.	.	.	.	.
51300	25	0x19		.	.	.	.	.	.	.
51304	26	0x1A		.	.	.	.	.	.	.
51308	27	0x1B		.	.	.	.	.	.	.
51312	28	0x1C		.	.	.	.	.	.	.
51316	29	0x1D		.	.	.	.	.	.	.
51320	30	0x1E		.	.	.	.	.	.	.
51326	31	0x1F		.	.	.	.	.	.	.
51331	32	0x20		.	.	.	.	.	.	.
51335	33	0x21		.	.	.	.	.	.	.
51339	34	0x22		.	.	.	.	.	.	.
51343	35	0x23		.	.	.	.	.	.	.
51349	36	0x24		.	.	.	.	.	.	.
51353	37	0x25		.	.	.	.	.	.	.
51357	38	0x26		.	.	.	.	.	.	.
51361	39	0x27		.	.	.	.	.	.	.
51365	40	0x28		.	.	.	.	.	.	.
51369	41	0x29		.	.	.	.	.	.	.
51376	42	0x2A		.	.	.	.	.	.	.
51380	43	0x2B		.	.	.	.	.	.	.
51384	44	0x2C		.	.	.	.	.	.	.
51388	45	0x2D		.	.	.	.	.	.	.
51392	46	0x2E		.	.	.	.	.	.	.
51396	47	0x2F		.	.	.	.	.	.	.
51402	48	0x30		.	.	.	.	.	.	.
51406	49	0x31		.	.	.	.	.	.	.
51410	50	0x32		.	.	.	.	.	.	.
51415	51	0x33		.	.	.	.	.	.	.
51419	52	0x34		.	.	.	.	.	.	.
51425	53	0x35		.	.	.	.	.	.	.
51429	54	0x36		.	.	.	.	.	.	.
51433	55	0x37		.	.	.	.	.	.	.
51437	56	0x38		.	.	.	.	.	.	.
51441	57	0x39		.	.	.	.	.	.	.
51445	58	0x3A		.	.	.	.	.	.	.
51451	59	0x3B		.	.	.	.	.	.	.
51456	60	0x3C		.	.	.	.	.	.	.
51460	61	0x3D		.	.	.	.	.	.	.
51464	62	0x3E		.	.	.	.	.	.	.
51468	63	0x3F		.	.	.	.	.	.	.
51472	64	0x40		.	.	.	.	.	.	.
51478	65	0x41		.	.	.	.	.	.	.
51482	66	0x42		.	.	.	.	.	.	.
51486	67	0x43		.	.	.	.	.	.	.
51490	68	0x44		.	.	.	.	.	.	.
51494	69	0x45		.	.	.	.	.	.	.
51501	70	0x46		.	.	.	.	.	.	.
51505	71	0x47		.	.	.	.	.	.	.
51509	72	0x48		.	.	.	.	.	.	.
51513	73	0x49		.	.	.	.	.	.	.
51517	74	0x4A		.	.	.	.	.	.	.
51521	75	0x4B		.	.	.	.	.	.	.
51527	76	0x4C		.	.	.	.	.	.	.
51531	77	0x4D		.	.	.	.	.	.	.
51535	78	0x4E		.	.	.	.	.	.	.
51539	79	0x4F		.	.	.	.	.	.	.
51544	80	0x50		.	.	.	.	.	.	.
51548	81	0x51		.	.	.	.	.	.	.
51554	82	0x52		.	.	.	.	.	.	.
51558	83	0x53		.	.	.	.	.	.	.
51562	84	0x54		.	.	.	.	.	.	.
51566	85	0x55		.	.	.	.	.	.	.
51570	86	0x56		.	.	.	.	.	.	.
51576	87	0x57		.	.	.	.	.	.	.
51580	88	0x58		.	.	.	.	.	.	.
51585	89	0x59		.	.	.	.	.	.	.
51589	90	0x5A		.	.	.	.	.	.	.
51593	91	0x5B		.	.	.	.	.	.	.
51597	92	0x5C		.	.	.	.	.	.	.
51603	93	0x5D		.	.	.	.	.	.	.
51607	94	0x5E		.	.	.	.	.	.	.
51611	95	0x5F		.	.	.	.	.	.	.
51615	96	0x60		.	.	.	.	.	.	.
51619	97	0x61		.	.	.	.	.	.	.
51623	98	0x62		.	.	.	.	.	.	.
51630	99	0x63		.	.	.	.	.	.	.
51634	100	0x64		.	.	.	.	.	.	.
51638	101	0x65		.	.	.	.	.	.	.
51642	102	0x66		.	.	.	.	.	.	.
51648	103	0x67		.	.	.	.	.	.	.
51652	104	0x68		.	.	.	.	.	.	.
51656	105	0x69		.	.	.	.	.	.	.
51660	106	0x6A		.	.	.	.	.	.	.
51666	107	0x6B		.	.	.	.	.	.	.
51671	108	0x6C		.	.	.	.	.	.	.
51675	109	0x6D		.	.	.	.	.	.	.
51679	110	0x6E		.	.	.	.	.	.	.
51683	111	0x6F		.	.	.	.	.	.	.
51689	112	0x70		.	.	.	.	.	.	.
51693	113	0x71		.	.	.	.	.	.	.
51697	114	0x72		.	.	.	.	.	.	.
51701	115	0x73		.	.	.	.	.	.	.
51707	116	0x74		.	.	.	.	.	.	.
51712	117	0x75		.	.	.	.	.	.	.
51716	118	0x76		.	.	.	.	.	.	.
51720	119	0x77		V	V	V	V	V	V	V

1 devices found in 508 milliseconds.
Port closed

from datasheet:
After the conversion, using ADC read command the result is clocked out with the MSB first.
If the conversion is not executed before the ADC read command, or the ADC read command is repeated,
it will give 0 as the output result.

exactly what you saw.

please try this (i do not have such sensor)

//
//    FILE: MS5611.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.00
// PURPOSE: 
//    DATE: 
//     URL:
//
// Released to the public domain
//

#include <Wire.h>

int tempreg;

void setup()
{
  Wire.begin();
  Serial.begin(115200);
  Serial.println("demo v0.03");

  Serial.print("reset:\t");  
  Serial.println(reset(0x77));
  delay(1000);

  int conv = convertD1(0x77, 8);
  Serial.println(conv);
  delay(1000);
  int tempreg = getTemperature(0x77);  // fill in the right address here
  Serial.println(tempreg);
  delay(1000);

  conv = convertD2(0x77, 8);
  Serial.println(conv);  
  delay(1000);
  tempreg = getTemperature(0x77);  // fill in the right address here
  Serial.println(tempreg);
  delay(1000);
  
  
  for (int reg=0; reg<8; reg++)
  {
    uint16_t val = readProm(0x77, reg);
    Serial.println(val, HEX);
    delay(1000);
  }
  
  Serial.println("done...");
}


void loop(){
}


int reset(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x1E);
  return Wire.endTransmission();
}

int getTemperature(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x00);
  int result = Wire.endTransmission();  // if I2C fails 
  if (result == 0)
  {
    int nr = Wire.requestFrom(address, 1);
    if (nr > 0) return Wire.read();
    return -998;
  }
  Serial.print("Error:\t");
  Serial.println(result);
  return -999;  // to indicate an error value
}


int convertD1(int address, int bits)
{
  bits = constrain(bits, 8, 12);
  int offset = (bits - 8) * 2;

  Wire.beginTransmission(address);
  Wire.write(0x40 + offset);
  int result = Wire.endTransmission();  // if I2C fails 
  if (result == 0)
  {
    return 0;
  }
  Serial.print("Error:\t");
  Serial.println(result);
  return -999;  // to indicate an error value
}

int convertD2(int address, int bits)
{
  bits = constrain(bits, 8, 12);
  int offset = (bits - 8) * 2;

  Wire.beginTransmission(address);
  Wire.write(0x50 + offset);
  int result = Wire.endTransmission();  // if I2C fails 
  if (result == 0)
  {
    return 0;
  }
  Serial.print("Error:\t");
  Serial.println(result);
  return -999;  // to indicate an error value
}

uint16_t readProm(int address, int reg)
{
  reg = constrain(reg, 0, 7);
  reg = reg * 2;
  Wire.beginTransmission(address);
  Wire.write(0xA0 + reg);
  int result = Wire.endTransmission();  // if I2C fails 
  if (result == 0)
  {
    int nr = Wire.requestFrom(address, 2);
    if (nr >= 2) 
    {
      uint16_t val = Wire.read() * 256;
      val += Wire.read();
      return val;
    }
    return -998;
  }
  Serial.print("Error:\t");
  Serial.println(result);
  return -999;  // to indicate an error value
}

update: code updated

Hi Robs.. I Don't have any words for your help!!! I just appreciate it!

Wel. now something is different. Using your code tats what I get:

Port open
demo v0.03
reset:	0
0
121
0
127
50
D109
DC6B
7F52
7A67
7B7C
6CF6
B2D9
done...

Just need now transform it into press/temperature..

Tank you VERY MUCH

Good to hear it works,

I am trying to wrap it up in a basic library at the moment, might take some time.
I need your help to test and tune it as I do not have such sensor.