Arduino unable to read $5 (0x41) and $10 (0x42) but reads others $1, $20 just fine (ICT bill acceptor)

Here is my issue:

My code successfully recognizes and accepts $1 (0x40) and $20 bills (0x43), but it fails to recognize, display, process, anything for the $5 bill (0x41), and $10 bills (0x42). Also, when I say "Arduino", I mean TTGO btw...

I have verified that the bill acceptor is indeed sending the correct value (0x41) for the $5, and $10 (0x42) bills using an external monitoring tool like Docklight, and I used an oscilloscope too! All signals from all bill types were near identical and valid. However, the Arduino code does not seem to receive those two values (and ONLY those two values) at all... Meanwhile, it will display every other little thing there is... I have my code setup where it displays all incoming bytes, be it B.A. (bill acceptor) idle signals, rejection signals, everything, but it goes 100% blank, MIA, for 0x41 and 0x42... WHY?!?! So frick'n random...

===================================================

Just so you all know, this is how the bill acceptor (B.A.) works:

  1. Insert a bill into BA
  2. BA sends the corresponding HEX value (ex. 0x40) of the bill to my Arduino (Using RS232 cables and an RS232 to TTL converter (the converters are confirmed to be 100% operational BTW))
  3. Once the Arduino "sees" the HEX value for a bill of N value, it will then send 0x02 to the BA to accept the bill.
  4. If 0x02 is NOT sent to the BA within 5 seconds, then it will reject the bill and spit it back out the front.
  5. Code then adds that value to "total count"

OFC, my code is setup where the only way an accept (0x02) signal is sent is IF 0x4N is received... So, the fact that 0x41 and 0x42 disappear into thin air means 0x02 is never sent so those two values are always rejected... Very, very, simple stuff, so the fact that it consistently is unable to ONLY NOT read 0x41 and 0x42 while clearly displaying all other sent HEX values is causing me unlimited headaches and conniptions... Programming... YAY! -_-

So, anyone... please, do you know what's going on? The signal is 100% being generated, and my code, below, is setup to display all incoming bytes, but it acts like 0x41 and 0x42 do not exist at all! Nothing. Nada. Zilch. WTF? It literally handles everything I can throw at it... except 0x41 and 0x42!!! FUUUUUUUUUUUU!!! So mad...

HERE IS THE ICT RS232 PROTOCL FOR MY BILL ACCEPTOR - http://tdmegalit.ru/upload/iblock/401/ict_protocol.pdf

ALSO, I HAVE ALL DIP SWITCHES CORRECTLY SET, POWER SUPPLY IS PERFECT, ALL WIRES ARE TESTED AND PERFECT, RS232 TO TTL CONVERTERS ARE PERFECT. I GUESS IT IS SOFTWARE SERIAL, OR THE TTGO

So with all that said, below is my code. It is a part of a much great whole of a program, so to remove the possibilities of the rest of the code causing the error, I reduced it to what you see below, but the problem persist... bruh

Also, I have included the Serial Monitor LOG. The LOG below shows startup, and then a 1, 5, 10, and 20 dollar bill being inserted...

SERIAL MONITOR LOG:

PLZ NOTE, I ADDED SPACES AND COMMENTS TO SHOW WHATS GOING ON...
====================================================================

... Received: 0x80       //IDLE SIGNALS (BA POWERED ON BEFORE "SETUP" SENT)
... Received: 0x8F
... Received: 0x80
... Received: 0x8F
... Received: 0x80
... Received: 0x8F

SETUP - ...Sent: STX     //SETUP TO INITALIZE BA
SETUP - ...Sent: DLE
SETUP - ...Sent: ETX
=======================
                         //INSERTED $1 (0x40) SUCCESS!!!
... Received: 0x40
$1 accepted
... Sent: 0x02
... Received: 0x10
                         //INSERTED $5 and 5 seconds later 0x29>>0x29>>0x2F = Rejection
... Received: 0x29
Bill rejected
... Received: 0x29
Bill rejected
... Received: 0x2F
                         //INSERTED $10 and 5 seconds later 0x29>>0x29>>0x2F = Rejection
... Received: 0x29
Bill rejected
... Received: 0x29
Bill rejected
... Received: 0x2F
                         //INSERTED $20 (0x43) SUCCESS!!!
... Received: 0x43
$20 accepted
... Sent: 0x02
... Received: 0x10

BILL ACCEPTOR CODE:

#include <SoftwareSerial.h>

SoftwareSerial BA(32, 33);  // RX, TX

int billCounter = 0;

void setup() {
  Serial.begin(9600);
  BA.begin(9600);
  delay(3000); //WAIT BC TRESH

  BA.write(0x02); // Send the initialization command (STX)
  Serial.println("SETUP - ...Sent: STX");
  BA.write(0x10); // Send the command to enable the bill acceptor
  Serial.println("SETUP - ...Sent: DLE");
  BA.write(0x03); // Send the end of text character (ETX)
  Serial.println("SETUP - ...Sent: ETX");
  Serial.println("=======================");
}

void loop() {
  if (BA.available()) {
    byte receivedByte = BA.read();
    Serial.print("... Received: 0x");
    Serial.println(receivedByte, HEX);

    if (receivedByte == 0x29) {
      delay(200);
      Serial.println("Bill rejected");
      // Handle bill rejection here (e.g., display message or perform necessary actions)

    } else if (receivedByte == 0x40) {
      delay(200);
      Serial.println("$1 accepted");
      BA.write(0x02); // Send the HEX value 0x02 to accept the bill
      Serial.println("... Sent: 0x02");

      // Increment the counter by $1
      billCounter += 1;

    } else if (receivedByte == 0x41) {
      delay(200);
      Serial.println("$5 accepted");
      BA.write(0x02); // Send the HEX value 0x02 to accept the bill
      Serial.println("... Sent: 0x02");

      // Increment the counter by $5
      billCounter += 5;

    } else if (receivedByte == 0x42) {
      delay(200);
      Serial.println("$10 accepted");
      BA.write(0x02); // Send the HEX value 0x02 to accept the bill
      Serial.println("... Sent: 0x02");

      // Increment the counter by $10
      billCounter += 10;

    } else if (receivedByte == 0x43) {
      delay(200);
      Serial.println("$20 accepted");
      BA.write(0x02); // Send the HEX value 0x02 to accept the bill
      Serial.println("... Sent: 0x02");

      // Increment the counter by $20
      billCounter += 20;

    } else if (receivedByte == 0x44) {
      delay(200);
      Serial.println("$50 accepted");
      BA.write(0x02); // Send the HEX value 0x02 to accept the bill
      Serial.println("... Sent: 0x02");

      // Increment the counter by $50
      billCounter += 50;

    } else if (receivedByte == 0x45) {
      delay(200);
      Serial.println("$100 accepted");
      BA.write(0x02); // Send the HEX value 0x02 to accept the bill
      Serial.println("... Sent: 0x02");

      // Increment the counter by $100
      billCounter += 100;
    }
  }
}

Downloaded the code and formatted it, and don't see any obvious error.

Does this code

void loop() {
  if (BA.available()) {
    byte receivedByte = BA.read();
    Serial.print("... Received: 0x");
    Serial.println(receivedByte, HEX);

verify the proper coin value?

1 Like

How old is the firmware on the bill acceptor? 5's and 10's were the last two to change.

1 Like

I see in the protocol spec that the device uses EVEN parity and SoftwareSerial has NO parity. That might be the problem.

Does the TTGO have a second serial port you can use, like Serial1 or Serial2? If not, you may have to find a version of SoftwareSerial that does support parity settings.

Yess!!! Thank you @johnwasser! You were right and this is the solution! SOLVED

To make it work, I did some research on how to make the parity bit even, and even parity is unsupported by SoftwareSerial, so I used HardwareSerial as shown below :smiley: . The default for hardware serial is SERIAL_8N1, but I needed to use SERIAL_8E1

SERIAL_8N1 means "8" bits, "N"o parity, and "1" stop bit (hence 8N1)
SERIAL_8E1 means "8" bits, "E"ven parity, and "1" stop bit (hence 8E1)

Good stuff! I am glad I got this figured out. I hope this solution can help somebody!

#include <HardwareSerial.h>

HardwareSerial BA(1);  // Use Hardware Serial on TTGO

void setup() {
  Serial.begin(9600);
  BA.begin(9600, SERIAL_8E1, 32, 33);  // Initialize Hardware Serial with RX pin 32 and TX pin 33 
  ...  //rest of my code

Can you please share your circuit diagram or wire connections for rs232 to ttl converter?
I cannot stablish the connection. It will be a great help for me.

Why you are hijacking a thread?

Open a new forum post!

1 Like

Don't be hiper brother. Already did it on my own.

I am so proud of you.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.