Read the data of the NFC reader connected to Raspberry Pi 3 with Python and send it to openFrameworks with OSC

1. Overview

Continuing from the previous article (Running openFrameworks sample program on Raspberry Pi 3 --Qiita), replace Mac for exhibition with Raspberry Pi It is an attempt to do so.

Last time, I installed oF on Raspberry Pi and ran the sample program, so this time I will connect the NFC reader to Raspberry Pi and send the NFC data read from the python program to openFrameworks with OSC.

2. Working environment

3. Reference site

  1. How to connect NFC reader / writer RFID-RC522 of SPI communication method to Raspberry Pi 3 Model B and read NFC tag (How to connect NXP MFRC522 RFID reader / writer to Raspberry Pi 3 and read NFC card without contact)
  2. mxgxw/MFRC522-python: A small class to interface with the NFC reader Module MFRC522
  3. Python OSC (pyOSC) | Android Days
  4. pyOSC 0.3.5b-5294 : Python Package Index
  5. Realize ofxFaceTracker with Raspberry Pi2 --Take ’s diary

4. Use NFC reader on Raspberry Pi 3

I made it possible to use the NFC reader by relying on the reference site 1. The program I ran is Read.py on reference site 2. Since it was as per the reference site, it is omitted.

When I first tried it, I ran the program and it didn't respond to NFC tags. The site said that I had to disable the Device Tree, but I couldn't find the Device Tree in the Advanced Option even after `sudo raspi-config`.

I wasn't sure, but I reinstalled Raspbian and it got better. I bought a micro SD card with Raspbian 2016-02-26 pre-installed, but the pre-installed one may not have been good.

5. Install pyOSC

I used osc to bring the python sample program run in 4. to openFrameworks. I thought it would be nice if I could read the NFC reader directly from oF, but I didn't know what to do, so I chose this method.

I tried pyOSC while looking at the reference site 3. (Python OSC (pyOSC) | Android Days).

Install pyOSC

git clone https://gitorious.org/pyosc/devel.git
cd devel
sudo python setup.py install

Failure

Reference site 3. I tried the sample program written in, but it didn't work.

git clone https://github.com/conanxin/Arduino-Meets-Blender-OSC.git

Start up two terminals and try running the sample program.

terminal1


cd Arduino-Meets-Blender-OSC/pyOSC_examples
python basic_receive.py

terminal2


cd Arduino-Meets-Blender-OSC/pyOSC_examples
python basic_send.py

When I ran send.py, I got the following error.

terminal2


Traceback (most recent call last):
  File "basic_send.py", line 28, in <module>
    client.sendto(msg, ('127.0.0.1', 2014)) # note that the second arg is a tupple and not two arguments
  File "/usr/local/lib/python2.7/dist-packages/OSC.py", line 1174, in sendto
    ret = select.select([],[self._fd], [], timeout)
AttributeError: 'OSCClient' object has no attribute '_fd'

I just didn't understand.

success

Take a moment and try another sample. Run the sample that was in the develop folder where you downloaded pyOSC.

terminal1


cd devel/examples
python knect-rcv.py

terminal2


cd devel/examples
python knect-snd.py

When I executed knect-snd.py, the following was displayed on the screen of knect-rcv.py.

terminal1


('Now do something with', 'user1', 3.0, 1.0, -1.0)
('Now do something with', 'user2', 4.0, 2.0, -2.0)
('Now do something with', 'user3', 3.0999999046325684, 2.0, -2.0)
('Now do something with', 'user4', 6.0, 3.200000047683716, -2.4000000953674316)

6. Add OSC processing to RFID program

I inserted the knect-snd.py program into Dump.py.

Dump_osc.py


#!/usr/bin/env python
# -*- coding: utf8 -*-

import RPi.GPIO as GPIO
import MFRC522
import signal

# OSC setting
from OSC import OSCClient, OSCMessage
client = OSCClient()
client.connect(("localhost", 7110))

continue_reading = True

# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
    global continue_reading
    print "Ctrl+C captured, ending read."
    continue_reading = False
    GPIO.cleanup()

# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)

# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()

# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:

    # Scan for cards    
    (status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)

    # If a card is found
    if status == MIFAREReader.MI_OK:
        print "Card detected"

    # Get the UID of the card
    (status,uid) = MIFAREReader.MFRC522_Anticoll()

    # If we have the UID, continue
    if status == MIFAREReader.MI_OK:

        # Print UID
        print "Card read UID: "+str(uid[0])+","+str(uid[1])+","+str(uid[2])+","+str(uid[3])

        # Send OSC
        client.send( OSCMessage("/user/1", [uid[0], uid[1], uid[2], uid[3]] ) )

        # This is the default key for authentication
        key = [0xFF,0xFF,0xFF,0xFF,0xFF,0xFF]

        # Select the scanned tag
        MIFAREReader.MFRC522_SelectTag(uid)

7. Create a program to receive OSC with openFrameworks

The sample program is also used here. Copy the sample program oscReceiveExample to openFrameworks / apps / myApps /.

cd openFrameworks/examples/addons
cp -r oscReceiveExample /home/pi/openFrameworks/apps/myApps/

Open ofApp.h.

cd /home/pi/openFrameworks/apps/myApps/oscReceiveExample/src
vim ofApp.h

Change `# define PORT 12345``` on the 7th line where the port number is set to `# define PORT 7110``` and save.

Go back up one folder and do make. When the compilation is finished, make run.

cd ..
make
make run

A blue window will open in the upper right corner of the screen. Launch another terminal and launch Dump_osc.py created in 6.

cd MFRC522-python
python Dump_osc.py

When you hold the NFC key chain attached to the NFC reader, the NFC UID is also displayed on the blue screen.

スクリーンショット 2016-10-25 00.03.14.png

The video looks like this. (Click the image to go to YouTube) IMAGE ALT TEXT HERE

Now that we've done this, it seems good to do the processing according to the UID received by oF.

Recommended Posts

Read the data of the NFC reader connected to Raspberry Pi 3 with Python and send it to openFrameworks with OSC
Return the image data with Flask of Python and draw it to the canvas element of HTML
I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)
Get additional data to LDAP with python (Writer and Reader)
I sent the data of Raspberry Pi to GCP (free)
It was great to edit the Python file in the Raspberry Pi with Atom's remote function
I tried to automate the watering of the planter with Raspberry Pi
Move data to LDAP with python Change / Delete (Writer and Reader)
Process the gzip file UNLOADed with Redshift with Python of Lambda, gzip it again and upload it to S3
Send the temperature, humidity, etc. measured by SensorTag to Ambient via Raspberry Pi 3 and graph it.
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
Measure temperature, humidity, etc. with SensorTag and send it to Ambient via Raspberry Pi 3 to graph it Part 2
CSV output of pulse data with Raspberry Pi (confirm analog input with python)
Use python on Raspberry Pi 3 to light the LED with switch control!
Send and receive image data as JSON over the network with Python
Read CSV file with Python and convert it to DataFrame as it is
[python] Send the image captured from the webcam to the server and save it
Output the report as PDF from DB with Python and automatically attach it to an email and send it
How to put OpenCV in Raspberry Pi and easily collect images of face detection results with Python
I tried to get and analyze the statistical data of the new corona with Python: Data of Johns Hopkins University
I made an npm package to get the ID of the IC card with Raspberry Pi and PaSoRi
Upload data to s3 of aws with a command and update it, and delete the used data (on the way)
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
Connect to the console of Raspberry PI and display local IP and SD information
Summary of how to read numerical data with python [CSV, NetCDF, Fortran binary]
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
[Python] How to read data from CIFAR-10 and CIFAR-100
Periodically notify the processing status of Raspberry Pi with python → Google Spreadsheet → LINE
CSV output of pulse data with Raspberry Pi (CSV output)
Get CPU information of Raspberry Pi with Python
(Diary 1) How to create, reference, and register data in the SQL database of Microsoft Azure service with python
GAE --With Python, rotate the image based on the rotation information of EXIF and upload it to Cloud Storage.
Use python on Raspberry Pi 3 and turn on the LED when it gets dark!
Connect to MySQL with Python on Raspberry Pi
I tried to automatically send the literature of the new coronavirus to LINE with Python
[Introduction to Python] How to get the index of data with a for statement
Measure CPU temperature of Raspberry Pi with Python
A story about getting the Atom field (XML telegram) of the Japan Meteorological Agency with Raspberry Pi and tweeting it
[Python Data Frame] When the value is empty, fill it with the value of another column.
Control music playback on a smartphone connected to Raspberry Pi 3 and bluetooth with AVRCP
Extract images and tables from pdf with python to reduce the burden of reporting
I tried to automate the article update of Livedoor blog with Python and selenium.
Quickly create a Python data analysis dashboard with Streamlit and deploy it to AWS
I just wanted to extract the data of the desired date and time with Django
Read the csv file with jupyter notebook and write the graph on top of it
I tried to compare the processing speed with dplyr of R and pandas of Python
It is easy to execute SQL with Python and output the result in Excel
A memo connected to HiveServer2 of EMR with python
Template of python script to read the contents of the file
Easy IoT to start with Raspberry Pi and MESH
Try to visualize the room with Raspberry Pi, part 1
How to use the Raspberry Pi relay module Python
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Read json file with Python, format it, and output json
Extract the band information of raster data with python
Let's operate GPIO of Raspberry Pi with Python CGI
Python --Read data from a numeric data file to find the covariance matrix, eigenvalues, and eigenvectors
Make a note of what you want to do in the future with Raspberry Pi
I tried to move ROS (Melodic) with the first Raspberry Pi (Stretch) at the beginning of 2021