PHPoC [WiFi] Shield has a built-in rechargeable battery and RTC that allow to keep date and time information even when power is down.
This tutorial shows how to use Arduino Uno/Mega to get date and time information from RTC on PHPoC [WiFi] Shield. Date and time are printed to serial monitor.
Hardware Required
- Arduino Uno or Mega
- USB Cable for Arduino
- PHPoC Shield (P4S-347) or PHPoC WiFi Shield (P4S-348)
Circuit
- Stack PHPoC Shield or PHPoC WiFi Shield on Arduino Uno or Mega
Note that: Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT be used for general I/O.
Install Arduino IDE
If you have not install Arduino IDE yet, please download and install Arduino IDE .
Install Library
- Run Arduino IDE.
- Navigate to Sketch > Include Library > Manage Libraries
- Search "Phpoc" on search bar of the Library Manager.
- Select the PHPoC library and press the [Install] button.
- Restart Arduino IDE for the next step.
Source Code
- Open "DataTime" example on Arduino IDE
Code:// Arduino RTC Date & Time Test // // PHPoC Shield and PHPoC WiFi Shield are Internet Shields for Arduino Uno and // Mega. // // PHPoC [WiFi] Shield has a built-in rechargeable battery and RTC that allow to // keep date and time information even when power is down. // // This is an example of using Arduino Uno/Mega to get date and time information // from RTC on PHPoC [WiFi] Shield and print it to serial monitor. // // Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on // the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT // be used for general I/O. // // This example code was written by Sollae Systems. It is released into the // public domain. // // Tutorial for the example is available here: // https://forum.phpoc.com/articles/tutorials/1244-arduino-date-and-time #include <Phpoc.h> PhpocDateTime datetime; void setup() { Serial.begin(9600); while(!Serial) ; // initialize PHPoC [WiFi] Shield: Phpoc.begin(PF_LOG_SPI | PF_LOG_NET); Serial.println("Get year/month/day/dayofWeek/hour/minute/second from RTC in PHPoC Shield"); Serial.print(datetime.year()); Serial.print('-'); Serial.print(datetime.month()); Serial.print('-'); Serial.print(datetime.day()); Serial.print(' '); Serial.print(datetime.dayofWeek()); Serial.print(' '); Serial.print(datetime.hour()); Serial.print(':'); Serial.print(datetime.minute()); Serial.print(':'); Serial.print(datetime.second()); Serial.println(); // set date and time format: datetime.date(F("Y-m-d H:i:s")); } void loop() { Serial.println(datetime.date()); delay(10); }
- The line-by-line explaination of code is presented inside the code.
For more detail of functions's reference, please refer to PHPoC Shield for Arduino Library Reference - Compile the example code and upload to Arduino by clicking "Upload" button on Arduino IDE
Test and Result
- Open Serial Monitor tool on Arduino IDE to see the output log
See Also
- Arduino - TCP Chat Server
- Arduino - TCP IPv6 Chat Server
- Arduino - Telnet Server
- Arduino - SSH Server
- Arduino - SSL Server
- Arduino - Email Client
- Arduino - Gmail Client
- Arduino - Web Client
- Arduino - IPv6 Web Client
- Arduino - SSL Web Client
- Arduino - SSL IPv6 Web Client
- Arduino - Web Server - Remote Push
- Arduino - Web Server - Remote Slide
- Arduino - Web Server - Remote Pad
- Arduino - Web Serial Plotter
- Arduino - Web Serial Monitor
- Arduino - RTC Date and Time
References