Created
August 25, 2011 23:54
-
-
Save cfaulkingham/1172343 to your computer and use it in GitHub Desktop.
Temp Humidity Printer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TempHumidityPrinter | |
(c) Colin Faulkingham 2011 - MIT license | |
Sparkfun Thermal Printer http://www.sparkfun.com/products/10438 | |
Adafruit DHT11 Temp and Humidy Sensor https://www.adafruit.com/products/386 | |
Sparkfun 16x2 LCD display http://www.sparkfun.com/products/9761 | |
Arduino UNO SMD http://www.sparkfun.com/products/10356 | |
*/ | |
#include <LiquidCrystal.h> | |
#include <NewSoftSerial.h> | |
#include "DHT.h" | |
// PIN FOR TEMP sensor. | |
#define DHTPIN 6 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
// Setup for the Thermal Printer | |
#define FALSE 0 | |
#define TRUE 1 | |
NewSoftSerial Thermal(8,9); | |
// initialize the library with the numbers of the interface pins | |
int printOnBlack = FALSE; | |
int printUpSideDown = FALSE; | |
int ledPin = 13; | |
int heatTime = 255; //80 is default from page 23 of datasheet. Controls speed of printing and darkness | |
int heatInterval = 255; //2 is default from page 23 of datasheet. Controls speed of printing and darkness | |
char printDensity = 15; //Not sure what the defaut is. Testing shows the max helps darken text. From page 23. | |
char printBreakTime = 15; //Not sure what the defaut is. Testing shows the max helps darken text. From page 23. | |
// Setup for the 16x2 LCD | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
void setup() { | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
// Print a message to the LCD. | |
//lcd.print("Temp and Humidity"); | |
Serial.begin(9600); | |
Serial.println("DHTxx test!"); | |
Thermal.begin(19200); //Setup soft serial for ThermalPrinter control | |
printOnBlack = FALSE; | |
printUpSideDown = FALSE; | |
//Modify the print speed and heat | |
Thermal.print(27, BYTE); | |
Thermal.print(55, BYTE); | |
Thermal.print(7, BYTE); //Default 64 dots = 8*('7'+1) | |
Thermal.print(heatTime, BYTE); //Default 80 or 800us | |
Thermal.print(heatInterval, BYTE); //Default 2 or 20us | |
//Modify the print density and timeout | |
Thermal.print(18, BYTE); | |
Thermal.print(35, BYTE); | |
int printSetting = (printDensity<<4) | printBreakTime; | |
Thermal.print(printSetting, BYTE); //Combination of printDensity and printBreakTime | |
dht.begin(); | |
} | |
void loop() { | |
// set the cursor to column 0, line 1 | |
// (note: line 1 is the second row, since counting begins with 0): | |
lcd.setCursor(0,0); | |
// print the number of seconds since reset: | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
//char st = strcat("H: ",h," Temp: ",t); | |
lcd.print("Humidity: "); | |
lcd.print(h); | |
lcd.setCursor(0,1); | |
lcd.print("Temp: "); | |
float temp = 1.8 * t + 32; | |
lcd.print(temp); | |
Serial.print("Humidity: "); | |
Serial.print(h); | |
Serial.print(" %\t"); | |
Serial.print("Temperature: "); | |
Serial.print(temp); | |
Serial.print("BLAH: "); | |
Serial.print(t); | |
Serial.println(" *C"); | |
char option; | |
while(1) { | |
while(!Serial.available()); | |
option = Serial.read(); | |
if(isalnum(option)) break; | |
} | |
if(option == '1') { | |
Thermal.print("Humidity: "); | |
Thermal.print(h); | |
Thermal.print(" %\t"); | |
Thermal.print(10, BYTE); | |
Thermal.print("Temperature: "); | |
Thermal.print(temp); | |
Thermal.print(10, BYTE); | |
Thermal.print(10, BYTE); | |
Thermal.print(10, BYTE); | |
//Thermal.print("BLAH: "); | |
//Thermal.print(t); | |
//Thermal.println(" *C"); | |
//Thermal.print(10, BYTE); | |
} | |
else { | |
Serial.print("Choice = "); | |
Serial.println(option, DEC); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment