Go Down

Topic: I2C - DSPC01 Digital Compass Pressure Sensor Module (Read 4084 times) previous topic - next topic

impf0s

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:
Code: [Select]

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

impf0s

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

pylon

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

Quote
because they want a 7bit value.


Where in the datasheet did you found that information?

How have you wired the sensor to the Arduino?

impf0s

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

It's 2

Quote
Where in the datasheet did you found that information?

Here: http://arduino.cc/en/Reference/WireBeginTransmission
address: the 7-bit address of the device to transmit to

Quote
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

silasmoeckel

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

pylon

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

Quote
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().

mushroom

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

VanceAnce

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 .... :~
http://vanceance.blogspot.com/

pylon

Try this sketch and show us the result:

Code: [Select]
#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
}

VanceAnce

#9
Nov 07, 2012, 08:34 pm Last Edit: Nov 07, 2012, 09:02 pm by VanceAnce Reason: 1
first of all - thx for your answer :)   - i hoped this thread isnt dead

serial output:

Code: [Select]

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 ? :( )


note:in your nice test prog:
at thise line is an "u" where it doesnt belong to ^^
Code: [Select]
uint t = Wire.read();


http://vanceance.blogspot.com/

pylon

Quote
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?

VanceAnce

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


like in this link: http://www.arduino.cc/en/Reference/Wire

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    :smiley-roll:)
http://vanceance.blogspot.com/

pylon

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?

Code: [Select]
#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
}

VanceAnce

ah cool,


hm - now i dont get any response on the serial monitor  :(
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



http://vanceance.blogspot.com/

pylon

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.

Go Up