using System;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.FEZ;
using Gadgeteer.Modules.GHIElectronics;
namespace DS1820
{
public partial class Program
{
void ProgramStarted()
{
// Change this your correct pin!
Cpu.Pin myPin = (Cpu.Pin)FEZ_Pin.Digital.Di4;
OneWire ow = new OneWire(myPin);
ushort temperature;
// read every second
while (true)
{
if (ow.Reset())
{
ow.WriteByte(0xCC); // Skip ROM, we only have one device
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
Debug.Print("Temperature: " + temperature / 16);
Thread.Sleep(1000);
}
else
{
Debug.Print("Device is not detected.");
}
Thread.Sleep(1000);
}
}
}
}
Now it compiles and the output is: “Device is not detected”.
My Problem is that i have no idea what this line means:
Cpu.Pin myPin = (Cpu.Pin)FEZ_Pin.Digital.Di4;
Where can i find a Document about the pin assignment?
So maybe someone here can help me
How can i change my code to use the DS1820 soldered to the Externeder Board with my FEZ Spider?
As an example, with Extender Module P6 on DATA of the DS1820…
Or maybe someone knows a great tutorial to do this?
Don’t add anything in the designer, just Spider mainboard. Next replace the line that initializes the myPin variable with this:
var extenderSocketNumber = 1;
var extenderDataPin = 4;
var myPin = Socket.GetSocket(extenderSocketNumber, true, null, null).CpuPins[extenderDataPin];
Adjust first two values to your device. First one is the Spider port number to which the extender is pluged in. The second value is the pin number on the Extender that has the data line connected.
Thank you for your answers! Sorry for my late replay, i had much to do last week…
When i use this code:
var extenderSocketNumber = 1;
var extenderDataPin = 4;
var myPin = Socket.GetSocket(extenderSocketNumber, true, null, null).CpuPins[extenderDataPin];
ow.ReadByte() is alwas 0 so i get no temperature.
No matter if the device is connected or not, i never get “Debug.Print(“Device is not detected.”);” …
I tried your tipp RorschachUK, but i cannot run this example: No entry point Main Mehthod …
“No entry point Main method” sounds like it’s arbitrarily decided which of the two projects in the solution is the startup project, and guessed wrong. Try right-clicking the OneWireTest project and selecting Set as Startup project, if it still complains after that try looking in OneWireTest’s Properties to see if the startup object’s set to the Program class.
Ok, i can run it now, but the same output as before:
Starting …
Found device: Family Code: 16, Serial Number: 28, 93, 225, 1, 8, 0, CRC: 191
Found 0 devices
So there is a device. Maybe the Problem is, that the Code is for DS18B20 and i use a DS1820-BT.
I tried changing the FamiliyCode from 0x28 to 0x10 in DS18B20.cs.
And i got a temperature like 3.7C … 4C so the temperature is wrong.
When i put the DS in my hand, the temp is rising from 3,7 to 4C … so in a way it works. But thats not the real temperature …
On this site i found the DS1820 FamilyCode: http://www.anotherurl.com/therm/frame_format_DS1820.htm
I searched the DS1820 Datasheed but where is an information about these codes.
Maybe the other codes in DS18B20.cs are wrong, too.
public const byte AlarmSearch = 0xEC;
public const byte StartTemperatureConversion = 0x44;
…
Has anyone an idea, where to find the right codes for my DS1820-BT?