<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>LeafLabs Garden &#187; Topic: 1-Wire ds18b20 code example</title>
		<link>http://forums.leaflabs.com/topic.php?id=864</link>
		<description>A place to share, learn, and grow...</description>
		<language>en-US</language>
		<pubDate>Fri, 22 Jan 2016 00:15:25 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://forums.leaflabs.com/search.php</link>
		</textInput>
		<atom:link href="http://forums.leaflabs.com/rss.php?topic=864" rel="self" type="application/rss+xml" />

		<item>
			<title>kdepp on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864&amp;page=2#post-8228</link>
			<pubDate>Fri, 17 Feb 2012 08:44:55 +0000</pubDate>
			<dc:creator>kdepp</dc:creator>
			<guid isPermaLink="false">8228@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Just received a new DS18B20.&#60;br /&#62;
Using the same code, I receive approx. 7K lower temperature readings.&#60;br /&#62;
So my other sensor is gone I guess.&#60;br /&#62;
I will make some tests to see, whether the difference is a kind of offset, or dynamic according to temperature level.&#60;br /&#62;
And my problem regarding the external crystal is also solved. Found something in the Docs area.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>siy on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864&amp;page=2#post-8200</link>
			<pubDate>Wed, 15 Feb 2012 06:49:29 +0000</pubDate>
			<dc:creator>siy</dc:creator>
			<guid isPermaLink="false">8200@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;By the way, recently I've found at one site very clever 1-Wire lib which uses UART to implement 1-Wire protocol and involves DMA for data transfers: &#60;a href=&#34;http://we.easyelectronics.ru/STM32/stm32-1-wire-dma.html&#34; rel=&#34;nofollow&#34;&#62;http://we.easyelectronics.ru/STM32/stm32-1-wire-dma.html&#60;/a&#62; . The article is in Russian, but this should not be big problem due to big pieces of code inside. I may translate article, if necessary (or, perhaps, contact author and ask him if he can translate it). But my main concern is that library is written with standard peripheral library as a base, perhaps it worth to update it to use libmaple instead...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>kdepp on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-8197</link>
			<pubDate>Tue, 14 Feb 2012 14:50:23 +0000</pubDate>
			<dc:creator>kdepp</dc:creator>
			<guid isPermaLink="false">8197@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thanks for sharing your code rcee96.&#60;br /&#62;
Helped me a lot with my Olimexino Board (Maple-Clone), but have no display though.&#60;br /&#62;
I use SerialUSB.print(and println) instead.&#60;br /&#62;
There were some timing issues, because the RC-Oscillator inside my STM32F103 does not seem to be very precise. I wrote a few lines to control delay times with a Multimeter with Oscilloscope function. A programmed delay of 480µs came out the be only 320µs. I had to multiply almost every delay value for the Sensor with 1.5 to get it working.&#60;br /&#62;
Now, it is working so far, and I get readings from the DS18B20.&#60;br /&#62;
My only problem is, that the output temperature is too high, because I can't imagine, that my room is 27,xx°C or my fingers are 41,xx°C. A kitchen thermometer says, the room is about 21°C.&#60;br /&#62;
Is it likely, that my DS18B20 is defective? I ordered some more, they should arrive in a few days. I have to admit, that I forgot to solder the 4,7kOhm resistor at first. So the Sensor ran without it for a few minutes, before I saw the unused resistor on my table.&#60;/p&#62;
&#60;p&#62;But is there a chance that something else is wrong?&#60;br /&#62;
I suspect the delay times are still not optimised.&#60;br /&#62;
Although my Board has a 8MHz crystal on it, I honestly don't know, how to change HSI to HSE using RCC commands. Can someone guide me through that. By now, you all should have realised, that I am new to µC. &#60;/p&#62;
&#60;p&#62;So any help is appreciated.&#60;br /&#62;
Thank you in advance.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>smoothisfast on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-6045</link>
			<pubDate>Tue, 23 Aug 2011 00:21:04 +0000</pubDate>
			<dc:creator>smoothisfast</dc:creator>
			<guid isPermaLink="false">6045@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Thank you for the code. This really helps out a novice like me.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rcee96 on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-6039</link>
			<pubDate>Mon, 22 Aug 2011 15:33:27 +0000</pubDate>
			<dc:creator>rcee96</dc:creator>
			<guid isPermaLink="false">6039@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;I figured someone would scold me on posting the code in-line.  Having only about 10 minutes of time before having to run out of the house for several days, github was not a option to figure out and I wanted to get the code made available.  Thanks for the pastebin link, maybe that one is easer to use than github.  I will have to take a look at it.  It is a shame there is not a way within the forum to quickly post code without going to other external sites.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>mbolivar on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-6032</link>
			<pubDate>Mon, 22 Aug 2011 14:31:33 +0000</pubDate>
			<dc:creator>mbolivar</dc:creator>
			<guid isPermaLink="false">6032@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rcee96,&#60;/p&#62;
&#60;p&#62;Thanks for sharing your code with us!&#60;/p&#62;
&#60;p&#62;However, in the future, could you please avoid pasting long code listings directly into the forum?  The extra scrolling it causes makes it harder to follow the thread of conversation.&#60;/p&#62;
&#60;p&#62;If you want to share multiple pages of source, please upload it to an external site and paste a link to it in your forum post.  We recommend pastebin and GitHub Gists for this purpose:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/&#60;/a&#62;&#60;br /&#62;
&#60;a href=&#34;https://gist.github.com/&#34; rel=&#34;nofollow&#34;&#62;https://gist.github.com/&#60;/a&#62;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rcee96 on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-6020</link>
			<pubDate>Sat, 20 Aug 2011 09:37:48 +0000</pubDate>
			<dc:creator>rcee96</dc:creator>
			<guid isPermaLink="false">6020@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Here is what I have working so far.  The Parasite power devices I have yet to be able to make work with this code and/or my wiring, but for the powered devices this works very well.  You will also find some unused code, etc. in this sample, but it will be enough to get you going.  I was working on the creation of a general purpose, compact, 1-wire library, but have been unable to spend any time on it for the past couple of months.  I would like to get this finished up and formally posted in the libraries section for others to use.  Maybe a few of us can tag team this and complete my started effort for the base 1-wire protocol and support for the more common 1-wire devices.    &#60;/p&#62;
&#60;p&#62;// Example of how to use the pcd8544 library, the lcd-driver used in&#60;br /&#62;
// Nokia 3310 and others.&#60;br /&#62;
//&#60;br /&#62;
// Tested on Sparkfun's &#34;Graphic LCD 84x48 - Nokia 5110&#34;.&#60;br /&#62;
#include &#34;pcd8544.h&#34;&#60;br /&#62;
//#include &#38;lt;stdio.h&#38;gt;&#60;/p&#62;
&#60;p&#62;/*&#60;br /&#62;
  Display, top row left to right - Maple/Arduino&#60;/p&#62;
&#60;p&#62;  Vcc                            - 3.3V&#60;br /&#62;
  GND                            - GND&#60;br /&#62;
  SCE - chip enable/select       - 7&#60;br /&#62;
  RST                            - 6&#60;br /&#62;
  D/C                            - 5&#60;br /&#62;
  DN - MOSI                      - 11&#60;br /&#62;
  SCLK                           - 13&#60;br /&#62;
  LED                            - resistor - Vcc or unconnected&#60;br /&#62;
 */&#60;/p&#62;
&#60;p&#62;// Some Aruino/Maple specific stuff&#60;br /&#62;
#define PROGMEM&#60;/p&#62;
&#60;p&#62;#define ONEWIRE_DQ_1 21&#60;br /&#62;
#define ONEWIRE_DQ_2 22&#60;/p&#62;
&#60;p&#62;byte dc_pin = 14;    // Data/Command&#60;br /&#62;
byte reset_pin = 13;&#60;br /&#62;
byte cs_pin = 12;    // Chip select (SCE)&#60;/p&#62;
&#60;p&#62;// Create a pcd8544 object.&#60;br /&#62;
// Hardware SPI will be used.&#60;br /&#62;
// (SPI1 on the Maple, add 2 as last argument for SPI2 (untested)).&#60;br /&#62;
// sdin (MOSI) is on pin 11 and sclk on pin 13.&#60;br /&#62;
pcd8544 lcd(dc_pin, reset_pin, cs_pin);&#60;/p&#62;
&#60;p&#62;// Use 5 arguments for soft SPI. Any pins can be choosen.&#60;br /&#62;
// byte sdin_pin = 11, sclk_pin = 13;&#60;br /&#62;
// pcd8544 lcd(dc_pin, reset_pin, cs_pin, sdin_pin, sclk_pin);&#60;/p&#62;
&#60;p&#62;// 2 rows by 16 cols smiley. First 16 bytes is first row,&#60;br /&#62;
// next 16 is second.&#60;br /&#62;
byte smile[] PROGMEM = {&#60;br /&#62;
	0xE0,0x18,0x04,0x04,0x02,0x32,0x32,0x02,0x02,0x22,0x22,&#60;br /&#62;
	0x02,0x04,0x04,0x18,0xE0,0x07,0x18,0x20,0x22,0x44,0x48,&#60;br /&#62;
	0x48,0x48,0x48,0x48,0x48,0x44,0x22,0x20,0x18,0x07};&#60;/p&#62;
&#60;p&#62;int   OneWire_Reset(int);&#60;br /&#62;
int   OneWire_ReadByte(int, int);&#60;br /&#62;
int   OneWire_ReadBit(int, int);&#60;br /&#62;
void  OneWire_WriteByte(int, int);&#60;br /&#62;
void  OneWire_WriteBit(int, int);&#60;/p&#62;
&#60;p&#62;int   OneWire_DS18B20_ConvertTemperature(int);&#60;br /&#62;
float OneWire_DS18B20_ReadTemperature(int);&#60;br /&#62;
int   OneWire_DS18B20_ReadPower(int);&#60;/p&#62;
&#60;p&#62;void setup(void)&#60;br /&#62;
{&#60;br /&#62;
        pinMode(BOARD_LED_PIN, OUTPUT);&#60;br /&#62;
        pinMode(BOARD_BUTTON_PIN, INPUT);&#60;/p&#62;
&#60;p&#62;	lcd.begin();                         // Always call lcd.begin() first.&#60;br /&#62;
	lcd.clear();&#60;/p&#62;
&#60;p&#62;	lcd.gotoRc(4, 57);                   // Draw an image&#60;br /&#62;
	lcd.bitmap(smile, 2, 16);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void loop(void)&#60;br /&#62;
{&#60;br /&#62;
        float Celsius;&#60;br /&#62;
        float Fahrenheit;&#60;br /&#62;
        int error;&#60;/p&#62;
&#60;p&#62;        lcd.gotoRc(2, 0);&#60;br /&#62;
        lcd.print(&#34;              &#34;); &#60;/p&#62;
&#60;p&#62;        error = OneWire_DS18B20_ConvertTemperature(ONEWIRE_DQ_1);&#60;br /&#62;
        if (error == 1)&#60;br /&#62;
            {&#60;br /&#62;
            lcd.gotoRc(2, 0);&#60;br /&#62;
            lcd.print(&#34;Sensor1 Error&#34;);&#60;br /&#62;
            } &#60;/p&#62;
&#60;p&#62;        error = OneWire_DS18B20_ConvertTemperature(ONEWIRE_DQ_2);&#60;br /&#62;
        if (error == 1)&#60;br /&#62;
            {&#60;br /&#62;
            lcd.gotoRc(2, 0);&#60;br /&#62;
            lcd.print(&#34;Sensor2 Error&#34;);&#60;br /&#62;
            } &#60;/p&#62;
&#60;p&#62;        delay(1000);                                // Wait for temperature conversion to complete&#60;br /&#62;
        Celsius = OneWire_DS18B20_ReadTemperature(ONEWIRE_DQ_1);&#60;br /&#62;
        Fahrenheit = ((Celsius * 9) / 5) + 32;&#60;br /&#62;
        lcd.setCursor(0,0);                  // Set cursor to (character) column zero and row 0&#60;br /&#62;
	lcd.println(&#34;Temp1: &#34;);              // println skips to second line&#60;br /&#62;
   	lcd.gotoRc(0, 8*5);                        // Display temperature&#60;br /&#62;
	lcd.print(Fahrenheit);&#60;br /&#62;
	lcd.data(0);&#60;br /&#62;
	// A degree sign&#60;br /&#62;
	lcd.data(0b00000100); // Degree&#60;br /&#62;
	lcd.data(0b00001010);&#60;br /&#62;
	lcd.data(0b00000100);&#60;br /&#62;
	lcd.data(0);&#60;br /&#62;
	lcd.print('F');&#60;br /&#62;
	lcd.clearRestOfLine();&#60;/p&#62;
&#60;p&#62;        Celsius = OneWire_DS18B20_ReadTemperature(ONEWIRE_DQ_2);&#60;br /&#62;
        Fahrenheit = ((Celsius * 9) / 5) + 32;&#60;br /&#62;
	lcd.setCursor(0,1);                  // Set cursor to (character) column zero and row 1&#60;br /&#62;
	lcd.println(&#34;Temp2: &#34;);              // println skips to second line&#60;br /&#62;
   	lcd.gotoRc(1, 8*5);                        // Display temperature&#60;br /&#62;
	lcd.print(Fahrenheit);&#60;br /&#62;
	lcd.data(0);&#60;br /&#62;
	// A degree sign&#60;br /&#62;
	lcd.data(0b00000100); // Degree&#60;br /&#62;
	lcd.data(0b00001010);&#60;br /&#62;
	lcd.data(0b00000100);&#60;br /&#62;
	lcd.data(0);&#60;br /&#62;
	lcd.print('F');&#60;br /&#62;
	lcd.clearRestOfLine();&#60;/p&#62;
&#60;p&#62;        if (OneWire_DS18B20_ReadPower(ONEWIRE_DQ_1) == 0)&#60;br /&#62;
             {&#60;br /&#62;
             lcd.gotoRc(3, 0);&#60;br /&#62;
             lcd.print(&#34;Parasite&#34;);&#60;br /&#62;
             }&#60;br /&#62;
        else&#60;br /&#62;
              {&#60;br /&#62;
              lcd.gotoRc(3, 0);&#60;br /&#62;
              lcd.print(&#34;Powered&#34;);&#60;br /&#62;
              };&#60;/p&#62;
&#60;p&#62;	delay(1000);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;int OneWire_Reset(int pin_DQ)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Issue a OneWire Reset Pulse  						*/&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	int result = 1;&#60;/p&#62;
&#60;p&#62;        pinMode(pin_DQ, OUTPUT_OPEN_DRAIN);                     // Set Data Direction to output&#60;br /&#62;
        digitalWrite(pin_DQ, LOW);                              // Pull DQ data line low (+0v).&#60;br /&#62;
        delayMicroseconds(480);		                        // Hold low for a minimum of 480uSec &#60;/p&#62;
&#60;p&#62;	pinMode(pin_DQ, INPUT);                                 // Set Data Direction to input, this releases the DQ data line&#60;br /&#62;
	delayMicroseconds(60);		                        // 4.7k pullup resistor on data line will take the bus high&#60;br /&#62;
      	        		                                // Wait for 60uSec, within 15 to 60uSec the DS1820 will&#60;br /&#62;
                                                                // pull DQ data line low&#60;/p&#62;
&#60;p&#62;	result = digitalRead(pin_DQ);                           // Read Data line, 0=DS18B20 found, 1=DS18B20 not found&#60;br /&#62;
	delayMicroseconds(240); 		                // Wait for 240usec to ensure 'presence' pulse is complete&#60;/p&#62;
&#60;p&#62;	return (result);			                // Return result&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;void OneWire_WriteByte(int pin_DQ, int data)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Write 1-wire data byte							*/&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	int loop;&#60;/p&#62;
&#60;p&#62;	for (loop = 0; loop &#38;lt; 8; loop++)	                // Loop to write each bit in the byte, LS-bit first&#60;br /&#62;
		{&#60;br /&#62;
		OneWire_WriteBit(pin_DQ, data &#38;amp; 0x01);&#60;br /&#62;
		data &#38;gt;&#38;gt;= 1;			                // shift the data byte for the next bit&#60;br /&#62;
		}&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;void OneWire_WriteBit(int pin_DQ, int bit)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Send a 1-wire write bit							*/&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	if (bit)						// Write '1' bit&#60;br /&#62;
		{&#60;br /&#62;
		pinMode(pin_DQ, OUTPUT_OPEN_DRAIN); 	        // drive DQ low to generate a time slot&#60;br /&#62;
		digitalWrite(pin_DQ, LOW);&#60;br /&#62;
		delayMicroseconds(5); 			        // 5uSec.&#60;/p&#62;
&#60;p&#62;		pinMode(pin_DQ, INPUT); 			// release DQ. allow DQ to float high, generating a 'write 1' slot&#60;br /&#62;
		delayMicroseconds(60); 				// 60usec. Wait for DS18B20 to finish sampling the 1 bit&#60;br /&#62;
		}&#60;br /&#62;
	else							// Write '0' bit&#60;br /&#62;
		{&#60;br /&#62;
		pinMode(pin_DQ, OUTPUT_OPEN_DRAIN);		// drive DQ low to generate a time slot&#60;br /&#62;
		digitalWrite(pin_DQ, LOW);&#60;br /&#62;
		delayMicroseconds(60); 				// 60uSec. hold bus low, generating a 'write 0' slot&#60;/p&#62;
&#60;p&#62;		pinMode(pin_DQ, INPUT);			        // release DQ&#60;br /&#62;
		}&#60;/p&#62;
&#60;p&#62;	delayMicroseconds(10); 					// 10uSec recovery time&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;int OneWire_ReadByte(int pin_DQ)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Read 1-Wire data byte and return it						*/&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	int loop, result=0;&#60;/p&#62;
&#60;p&#62;	for (loop = 0; loop &#38;lt; 8; loop++)&#60;br /&#62;
		{&#60;br /&#62;
		result &#38;gt;&#38;gt;= 1;					// shift the result to get it ready for the next bit&#60;/p&#62;
&#60;p&#62;		if (OneWire_ReadBit(pin_DQ))			// if result is one, then set MS bit&#60;br /&#62;
			result &#124;= 0x80;&#60;br /&#62;
		}&#60;br /&#62;
	return result;&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;int OneWire_ReadBit(int pin_DQ)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Read a bit from the 1-Wire bus and return it				        */&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	int result;&#60;/p&#62;
&#60;p&#62;	pinMode(pin_DQ, OUTPUT_OPEN_DRAIN); 		        // drive DQ low&#60;br /&#62;
	digitalWrite(pin_DQ, LOW);&#60;br /&#62;
	delayMicroseconds(5);					// 5uSec delay&#60;/p&#62;
&#60;p&#62;	pinMode(pin_DQ, INPUT);				        // release DQ to generate a 'Read' time slot&#60;br /&#62;
	delayMicroseconds(5);					// 5uSec. wait for read slot data to be valid&#60;/p&#62;
&#60;p&#62;	result = digitalRead(pin_DQ);			        // Sample the bus&#60;br /&#62;
	delayMicroseconds(60);					// 60uSec. complete the time slot&#60;/p&#62;
&#60;p&#62;	return (result);&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;int OneWire_TouchByte(int pin_DQ, int data)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Write a 1-Wire data byte and return the sampled result.			*/&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	int loop;&#60;br /&#62;
        int result=0;&#60;/p&#62;
&#60;p&#62;	for (loop = 0; loop &#38;lt; 8; loop++)&#60;br /&#62;
	{&#60;br /&#62;
		result &#38;gt;&#38;gt;= 1;						// shift the result to get it ready for the next bit&#60;/p&#62;
&#60;p&#62;		if (data &#38;amp; 0x01)					// If sending a '1' then read a bit else write a '0'&#60;br /&#62;
			{&#60;br /&#62;
			if (OneWire_ReadBit(pin_DQ))&#60;br /&#62;
				result &#124;= 0x80;&#60;br /&#62;
			}&#60;br /&#62;
		else&#60;br /&#62;
			OneWire_WriteBit(pin_DQ, 0);&#60;/p&#62;
&#60;p&#62;		data &#38;gt;&#38;gt;= 1; 						// shift the data byte for the next bit&#60;br /&#62;
	}&#60;br /&#62;
	return result;&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;void OneWire_Block(int pin_DQ, unsigned char *data, int data_len)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Write a block of 1-Wire data bytes and return the sampled result in the same */&#60;br /&#62;
/* buffer.									*/&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	int loop;&#60;/p&#62;
&#60;p&#62;	for (loop = 0; loop &#38;lt; data_len; loop++)&#60;br /&#62;
	    {&#60;br /&#62;
	    data[loop] = OneWire_TouchByte(pin_DQ, data[loop]);&#60;br /&#62;
	    }&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;int OneWire_DS18B20_ConvertTemperature(int pin_DQ)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Instruct device to convert temperature.					*/&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
        {&#60;br /&#62;
        int error;&#60;/p&#62;
&#60;p&#62;        error = OneWire_Reset(pin_DQ);                          // Perform Master Reset of OneWire Bus&#60;br /&#62;
        OneWire_WriteByte(pin_DQ, 0xCC);			// skip ROM&#60;br /&#62;
	OneWire_WriteByte(pin_DQ, 0x44);			// convert temperature&#60;br /&#62;
	OneWire_Reset(pin_DQ);				        // Perform Master Reset of OneWire Bus&#60;br /&#62;
        return(error);&#60;br /&#62;
        }&#60;/p&#62;
&#60;p&#62;float OneWire_DS18B20_ReadTemperature(int pin_DQ)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Obtain a celsius temperature value from a DS18B20 device.		        */&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	unsigned char get[10];&#60;br /&#62;
	int x;&#60;br /&#62;
	long temp;&#60;br /&#62;
	float ftemp;&#60;/p&#62;
&#60;p&#62;	OneWire_WriteByte(pin_DQ, 0xCC);			// skip ROM&#60;br /&#62;
	OneWire_WriteByte(pin_DQ, 0xBE);			// read scratch pad&#60;br /&#62;
        for (x=0; x&#38;lt;9; x++)					// read 9 bytes from scratchpad&#60;br /&#62;
            {&#60;br /&#62;
	    get[x]=OneWire_ReadByte(pin_DQ);&#60;br /&#62;
            }&#60;br /&#62;
        temp = get[1];                                          // Get MSB of Scratchpad&#60;br /&#62;
	temp = temp &#38;lt;&#38;lt; 8;					// Shift the MSB left 8 bits&#60;br /&#62;
	temp = (temp &#124; get[0]);					// Get LSB of Scratchpad&#60;br /&#62;
	if (get[1] &#38;gt;= 0x80)					// Check if MSB indicates negative temperature&#60;br /&#62;
            {&#60;br /&#62;
	    temp = 0xffff0000 &#124; temp;                           // Set first 2 bytes of long data type to reflect 2s compliment negative value&#60;br /&#62;
            }&#60;br /&#62;
	ftemp = temp;&#60;/p&#62;
&#60;p&#62;        return (ftemp/16);&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;int OneWire_DS18B20_ReadPower(int pin_DQ)&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
/* Determine Power Mode                                    		        */&#60;br /&#62;
/********************************************************************************/&#60;br /&#62;
	{&#60;br /&#62;
	int x;&#60;/p&#62;
&#60;p&#62;	OneWire_WriteByte(pin_DQ, 0xCC);			// skip ROM&#60;br /&#62;
	OneWire_WriteByte(pin_DQ, 0xB4);			// read scratch pad&#60;br /&#62;
        x = OneWire_ReadBit(pin_DQ);&#60;/p&#62;
&#60;p&#62;        return (x);&#60;br /&#62;
	}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>smoothisfast on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-6016</link>
			<pubDate>Fri, 19 Aug 2011 18:48:15 +0000</pubDate>
			<dc:creator>smoothisfast</dc:creator>
			<guid isPermaLink="false">6016@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;rcee96 I'm trying to get my ds18b20 to work on my maple. Could you post your code please?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-5322</link>
			<pubDate>Fri, 17 Jun 2011 13:16:40 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5322@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;haha, good to hear. Would be great if you posted a lib to github, or maybe a blurb about it on the wiki! Im sure others will get a lot of use out of it on their own one-wire jobs. &#60;/p&#62;
&#60;p&#62;fyi, the delay function is actually just calling delayMicroseconds, which is actually just calling assembly no-ops. heh. &#60;/p&#62;
&#60;p&#62;If you need an asynchronous clock, you can use millis() or micros() which use the internal systick clock.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rcee96 on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-5318</link>
			<pubDate>Fri, 17 Jun 2011 13:02:49 +0000</pubDate>
			<dc:creator>rcee96</dc:creator>
			<guid isPermaLink="false">5318@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Open Drain did the trick on the 1-wire protocol, thank you so much for pointing out my error.  I'm still in transition from PIC to Maple, just a bit of learning curve.  I very much like this platform so far.  Yes, am aware of the BOARD_LED_PIN, was just too lazy to type that in for diagnostic purposes. &#60;/p&#62;
&#60;p&#62;By the way, I did get the 1-Wire protocol working last night and can pull temperature readings off of the ds18b20.  Once I complete some more of the function development, I might try to post something on Github, if I can figure that out.  I can't tell you how much I appreciate the maple delay functions, beats the heck out of doing microsecond delays using clock cycle counts on the PIC.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-5317</link>
			<pubDate>Fri, 17 Jun 2011 12:36:16 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5317@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;also, you can use BOARD_LED_PIN as a convenience macro so you dont have to think about which pin number is the LED. It resolves to the correct value for any of our products.&#60;br /&#62;
 (as does BOARD_BUTTON_PIN). &#60;/p&#62;
&#60;p&#62;see the language reference: &#60;a href=&#34;http://leaflabs.com/docs/language.html#id3&#34; rel=&#34;nofollow&#34;&#62;http://leaflabs.com/docs/language.html#id3&#60;/a&#62;  to see some of the other convenience functions and macros (like toggleLED() and waitForButtonPress() )
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-5316</link>
			<pubDate>Fri, 17 Jun 2011 12:34:28 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5316@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;definitely understand that. &#60;/p&#62;
&#60;p&#62;so you arnt using open drain then?
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rcee96 on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-5288</link>
			<pubDate>Thu, 16 Jun 2011 21:51:47 +0000</pubDate>
			<dc:creator>rcee96</dc:creator>
			<guid isPermaLink="false">5288@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Please ignore last post. I had things wired up incorrect.... I had LED on pin 31 tied to +3.3 instead of ground.  That sure explains the inverted behavior.  I need a new set of eyes that can actually see things.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>rcee96 on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-5287</link>
			<pubDate>Thu, 16 Jun 2011 21:35:23 +0000</pubDate>
			<dc:creator>rcee96</dc:creator>
			<guid isPermaLink="false">5287@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;Ok, still no luck. What I am seeing is what looked to be inverted outputs on the gpio pins, so I put together the following sample code which just flashed the onboard LED then sets the line to LOW and then flashed another LED on another gpio pin and also set the line to LOW.  What is interesting is the first block of LED flashing on PIN 33 the final LOW state turns the LED off as expected.  Then in the next set of LED flashing on PIN 31 the final LOW state turns the LED on, which is not expected.  This is on a Maple Mini so I am starting to wonder if there is some sort of bug or I am just a complete nut case.  This is with IDE 0.0.11.  &#60;/p&#62;
&#60;p&#62;void setup() {&#60;br /&#62;
    pinMode(33, OUTPUT);&#60;br /&#62;
    pinMode(31, OUTPUT);&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;void loop() {&#60;br /&#62;
    int x;&#60;/p&#62;
&#60;p&#62;    for (x = 0; x &#38;lt; 10; x++)&#60;br /&#62;
	{&#60;br /&#62;
        digitalWrite(33,HIGH);&#60;br /&#62;
	delay(100);&#60;br /&#62;
        digitalWrite(33,LOW);&#60;br /&#62;
        delay(100);&#60;br /&#62;
        }&#60;/p&#62;
&#60;p&#62;        digitalWrite(33,LOW);	// Onboard LED on pin 33 if off as expected&#60;br /&#62;
      	delay(5000);		   &#60;/p&#62;
&#60;p&#62;     for (x = 0; x &#38;lt; 10; x++)&#60;br /&#62;
	{&#60;br /&#62;
        digitalWrite(31,HIGH);&#60;br /&#62;
	delay(100);&#60;br /&#62;
        digitalWrite(31,LOW);&#60;br /&#62;
        delay(100);&#60;br /&#62;
        }&#60;/p&#62;
&#60;p&#62;        digitalWrite(31,LOW);	// LED on pin 31 is ON, which is not correct&#60;br /&#62;
      	delay(5000);	  &#60;/p&#62;
&#60;p&#62;}
&#60;/p&#62;</description>
		</item>
		<item>
			<title>poslathian on "1-Wire ds18b20 code example"</title>
			<link>http://forums.leaflabs.com/topic.php?id=864#post-5260</link>
			<pubDate>Thu, 16 Jun 2011 13:40:01 +0000</pubDate>
			<dc:creator>poslathian</dc:creator>
			<guid isPermaLink="false">5260@http://forums.leaflabs.com/</guid>
			<description>&#60;p&#62;open drain is what you want!
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
