0

I'm using the SPI library SPI-Py with MFRC522 RFID Library. I'm getting this error when I run REad.py. This issue is related to the SPI-Py library

can't send spi message: Invalid argument

I have enabled SPI using /boot/config.txt

dtparam=spi=on

here is my /dev/spi*

pi@bpi-iot-ros-ai:~ $ ls /dev/spidev*

/dev/spidev0.0

here is my lsmod output

pi@bpi-iot-ros-ai:~ $ lsmod

Module                  Size  Used by
option                 25650  0
usb_wwan               12492  1 option
usbserial              37170  2 option,usb_wwan
spidev                  6366  0

I have made the following connections

    3.3v connects to Pin 01
    MOSI connects to Pin 19
    MISO connects to Pin 21
    SCK connects to Pin 23
    GND connects to Pin 06
    SDA connects to Pin 24
    RST connects to Pin 16

Could someone tell me why I'm getting this error??

6
  • If you REALLY are running Jessie (which is hopelessly out of date and not supported) forget it.
    – Milliways
    May 27 at 7:25
  • The following MAY help (but with an ancient OS who knows) raspberrypi.stackexchange.com/a/142786/8697
    – Milliways
    May 27 at 8:32
  • I have tried the tutorial in that but it shows me below error. ** val = self.spi.xfer2([(addr << 1) & 0x7E, val]) IOError: [Errno 22] Invalid argument ** Do you know how to resolve this issue? @Milliways
    – niranjan
    May 29 at 11:10
  • I have seen the post and made the exact connections which are specified as follows 3.3v connects to Pin 17 MOSI connects to Pin 19 MISO connects to Pin 21 SCK connects to Pin 23 GND connects to Pin 25 SDA connects to Pin 24 @Milliways
    – niranjan
    May 30 at 4:41
  • so I have to upgrade the OS to get it work? there is other workaround? @Milliways
    – niranjan
    May 30 at 4:47

1 Answer 1

0

I can't help with ancient OS or ancient libraries. Many things have changed including how to enable SPI.
I run Raspberry Pi OS Bullseye (but Buster should work). It is entirely possible it may work with earlier OS; if you want to use this you will have to test yourself.
I use the following code for test:-

#!/usr/bin/env python3
# Original https://pimylifeup.com/raspberry-pi-rfid-rc522/
# Better https://docs.sunfounder.com/projects/davinci-kit/en/latest/2.2.7_mfrc522_rfid_module.html
# 2022-08-21


import RPi.GPIO as GPIO
from time import sleep
from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()
# print(reader);

try:
        while 1:
                id, text = reader.read()
                print(id)
                print('{0:#8X}'.format(id) )
                print(">"+text.strip()+"<")
                xx = text.strip()
                print("len xx", len(xx), xx)
                sleep(1)

except KeyboardInterrupt:
        print("Quit")

finally:
        GPIO.cleanup()

and the following connections:-

Datasheet:-
    MFRC522
    Standard 3V MIFARE reader solution
    Rev. 3.8 — 17 September 2014

SPI needs to be enabled.

Correct connections
    3.3v connects to Pin 17
    MOSI connects to Pin 19
    MISO connects to Pin 21
    SCK connects to Pin 23
    GND connects to Pin 25
    SDA connects to Pin 24

     3.3v      17 || 18
    SPI0_MOSI  19 || 20
    SPI0_MISO  21 || 22
    SPI0_SCLK  23 || 24  CE0
     GND       25 || 26  CE1

I don't consider the linked code acceptable I was merely using to test hardware while developing my own libraries and discovered connection errors in most on-line tutorials. I also use c code using ioctl SPI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.