Close

Time is on my side

A project log for Wi-Fi Thermal Receipt Printer V1

This was a technical thesis project designed to allow a user to get a print out of the current weather and the word of the day via Wi-Fi.

scott-clandininScott Clandinin 07/12/2016 at 22:410 Comments

The implementation of getting the current time went really well, and its improved the project nicely.

The last project log details how I used a HEAD request to google to get the current time in GMT, and convert that to CST.

I decided to do a request for time every minute, and update the current time in memory, and on the LCD. While the weather is being requested, the LCD reflects this in case the user wants to do a print. It takes about 5-7 seconds to update the time.

It takes so long because my current method for getting data begins with a fresh connection to the network. I will soon try to find a way to improve this time and still ensure the program does not freeze should the signal be lost before the button is pressed.

Timers and Interrupts

To ensure time is requested every minute, timers and interrupts need to be used. I used the timer0 module in the PIC and set it up to trigger an interrupt every minute. The 16-bit timer can be set up to trigger an interrupt on overflow, so the timer0 registers need to be set up to overflow every minute. I used the following equation to determine the number:


I chose an overflow time of 10ms (100Hz), so every 10ms, an interrupt would occur and increment a counter. Once the counter reached 6000, 1 minute would have passed, and a call for time would be made. During API calls it is crucial to disable interrupts so no data is missed. We don't want the program to enter an interrupt while we are waiting for data to arrive. The format for API calls would be:

  1. Disable global interrupts
  2. Make the call
  3. Enable global interrupts
  4. Reset the timer0 registers to 0xD8F0

To get a better idea of how this works you can check out the Github repository.

Scheduled Printing

I added functionality to have the printer print off every day at a preset time. For now I have programmed the device to print off the weather and word of the day every day at 7AM. This is a great excuse to look into adding weather forecast to the project. Who needs to go check the weather network when you get a print out of it automatically every morning?

Discussions