Driver for TMP06 temperature sensor. Data is sent by PWM. Tested on Hani-IoT board with TMP06BRTZ sensor.
Example usage
main.cpp
#include "mbed.h" #include "TMP06.h" int main() { TMP06 temp_sensor(P0_1); float temperature; while (true) { if(temp_sensor.read(&temperature) == SUCCESS) { printf("Temperature: %f\n", temperature); } else { printf("Error!\n"); } ThisThread::sleep_for(2000); } }
TMP06.h
- Committer:
- Pawel Zarembski
- Date:
- 2020-02-25
- Revision:
- 0:cee46eec60a8
- Child:
- 2:1ff2f041925a
File content as of revision 0:cee46eec60a8:
/* Copyright (C) 2020 Arrow Electronics */ #ifndef _TMP06_H_ #define _TMP06_H_ #include "mbed.h" #define SUCCESS 0 #define FAILURE 1 #define SEM_TIMEOUT_MS 200 class TMP06 { public: TMP06(PinName pin); ~TMP06(); int read(float *temperature); private: void on_rise(); void on_fall(); InterruptIn _pwm_pin; Timer _timer1; Timer _timer2; Semaphore _semaphore; bool _first_run; }; #endif /* _TMP06_H_ */