Hi to all... I'm a first time poster and Arduino noob, and I have what I think is probably a simple question about interfacing my Uno to a Maxim DS18B20.
I'm starting from the ground up, trying to write my first routine, a 1-Wire reset. Here's the entire program:
int My_Pin = 2; // Switch connected to digital pin 2
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // start serial port
}
void loop()
{
byte status=0;
Serial.print("Reset returns: ");
status=OneWire_Reset(My_Pin);
Serial.println(status);
delay(2000);
}
int OneWire_Reset(int pin)
{
int result;
pinMode(pin, OUTPUT); // sets the digital pin as output
delayMicroseconds(10);
digitalWrite(pin, LOW); // pull the bus LOW
delayMicroseconds(600); // Hold it low for at least 480us
pinMode(pin, INPUT); // let go of the bus
delayMicroseconds(60); // bus comes back HIGH...
delayMicroseconds(150); // DS18B20 pulls it low, so make sure we are within 60-240us reply window
result = digitalRead(pin); // Sample for presence pulse from slave
delayMicroseconds(300); // wait until the window closes
return (result); // LOW = reset, HIGH = no reset
}
My circuit to the DS18B20 is very straightforward... ground to pin 1, pin 2 connected to Digital 2 of the Arduino and connected to a 4.7K pullup w/+5V, and +5 on the pin 3. Switching jumpers around to put it in parasitic power mode make no difference.
This always returns HIGH, which means that the 1 Wire bus is not getting pulled low (which = reset acknowledge). I've varied the timings a bit, but that seem to have no effect. I suspect I'm doing something obviously wrong here, but not sure what....
Thanks for any help,
Dan
PS I know there is a complete 1 wire library out there, but I really want to learn how to do this....