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:
- Insert a bill into BA
- 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))
- 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.
- If 0x02 is NOT sent to the BA within 5 seconds, then it will reject the bill and spit it back out the front.
- 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;
}
}
}