Sliding game opener project

Read the message. It can't find

#include <YetAnotherPcInt.h>

which probably means you have not installed a library used in the sketch, or installed it incorrectly or something.

The other two failures I have no clue about.

Do you have any other Arduino boards like UNO to try the examples on?

Do the examples have comments that require you to change or do anything with your circuit? I see you plan to randomly try other pins, perhaps a way of doing so with informed intention rather than here and there if that is what you mean.

a7

The pins I tried were labeled D0 and D1 on the image, so though I'd try. I don't really know what all the different things mean on the labels in that image.

I do have an uno and a nano I can try with.

I installed the library with the library manager.

I've tried with my Nano and my Uno and get the same results. Kinda leads me to believe my keypad is defective...

Or there are specific pins a wiegand device should be connected to and I'm just not finding it.

I've not dived deep, and obvsly, perhaps, I don't have any Weigand standard device to test with.

The documentation at the GitHub site, however, seems to imply that there is flexibility in the code and with that comes the responsibility to figure out the details of pins and stuff.

I'll look later, but it seems like you do have to make some (informed) choices, all I can suggest is carefully reading the docs and/or finding a tutorial or other complete example to follow slavishly.

My first thought is not usually that something in front of me is defective, I don't think it should be your conclusion just yet.

a7

I've been able to get a different output:

State changed: CONNECTED

Card readed: 24bits / 515CB7

Card read error: Unsupported message format - Raw data: 1bits / 00

I found this (emphasis mine)

The Wiegand interface uses three wires, one of which is a common ground and two of which are data transmission wires usually called DATA0 and DATA1, alternately labeled "D0" and "D1" or "Data Low" and "Data High". When no data is being sent, both DATA0 and DATA1 are pulled up to the "high" voltage level — usually +5 VDC. When a 0 is sent the DATA0 wire is pulled to a low voltage while the DATA1 wire stays at a high voltage. When a 1 is sent the DATA1 wire is pulled to a low voltage while DATA0 stays at a high voltage.

From here GitHub - jvondrus/Wiegand26: Library for receiving data from the Wiegand26 card readers, it's made for the Arduino IDE and for an Arduinos, ESP32 and ESP8266 devices..

The schematic in my owners manual is super simple and has the power coming from the same source that receives the signal. After finding that quote I ran a ground wire from the power supply ground wire to the Uno and got a real output. Still erroring, but it updates when I use one of the provided rfid cards. I haven't programmed any codes in yet.

Swiped the card again and didn't get the error, so looks like it just errors on first read. Now to figure out how to do something with it, and probably to get it to work with the esp32 board.

It looks like it sends a 4bit signal for each keypress and I can't get a programmed keycode to work. So maybe I can take the key press inputs into a string and compare to a constant programmed in to activate the gate.

Each key sends it's number, * sends A, and # sends B. I'll have to think through how to do this best. Maybe I'll be able to figure out what I'm doing wrong in programming it so I can see what kind of signal it sends with a correct code.

I got a code programmed in, there is no additional signal sent after a completed code, and I've not been able to detect a signal on any of the other wires, so I'll just capture the bits as the come in and compare against a constant. So I'll just have to figure out how to do that...

OK, I am confused.

Are you using a keypad or some kind of card reader?

Please remind us what exact input device you are trying to get working.

There is no need in any case for you to be worrying about gathering bits or whatever. That should be handled by the library.

a7

Sorry it's take so long didn't get on the computer at all this weekend.

It's both, has a keypad and an rfid reader. Not planning on using the rifd chips, but they have been handy for testing.

Here is a link to the keypad I got. https://www.amazon.com/gp/product/B07RCH8T17/ref=ppx_yo_dt_b_search_asin_title?ie=UTF8&psc=1

No matter how fast I enter the key code with the keypad it shows each keypress, rather than a string of key presses, and when a saved keycode is entered there wasn't an additional signal sent.

Please post code you are using. Without seeing the way you are handling this input device, I can only assume you are not doing it correctly yet.

Or some example sketch that you didn't write or mess with, showing how to work it for developing input strings.

It is normal for a process to receive key strokes, like from a regular keyboard, and collect them until some kind of condition is met - four characters, or a carriage return or whatever marking the end of the a sequence.

a7

I've been using the polling example, with the only modifications being the pins and a commented out Serial.print command to get rid of the leading 0 on the output.

/*
 * Example on how to use the Wiegand reader library with interruptions.
 */

#include <Wiegand.h>

// These are the pins connected to the Wiegand D0 and D1 signals.
#define PIN_D0 14
#define PIN_D1 12

// The object that handles the wiegand protocol
Wiegand wiegand;

// Initialize Wiegand reader
void setup() {
  Serial.begin(9600);

  //Install listeners and initialize Wiegand reader
  wiegand.onReceive(receivedData, "Card readed: ");
  wiegand.onReceiveError(receivedDataError, "Card read error: ");
  wiegand.onStateChange(stateChanged, "State changed: ");
  wiegand.begin(Wiegand::LENGTH_ANY, true);

  //initialize pins as INPUT
  pinMode(PIN_D0, INPUT);
  pinMode(PIN_D1, INPUT);
}

// Continuously checks for pending messages and polls updates from the wiegand inputs
void loop() {
  // Checks for pending messages
  wiegand.flush();

  // Check for changes on the the wiegand input pins
  wiegand.setPin0State(digitalRead(PIN_D0));
  wiegand.setPin1State(digitalRead(PIN_D1));
}

// Notifies when a reader has been connected or disconnected.
// Instead of a message, the seconds parameter can be anything you want -- Whatever you specify on `wiegand.onStateChange()`
void stateChanged(bool plugged, const char* message) {
    Serial.print(message);
    Serial.println(plugged ? "CONNECTED" : "DISCONNECTED");
}

// Notifies when a card was read.
// Instead of a message, the seconds parameter can be anything you want -- Whatever you specify on `wiegand.onReceive()`
void receivedData(uint8_t* data, uint8_t bits, const char* message) {
    Serial.print(message);
    Serial.print(bits);
    Serial.print("bits / ");
    //Print value in HEX
    uint8_t bytes = (bits+7)/8;
    for (int i=0; i<bytes; i++) {
        //Serial.print(data[i] >> 4, 16);
        Serial.print(data[i] & 0xF, 16);
    }
    Serial.println();
}

// Notifies when an invalid transmission is detected
void receivedDataError(Wiegand::DataError error, uint8_t* rawData, uint8_t rawBits, const char* message) {
    Serial.print(message);
    Serial.print(Wiegand::DataErrorStr(error));
    Serial.print(" - Raw data: ");
    Serial.print(rawBits);
    Serial.print("bits / ");

    //Print value in HEX
    uint8_t bytes = (rawBits+7)/8;
    for (int i=0; i<bytes; i++) {
        Serial.print(rawData[i] >> 4, 16);
        Serial.print(rawData[i] & 0xF, 16);
    }
    Serial.println();
}

The output I get when hitting the key code ending with a # as the instructions say to enter it is:

Card readed: 4bits / 1

Card readed: 4bits / 4

Card readed: 4bits / 7

Card readed: 4bits / 8

Card readed: 4bits / B

The keypad light and beeps indicate that the key code was accepted, but there isn't a signal sent that a valid key code was entered.

When I use one of the rfid cards I get this output:

Card readed: 24bits / 515CB7

That callback is working perfectly, delivering keystrokes as you press buttons.

It looks like you pressed 1 4 7 8 #

your keypad is like

123
456
789
*0#

with the usual or unusual substitution of A for * and B for '#'.

So what you need to do is write a modify the callback function receivedData() that gets the press, as it seems to be called on each, and decides whether a complete message (of your own design) has been received, it could then set a flag to be recognized in the input phase of your loop, which would then use the complete message however you want.

I can't believe there aren't better examples. But this is sufficient.

I think you may not get the idea of the callback mechanism. Those obscure loop calls let the device handling software see if anything needs to be collected; that software then, maybe, calls the callback so you can do whatever you want with the new data it has gathered. In this case a single keystroke.

bool myWegandFlag;

void loop() {
  // Checks for pending messages
  wiegand.flush();

  // Check for changes on the the wiegand input pins
  wiegand.setPin0State(digitalRead(PIN_D0));
  wiegand.setPin1State(digitalRead(PIN_D1));


  if (myWegandFlag) {

// handle the wetland-collected key presses, like password seen or whatever 

    myWegandFlag = false;    // reset flag for next time

  }
}

Please post the working code that has no weigand stuff at all, and point out where and how you expect the weigand device to inform the flow of your process.

Ideally this is still be something that runs in the wokwi.

HTH

a7

I am going to work on this, first step is to figure out what a callback function is :slight_smile:

Precisely.

Callbacks are fun.

Because in setup() you registered (the comment calls it installing) the function receivedData


  wiegand.onReceive(receivedData, "Card readed: ");

If you do this in your loop


void loop() {
  // Checks for pending messages
  wiegand.flush();

  // Check for changes on the the wiegand input pins
  wiegand.setPin0State(digitalRead(PIN_D0));
  wiegand.setPin1State(digitalRead(PIN_D1));


then almost like magic, when data is received ("on receive"), that function receivedData gets called. And it is for you to do whatever you want with that opportunity.

You can see from the code that you can install two other callbacks, and do things appropriate for those events.

If you don't need a particular callback, simply ignore it: don't install a callback function, and you won't need to write it. The weigand software still does everything it needs to do, and with no callback installed just doesn't call back to you.

There may be limits to what you can do in a callback, but stashing an incoming character and/or setting a flag for you to notice in your loop are certainly OK.

a7

I haven't been able to figure out how to get the full sequence from the callback, but I did find the signal pin. It's an always hot pin and it gets turned off when the correct code is entered. So I think I can use the keypad without having to worry about any of the weigand stuff.

Suit yourself.

If you made any serious attempt to modify the code in #71 to accept and react to a key sequence, post it and say what it does or doesn't do that it shouldn't or should. Do.

a7

I was mostly just reading stuff to try and figure out what is going on. I've been reading through the wiegand.h and .cpp files, and searching the internet for examples, the stuff I found I couldn't make heads or tails of. So I don't really have any different code to share, it seems that most of the stuff that handles the input is hardwired in the library. The weather is getting colder which is aggravating my vertigo, so it's getting harder to focus.

I figured there had to be an output wire, I read through the manual a few more times then I just hooked up the other wires to an arduino, rather than use the multimeter to monitor them and found a wire that changed when I entered a code. I think the problem I was having with the multimeter is the signal length is too short for me to see it.

I'm sure I could do some cool stuff with the weigand stuff, but I'm out of my depth on it, and I would like to get this project done. So now I need to wire in the keypad and install it on the gate, install the runners to make sure the gate moves in a straight line, then test it in place.

Now the problem I'm working on is what kind of drill to get to drill holes in the concrete, my impact just isn't cutting it.