2016/07/31

Adafruit Max6675 Library For Thermocouple Need To Be Modified To Run On ESP8266

Test the sketch "Wiring Thermocouple Max6675 on ESP8266 12E NodeMCU" of 14Core, and find Adafruit MAX6675 library installed using Library Manager is not compatible with ESP8266.

By replacing max6675.h and max6675.cpp with the ones from SirUli on github, copying other files on the link and commenting out the statements relating display functions, the sketch of 14Core has been compiled and run without fail on NodeMCU Dev Kit 1.0.

Also the serialthermocoupl.pde example sketch runs without fail.

I think the tutorials of 14Core had better specify from where the library they downloaded.

Wiring from 14Core



Output


Sketch

#include <max6675.h>
// #include <Wire.h>
// #include <Adafruit_GFX.h>
// #include <ESP_Adafruit_SSD1306.h>

// #define OLED_RESET 4

int ktcSO = 12;
int ktcCS = 13;
int ktcCLK = 14;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);
// Adafruit_SSD1306 display(OLED_RESET);
  
void setup() {
  Serial.begin(115200);
  Serial.println("Max6675 test");
  delay(500);
  // display.begin(SSD1306_SWITCHCAPVCC, 0x78>>1);
  // display.display();
  // delay(2000);
  // display.clearDisplay();
}

void loop() {
  // basic readout test
  //  
  //  display.setTextSize(2);
  //  display.setTextColor(WHITE);
  //  display.setCursor(52,10);
  //  display.print((char)223); 
  //  display.print("C = "); 
  //  display.print(ktc.readCelsius());
  //  display.print((char)223); 
  //  display.print("\t F = ");
  //  display.setCursor(52,30);
  //  display.println(ktc.readFahrenheit());

  float DC = ktc.readCelsius();
  // Read temperature as Celsius
  float DF = ktc.readFahrenheit();
  
   Serial.print("C = "); 
   Serial.print(ktc.readCelsius());
   Serial.print("\t F = ");
   Serial.println(ktc.readFahrenheit());
// 

 delay(1000);
 // displayData();
}

void displayData(){
  // display.setTextSize(1);
  // display.setCursor(5,1);
  // display.println("14CORE|THERMOCOUPLE");
  // display.setTextSize(2);
  // display.setTextColor(WHITE);
  // display.setCursor(18,20);
  // display.print((char)248); 
  // display.print("C:"); 
  // display.print(ktc.readCelsius());
  
    
  // display.setCursor(18,40);
  // display.print((char)248); 
  // display.print("F:");
  // display.println(ktc.readFahrenheit());
  // display.display();
  // display.clearDisplay();
}

IPs And Domain Names of NTP Servers Available Publicly In Taiwan

From time to time I need an NTP server available publicly in Taiwan for reference to compare with my homebrew MakerNTP (posted on Dec. 24, 2015) Stratum 1 GPS-based NTP server, so I list some useful NTP servers.

1. time.stdtime.gov.tw: 118.163.81.61

2. tick.stdtime.gov.tw: 118.163.81.62

3. watch.stdtime.gov.tw: 118.163.81.63

4. tock.stdtime.gov.tw: 211.22.103.157

5. clock.stdtime.gov.tw: 211.22.103.158

6. tw.pool.ntp.org: A. 103.18.128.60 B.  117.56.223.235 C. 59.124.29.241 D. 59.125.122.217


2016/07/13

Sketch Displaying Temperature and Humidity on Serial Monitor Using ESP8266 NodeMCU Dev Kit 1.0 and DHT11


Output



Sketch

// Modified by Befun Hung on Jul. 13, 2016 with Arduino IDE supporting ESP8266
// Runs on NodeMCU Dev Kit 1.0 without fails with DHT11 breakout 
// Original source code from 14core.com commented out OLED part and correct typos
// "Wiring DHT11, DHT22, with OLED Screen on ESP8266 12E"
// Wiring diagram show data pin of DHT connect D6 (GPIO 12)
// While the sketch define DHTPIN 14 (D5) 

// #include <Wire.h>
// #include <Adafruit_GFX.h>
// #include <ESP_Adafruit_SSD1306.h>
#include "ESP8266WiFi.h"
#include "DHT.h"

// #define OLED_RESET 4
// Adafruit_SSD1306 display(OLED_RESET);

// #define DHTPIN 12     // Connected to Pin D6 in NodeMCU
#define DHTPIN 14     // Connected to Pin D5 in NodeMCU

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);

/*
byte img [] = { 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x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 0x0, 0x20, 0x0, 0x0, 0xe, 0x0, 
0x0, 0x70, 0x0, 0x0, 0x0, 0x1, 0x80, 0x70, 0x0, 0x0, 0x0, 0x1, 0x80, 0xf8, 0x0, 
0x0, 0x0, 0x3, 0xc0, 0xf8, 0x0, 0x0, 0x0, 0x3, 0xc0, 0xf8, 0x0, 0x0, 0x0, 0x3, 
0xc0, 0x70, 0x0, 0x0, 0x0, 0x3, 0xc0, 0x0, 0x0, 0x0, 0x0, 0x3, 0xc0, 0x0, 0x0, 
0x0, 0x0, 0x1, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 

 };
 */

void setup() {
  Serial.begin(115200); 
  Serial.println("DHTxx test!");

  // dht begin
  dht.begin();
  
  // set display
  // display.begin(SSD1306_SWITCHCAPVCC, 0x78>>1);
  // display.display();
  // delay(2000);
  // display.clearDisplay();
  
}

/* 
void showTemp(float temp,float hud) {
  display.drawBitmap(0, 5,  img, 48, 50, 1);
  display.setTextSize(1);
  display.setCursor(3,0);
  display.println("Temperature/Humidity");
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(52,10);
  display.print(temp);
  display.println("C");
  display.setCursor(52,30);
  display.print(hud);
  display.println("%");
  display.setTextSize(1);
  display.setCursor(52,50);
  display.println("14CORE.COM");
  display.display();
  display.clearDisplay();
}
*/

void loop() {

  delay(2000);   // Wait a few seconds between measurements.
  float h = dht.readHumidity();
     // Serial.print("h= ");
     // Serial.println(h);
  float t = dht.readTemperature();   // Read temperature as Celsius
     // Serial.print("t= ");
     // Serial.println(t);

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
       Serial.println();
    return;
  }
  Serial.print("Humidity: ");    // show in serial monitor
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");    // show in serial monitor
  Serial.print(t);
  Serial.print(" *C \n");
  // showTemp(t,h);   // show temp
}