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().
#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 - 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 ? )
note:in your nice test prog:
at thise line is an "u" where it doesnt belong to ^^
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
}
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
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.
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.
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 ?
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.