Netduino Plus 2 OneWire
on .NET Micro Framework 4.2
DS18B20
Example code:
public static void Main() { // DS18B20, NETMF 4.2 // center pin is connected to digital pin 0, right pin is connected to 5V, // left pin GND, 4k7 pull-up resistor between 5V and the center pin OneWire oneWire = new OneWire(new OutputPort(Pins.GPIO_PIN_D0, false)); ushort temperature; while (true) { if (oneWire.TouchReset() > 0) { oneWire.WriteByte(0xCC); // Skip ROM, we only have one device oneWire.WriteByte(0x44); // Start temperature conversion while (oneWire.ReadByte() == 0) ; // wait while busy oneWire.TouchReset(); oneWire.WriteByte(0xCC); // Skip ROM oneWire.WriteByte(0xBE); // Read Scratchpad temperature = (byte)oneWire.ReadByte(); // LSB temperature |= (ushort)(oneWire.ReadByte() << 8); // MSB //Temperatu in C, If you will in F would be: ((1.80 * (temperature / 16.0)) + 32); Debug.Print("Temperature: " + temperature / 16.0 + "C"); } else { Debug.Print("No device detected"); } Thread.Sleep(1000); } }