Friday, July 8, 2011

Project 1 - Arduino Accepting Coins

I am unable to finish this sketch at the moment.  I have run into trouble listening for the interrupt, pulling the send line to low, and listening on the data line (at 600bps) for binary.  Any assistance, advice, or anything that helps would greatly help.  In the meantime, I can control the solenoids that dispense change using the code below.  Have fun and thank you

Update 11/5/11: The MDB RS-485 is a 9-bit protocol.  It's really not cool.  8 regular bit and a mode bit to make an address or data byte.  This is in addition to the obvious start and stop.  There's not a ton of material to make something read this.  It sounds like one of those do it yourself without reference material.

2/23/12:  Still work in progress, no positive results.

SUMMARY:  This post focuses on one of the many devices that accepts coins, known as the coin mechanism, and how to get it to work with an Arduino.


Material from coinco:

I. Valid Coin
  1. The valid coin status message defines the value of the

valid coin, the status of the coin tube sensors, and the destination of the valid coin (cash box or inventory
tubes).
  1. The changer will attempt to validate coins and transmit

the information to the external controller if the external controller is not requesting information from
the changer (i.e. the accept enable input line is low and
the send input line is high,
see Table 7 Sections I B and
C respectively) and the changer is not in the process of sending information to the external controller (i.e. the interrput output line is high and the data output line is high. See Table 7 Sections II A and B respectively).
  1. If the coin is valid then a single message will be sent to the external controller from the changer as follows:
  1. The interrupt output line will be pulled low by the
changer indicating to the external controller a
message is ready to be transmitted.
  1. The external controller will acknowledge the

interrupt output request within 5 MSEC +/- .5 MSEC
by pulling the send input line low.
  1. The changer will then begin serially transmitting the message within 2 MSEC at 600 BAUD using the data output line. After the transmission of 10 BITS
(approximately 16.66 MSEC) the external controller will pull the send input line high for at least 2 MSEC but not more than 20 MSEC (refer to Figure 6). This completes the single transmission communication
protocol (see Table 8 for status word definitions).
  1. The external controller can request a repeated

transmission if it elects to do so. However, a maximum of 4 repeats is recommended. A repeated
transmission is initiated by the external controller pulling the send input low 2 MSEC minimum to 4 MSEC maximum after the send input line is pulled high, indicating the completion of the previous transmission by the changer as described in pargraph 3C above



Code for TRC-6010:

/*
* Rough draft of arduino sketch used to
* communicate with a coin mechanism.
* Coin mechanism model used is:
* Mars(MEI) TRC-6010 (12-pin plug)
*/


// declare constants for the pins
const int sendPin = 3;
const int interruptPin = 2;
const int dataPin = 5;
const int enablePin = 6;
const int quarterPin = 7;
const int dimePin = 8;
const int nickelPin = 9;
const int resetPin = 11;

// declare variables
int counter = 0; // counter is a means to view the number of interrupts in triggered()
char incoming_char = 0; // to isolate/test coin mech functions

void setup()
{

  // initialize the interrupt
  // set the interrupt
  attachInterrupt(0, triggered, FALLING);
  // so when interrupt zero (digital pin 2) changes state,
  // triggered is fired

  // initialize required lines from arduino to coin mech (OUTPUT)
  pinMode(sendPin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(quarterPin, OUTPUT);
  pinMode(dimePin, OUTPUT);
  pinMode(nickelPin, OUTPUT);
  pinMode(resetPin, OUTPUT);

  // set the pins to proper state
  digitalWrite(sendPin, HIGH);    // HIGH = Waiting
  digitalWrite(enablePin, LOW);   // LOW = Enabled(accept coins)
  digitalWrite(quarterPin, HIGH); // HIGH = Not active
  digitalWrite(dimePin, HIGH);    // HIGH = Not active
  digitalWrite(nickelPin, HIGH);  // HIGH = Not active
  digitalWrite(resetPin, LOW);    // LOW = No reset



  // Initialize serial port communication
  Serial.begin(9600);
  Serial.println("Waiting for interrupt...");
}


void loop()
{


  if (Serial.available())
  {
    incoming_char = Serial.read();
 
    if (incoming_char == '1')
    {
      digitalWrite(quarterPin, LOW);
      Serial.println("quarterPin set to LOW");
      delay(100);
      digitalWrite(quarterPin, HIGH);
      Serial.println("quarterPin set to HIGH");
    }
 
 
    else if (incoming_char == '2')
    {
      digitalWrite(nickelPin, LOW);
      Serial.println("nickelPin set to LOW");
      delay(100);
      digitalWrite(nickelPin, HIGH);
      Serial.println("nickelPin set to HIGH");
    }
 
    else if (incoming_char == '3')
    {
     digitalWrite(dimePin, LOW);
     Serial.println("dimePin set to LOW");
     delay(100);
     digitalWrite(dimePin, HIGH);
     Serial.println("dimePin set to HIGH");
    }
 
    else if (incoming_char == '4')
    {
      digitalWrite(enablePin, LOW);
      Serial.println("enablePin set to LOW = ACTIVE");
    }
 
    else if (incoming_char == '5')
    {
      digitalWrite(enablePin, HIGH);
      Serial.println("enablePin set to HIGH = DISABLED");
    }
 
    else if (incoming_char == '6')
    {
      digitalWrite(resetPin, HIGH);
      Serial.println("Reseting coin mechanism");
      delay(1000);
      digitalWrite(resetPin, LOW);
      Serial.println("Reset complete.");
    }

  }
}

void triggered()
{
  counter++;
  Serial.println(counter);
  digitalWrite(sendPin, LOW);
  delay(4);
  digitalWrite(sendPin, HIGH);
}

No comments:

Post a Comment