4

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 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;
    }
  }
}
4
  • looks like the bill validator is rejecting the 10 and the 5
    – jsotola
    Jun 13, 2023 at 19:25
  • @jsotola It is not though. As you can see, for 1 and 20, it shows 0x40 and 0x43 when the bill is inserted. Meanwhile, absolutely nothing appears for 5 and 10 and it is automatically rejected after 5 seconds... Again, I have confirmed that 5 and 10 dollar bills do indeed send a hex value but my code shows nothing for only 5 and 10 dollar bills fuuuuu Jun 13, 2023 at 21:07
  • 2
    The default for Arduino Serial is 8 data bits, no parity, one stop bit. The first page of your linked documents says: Start bit 1, Data bit 8, Parity bit Even, Stop bit 1. The mismatched parity parameter could explain a partial failure of this. Look at (Software) Serial begin() method to change this.
    – 6v6gt
    Jun 13, 2023 at 21:23
  • @6v6gt, you should make it an answer. Jun 14, 2023 at 4:47

2 Answers 2

3

The default for Arduino Serial is 8 data bits, no parity, one stop bit. The first page of your linked documents says: Start bit 1, Data bit 8, Parity bit Even, Stop bit 1. The mismatched parity parameter could explain a partial failure of this communication. The documentation for the Serial begin() method describes the various configuration options.

However, see also this thread: https://forum.arduino.cc/t/altsoftserial-how-to-change-parity-solved/668535 It appears that the various software serial libraries do not support EVEN parity settings. Use a hardware serial port on your TTGO Arduino instead. This may mean using SoftwareSerial for the debug printing (maybe with a USB/UART adapter) and dedicating the hardware serial port to your bank note reader.

Thank you 6v6gt! Using HardwareSerial was the answer and setting the parity bit to EVEN was the answer too :D Here is what I did to fix it if anyone ever needs to see this answer in the future...

Also note, here is the logic:

The default for hardware serial is SERIAL_8N1, but I needed to use SERIAL_8E1 for the even parity because:

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)

Here is the chart I used to get the protocol format I needed:

/* Baud-rates available: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200, 256000, 512000, 962100
 *  
 *  Protocols available:
 * SERIAL_5N1   5-bit No parity 1 stop bit
 * SERIAL_6N1   6-bit No parity 1 stop bit
 * SERIAL_7N1   7-bit No parity 1 stop bit
 * SERIAL_8N1 (the default) 8-bit No parity 1 stop bit
 * SERIAL_5N2   5-bit No parity 2 stop bits 
 * SERIAL_6N2   6-bit No parity 2 stop bits
 * SERIAL_7N2   7-bit No parity 2 stop bits
 * SERIAL_8N2   8-bit No parity 2 stop bits 
 * SERIAL_5E1   5-bit Even parity 1 stop bit
 * SERIAL_6E1   6-bit Even parity 1 stop bit
 * SERIAL_7E1   7-bit Even parity 1 stop bit 
 * SERIAL_8E1   8-bit Even parity 1 stop bit 
 * SERIAL_5E2   5-bit Even parity 2 stop bit 
 * SERIAL_6E2   6-bit Even parity 2 stop bit 
 * SERIAL_7E2   7-bit Even parity 2 stop bit  
 * SERIAL_8E2   8-bit Even parity 2 stop bit  
 * SERIAL_5O1   5-bit Odd  parity 1 stop bit  
 * SERIAL_6O1   6-bit Odd  parity 1 stop bit   
 * SERIAL_7O1   7-bit Odd  parity 1 stop bit  
 * SERIAL_8O1   8-bit Odd  parity 1 stop bit   
 * SERIAL_5O2   5-bit Odd  parity 2 stop bit   
 * SERIAL_6O2   6-bit Odd  parity 2 stop bit    
 * SERIAL_7O2   7-bit Odd  parity 2 stop bit    
 * SERIAL_

CODE SOLUTION:

#include <HardwareSerial.h>

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

void setup() {
  Serial.begin(9600);
  BA.begin(9600, SERIAL_8E1, 32, 33);  // (Baud rate, Protocol, RX, TX)
  ...  //rest of my code
2

The default for Arduino Serial is 8 data bits, no parity, one stop bit. The first page of your linked documents says: Start bit 1, Data bit 8, Parity bit Even, Stop bit 1. The mismatched parity parameter could explain a partial failure of this communication. The documentation for the Serial begin() method describes the various configuration options.

However, see also this thread: https://forum.arduino.cc/t/altsoftserial-how-to-change-parity-solved/668535 It appears that the various software serial libraries do not support EVEN parity settings. Use a hardware serial port on your TTGO Arduino instead. This may mean using SoftwareSerial for the debug printing (maybe with a USB/UART adapter) and dedicating the hardware serial port to your bank note reader.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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