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); } }
Diff: TMP06.h
- Revision:
- 0:cee46eec60a8
- Child:
- 2:1ff2f041925a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TMP06.h Tue Feb 25 11:30:44 2020 +0100 @@ -0,0 +1,29 @@ +/* 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_ */ \ No newline at end of file