想請問一下,如果我要將溫溼度感測器改成DS18B20的溫度控制器了話,我需要改哪段城式才能讓我順利存取
1.比較兩者差異調接腳或程式2.換成DHT3.使用過時(已停產?)的板子開發不妥
老師不好意思 我還是不太了解,我是新手,想請老師能講清楚一些,這個是 我們溫度感測的程式DS18B20(溫度感測器)// 匯入程式庫標頭檔 #include #include // Arduino數位腳位2接到1-Wire裝置#define ONE_WIRE_BUS 2// 運用程式庫建立物件OneWire oneWire(ONE_WIRE_BUS);DallasTemperature sensors(&oneWire);void setup(void){ Serial.begin(115200); Serial.println("Temperature Sensor"); // 初始化 sensors.begin();}void loop(void){ // 要求匯流排上的所有感測器進行溫度轉換(不過我只有一個) sensors.requestTemperatures(); // 取得溫度讀數(攝氏)並輸出, // 參數0代表匯流排上第0個1-Wire裝置 Serial.println(sensors.getTempCByIndex(0)); delay(1000);}
這是是 TEMBOO+YUN+溫溼度感測器(DH11)#include #include #include // Contains Temboo account information#include "TembooAccount.h" // TembooAccount.h是依照AppendRow成功後自動產生的header file sample code而建立的档案(档名可以自己取,只要這裡和.h档同名即可)// Variablesint lightLevel;float humidity;float temperature;unsigned long time;// Process to get the measurement timeProcess date;// Your Google Docs dataconst String GOOGLE_USERNAME = "0000000000000000";const String GOOGLE_PASSWORD = "000000000";const String SPREADSHEET_TITLE = "green";// Include required libraries#include "DHT.h"// DHT11 sensor pins#define DHTPIN 8#define DHTTYPE DHT11// DHT instanceDHT dht(DHTPIN, DHTTYPE);// Debug mode ?boolean debug_mode = true;void setup() {// Start Serialif (debug_mode == true){Serial.begin(115200);delay(4000);//while(!Serial);}// Initialize DHT sensordht.begin();// Start bridgeBridge.begin();// Start date processtime = millis();if (!date.running()) {date.begin("date");date.addParameter("+%D-%T");date.run();}if (debug_mode == true){Serial.println("Setup complete. Waiting for sensor input...\n");}}void loop() {// Measure the humidity & temperaturehumidity = dht.readHumidity();temperature = dht.readTemperature();// Measure light levelint lightLevel = analogRead(A0);if (debug_mode == true){Serial.println("\nCalling the /Library/Google/Spreadsheets/AppendRow Choreo...");}// Append data to Google Docs sheetrunAppendRow(lightLevel, temperature, humidity);// Repeat every 10 minutesdelay(20000);}// Function to add data to Google Docsvoid runAppendRow(int lightLevel, float temperature, float humidity) {TembooChoreo AppendRowChoreo;// Invoke the Temboo clientAppendRowChoreo.begin();// Set Temboo account credentialsAppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);// Set Choreo inputs AppendRowChoreo.addInput("SpreadsheetTitle", "green"); AppendRowChoreo.addInput("RefreshToken", "1/BmQpDFlxYuCFCc1FvCXdakmJVvxYuU0m812EDPuKNlI"); AppendRowChoreo.addInput("ClientSecret", "JB1GRQR4wOaTnsmkOuEn3Ttv"); AppendRowChoreo.addInput("ClientID", "42860837124-dl666hpijf61njpldhiv09ki9nlvka8j.apps.googleusercontent.com");// Identify the Choreo to runAppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");// Restart the date process:if (!date.running()) {date.begin("date");date.addParameter("+%D-%T");date.run();}// Get dateString timeString = date.readString();// Format dataString data = "";data = data + timeString + "," + String(temperature) + "," + String(humidity) + "," + String(lightLevel);// Set Choreo inputsAppendRowChoreo.addInput("RowData", data); //此data字串即是要寫到Google spreedsheet的sensesing data// Run the Choreounsigned int returnCode = AppendRowChoreo.run();// A return code of zero means everything workedif (returnCode == 0) {if (debug_mode == true){Serial.println("Completed execution of the /Library/Google/Spreadsheets/AppendRow Choreo.\n");}} else {// A non-zero return code means there was an error// Read and print the error messagewhile (AppendRowChoreo.available()) {char c = AppendRowChoreo.read();if (debug_mode == true){ Serial.print(c); }}if (debug_mode == true){ Serial.println(); }}AppendRowChoreo.close();}
1.您們有把我寫的這個DHT範例如數跑过一次嗎?自己動手親做一次,可增加成功經驗外,並能累積一些「手感」。很甜的!2.如果您們一定要用「DS18B20」,建議先在Arduino平台上跑过。範例程式Google一下,應該有一堆。3.您們有學过「C語言」嗎?玩sensros的裡底層要有程式去控硬体,要嘛用別人寫好的libraries,include進來;要嘛自己寫。
張貼留言
5 則留言:
想請問一下,如果我要將溫溼度感測器改成DS18B20的溫度控制器了話,我需要改哪段城式才能讓我順利存取
1.比較兩者差異調接腳或程式
2.換成DHT
3.使用過時(已停產?)的板子開發不妥
老師不好意思 我還是不太了解,我是新手,想請老師能講清楚一些,這個是 我們溫度感測的程式
DS18B20(溫度感測器)
// 匯入程式庫標頭檔
#include
#include
// Arduino數位腳位2接到1-Wire裝置
#define ONE_WIRE_BUS 2
// 運用程式庫建立物件
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup(void)
{
Serial.begin(115200);
Serial.println("Temperature Sensor");
// 初始化
sensors.begin();
}
void loop(void)
{
// 要求匯流排上的所有感測器進行溫度轉換(不過我只有一個)
sensors.requestTemperatures();
// 取得溫度讀數(攝氏)並輸出,
// 參數0代表匯流排上第0個1-Wire裝置
Serial.println(sensors.getTempCByIndex(0));
delay(1000);
}
這是是 TEMBOO+YUN+溫溼度感測器(DH11)
#include
#include
#include
// Contains Temboo account information
#include "TembooAccount.h" // TembooAccount.h是依照AppendRow成功後自動產生的header file sample code而建立的档案(档名可以自己取,只要這裡和.h档同名即可)
// Variables
int lightLevel;
float humidity;
float temperature;
unsigned long time;
// Process to get the measurement time
Process date;
// Your Google Docs data
const String GOOGLE_USERNAME = "0000000000000000";
const String GOOGLE_PASSWORD = "000000000";
const String SPREADSHEET_TITLE = "green";
// Include required libraries
#include "DHT.h"
// DHT11 sensor pins
#define DHTPIN 8
#define DHTTYPE DHT11
// DHT instance
DHT dht(DHTPIN, DHTTYPE);
// Debug mode ?
boolean debug_mode = true;
void setup() {
// Start Serial
if (debug_mode == true){
Serial.begin(115200);
delay(4000);
//while(!Serial);
}
// Initialize DHT sensor
dht.begin();
// Start bridge
Bridge.begin();
// Start date process
time = millis();
if (!date.running()) {
date.begin("date");
date.addParameter("+%D-%T");
date.run();
}
if (debug_mode == true){
Serial.println("Setup complete. Waiting for sensor input...\n");
}
}
void loop() {
// Measure the humidity & temperature
humidity = dht.readHumidity();
temperature = dht.readTemperature();
// Measure light level
int lightLevel = analogRead(A0);
if (debug_mode == true){
Serial.println("\nCalling the /Library/Google/Spreadsheets/AppendRow Choreo...");
}
// Append data to Google Docs sheet
runAppendRow(lightLevel, temperature, humidity);
// Repeat every 10 minutes
delay(20000);
}
// Function to add data to Google Docs
void runAppendRow(int lightLevel, float temperature, float humidity) {
TembooChoreo AppendRowChoreo;
// Invoke the Temboo client
AppendRowChoreo.begin();
// Set Temboo account credentials
AppendRowChoreo.setAccountName(TEMBOO_ACCOUNT);
AppendRowChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME);
AppendRowChoreo.setAppKey(TEMBOO_APP_KEY);
// Set Choreo inputs
AppendRowChoreo.addInput("SpreadsheetTitle", "green");
AppendRowChoreo.addInput("RefreshToken", "1/BmQpDFlxYuCFCc1FvCXdakmJVvxYuU0m812EDPuKNlI");
AppendRowChoreo.addInput("ClientSecret", "JB1GRQR4wOaTnsmkOuEn3Ttv");
AppendRowChoreo.addInput("ClientID", "42860837124-dl666hpijf61njpldhiv09ki9nlvka8j.apps.googleusercontent.com");
// Identify the Choreo to run
AppendRowChoreo.setChoreo("/Library/Google/Spreadsheets/AppendRow");
// Restart the date process:
if (!date.running()) {
date.begin("date");
date.addParameter("+%D-%T");
date.run();
}
// Get date
String timeString = date.readString();
// Format data
String data = "";
data = data + timeString + "," + String(temperature) + "," + String(humidity) + "," + String(lightLevel);
// Set Choreo inputs
AppendRowChoreo.addInput("RowData", data); //此data字串即是要寫到Google spreedsheet的sensesing data
// Run the Choreo
unsigned int returnCode = AppendRowChoreo.run();
// A return code of zero means everything worked
if (returnCode == 0) {
if (debug_mode == true){
Serial.println("Completed execution of the /Library/Google/Spreadsheets/AppendRow Choreo.\n");
}
} else {
// A non-zero return code means there was an error
// Read and print the error message
while (AppendRowChoreo.available()) {
char c = AppendRowChoreo.read();
if (debug_mode == true){ Serial.print(c); }
}
if (debug_mode == true){ Serial.println(); }
}
AppendRowChoreo.close();
}
1.您們有把我寫的這個DHT範例如數跑过一次嗎?自己動手親做一次,可增加成功經驗外,並能累積一些「手感」。很甜的!
2.如果您們一定要用「DS18B20」,建議先在Arduino平台上跑过。範例程式Google一下,應該有一堆。
3.您們有學过「C語言」嗎?玩sensros的裡底層要有程式去控硬体,要嘛用別人寫好的libraries,include進來;要嘛自己寫。
張貼留言