I’m using the following code to read a single ds18b20 sensor. I’d like to wire up a few more (likely < 6 total) but can’t find any sample code and schematics to point me in the right direction.
Specific questions
Should I wire up the sensors using the “normal” or “parasitic” power mode?
Once the sensors are wired up, how do I query the pin to get all the sensors and then iterate the collection to output the data?
Thanks!
public static void TempFromMaximIc()
{
byte[] romid = new byte[8];
Cpu.Pin myPin = (Cpu.Pin)FEZ_Pin.Digital.Di52;
OneWire ow = new OneWire(myPin);
ushort temperature;
while (true)
{
if (ow.Reset())
{
ow.WriteByte(0x33);
ow.Read(romid, 0, 8);
ow.WriteByte(0x44); // Start temperature conversion
while (ow.ReadByte() == 0) ; // wait while busy
ow.Reset();
ow.WriteByte(0xCC); // skip ROM
ow.WriteByte(0xBE); // Read Scratchpad
temperature = ow.ReadByte(); // LSB
temperature |= (ushort)(ow.ReadByte() << 8); // MSB
var temp = (temperature / 16) * 9 / 5 + 32;
string result = SendToPachube(temp.ToString());
Thread.Sleep(1000);
}
else
{
Debug.Print("Device is not detected.");
}
Thread.Sleep(1000);
}
}
I also have a project where I work with onewire. In my case, I use a couple of 4 channel ad converters.
This works fine, but I have experienced an issue that you might run into as well.
When executing a search on the one-wire object, I’m not always getting the addresses for all the devices on the network. Sometimes I get all devices, sometimes one or two are missing. To overcome this, I have written a loop that searches until all devices have been found. Below is my code. Ofcourse you need to know how many devices you expect, but in my case this was no problem.
public static void GetDevices()
{
byte[] OW_Address = new byte[8];
if (ow.Reset())
{
while (true)
{
while (ow.Search_GetNextDevice(OW_Address))
{
OW_Addresses.Add(OW_Address);
OW_Address = new byte[8];
}
if (OW_Addresses.Count == Common.NumberOfOWDevices)
break;
}
}
Log.OutputOWAddresses(OW_Addresses);
}
I’m sorry for not using the code tags, but my browser is giving me a javascript error when I try to add them to the post… Can I also add them manually?
Nothing wrong with beeing curious…
I think it was Einstein who said: I am neither especially clever nor especially gifted. I am only very, very curious.
Anyway, I don’t know why. didn’t get around to update it I guess… So far, I didn’t have any problems with it, however I suspect that this forum does not like IE8?