Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of NUCLEO-F401RE-DS1820andThermistorNTC10K by
main.cpp@5:22fb02a92579, 2016-10-21 (annotated)
- Committer:
- anywill
- Date:
- Fri Oct 21 01:48:28 2016 +0000
- Revision:
- 5:22fb02a92579
- Parent:
- 4:02a922030bc3
- Child:
- 6:7f43285de85b
DS18B20??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emcu | 4:02a922030bc3 | 1 | |
| emcu | 4:02a922030bc3 | 2 | /** |
| emcu | 4:02a922030bc3 | 3 | |
| anywill | 5:22fb02a92579 | 4 | NUCLEO-F070R + DS18B20 |
| anywill | 5:22fb02a92579 | 5 | |
| emcu | 4:02a922030bc3 | 6 | |
| anywill | 5:22fb02a92579 | 7 | By: |
| anywill | 5:22fb02a92579 | 8 | Date: Oct.2016 |
| anywill | 5:22fb02a92579 | 9 | Version: 1.0 |
| anywill | 5:22fb02a92579 | 10 | Name: NUCLEO-F070R-DS1820 |
| anywill | 5:22fb02a92579 | 11 | NOTE: For more info see here: http://www.emcu.it/NUCLEOevaBoards/mBed/QSG-Mbed-Library.pdf |
| anywill | 5:22fb02a92579 | 12 | 原程序带NTC测温,本人将已其删除 |
| emcu | 4:02a922030bc3 | 13 | |
| anywill | 5:22fb02a92579 | 14 | UART |
| emcu | 4:02a922030bc3 | 15 | Baud Rate: 9600 |
| emcu | 4:02a922030bc3 | 16 | Data Bit: 8 |
| emcu | 4:02a922030bc3 | 17 | Parity: NONE |
| emcu | 4:02a922030bc3 | 18 | Stop Bit: 1 |
| emcu | 4:02a922030bc3 | 19 | Flow Control: NONE |
| emcu | 4:02a922030bc3 | 20 | |
| anywill | 5:22fb02a92579 | 21 | |
| anywill | 5:22fb02a92579 | 22 | Connect to the NUCLEO-F070R8 the DS18B20 sensor (see the schematic below). |
| emcu | 4:02a922030bc3 | 23 | The temperature sampling time is 1 sec. |
| emcu | 4:02a922030bc3 | 24 | |
| emcu | 4:02a922030bc3 | 25 | DS18B20 front view |
| emcu | 4:02a922030bc3 | 26 | __________ |
| emcu | 4:02a922030bc3 | 27 | | | |
| emcu | 4:02a922030bc3 | 28 | | DS | |
| emcu | 4:02a922030bc3 | 29 | | 18B20 | |
| emcu | 4:02a922030bc3 | 30 | | | |
| emcu | 4:02a922030bc3 | 31 | |__________| |
| emcu | 4:02a922030bc3 | 32 | | | | |
| emcu | 4:02a922030bc3 | 33 | 1 2 3 |
| emcu | 4:02a922030bc3 | 34 | GND DQ VCC (3V3) |
| anywill | 5:22fb02a92579 | 35 | | | |______________ to VCC (3.3V on the NUCLEO-F070R) |
| emcu | 4:02a922030bc3 | 36 | | | _|_ |
| emcu | 4:02a922030bc3 | 37 | | | | | |
| emcu | 4:02a922030bc3 | 38 | | | | | 4K7 |
| emcu | 4:02a922030bc3 | 39 | | | | | |
| emcu | 4:02a922030bc3 | 40 | | | -|- |
| anywill | 5:22fb02a92579 | 41 | | |___|______________ to A1 (on the NUCLEO-F070RE) |
| emcu | 4:02a922030bc3 | 42 | | |
| emcu | 4:02a922030bc3 | 43 | | |
| anywill | 5:22fb02a92579 | 44 | |______________________ to GND (on the NUCLEO-F070RE) |
| emcu | 4:02a922030bc3 | 45 | |
| emcu | 4:02a922030bc3 | 46 | This SW is just for only one DS18B20 |
| emcu | 4:02a922030bc3 | 47 | This SW is a derivative of:: https://developer.mbed.org/users/Sissors/code/DS1820_HelloWorld/ |
| emcu | 4:02a922030bc3 | 48 | On the: https://developer.mbed.org/users/Sissors/code/DS1820_HelloWorld/ there is a multi sensor (DS18B20) example. |
| emcu | 4:02a922030bc3 | 49 | |
| anywill | 5:22fb02a92579 | 50 | |
| emcu | 4:02a922030bc3 | 51 | */ |
| emcu | 4:02a922030bc3 | 52 | |
| Sissors | 0:e069f9f26768 | 53 | #define MULTIPLE_PROBES |
| emcu | 4:02a922030bc3 | 54 | #define DATA_PIN A1 |
| Sissors | 0:e069f9f26768 | 55 | |
| Sissors | 0:e069f9f26768 | 56 | #ifdef MULTIPLE_PROBES |
| Sissors | 0:e069f9f26768 | 57 | |
| Sissors | 0:e069f9f26768 | 58 | #include "mbed.h" |
| Sissors | 0:e069f9f26768 | 59 | #include "DS1820.h" |
| Sissors | 0:e069f9f26768 | 60 | |
| Sissors | 0:e069f9f26768 | 61 | #define MAX_PROBES 16 |
| emcu | 4:02a922030bc3 | 62 | |
| emcu | 4:02a922030bc3 | 63 | float get_temperature(void); |
| emcu | 4:02a922030bc3 | 64 | |
| anywill | 5:22fb02a92579 | 65 | //AnalogIn thermistor(A5); // Thermistor |
| emcu | 4:02a922030bc3 | 66 | |
| emcu | 4:02a922030bc3 | 67 | float temp=0; |
| emcu | 4:02a922030bc3 | 68 | float tempArr[100]; |
| anywill | 5:22fb02a92579 | 69 | int n=0;//n个测温设备 |
| anywill | 5:22fb02a92579 | 70 | Serial pc(SERIAL_TX, SERIAL_RX); // 虚拟 USART2 tx, rx |
| Sissors | 0:e069f9f26768 | 71 | DS1820* probe[MAX_PROBES]; |
| Sissors | 0:e069f9f26768 | 72 | |
| anywill | 5:22fb02a92579 | 73 | int main() |
| anywill | 5:22fb02a92579 | 74 | { |
| Sissors | 0:e069f9f26768 | 75 | // Initialize the probe array to DS1820 objects |
| Sissors | 0:e069f9f26768 | 76 | int num_devices = 0; |
| Sissors | 0:e069f9f26768 | 77 | while(DS1820::unassignedProbe(DATA_PIN)) { |
| Sissors | 0:e069f9f26768 | 78 | probe[num_devices] = new DS1820(DATA_PIN); |
| Sissors | 0:e069f9f26768 | 79 | num_devices++; |
| Sissors | 0:e069f9f26768 | 80 | if (num_devices == MAX_PROBES) |
| Sissors | 0:e069f9f26768 | 81 | break; |
| Sissors | 0:e069f9f26768 | 82 | } |
| Sissors | 0:e069f9f26768 | 83 | |
| anywill | 5:22fb02a92579 | 84 | printf("Found %d device(s)\r\n\n", num_devices);//检测到n个测温设备 |
| anywill | 5:22fb02a92579 | 85 | |
| emcu | 4:02a922030bc3 | 86 | while(1) |
| emcu | 4:02a922030bc3 | 87 | { |
| Sissors | 0:e069f9f26768 | 88 | probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
| Sissors | 0:e069f9f26768 | 89 | for (int i = 0; i<num_devices; i++) |
| anywill | 5:22fb02a92579 | 90 | printf("Device %d returns %3.3f oC\r\n", i, probe[i]->temperature()); |
| anywill | 5:22fb02a92579 | 91 | |
| emcu | 4:02a922030bc3 | 92 | |
| Sissors | 0:e069f9f26768 | 93 | wait(1); |
| Sissors | 0:e069f9f26768 | 94 | } |
| Sissors | 0:e069f9f26768 | 95 | |
| Sissors | 0:e069f9f26768 | 96 | } |
| Sissors | 0:e069f9f26768 | 97 | |
| Sissors | 0:e069f9f26768 | 98 | #else |
| Sissors | 0:e069f9f26768 | 99 | #include "mbed.h" |
| Sissors | 0:e069f9f26768 | 100 | #include "DS1820.h" |
| Sissors | 0:e069f9f26768 | 101 | |
| Sissors | 0:e069f9f26768 | 102 | DS1820 probe(DATA_PIN); |
| Sissors | 0:e069f9f26768 | 103 | |
| Sissors | 0:e069f9f26768 | 104 | int main() { |
| Sissors | 0:e069f9f26768 | 105 | while(1) { |
| Sissors | 0:e069f9f26768 | 106 | probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
| anywill | 5:22fb02a92579 | 107 | printf("It is %3.3f oC\r\n", probe.temperature()); |
| Sissors | 0:e069f9f26768 | 108 | wait(1); |
| Sissors | 0:e069f9f26768 | 109 | } |
| Sissors | 0:e069f9f26768 | 110 | } |
| Sissors | 0:e069f9f26768 | 111 | |
| emcu | 4:02a922030bc3 | 112 | #endif |
