I'm using a Raspberry Pi 2 and a nRF24L01+ with the pyRF24 library. I've had it working fine on a Raspberry Pi (1) model B rev 2 but on the Pi 2 I'm getting this error:
can't send spi message: Invalid argument
I have enabled SPI in
raspi-config and I have this in
snd-bcm2835 i2c-bcm2708 i2c-dev
I am running the following code with
sudo python3 test.py:
#!/usr/bin/python3 # -*- coding: utf-8 -*- import time, sys, datetime, yaml, urllib.request, urllib.parse, urllib.error from pyRF24 import pyRF24 class FleetHubError(Exception): """ Some weird error """ pass class CorruptDataError(Exception): """ Data was currupt """ pass class ServerConnectionError(Exception): """ Couldn't connect to server """ pass class FleetHub: def __init__(self,port=0,pipes=[0xF0F0F0F0E1, 0xF0F0F0F0E2]): try: self.radio = pyRF24("/dev/spidev0.0", 8000000, 25, retries = (15, 15), channel = 76, dynamicPayloads = True, autoAck = True) self.radio.openWritingPipe(pipes) self.radio.openReadingPipe(1, pipes) self.radio.setDataRate(2) self.mode("rcv") except Exception as e: raise e def mode(self,mode): if mode == "receive" or mode == "rcv": radio.startListening() time.sleep(0.25) else: radio.stopListening() time.sleep(0.25) def available(self,updateServer=True): # returns the data (as dictionary) if there is any, otherwise False try: self.recv() timeout = False started_waiting_at = time.time() while not self.radio.available() and not timeout: if ((time.time() - started_waiting_at) > 5): timeout = True if timeout: return False else: ok = True data = binascii.hexlify(self.radio.read(radio.getDynamicPayloadSize())).decode('utf-8').rstrip() # read data try: data = yaml.safe_load(data) # attempt to convert to dict except: ok = False if ok: # all good data['status'] = data['status'].replace(" ","") # clean up status try: # to get speed data['kph'] = data['speed']['kph'] data['mph'] = data['speed']['mph'] data['knots'] = data['speed']['knots'] except: # no speed data['kph'] = "" data['mph'] = "" data['knots'] = "" try: # to get location data['lat'] = data['location'] data['lng'] = data['location'] except: # no location data['lng'] = "" data['lat'] = "" if updateServer: self.updateServer(data) # we need server updated return(data) except KeyError: raise CorruptDataError except OSError: raise DeviceConnectionError except TypeError: raise CorruptDataError except SystemExit: pass except Exception as e: raise(e) def updateServer(self,params): params.pop("location") params.pop("speed") try: server_response = urllib.request.urlopen("http://myserver.com/update?%s" % urllib.parse.urlencode(params)).read().decode("utf-8") return(server_response) except urllib.error.URLError: raise ServerConnectionError except SystemExit: pass except Exception as e: raise(e) if __name__ == "__main__": radio = FleetHub()
Could someone tell me why I'm getting this error?
EDIT: I just came accross this https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=97314 - does it have anything to do with it?
EDIT: I have it working fine in C++, as per the instructions from @user1628, which to me suggests that Python doesn't have the correct SPI BCM2835_PERI_BASE details. So now the question is: How can I make it work in Python3?