1 1
AndreWicked

RFID-MFRC522 on NanoPi Neo

Recommended Posts

 

Hello everybody! Can I read data from the RFID-MFRC522 module with my NanoPi, if so, tell me what python libraries are in Armbian or will it be necessary to install an official ROM and work through RPi.GPIO?

Share this post


Link to post
Share on other sites

I2C protocol, which is needed for this device, is supported but disabled by default. Use armbian-config to enable the appropriate I2C port or edit .fex file (decompile-edit-compile) /boot/script.bin if you are using old legacy 3.4.y kernel.

RPi GPIO is on Raspberry Pi.


I am not aware of Python libraries, but officially is this what you get: https://github.com/friendlyarm/WiringNP

Share this post


Link to post
Share on other sites
26 minutes ago, Igor said:

I2C protocol, which is needed for this device, is supported but disabled by default. Use armbian-config to enable the appropriate I2C port or edit .fex file (decompile-edit-compile) /boot/script.bin if you are using old legacy 3.4.y kernel.

RPi GPIO is on Raspberry Pi.


I am not aware of Python libraries, but officially is this what you get: https://github.com/friendlyarm/WiringNP

Thanks for the quick response. But can you explain it to me then? http://wiki.friendlyarm.com/wiki/index.php/RPi.GPIO_:_NanoPi_NEO/NEO2/Air_GPIO_Programming_with_Python

As I understand in the official ROMs there is support RPi.GPIO.

Share this post


Link to post
Share on other sites
4 minutes ago, AndreWicked said:

I am not aware of Python


We deal with board hardware issues and OS. I rarely use Python and I am sure those libraries can be easily installed but this I don't know. You can also do some search or wait for someone that plays with this.

 

For setting GPIO on and off you don't need any libs http://linux-sunxi.org/GPIO

Share this post


Link to post
Share on other sites
14 minutes ago, Igor said:


We deal with board hardware issues and OS. I rarely use Python and I am sure those libraries can be easily installed but this I don't know. You can also do some search or wait for someone that plays with this.

 

For setting GPIO on and off you don't need any libs http://linux-sunxi.org/GPIO

Now I understand. Thank you very much, I will understand further.

Share this post


Link to post
Share on other sites
19 hours ago, martinayotte said:

Since NanoPi-Neo is using H3 SoC, you can use this python library :

https://github.com/duxingkei33/orangepi_PC_gpio_pyH3

 

root@nanopineo:/# sudo git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
Cloning into 'orangepi_PC_gpio_pyH3'...
remote: Counting objects: 61, done.
remote: Total 61 (delta 0), reused 0 (delta 0), pack-reused 61
Unpacking objects: 100% (61/61), done.
Checking connectivity... done.
root@nanopineo:/# cd orangepi_PC_gpio_pyH3/
root@nanopineo:/orangepi_PC_gpio_pyH3# python setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-2.7
creating build/lib.linux-armv7l-2.7/pyA20
copying pyA20/__init__.py -> build/lib.linux-armv7l-2.7/pyA20
creating build/lib.linux-armv7l-2.7/pyA20/gpio
copying pyA20/gpio/__init__.py -> build/lib.linux-armv7l-2.7/pyA20/gpio
running build_ext
Detected processor:  Allwinner sun8i Family (Probably Allwinner H3)
building 'pyA20.gpio.gpio' extension
creating build/temp.linux-armv7l-2.7
creating build/temp.linux-armv7l-2.7/pyA20
creating build/temp.linux-armv7l-2.7/pyA20/gpio
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pyA20/gpio/gpio_lib.c -o build/temp.linux-armv7l-2.7/pyA20/gpio/gpio_lib.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pyA20/gpio/gpio.c -o build/temp.linux-armv7l-2.7/pyA20/gpio/gpio.o
pyA20/gpio/gpio.c:25:20: fatal error: Python.h: No such file or directory
compilation terminated.

Tell me please what is the problem?

Share this post


Link to post
Share on other sites
1 hour ago, AndreWicked said:

root@nanopineo:/# sudo git clone https://github.com/duxingkei33/orangepi_PC_gpio_pyH3
Cloning into 'orangepi_PC_gpio_pyH3'...
remote: Counting objects: 61, done.
remote: Total 61 (delta 0), reused 0 (delta 0), pack-reused 61
Unpacking objects: 100% (61/61), done.
Checking connectivity... done.
root@nanopineo:/# cd orangepi_PC_gpio_pyH3/
root@nanopineo:/orangepi_PC_gpio_pyH3# python setup.py install
running install
running build
running build_py
creating build
creating build/lib.linux-armv7l-2.7
creating build/lib.linux-armv7l-2.7/pyA20
copying pyA20/__init__.py -> build/lib.linux-armv7l-2.7/pyA20
creating build/lib.linux-armv7l-2.7/pyA20/gpio
copying pyA20/gpio/__init__.py -> build/lib.linux-armv7l-2.7/pyA20/gpio
running build_ext
Detected processor:  Allwinner sun8i Family (Probably Allwinner H3)
building 'pyA20.gpio.gpio' extension
creating build/temp.linux-armv7l-2.7
creating build/temp.linux-armv7l-2.7/pyA20
creating build/temp.linux-armv7l-2.7/pyA20/gpio
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pyA20/gpio/gpio_lib.c -o build/temp.linux-armv7l-2.7/pyA20/gpio/gpio_lib.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c pyA20/gpio/gpio.c -o build/temp.linux-armv7l-2.7/pyA20/gpio/gpio.o
pyA20/gpio/gpio.c:25:20: fatal error: Python.h: No such file or directory
compilation terminated.

Tell me please what is the problem?

Sorry,

apt-get install python-dev 

solved the problem.

Share this post


Link to post
Share on other sites

If you wish to test some gpio pins, here a small flasher script :

#!/usr/bin/python

import time
from pyA20.gpio import gpio
from pyA20.gpio import port

gpio.init()
gpio.setcfg(port.PA20, gpio.OUTPUT)
while True:
	gpio.output(port.PA20, gpio.LOW)
	time.sleep(0.25)
	gpio.output(port.PA20, gpio.HIGH)
	time.sleep(0.25)

If you wish to send something on I2C port, you will have to study the RFID-MFRC522 datasheet to figure out what to send and what to retrieve...

But here is at least small example how to initialize some other kind of I2C devices, here is another flasher script working with a MCP23017 GPIO expander :

 

#!/usr/bin/env python

import time
from pyA20 import i2c

i2c.init("/dev/i2c-1")
i2c.open(0x20)
i2c.write([0x00, 0x00])
i2c.write([0x01, 0x00])
while True:
	i2c.write([0x12, 0x0F])
	i2c.write([0x13, 0x0F])
	time.sleep(0.15)
	i2c.write([0x12, 0xF0])
	i2c.write([0x13, 0xF0])
	time.sleep(0.15)

 

Share this post


Link to post
Share on other sites
1 hour ago, martinayotte said:

If you wish to test some gpio pins, here a small flasher script :


#!/usr/bin/python

import time
from pyA20.gpio import gpio
from pyA20.gpio import port

gpio.init()
gpio.setcfg(port.PA20, gpio.OUTPUT)
while True:
	gpio.output(port.PA20, gpio.LOW)
	time.sleep(0.25)
	gpio.output(port.PA20, gpio.HIGH)
	time.sleep(0.25)

If you wish to send something on I2C port, you will have to study the RFID-MFRC522 datasheet to figure out what to send and what to retrieve...

But here is at least small example how to initialize some other kind of I2C devices, here is another flasher script working with a MCP23017 GPIO expander :

 


#!/usr/bin/env python

import time
from pyA20 import i2c

i2c.init("/dev/i2c-1")
i2c.open(0x20)
i2c.write([0x00, 0x00])
i2c.write([0x01, 0x00])
while True:
	i2c.write([0x12, 0x0F])
	i2c.write([0x13, 0x0F])
	time.sleep(0.15)
	i2c.write([0x12, 0xF0])
	i2c.write([0x13, 0xF0])
	time.sleep(0.15)

 

Thank you, it worked. Last question, you write that RFID Reader needs to be connected by I2C, and on many forums write about SPI, I'm a little confused. Will you prompt?

Share this post


Link to post
Share on other sites
2 minutes ago, AndreWicked said:

many forums write about SPI, I'm a little confused. Will you prompt?

You're right ! I've mentioned I2C simply because I saw Igor talking about it in his first reply ...

For SPI, you need to add spidev overlay in your /boot/armbianEnv.txt along with proper parameters. (refer to : https://docs.armbian.com/User-Guide_Allwinner_overlays/ )

Then, you can try this small SPI loopback script to verify :

#!/usr/bin/python

from pyA20 import spi

data = [0x00,0x01,0x02,0x03,0x04,0x05]

spi.open("/dev/spidev0.0")
spi.write(data)
data = spi.xfer(data, len(data))
spi.close()
print data

 

Share this post


Link to post
Share on other sites
6 hours ago, martinayotte said:

You're right ! I've mentioned I2C simply because I saw Igor talking about it in his first reply ...

For SPI, you need to add spidev overlay in your /boot/armbianEnv.txt along with proper parameters. (refer to : https://docs.armbian.com/User-Guide_Allwinner_overlays/ )

Then, you can try this small SPI loopback script to verify :


#!/usr/bin/python

from pyA20 import spi

data = [0x00,0x01,0x02,0x03,0x04,0x05]

spi.open("/dev/spidev0.0")
spi.write(data)
data = spi.xfer(data, len(data))
spi.close()
print data

 

Traceback (most recent call last):
  File "test_spi.py", line 5, in <module>
    spi.open("/dev/spidev0.0")
AttributeError: 'module' object has no attribute 'open'


 

Share this post


Link to post
Share on other sites
21 minutes ago, martinayotte said:

Unbelievable !

You must have done a typo somewhere ...

Just to prove that do the following before the "open" :

 


print dir(spi)

 

I copied your code:

#!/usr/bin/python

from pyA20 import spi

data = [0x00,0x01,0x02,0x03,0x04,0x05]

print dir(spi)
spi.open("/dev/spidev0.0")
spi.write(data)
data = spi.xfer(data, len(data))
spi.close()
print data

and run it

root@NanoPi-NEO:/# sudo python test_spi.py
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
Traceback (most recent call last):
  File "test_spi.py", line 8, in <module>
    spi.open("/dev/spidev0.0")
AttributeError: 'module' object has no attribute 'open'

 

Share this post


Link to post
Share on other sites
18 minutes ago, AndreWicked said:

I copied your code:


#!/usr/bin/python

from pyA20 import spi

data = [0x00,0x01,0x02,0x03,0x04,0x05]

print dir(spi)
spi.open("/dev/spidev0.0")
spi.write(data)
data = spi.xfer(data, len(data))
spi.close()
print data

and run it


root@NanoPi-NEO:/# sudo python test_spi.py
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__']
Traceback (most recent call last):
  File "test_spi.py", line 8, in <module>
    spi.open("/dev/spidev0.0")
AttributeError: 'module' object has no attribute 'open'

 

You had an error in this line.

from pyA20 import spi

 

I changed to

from pyA20.spi import spi

And got this error

root@NanoPi-NEO:/# sudo python test_spi.py
['__doc__', '__file__', '__name__', '__package__', 'close', 'open', 'read', 'write', 'xfer']
Segmentation fault

 

Share this post


Link to post
Share on other sites

Still Unbelievable ...

You got proper "dir" with "from pyA20.spi import spi" instead of "from pyA20 import spi" instead of "from pyA20 import spi" but still got that "Segmentation fault".

Do you have set overlays properly ? what does "ls /dev/spidev*" report ?

Still, I don't understand why the "from pyA20.spi import spi" was required, maybe bug introduced since I last fetch that library ...

 

Just in case, here is my orangepi_PC_gpio_pyH3-master.zip I'm using since Nov 2015 ...

 

orangepi_PC_gpio_pyH3-master.zip

Share this post


Link to post
Share on other sites
15 minutes ago, martinayotte said:

Still Unbelievable ...

You got proper "dir" with "from pyA20.spi import spi" instead of "from pyA20 import spi" instead of "from pyA20 import spi" but still got that "Segmentation fault".

Do you have set overlays properly ? what does "ls /dev/spidev*" report ?

Still, I don't understand why the "from pyA20.spi import spi" was required, maybe bug introduced since I last fetch that library ...

 

Just in case, here is my orangepi_PC_gpio_pyH3-master.zip I'm using since Nov 2015 ...

 

orangepi_PC_gpio_pyH3-master.zip

Everything turned out with RPi.GPIO_NP library

https://github.com/chainsx/RPi.GPIO.NP

SPI-Py Library

https://github.com/lthiery/SPI-Py.git

And 

https://github.com/BiTinerary/OrangePiZeroMFRC522

 

On NanoPi Neo, the libraries from OrangePi Zero are completely suitable, even the pinouts are the same.

root@NanoPi-NEO:~/OrangePiZeroMFRC522/MFRC522-python# sudo python Read.py
Welcome to the MFRC522 data read example
Press Ctrl-C to stop.
Card detected
Card read UID: 194,86,17,48
Size: 8
Sector 8 [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

You can fix it somewhere, if anyone else needs to implement an RFID reader with NanoPi Neo, since it takes very little space :) 

Thank you for your help!

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
1 1