Teensy 3.2 with Adafruit 4-Coin Counter

Status
Not open for further replies.

tblewis

New member
Hello,
I am using the Teensy 3.2 with the Adafruit 4 coin counter. I am powering it up correctly, and I have programmed it. The Adafruit has a wire "COIN" which is triggered and held high when a correct coin goes through. However, I am not able to detect this, I'm wondering is it a software issue or perhaps something with the hardware?

here is my code, I have tried using "pulseIn", and without interrupts but nothing seems to work.:

#define COIN 22
#define led 13
int coins;

void setup() {
// put your setup code here, to run once:
pinMode (COIN,INPUT);
pinMode (led,OUTPUT);
Serial.begin(115200);



attachInterrupt(COIN, isrService, RISING);
delay(500);
coins = 0;
}

void loop()
{

digitalWrite(led,LOW);
}

// watermark generates this interrupt
void isrService()
{
cli();
Serial.println("At ISR0");
coins++
digitalWrite(led,HIGH);
delay(300);
digitalWrite(COIN,LOW);
sei();
}
 
I see what looks like too much time and code that shouldn't be in an ISR.

Also why is there : digitalWrite(COIN,LOW);
That perhaps intended to be digitalWrite(led,LOW);

The isrService() and coins creation could just perhaps be:
Code:
int coins = 0;
volatile int isrcoins = 0;

void isrService()
 {
   isrcoins++
 }

Then in loop() keep a secondary 'known' prior copy of 'coins' and when it is seen to change then turn on the led for 300 millis, and update your 'known' prior copy of 'coins'.

Look into elapsedMillis to track the wait time to turn off the LED, a delay() will keep you from detecting coin arrival usably, especially as done with interrupts disabled.

Does Adafruit publish any sample code?

Also to make your code display more readable wrap it like this: code.PNG
 
Hello,
Thank you for the reply. I appears that the code doesn't even enter the ISR(), could it be because the change is happening too fast? Or maybe the Adafruit doesn't supply enough current?
 
I'd start with the hardware. If you don't have a voltmeter or a scope, can you simply connect a LED to the "COIN" output to see if it is ever going high?

In general you should not be putting Serial.print() statements into an interrupt routine- I'm not sure if that ever works. Try defragster's suggestion of simply incrementing the variable; you can print the value of the variable from your main() code to keep track of it.
 
Per @JBeale check your coin counter hardware setup - go back to Adafruit and confirm the details and check for a sample. I suppose there must be multiple outputs because coins have different values - there may be a some other setup? If it is bringing that line from low to high the Teensy should not miss it. If you can safely get 3.3v on a wire to touch to pin 22 (with coin counter disconnected) that should show the Teensy code to work with the print on coin change.

If you've updated your code per my first post - show what you have now.
 
uhm... doesn't attachInterrupt requires use of the "digitalPinToInterrupt(pin)" on teensy?

Try replacing:
attachInterrupt(COIN, isrService, RISING);
To:
attachInterrupt(digitalPinToInterrupt(COIN), isrService, RISING)
 
For PinInt #2 and touch screen usage I just did this and worked perfectly: attachInterrupt( PinInt, TS_isrPin, FALLING );
 
Hello,
I checked the Coin Acceptor with an LED as suggested. I checked with a scope before and I thought it worked, but the when I tested with the LED it was clearly not. Maybe something happened along the way but it was a hardware issue. Currently using a different coin collector, the DG600F.
Thanks for the help!
 
Status
Not open for further replies.
Back
Top