Good afternoon,
attached is what I was able to do from my coin acceptor code.
I am not getting the 1 euro two pulse coin, the 0.50 cent coin of a pulse and the 2 euro 4 pulse coin.
thank you for help
codigo_final.ino.ino (4.54 KB)
Good afternoon,
attached is what I was able to do from my coin acceptor code.
I am not getting the 1 euro two pulse coin, the 0.50 cent coin of a pulse and the 2 euro 4 pulse coin.
thank you for help
codigo_final.ino.ino (4.54 KB)
Hello
Welcome to the Arduino fora.
Before you do anything else please read General guidance
And
How to use this forum
Especially item #7 on posting code.
You are asking us for help with some mystery coin acceptor that you have told us nothing about. You have also not told us anything about how you have connected it or what Arduino or other hardware you have. There are some clever people on here, I don't think any of them are telepathic. Please read the forum instructions linked to above and provide a lot more information, then someone might be able to help.
Thank you.
thanks,
the arduino I used was the arduino nano.
I used the coin acceptor ch926.
I connected the coin acceptor signal wire to the D2 of the arduino nano, I connected a pull-up resistor 10k between the 5v pin of the arduino nano and the D2 pin.
I also used a 16 by 2 i2c display.
I have the time to show on the display and count the coins by putting in the coin acceptor with the coin acceptor connected to the arduino nano.
this is counting badly the currencies' impulses, I have the same impulse for different currencies and so the time that the currency should give is not enough.
I want the 50 cent to give an impulse, the 1 euro to give two impulses
and the two euro to give 4 impulses
Pedro,
I don't think you have read the instructions in the 2 links I provided, you certainly have not provided the information requested. Saying you connected this to that is not providing a schematic. Saying it is a CH926 tells me nothing useful.
If you want help you have to provide information, the information needed for me to stand any chance of helping is stated in the instructions.
Just in case you read this, there have been quite a few coin mech threads over the last year or two... some for the CH296.
Using the search tool in the menu bar might get some specific threads for you.
Have you confirmed that you have the coin acceptor properly set up and that it is accurately recognizing the coins?
Your beep() function is expecting an unsigned char, which would be limited to values from 0 through 255, but you are using values larger than that.
The interrupt service routine credito() is going to take much too long to execute, set a flag and move the portion with the analogWrite out of the ISR and into the main code. Also, the CT variable should be declared as volatile, and because it is larger than a single byte, you need to temporarily disable interrupts whenever accessing CT in your main code, otherwise an interrupt may occur between accessing the first and second byte of CT.
thanks,
I programmed the coin acceptor as follows:
50 centimos coin of 1 pulse, 1 euro coin of two pulses and 2 euro coin of four pulses.
so this is not happening and has to do with the code on the arduino
attached sending the coin acceptor ch926 manual
ch-926 multi coin acceptor.pdf (159 KB)
What is missing from the manual is the VOLTAGE of the pulse and is it - or + . I sure hope it is not a 12 volt pulse. Have you measured the pulse or looked at it on an oscilloscope?
And in order to have the Arduino even see a pulse, you need to have the Arduino ground connected to the black, ground, of the coin machine.
Paul
I didn't see it with the oscilloscope. I don't have an oscilloscope the coin acceptor ground is connected to the Arduino ground
Without doing any research, I recall from earlier discussions that the coin output is open collector, so a simple INPUT_PULLUP will provide what’s needed.
Counting the pulses with a timeout between coins up is needed,
As mentioned, this exact project has been resolved about five months ago on the forum.
https://www.google.com/search?ie=UTF-8&oe=UTF-8&q=ch926&domains=https%3A%2F%2Fforum.arduino.cc&sitesearch=https%3A%2F%2Fforum.arduino.cc
thanks, I changed some things in the code and I still have the same problem of time not hitting.
librarias para display ////////////////////
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
LiquidCrystal_I2C lcd(I2C_ADDR,2, 1, 0, 4, 5, 6, 7);
///////////// libraria para eeprom /////////////////////////
#include <EEPROM.h>
//////////// funcion del buzzer /////////////////////
void beep(unsigned char pausa)
{
analogWrite(9, 20); // suena
delay(pausa); // Espera
analogWrite(9, 0); // Apaga
delay(pausa); // Espera
}
//Variaveis
int CT=0;
int mxc;
int segundos=0;
int set=0;
volatile int pulses = 0;
volatile long timeLastPulse = 0;
////////////funcão para sumar tiempo de juego por interrupcion///////
void credito(){
pulses++;
timeLastPulse = millis();
CT=(mxc*60)+CT;
set=1;
int i=0;
while(i<=30000){
analogWrite(9, 20); // suena
i=i+1;
}
analogWrite(9, 0); // apaga
}
//////////funcion para convertir en segundos//////////////
void calseg(int count)
{
int minuto;
int segundo;
int unidad;
int decena;
minuto = count/60;
segundo = count-(minuto *60);
unidad = segundo%10;
decena = ((segundo/10)%10);
lcd.setCursor ( 12, 1 );
lcd.print(unidad);
lcd.setCursor ( 11, 1 );
lcd.print(decena);
}
//////////funcion para convertir en minutos//////////////
void calmin(int count)
{
int unidad;
int decena;
unidad = ((count/60)/1) % 10;
decena = ((count/60)/10) % 10;
lcd.setCursor ( 9, 1 );
lcd.print(unidad);
lcd.setCursor ( 8, 1 );
lcd.print(decena);;
}
void setup()
{
////// asignamos a mxc el valor guardado en eeprom celda 2 ////////
mxc=EEPROM.read(2);
////////declaramos interrupcion 0 del pin 2///////////
attachInterrupt(0, credito, FALLING);
//////////// declaramos saidas
pinMode(9, OUTPUT); //pin 9 como salida buzzer
pinMode(8, OUTPUT); //pin 8 como salida rele
//////// iniciamos con sonido de buzzer al energizar //////
beep(2000);
/////////// Inicializar DISPLAY ///////////
lcd.begin (16,2);
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // va a inicio
lcd.print("Iniciando timer");
lcd.setCursor ( 0, 1 ); // va a 2da linea
lcd.print(" Aguarde ");
delay(1000);
delay(1000);
delay(1000);
}
void loop()
{
lcd.home ();
lcd.print(" Inserir Moeda ");
delay(200);
long timeFromLastPulse = millis() - timeLastPulse;
if (pulses > 0 && timeFromLastPulse > 200)
{
if (pulses == 1)
{ mxc=1;
}
else if (pulses == 2)
{ mxc=2;
}
else if (pulses == 4)
{
mxc=4;
}
}
CT=mxc*60;
if (set==1)
{
EEPROM.update(2, mxc);
segundos=59;
// lcd.clear();
lcd.home (); // va a inicio
lcd.print(" Moeda Aceite ");
delay(1000);
lcd.clear();
while(CT>=1)
{
for(segundos=59;segundos>=0;segundos--){
CT=CT-1;
digitalWrite(8,HIGH);//ACTIVA RELE
//IMPRIME TIEMPO
lcd.home ();
lcd.print("min x credito: ");
lcd.setCursor ( 14, 0 ); //
lcd.print(mxc);//
lcd.setCursor ( 0, 1 ); //
lcd.print(" TIEMPO :");
calseg(CT); //muestra tiempo en segundos
calmin(CT); //muestra tiempo en minutos
delay(970);
if(CT==30)/////primera advertencia de poco tiempo de juego
{
beep(500); //prender buzzer
beep(100);
beep(500); //prender buzzer
beep(100);
beep(500); //prender buzzer
beep(100);
}
if(CT<=10)/////ultimas advertencias de poco tiempo de juego
{
beep(500); //prender buzzer
beep(100);
beep(500); //prender buzzer
}
}
}
if(CT==0){
set=0;
digitalWrite(8, LOW);
delay(1000);
beep(500); //prender buzzer
beep(100);
beep(500); //prender buzzer
beep(100);
beep(500); //prender buzzer
beep(100);
// delay(1000);
}
}
lcd.setCursor ( 0, 1 ); // va a 2da linea
lcd.print(" ");
delay(2);
}
good, I'm using a wemos d1 mini.
I'm having trouble reading the pulses that the coin acceptor gives and showing on the monitor port of the Arduino program.
would appreciate help
Would appreciate seeing the program and a schematic and details of the coin acceptor (link ?)
I want to read the pulses with the wemos and send them to thingspeak using the api code.
the signal wire from the coin acceptor is connected to the wemos D2.
I have an external 12 volt source to power the coin acceptor.
The gnd wire is connected to the wemos gnd, the EXTERNAL SOURCE GND and the coin acceptor gnd
Still no code or details of the coin acceptor
I've merged your other cross-post @pedroborges1994.
Cross-posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes (or more) writing a detailed answer on this topic, without knowing that someone else already did the same in the other topic.
Repeated cross-posting will result in a suspension from the forum.
In the future, please take some time to pick the forum board that best suits the topic of your question and then only post once to that forum board. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum board. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
#include <ESP8266WiFi.h>
#define tempo 15 // envia para o Thingspeak passado 15 segundos
#define D2 19
#define COIN_PIN D2
volatile int pulses = 0;
volatile long timeLastPulse = 0;
const char* server = "api.thingspeak.com";
String apiKey = "88F5VAVXVOF56PFU";
const char* nome_rede = "MEOCASA";
const char* password_rede = "JATEDISSE";
void setup() {
Serial.begin(115200);
FazConexaoWiFi();
Serial.println("Ready");
pinMode(COIN_PIN, INPUT);
attachInterrupt(D2, coinISR, RISING); // COIN wire connected to D2;
}
// executed for every pulse;
void coinISR()
{
pulses++;
timeLastPulse = millis();
}
void loop ()
{ long timeFromLastPulse = millis() - timeLastPulse;
if (pulses > 0 && timeFromLastPulse > 200)
{
// sequence of pulses stopped; determine the coin type;
if (pulses == 1)
{
Serial.println("1 pulses");
}
else if (pulses == 2)
{
Serial.println("2 pulses");
}
else if (pulses == 4)
{
Serial.println("4 pulses");
}
else
{
Serial.print("Unknown coin: ");
Serial.print(pulses);
Serial.println(" pulses");
}
pulses = 0;
}
if(pulses > 0)
{digitalWrite(LED_BUILTIN,HIGH);
delay(2000);}
else
{digitalWrite(LED_BUILTIN,LOW);
}
enviopulso(pulses);
int contador = tempo;
while(contador--)
delay(200);
}
void FazConexaoWiFi()
{Serial.println("Conectando-se à rede WiFi...");
WiFi.begin(nome_rede, password_rede);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("");
Serial.println("Connectado");
Serial.println("IP OBTIDO");
Serial.println(WiFi.localIP());
}//end
void enviopulso(int pulses)
{
WiFiClient client;
if (client.connect(server, 80)) { // use ip 184.106.153.149 or api.thingspeak.com
Serial.println("Informação enviada para o Thingspeak");
String postStr = apiKey;
postStr += "&field1=";
postStr += String(pulses);
postStr += "\r\n\r\n";
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
delay(1000);
}
}
Without seeing your circuit,my first guess would be to check the INPUT_PULLUP you didn’t use.
I hope you have an external pullup resistor and another ThingSpeak account, because now we know your login details.
Tidy code formatting doesn’t make your code run any better, but it often means it will run sooner.
manual coin acceptor
ch-926 multi coin acceptor.pdf (159 KB)
I've used a 10k pull up resistor connected to the coin acceptor signal pin at 5 more volts.
I think I have something bad in the code
I'm in trouble at the wemos already flashed several times and I couldn't.
but now I went to the monitor port on the arduino and this error appeared to me
3fffff60: 3ffee598 3fffdad0 3ffee53c 40203c52
3fffff70: 3fffdad0 3ffee48c 3ffee4c4 402010a6
3fffff80: 0001c200 0000001c 00000000 feefeffe
3fffff90: 3fffdad0 00000000 3ffee4c4 40201114
3fffffa0: feefeffe feefeffe 3ffee4fc 402037b0
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld