Sore hari yang penuh warna, sejuk udaranya melebur sanubari, kali ini saya akan menjelaskan mengenai bagaimana cara mengakses Printer Thermal Arduino dan juga bagaimana cara membuat alat untuk monitoring suhu. Pada alat ini terdapat beberapa device yaitu RTC yang digunakan untuk menampilkan jam dan tanggal, kemudian Arduino untuk memproses data, Sensor suhu LM35 sebagai sensor suhu, dan yang terakhir adalah printer thermal yang berfungsi sebagai alat pencetak hasil yang didapat oleh Arduino (mikrokontroller), jadi data tanggal, jam dan suhu akan tercetak pada kertas thermal melalui printer thermal, sebenarnya terdapat sebuah tombol yang mana fungsinya untuk mem-print hasil, jika tombol tersebut tidak ditekan maka printer tidak akan aktif. Berikut adalah penjelasan gambar dan programnya.
a. Arduino Mega
b. RTC Module
c. Sensor LM35
d. Printer Thermal
*NOTE = Supply VCC untuk Printer Thermal Pakai 5V 2A
TX masuk ke pin 2 dan RX ke pin 3
e. Skema Push Button
#include "Wire.h"
#define DS3231_I2C_ADDRESS 0x68
#include <SoftwareSerial.h>
SoftwareSerial Thermal(2, 3);
int zero=0;
int heatTime = 80;
int heatInterval = 255;
char printDensity = 15;
char printBreakTime = 15;
char barCode[]={ '5','5','0','9','2','1','2','4','2','3','4','0'};
const int buttonPin = 7;
int buttonState = 1;
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}
void setup() {
pinMode(buttonPin, INPUT);
Wire.begin();
Serial.begin(9600);
Thermal.begin(19200); // to write to our new printer
initPrinter();
// DS3231 seconds, minutes, hours, day, date, month, year
// setDS3231time(0,10,11,2,3,8,15);
}
void initPrinter()
{
//Modify the print speed and heat
Thermal.write(27);
Thermal.write(55);
Thermal.write(7); //Default 64 dots = 8*('7'+1)
Thermal.write(heatTime); //Default 80 or 800us
Thermal.write(heatInterval); //Default 2 or 20us
//Modify the print density and timeout
Thermal.write(18);
Thermal.write(35);
int printSetting = (printDensity<<4) | printBreakTime;
Thermal.write(printSetting); //Combination of printDensity and printBreakTime
}
void printBarcode(char zz[])
{
Thermal.write(29); //GS
Thermal.write(107); //k
Thermal.write(zero); //m = 0
for (int z=0; z<12; z++)
{
Thermal.write(zz[z]);
}
Thermal.write(zero); // bar code terminator
delay(3000); // necessary delay
Thermal.write(10);
Thermal.write(10);
Thermal.write(10);
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte dayOfMonth, byte month, byte year)
{
// sets time and date data to DS3231
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set next input to start at the seconds register
Wire.write(decToBcd(second)); // set seconds
Wire.write(decToBcd(minute)); // set minutes
Wire.write(decToBcd(hour)); // set hours
Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
Wire.write(decToBcd(month)); // set month
Wire.write(decToBcd(year)); // set year (0 to 99)
Wire.endTransmission();
}
void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0); // set DS3231 register pointer to 00h
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
// request seven bytes of data from DS3231 starting from register 00h
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
// send it to the serial monitor
Serial.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
Serial.print(":");
if (minute<10)
{
Serial.print("0");
}
Serial.print(minute, DEC);
Serial.print(":");
if (second<10)
{
Serial.print("0");
}
Serial.print(second, DEC);
Serial.print(" ");
Serial.print(dayOfMonth, DEC);
Serial.print("/");
Serial.print(month, DEC);
Serial.print("/");
Serial.print(year, DEC);
Serial.print(" Hari : ");
switch(dayOfWeek){
case 1:
Serial.println("MINGGU");
break;
case 2:
Serial.println("SENIN");
break;
case 3:
Serial.println("SELASA");
break;
case 4:
Serial.println("RABU");
break;
case 5:
Serial.println("KAMIS");
break;
case 6:
Serial.println("JUM'AT");
break;
case 7:
Serial.println("SABTU");
break;
}
}
void printTime()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
// retrieve data from DS3231
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
// send it to the serial monitor
Thermal.print(hour, DEC);
// convert the byte variable to a decimal number when displayed
Thermal.print(":");
if (minute<10)
{
Thermal.print("0");
}
Thermal.print(minute, DEC);
Thermal.print(":");
if (second<10)
{
Thermal.print("0");
}
Thermal.print(second, DEC);
Thermal.print(" ");
Thermal.print(dayOfMonth, DEC);
Thermal.print("/");
Thermal.print(month, DEC);
Thermal.print("/");
Thermal.print(year, DEC);
Thermal.print(" Hari : ");
switch(dayOfWeek){
case 1:
Thermal.println("MINGGU");
break;
case 2:
Thermal.println("SENIN");
break;
case 3:
Thermal.println("SELASA");
break;
case 4:
Thermal.println("RABU");
break;
case 5:
Thermal.println("KAMIS");
break;
case 6:
Thermal.println("JUM'AT");
break;
case 7:
Thermal.println("SABTU");
break;
}
}
void loop() {
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0) * 100;
buttonState = digitalRead(buttonPin);
delay(1000);
if (buttonState == HIGH ) {
displayTime();
Serial.print("Suhu = ");
Serial.print(voltage);
Serial.println(" c");
Serial.println("no print");
delay(1000);
}
if (buttonState == LOW ) {
Serial.println("print ready");
Serial.println("printing....");
delay(1000);
//UNDERLINE MODE
Thermal.write(27);
Thermal.write(45);
Thermal.write(1);
Thermal.println("kursuselektronikaku.blogspot.com");
Thermal.write(10);
//TURN OFF UNDERLINE MODE
Thermal.write(27);
Thermal.write(45);
Thermal.write(zero);
delay(3000);
//NORMAL MODE
Thermal.println("BY YANUAR MUKHAMMAD");
Thermal.write(10);
//print waktu
printTime();
Thermal.write(10);
//print suhu
Thermal.print("Suhu = ");
Thermal.print(voltage);
Thermal.println(" c");
Thermal.write(10);
Thermal.write(10);
//barcode
Thermal.println(" MY BBM PIN ");
printBarcode(barCode);
Thermal.write(10);
Thermal.write(10);
}
}
g. Hasil Print Out
h. VIDEO HASILNYA
Thanks Mas Sketch Nya.. (Y)
ReplyDelete