-
Notifications
You must be signed in to change notification settings - Fork 2
/
printer_test.ino
59 lines (49 loc) · 1.39 KB
/
printer_test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//Printer Pins
const int dataPins[] = {41,42,43,44,45,46,47,48};
const int strobePin = 39;//active low
//const int lineFeedPin = 40;//active low
//const int errorPin = 41;
//const int resetPin = 42;
//const int ackPin = 43;
const int busyPin = 40;//active low
//const int paperOutPin = 45;
//const int selPin = 46;//high if printer is on
//End Printer Pins
char buffer = 0x00;
void setup() {
//Printer I/O Setup
for (int i = 0; i < sizeof(dataPins) / sizeof(dataPins[0]); ++i)
pinMode(dataPins[i], OUTPUT);
pinMode(strobePin, OUTPUT);
pinMode(busyPin, INPUT);
//pinMode(ackPin, INPUT);
digitalWrite(strobePin, HIGH);
//End Printer I/O Setup
//Setup init, lf, sel
//init is ??
//lf is high
//sel is low
//Use Serial input to stream to the printer for testing
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
printer(Serial.read());
}
}
void printer(char buffer)
{
//Write out our buffer
for (int j = 0; j < sizeof(dataPins) / sizeof(dataPins[0]); ++j)
digitalWrite(dataPins[j], (buffer & (1 << j)));
//buffer = 0x00;
//Block and wait for the printer to be ready
while (digitalRead(busyPin));
//Tell the printer to write out the data
digitalWrite(strobePin, LOW);
delay(10);
digitalWrite(strobePin, HIGH);
//Reset the data lines
for (int j = 0; j < sizeof(dataPins) / sizeof(dataPins[0]); ++j)
digitalWrite(dataPins[j], LOW);
}