This repository contains the code required to connect a DS18B20 temperature sensor to an Azure Sphere device.
- Copy the ds18b20 folder into your Azure Sphere project.
- Add add_subdirectory(ds18b20) to your CMakeLists.txt file.
#include "ds18b20/ds18b20.h"
int sensor = -1;
int main(void)
{
sensor = ds18b20Init(0); // initinitialize ds18b20 and one wire bus on GPIO0
ds18b20Convert(sensor); // instruct ds18b20 to convert temperature
// wait at least 750 ms
// get and print temperature
float temp = ds18b20GetTemperature(sensor);
Log_Debug("%.1f C\n", temp);
}
This project was adapted from libraries found at https://github.com/simonbarker/pic-libraries.