Javier Perez
/
test_temperature_ds18b20
Test of DS18B20 Digital temperature sensor using k22f board.
Revision 0:6367a3d990f2, committed 2018-04-19
- Comitter:
- javibenjas
- Date:
- Thu Apr 19 04:10:42 2018 +0000
- Commit message:
- initial version
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Thu Apr 19 04:10:42 2018 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DS1820.lib Thu Apr 19 04:10:42 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/DS1820/#236eb8f8e73a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Thu Apr 19 04:10:42 2018 +0000 @@ -0,0 +1,57 @@ +# Getting started with Blinky on mbed OS + +This guide reviews the steps required to get Blinky working on an mbed OS platform. + +Please install [mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). + +## Import the example application + +From the command-line, import the example: + +``` +mbed import mbed-os-example-blinky +cd mbed-os-example-blinky +``` + +### Now compile + +Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the ARM Compiler 5: + +``` +mbed compile -m K64F -t ARM +``` + +Your PC may take a few minutes to compile your code. At the end, you see the following result: + +``` +[snip] ++----------------------------+-------+-------+------+ +| Module | .text | .data | .bss | ++----------------------------+-------+-------+------+ +| Misc | 13939 | 24 | 1372 | +| core/hal | 16993 | 96 | 296 | +| core/rtos | 7384 | 92 | 4204 | +| features/FEATURE_IPV4 | 80 | 0 | 176 | +| frameworks/greentea-client | 1830 | 60 | 44 | +| frameworks/utest | 2392 | 512 | 292 | +| Subtotals | 42618 | 784 | 6384 | ++----------------------------+-------+-------+------+ +Allocated Heap: unknown +Allocated Stack: unknown +Total Static RAM memory (data + bss): 7168 bytes +Total RAM memory (data + bss + heap + stack): 7168 bytes +Total Flash memory (text + data + misc): 43402 bytes +Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin +``` + +### Program your board + +1. Connect your mbed device to the computer over USB. +1. Copy the binary file to the mbed device. +1. Press the reset button to start the program. + +The LED on your platform turns on and off. + +## Troubleshooting + +If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Apr 19 04:10:42 2018 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "DS1820.h" + +#define SLEEP_S 2 + +// I'm using DS18B20, connections +// red -> 5v +// blue -> GND +// yellow -> D6 +DigitalOut led_r(LED1); +DigitalOut led_g(LED2); +DigitalOut led_b(LED3); +DS1820 temp_probe(D6); + +//we will use the first read as environment temperature +float env_temperature = -99; +// red means higher than environment +// blue means cooler than environment +// green means same as env + +float read_temperature() { + float tmp_temp; + temp_probe.convertTemperature(true, DS1820::this_device); + do { + // TODO limit the n of tries + // if device is not responding, will cycle forever + tmp_temp = temp_probe.temperature(); + wait_ms(10); + } while(tmp_temp == -1000); + return tmp_temp; +} + +int main() { + printf("Temperature probe test\r\n"); + float temperature = 0; + temp_probe.setResolution(9); //9bits + + //read env temperature + wait(1); //wait for device to be ready + env_temperature = read_temperature(); + + while(1) { + temperature = read_temperature(); + printf("Temperature %3.1foC\r\n", temperature); + if(temperature < env_temperature) { + led_r = 1; // 1 is off in this board + led_g = 1; + led_b = 0; + } else if(temperature > env_temperature) { + led_r = 0; + led_g = 1; + led_b = 1; + } else { + led_r = 1; + led_g = 0; + led_b = 1; + } + // sleep + wait(SLEEP_S); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Apr 19 04:10:42 2018 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#addec7ba10054be03849eff58a1d17f157391e7d