Wednesday, November 30, 2022

Translation and Rotation of Images in Six Degree of Freedom Using OpenCV

I would like to share a small C++ function to translate and rotate images in 3D space in six degree of freedom (6 DoF). It also adjusts brightness and contrast. I use OpenCV library to perform some image processing.



Monday, November 7, 2022

Near Field Communication (NFC) Using PN7150RPIM

Using OM5578 PN7150 NFC controller with Raspberry Pi is discussed.


Hardware Module

PN7150RPIM demo kit consists of PN7150 controller which is soldered on Raspberry Pi Interface board. It also includes NTAG216 a NFC card for testing [1]. There are three different versions of interface board for PN7150 NFC controller - Raspberry Pi interface, BeagleBone interface, or Arduino interface [2]. As illustrated in Figure 1, it only uses 6 pins - 3.3V, and GND for power, SDA and SCL for I2C, a GPIO input IRQ for interrupt, and a GPIO output for Enable pin. There is also an optional 5V power VANT.


Figure 1. PN7150 NFC Controller Board Pins.


The Raspberry Pi version is used as SBC interface for this discussion. Its connections to the header is shown in the following Figure [3].


Figure 2. PN7150 RPi Interface Board Connections.


Library

There is NXP Linux libnfc-nci software stack on GitHub that supports PN7150 NFC controller [4] which we will clone as follows.

$ sudo apt install autoconf automake libtool git pkg-config
$ git clone https://github.com/NXPNFCLinux/linux_libnfc-nci.git


Then, navigate into the directory and generate the configuration script. The machine should have automake, autoconf and libtool packages installed before running the script.

$ cd linux_libnfc-nci/
$ ./bootstrap


There are three options to generate the Makefile to map Linux NFC stack-
--enable-i2c
To use PN5xx I2C kernel mode driver which is default.
--enable-alt
To access GPIO and I2C resources from the user space in case the existing kernel offers access to them.
--enable-lpcusbsio
For USB devices implementing PN7150 with HID interface expose via LPCUSBSIO. protocol.
In our case, we will use --enable-alt option as the Raspberry Pi supports using GPIO and I2C through /sys/class/gpio and /dev/i2c-dev interface [5]. The stack is illustrated in the following figure.


Figure 3. libnfc-nci SW stack.


The i2c bus and GPIO pin can be configured in phTmlNfc_alt.h which is in ./src/halimpl/pn54x/tml/i2c directory. The existing values are

#define I2C_BUS "/dev/i2c-1"
#define I2C_ADDRESS 0x28
#define PIN_INT 23
#define PIN_ENABLE 24


Execute the following commands to generate the Makefile for the above settings, build and install the library.

$ ./configure --enable-alt
$ make 
$ sudo make install 


The install path is at /usr/local/lib. And for that you can use

$ export LD_LIBRARY_PATH=/usr/local/lib


or create config file as follows.

$ sudo sh -c "echo /usr/local/lib/ > /etc/ld.so.conf.d/nfc-nci.conf"


And load the configuration.

$ sudo ldconfig


C++ Examples

Example C++ programs to use NXP Linux libnfc-nci software stack as reader, emulator, etc. are also available on GitHub [6] which we will clone as follows.

$ git clone https://github.com/NXPNFCLinux/linux_libnfc-nci_examples


Then, you can navigate into an example directory, build, and run.

$ cd linux_libnfc-nci_examples/xxxx
$ make 
$ ./xxxx 




References

[1] NXP Semiconductors. PN7150 Raspberry Pi SBC Kit Quick Start Guide. 2019-07-08.
url: https://www.nxp.com/docs/en/application-note/AN11758.pdf.

[2] NXP Semiconductors. PN7150 NFC Controller SBC Kit User Manual. 2019-07-10.
url: https://www.nxp.com/docs/en/user-guide/UM10935.pdf.

[3] NXP Semiconductors. NFC's SBC Interface Boards User Manual. 2016-05-02.
url: https://www.nxp.com/docs/en/user-guide/UM10956.pdf.

[4] NXP Semiconductors. PN71xx Linux Software Stack Integration Guidelines. 2018-08-10.
url: https://www.nxp.com/docs/en/application-note/AN11697.pdf.

[5] NXP Semiconductors. Easy set-up of NFC on Raspberry Pi. 2018-08-14.
url: https://community.nxp.com/docs/DOC-341231.

[6] NXP Semiconductors. linux_libnfc-nci_examples.
url: https://github.com/NXPNFCLinux/linux_libnfc-nci_examples.