rfid2ln & rfid2wifi interfaces

Moderator: Moderators

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 25.12.2015, 09:47

Hello Gerard,

yes, you have right, but I've just put together some existing libraries. I should/I will look deeper in the Loconet library next days.
I also have some own Loconet modules and they are working good enough for me (I had 4 or 5 working on my layout), but they are not totally conform to the Loconet specification. My first idea was to extend my existing project with the rfid reader; the software part is already implemented (or more exactly it compiles, but nothing is tested).
To test the rfid module I used an Arduino (laying around) + the MFFR522 library; it was easy to just put the Loconet library on top of the mfrc522 one to have an working rfid2ln module to make some tests.
And because the Loconet library is "approved", and because is easier for others to start with Arduinos than to start with a "bare" PICs, I've just "released" it, but (as always mentioned it) without testing it to much (I haven't had enough hardware to do it, but the situation is changing).
My only part in the rfid2ln project are the xfer decoding function (the existing function is somehow restricting the messages), and the check-sum calculation one. All other Loconet functions are the library's ones. And because some time ago, on the Loconet-Hakers group (on yahoo), I've read a discussion about "to identical" boards, and because Alex Shepherd is an active member of the group, I was supposing that it has implemented some methods to avoid this problem. Maybe he has and I should just find it out. Or maybe not, and than I should find a method to implement myself something. Or maybe I should just contact Alex and ask him...

Regards,
Liviu
Last edited by Liviu M on 11.01.2016, 10:42, edited 1 time in total.
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 26.12.2015, 16:48

Hello Gerard, hello Vik,
Today I've finished my second board and made some changes in the program. In my tests (with the two boards I have) I had no problems querying the boards addresses or changing the boards & sensors addresses.
If you like to test the new version, you find it on git, as usual.

Regards,
Liviu

PS Only the single version is corrected at the moment.
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 11.01.2016, 10:47

Hello all,
Liviu M wrote:PS Only the single version is corrected at the moment.

I've updated the multi version also.

Best regards,
Liviu
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 03.02.2016, 20:16

Hello all,

today I had some successful test using interrupts.
Because (I think) the tag needs an "activation" command, the Arduino should send periodically commands to the reader, but reading the UID can be done triggered by an IRQ event.
For the braves :mrgreen: wanting to test the new "communication flow", the code has it's own branch - rfid2ln_int. Only the single version is in the moment changed, because I need to change my hardware adapter.

Attention should be paid to the pins. A new pin (IRQ_PIN) should be connected. This pin should have interrupt capabilities. The pins are listed on the arduino.cc:
Code: Select all
Board   Digital Pins Usable For Interrupts
Uno, Nano, Mini, other 328-based          2, 3
Mega, Mega2560, MegaADK                   2, 3, 18, 19, 20, 21
Micro, Leonardo, other 32u4-based         0, 1, 2, 3, 7
Zero, MKR1000   all digital pins, except  4
Due   all digital pins


Enjoy,
Liviu
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 06.02.2016, 12:44

Hello all,

These days I've arrived to a stand in which the rfid2ln readers can be used as "normal" sensors also.
That means:
- the board sends the UID-Message only once per read (if the tag stays on the reader, the UID is sent only once). The message can be used both, as identification code and as a "sensor active" for the feedback system.
- the board sens a "sensor free" message when the tag leaves the reader for the feedback system.

Nice week-end,
Liviu
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 07.02.2016, 15:08

Hi,
today I've mixed in one program all the goodies:
- single-reader or multi-reader
- polling or interrupt based reader detection
As usual, the last version is on the github.

The future plans - to implement the Gerard & Peter *) idea of duplicating other functionality of the LocoIO. I suppose that extending the RFID inputs with some "normal" inputs will be quite straightforward. More complicated will be with the outputs.

Regards,
Liviu

*) Later edit: Gerard, Peter, if you had some success implementing new functionality, it will be nice to share it.
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby KinnieDhar » 28.03.2016, 18:07

As per my setup the two RFID readers are still working, they read the tags of trains and wagons simultaneously and the Arduino sends the data to Rocrail.
Only sometimes the reading is not reliable and then I miss some figures.
I have the feeling that this has nothing to do with the software but more with the communication between the RFID reader and the tags.
KinnieDhar
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 28.03.2016, 19:04

Hi,
can be, unfortunately I can't really test it, I don't have any functional layout for real test (and I've bricked one reader).
But if you find anything new, I'll be glad to hear it. :)

Regards,
Liviu
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby vikr » 05.04.2016, 18:45

Hi KinnieDhar,
KinnieDhar wrote:Only sometimes the reading is not reliable and then I miss some figures.
Can you please tell a little bit more, what is your infrastructur and in which situations the reading is not reliable?
What did you find in the RR-logs? Nothing? or a wrong ID?
KinnieDhar wrote:I have the feeling that this has nothing to do with the software but more with the communication between the RFID reader and the tags.
May be you could reduce the Reader-TAG-Distance for a test.
regards

vik
vikr
 

Re: rfid2ln & rfid2wifi interfaces

Postby Dagnall » 06.09.2016, 18:48

Hi,
I have been working in my version of the RFID reader , which uses a single RFID reader on the Engine and RFID tags on the track to work as block sensors.
My ESP8266 works as a sort of Command Station and accepts Loconet commands over UDP that allows the ESP8266 to control a servo output that then drives the wheels etc.
The code uses CV values that can be set and read using the Programming tag. Each ESP8266 has a LOCO id set in CV's and responds as you woud expect.

I will be starting a new post about this, but the reason for adding to this topic is that whilst trying to get my code to work more reliably, I discovered that the MRFC code I used from the GIThub , specifically MFRC522.cpp, uses a fixed serial speed, set by a variable "SPI_CLOCK_DIV_4", which for an ESP8266 is not working exactly as I think the coders intended. To set the SPI clock speed you want, you may need to modify the code.
I changed the variable name and set the variable to the actual frequency I wanted, (1MHz), and the code works fine, and I have been experimenting to try and get the code running as fast as possible. I will leave some reference code atthe bottom to show exactly what I mean.
With my SPI clock running at a speed I could control, I did a lot of timings with my version of Livius' RFID code and found that the main RFID reading code takes about 25ms to complete with 160Mhz or 80Mhz ESP and 1Mhz SPI. Very interestingly, the code timing is not directly SPI related, and increasing the clock to 5MHz SPI only reduces the loop to abut 21 ms..

With a 25-21ms loop time , a fast engine may well pass the reader before the tag can be read.....This might be your problem?

It would be good if we can find where the main delays are in the RFID reading loops to make it quicker..

My version of Liviu's read code to check for tags and send messages if they are found is shown below:
If I find a tag, I send a UDP message (using SENDUID). In the main loop, I then do not repeat this read unless the time is greater than "RFIDCycle", if the last tag was not reset, I send a reset message for the old tag.
This code takes about 21ms to complete. I would very much like to know where the delays in the code actually are!.
I have left in some of the serial prints I used during debug..
Code: Select all
void checkRFID(){
    if(bReaderActive){
        if ( mfrc522.PICC_IsNewCardPresent()&& mfrc522.PICC_ReadCardSerial()){
        //  Serial.println("Newcard and Piccreadserial line 107");
               if(!compareUid( mfrc522.uid.uidByte, oldUid, mfrc522.uid.size)){// NEW  (NOT same UID)
                          SendUID(oldUid,0,2);   //clear old uid
                          SendUID(mfrc522.uid.uidByte,1,1);
                          RFIDCycle=millis()+2000;   // switched on, so do'nt do any more reading for 2 secs..
                          copyUid(mfrc522.uid.uidByte, oldUid, mfrc522.uid.size); //save in oldUID
                          uiStartTime = millis()+2000;     
                          bRFIDquiet=false;
                    //    Serial.println("Found new card..line116");
                                                                              }//  end NOT same UID same
                                else{//is the same card still...
                   //                    Serial.println("Same card..line119");
                                      uiStartTime = millis()+2000;
                                      RFIDCycle=millis()+2000;  //update time card was seen
                                      }                                              //same card end..
                   } else { //  nothing read..

                             if((!bRFIDquiet)& (millis()>= uiStartTime + uiDelayTime)){
                  //           Serial.println("Nothing read for a while .line 126"); // wait delay before declaring the card gone
                                 SendUID(oldUid,0,3);
                                 bRFIDquiet=true; } //if((uiActTime
                                                                                             }// nothing read 
                                 
                                                                               
                                                                               
 }//ifmrfc
}




How fast is your main "RFID tag read" ??

Cheers
Dagnall












DETAILS about MRFC522,
MRFC522 SPI clock is "hard" set to use SPI_CLOCK_DIV4 to set the SPI clock frequency.......
Example
Code: Select all
void MFRC522::PCD_WriteRegister(   byte reg,      ///< The register to write to. One of the PCD_Register enums.
                           byte value      ///< The value to write.
                        ) {
   SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0));   // Set the settings to work with SPI bus
   digitalWrite(_chipSelectPin, LOW);      // Select slave
   SPI.transfer(reg & 0x7E);            // MSB == 0 is for writing. LSB is not used in address. Datasheet section 8.1.2.3.
   SPI.transfer(value);
   digitalWrite(_chipSelectPin, HIGH);      // Release slave again
   SPI.endTransaction(); // Stop using the SPI bus

But SPI_CLOCK_DIV4 is seems to be used differently in the ESP8266 version where SPI.h defines it thus....
Code: Select all
// This defines are not representing the real Divider of the ESP8266
// the Defines match to an AVR Arduino on 16MHz for better compatibility
#define SPI_CLOCK_DIV2       0x00101001 //8 MHz
#define SPI_CLOCK_DIV4       0x00241001 //4 MHz
#define SPI_CLOCK_DIV8       0x004c1001 //2 MHz
#define SPI_CLOCK_DIV16    0x009c1001 //1 MHz
#define SPI_CLOCK_DIV32    0x013c1001 //500 KHz
#define SPI_CLOCK_DIV64    0x027c1001 //250 KHz
#define SPI_CLOCK_DIV128    0x04fc1001 //125 KHz
Dagnall
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 06.09.2016, 19:50

Hi Dagnall,

interesting info in your last posts, thanks.
I've also seen that the SPI speed as implemented in the MFRC522 library (or the SPI library itself ?) doesn't work as expected, but had no needs to change it. You can try to make a pull request on the MFRC522 repo with your version, in my case it was working (the multi-reader implementation is my contribution).
Regarding the "waste time", i suppose the most part is spent in the IsNewCardPresent() function. I was looking through it and found it quite complicated. For that reason I was recommended you to try the interrupt version.

Cheers,
Liviu
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby vikr » 06.09.2016, 22:57

Hallo Dagnall,
rather interessing, thanks for your explanations...
Dagnall wrote:How fast is your main "RFID tag read" ??

It needs starting with the Request about 25ms to detect a TAG, means to find out the complete UID (if there is only one TAG in the field; using NFC according ISO 14443).

Regards,

vik
vikr
 

Re: rfid2ln & rfid2wifi interfaces

Postby Dagnall » 08.09.2016, 10:16

Livu, vik,
[quote You can try to make a pull request on the MFRC522 repo with your version, ][/quote]
I had a quick look and someone else has already offered a similar solution.. I am not familiar enough with the Github to add anything other than a comment, which I have now done..


Re:
most part is spent in the IsNewCardPresent() function
, I will see if I can follow this code through, and will let you know what I find..
I still have the option of using your interrupt version, but right now, my code does seem to be working ok.
I ran it as a reversing train on a short track for about two hours. My test tram is not fast, so the 25ms RFID read speed is adequate for this application. For faster trains it may not be fast enough..
With the reader just above the track, and the top of the tag at about track height, have measured a static a "longitudinal" range of about 35mm along the track where the reader can read the tag. I calculate that this translates to circa 1.2 M/s maximum train speed before tags can be missed.

I plan to now put the "lessons learned" back into the "static" version of the code and then actually use it in the garden...
I had not planned to use the RFIDreader in the static version, but just use switches, reed relays or current sensors for block detectors...
Dagnall
 

Re: rfid2ln & rfid2wifi interfaces

Postby Liviu M » 08.09.2016, 14:08

Hi Dagnall,

Dagnall wrote:Hi,
and found that the main RFID reading code takes about 25ms to complete

How are you measuring the time? Do you toggle a pin and watch the signals with an oscilloscope?

Cheers,
Liviu
----------------------------------------------
System: DCC N-Scale
CS: Profiboss (Loconet)
Server: RaspberryPi/OdroidC1/OpenSuse
Client: OpenSuse/Windows(?)
----------------------------------------------
Liviu M
 

Re: rfid2ln & rfid2wifi interfaces

Postby Dagnall » 08.09.2016, 16:46

Liviu M wrote:How are you measuring the time? Do you toggle a pin and watch the signals with an oscilloscope?


I have done that, but mainly I set start=micros() reading at the start of the loop, and a "serial.print (micros()-start)" where I want to see the time..
Its slightly tedious as it can fill the monitor, but does seem to work.
I have RFID only reading (and printing this line) when speed >0, so if I "stop" the motor it stops filling up the screen... Crude but effective...
Dagnall
 

PreviousNext

Return to DIY Hardware