Moderators: adafruit_support_bill, adafruit
#include <SoftwareSerial.h>
#include <Adafruit_Thermal.h>
int printer_RX_Pin = 8; // this is the green wire
int printer_TX_Pin = 9; // this is the yellow wire
Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);
void setup() {
Serial.begin(1200);
printer.begin();
}
String line = "";
void loop() {
if (Serial.available()) {
char inByte = Serial.read();
switch (inByte) {
case '\n':
Serial.println(line); //print complete line
printer.println(line);
line = ""; //reset to empty string
break;
default:
line += inByte; //append inByte to the line String
}
}
}How is it that it compiles for you without including Wire.h?
what version of Arduino are you using?
What versions of the libraries are you using? Are they all Adafruit libraries?
This is expected. Adafruit_Thermal does this normally.when I have the printer.print command active it use another way to write lines on the scree:
0XE()
0XFE()
0X20()
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = RTC.now();
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}SdFile::dateTimeCallback(dateTime);
DateTime now = RTC.now();
cout << now << endl;#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include <SoftwareSerial.h>
#include <Adafruit_Thermal.h>
#include <LiquidCrystal.h>
#define SYNC_INTERVAL 10000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
// the digital pins that connect to the LEDs
//#define redLEDpin 2
//#define greenLEDpin 3
RTC_DS1307 RTC; // define the Real Time Clock object
const int chipSelect = 10;
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
while(1);
}
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int printer_RX_Pin = 8; // this is the green wire
int printer_TX_Pin = 9; // this is the yellow wire
Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);
void setup(void)
{
Serial.begin(1200);
Serial.println();
lcd.begin(20,4);
printer.begin();
//use debugging LEDs
//pinMode(redLEDpin, OUTPUT);
//pinMode(greenLEDpin, OUTPUT);
// initialize the SD card
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
error("Card failed, or not present");
//digitalWrite(redLEDpin, HIGH);
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
//digitalWrite(redLEDpin, HIGH);
}
Serial.print("Logging to: ");
Serial.println(filename);
// connect to RTC
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
//digitalWrite(redLEDpin, HIGH);
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("millis,stamp,datetime,data");
} //end SETUP
String line = "";
void loop(void)
{
if (Serial.available()) {
char inByte = Serial.read();
switch (inByte) {
case '\n':
//digitalWrite(greenLEDpin, HIGH);
lcd.setCursor(0,0);
lcd.print(line);
printer.println(line);
// if the file is available, write to it:
if (logfile){
DateTime now;
// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
// fetch the time
now = RTC.now();
// log time
logfile.print(now.unixtime()); // seconds since 1/1/1970
logfile.print(", ");
logfile.print('"');
logfile.print(now.year(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
logfile.print('"');
#if ECHO_TO_SERIAL
Serial.print(now.unixtime()); // seconds since 1/1/1970
Serial.print(", ");
Serial.print('"');
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.print('"');
#endif //ECHO_TO_SERIAL
logfile.print(", ");
logfile.println(line);
}
Serial.println(line); //print complete line
line = ""; //reset to empty string
//digitalWrite(greeLEDpin, LOW);
break;
default:
line += inByte; //append inByte to the line String
}
}
if ((millis() - syncTime) < SYNC_INTERVAL) return;
syncTime = millis();
//digitalWrite(redLEDpin, HIGH);
logfile.flush();
//digitalWrite(redLEDpin, LOW);
}
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include <SoftwareSerial.h>
#include <Adafruit_Thermal.h>
#include <LiquidCrystal.h>
#define SYNC_INTERVAL 10000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()
#define ECHO_TO_SERIAL 1 // echo data to serial port
#define WAIT_TO_START 0 // Wait for serial input in setup()
// the digital pins that connect to the LEDs
//#define redLEDpin 2
//#define greenLEDpin 3
RTC_DS1307 RTC; // define the Real Time Clock object
const int chipSelect = 10;
File logfile;
void error(char *str)
{
Serial.print("error: ");
Serial.println(str);
while(1);
}
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int printer_RX_Pin = 8; // this is the green wire
int printer_TX_Pin = 9; // this is the yellow wire
Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);
// call back for file timestamps
void dateTime(uint16_t* date, uint16_t* time) {
DateTime now = RTC.now();
// return date using FAT_DATE macro to format fields
*date = FAT_DATE(now.year(), now.month(), now.day());
// return time using FAT_TIME macro to format fields
*time = FAT_TIME(now.hour(), now.minute(), now.second());
}
void setup(void)
{
Serial.begin(1200);
Serial.println();
lcd.begin(20,4);
printer.begin();
//use debugging LEDs
//pinMode(redLEDpin, OUTPUT);
//pinMode(greenLEDpin, OUTPUT);
// initialize the SD card
Serial.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(chipSelect)) {
error("Card failed, or not present");
//digitalWrite(redLEDpin, HIGH);
}
Serial.println("card initialized.");
// create a new file
char filename[] = "LOGGER00.CSV";
for (uint8_t i = 0; i < 100; i++) {
filename[6] = i/10 + '0';
filename[7] = i%10 + '0';
if (! SD.exists(filename)) {
// only open a new file if it doesn't exist
logfile = SD.open(filename, FILE_WRITE);
SdFile::dateTimeCallback(dateTime);
DateTime now = RTC.now();
cout << now << endl;
break; // leave the loop!
}
}
if (! logfile) {
error("couldnt create file");
//digitalWrite(redLEDpin, HIGH);
}
Serial.print("Logging to: ");
Serial.println(filename);
// connect to RTC
Wire.begin();
if (!RTC.begin()) {
logfile.println("RTC failed");
//digitalWrite(redLEDpin, HIGH);
#if ECHO_TO_SERIAL
Serial.println("RTC failed");
#endif //ECHO_TO_SERIAL
}
logfile.println("millis,stamp,datetime,data");
} //end SETUP
String line = "";
void loop(void)
{
if (Serial.available()) {
char inByte = Serial.read();
switch (inByte) {
case '\n':
//digitalWrite(greenLEDpin, HIGH);
lcd.setCursor(0,0);
lcd.print(line);
printer.println(line);
// if the file is available, write to it:
if (logfile){
DateTime now;
// log milliseconds since starting
uint32_t m = millis();
logfile.print(m); // milliseconds since start
logfile.print(", ");
// fetch the time
now = RTC.now();
// log time
logfile.print(now.unixtime()); // seconds since 1/1/1970
logfile.print(", ");
logfile.print('"');
logfile.print(now.year(), DEC);
logfile.print("/");
logfile.print(now.month(), DEC);
logfile.print("/");
logfile.print(now.day(), DEC);
logfile.print(" ");
logfile.print(now.hour(), DEC);
logfile.print(":");
logfile.print(now.minute(), DEC);
logfile.print(":");
logfile.print(now.second(), DEC);
logfile.print('"');
#if ECHO_TO_SERIAL
Serial.print(now.unixtime()); // seconds since 1/1/1970
Serial.print(", ");
Serial.print('"');
Serial.print(now.year(), DEC);
Serial.print("/");
Serial.print(now.month(), DEC);
Serial.print("/");
Serial.print(now.day(), DEC);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(":");
Serial.print(now.minute(), DEC);
Serial.print(":");
Serial.print(now.second(), DEC);
Serial.print('"');
#endif //ECHO_TO_SERIAL
logfile.print(", ");
logfile.println(line);
}
Serial.println(line); //print complete line
line = ""; //reset to empty string
//digitalWrite(greeLEDpin, LOW);
break;
default:
line += inByte; //append inByte to the line String
}
}
if ((millis() - syncTime) < SYNC_INTERVAL) return;
syncTime = millis();
//digitalWrite(redLEDpin, HIGH);
logfile.flush();
//digitalWrite(redLEDpin, LOW);
}
// Serial print stream
ArduinoOutStream cout(Serial);
Return to Other Arduino products from Adafruit
Users browsing this forum: No registered users and 3 guests