jm rfid demo
in Propeller 1
Hi, im not clear on how to set up the display with this object and what to do with pins 28 through 31. Does full duplex serial need to be used through an lcd display, or is it something on the computer like the p.s.t.? Also is there something i need to set up for i2c or is that taken care of through com lines built in. Im using the professional dev. board. For the enable on the rfid reader and serial out i have 3.9k resistor to deal with the 5v and 3.3 volt difference. Thanks for the help!
'' =================================================================================================
''
'' File....... jm_rfid_demo__2015.spin
'' Purpose.... Identifies RFID tags while displaying a running timer
'' Author..... Jon "JonnyMac" McPhalen
'' Copyright (c) 2015 Jon McPhalen
'' -- see below for terms of use
'' E-mail..... jon@jonmcphalen.com
'' Started....
'' Updated.... 13 APR 2015
''
'' =================================================================================================
con { timing }
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000 ' use 5MHz crystal
CLK_FREQ = (_clkmode >> 6) * _xinfreq ' system freq as a constant
MS_001 = CLK_FREQ / 1_000 ' ticks in 1ms
US_001 = CLK_FREQ / 1_000_000 ' ticks in 1us
DISPLAY_MS = 4_000
con { io pins }
RX1 = 31 ' programming / terminal
TX1 = 30
SDA = 29 ' eeprom / i2c
SCL = 28
RFID_RX = 17 ' RFID on PAB
RFID_EN = 16
obj
io : "jm_io" ' basic io control
time : "jm_time" ' timing and delays
rfid : "jm_rfid" ' * RFID input
term : "jm_fullduplexserial" ' * serial io for terminal
str : "jm_strings" ' string methods
var
long showtag ' true when data data displayed
dat
lastsecs long -1 ' for clock updates
timestr byte "00:00:00", 0
pub main
setup ' start program objects
term.tx(term#CLS)
repeat
show_clock(0, 0) ' show running clock
check_tag
pub show_clock(x, y) | s, m, h
s := time.seconds ' get seconds from timer
if (s == lastsecs)
return
lastsecs := s ' save for next check
h := (s / 3600) // 24 ' extract hours (keep 0..23)
m := (s // 3600) / 60 ' extract minutes
s //= 60 ' extract seconds
timestr[0] := h / 10 + "0" ' format time
timestr[1] := h // 10 + "0"
timestr[3] := m / 10 + "0"
timestr[4] := m // 10 + "0"
timestr[6] := s / 10 + "0"
timestr[7] := s // 10 + "0"
cursor_xy(x, y) ' move cursor
term.str(@timestr) ' print time
pub cursor_xy(x, y)
term.tx(term#GOTOXY)
term.tx(x)
term.tx(y)
pub check_tag | state, tidx, t1
state := rfid.check ' check on rfid tage
ifnot (showtag) ' if no tag showing
if (state == rfid#READY) ' has tag been presented?
tidx := rfid.tag_index(@Tags, LAST_TAG) ' validate the tag
if (tidx => 0) ' if valid
display_tag(tidx) ' show the tag info
showtag := true ' enable timing of display
time.start ' restart timer (optional)
t1 := time.millis ' mark display sync point
lastsecs := -1
else
rfid.enable ' re-enable after unknown tag
else
if ((time.millis - t1) => DISPLAY_MS) ' time to clear last tag?
clear_tag ' clear previous tag info
showtag := false ' mark cleared
rfid.enable ' re-enable rfid
pub display_tag(tidx)
'' Displays tag information if tidx in valid range
if ((tidx < 0) or (tidx > LAST_TAG))
return
cursor_xy(0, 2)
term.str(string("Tag.... "))
term.str(rfid.address)
term.tx(term#CR)
term.str(string("ID..... "))
term.dec(tidx)
term.tx(term#CR)
term.str(string("Name... "))
term.str(str.pntr(tidx, @Names))
term.tx(term#CR)
pub clear_tag
'' Clears onscreen tag information
cursor_xy(0, 2)
term.tx(term#CLRDN) ' clear screen from here
showtag := false
pub setup
'' Setup IO and objects for application
time.start ' start/sync time
rfid.start(RFID_EN, RFID_RX) ' start RFID
term.start(RX1, TX1, %0000, 115_200) ' terminal via programming port
dat { tags data }
Tags
Tag0 byte "0415148F26", 0
Tag1 byte "0415148E0C", 0
Tag2 byte "041514AEA3", 0
Tag3 byte "041514A076", 0
Tag4 byte "04129C1B43", 0
LAST_TAG byte 4
Names
Name0 byte "Luke Skywalker", 0
Name1 byte "Princess Leia", 0
Name2 byte "Darth Vader", 0
Name3 byte "Obi Wan Kenobi", 0
Name4 byte "Yoda", 0
dat { license }
{{
Terms of Use: MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this
software and associated documentation files (the "Software"), to deal in the Software
without restriction, including without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies
or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
There is no setup needed beyond what is already done in the program. The enable is an output from the propeller and an input on the rfid so it does not need a resistor, but the serial output from the rfid is an input to the propeller and does require the resistor.
Post (or link) the code which is working well. I'll see if I can modify to display the ID numbers of unrecognized tags.
Edit: Is this the code you're using? I'll see if I can modify it to display unrecognized ID numbers.
'' 'Thanks Duane ================================================================================================= '' '' File....... jm_rfid_demo.spin '' Purpose.... Parallax Serial RFID Reader demo for the Propeller Activity Board. ' '' Use pins 16 and 17 as they have 3.9K resistors inline to prevent too much current '' into the pins from the 5V RFID device. Make sure that the header power jumpers are '' set to 5V (default), and to move the power switch to position 2 to power the headers. '' Author..... Jon "JonnyMac" McPhalen '' Copyright (c) 2014 Jon McPhalen '' -- see below for terms of use '' E-mail..... jon@jonmcphalen.com '' Started.... 23 SEP 2014 '' Updated.... 03 OCT 2014 '' '' ================================================================================================= con { timing } _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 ' use 5MHz crystal CLK_FREQ = ((_clkmode - xtal1) >> 6) * _xinfreq ' system freq as a constant MS_001 = CLK_FREQ / 1_000 ' ticks in 1ms US_001 = CLK_FREQ / 1_000_000 ' ticks in 1us con { io pins } RX1 = 31 ' programming / terminal TX1 = 30 SDA = 29 ' eeprom / i2c SCL = 28 RFID_RX = 17 ' RFID on PAB RFID_EN = 16 con #0, LSBFIRST, MSBFIRST con { pst formatting } #1, HOME, GOTOXY, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR #14, GOTOX, GOTOY, CLS obj term : "fullduplexserial" rfid : "fullduplexserial" var pub main | idx setup ' start program objects repeat repeat 2 term.tx(CR) term.str(string("Present tag:", CR)) accept_tag(@tagbuf) ' wait for tag term.str(string("-- ")) ' display tag string repeat idx from 0 to 9 term.tx(byte[@tagbuf][idx]) term.tx(CR) idx := get_tag_id(@tagbuf) ' lookup tag if (idx => 0) ' display name for tag term.str(string("-- ")) term.str(@@Names[idx]) else term.str(string("-- Unknown tag")) pause(3000) pub setup '' Setup IO and objects for application term.start(RX1, TX1, %0000, 115_200) ' terminal via programming port rfid.start(RFID_RX, RFID_RX, %1100, 2400) ' open-drain serial for RFID con { --------- } { R F I D } { --------- } con LAST_TAG = 3 ' tag #s are 0..LAST_TAG var byte tagbuf[10] ' tag buffer pub accept_tag(p_buf) | c, idx '' Enables RFID reader for ms milliseconds '' -- reads tag bytes (if available) into p_buf bytefill(p_buf, 0, 10) ' clear old data rfid.rxflush ' clear rx buffer low(RFID_EN) ' enable reader repeat c := rfid.rx until (c == $0A) ' wait for $0A (LF) repeat 10 ' rx 10 tag bytes byte[p_buf++] := rfid.rx input(RFID_EN) ' disable reader pub get_tag_id(p_buf) | tidx, p_check, bidx '' Compares tag data in ram (at p_buf) with known tags '' -- returns tag index (0..LAST_TAG) if found '' -- returns -1 if tag not found repeat tidx from 0 to LAST_TAG ' loop through known tags p_check := @@Tags[tidx] ' get hub address of tag being tested repeat bidx from 0 to 9 ' loop through bytes in tag if (byte[p_buf][bidx] <> byte[p_check][bidx]) ' if byte mismatch quit ' abort this tag if (bidx == 10) ' if all bytes matched return tidx ' return this tag id return -1 ' return not found dat { tags data } Tag0 byte "0415148F26" Tag1 byte "0415148E0C" Tag2 byte "041514AEA3" Tag3 byte "041514A076" Tags word @Tag0, @Tag1, @Tag2, @Tag3 Name0 byte "Luke Skywalker", 0 Name1 byte "Princess Leia", 0 Name2 byte "Darth Vader", 0 Name3 byte "Obi Wan Kenobi", 0 Names word @Name0, @Name1, @Name2, @Name3 con { ------------- } { B A S I C S } { ------------- } pub pause(ms) | t '' Delay program in milliseconds if (ms < 1) ' delay must be > 0 return else t := cnt - 1776 ' sync with system counter repeat ms ' run delay waitcnt(t += MS_001) pub high(pin) '' Makes pin output and high outa[pin] := 1 dira[pin] := 1 pub low(pin) '' Makes pin output and low outa[pin] := 0 dira[pin] := 1 pub toggle(pin) '' Toggles pin state !outa[pin] dira[pin] := 1 pub input(pin) '' Makes pin input and returns current state dira[pin] := 0 return ina[pin] dat { license } {{ Terms of Use: MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. }}I used the code attached to the posted I linked to earlier. I've attached the modified version with the name "rfid_demo160910a".
The code you embedded above looks like it displays the number of the card or the tag already?
Do you not see this information?
I modified the code you just posted to include an extra display of the serial number of the card just read but I doubt it will make much of a difference to you. This second program is named "rfid_demo2_160910a"
I've read posts from JonnyMac where he stated his wish for modified code not to include the prefix "jm". I made minor changes but I still removed the "jm" prefix as JonnyMac has asked.
Let me know if the attached code works okay. It compiles but I haven't tested it with an RFID reader. I don't have a Parallax RFID reader.
Are you sure all the tags and cards you have are intended to be used with the Parallax reader?
rfid_demo160910a i cant get to compile. Even though the sub folder objects are open it will show error message that the objects are not in the library or open folder. I've tried saving the objects also.
Having objects open wont allow the top object to find them. This is an error in the Propeller Tool's instructions. You need to have the child objects either in the same folder as the top object of the child objects have to be in the Propeller Tool's library folder.
I've attached an archive of "rfid_demo160910a".
I don't know what would cause the other problems you're describing.
, but no tag i.d. . I found a couple programs and tried it with bs2 and having the same issue. one bs2 is specifically for showing the id, but it wont read at all. The other bs2 code says id is unidentified, but it will acknowledge its been read. i wonder if there's a problem with the cards/fob, and if its possible to buy some that show their id's?
I've only used the inexpensive MRFC522 RFID readers like those found on ebay. These readers use 13.56MHz cards and tags which are also very inexpensive.
I've posted Propeller code in this thread which will read the serial numbers from the 13.56MHz cards and tags.
I think I was able to write data to the cards and read data from the card but I don't think I got all the password features working correctly with the Propeller.
I don't know enough about RFID to know how these cheap cards and readers compare with the Parallax reader but I thought the cheap reader worked well.
I tend to write product demos that run via PST so that there is nothing else to connect. This is not a full-blown app, it's a demo so that you can learn to integrate the Parallax RFID reader into your own projects.
As others have pointed out, there is nothing to do with pins 28..31. I put them into the listing as a reminder that they do serve a purpose and should not be used in your app without careful consideration.
Pin 1 - P0 - rx1, data in from the rfid (needs 3.9 - 10K current limiting resistor)
Pin 2 - P1 - tx1, data out from propeller - not used
Pin 3 - P2 - rfid enable - enables rfid reader when low
I tend to use the four port serial object with port 0 for debugging with pst and the rest as comms for whatever else I need.