I am trying to analize 3 wires conected to pin A3,A4,A5 so i ´ve created a function that detect the pulse,
with just one wire works well , but when I call the function using the 3 wires the code doesnt work , can anyone give me help to know why it happens? Many thanks
I expected to display a message according the LOW pulse if A3,A4 or A5
Why does leerpulso() contain a return statement that tries to return a value? The return type is void, so the function can NOT return a value.
but when I call the function using the 3 wires the code doesnt work
The code DOES work. That it doesn't do what you expect means that your expectations are wrong.
What is connected to the pins? Does that actually force the pins to a HIGH or LOW state ALL THE TIME? Or, should you have pullup or pulldown resistors to guarantee a valid state for the pins at all times?
when pulseIn() returns an unsigned long - a number of microseconds.
...R
PS ... To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum
C:\Users\Philippe10\Documents\Arduino\sketch_aug15b\sketch_aug15b.ino: In function 'void leerpulso(char)':
C:\Users\Philippe10\Documents\Arduino\sketch_aug15b\sketch_aug15b.ino:55:8: warning: return-statement with a value, in function returning 'void' [-fpermissive]
return resultado;
As you have "void leerpulso(char pinentrada)" (a void function), you can't have a return.
Hi all , a friend give me a bill validator , is an old Bill Acceptor ( NV10 ) , the Bill validator is the one that validate the Billnote, then it has 4 wires in paralel , one for each channel ( billnote ) , the billvalidator has always the 4 wires to 5V and gives a pulse acoording the billnote 1 , billnote2,etc... the pulse according the manual that i found on internet is 100ms +- 3ms , but i read that values 99676,99668,99684,99691,99689,99680 so all of them are very close and when the bill is invalid give me the value 0 , so is really easy to detect .I know that really the function and the code is not optimized , just first i try that works and the optimize all , as the arduido code is really a LOOP i call 3 times to read 3 wires at the same time.
THe wiring is really easy 4 cables comming from bill acceptor with 5V and when bill is valid i get a milisecond down pulse in the desired wire.Just need to identify and after that I will active a led for some second depending of the wire.
I add the code cleaned and commented into english , hope now wil be more easy to understand the project, I Have done all correction by you but still give me the same results.
int external_pulse_input;
void setup ()
{
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
Serial.begin (9600);
}
void loop ()
{
exteral_pulse_read(A3); //red wire from bill acceptor
exteral_pulse_read(A4); // yellow wire from bill aceeptor
exteral_pulse_read(A5); // blue wire from bill acceptor
}
//MIS FUNCIONES
void exteral_pulse_read(int external_pulse_input) //Reads bill acceptor pulse getting the pinnumber from the void loop
{
float Pulso;
float Tiempo = 0;
//Serial.print (external_pulse_input);
Pulso = pulseIn (external_pulse_input, LOW);
Tiempo = Pulso;
if (Tiempo >= 99600)
{
if (external_pulse_input == A3)
{
Serial.print ("Bill detected -pulse on pin A3 ");
Serial.print (Tiempo);
}
else if (external_pulse_input == A4)
{
Serial.print ("Bill detected -pulse on pin A4 ");
Serial.print (Tiempo);
}
else if (external_pulse_input == A5)
{
Serial.print ("Bill detected -pulse on pin A5 ");
Serial.print (Tiempo);
}
}
}
You are NOT reading all three wires AT THE SAME TIME. The pulseIn() function is a blocking function. It does NOT return until the expected condition has been met, or enough time has elapsed to reasonably conclude that the expected condition is not going to be met.
To read all 3 wires "at the same time" you need to use interrupts. The UNO only has 2 external interrupt pins, so you need a different Arduino. A Mega has 5 external interrupts.
According to 6.5 of this manual, if it is anything like what you have described, you want to tie pins 1-4 of the bill accepter to pins 1-4 of a ULN2001. You will need 4 1k pull-up (to 5 volts) resistors, one on each of pins 16,15,14 and 13, of the ULN2001 and these same pins will be your input to the Arduino. Next, you will want to tie ground on the bill validator to pin 8 on the ULN2001 and ground on the arduino, so they all reference the same ground. This will prevent the bill validator from sending 12 volts to the input pins on your Arduino. Because it's a darlington NPN transistor array, a high-to-low pulse from the bill validator will be seen as a low-to-high pulse on the input pin of the Arduino. the code can be more or less as follows:
int vend1PinState = digitalRead(vend1Pin);
if (vend1PinState != lastVend1PinState && vend1PinState == HIGH) {// looks for low to high transition
if (micros() - lastVend1PinTime >= debounceTime) {// only valid after debounce time
lastVend1PinTime = micros();
lastVend1PinState = vend1PinState;
while (digitalRead(vend1Pin) == HIGH);//stays here for the pulse length: NOTE blocking code
unsigned long timeNow = micros();
if (timeNow - lastVend1PinTime >= minimumPulseTime && timeNow - lastVend1PinTime <= maximumPulseTime) {
// turn on the LED
}
}
}
else lastVend1PinState = vend1PinState;
ULN2001 sounds really a good option !! , also i read all comments and I ordered one ULN2001 , as am experimenting i decide to create this code .
I will use only 3 wires and it works as expected, the main loop call to read one of the 3 wires meanwhile the others 2 will be controlled by an Interrupt , so i will have monitor of 3 wires right?
How i can do a delay only first time when I boot the system , arduino give a false interrupt when it reset
so i need that arduino will start with a delay. :o
code is:
const byte interruptPin2 = 2;
const byte interruptPin3 = 3;
void setup ()
{
pinMode(A3, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
Serial.begin (9600);
attachInterrupt(digitalPinToInterrupt(interruptPin2),function2, FALLING);
attachInterrupt(digitalPinToInterrupt(interruptPin3),function3, FALLING);
}
void loop ()
{
exteral_pulse_read(); //red wire from bill acceptor (pnly called once due pulseln is a blocked fuction)
}
//MIS FUNCIONES
void function2()
{
Serial.print ("10 Euros Bill detected -pulse on pin A4 "); // Yellow Wire
}
void function3()
{
Serial.print ("20 Eur Bill detected -pulse on pin A5 "); // Blue Wire
}
void exteral_pulse_read() //Reads bill acceptor pulse getting the pinnumber from the void loop
{
float Pulso;
float Tiempo = 0;
Pulso = pulseIn (A3, LOW);
Tiempo = Pulso;
if (Tiempo >= 99600)
{
Serial.print ("5 Euros Bill detected -pulse on pin A3 "); // Red wire
Serial.print (Tiempo);
}
}
This code works well with bills acceptor connected to arduino UNO and detects pulses from 3 diferent channels.
cli();//turns off the global interrupt flag. Interrupts will cue up, but not execute
delayMicroseconds(5000UL)
sei();//turns on the global interrupt flag. Any interrupts that have cued will execute in order.