I2C - DSPC01 Digital Compass Pressure Sensor Module

Hi!
I'm new in this forum and of course.... I have a question that I can't answer with my knowleghe and I can't find the answer somewhere...

I have to DSPC01 sensor and I want to read the data from it through I2C.
Here is the information sheet for the DSPC01 http://www.dorji.com/docs/data/DSPC01.pdf

My code:

#include <Wire.h>
void setup() {
  Serial.begin(9600);
  //initialize network connection
  //delete second param if DHCP
  Ethernet.begin(mac, ip);
  Wire.begin();
  delay(1000);
}

void loop() {
while(true) {
    
    Wire.beginTransmission(0x20);
    Wire.write(0x70);
    int test = Wire.endTransmission();
    if (test != 0) {
      Serial.println("Transmission failed:");
      Serial.println(test);
    }
    
    Wire.requestFrom(0x21, 2);
    if (Wire.available()) {
       temperature = Wire.read();
       Serial.println("Available");
    }
}

I always get transmission failed. I also tried 0x10 as beginTransmission and requestFrom param, because they want a 7bit value. It also didnt work.

So I don't know any further....

I also did a scan with the I2CScanner now and it didnt found an I2C interface...

What return value do you get from Wire.endTransmission()?

because they want a 7bit value.

Where in the datasheet did you found that information?

How have you wired the sensor to the Arduino?

What return value do you get from Wire.endTransmission()?

It's 2

Where in the datasheet did you found that information?

Here: Wire - Arduino Reference
address: the 7-bit address of the device to transmit to

How have you wired the sensor to the Arduino?

Data pin and clock pin to Arduino Uno Analog Pins 4 and 5
VCC to 3V and the 4 Ground to GND

Isn't that a 3v part you connect up to an arduino 5v i2c? Did you isolate it?

Insert Quote
Isn't that a 3v part you connect up to an arduino 5v i2c? Did you isolate it?

I2C's SCL and SDA are open drain, so the different levels (3V3 and 5V) often are quite fine as long as the pull-ups are small enough to get the speedy edges you need because the ATmega needs about 60% of VCC (3V) to detect a logic HIGH.

@OP: can you measure the pull-ups? The datasheet doesn't specify the value of the pull-up resistors. They may be to big.

Do you have an oscilloscope to check the signal curve? You might need a signal converter like this http://www.sparkfun.com/products/8745 to get the signal shaped clear enough for the Arduino to understand.

address: the 7-bit address of the device to transmit to

This is standard as one bit is used to control the direction of the communication (read or write).

The correct 7-bit address for your device seems to be 0x10, provide this to beginTransmission().

Have you had success with your DSPC01, baught the same module but I have no clue how I get it to run.

hy,

i also have those module and didnt get a single response

connected like described in the i2c/wire library,
checked the (short datasheet) and also tried - but no answer ....

my guess is that the wire library doesnt realy work propper for that device

did you had a look on the programmed sample ( in C) ?

maybe all the wake up processes interfere with the i2c wire library ...

im sad that i bought this and dont get it running .... :~

Try this sketch and show us the result:

#include <Wire.h>

#define DSCP01_ADDRESS   0x10
void setup() {
  Serial.begin(9600);
  Wire.begin();
}

void loop() {
  Wire.beginTransmission(DSCP01_ADDRESS);
  Wire.write(0x70); // wake up
  int test = Wire.endTransmission();
  if (test != 0) {
    Serial.println("Transmission failed:");
    Serial.println(test);
  }
  // wait for the sensor to wake up
  delay(1000);
  
  // send temperature command
  Wire.beginTransmission(DSCP01_ADDRESS);
  Wire.write(0x80); // request temperature
  Wire.endTransmission();
  Wire.requestFrom(DSCP01_ADDRESS, 2);
  if (Wire.available()) {
    uint t = Wire.read();
    t <<= 8;
    t |= Wire.read();
    int temperature = (t & 0x8000) ? -(t &0x7FFF) : t & 0x7FFF;
    Serial.print("Temp: ");
    Serial.print((float)temperature/10.0);
    Serial.println(" C");
  }
  // go to sleep
  Wire.beginTransmission(DSCP01_ADDRESS);
  Wire.write(0x71); // sleep
  Wire.endTransmission();
  delay(5000); // wait a bit, temperatue isn't changing fast
}

first of all - thx for your answer :slight_smile: - i hoped this thread isnt dead

serial output:

Transmission failed:
2
Transmission failed:
2

so i dont get an acknowledge....but that could have several reasons - or do u have any suggestions ?
( i've to say that i dont have an oszillograph/oszi at home ... so error detection might be hard or impossible ? :frowning: )

note:in your nice test prog:
at thise line is an "u" where it doesnt belong to ^^

uint t = Wire.read();

at thise line is an "u" where it doesnt belong to ^^

Wrong, it's just not the complete type. It should be uint16_t. It must be unsigned to keep it from getting errors from signed expansion.

How have you wired the module to the Arduino?

oh - big sry then - but when i write uint (for unsigned) i get an error ?

like in this link: Wire - Arduino Reference

Board I2C / TWI pins
Uno, Ethernet A4 (SDA), A5 (SCL)

VCC: to the 3.3V
SCK: A5
SDA: A4
GND: Arduino Ground

I hope i didnt make a big mistake at this early point

(as you might noticed im a bit of a beginner :roll_eyes:)

Based on some code written for a PIC controller to be used with this module, I changed the test code to the following. Could you try it?

#include <Wire.h>

#define DSCP01_ADDRESS   0x10
void setup() {
  Serial.begin(9600);
  Wire.begin();
  int res = 2;
  while (res != 0) {
    Wire.beginTransmission(DSCP01_ADDRESS);
    Wire.write(0x70); // wake up
    res = Wire.endTransmission();
  }
  // wait for the sensor to wake up
  delay(1000);
}

void loop() {
  // send temperature command
  Wire.beginTransmission(DSCP01_ADDRESS);
  Wire.write(0x80); // request temperature
  int test = Wire.endTransmission();
  if (test != 0) {
    Serial.println("Transmission failed:");
    Serial.println(test);
  }
  delay(200); // seems to be necessary
  Wire.requestFrom(DSCP01_ADDRESS, 2);
  if (Wire.available()) {
    uint16_t t = Wire.read();
    t <<= 8;
    t |= Wire.read();
    int temperature = (t & 0x8000) ? -(t &0x7FFF) : t & 0x7FFF;
    Serial.print("Temp: ");
    Serial.print((float)temperature/10.0);
    Serial.println(" C");
  }
  delay(1000); // wait a bit, temperatue isn't changing fast
}

ah cool,

hm - now i dont get any response on the serial monitor :frowning:
not even that connection failed or like last time no acknowledge

hm could i somehow destroyed something during the soldering process ?

im used to soldier a bit (built a few led cubes, my own litle radio device, power adapter and so on ... )
and i thought i soldered those 4 little pins quite well ... but now im not quite sure if i did something wrong - or im just a to big beginner that i get any response
the only things i built so far with an arduino was an led cube and a motor driver

The last change I did was ignoring the NAKs the Arduino gets from the module until it wakes up. I did that because the example code for the PIC did the same (although this was not specified in the datasheet). Maybe it runs now in an endless loop if the module does not wake up and answers with an ACK.
If you have one try to attach a scope or logic analyzer and check if the module is answering to any request. Debugging with just software changes gets now quite complicated. I'm not sure if your module got burned, it may be some other problem, but without checking the signal it's very difficult to help you more.

One thing you could try is programming your Arduino to continually request the temperature from the module and starting (powering) the Arduino a few seconds before you put power to the Vcc of the module. This way it should never go to sleep and immediately answer the requests.

ok i was afraid that there is no other way than to get to an oszi. - hm i will try

ok - so simply said - using your programm:

  1. load sketch on arduino
  2. power off - and plug out Vcc from modul
  3. power on arduino
  4. wait a sec
  5. plug in Vcc ( 3.3V) for the modul

as a lats try ?

but a realy big thanks to you so far that you bother to write this usefull programm !! :slight_smile:

No, you cannot use the sketch I posted, you need to modify it for this last check.
You have to remove all delay()s in loop(), the rest probably should work.

If that doesn't work, it's not the stand-by handling that is causing troubles. Without a scope I would guess that the module is damaged.

sry - wasnt at home to try it earlier.

but looks bad - commented out the "delays" in the loop, loaded the sketch with Vcc not connected to the sensor - restarted arduino and plugged in Vcc-Sensor - but no response on the SerialMontior

hm i just wonder i added in this loop

  while (res != 0) 
  {
    Wire.beginTransmission(DSCP01_ADDRESS);
    Wire.write(0x70); // wake up
    res = Wire.endTransmission();
    println(res);
    Serial.println(res);
  }

the last line so that it should print me again the NAK - but i only get one response - do i have a missunderstanding what the written line should do ?

hm would there be a solution with a simple loop which and trial which runs through all possible adresses and if there is a result - an aknowledge - i print it

and maybe an second while or whatever which runs through different delay times in principle like that:

int time_var  // start from 10ms ...1s
int adr_var // start from logic "good" adress to an end adress

for(;;time++)   while no correct answer  <- time varialbe loop
{
    for(;; adr ++)  while no correct answer <- adr. varialbe loop
    {
         send and wait if response  like in your loop !=2  (an other value than NAK/2)
          
          if(correct response)  - JEAH ...do sth
    }
}

or doesnt that have any use - because that i didnt get an asnwer in the 2 test programms you wrote
me includes those cases ?

Nick Gammon has such an I2C scanner on his page: http://www.gammon.com.au/forum/?id=10896

You may try that one, but I doubt that it will have another address, the datasheet clearly specifies 0x20 and 0x21 which translates to a 0x10 in 7-bit format.

ok thx

hm i tried to run the prog but even it looks somehow not so well

i run this as you posted the link:

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

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

  Serial.println ();
  Serial.println ("test");
  Serial.println ("I2C scanner Scanning ...");
  byte count = 0;  
  
  Wire.begin();  
   ... (same as on posted link)

but at the first serial println it doesnt print the last letter of "test"

what could that mean ?

i only get

"tes"
and not even the second line

causes the (maybe broken) sensor modul troubles with the serial communication ?

------------------------------------------------------------------------------------------------------------------------------ add

modified it a bit and now i can see that it got stuck at adress 6:

with this changed code

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

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

  // Leonardo: wait for serial port to connect
  //while (!Serial) 
  //{
  //}

  
  //
  Serial.println ();
  Serial.println ("test");
  Serial.println ("I2C scanner Scanning ...");
  byte count = 0;
  
  delay(1000);
  
  
  Wire.begin();
  
  for (byte i = 1; i < 120; i++)
  { 
    Serial.println(i);
    delay(300);    
    
    Wire.beginTransmission (i);
    
    if (Wire.endTransmission () == 0)
    {
      /*
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      */
    } // end of good response
     
    
    
  } // end of for loop
  
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
  
}  // end of setup

void loop() 
{
}

this is the serial output

test
I2C scanner Scanning ...
1
2
3
4
5
6

also when i change the range it got stuck at those adresses i tested so far: 6,9,14,17,19,....

dont know what it means or if there is just an loop checker who stops when recognizing that there is an error ... ^^