danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Tue Jul 28, 2015 2:50 am

Weird?? Looks the same but it isn't

The reference is for a "bloob" folder which is not there anymore.

I do have a copy into my dropbox.

Remove the rfid library and download the one in my github.

https://dl.dropboxusercontent.com/s/47l ... 0/rfid.zip
Last edited by danjperron on Wed Oct 04, 2017 7:10 pm, edited 1 time in total.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Tue Jul 28, 2015 7:14 pm

That did it - many thanks. I saw you project just before I was due to travel to France for a holiday so I packed all my electronic stuff with me so I could have a bash at it whilst I am away. Your prompt response really helped and I will be busy prototyping this in the sun tomorrow I hope!
Regards
David

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Tue Jul 28, 2015 7:42 pm

Perfect!

have fun in France!

I hope your french is good. This is my first language.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 10, 2015 1:30 pm

Hi Daniel,
Mon francais est pas trop mal et ma femme est Belg.

My English is, however, better! We had a great time and have had a place there now for over 10 years, its our intention to move there in 2 or 3 years if all goes well.
I have most of the project working now, just a couple of issues to resolve and then I will try to build on what I've learnt from you.
If I only want to retrieve information from a single reader, do I need to change the minimalmodbus address in the python code to 1? Or is there more to it than that?

Best Regards from a less sunny (than France) England.

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 10, 2015 3:42 pm

If I only want to retrieve information from a single reader, do I need to change the minimalmodbus address in the python code to 1? Or is there more to it than that?
If you have only one reader you need to know what is the SLAVE_ID number and use it to communicate .

If you have more than one, each card readers will need a different SLAVE_ID number.

Then the default which is set to 1 is ok for only one reader.

Each reader needs to have a different SLAVE_ID. This is how the modbus protocol differentiates devices.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 10, 2015 5:11 pm

Hi,
Okay, thanks. I will look at it when I get back from work.
Regards

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Wed Aug 12, 2015 11:13 am

Hi,
The hardware seems to be working but I don't get data passed from the Arduino to the Pi although I think the Arduino is receiving commands from the Pi as it accepts the night command ( I checked this by changing it to DAY in the python code and could see the different operation.. Swiping a card is working (I can check it if I connect the Arduino USB cable and look at the serial data) and the LED changes colour to indicate its waiting for response from the Pi to acknowledge the card authority but then it seems to hang until it times out. I am using a Nano not a Micro I have checked the wiring and it seems correct. I am using the simplemodbus slave version 9 in the Arduino library.
Any idea what I have done wrong or do you need more detailed explanation? I have looked at getting a modbus tester programme as suggested on the simplemodbus link page but though I would ask before I delve in!
Cheers
D

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Wed Aug 12, 2015 12:23 pm

I will give you some debug method tonight when I return from work or maybe at lunch time.

Try to use the python console and see if the arduino reply.

Enable the debug mode in minimal modbus

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Wed Aug 12, 2015 1:08 pm

Hi,
I should have mentioned that I tried enabling the debug mode (after following the guide on the simplemodbus page)and it indicated an error but I couldn't understand the result. I will run it again tonight and show you the result.
Regards
D

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Wed Aug 12, 2015 4:55 pm

Hi, This is what I get from Modbus debug:

MinimalModbus debug mode. Writing to instrument (expecting 7 bytes back): '\x02\x03\x01!\x00\x01ÕÏ'
MinimalModbus debug mode. No sleep required before write. Time since previous read: 1439398359402.2 ms, minimum silent period: 2.01 ms.
MinimalModbus debug mode. Response from instrument: '' (0 bytes), roundtrip time: 51.0 ms. Timeout setting: 50.0 ms.

Traceback (most recent call last):
File "DoorSystem.py", line 12, in <module>
print (MReader.read_register(289, 1)) # Remember to use print() for Python3
File "/usr/local/lib/python3.2/dist-packages/minimalmodbus.py", line 254, in read_register
return self._genericCommand(functioncode, registeraddress, numberOfDecimals=numberOfDecimals, signed=signed)
File "/usr/local/lib/python3.2/dist-packages/minimalmodbus.py", line 693, in _genericCommand
payloadFromSlave = self._performCommand(functioncode, payloadToSlave)
File "/usr/local/lib/python3.2/dist-packages/minimalmodbus.py", line 791, in _performCommand
response = self._communicate(message, number_of_bytes_to_read)
File "/usr/local/lib/python3.2/dist-packages/minimalmodbus.py", line 909, in _communicate
raise IOError('No communication with the instrument (no answer)')
IOError: No communication with the instrument (no answer)

Regards
D

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Wed Aug 12, 2015 6:13 pm

There is no signal returning. Try to increase the timeout for 0.2 sec.

Maybe the first thing to do will be to bypass the RS-485 and use the TTl serial port.

With only one reader near the Pi the RS-485 is not needed.

Use a resistor divider on the arduino TX and connect the arduino ttl serial to the raspberry pi internal serial pin 8 and 10 of P1.

Be sure that you disable the serial console using raspi-config.


I do have an arduino micro. I will explain how to do it but It could be next week. I'm away for fives days.

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Thu Aug 13, 2015 1:02 am

I put an Arduino micro to my breadboard and hook it up directly to the RPi Rx and Tx pin.

This is a full size picture of the setup.
Image

P.S. There is a 10K resistor behind the LED to reduce the Arduino TX to 3.3V.

This is a small python code to detect RFID cards .

Code: Select all

#!/usr/bin/python3
# -*- coding: utf-8 -*-
import numpy as nb;
import minimalmodbus
import time

CMD_REFUSE=1
CMD_ACCEPT=2

reader = minimalmodbus.Instrument('/dev/ttyAMA0',1)
reader.serial.baudrate=9600
reader.serial.timeout=0.2


def GetID(registers):
  value = nb.int64(0)
  for i in range(3):
    value = value * nb.int64(65536)
    value = value + nb.int64(registers[3-i])
  return value



while(True):

 #Read modules first 4 register
 #register0  Status  0=> no card   1=> card
 #register1  first and second byte
 #register2  third and fourth byte
 #register3  fifth byte in lsb

 holdingRegs = reader.read_registers(0,4,3);

 if (holdingRegs[0] & 1) == 1:
   #we got a valid keys
   # let's make int64 key id
   #print(holdingRegs)

   cardID = GetID(holdingRegs)
 
   print('Found CARD ID ' + hex(cardID),end=" ")
  
   isValid = input('Valid?(Y/N) and press enter ')

   if isValid == 'Y':
       #validate
       reader.write_register(4,CMD_ACCEPT)
   else:
       reader.write_register(4,CMD_REFUSE)
 time.sleep(0.1)
And I got it working fine.

Code: Select all

pi@PiB ~ $ python3 rfid.py
Found CARD ID 0xd1732e0488 Valid?(Y/N) and press enter N
Found CARD ID 0xde0658d555 Valid?(Y/N) and press enter Y
Found CARD ID 0xde0658d555 Valid?(Y/N) and press enter N
Found CARD ID 0xde0658d555 Valid?(Y/N) and press enter Y
Found CARD ID 0xde0658d555 Valid?(Y/N) and press enter N
Found CARD ID 0xde0658d555 Valid?(Y/N) and press enter N
Found CARD ID 0xd9065b51d5 Valid?(Y/N) and press enter Y
Last edited by danjperron on Sat Sep 29, 2018 2:52 pm, edited 2 times in total.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Thu Aug 13, 2015 7:43 am

I wondered if I had some sort of issue with my Arduino Nano so I swapped it for a Pro Mini last night but still couldn't get it running. There is data coming out of TX on the Arduino because I can see it on the scope (and I can see it on the serial monitor if if connect the usb but I cant get the link between the Arduino and the Pi up using the RS485 link hardware.
Tonight I will rig up the set up you have shown in your last post and see if I have any more luck. Thanks for bearing with me - I am probably doing something stupid but sometimes you can get so involved you don't spot obvious errors.
Your help (and obvious expertise) is much appreciated.
D

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Thu Aug 13, 2015 12:26 pm

Oops I misread your post. I tought you were using a arduino micro.

Well I'm leaving for vacation right now . I will post the same thing with an arduino pro mini.

The 'micro' use different pins for miso,mosi and sck. You have to use serial1 instead of serial.


With the pro mini use the schematic to connect the RC522 card.

Looks like a problem with the RS-485 switching.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Thu Aug 13, 2015 1:54 pm

Hi
Thanks for the help - hope your vacation is as good as mine was!

Regards
D

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 2:25 am

There is something I forget about the RC-522 is that is not 5V tolerant.

This is the setup for an arduino pro mini. In reality it is a chinese clone (funduino 5V).

Since it is 5V and it use a 16Mhz crystal. I put 1K/2K resistor divider to get the 3.3V SPI I/O.

The resistor dividers are on , MOSI,SCK,SDA,Reset and TX.

Image

It is possible to use an arduino pro mini at 3.3V but it is outside the speck and some won't work. 16Mhz is just too fast.

I do have some 3.3V arduino pro mini with 8Mhz crystal. I will put a setup picture tomorrow. This way everything is 3.3V and no resistor divider is needed.
Last edited by danjperron on Sat Sep 29, 2018 2:53 pm, edited 1 time in total.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 7:41 am

Hi, Due to work commitments I haven't been able to get back on this project over the weekend, I'm hoping to have a few minutes this evening. I was thinking about it though and I wondered, if the TX line from the Arduino is always busy I assume this will affect the comms protocol to the Pi as its a Master/Slave relationship. I noticed that if I put a scope on the TX line from the Arduino it is busy and this would tie up with the fact that, when I use the serial monitor in the Arduino IDE I see that it is streaming the status of the RC522. Is this correct? I thought that I would only see activity on the TX line when a card has been detected.
Regards
D

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 11:30 am

With a arduino mini, you can't have anything plug to the serial port except the Pi. The Rx pin will be tied to the Tx of the usb to serial adapter and will overide the serial communication. This is probably your main problem.

This is the same thing with the Uno. The Arduino micro has 2 port it is possible to debug with it.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 12:07 pm

Hi,
The usb serial port was only connected during debugging when I wanted to see why the TX pin was busy even though no card was present. When the Pi is connected to RX/TX the PC is disconnected - I think this is my problem however I don't understand why I have this problem and you do not - I must have done something different but don' see it at the moment.
D

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 12:20 pm

If you run the latest python3 script that I posted and it doesn't complain, it is working!

I'm stuck home . I got all my house's windows changed today, just waiting for the contractor, so I will made a setup exactly like the schematic and use my pic18F1240 on the Pi for the RS-485 switch. I think this what you are using.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 1:06 pm

Hi, Getting your windows changed doesn't seem like much of a holiday but then again, I was pointing a wall during my time in France so I guess we are all up to the same stuff, no matter where you are in the world!

I had a look at the RFID.cpp library and noticed that it is calling up a Serial.print to give status request , tag type etc. I think it might be worth commenting it out, what do you think?
D

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 9:09 pm

Ok I had time to check my github and I made a mistake.

The png image for rs-485 switches was not for the code in the Github.


This is the correct schema for the code.

Image

And this is the schematic for an arduino pro-mini at 3.3V. I use the build-in 3.3V regulator.

Image

This is the full setup using the RS-485 switch.

Image


N.B. If your arduino mini is 5V just use an external 3.3V regulator.
Last edited by danjperron on Sat Sep 29, 2018 2:57 pm, edited 1 time in total.

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 9:20 pm

Hi, Just managed to get on it for 5 minutes before I go to bed and....Eureka, it works!!
For me the problem was the RFID.cpp file. There are 3 Serial.print lines that need to be commented out or they use the serial port which is bridged to the RX/TX line. I simply commented these lines out, saved the file and recompiled it and I am up and running.
Thanks for all the help - your project really helped me get up and running with 3 areas I know nothing about, the RFID (although I had got this running on Arduino before, not in conjunction with the Pi), MySql and Modbus. I really learnt a huge amount in a short time because of your knowledge. I now want to add time stamps on the mysql base to log date and time when a certain card is swiped so I'm off to have a go at that.

All the best from the UK.
David

danjperron
Posts: 3974
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: 3 RC-522 on 1 Raspberry ?

Mon Aug 17, 2015 11:37 pm

I maybe disabled the print in the early stage and forgot about it. Since the library was already changed I didn't have that problem.


I will update the RS-485 switch schematic on the github.

I whish you good luck with your project. ;-)

Daniel

djdixon
Posts: 15
Joined: Mon Jul 27, 2015 9:16 pm

Re: 3 RC-522 on 1 Raspberry ?

Tue Feb 23, 2016 9:25 pm

Hi Daniel,
Hope you are well. I managed to modify your code to give me an attendance log with a time & Date stamp, thank you. I've a little more time to work on this now and I would like to add an extra column or two to the "cards" table which has a serial number (alpha-numeric" which I can then also display when the card is swiped. I've tried a variety of ways to achieve this but without success (a number only doesn't seem such a big problem but adding a letter throws out errors) can you point me in the right direction. Ideally I would like to possible attach multiple cards to single user (this I can do) but have each card linked to a unique alpha numeric number stored in one of the other columns) The mysql side is straightforward enough but linking it to the python code gives me problems.
Any guidance is as always, much appreciated.
Regards
David

Return to “Automation, sensing and robotics”