0

I am using this program. However, I am getting garbage values only. Do revert as to how can I get proper values over my arduino.

/*****************************************************************************/
* PrinterCapturePoll.ino
* ------------------
* Monitor a parallel port printer output and capture each character. Output the
* character on the USB serial port so it can be captured in a terminal program.
*
* By............: Paul Jewell
* Date..........: 29th January 2015
* Version.......: 0.1a
*-------------------------------------------------------------------------- -     ----
* Wiring Layout
* ------------ -
*
* Parallel Port Output               Arduino Input
* --------------------               ------------ -
* Name      Dir.   Pin                Name    Pin
* ----             -- -                ----    -- -
* nSTROBE    >       1..........................2
* DATA BYTE  >     2 - 9.......................3 - 10
* nACK       <      10.........................11
* BUSY       <      11.........................12
* OutofPaper <      12................GND
* Selected   <      13.................5v
* GND        <>  18 - 25................GND
*------------------------------------------------------------------------------ -
******************************************************************************** /

int nStrobe = 2;
int Data0   = 3;
int Data1   = 4;
int Data2   = 5;
int Data3   = 6;
int Data4   = 7;
int Data5   = 8;
int Data6   = 9;
int Data7   = 10;
int nAck    = 11;
int Busy    = 12;
int led     = 13; // use as status led

void setup() {
  // Configure pins
  pinMode(nStrobe, INPUT_PULLUP);
  for (int n = Data0; n < (Data7 + 1); n++)
    pinMode(n, INPUT_PULLUP);
  pinMode(nAck, OUTPUT);
  pinMode(Busy, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  while (!Serial) {
    Serial.println("Waiting to Initialise");
  }
  //State = READY;
  delay(1000);
  Serial.println("Initialised");
  delay(1000);
}

void loop() {
  while (digitalRead(nStrobe) == HIGH) {
    digitalWrite(Busy, LOW);
    digitalWrite(nAck, HIGH);
    digitalWrite(led, HIGH);
    ProcessChar();
  }
  digitalWrite(Busy, HIGH);
  digitalWrite(led, LOW);
  digitalWrite(nAck, LOW);
  delay(5); //milliseconds. Specification minimum = 5 us
}

void ProcessChar() {
  byte Char;
  Char = digitalRead(Data0) +
         (digitalRead(Data1) << 1) +
         (digitalRead(Data2) << 2) +
         (digitalRead(Data3) << 3) +
         (digitalRead(Data4) << 4) +
         (digitalRead(Data5) << 5) +
         (digitalRead(Data6) << 6) +
         (digitalRead(Data7) << 7);
  Serial.print(char(Char));
}
8
  • The ProcessChar(); command should be before the DigitalWrite(nAck,LOW);
    – dhimaspw
    Dec 6 '16 at 6:50
  • Thanks for this one. It is storing data. But, it is storing garbage bytes only.
    – Abhay Bh
    Dec 6 '16 at 8:27
  • When I try to print the output bits in char, they show - " " . When in int, they show: "1". And, the raw data when printed, shows like: 'ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ}}xa44=wwwwwÿÿÿÿÿÿÿÿÿÿÿ' . I have set the Baud Rate: 9600, Parity: None, Data Bits: 8, Stop Bits: 1 and Hardware Control: None
    – Abhay Bh
    Dec 6 '16 at 8:31
  • Do the hard-coded messages (Waiting to Initialise and Initialised) appearing correctly?
    – Mark Smith
    Dec 6 '16 at 9:30
  • Yes. They appear properly. And after that when I switch on my DPU, it starts giving me : ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ... And, when I print something from it to the Printer, over the DB25 port, it shows varied symbols like }}xa44=wwwww or i#%&quot;%0#&quot;`iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiggggggggggf*iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiâ+¾ioig8$iig &#39; etc
    – Abhay Bh
    Dec 6 '16 at 11:39
1

I think I can see the problem - although I have no way to test it.

According to Wikipedia:

When the data was ready, the host pulled the STROBE pin low, to 0 V. The printer responded by pulling the BUSY line high, printing the character, and then returning BUSY to low again.

That's not what you're doing - you are repeatedly reading while the strobe is HIGH.

Here's my attempt at your loop() which I hope will at least get you started:

void loop()
{
    // Wait for strobe to go LOW, indicating a character is ready
    while (digitalRead(nStrobe) == LOW) {
        delay(1)
    };

    // Strobe is now LOW - a character is ready.
    // Pull BUSY to high
    // (NB: I don't know what you're doing with nAct and led)
    digitalWrite(Busy, HIGH);
    digitalWrite(led, LOW);
    digitalWrite(nAck,LOW);

    // Print the character
    ProcessChar();

    // Return BUSY to low again
    // (NB: I don't know what you're doing with nAct and led)
    digitalWrite(Busy, LOW);
    digitalWrite(led, HIGH);
    digitalWrite(nAck,HIGH);

    // Wait for the strobe to go HIGH again
    while (digitalRead(nStrobe) == LOW) {
        delay(1)
    };
}    

You should also probably consider setting the initial values of your outputs (BUSY and nAck) rather than relying on them defaulting to some particular state. I don't know what (n)Ack is for in this case -- Wikipedia doesn't mention it.

0

Do you know the printer is working properly?

You are trying to fix more than one thing at once and that's never a good idea. What I suggest you do is get a breadboard and make your own printer simulator. You need to connect and LED up to every output pin and a button to every input pin.

Then you can simulate data from the printer, i.e. just pressing the button for pin 3 and you should see 1 coming out on the serial monitor. OK I agree this "simulator" is rubbish, but you probably have the bits to knock it up now.

If you are still seeing 'junk' values then have a look and see if there is a pattern to the data. This would be helped by printing the values in hex.

Of course if the Arduino side works then the issue is that the printer is sending data that you are not expecting. It might help stick LEDs on every pin, both directions, it will help you see what is being sent.

Its possible that you are expecting 1 to indicate the bit is set and the printer is using 0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.