0

I am new to the Raspberry Pi platform and I have been trying to get my Pi to communicate with an NRF24L01 module. I have been at this for a few days and just cannot get it to work. Here is my info and what I have tried so far:

@raspberrypi:~ $ ./versioncheck.sh
- Original Installation
Raspberry Pi reference 2020-02-13
- Current OS
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster
- Kernel
4.19.97-v7l+
- Model
Raspberry Pi 4 Model B Rev 1.1
- Firmware
Feb 12 2020 12:36:21 
Copyright (c) 2012 Broadcom
version c3c8dbdf147686fb0c3f32aece709d0653368810 (clean) (release) (start)
Filesystem created:       Sun Mar 15 20:45:11 2020

I have followed a bunch of tutorials and none have worked for me, however I was closest with this one: Youtube Tutorial

My code is:

import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev

GPIO.setmode(GPIO.BCM)

pipes = [[0xE8, 0xE8, 0xF0, 0xF0, 0xE1], [0xF0, 0xF0, 0xF0, 0xF0, 0xE1]]

radio = NRF24(GPIO,spidev.spiDev())
radio.begin(0,17)

radio.setPayloadsize (32)
radio.setChannel (0x76)
radio.setDataRate (NRF24.BR_1MBPS)
radio.setPALevel (NRF24.PA_MIN)

radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()

radio.openReadingPipe(1, pipes[1])
radio.printDetails()
radio.startListening()

while True:

        while not radio.available(0):
            time.sleep(1/100)

        recievedMessage = []
        radio.read(receivedMessage, radio.getDynamicPayLoadSize())
        print("Recieved: {}".format(recievedMessage))

        print("Translating our received message into unicode characters...")
        string = ""

        for n in receivedMessage:
            if (n >= 32 and n <= 126):
                string =+ chr(n)
            print("Our received message decodes to: {}".format (string))

When I run the code I get:

  File "/home/pi/Desktop/NRF24L01/recieveArduino.py", line 11, in <module>
    radio = NRF24(GPIO,spidev.spiDev())
AttributeError: module 'spidev' has no attribute 'spiDev'

I have tried the following:(I think the is everything)

sudo apt-get install python3-dev 
  174  wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
  175  unzip master.zip
  176  ls
  177  rm master.zip
  178  cd py-spidev-master/
  179  sudo python3 setup.py install
  180  cd desktop
  181  cd
  182  cd desktop/
  183  cd Desktop/
  184  ls
  185  mkdir NRF24L01
  186  cd NRF24L01/
  187  git clone https://github.com/BLavery/lib_nrf24
  188  cd lib_nrf24/
  189  ls
  190  cp lib_nrf24.py ~/Desktop/NRF24L01/
194  cd
  195  cd Desktop
  196  git clone https://github.com/tmrh20/RF24

I tried updating:

sudo apt-get update
  258  sudo apt-get dist-upgrade
  259  sudo easy_install RPi.gpio
  260  sudo apt-get install python-rpi.gpio python3-rpi.gpio
  261  sudo reboot
  262  history
  263  sudo apt-get python-dev python3-dev gcc python3-setuptools python3-pip
  264  sudo apt-get python3-dev gcc python3-setuptools python3-pip
  265  sudo apt-get instal python-dev python3-dev gcc python3-setuptools python3-pip
  266  sudo apt-get install python-dev python3-dev gcc python3-setuptools python3-pip
  267  sudo pip3 install RPi.GPIO

And:

cd py-spydev
  283  git clone https://github.com/Gadgetoid/py-spydev
  284  sudo apt-get update
  285  sude apt-get install python-dev python3-dev -y
  286  sudo apt-get install python-dev python3-dev -y
  287  history
  288  wget https://github.com/Gadgetoid/py-spidev/archive/master.zip
  289  ls
  290  unzip master.zip
  291  rm master.zip
  292  cd py-spidev-master/
  293  ls
  294  sudo python setup.py install
  295  sudo python3 setup.py install

I have referenced the following answers:

Read this if you use Python Spidev

Raspberry Pi won't recognize nRF24L01+

'SpiDev' object has no attribute 'GPIO'

Possible SPI issues around NRF24 operations post RPi system update?

Problem with SPI after updating to Stretch

Sorry about the long post but I am at a loss and hoped to give as much info as I can in order to get this module to work. Thank you all in advance.

NOTE: Yes SPI is enabled and I have verified proper hardware connections

  • Hi, this guy does not seem to have your spiDev problem: https://raspberrypi.stackexchange.com/questions/107608/rpi-spi-nrf24l01-2-4ghz-transceiver-module-send-message-to-arduino-problem. – tlfong01 Apr 15 '20 at 05:13
  • 1
    True, however it got to the point that I was searching all over for any kind of hints that may help. – PiMikeTSQL Apr 15 '20 at 06:02
  • Well, you got stuck at a point after "import spidev", So I would suggest to check if you import garbage, and therefore output garbage. You might like to study Ref 28 of my answer to the following question related to non standard spidav:. https://raspberrypi.stackexchange.com/questions/109773/how-can-rpi-python-read-a-mfrc522-pn532-nfc-rfid-mifare-smart-card-tag. Cheers. – tlfong01 Apr 15 '20 at 06:28
  • And you might like to read Parts 3 and 4 on how I debug garbage SPI stuff. In Part 3, I do a SPI loopback test, to make sure relevant SPI hardware and software are compatible, updated, upgraded, wired, and configured OK. In Part 4 I only use two statements: (a) "from ABC import CDE", (b) create an object "xyz = CDE()", and job is done. – tlfong01 Apr 15 '20 at 06:42
  • 1
    @tlfong01 thank you very much for your comments it was really great information. I just needed to pay attention to my case sensitivity haha. – PiMikeTSQL Apr 15 '20 at 08:44
  • Hi @PiMikeTSQL, LOL. Many thanks for bringing back me my sweet memory of making my very first typo mistake, when copying and pasting my teacher's little demo program to run by the huge computer, in my very first day of learning computer programming, and going to the computer lab. After so many decades, now I still remember vividly my big joy of, after correcting the typo and the big, unforgiving computer finally accepted my little 4 line program and ran it! – tlfong01 Apr 15 '20 at 09:15
  • 1
    I couldn't believe I spent 3 days over a typo however I have done the same with SQL so I should have looked closer but it happens :p. My program is actually running but for some reason it isnt communicating properly. I am not getting anything out of the 'receiveMessage []' its just blank so that is what I am working through now. – PiMikeTSQL Apr 15 '20 at 19:48
  • Well you also brought back my sweet memories in my evil Visual Studio days, when everything "auto complete", "auto spelling check", so I never worried about typo, or forgot which functions to choose. As soon as I typed the first characters, "spidev." VS will immediately, well before I type the next char, help me to complete the only functions, or if there are more than one function, a drop menu of the available functions, with the parameter list, etc. In other words, I would never go wrong. It is sort of Google search, even if I wrongly spell something, google would offer suggestions, .. – tlfong01 Apr 16 '20 at 07:30
  • Anyway, now I am using Thonny, which is also "auto complete", sort of, ... https://imgur.com/gallery/wTplmXz. – tlfong01 Apr 16 '20 at 07:31
  • When I first started coding I used VS for C#, then SSDT for TSQL and got used to that. Now working with Thonny and Arduino IDE takes some getting used to. It is very weird to me to use python and have no ' ; ' closing statements off. – PiMikeTSQL Apr 16 '20 at 20:46

1 Answers1

1

Python is case sensitive.

Linux is case sensitive.

https://pypi.org/project/spidev/

Try spidev.SpiDev() not spidev.spiDev().

joan
  • 71,024
  • 5
  • 73
  • 106
  • 1
    Thank you so much I almost laughed when I read that. I also happened to find a few other typo's and what do ya know it works. Thank you so much! – PiMikeTSQL Apr 15 '20 at 08:43