SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By srk
#199168
Hi everybody,

I am trying to read dissolved oxygen from the Atlas Scientific sensor.datasheet is given here
https://www.atlas-scientific.com/_files ... asheet.pdf?

My code for reading is as under:


#include <Wire.h>

void setup() {
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(9600); // start serial communication at 9600bps
}

int reading = 0;

void loop() {
// step 1: instruct sensor to read echoes
Wire.beginTransmission(97); // transmit to device #97(0x70)
// the address specified in the datasheet is 224 (0xE0)
// but i2c adressing uses the high 7 bits so it's 97
Wire.write(byte(0x00)); // sets register pointer to the command register (0x00)
Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50)
// use 0x51 for centimeters
// use 0x52 for ping microseconds
Wire.endTransmission(); // stop transmitting

// step 2: wait for readings to happen
delay(700); // datasheet suggests at least 65 milliseconds

// step 3: instruct sensor to return a particular echo reading
Wire.beginTransmission(97); // transmit to device #97
Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02)
Wire.endTransmission(); // stop transmitting

// step 4: request reading from sensor
Wire.requestFrom(97, 2); // request 2 bytes from slave device #97

// step 5: receive reading from sensor
if (2 <= Wire.available()) { // if two bytes were received
reading = Wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte to be high 8 bits
reading |= Wire.read(); // receive low byte as lower 8 bits
Serial.println(reading); // print the reading
}

delay(250); // wait a bit since people have to read the output :)
}

But im not able to read in the serial monitor and the response is pasted here as :
requestFrom: readed=0, quantity=2 : ERROR
requestFrom: readed=0, quantity=2 : ERROR
Can you please guide where is the mistake ? thanking a lot in advance.
By jremington
#199174
It looks like you got partway through modifying code for a ping sensor, but didn't finish.

Among other possible errors, what is a dissolved oxygen sensor supposed to do with a command that tells it to measure in "inches"? (Hint: that command does something else entirely).
Code: Select all
Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50)
Carefully study the device data sheet and use the correct commands, in the correct order. Get rid of the leftover ping sensor junk.

Finally, you are allowed to make one reading per second, so reconsider this line:
Code: Select all
delay(250); // wait a bit since people have to read the output :)