Inputs, outputs Arduino > UART PTVO > Domoticz
Posted: Sunday 02 July 2023 19:25
With a simple .ino I connected an MFRC522 via a nano and a CC2530 (PTVO UART) to Domoticz. This setup works well. In connection with another application, I want to use multiple pins (2 inputs and 2 outputs) of the nano. I managed to replace the Wiegand (see https://github.com/Gio-dot/Z1-Mini/blob ... iegand.ino) with a MFRC522.
With the above code it's possible to make the uids visible in Domoticz. There are no error messages when compiling and uploading. But when switching in the inputs there is no response to be found in the Zigbee2mqtt log. I got stuck due to lack of knowledge.
Hopefully someone will be willing to help. Thanks in advance.
Regards,
Jan
Code: Select all
/*
060420 MODIFIED BY https://github.com/Gio-dot
ADDED WIEGAND PROTOCOL READING ON SERIAL PINS 2 (D0) AND PIN 3 (D1)
READING OUT CODE ON UART RX/TX PINS
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
unsigned long duration_code = 0; // MFRC 522 code duration (after a certain time sending empty code on the serial)
int flag_duration_code = 0; // Flag to delete MFRC 522 only once
const int Out1 = 7;
const int Out2 = 8;
const int In1 = 5;
const int In2 = 6;
// const int In3 = 5;
// const int In4 = 6;
const int In1rd;
const int In2rd;
// const int In3rd;
// const int In4rd;
// int flag1off= 1;
// int flag1on= 1;
// int flag2off= 1;
// int flag2on= 1;
// int flag3off= 1;
// int flag3on= 1;
// int flag4off= 1;
// int flag4on= 1;
char st[20];
char ch;
void setup()
{
Serial.begin(9600); // Initialiseer seriƫle communicatie
SPI.begin(); // Initialiseer SPI bus
mfrc522.PCD_Init(); // Initialiseer MFRC522
pinMode(Out1, OUTPUT);
pinMode(Out2, OUTPUT);
pinMode(In1, INPUT_PULLUP);
pinMode(In2, INPUT_PULLUP);
}
void loop()
{
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial())
{
return;
}
// Toon UID tag
Serial.print(" ");
String inhoud= "";
byte letter;
for (byte i = 0; i < mfrc522.uid.size; i++)
{
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
inhoud.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
inhoud.concat(String(mfrc522.uid.uidByte[i], HEX));
duration_code= millis(); // zero time to send empty chaodice Wiegand
flag_duration_code= 1; // Flag to delete Wiegand only once
}
{
delay(2000); // waits for 2 seconds
}
if ( ( (millis()-duration_code)>=2000)&&(flag_duration_code== 1) )
{
Serial.println(0); // After 2 seconds of reading send empty Wiegand code to be ready for subsequent readings
flag_duration_code= 0;
}
int In1rd = digitalRead(In1); // read the status of the 2 entrances...
int In2rd = digitalRead(In2);
if (Serial.available() > 0)
{
ch = Serial.read();
// Serial.println (ch); //
}
if (ch == '1')
{
digitalWrite(Out1, LOW);
}
else if (ch == '2')
{
digitalWrite(Out1, HIGH);
}
else if (ch == '3')
{
digitalWrite(Out2, LOW);
}
else if (ch == '4')
{
digitalWrite(Out2, HIGH);
}
}
Hopefully someone will be willing to help. Thanks in advance.
Regards,
Jan