Reading data from coin acceptor on Arduino Uno

I'm working on a project involving a programmable coin acceptor, but I'm running into problems getting the Arduino to read the data from the coin acceptor.

This is the coin acceptor: Programmable Coin Acceptor - RobotShop

I've tried using the code from this site:

to set up the coin acceptor, but I'm still having no luck.

I've attached my code below. Is there something I'm missing/not getting? When I put a coin through the acceptor, the acceptor recognizes the coin, but the Arduino isn't picking anything up.

// Use the softwareserial library to create a new "soft" serial port
// for the display. This prevents display corruption when uploading code.
#include <SoftwareSerial.h>
#define CACC 3

// Attach the serial display's RX line to digital pin 2
SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (unused)

long lcdSwitch = 0;
int lcdState = 0;
int coin = 0;
volatile int pulses = 0;
volatile long timeLastPulse = 0;

void setup()
{ 
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up

  pinMode(CACC, INPUT);
  attachInterrupt(digitalPinToInterrupt(CACC), coinISR, RISING);
  
  mySerial.write(254); // cursor to beginning of first line
  mySerial.write(128);
} 

void loop() 
{  
  long timeFromLastPulse = millis() - timeLastPulse;
  if (pulses > 0 && timeFromLastPulse > 200)
  {
    // sequence of pulses stopped; determine the coin type;
    if (pulses == 10)
    {
      Serial.println("Received dime (2 pulses)");
      //money += .1;
    }
    else if (pulses == 20)
    {
      Serial.println("Received quarter (5 pulses)");
      //money += .25;
    }
    else if (pulses == 30)
    {
      Serial.println("Received looney (10 pulses)");
      //money += 1.0;
    }
    else if (pulses == 40)
    {
      Serial.println("Received tooney (15 pulses)");
      //money += 2.0;
    }
    else
    {
      Serial.print("Unknown coin: ");
      Serial.print(pulses);
      Serial.println(" pulses");
    }

    pulses = 0;
  }
  
  if((millis() - lcdSwitch) > 5000ul)
  {
    lcdSwitch = millis();
    lcdState++;
    lcdState %= 2;
  }
  if(lcdState == 0)
  {
    mySerial.write("Gold Rush Draw  ");
    mySerial.write("Terminal        ");
  }
  else if (lcdState == 1)
  {
    mySerial.write("Please insert   ");
    mySerial.write("$1 or $2 coin   ");
  }
}

void coinISR()
{
  pulses++;
  timeLastPulse = millis();
}

lcd_test.ino (1.84 KB)

You appear to be trying to use pin 3 for the coin acceptor interrupt AND for SoftwareSerial. That won't work.

So if we change the pin number, our code should work? (I am working with Josul on this project)

tomhanksinapollo13:
So if we change the pin number, our code should work? (I am working with Josul on this project)

I don't know. I don't know what a mySerial is or why you have connected one to the Arduino.

If that is not what is attached to pins 2 and 3, why the hell is it called that in the program?

That is the LCD Screen that is displaying

 if((millis() - lcdSwitch) > 5000ul)
  {
    lcdSwitch = millis();
    lcdState++;
    lcdState %= 2;
  }
  if(lcdState == 0)
  {
    mySerial.write("Gold Rush Draw  ");
    mySerial.write("Terminal        ");
  }
  else if (lcdState == 1)
  {
    mySerial.write("Please insert   ");
    mySerial.write("$1 or $2 coin   ");
  }

You're using code designed to work with one coin acceptor, but that's not the coin accepter you're using...

It looks like the coin accepter you're using has switches to configure the format that it outputs data in - have you done that in accordance with the manual?

I updated the code to display

mySerial.write("Please Enter    ");
      mySerial.write("Eligible Number ");

for one coin and

mySerial.write("Credits: 1/2    ");
      mySerial.write("Please Insert $1");

for another, i can tell that they are displaying because they are interrupting what the LCD screen is already displaying but they are only flashing on the screen for a brief moment. How do I display the new text and not the old text?

#include <SoftwareSerial.h>
#define CACC 3

// Attach the serial display's RX line to digital pin 2
SoftwareSerial mySerial(3,2); // pin 2 = TX, pin 3 = RX (unused)

long lcdSwitch = 0;
int lcdState = 0;
int coin = 0;
volatile int pulses = 0;
volatile long timeLastPulse = 0;

void setup()
{ 
  mySerial.begin(9600); // set up serial port for 9600 baud
  delay(500); // wait for display to boot up

  pinMode(CACC, INPUT);
  attachInterrupt(digitalPinToInterrupt(CACC), coinISR, RISING);
  
  mySerial.write(254); // cursor to beginning of first line
  mySerial.write(128);
} 

void loop() 
{  
  long timeFromLastPulse = millis() - timeLastPulse;
  if (pulses > 0 && timeFromLastPulse > 200)
  {
    // sequence of pulses stopped; determine the coin type;
    if (pulses == 10)
    {
       mySerial.write("Credits: 1/2    ");
       mySerial.write("Please Insert $1");
      //money += .1;
    }
    else if (pulses == 20)
    {
      mySerial.write("Credits: 1/2    ");
      mySerial.write("Please Insert $1");
      //money += .25;
    }
    else if (pulses == 30)
    {
      mySerial.write("Please Enter    ");
      mySerial.write("Eligible Number ");
      //money += 1.0;
    }
    else if (pulses == 40)
    {
      mySerial.write("Please Enter    ");
      mySerial.write("Eligible Number ");
      //money += 2.0;
    }
    else
    {
      Serial.print("Unknown coin: ");
      Serial.print(pulses);
      Serial.println(" pulses");
    }

    pulses = 0;
  }
  
  if((millis() - lcdSwitch) > 5000ul)
  {
    lcdSwitch = millis();
    lcdState++;
    lcdState %= 2;
  }
  if(lcdState == 0)
  {
    mySerial.write("Gold Rush Draw  ");
    mySerial.write("Terminal        ");
  }
  else if (lcdState == 1)
  {
    mySerial.write("Please insert   ");
    mySerial.write("$1 or $2 coin   ");
  }
}

void coinISR()
{
  pulses++;
  timeLastPulse = millis();
}

Because the new text flashes for an instant, I know that the coin acceptor is reading the data properly. Now my issue is that the way that my text is set up.

When you walk through your display code, think about how long each step takes. Compare it with how long you want it to take.