A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By btidey
#85222 Logically you can use an esp8266 and with that simple code. You just have to be careful about mapping the GPIO pins. If you are trying to make this a wifi accessible service then that seems to be the right thing to do.

However, the Centronics port is defined as a 5V interface so there could be some interface level issues. The GPIO output of the esp8266 will be fine for the logic 0 levels but the 3.3V output could be marginal for the logic 1 levels. Theoretically it claims to use TTL levels where 2.0V is sufficient, however, the picture seems to show that HC logic is used which might need a bit more. There is a very good chance it would work and if this is just a one-off then it may be worth trying. Otherwise you will need a level shifter. There is one input signal fed back from the interface (/busy). This will be at 5V so should not be directly connected to a GPIO on the esp8266. You could simply put it through a 2 resistor divider. E,g, /busy to 2.2k resistor, 3.3k to GND and the junction to be fed into the esp8266 GPIO to monitor /busy.

On the bitmap you seem to be using the function on 4-49. You are sending the command and sizes but the bit map data does not seem to be right. First it starts with a space rather than a number, second it does not seem to have the right amount of data for the size you have defined. Third you need to send the data as binary values.

If you look at the diagram on 4-56 you can see that x=64, 8=96 corresponds to a 512 x 768 bit map image and needs 96 bytes to define each column and 512 columns. It therefore needs 49152 bytes of data. (Diagram seems to have a spurious 9 in the final column labels)
User avatar
By christophe195
#85246 Sorry but i have try more than 3 hours off printing the google logo but never did the printer something. Can you please give example code? i'ts the last step to make verything working.

Thanks for all your time.
User avatar
By btidey
#85249 I would do things in small steps.

Looking at the docs your original code looks to have the right structure and printer commands but I would replace the uploadBitmap with something like

#define Y_MAX 96
#define X_MAX 64
Code: Select allvoid uploadBitmap() {
  int x;
  int y;
  writeByte(28);
  writeByte(113);
  writeByte(1);
  writeByte(X_MAX);
  writeByte(Y_MAX);
  for(y = 0; y < 96; y++) {
    for(x = 0; x < 64; x++) {
      writeByte(7);
   }
    delay(1);
  }
}


This should send the correct number of data bytes with a pattern that is just thin lines (5 bits off 3 bits on in the y direction). I split the x and y out so that the delay is only in the outer loop as you have to send quite a lot of data (e.g. 49152 x 1msec) if you have 1msec delay per byte which would be very slow.

Once you have that producing some print then you can concentrate on sending real data corresponding to the image you want. If you just want one fixed logo then you could represent the logo in a header file as a byte array but you will probably need some way of generating that from whatever your representation of the logo file is. Something like https://littlevgl.com/image-to-c-array might help here. A more general solution would be store it as an image file in SPIFFS and then use an image library to read and decode it on the fly to send in the upload routine.
User avatar
By christophe195
#85314 Ok, comming back on topic.

I have try your skets but it does not print, i will make the image print optional.

I'm now trying to convert the arduino pinout to nodemcu but it reset. I have use the yield() function in all loops.
Dit i use the wrong pins?

Error:
Code: Select all ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v8b899c12
~ld



Current Code:
Code: Select all/*=== settings ===*/
const int chartsPerLine = 80; // max tekens per lijn;

const int nStrobe = 2;    //D4
const int data_0 = 16;    //D0
const int data_1 = 10;   //SD3
const int data_2 = 5;     //D1
const int data_3 = 0;     //D3
const int data_4 = 14;    //D5
const int data_5 = 13;    //D7
const int data_6 = 12;    //D6
const int data_7 = 3;     //RX
const int busy = 9;       //SD2

const int strobeWait = 2;   // microseconds to strobe for

const int debugBaut = 115200;


void setup() {
  Serial.begin(debugBaut);

  pinMode(nStrobe, OUTPUT);      // is active LOW
  digitalWrite(nStrobe, HIGH);   // set HIGH
  pinMode(data_0, OUTPUT);
  pinMode(data_1, OUTPUT);
  pinMode(data_2, OUTPUT);
  pinMode(data_3, OUTPUT);
  pinMode(data_4, OUTPUT);
  pinMode(data_5, OUTPUT);
  pinMode(data_6, OUTPUT);
  pinMode(data_7, OUTPUT);
  pinMode(busy, INPUT);
  pinMode(13, OUTPUT);
  resetPrinter();
 
  Serial.println("Startup complete");
}

void loop() {
  /*setAlignment(1,0,0);
  writeLine("Links", 3);
  setAlignment(0,1,0);
  writeLine("Center", 3);
  setAlignment(0,0,1);
  writeLine("Rechts", 3);

  writeLine("fontsize 1", 1);
  writeLine("fontsize 2", 2);
  writeLine("fontsize 3", 3);
  writeLine("fontsize 4", 4);
  writeLine("fontsize 5", 5);
  writeLine("fontsize 6", 6);
  writeLine("fontsize 7", 7);
  writeLine("fontsize 8", 8);*/

  /*uploadBitmap();
  printBitmap();
 
  cutPaper();*/
 
  while(true) {
    yield();
  }
}

void writeLine(String text, int fontSize) {
  setCharacterSize(fontSize);
 
  digitalWrite(13, HIGH);
  for(int cursorPosition = 0; cursorPosition < text.length(); cursorPosition++) {
    Serial.println(text[cursorPosition]);
    byte character = text[cursorPosition];
    writeByte(character);
    yield();
    delay(1);
  }
  printLine();
  writeByte(13); // carriage return
  digitalWrite(13,LOW);
}

void printLine() {
  writeByte(10); // new line
}

void cutPaper() {
  writeLine("", 2);
  writeByte(29);
  writeByte(86);
  writeByte(1);
}

void uploadBitmap() {

}

void printBitmap() {
    writeByte(28);
    writeByte(112);
    writeByte(1);
    writeByte(48);
    Serial.println("printBitmap");
}


void setCharacterSize(int size) {
    int data[] = {0,17,34,51,68,85,102,119};
    writeByte(29);
    writeByte(33);
    writeByte(data[size - 1]);
    Serial.print("setCharacterSize: ");
    Serial.println(data[size - 1]);
}

void drawerKick(bool a, bool b) {
  if(a == true) {
    writeByte(27);
    writeByte(112);
    writeByte(0);
    writeByte(100);
    writeByte(100);
    Serial.println("drawerKick: A");
  }

  if(b == true) {
    writeByte(27);
    writeByte(112);
    writeByte(1);
    writeByte(100);
    writeByte(100);
    Serial.println("drawerKick: B");
  }
}

void setAlignment(int left, int center, int right) {
  writeByte(27);
  writeByte(97);
  if(left == 1) {
    writeByte(0);
    Serial.println("setAlignment: Left");
  } else if(center == 1) {
    writeByte(1);
    Serial.println("setAlignment: Center");
  } else {
    writeByte(2);
    Serial.println("setAlignment: Right");
  }
}

void emptyLine() {
  Serial.println("Empty line");
  writeByte(10); // reset printer
}

void writeByte(byte inByte) {
  while(digitalRead(busy) == HIGH) {
    // wait for busy to go low
    yield();
  }

  int b0 = bitRead(inByte, 0);
  int b1 = bitRead(inByte, 1);
  int b2 = bitRead(inByte, 2);
  int b3 = bitRead(inByte, 3);
  int b4 = bitRead(inByte, 4);
  int b5 = bitRead(inByte, 5);
  int b6 = bitRead(inByte, 6);
  int b7 = bitRead(inByte, 7);

  digitalWrite(data_0, b0);        // set data bit pins
  digitalWrite(data_1, b1);
  digitalWrite(data_2, b2);
  digitalWrite(data_3, b3);
  digitalWrite(data_4, b4);
  digitalWrite(data_5, b5);
  digitalWrite(data_6, b6);
  digitalWrite(data_7, b7);

  digitalWrite(nStrobe, LOW);       // strobe nStrobe to input data bits
  delayMicroseconds(strobeWait);
  digitalWrite(nStrobe, HIGH);

  while(digitalRead(busy) == HIGH) {
    // wait for busy line to go low
    yield();
  }
}

void resetPrinter() {
   yield();
  Serial.println("Reseting printer...");
  writeByte(27); // reset printer
  writeByte(64); // reset printer
}