DS1820 with FEZ Spider

Hallo,

i have some issues using a DS1820 Temperature with my FEZ Spider.
The DS1820 i’m using is this one: http://www.conrad.de/ce/de/product/184037/

I found this code: GHI Electronics – Where Hardware Meets Software
But i had to change it to this code, because the original code doesn’t compile.

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?

I want to use the FEZ SPider Extzernder Board for soldering the DS1820.
http://www.ghielectronics.com/catalog/product/273

So maybe someone here can help me :slight_smile:
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?

King Regards

Yuri

Try this one, which mentions Gadgeteer and Spider: http://www.tinyclr.com/codeshare/entry/392

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.

Is this 4.2 or 4.1?

1 Like

Spider/EMX is currently 4.1

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 …

Any other ideas :slight_smile:

I tested something:

Some parts of this Code: http://www.tinyclr.com/codeshare/entry/392 with some of my first code…

And i get:

Starting …
Found device: Family Code: 16, Serial Number: 28, 93, 225, 1, 8, 0, CRC: 191
Found 0 devices

When i disconnect the DS i get:
Starting …
Found 0 devices

So there is a device …

The best way is, if some one could help me running the example posted by Rorschach.

Now i created this code: http://yuri.exwede.de/DS1820_2.rar
Maybe someone can try it …

Thank you!

“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?

I found this: http://www.micropik.com/PDF/ds1820.pdf

Exept for the FamilyCode, the comands are the same.
So i only changed

//public new static byte FamilyCode = 0x28;
public new static byte FamilyCode = 0x10;

Device: Family Code: 16, Serial Number: 28, 93, 225, 1, 8, 0, CRC: 191
Synchronous temperature: 3.0625C
Asynchronous temperature: 3.0625C

So any ideas why the temperature is wrong?