MyEngineeringStuffs
Published © GPL3+

Mini Serial TTL Thermal Printer Token Machine

Managing a queue becomes much more difficult when the time taken to serve cannot be predetermined due to various reasons.

IntermediateProtip5 hours588
Mini Serial TTL Thermal Printer Token Machine

Things used in this project

Story

Read more

Code

RTC interfacing code

Arduino
This code is for RTC interfacing with Arduino and get the actual time.
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][10] = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"};
int HOUR=0,MINUT=0,SECOND=0;//Variable to store current time 
void setup(){
   Serial.begin(9600);
   Serial.println("       WELCOME TO    ");
   Serial.println("     RTC SERIAL TEST ");
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2018, 4, 27, 23, 40, 0));
  }
}

void loop () {
    //Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
 DateTime now = rtc.now();
 Serial.print(now.day());
 Serial.print("/");
 Serial.print(now.month());
 Serial.print("/");
 Serial.print(now.year()); 
 Serial.print(" ");
 Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); 
 Serial.print(" "); 
 Serial.print(HOUR=now.hour()); 
 Serial.print(":");
 Serial.print(MINUT=now.minute());
 Serial.print(":");
 Serial.print(SECOND=now.second());
 Serial.print(" ");
 if(HOUR < 12){                  // Adding the AM/PM sufffix
    Serial.print("AM");
    }
   else{
    Serial.print("PM");
   }
 delay(1000);
 Serial.println();
}

Thermal Printer interfacing code.

Arduino
This code if for interfacing thermal printer with Arduino
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"


#define TX_PIN 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN 5 // Arduino receive   GREEN WIRE   labeled TX on printer

SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor
void setup() {
  mySerial.begin(9600);  // Initialize SoftwareSerial
  printer.begin();        // Init printer (same regardless of serial type)
  printer.justify('L');
  printer.println("***  MY ENGINEERING STUFFS  ***\n");
  printer.justify('C');
  printer.setSize('L');        // Set type size, accepts 'S', 'M', 'L'
  printer.println("TOKEN NUMBER");
  printer.boldOn();
  printer.setSize('L');
  printer.println("001\n");
  printer.boldOff();
  printer.justify('C');
  printer.setSize('S');
  printer.println("***  HAVE A NICE DAY  ***");
  printer.justify('C');
  printer.print("DATE:24/01/2018\t");
  printer.println("TIME: 00:07");
  printer.println("TODAY: WEDNESDAY");   
  printer.write(10);
  printer.write(10);
  printer.write(10);
}

void loop() {
}

Project Source code

Arduino
This is the full source code of the project
#include "Adafruit_Thermal.h"
#include "SoftwareSerial.h"
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
char daysOfTheWeek[7][10] = {"SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY"};
int HOUR=0,MINUT=0,SECOND=0;//Variable to store current time 

#define TX_PIN 6 // Arduino transmit  YELLOW WIRE  labeled RX on printer
#define RX_PIN 5 // Arduino receive   GREEN WIRE   labeled TX on printer

const int buttonPin = A0;     // the number of the pushbutton pin
int buttonState = 0;
int count =0;

String datevalue = "", timevalue = "", counter = "";

SoftwareSerial mySerial(RX_PIN, TX_PIN); // Declare SoftwareSerial obj first
Adafruit_Thermal printer(&mySerial);     // Pass addr to printer constructor

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);  // Initialize SoftwareSerial
  pinMode(buttonPin, INPUT);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2018, 4, 27, 23, 40, 0));
  }
  printer.begin();        // Init printer (same regardless of serial type)
}

void loop() {
 buttonState = digitalRead(buttonPin1);
 if (buttonState == HIGH) {
    DateTime now = rtc.now();
    datevalue = "DATE:"+String(now.day())+'/'+String(now.month())+'/'+String(now.year())+"\t";
    timevalue = "TIME:"+String(now.hour())+':'+String(now.minute())+':'+String(now.second());
    //Serial.print(datevalue);
    //Serial.println(timevalue);
    count++;
    if(count < 10){
      counter = "00"+String(count);
    }else if(count < 100){
      counter = "0"+String(count);
    }else{
      counter = String(count);
    }
    //Serial.println(counter);
    printer.justify('L');
    printer.println("***  MY ENGINEERING STUFFS  ***\n");
    printer.justify('C');
    printer.setSize('L');        // Set type size, accepts 'S', 'M', 'L'
    printer.println("TOKEN NUMBER\n");
    printer.boldOn();
    printer.setSize('L');
    printer.println(counter+"\n");
    printer.boldOff();
    printer.justify('C');
    printer.setSize('S');
    printer.println("***  HAVE A NICE DAY  ***");
    printer.justify('C');
    printer.print(datevalue);
    printer.println(timevalue);
    printer.println("TODAY: "+String(daysOfTheWeek[now.dayOfTheWeek()]));   
    printer.write(10);
    printer.write(10);
    printer.write(10);
    delay(1000);
    } else;
}

Credits

MyEngineeringStuffs
13 projects โ€ข 72 followers
I ๐Ÿ˜ to help people, students are always FIRST, and Yes๐Ÿ‘‰https://paypal.me/pawanbehera1 you can buy me a COFFEE if U๐Ÿ˜ my WORK, NAMASTE ๐Ÿ™

Comments