Package: matrix-lite-nfc
MATRIX-Lite-NFC-PyMATRIX Lite NFC Py is a package that allows users of varying skill levels to easily program NFC with their MATRIX Creator.Smartphone Apps For DebuggingIOS AppAndroid AppRoadmapReading Info  (All tags)Reading Pages (MIFARE Ultralight & NTAG)Writing Page  (MIFARE Ultralight & NTAG)Reading NDEF  (MIFARE Ultralight & NTAG)Writing NDEF  (MIFARE Ultralight & NTAG)Installation1. Install MATRIX HAL NFChttps://github.com/matrix-io/matrix-hal-nfc2. Install PIP3To call your scripts with python 3, usepython3 YOUR_SCRIPT.pysudo apt-get install python3-pip3. Upgrade PIPpython3 -m pip install --upgrade pip4. Install matrix-lite-nfc-pysudo python3 -m pip install matrix-lite-nfcReferenceImport Statementimportmatrix_lite_nfcasnfcnfc.statusWhen a read or write function completes, it will contain a status code to indicate the result. nfc.Status returns a string of what that number means.nfc.status(/*number*/)nfc.readThere can only be one instance of NFC reading. This is a hardware limitation that will not change.Synchronous ReadA simple read that returns an object with tag data.nfc.read.scan({# At least 1 read options is required. Less options -> faster reading!"info":True,# Generic information for any NFC tag"pages":True,# All page data"ndef":True,# A single page(faster than pages)"page":0,# All NDEF data})Starting Read LoopA non-blocking loop that passes tag data to a callback.defread_callback(tag):if(tag.status==256):print("NFC Tag Scanned!")print(tag)elif(tag.status==1024):print("Nothing Scanned!")# Configure what you want to readnfc.read.start({"rate":0.5,# Read loop speed (Seconds)"info":True,"pages":True,"ndef":True,"page":0,},read_callback)Stopping Read Loopnfc.read.stop()nfc.Message1. Creating a new NDEF Message# Create an empty NDEF messagemsg=nfc.Message()# Add NDEF Records to messagemsg.addUriRecord("https://community.matrix.one")msg.addUriRecord("tel:+14085551212")msg.addTextRecord("Hello World")msg.addTextRecord("Hola Mundo","es")msg.addMimeMediaRecord("text/json",'{"answer": 42}')# You then pass msg into nfc.write.message(msg)2. Reading a new NDEF Message# Get NDEF data from scanned tagtag=nfc.read.scan({"ndef":True})# Create & print NDEF messagemsg=nfc.Message(tag.ndef.content)print(msg.getRecords())nfc.writeWriting to an NFC tag should normally be done inside the read loop.Writing an NDEF message# Create new messagemsg=nfc.Message()msg.addUriRecord("https://community.matrix.one")# Write and then Print status codes for activation & writingprint(nfc.write.message(msg))Erasing an NDEF messageprint(nfc.write.erase())Writing to a tag's page (WARNING)Be careful when writing to a page. You can accidentally lock your NFC tag!# arg1: page you want to overwrite# arg2: Array of numbers that represents a byteprint(nfc.write.page(25,[48,45,59,21]))Building Locally For DevelopmentDownload the repository.git clone https://github.com/matrix-io/matrix-lite-nfc-pyInstall pybind11.sudo python3 -m pip install pybind11Compile and install library.sudo python3 -m pip install ./matrix-lite-nfc-pyTest your changes by importing any of the following libraries into a.pyfile.# Direct C++ bindingsimport_matrix_hal_nfcashal_nfc# Abstractions to _matrix_hal_nfcimportmatrix_lite_nfcasnfc