Adding the Output

Hello,

I have this project that involves Bill Acceptor and Arduino. Whenever I insert a bill, it instantly displays the bill Ive inserted (e.g. insert 500 bill, arduino displays 500). I just have a little problem in this project. I want to add the total bills (example, first bill inserted is 500, then another 500 bill is inserted, it should display 1000). Do you guys know what command to use? this is my code BTW. I got it from Pyramid Apex 5000 Bill Acceptor + Arduino Uno - YouTube. Thanks for the video, I really really find it very useful.

//Pyramid Technologies APEX Series 5000 Bill Acceptor
//Arduino Library
//By Jesse Campbell, www.jbcse.com
//Configuration info: Imgur: The magic of the Internet, http://i.imgur.com/b6b0SuH.jpg
//2014-11-15

#include <ReceiveOnlySoftwareSerial.h>
//http://gammon.com.au/Arduino/ReceiveOnlySoftwareSerial.zip

#define PIN_TTL_RX 10 //Green wire, Transmit data line from acceptor
#define PIN_INTERRUPT_LINE 4 //orange wire on APEX, Request send data to host
#define PIN_SEND_LINE 5 //white/blue wire, host ready signal

ReceiveOnlySoftwareSerial mySerial(PIN_TTL_RX); //RX

struct codeMap{
int code;
String description;
};

const int codeCount = 13;
codeMap codes[codeCount];

void setup()
{
Serial.begin(115200);
while (!Serial) { } //wait for Serial to be available

//set the data rate for the ReceiveOnlySoftwareSerial port
mySerial.begin(600);
digitalWrite(PIN_TTL_RX, HIGH); //internal pull up required

codes[0].code = 0x81;
codes[0].description = "20 Pesos Credit";
codes[1].code = 0x82;
codes[1].description = "50 Pesos Credit";
codes[2].code = 0x83;
codes[2].description = "100 Pesos Credit";
codes[3].code = 0x84;
codes[3].description = "200 Pesos Credit";
codes[4].code = 0x85;
codes[4].description = "500 Pesos Credit";
codes[5].code = 0x86;
codes[5].description = "1000 Pesos Credit";
codes[6].code = 0x87;
codes[6].description = "1 Credit";
codes[7].code = 0x88;
codes[7].description = "Reserved";
codes[8].code = 0x89;
codes[8].description = "Vend";
codes[9].code = 0x8A;
codes[9].description = "Return";
codes[10].code = 0x8B;
codes[10].description = "Reject";
codes[11].code = 0x8C;
codes[11].description = "Failure";
codes[12].code = 0x8D;
codes[12].description = "Full or Jam";

pinMode(PIN_INTERRUPT_LINE, INPUT);
pinMode(PIN_SEND_LINE, OUTPUT);
}

void loop() //run over and over again
{
if (digitalRead(PIN_INTERRUPT_LINE) == LOW){
digitalWrite(PIN_SEND_LINE, LOW);
digitalWrite(PIN_SEND_LINE, HIGH);
}

long start = millis();

while(millis() < start+5)
if (mySerial.available()){

int codeFromBillAcceptor = mySerial.read();
//Serial.println(codeFromBillAcceptor, HEX);

for(int i=0; i<codeCount; i++)
if (codes*.code == codeFromBillAcceptor){*

  • //Serial.print(millis());*
    _ Serial.println(codes*.description);_
    _
    }_
    _
    }_
    _
    }*_

How do you decide when to zero the total?

Hopefully now you can see why we ask you to please remember to use code tags when posting code.

void loop() //run over and over again
{
   if (digitalRead(PIN_INTERRUPT_LINE) == LOW){
   digitalWrite(PIN_SEND_LINE, LOW);
   digitalWrite(PIN_SEND_LINE, HIGH);
}

Why do you do this? A week from now, you won't remember, if you know now. Put a comment in the code when it is doing something that is not obvious.

Why does the close } for the if statement line up with the open { for the loop() function?

Use Tools + Auto Format so you don't look so clueless.

e.g. insert 500 bill, arduino displays 500

It does NOT. It displays "500 Pesos Credit".

I want to add the total bills (example, first bill inserted is 500, then another 500 bill is inserted, it should display 1000

Grab your calculator. What is "500 Pesos Credit" plus "500 Pesos Credit"? You can't answer that, which shows that you have a problem. Your struct needs at least one more field, to hold the value 500 associated with the string "500 Pesos Credit". You can also see that the string "500 Pesos Credit" is useless, because that string is NOT the string you want to display.

Then, when more than one bill is inserted, you can add the numeric values, and create the string to be printed.

Of course, AWOL's point needs serious consideration. What defines a single transaction vs. multiple transactions?

Yes, I already know im not so good in arduino thats why im here. Im a beginner. Thats why I asked the community some help. Asked the "needed command" specifically. This what makes me hesitant sometimes to ask the community because instead of getting a helpful answer, I get sarcastic responses. The RPi community is way much better compared to people here.

Yes, I know Im asking stupid questions. My point is, I want to learn thats why I bothered to ask. I want to be enlightened, not insulted.

Im disappointed BTW. Thanks anyways for answering a stupid question.
Wish you guys could be more friendly next time.

Thats why I asked the community some help

And help you got.
Maybe from way up there on your high horse you can't quite make it out.

I'm still trying to figure out what it was you took as an insult.

The RPi community is way much better compared to people here.

No it is not. You can wait weeks for an answer and when / if you get it then it is rubbish.
This happens to a good half the questions I post there. Try following a Linux tutorial on the web that is over six months old and you are told you are stupid for following something so old. Most of them end up bricking your operating system and so you loose all the installs you previously had, that have taken days to install.

You try complaining of something in Linux that doesn’t work and you get the full gamete of :- we are only part time, we give our time for free, I don’t know why I bother. But absolutely no help.

Our responses are designed to make you think about what you have done in an effort to try and make you think. You got excellent help here. Especially for someone who couldn’t be arsed reading how to use the forum.

Asked the "needed command" specifically.

You asked how to add two strings to get a number. It should be obvious that that can not be done.

AWOL:
And help you got.
Maybe from way up there on your high horse you can't quite make it out.

I'm still trying to figure out what it was you took as an insult.

u are finding hard time figuring it out because u are too ignorant to notice it. Why dont you try looking back the time u really really badly needed help but get an insult instead.

If u cant provide any good answer, u dont need to be sarcastic. Why not give suggestions instead of directly saying "NO U CANT DO THAT". Why not provide alternatives? This community is clearly not for beginners, like me. Im sure I have learnt how to do solve my problem. I just cant seem to know how to properly use the right command.

I can compare myself to a 5 year old kid wanting to learn. Give a 5 year old a bicycle, he finds it hard how to use it properly. Thats why parents guide the child on how to use the bicycle. But saying directly to a child "YOU DONT KNOW HOW TO RIDE A BIKE" could be the end of a child's dream to ride a bike.

Nevertheless, there is no need for me to explain further why Im not so good at this. Just get my point. I just needed some guidance. You really dont need to be sarcastic afterall.

And oh, Im so sorry for asking for your PART TIME dear sir. Even if ur PART TIME is to insult others or end others motivation to learn, then it is not part time i believe.

This thread ends here.
Again, you could have provided a more friendly response. Never thought even the moderator discourages someone's will to learn.

Wow. You only get one post every five minutes, and you (note, not "u") waste it posting tripe like that.

Good luck with the learning.

OK, let's break down PaulS' response down.

You have a mismatch between what your sketch "says", and what it should say.

Let's say I have five 500 peso notes.

After I put in the second note, the display says "500 Pesos Credit"

Oops. I don't want to see that.

So the message should briefly say something like "500 Peso note entered", then "1000 Pesos Credit".

That means that the message associated with the event of entering a 500 Peso note (or indeed, any note) is incorrect.

Then as PaulS says, the value contained in the string is virtually useless, so you need to add an extra element in your structure, that gives the value of the note associated with the code returned by the bill acceptor.

This value needs to be added to a running-total, which is probably going to be a global integer variable BUT, as I noted in my first reply, you have to have some means of deciding when a new transaction is beginning, and zeroing this total.

Learning is about thinking - not about being spoon-fed answers.