{"id":1897,"date":"2019-12-18T18:28:27","date_gmt":"2019-12-18T10:28:27","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=1897"},"modified":"2020-12-12T22:50:02","modified_gmt":"2020-12-12T14:50:02","slug":"how-to-use-an-esp32-development-board-to-read-rfid-tags-from-a-sparkfun-rfid-usb-reader","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-to-use-an-esp32-development-board-to-read-rfid-tags-from-a-sparkfun-rfid-usb-reader\/","title":{"rendered":"How to use an ESP32 development board to read RFID tags from a SparkFun RFID USB Reader"},"content":{"rendered":"<p>When you have an <a href=\"https:\/\/www.amazon.com\/RFID-Starter-Kit-by-Sparkfun\/dp\/B00EPH81RS\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=c00e2320920331b717ec75ae7f108340&language=en_US\" rel=\"noopener\" target=\"_blank\">RFID starter kit from Sparkfun<\/a>, you will be able to read RFID tags through a serial connection.<\/p>\n<p>Although the SparkFun RFID USB Reader comes with a USB port, you can also read RFID tags with an <a href=\"https:\/\/www.amazon.com\/s\/ref=as_li_ss_tl?k=ESP32+development+board&ref=nb_sb_noss&linkCode=ll2&tag=clivsperswebs-20&linkId=039dbb02b543a7a0fe7268f0a97bd03e&language=en_US\" rel=\"noopener\" target=\"_blank\">ESP32 development board<\/a>. <\/p>\n<p>In case you need it, this is how to use an ESP32 development board to read RFID tags from a SparkFun RFID USB Reader.<\/p>\n<p><img decoding=\"async\" width=\"456\" height=\"330\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/SparkFun-RFID-USB-Reader.jpg\" alt=\"SparkFun RFID USB Reader\" class=\"aligncenter size-full wp-image-1898\" \/><\/p>\n<h2>Solder GPIO header pins onto the SparkFun RFID USB Reader<\/h2>\n<p>First, solder some <a href=\"https:\/\/www.amazon.com\/LUOXINMAO-2-54mm-Straight-Single-W1-40pin\/dp\/B07RND4XLX\/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=clivsperswebs-20&linkId=8fff6285ca46f3fea40b40a68a804204&language=en_US\" rel=\"noopener\" target=\"_blank\">GPIO header pins<\/a> onto the SparkFun RFID USB Reader: <img decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/SparkFun-RFID-USB-Reader-with-GPIO-headers.jpg\" alt=\"SparkFun RFID USB Reader with GPIO headers\" class=\"aligncenter size-full wp-image-1899\" \/><\/p>\n<h2>Connecting the SparkFun RFID USB Reader to your ESP32 development board<\/h2>\n<p>Once you had soldered the GPIO pins to your SparkFun RFID USB Reader, connect it with your ESP32 development board:<br \/>\n<img decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Underside-of-Espressif-ESP32-devkit-v4-with-GPIO-wires-connected-to-GND-3v3-GPIO16-and-GPIO17-pins.jpg\" alt=\"Underside of Espressif ESP32 devkit v4 with GPIO wires connected to GND 3v3 GPIO16 and GPIO17 pins\" class=\"aligncenter size-full wp-image-1902\" \/><br \/>\n<img decoding=\"async\" width=\"800\" height=\"600\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/GPIO-wires-connected-to-VCC-GND-TX-and-TXR-pins-of-SparkFun-RFID-USB-Reader.jpg\" alt=\"GPIO wires connected to VCC GND TX and TXR pins of SparkFun RFID USB Reader\" class=\"aligncenter size-full wp-image-1903\" \/><\/p>\n<p>As shown above, I had connected:<\/p>\n<ul>\n<li><strong>3v3<\/strong> pin on ESP32 board to <strong>VCC<\/strong> pin on SparkFun RFID reader<\/li>\n<li><strong>GND<\/strong> pin on ESP32 board to <strong>GND<\/strong> pin on SparkFun RFID reader<\/li>\n<li><strong>GPIO16<\/strong> pin on ESP32 board to <strong>TX<\/strong> pin on SparkFun RFID reader<\/li>\n<li><strong>GPIO17<\/strong> pin on ESP32 board to <strong>TXR<\/strong> pin on SparkFun RFID reader<\/li>\n<\/ul>\n<h2>Writing an Arduino Sketch to read RFID tags with SparkFun RFID USB reader connected to ESP32 board<\/h2>\n<p>After you have connected your ESP32 board to the RFID reader, you can write the software to read RFID tags.<\/p>\n<p>If you <a href=\"https:\/\/www.techcoil.com\/blog\/enabling-esp32-development-on-arduino-ide\/\" rel=\"noopener\" target=\"_blank\">enable ESP32 Development on Arduino IDE<\/a>, then you can upload an Arduino Sketch to your ESP32 board to read RFID tags.<\/p>\n<h3>Installing the Arduino libraries to read from the SparkFun RFID USB reader<\/h3>\n<p>First, let's install the Arduino libraries to help us read from the SparkFun RFID USB reader.<\/p>\n<p>In order to do so, go to <strong>Tools -> Manage Libraries...<\/strong>. After you had done so, the Library Manager window will appear. First search for <strong>SoftwareSerial esp32<\/strong> and install the <a href=\"https:\/\/github.com\/plerup\/espsoftwareserial\/\" rel=\"noopener\" target=\"_blank\">EspSoftwareSerial library<\/a>:<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Searching-for-SoftwareSerial-esp32-in-Arduino-IDE-1.8.7-libary-manager.gif\" alt=\"Searching for SoftwareSerial esp32 in Arduino IDE 1.8.7 libary manager\" class=\"aligncenter size-full wp-image-1904\" \/><\/p>\n<p>Next, search for <strong>SerialRFID<\/strong> and install the <a href=\"https:\/\/github.com\/agmangas\/SerialRFID\" rel=\"noopener\" target=\"_blank\">SerialRFID<\/a> library:<br \/>\n<img decoding=\"async\" width=\"800\" height=\"450\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Searching-for-SerialRFID-in-Arduino-IDE-1.8.7-libary-manager.gif\" alt=\"Searching for SerialRFID in Arduino IDE 1.8.7 libary manager\" class=\"aligncenter size-full wp-image-1906\" \/><\/p>\n<h3>Arduino sketch to read RFID tags with ESP32 board and SparkFun RFID USB reader<\/h3>\n<p>After you have installed the Arduino libraries, you can upload an Arduino sketch to read the RFID tags.<\/p>\n<p>Given that, let us look at an adaptation of the <a href=\"https:\/\/github.com\/agmangas\/SerialRFID\/blob\/master\/examples\/serialrfid\/serialrfid.ino\" rel=\"noopener\" target=\"_blank\">example code provided by SerialRFID's author<\/a>:<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;SoftwareSerial.h&gt;\r\n#include &lt;SerialRFID.h&gt;\r\n\r\nconst byte RX_PIN = 16;\r\nconst byte TX_PIN = 17;\r\n\r\nSoftwareSerial sSerial(RX_PIN, TX_PIN);\r\nSerialRFID rfid(sSerial);\r\n\r\nchar tag&#x5B;SIZE_TAG_ID];\r\nchar matchTag&#x5B;SIZE_TAG_ID] = &quot;041A4A48E9F5&quot;;\r\n\r\nvoid setup()\r\n{\r\n  Serial.begin(9600);\r\n  sSerial.begin(9600);\r\n\r\n  Serial.println(&quot;&gt;&gt; Starting SerialRFID example program&quot;);\r\n}\r\n\r\nvoid loop()\r\n{\r\n  if (rfid.readTag(tag, sizeof(tag)))\r\n  {\r\n    Serial.print(&quot;Tag: &quot;);\r\n    Serial.print(tag);\r\n\r\n    if (SerialRFID::isEqualTag(tag, matchTag))\r\n    {\r\n      Serial.println(&quot; \/ Match: OK&quot;);\r\n    }\r\n    else\r\n    {\r\n      Serial.println(&quot; \/ Match: No&quot;);\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>So what is the above code doing? <\/p>\n<p>First, we include the <code>SoftwareSerial<\/code> and <code>SerialRFID<\/code> libraries into the sketch.<\/p>\n<p>After that, we initialized an instance of <code>SoftwareSerial<\/code> and <code>SerialRFID<\/code> to help us read the RFID tags.<\/p>\n<h4>What is the code doing inside the <code>setup<\/code> function<\/h4>\n<p>Next, in the <code>setup<\/code> function, we set a baud rate of 9600 for two serial ports that we are using. After that, we send an indication to the board's serial port that the setup function had been ran.<\/p>\n<h4>What is the code doing inside the <code>loop<\/code> function<\/h4>\n<p>Once we had setup the facilities to read RFID tags, we can attempt to read the RFID tags. Whenever the <code>loop<\/code> function is called, we call <code>rfid.readTag<\/code> to attempt to read an RFID tag presented to the reader. If there is one, we then print out the tag id.<\/p>\n<p>After that, we try to match the tag id with a hard coded value. If the tag id matches the tag id from <code>matchTag<\/code>, then we output <strong>\" \/ Match: OK\"<\/strong> to the board's serial. However, if both the tag ids do not match, we output <strong>\" \/ Match: No\"<\/strong> to the board's serial.<\/p>\n<h4>Sample output of the sketch<\/h4>\n<p>When I run the sketch on my ESP32 development board, I got the following output:<\/p>\n<p><img decoding=\"async\" width=\"800\" height=\"446\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/Sample-output-of-using-SerialRFID-example-program-to-read-RFID-tags-from-SparkFun-USB-RFID-reader.gif\" alt=\"Sample output of using SerialRFID example program to read RFID tags from SparkFun USB RFID reader\" class=\"aligncenter size-full wp-image-1907\" \/><\/p>\n<p><img decoding=\"async\" width=\"600\" height=\"900\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/How-to-use-an-ESP32-development-board-to-read-RFID-tags-from-a-SparkFun-RFID-USB-Reader.jpg\" alt=\"How to use an ESP32 development board to read RFID tags from a SparkFun RFID USB Reader\" class=\"aligncenter size-full wp-image-1944\" \/><\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-uB\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-uB&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-uB&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F1897&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>When you have an <a href=\"https:\/\/www.amazon.com\/RFID-Starter-Kit-by-Sparkfun\/dp\/B00EPH81RS\/ref=as_li_ss_tl?ie=UTF8&#038;linkCode=ll1&#038;tag=clivsperswebs-20&#038;linkId=c00e2320920331b717ec75ae7f108340&#038;language=en_US\" rel=\"noopener\" target=\"_blank\">RFID starter kit from Sparkfun<\/a>, you will be able to read RFID tags through a serial connection.<\/p>\n<p>Although the SparkFun RFID USB Reader comes with a USB port, you can also read RFID tags with an <a href=\"https:\/\/www.amazon.com\/s\/ref=as_li_ss_tl?k=ESP32+development+board&#038;ref=nb_sb_noss&#038;linkCode=ll2&#038;tag=clivsperswebs-20&#038;linkId=039dbb02b543a7a0fe7268f0a97bd03e&#038;language=en_US\" rel=\"noopener\" target=\"_blank\">ESP32 development board<\/a>. <\/p>\n<p>In case you need it, this is how to use an ESP32 development board to read RFID tags from a SparkFun RFID USB Reader.<\/p>\n<p><img decoding=\"async\" width=\"456\" height=\"330\" src=\"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/SparkFun-RFID-USB-Reader.jpg\" alt=\"SparkFun RFID USB Reader\" class=\"aligncenter size-full wp-image-1898\" \/><\/p>\n","protected":false},"author":1,"featured_media":1898,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[375,4],"tags":[588,630,484,705,707,708,706],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/SparkFun-RFID-USB-Reader.jpg","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-uB","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1897"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=1897"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/1897\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/1898"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=1897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=1897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=1897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}