Build a RFID card reader with Adafruit Feather HUZZAH w/ESP32 and Medium One’s Prototyping Sandbox

This tutorial uses the Feather HUZZAH w/ESP32 WiFi board as a RFID card reader.    ESP32 connects to Medium One’s Prototyping Sandbox so that a new scanned RFID card key can be sent and processed.   The sandbox will perform the following operations: add, delete or verify a RFID card key.  The user can use the Medium One IoT Controller app on a smartphone to select the card processing mode.

 

In this Quick Start Guide, you will:

  • Set up an Arduino environment
  • Program the Feather HUZZAH w/ESP32 board
  • Use Medium One Workflows to turn on/off the green or red LED’s, set RFID card process mode, and process a new card ID key received from the card reader

Here’s what you need to get started:

 

STEP 1: SET UP RFID card reader and Adafruit ESP32 Feather Board.

STEP 2: SET UP THE MOBILE APP

Note: These instructions are for the Android app, but the IOS app is similar.

Open the IoT Controller app and click on the plus sign in the bottom corner.

Now you can give your project a name and input your Username, Password, and API Key from the account set up. Select “Sandbox”. Then press “Done”.

If you entered everything correctly, you should see two blue circular icons on the bottom.  If you entered something incorrectly, the color of the of the plus circular icon will be red instead of blue.

Next, press “+Add New Widget”.

Select “Switch”.  Swipe the whole “switch” block to the right to access the settings.

The stream field is represented by a two-arrow icon.  The tag field is represented by a price tag icon. The delete button is represented by a trash can icon.

Press each icon to enter the field.  Type “raw” for the stream, and “redledsw” for the tag.

Press “+ Add New Widget” again.  Four more similar switches are created.   At the end, this is what your screen will look like.

Next, press “+Add New Widget”.

Select “Notification”.  Swipe the whole “Notification” block to the right to access the settings.

Press each icon to enter the field.  Type “notifications” for the stream, and “message” for the tag.

At the end, there are four “switch” widgets and one “notification” widget.  The tag name will appear on each widget.

 

Checkpoint

Go to your Medium One account and go to the “Dashboard” from the left-hand sidebar.  Click “Single User Real Time Events Stream”.

Select your user in the right hand corner of the widget.

Now, on the app, click on the “redledsw” switch to turn it on.

You should see an event show up on the widget.

Click the save icon (floppy disk) in the top right corner of the dashboard.

 

STEP 3: SET UP THE ESP32 BOARD

Go to Tools -> Board:”Adafruit ESP32 Feather”

Copy and paste the following code from this link into your project.

https://github.com/Medium-One/esp32/tree/master/Sparkfun_125kHz_RFID_Card_Reader/esp32_arduino_c_code

 

Fill in your Sandbox and WiFi credentials where necessary near the top portion code.

For example, it will look something like this:

STEP 4: PROGRAMMING THE BOARD

Connect your board to your PC via USB.

Next, go to Tools -> Port. If the board is properly connected and the USB driver is installed, you’ll see *SLAB_USBtoUART device listed.  Note, on Windows, you’ll need to select the correct com port.

Then click on the upload arrow in the top left corner to compile and flash the board, this may take a few minutes.

Note the output log during this step to see when it’s completed.

Once complete, go back to your Medium One Dashboard, where the Real Time Events Stream should be open. You should eventually receive an event from your board within a minute.

You should go to Tools -> Serial Monitor to see print statements from the board, so that you can see when the board connects to the WiFi.  (Use 115200 baud)

You will also receive a heartbeat event from the board every minute.

 

STEP 5: WRITE WORKFLOW 1: SWITCH LED

Press these two switches to send event data to the sandbox.

The events will appear.

Go to “Config” on the left-hand sidebar in your Medium One account and click “Data Streams”.

Click “raw” and then click the active checkbox next to “redledsw” and “greenledsw”. Then click “Save Data Stream”.

Now go to your Workflow Studio in your Medium One account and click “Create”.

Give your workflow a name. We named ours “LED Control”.

Click the “Tags and Triggers” icon, which is the first icon on the right-hand sidebar.

Click “raw” and drag the “redledsw” and “greenledsw” tags into the main area of the workflow.

Now click on the “Modules” icon (the second icon in the sidebar), click on “Foundation” and drag a “Base Python” module into the workflow.

Double click on the base python block.  Click to add the 2nd input called in2.   Then press “save”.

Connect the bottom end of the switch tag to the “in1” and “in2” circles on the Base Python module.

Double-click on the Base Python module and copy and paste the following code (follow link) into the Script section, replacing any code that is originally there.

Now click “Save and Activate”.

 

Checkpoint

Plug the board in and open the IoT Controller app.

After the board is done setting up (within a minute), turn the app switch on and off. You should see the LED on the board turn on and off.

Unplug the board.

 

 

STEP 6: WRITE WORKFLOW 2: Set RFID Card Key Processing Mode (Add, Delete, Verify)

Press these two switches to send event data to the sandbox.

The events will appear.

Go to “Config” from the left-hand sidebar on your Medium One account and click “Data Streams”.

Click “raw” and then click the active checkbox next to “add_user_mode” and “del_user_mode”. Then click “Save Data Stream”.

Create a new stream called notification.  Click on “Create New Stream”.

Enter “notifications” for the Name field.  Choose “Never Expire.” Click “Save Data Stream.”

The new data stream is created.

Create a new workflow, name it, and drag the raw “add_user_mode” and “del_user_mode” tags into the workflow.

Drag a Base Python module into the workflow.

Double click on the base python block.  Click to add the 2nd input called in2.   Then press “save”.

Click the “Outputs” icon (third icon on sidebar) and drag one “Processed Stream – Single” output into the workflow.

Double click “Processed Stream – Single” output block.

Choose “notifications” for Datastreams field.   Click “Save.”

Connect the blocks as shown below.

Copy and paste the following code into the Script area, replacing any code (follow link below) that was previously there. Then click “Save”.

Now click on the “Revisions” icon (second from the bottom of the sidebar).

Click the checkmark under the latest revision to activate the workflow if it’s not activated.

 

Checkpoint

Go to your Mobile App.

Click the “add_user_mode” switch to change the state from OFF to ON.  A message will appear to indicate that the “add a user’s card key” mode is enabled, and the firmware is waiting for a user to scan a card.

Click the “add_user_mode” switch to change the state from ON to OFF.  A message will appear to indicate that the “verify a user’s card key” mode is enabled, and the firmware is waiting for a user to scan a card.

Click the “del_user_mode” switch to change the state from OFF to ON.  A message will appear to indicate that the “delete a user’s card key” mode is enabled, and the firmware is waiting for a user to scan a card.

Click the “del_user_mode” switch to change the state from ON to OFF.  A message will appear to indicate that the “verify a user’s card key” mode is enabled, and the firmware is waiting for a user to scan a card.

 

STEP 7: WRITE WORKFLOW 3: Process RFID card key.

Place the RFID key over the reader and hold it there until the buzzer sounds a beep.  This step will send the “card_key” tag to the cloud.

The “card_key” tag and value appear.

Go to “Config” from the left-hand sidebar on your Medium One account and click “Data Streams”.

Click “raw” and then click the active checkbox next to “card_key.” Then click “Save Data Stream”.

Now go to your Workflow Studio on your Medium One account and click “Create.”

Give your workflow a name. We named ours “Process RFID Card Key.”

Click the “Tags and Triggers” icon, which is the first icon on the right-hand sidebar. Click “raw” and drag the “card_key” tag into the main area of the workflow.

Now click on the “Modules” icon (the second icon in the sidebar), click on “Foundation” and drag a “Base Python” module into the workflow.

Click the “Outputs” icon (third icon on sidebar) and drag one “Processed Stream – Single” output into the workflow.

Double click “Processed Stream – Single” output block.

Choose “notifications” for Datastreams field.   Click “Save.”

Connect the blocks as shown below.

Copy and paste the following code into the Script area, replacing any code (follow link below) that was previously there. Then click “Save”.

Now click on the “Revisions” icon (second from the bottom of the sidebar).

Congrats! You have finished the tutorial.

Click the checkmark under the latest revision to activate the workflow if it’s not activated.

 

Checkpoint

Go to your Mobile App.  Let’s try out each of the different card key modes.

[Add Card Key Mode]

Click the “add_user_mode” switch to change the state from OFF to ON.  Wait for the message: “Add card ID: Please scan your card.”

Scan your card. This message will appear: “Add card (<the card key #1>). Pass!”   The green LED light will blink once.

[Verify Card Key Mode]

Click the “add_user_mode” switch to change the state from ON to OFF.  Wait for the message: “Verify card ID: Please scan your card.”

Scan your card key #1.  Because the keys match, this message should appear: “Verify card (<the card key #1>). Pass!” The green LED light blinks once.

Scan your card key #2.  Because the keys do not match, this message should appear: “Verify card (<the card key #2>). Fail!”  The red LED light blinks once.

[Delete Card Key Mode]

Click the “del_user_mode” switch to change the state from OFF to ON.  Wait for the message: “Delete card ID: Please scan your card.”

Scan your card key #1.  This message will appear: “Delete card (<the card key #1>). Pass!” The green LED light blinks once.

Click the “del_user_mode” switch to change the state from ON to OFF.  Wait for the message: “Verify card ID: Please scan your card.”

[Add Card Key Mode]

Click the “add_user_mode” switch to change the state from OFF to ON.  Wait for the message: “Add card ID: Please scan your card.”

Scan your card.  This message will appear: “Add card (<the card key #2>). Pass!”  The green LED light blinks once.

[Verify Card Key Mode]

Click the “add_user_mode” switch to change the state from ON to OFF.  Wait for the message: “Verify card ID: Please scan your card.”

Scan your card key #2.  Because the keys match, this message will appear: “Verify card (<the card key #2>). Pass!” The green LED light blinks once.

Scan your card key #1.  Because the keys do not match, this message will appear: “Verify card (<the card key #1>). Fail!”  The red LED light blinks once.

Congratulations!  You have successfully completed the RFID Card Reader tutorial!  To learn more about the Medium One Sandbox and all its capabilities go here [Medium-One-Docs].

Author: Rochelle Drenan