I have a project where I simulate up to 26 wiegand readers using an arduino mega. I use this library for the wiegand output: GitHub - castrofernando/WiegandOutput-Arduino: Wiegand output library for 26 and 34 bits for arduino
Instead of declaring declaring the spesific pins to output the wiegand to each time, I have the pin pairs stored in an array so I can use the array as a "reader channel" insted.
My array for the pins looks like this:
// Define the pin pairs for each reader
const int pins[][2] = {
{54, 55}, // Pin pairs for reader 1
{56, 57}, // Pin pairs for reader 2
{58, 59}, // Pin pairs for reader 3
{60, 61}, // Pin pairs for reader 4
{62, 63}, // Pin pairs for reader 5
{64, 65}, // Pin pairs for reader 6
{66, 67}, // Pin pairs for reader 7
{68, 69}, // Pin pairs for reader 8
{6, 7}, // Pin pairs for reader 9
{8, 9}, // Pin pairs for reader 10
{22, 23}, // Pin pairs for reader 11
{24, 25}, // Pin pairs for reader 12
{26, 27}, // Pin pairs for reader 13
{28, 29}, // Pin pairs for reader 14
{30, 31}, // Pin pairs for reader 15
{32, 33}, // Pin pairs for reader 16
{34, 35}, // Pin pairs for reader 17
{36, 37}, // Pin pairs for reader 18
{38, 39}, // Pin pairs for reader 19
{40, 41}, // Pin pairs for reader 20
{42, 43}, // Pin pairs for reader 21
{44, 45}, // Pin pairs for reader 22
{46, 47}, // Pin pairs for reader 23
{48, 49}, // Pin pairs for reader 24
{50, 51}, // Pin pairs for reader 25
{52, 53} // Pin pairs for reader 26
};
I then do this to initialize all the pins:
const unsigned int NUM_READERS = sizeof(pins) / sizeof(pins[0]);
WiegandOut* wiegandReaders[NUM_READERS];
for (int i = 0; i < NUM_READERS; i++) {
wiegandReaders[i] = new WiegandOut(pins[i][0], pins[i][1]);
}
And when I want to send something to a readerchannel I do this
wiegandReaders[readerNumber - 1]->send(cardNumber, 26, true);
The rest of the code is recieving and parsing MQTT messages and forwarding carddata to spesific channels.
This setup works, and works in my current code as long as I only use analog pins. In the first snippet of this post i declare them as 54-69, but I have also used the A0-A15 naming convention. When I add the analog pins to the array and use either naiming convention, my code stops executing after the first mqtt message is recieved. The message is handeled correctly and the wiegand data is passed as it should, but for some reason it just stops. I am unfortuntely not able to share the whole code, but since I have narrowed the issue down to the contents of the array, I am hoping that fixing this fixes the code stopping.
So with this setup, what do I need to do to use analog pins in this scenario as digital outputs? I have run around in circles for a while now and can't make heads or tales of this any more even if it's a basic thing.
6 posts - 5 participants