I am trying to program a DS18S20 Digital Sensor connected to Arduino UNO using Arduino 1.0 Software
I think that I have connected everything ok (attached photo).
This is my program:
#include <OneWire.h>
int DS18S20_Pin = 2;
OneWire ds(DS18S20_Pin);
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
float temperature = getTemp();
Serial.println(temperature);
delay(100);
}
float getTemp(){
byte i;
byte present = 0;
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!\n");
}
if ( addr[0] != 0x10) {
Serial.print("Device is not a DS18S20 family device.\n");
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
Serial.print("P=");
Serial.print(present,HEX);
Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
_ Serial.print(data*, HEX);_
_ Serial.print(" ");_
_ }_
_ Serial.print(" CRC=");_
_ Serial.print( OneWire::crc8( data, 8), HEX);_
_ Serial.println();_
_}*_
This is compiling and charging correctly in the Arduino Board, but I dont receive the result in the screen.
Can someone help me?