NUCLEO-F070R-DS1820

Dependencies:   mbed

Fork of NUCLEO-F401RE-DS1820andThermistorNTC10K by Enrico Marinoni

main.cpp

Committer:
anywill
Date:
2016-10-21
Revision:
5:22fb02a92579
Parent:
4:02a922030bc3
Child:
6:7f43285de85b

File content as of revision 5:22fb02a92579:


/**

    NUCLEO-F070R + DS18B20 
    

By:       
Date:     Oct.2016
Version:  1.0
Name:     NUCLEO-F070R-DS1820
NOTE:     For more info see here: http://www.emcu.it/NUCLEOevaBoards/mBed/QSG-Mbed-Library.pdf
        原程序带NTC测温,本人将已其删除

UART   
    Baud Rate:    9600 
    Data Bit:     8
    Parity:       NONE
    Stop Bit:     1
    Flow Control: NONE
    

Connect to the NUCLEO-F070R8 the DS18B20 sensor (see the schematic below).
The temperature sampling time is 1 sec.

 DS18B20 front view
    __________
   |          |
   |    DS    |
   |   18B20  |   
   |          |
   |__________|
     |   |   |
     1   2   3
    GND  DQ VCC (3V3)
     |   |   |______________ to VCC (3.3V on the NUCLEO-F070R)  
     |   |  _|_
     |   |  | |
     |   |  | | 4K7
     |   |  | |
     |   |  -|-
     |   |___|______________ to A1 (on the NUCLEO-F070RE) 
     |
     |
     |______________________ to GND (on the NUCLEO-F070RE)   

This SW is just for only one DS18B20
This SW is a derivative of:: https://developer.mbed.org/users/Sissors/code/DS1820_HelloWorld/
On the: https://developer.mbed.org/users/Sissors/code/DS1820_HelloWorld/ there is a multi sensor (DS18B20) example.

 
*/

#define MULTIPLE_PROBES
#define DATA_PIN        A1

#ifdef MULTIPLE_PROBES

#include "mbed.h"
#include "DS1820.h"

#define MAX_PROBES      16

float get_temperature(void);

//AnalogIn thermistor(A5); // Thermistor

float temp=0;
float tempArr[100];
int n=0;//n个测温设备
Serial pc(SERIAL_TX, SERIAL_RX); // 虚拟 USART2 tx, rx
DS1820* probe[MAX_PROBES];
 
int main()
 {  
    // Initialize the probe array to DS1820 objects
    int num_devices = 0;
    while(DS1820::unassignedProbe(DATA_PIN)) {
        probe[num_devices] = new DS1820(DATA_PIN);
        num_devices++;
        if (num_devices == MAX_PROBES)
            break;
    }
    
    printf("Found %d device(s)\r\n\n", num_devices);//检测到n个测温设备
    
    while(1) 
    {
        probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        for (int i = 0; i<num_devices; i++)
            printf("Device %d returns %3.3f oC\r\n", i, probe[i]->temperature());
        
        
        wait(1);
    }
    
}

#else
#include "mbed.h"
#include "DS1820.h"
 
DS1820 probe(DATA_PIN);
 
int main() {
    while(1) {
        probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        printf("It is %3.3f oC\r\n", probe.temperature());
        wait(1);
    }
}

#endif