Date, Time & Temperature Display Using XinaBox

Cool OLED display showing the date, time and temperature in Celsius and Fahrenheit using Xinabox xChips based off ESP8266.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Things Used in This Project

Hardware components

  • XinaBox IP01 x 1
    xChip USB Programmer based on FT232R From FTDI Limited
  • XinaBox CW01 x 1
    xChip Wi-Fi Core based on ESP8266 Wi-Fi Module
  • XinaBox SW01 x 1
    xChip Temperature, humidity and atmospheric pressure sensor based on the BME280 from Bosch.
  • XinaBox OD01 x 1
    xChip 128x64 Pixel OLED Display
  • XinaBox PU01 x 1
    xChip USB (Type A) Power Supply
  • XinaBox XC10 x 1
    xChip Bus Connectors
  • 5V USB Power Supply x 1

Software apps and online services

Step 2: Story

Introduction

I built this project to display the date, UCT time and temperature using XinaBox xChips that uses the I2C bus protocol. The time was retrieved from a google NTP server. The ambient temperature was measured using the SW01 xChip and was displayed on the OD01 xChip OLED display in Celsius and Fahrenheit. The image below shows the OLED display.

OLED displaying date, time and temperature

Step 3: Download Necessary Files

You will require the following libraries and software for this project.

  • Arduino IDE - Development Software in which you will code
  • xSW01 - Temperature sensor library
  • xCore - Core library for XinaBox xChips
  • xOD01 - OLED Display library.
  • Timezone - Library to choose your timezone
  • Time - To use time functions
  • NTPClient - Enables you to get time from a server
  • You will also need to download the ESP8266 board and follow the instructions that accompany it in order to have the board installed

Once downloaded you will install the IDE and the libraries. It is fairly straight forward if you follow the instructions.

Step 4: Assemble

Your main xChip that will execute and process the program is the CW01. It is based on the ESP8266 WiFi Module and uses the I2C bus protocol. In order to program to the CW01, you will need a programming xChip. The IP01 allows us to program the CW01 via the USB port on our computer simply by clicking together the two xChips using XC10 bus connectors and inserting it into the the USB port. No wiring and no soldering required. One thing to take note of is the orientation of the xChip identification names. They should all be orientated in the same direction. You should now have the following setup.

Click together CW01 and IP01 and insert it into the USB port on your computer

If you are familiar with xChips you may connect every xChip together using XC10 bus connectors that you want to use for your project and then insert it into the USB port. We will be using SW01 temperature sensor and the OD01 OLED display.

You may connect all your chips together and then insert it into your USB port

Step 5: Program

Download or copy and paste the code below into your Arduino IDE. If you aren't making any changes to the code simply enter your WiFi details in their respective fields as shown below. Also enter a reliable NTP time server. I've used a Google time server for this project.

WiFi details and NTP time server

Now compile and upload. Make sure you've selected the correct COM port and board under the tools menu in the Arduino IDE. Once uploaded, the time, date and temperature should show as below.

After uploading you should see the following

Step 6: Make It Portable

You may now remove the unit from your USB port and separate each xChip by simply pulling it apart. Since the programming is complete, IP01 is no longer required. You may now connect your project in any manner you wish as long as the identification names are all orientated in the same direction. To power our unit we will use the PU01. This allows us to power it from a normal power bank or any 5V USB power supply. I've connected mine as shown below.

Final assembly. xChips can be connected in any way you desire.

Step 7: Conclusion

This project will take 20min to complete. If you want the time in your location, consider looking at the example code in the Timezone library or do some arithmetic with the UTC time. No wires were used and no soldering was required.

Step 8: Code

Date_Time_Temp.ino Arduino
Simply enter your WiFi details in their respective fields and upload to your board.

#include <xCore.h>           // include core library for XinaBox xCHIPS
#include <xOD01.h>           // include OLED display library
#include <xSW01.h>           // include the temperature sensor library
#include <xESP8266WiFi.h>    // include ESP8266WiFi functionality
#include <String.h>
// include time libraries
#include <WifiUDP.h>
#include <NTPClient.h>
#include <Time.h>
#include <TimeLib.h>
#include <Timezone.h>

xSW01 SW01;
// define NTP properties
#define ntpOffset   60 * 60      // in seconds
#define ntpInterval 60 * 1000    // in miliseconds
// insert a reliable ntp time server between the double quotes
// here i've used a google ntp time server
#define ntpAddress "time1.google.com"

// set up the NTP UDP client
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, ntpAddress, ntpOffset, ntpInterval);

// temperature variable
float tempC;    // celsius
float tempF;    // fahrenheit

// your wifi details
const char* wifi_ssid = "XinaBox";             // your wifi ssid
const char* wifi_pass = "RapidIoT";           // your wifi password

// date and time variable
String date;
String clktime;

// variables containing days and months
const char * days[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"} ;
const char * months[] = {"Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec"} ;
const char * ampm[] = {"AM", "PM"} ;

void setup ()
{

  tempC = tempF = 0;    // initialize temperature to zero
  timeClient.begin();   // start the NTP UDP client
  // start serial communication
  Serial.begin(115200);
  // start i2c communication and set pins
  Wire.begin(2, 14);
  // start temperature sensor
  SW01.begin();
  // start OLED display
  OLED.begin();
  // clear OLED display
  OD01.clear();

  // establish wifi connection
  wifi_connect();
  delay(1000);
}

void loop()
{
  // run if wifi connection is established
  if (WiFi.status() == WL_CONNECTED) {
    SW01.poll();                  // read temperature
    tempC = SW01.getTempC();      // store temp in celcius
    tempF = SW01.getTempF();      // store temp in fahrenheit
    date = "";                    // clear date variable
    clktime = "";                 // clear time variable

    // update the ntp client and get the unix utc timestamp
    timeClient.update();
    unsigned long epochTime =  timeClient.getEpochTime();

    // convert received time stamp to time_t object
    time_t utc;
    utc = epochTime;

    // utc time
    TimeChangeRule utcRule = {"UTC", Last, Sun, Mar, 1, 0};
    Timezone UTC(utcRule, utcRule);

    // format time variables
    date += days[weekday(utc) - 1];
    date += ", ";
    date += months[month(utc) - 1];
    date += " ";
    date += day(utc);
    date += ", ";
    date += year(utc);

    // format the time to 12-hour format with AM/PM and no seconds
    clktime += hourFormat12(utc);
    clktime += ":";
    if (minute(utc) < 10) // add a zero if minute is under 10
      clktime += "0";
    clktime += minute(utc);
    clktime += " ";
    clktime += ampm[isPM(utc)];

    // display time, date and tempearure on OLED
    OD01.set2X();
    OD01.print("  ");
    OD01.println(clktime);
    OD01.set1X();
    OD01.println("");
    OD01.println("");
    OD01.print("   ");
    OD01.print(tempC);
    OD01.print(" C   ");
    OD01.print(tempF);
    OD01.println(" F");
    OD01.println("");
    OD01.println(date);
  } else {    // try to restablish wifi connection if disconnected
    wifi_connect();
  }
  delay(5000);  // updates display every 5seconds
}

// establishes a wifi connection
void wifi_connect() {
  Serial.print("Connecting to ");
  Serial.print(wifi_ssid);
  WiFi.begin(wifi_ssid, wifi_pass);    // connect to wifi
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print(".");
    delay(300);
  }
  Serial.println("");
  Serial.print("Connected to WiFi at ");
  Serial.print(WiFi.localIP());
  Serial.println("");
}

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    Discussions