I2C - DSPC01 Digital Compass Pressure Sensor Module

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 ... ^^

Have you tried running it without the device connected? It should run through without a problem. If it doesn't your Arduino board has a problem.

Usually this code runs through and displays the found devices (if you don't comment out the necessary lines). There is almost no way of letting it break (almost because a slave device can make the communication slower by holding the SCKL low for longer than the master intended. But that means the slave gets active and it has to implement that feature (most don't).

hy thx again for your responses,

yes i tried it without the sensor connected and it works as it should

hm not sure if i did get your second point, where you explained how that could be
so - if i understand right it means the device works and holds down the CLK line and my arduino waits for
an high impulse on the CLK ?

ok i now look at my old IC´s if there is an other I2C device and test this and try if i get it running, when my sensor dont want to work :smiley: :smiley:

so - if i understand right it means the device works and holds down the CLK line and my arduino waits for
an high impulse on the CLK ?

Almost. Usually I2C devices are just slaves, the master is controlling everything. The master is pulsing the clock line (spikes from high to low) which is giving the frequency for the serial transfer (in either direction). If a slave needs more time to fulfill it's task, it is allowed to hold the clock low even if the master isn't still pulling it (clock stretching). I don't know where the limits are for this feature but in every description I read it sounds like: "it's allowed to stretch the clock a little bit".
The blocking of the bus like you may experience is clearly a misbehavior.

ah ok thank you again - learned another thing :slight_smile:

if i can use an digital analyzer next months or get it running per experimenting i post here more :smiley:

I noted that he datasheet of DSPC01 (http://www.dorji.com/docs/data/DSPC01.pdf) was updated and some interesting information is added.

I did not succeed in communicating via the Arduino I2C library, too. I am wondering if it is a standard I2C protocol at all.

Nevertheless the module is working now. I kept straight with the example provided here for a PIC processor: http://www.dorji.com/docs/app/ADS1000.pdf
Here is the library and the example code:
GitHub - jenkie/DSPC01: Arduino Library for the Dorji DSPC01 pressure/altitude/temperature/compass module

And the nice thing: It is working directly with 5V supply and 5V logic. I see no need for level shifters by now.

If anyone gets it running using the Wire.h library please tell :slight_smile: