I use Raspberry pi 3 model B on Android Things.
for RC522 communication, I use https://github.com/Galarzaa90/android-things-rc522
this source success work, only 1 RC522 reader device
if RC522 reader device only 1 connect.
GPIO set
SDA - GPIO 8 (SPI0 CS0)
SCK - GPIO 11 (SPI0 SCLK)
MOSI - GPIO 10 (SPI0 MOSI)
MISO - GPIO 9 (SPI0 MISO)
GND - GND
RST - GPIO25
3.3V - 3.3V PWR
is work RC522 device.
and I would like to use 2 RC522 reader devices like the pictures.
this pictures set
SDA (blue) - SPI0 CS1(GPIO 7) , SPO0 CS0 (GPIO 8)
'SCK (green) - SPI0 SCLK
MOSI (yellow) - SPI0 MOSI
MISO (orange) - SPI0 MISO
GND (red) - GND
RST (Brown) - GPIO 25
3.3V (black) - 3.3V PWR
but Only the RC522 device to the left of the picture works.
first when I build with https://github.com/Galarzaa90/android-things-rc522 this source.
all RC522 devices not work.
with a little modification, I was able to operate only one RC522 device on the left.
MainActivity.class
private SpiDevice spiDevice;
private SpiDevice spiDevice2;
private static final String SPI_PORT = "SPI0.0";
private static final String SPI_PORT2 = "SPI0.1";
private Rc522 mRc522;
@Override
public void onCreate(Bundle savedInstanceState) {
PeripheralManager pioService = PeripheralManager.getInstance();
try {
spiDevice = pioService.openSpiDevice(SPI_PORT);
spiDevice2 = pioService.openSpiDevice(SPI_PORT2);
mRc522 = new Rc522(spiDevice, spiDevice2, gpioReset);
...
Rc522.class
private SpiDevice device;
private SpiDevice device2;
private Gpio resetPin;
private int busSpeed = 1000000;
private int busSpeed2 = 13650000; //13.65khz
public Rc522(SpiDevice spiDevice, SpiDevice spiDevice2, Gpio resetPin) throws IOException {
this.device = spiDevice;
this.device2 = spiDevice2;
initializePeripherals();
}
/**
* Performs the initial configuration on hardware ports
* @throws IOException if the hardware board had a problem with its hardware ports
*/
private void initializePeripherals() throws IOException {
device.setFrequency(busSpeed);
device2.setFrequency(busSpeed2);
resetPin.setDirection(Gpio.DIRECTION_OUT_INITIALLY_HIGH);
initializeDevice();
}
/**
* Performs the initial device setup and configure the pins used
*/
private void initializeDevice(){
reset();
writeRegister(REGISTER_TIMER_MODE, (byte) 0x8D);
writeRegister(REGISTER_TIMER_PRESCALER_MODE, (byte) 0x3E);
writeRegister(REGISTER_TIMER_RELOAD_LOW, (byte) 30);
writeRegister(REGISTER_TIMER_RELOAD_HIGH, (byte) 0);
writeRegister(REGISTER_TX_MODE, (byte) 0x40);
writeRegister(REGISTER_MODE, (byte) 0x3D);
setAntenna(true);
}
/**
* Writes to a RC522 register
* @param address The address to write to
* @param value The value that will be written
*/
private void writeRegister(byte address, byte value){
//Log.d(TAG, "writeRegister -->" + address);
//Log.d(TAG, "writeValue -->" + value);
byte buffer[] = {(byte) (((address << 1) & 0x7E)), value};
//Log.d(TAG, "writeBuffer -->" + buffer.toString());
byte response[] = new byte[buffer.length];
try {
device.transfer(buffer, response, buffer.length);
//device2.transfer(buffer, response, buffer.length);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Reads the current value on the RC522's register
* @param address The address to read from
* @return the byte value currently stored in the register
*/
public byte readRegister(byte address){
byte buffer[] = {(byte) (((address << 1) & 0x7E) | 0x80), 0};
byte response[] = new byte[buffer.length];
try {
device.transfer(buffer, response, buffer.length);
//device2.transfer(buffer, response, buffer.length);
return response[1];
} catch (IOException e) {
e.printStackTrace();
return 0;
}
}
I feel like I might be able to modify writeRegister()
and readRegister()
just a little bit.
perhaps,you have opened multiple devices in android things, if you have ever used an RC522 reader device.
please advice for me
thanks..