Getting Started with Near Field (NFC) for MIT App Inventor

9 Pages • 1,456 Words • PDF • 1 MB
Uploaded at 2021-09-24 12:33

This document was submitted by our user and they confirm that they have the consent to share it. Assuming that you are writer or own the copyright of this document, report to us by using this DMCA report button.


Getting Started with NFC tags (NXP NTAG203) for  MIT App Inventor  If you would like to learn how to use the Near Field component in MIT App  Inventor, you can use this guide to get started!   - Written on: 15/05/2019 

Introduction:

What is NFC (Near Field Communication)? NFC is a type of RFID, operating at 13.56  mHz frequency. It generally works at a short range, and you can use phones that have NFC to  interact with tags/ cards/ other phones by tapping on it. You probably also hear or see the  word RFID nowadays, such as at the Touch n Go tolls or anti-theft scanners you see at stores.  NFC technology is currently picking up, and can have applications such as secure contactless  payment, programming a smartphone to be a hotel key, and much more.     One challenge you may face when building your MIT app to work with these tags is it’s  incomplete documentation. In MIT App Inventor, if you right click> help on any of the blocks  with NFC, you will be able to access the current documentation about its Near Field  component. However, it doesn’t say a lot like what models of tags you can work with (which  was one of my initial struggles as I was using a wrong tag), or how certain blocks like  WriteType is meant to be used.     However, they are not impossible to work with, so in this guide, I share my findings to  create a simple project with MIT App Inventor.    

 

 

What do you require:   1) An Android smartphone with NFC   Not all Android phones have NFC, borrow one if your phone does not have NFC capability.    

  For my phone, I can easily access it in the dropdown menu.  If you can’t find yours, simply google for how to get to it!   

2) Readable and Writable NFC Tag    MIT App Inventor website does not specify what models work with the software.   Unfortunately, even if your phone could read and write on certain tags​, this software does  not work with every type of RFID/NFC tag, ​even if your phone can clearly do so when using  another app.     One such tag which couldn’t work for MIT App Inventor is the more common Mifare  tags/cards, which usually come along with the NFC or RFID modules you buy for the Arduino  or other microcontrollers. However, I have tested this with the NTAG203 tags/cards and they  are able to work with MIT App Inventor.     

 

 

Left: Mifare Card/Tags (​cannot​ work with MIT App Inventor)  Right: ​NTAG203 Card/Tags (can work with MIT App Inventor) 

I bought the NTAG203 tags and card via Shopee, which are around RM5.00+ each.    

 

Sample Project: Smart Classroom Attendance Taker (Demo)   Here is a sample project to demo the Near Field component capabilities in MIT App Inventor.     Let’s say you are a lecturer or teacher and usually, students will have to sign manually on a  paper and you have to key them in into a computer again anyway. Or, you have to call out  names one by one, and it consumes a lot of time.     What a hassle! No wonder sometimes your lecturer or teacher seems grumpy. What if we can  easily make a device that students can scan their student ID which will record their  attendance and timestamp? Let’s get started.     

Step 1: Prepare your User Interface Arrange your User Interface as below: 

         

  From top to bottom:       Component 

                         

Name 

Properties To Change 

Screen 

Screen1 

Align Horizontal: Center  BackgroundColor: Up to you  (optional) 

User Interface/  Label 

LabelNFC 

Height: 15%  Text: NFC STATUS: WAITING  FontTypeface: Monospace  (optional) 

User Interface/  Label 

Label1 

Text: Choose Mode 

Horizontal  Arrangement 

HorizontalArrangement1 



User Interface/ Button  Button_Write 

Text: Register Tag 

User Interface/ Button  Button_Read 

Text: Take Attendance 

User Interface/ Label 

Label2 

Text: Student Name to Register 

User Interface/  Textbox 

TextboxStudentName 



User Interface/ Label 

LabelStudent1 

Text:   

User Interface/ Label 

LabelStudent2 

Text:   

User Interface/ Label 

LabelStudent3 

Text:   

Sensor/NearField 

NearField1 



Sensor/Clock 

Clock1 



Step 2: Prepare the code for writing a NFC tag   Below is the code to enable your NFC tag to be written with a student’s name that  you have typed into a textbox. 

  *The text in LabelNFCStatus.text is   NFC IS IN WRITE MODE. Scan a tag after writing full name of student in the textbox.     ● As the documentation says, setting ​ReadMode​ to false will allow you to write a  text on a tag when it comes close to your NFC reader/writer on your phone.    ● Just set the ​TexttoWrite ​to your desired source of the text.     If you try to test it now using Connect, nothing may work yet. So, continue with the  codes in Step 3 first.                              

Step 3: Read the tags to store attendance Now, add more code as below:  

  *The text in LabelNFCStatus.text is   NFC IS IN READ MODE. Scan Tag to NFC Reader to take attendance.     The above is a simple algorithm to write another student’s name when it reads  a tag that contains a student full name, by adding +1 to the variable count each time  a tag is read, and after that print on the next label if another student’s tag is read. At  the moment, the number of students is only limited to how many if-thens you placed  and the amount of student name labels you have placed into the app (which is only 3  in this sample project). You can of course edit the above yourself to have a more  efficient algorithm to add the names, but for now, I will keep the code to be just as  simple as above.     

Step 4: Test your app!   As the documentation has mentioned, at the moment,​ ​the NearField component will  only work on Screen1​. I have already tested it by attempting to use NearField on  other new screens. Sadly, it really does not work. So make sure to use Screen1 in your  future projects if you would like to use NearField component.    Also another odd thing the documentation omitted is apparently, ​NearField only  works after you installed the apk file on your phone​, and does not work in  development mode. So, click Build> App(provide QR code for .apk) to transfer your  app to your phone.    

    After you have installed it, try writing some of your tags, and later take attendance  with them. Make sure your NFC is turned on!  

    If you are unable to write a student’s name unto the tag, do read the next page.  

Extra: Troubleshooting steps for MIT App Inventor Near Field   If you are having the following issues, double check on the following.    1. I have set read mode to false and I am 100% sure there isn’t any problem  with my code, but it doesn’t seem to write any text unto the tag.     One peculiar problem I encountered while attempting to write is for some reason, it  only works once or twice but most of the other times, it just refuses to write. On the  other hand, I have no problems with reading.     The fix?   The fix for helping your phone to write the names unto the tag would be to actually  use another existing app that can write tags to do so. For the NTAG203 which is  produced by NXP, you can download the NXP Tag Writer app from Playstore.  

  The app is pretty straightforward, so you can use the above to Write tags.   Choose New Dataset and then Plain text, and you can write the student’s name on the tag should you  continue to be unable to write via the MIT app.  

       

2. Nothing is happening. It’s not even reading.     If your phone has NFC, you should at the very least be able to read a tag that  contains a text via the app you just made with MIT. Do double check on the  following.     1. Make sure NFC is turned on on your device.  2. Make sure you have installed the app into the phone, not merely accessed via  Connect.   3. Make sure NearField is used on Screen1.  4. Mifare card/tag will not work with the app. If unsure, you can use the same  type I used, which is the NTAG203​.    

Extras: Other uses of the Ntag203 Do you think it will be cool if you could get your friends to scan your tag and they can get your contact to their phone? You can definitely do that! The only limitation of the tags are that it can only store very little data. The amount of bytes was just nice to store my personal contact number and e-mail. It is up to your creativity how you can make some things easier in your daily life by using the tag with NFC. Using the NXP Tag Writer app should be straightforward, so you can experiment with it yourself!
Getting Started with Near Field (NFC) for MIT App Inventor

Related documents

12 Pages • 1,733 Words • PDF • 1.8 MB

10 Pages • 736 Words • PDF • 1.1 MB

4 Pages • 438 Words • PDF • 318.3 KB

250 Pages • 60,745 Words • PDF • 14.5 MB

10 Pages • 3,451 Words • PDF • 152.5 KB

6 Pages • 635 Words • PDF • 52 KB

95 Pages • 37,253 Words • PDF • 3.9 MB

42 Pages • 13,266 Words • PDF • 12.1 MB

1 Pages • 622 Words • PDF • 1.6 MB