Posted on Leave a comment

Realtime Clock with 18F2550

I am trying to make use of the previous circuit on connecting LED display to 18F2550, and combining this with Real time clock module DS3231. So here are the diagram of the connection:

Here are the list of parts used in this project:

  • 18F2550 USB development board
  • Realtime clock DS3231
  • Button cell battery CR2032 (for realtime clock)
  • LCD Display
  • 10K ohm variable resistor (to control the brightness of LCD display)
  • 200 ohm pull up resistor

The 18F2550 USB development board can be shown below:

This board comes loaded with boot loader to allow easy loading of the firmware code. I am using the MPLAB IDE v8.92 to compile and build the code for the USB development board.

I am also using the previously ported LCD display code to use in this project.

Connect Everything together

First we connect the LCD Display to the Development board. We are only using 4 bit for the data transfer so here are the detail connection of the LCD Display:

  • RS LCD —- C6 Dev Board
  • EN LCD —- C7 Dev Board
  • D4 LCD —- A0 Dev Board
  • D5 LCD —- A1 Dev Board
  • D6 LCD —- A2 Dev Board
  • D7 LCD —- A3 Dev Board

You will also need to connect a pull up resistor to Anode pin of LCD display before connecting to +5V and Middle of 10k resistor to VO pin of LCD display, while the other ends of the 10K resistor is connected to VCC and GND respectively.

Test the LCD connection.

Once you had connected the LCD Display to 18F2550 development board you can load the demo display program. To load the demo program (C18-BOLT-LCD-MESSAGE-SCROLLING.HEX), you can use the loader program “MiEUSBHIDLoader.exe“. This program will display a scrolling Alphabet in the first row and numbers on the second row of the LCD Display, please make sure that this is working properly prior to continuing to the next step.

Connecting the Real time clock

First connect the button cell CR2032 to the realtime clock module DS3231. Then connect the DS3231 to the USB development board. To connect the real time clock DS3231 to the 18F2550 USB Development board use the following connection:

  • SDA RTC —- B0 Dev Board
  • SCL RTC —- B1 Dev Board

You will also need to connect the VCC of DS3231 to the 5V and GND to the ground of the 18F2550 Development board. Once this is done you can now upload the RTC clock program. You might want to recompile the code to set the date and time the first time you are loading the code

// uncomment the following to set the date and time
DS3231_SetDate(29,03,19); // setting the date to 29-Mar-2019
DS3231_SetTime(00,19,01); // setting the time to 00:19:01

Once the code is loaded, the date and time is now saved in the DS3231 module. As long as the button cell CR2032 is connected to the DS3231 module, the date and time will be retained. Now you need to recompile the code again with the above code uncommented, this is to ensure that every time you reset the USB development board, it will not reset the date and time of RTC module back to the date time above.

Please drop me a line and share this post if you like it, and let me know what I can improve on. Stay tune for the next revision that will include buttons to set the date and time.

Posted on Leave a comment

Connecting ESP8266 to P10 Display and displaying data from webserver

The concept is to have the ESP8266 driving the P10 display by reading the data from the webserver, this will ensure that the data can be updated automatically in the webserver via some automation and the P10 is being set to poll the data periodically and displaying it on the P10 display. You can see the concept in the following diagram:

Here are the connection diagram to connect to ESP8266 to P10 Display.


For simplicity here are the connection required from ESP8266 to the P10 header.

Coding preparation

What you will need is the Arduino IDE interface and loaded with the following library:

  1. DMD2 library can be downloaded via the link
  2. SPI library (this is usually already installed with Arduino)
  3. ESP8266WiFi library (you can search for this in the Arduino library via Sketch->Include Library->Manage Library and put ESP8266 in the search box)

The first step is to connect the ESP8266 to your WIFI, this is done in the following code

char ssid[] = "ssid"; //  your network SSID (name)
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
void setup() {
WiFi.begin(ssid, pass);

Then assuming the data is located in the webserver path /arduino/message.json, we then need to initialise the location as below:

const char* webserver = "";      // webserver where the cloud is hosted
String messagePath = "/arduino/message.json"; // location of message data

Once the connection to webserver is established, the following function will parse the data and store in the local variable MESSAGE:

void readMessage(){
DebugLn("Connecting to " + String(webserver));
WiFiClient client;
const int httpPort = 80;
if (!client.connect(webserver, httpPort)) {
Serial.println("connection failed");
client.print(String("GET ") + messagePath + " HTTP/1.1\r\n" +
"Host: " + webserver + "\r\n" +
"Connection: keep-alive\r\n\r\n");
delay(500); // wait for server to respond
// read response
String section="header";
String line = client.readStringUntil('\r');
// Serial.print(line);
// we’ll parse the HTML body here
if (section=="header") { // headers..
if (line=="\n") { // skips the empty space at the beginning
else if (section=="json") { // print the good stuff
String result = line.substring(1);
// Parse JSON
int size = result.length() + 1;
char json[size];
result.toCharArray(json, size);
StaticJsonBuffer<200> jsonBuffer;
JsonObject& json_parsed = jsonBuffer.parseObject(json);
if (!json_parsed.success())
Serial.println("parseObject() failed");
// read the message
MESSAGE = json_parsed["message"];
Serial.println(MESSAGE); //display message in serial window
Serial.print("closing connection. ");

The last piece is to display the message to the screen with the following function:

void scrolling() {
const char next = MESSAGE; while (next) {
dmd.clearScreen();// clear screen
if (i != 0) {
box.print(*next); //print the led pannel
delay(800); // letters speed changing

The full source code can be downloaded via the following link.

Please don’t hesitate to let me know if you experience any issue with the code. You can buy me a coffee later if you like this post.