bjarne-hansen / py-nrf24

Library for NRF24L01 communication using pigpiod on Raspberry Pi.
MIT License
61 stars 23 forks source link

Error while pip install #20

Closed ihabram closed 3 years ago

ihabram commented 4 years ago

Hello!

I got the following error after [pip install nrf24] command:

"Could not find a version that satisfies the requirement nrf24 (from versions: ) No matching distribution found for nrf24"

Could you help me what is the problem?

bjarne-hansen commented 4 years ago

Not sure what problem you are experiencing here - if you indeed executed "pip install nrf24".

My workflow for a new project is typically: $ python3 -m virtualenv venv $ source venv/bin/activate $ python -m pip install nrf24

I just executed this with success:

$ python -m pip install nrf24
Collecting nrf24 Using cached nrf24-1.1.1-py3-none-any.whl (10.0 kB) Collecting pigpio Downloading pigpio-1.78-py2.py3-none-any.whl (39 kB) Installing collected packages: pigpio, nrf24 Successfully installed nrf24-1.1.1 pigpio-1.78

...

Periphetez commented 4 years ago

Good Day sorry to bug ya,

I have everything installed correctly i think but am consistently getting an error. I cannot figure out what going wrong.

The error is Traceback(most recent call last) Pi = pigpio.pi(env['PIGPIO_HOST']) Then there's raise KeyError (key) from None KeyError: 'PIGPIO_HOST'

If you could please let me know if I'm just missing something or if I'm just doing something wrong. Thanks for your time.

Lennart99 commented 4 years ago

From the readme:

Examples reads the environment variable PIGPIO_HOST

In order to connect to the pigpiod daemon on the Raspberry Pi. $ export PIGPIO_HOST=server.example.com

bjarne-hansen commented 4 years ago

Hi Periphetez

The env['PIGPIO_HOST'] resolves a hostname for the Raspberry which runs the pigpiod daemon. You can set that to whatever the hostname of your Raspberry is.

on Linux/Max: export PIGPIO_HOST=localhost

on Windows: SET PIGPIO_HOST=localhost

Periphetez commented 4 years ago

I think I just misinterpreted what needed what for code. I thought this was all being performed on the raspberry. I'm kind of new to the raspberry used other microcontrollers before.

So you're running your main code on a pc and just connecting to the pi via the internet or is it a ethernet cord.

Again sorry for eating up your time just want to make sure I'm fully understanding what the pi code is doing.

Thanks.

Get Outlook for Androidhttps://aka.ms/ghei36


From: Bjarne Hansen notifications@github.com Sent: Wednesday, November 18, 2020 1:05:10 PM To: bjarne-hansen/py-nrf24 py-nrf24@noreply.github.com Cc: Periphetez Istout916@live.ca; Comment comment@noreply.github.com Subject: Re: [bjarne-hansen/py-nrf24] Error while pip install (#20)

Hi Periphetez

The env['PIGPIO_HOST'] resolves a hostname for the Raspberry which runs the pigpiod daemon. You can set that to whatever the hostname of your Raspberry is.

on Linux/Max: export PIGPIO_HOST=localhost

on Windows: SET PIGPIO_HOST=localhost

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/bjarne-hansen/py-nrf24/issues/20#issuecomment-729922547, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQNB56TO53WP5NEAJGAXVC3SQQSHNANCNFSM4TN4OGFQ.

Lennart99 commented 4 years ago

As long as it is on the same network it is fine, this could be both WiFi and wired

Periphetez commented 4 years ago

So just to make sure I'm understanding this right, again thanks for your time and patience.

All the code would be executed via your pc and whats stored on the nano. There's not really anything being done by the pi other then it giving you a means to read the nrf data and send it back to the pc.

So once the gateway is entered as long as the pi is on everything should executed. And obviously all the packages required installed on the pc. Or is there something else I'm missing here?

Again thanks.

Lennart99 commented 4 years ago

The pi will have to run the pigpio daemon It is also posible to run the daemon and this library both on the same raspberry pi

http://abyz.me.uk/rpi/pigpio/download.html

Periphetez commented 4 years ago

One last quick question hopefully, thanks for all your help so far.

First for you local host would that just just be 127. 0.0.1 or would it be the ipv4 of the pi. Or am I missing something here.

Also would it be possible to make this connection without internet just with a ethernet connection with a laptop? Just how in depth I guess does your local host information have to be?

Would there also be some program required on the laptop to make this communication?

Sorry for taking up so much of your time, I really appreciate the help.

Get Outlook for Androidhttps://aka.ms/ghei36


From: Lennart99 notifications@github.com Sent: Wednesday, November 18, 2020 2:47:45 PM To: bjarne-hansen/py-nrf24 py-nrf24@noreply.github.com Cc: Periphetez Istout916@live.ca; Comment comment@noreply.github.com Subject: Re: [bjarne-hansen/py-nrf24] Error while pip install (#20)

The pi will have to run the pigpio daemon It is also posible to run the daemon and this library both on the same raspberry pi

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/bjarne-hansen/py-nrf24/issues/20#issuecomment-729976722, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQNB56QDYXYTRH7UEGXWGQDSQQ6IDANCNFSM4TN4OGFQ.

Lennart99 commented 4 years ago

When running the application on the rpi itself the adres would be localhost When running the application on your laptop, the adres would be the ip of your rpi

You have to run the export command on the pc running the application.

Also I think it would be possible to do this with only a network cable, but the rpi needs an ip adres, therefore it would be easier to use a connection with your router.

Periphetez commented 4 years ago

I am still having some issues here again sorry.

Just with the original import statement of import os.environ as env is throwing error. I changed too from os import environ as env and no error but continually the PIGPIO_HOST error.

I tried to connect just via a mobile Hotspot using my phone as router to simplify connection and I can't get past on the raspberry using export localhost or switching it out for the ip on the pc.

Is there another step im missing here. Did a complete install on PIGPIOD daemon and functioned tested it and all seems to be working properly there. I just for some reason can't get it to connect....

Is there something that needs to be done with a SSH or something more im missing with the networking setup?

Lennart99 commented 4 years ago

On your Raspberry Pi install pigpio and make sure it is running http://abyz.me.uk/rpi/pigpio/download.html

then on your PC, run the export command with the ip address of the RPI then run the python application

Another option (might me easier) is to replace pi = pigpio.pi(env['PIGPIO_HOST']) with pi = pigpio.pi('IP ADDRESS OF PI HERE'), you can then remove the os.environ import

Periphetez commented 3 years ago

I got it all to compile one time each on pc and on the pi. Now when I go to try and do it again the program just hangs there is there something I need to reinitialize everytime?

Lennart99 commented 3 years ago

I believe you need to start the daemon on de pi (explained on page i shared earlier)

And of course you need to run the python application on your pc

Periphetez commented 3 years ago

Are you just running the code on the first page or do you have a modified version you are running based on your earlier comments?

Get Outlook for Androidhttps://aka.ms/ghei36


From: Lennart99 notifications@github.com Sent: Friday, November 20, 2020 1:19:29 PM To: bjarne-hansen/py-nrf24 py-nrf24@noreply.github.com Cc: Periphetez Istout916@live.ca; Comment comment@noreply.github.com Subject: Re: [bjarne-hansen/py-nrf24] Error while pip install (#20)

I believe you need to start the daemon on de pi (explained on page i shared earlier)

And of course you need to run the python application on your pc

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/bjarne-hansen/py-nrf24/issues/20#issuecomment-731387766, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQNB56Q4SSGPQWJDHYC6ER3SQ3FNDANCNFSM4TN4OGFQ.

Periphetez commented 3 years ago

Just wondering about the code because I don't believe the import statement is starting the nrf24 module.... am using from nrf24 import *. The code just seems to hang and not print anything. Just wondering if I am doing something wrong. If you run the import nrf24 like in the example you get an error saying the NRF24 is not defined.

Lennart99 commented 3 years ago

Have you installed the library? Pip install nrf24

Periphetez commented 3 years ago

Yes followed everything to the T like I said earlier I had everything working where it was printing data and now nothing. I just can't figure out where I am going wrong....

Get Outlook for Androidhttps://aka.ms/ghei36


From: Lennart99 notifications@github.com Sent: Saturday, November 21, 2020 3:19:18 PM To: bjarne-hansen/py-nrf24 py-nrf24@noreply.github.com Cc: Periphetez Istout916@live.ca; Comment comment@noreply.github.com Subject: Re: [bjarne-hansen/py-nrf24] Error while pip install (#20)

Have you installed the library? Pip install nrf24

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/bjarne-hansen/py-nrf24/issues/20#issuecomment-731645103, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQNB56U7A36JQISN2DQB2GTSRA4GNANCNFSM4TN4OGFQ.

bjarne-hansen commented 3 years ago

Dear Periphetez

I am a bit unsure what you have actually done, what you have installed, and what is running where.

For us to help, I think you need to attach your source code and perhaps a drawing of your setup.

In general, what is needed is:

  1. A Raspberry running the pigpiod daemon service and having a NRF24L01 module properly wired.

  2. A server program receiving data like for example the test code rcvr-01.py. This code can run on any PC, Mac, Linux, Rasperry that can run Python. If it runs on the Raspberry that has the pigpiod daemon running (and the nrf24 module attached) you will use "localhost" as the address. If you run the code on your laptop or another computer you will use the IP address when connecting, for example 192.168.0.4 ... or a hostname if you have a DNS ... like for example "pi.example.com".

When starting up you can use the command nrf.show_registers() to print out status of the module to see if it is properly connected.

Try supplying som more details on the error and some debug output ... like screenshots or similar...

Periphetez commented 3 years ago

NO data arduino PI Ok so I ran recv01.py just as is and there's just not data being transmitted. I also attached the raspberry pi wiring which is as per the drawing and the arduino nano wiring which is as per the drawing. Like I said I did get it to transmit one time both on the pc and the pi. But now for some reason this is as far as the code goes.... It just looks like there's no data to get; code on the arduino is the exact code on the bottom of master page. All libraries imported onto the arduino verified and uploaded code. Thanks for your help.

bjarne-hansen commented 3 years ago

Hi Periphetez Your python code works and your nrf24 module is connected - you can see the receiver address for P1 is set to 0xbabeface01 and P2, P3, P4 are 2, 3,.and 4.

Let's see the Arduino code....

Periphetez commented 3 years ago

Ardunio code was copy and pasted from the master but here it is.

include

include

include

// "DHT sensor library by Adafruit" // https://github.com/adafruit/DHT-sensor-library

include

include

define PIN_CS 9

define PIN_CE 10

define PIN_DHT 5

RF24 radio(PIN_CE, PIN_CS); const uint64_t tx_addr = 0xBABEFACE01LL;

byte protocol = 1; byte payload[32];

DHT dht(PIN_DHT, DHT11);

void setup() { // Setup radio. radio.begin(); radio.enableDynamicPayloads(); radio.setAutoAck(true); radio.setDataRate(RF24_1MBPS); radio.openWritingPipe(tx_addr); radio.stopListening();

// Setup sensor.
dht.begin();

}

void loop() {
float t, h;

// Read sensor.
h = dht.readHumidity();
t = dht.readTemperature();

// Prepare payload.
memcpy(payload, (byte *)(&protocol), 1);
memcpy((payload + 1), (byte *)(&t), 4);
memcpy((payload + 5), (byte *)(&h), 4);

// Send payload.
radio.write(payload, 9);

}

bjarne-hansen commented 3 years ago

Hi Periphetez

The channel, speed, crc bytes, and payload size must match. I see 1 mbps in Arduino and 250 kbps in Raspberry. Channel is 100 in raspberry - channel is 76 in arduino.

I will update the test and readme with examples that are consistent. Meanwhile make sure you set the same values.

//bjarne

Periphetez commented 3 years ago

Ok so I switched the data rate and channel around. It now will send and recieve the data but only when I hit upload code on the arduino. Is there a part of the code I'm missing or something I'm doing wrong were the arduino can just send data.

This is what the output looks like. 20201201_082535.jpg 20201201_082549.jpg

I usually get 2 blocks of output everytime I am using the upload button.

bjarne-hansen commented 3 years ago

What code are you running on the Arduino? I guess it would be better with a screenshot from there ...

By the way, your readings look wrong, are you sure you have a sensor connected?

tir. 1. dec. 2020 16.28 skrev Periphetez notifications@github.com:

Ok so I switched the data rate and channel around. It now will send and recieve the data but only when I hit upload code on the arduino. Is there a part of the code I'm missing or something I'm doing wrong were the arduino can just send data.

This is what the output looks like. [image: 20201201_082535.jpg] https://user-images.githubusercontent.com/68820730/100760301-da04b600-33ae-11eb-933c-04209837ca10.jpg [image: 20201201_082549.jpg] https://user-images.githubusercontent.com/68820730/100760349-e7ba3b80-33ae-11eb-91ec-e9d351ba9016.jpg

I usually get 2 blocks of output everytime I am using the upload button.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bjarne-hansen/py-nrf24/issues/20#issuecomment-736625528, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSOYVCL3HCN72YZNJSMZKLSSUDQLANCNFSM4TN4OGFQ .

Periphetez commented 3 years ago

20201204_121315.jpg20201204_121346.jpg It is the code from the main page I updated both code for 250KBPS and have python code looking on channel 76.

Not sure what I am doing wrong to me it just seems like I'm missing some code to initialize the nano.

Also will just ask to make sure i saw it right, it is a 10k ohm resistor you have on the dht22?

bjarne-hansen commented 3 years ago

Hi,

Try adding some Serial.print() statements to understand where the problem is, and share some debug information.

//bjarne

On Fri, 4 Dec 2020 at 20.25, Periphetez notifications@github.com wrote:

[image: 20201204_121315.jpg] https://user-images.githubusercontent.com/68820730/101205677-38d66380-362b-11eb-8c08-213275289ac6.jpg[image: 20201204_121346.jpg] https://user-images.githubusercontent.com/68820730/101205691-3bd15400-362b-11eb-8f09-dde3fd8648af.jpg It is the code from the main page I updated both code for 250KBPS and have python code looking on channel 76.

Not sure what I am doing wrong to me it just seems like I'm missing some code to initialize the nano.

Also will just ask to make sure i saw it right, it is a 10k ohm resistor you have on the dht22?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bjarne-hansen/py-nrf24/issues/20#issuecomment-738971698, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSOYVGFNSK4ABMLSQHSLRLSTEZSXANCNFSM4TN4OGFQ .

--

-- Bjarne Hansen ● skype: bjarne.hansen ● MeetMe: https://doodle.com/bjarne.hansen

Periphetez commented 3 years ago

20201206_084459.jpg20201206_084455.jpg20201206_084519.jpg

Added some serial print statements the data does seem to be correct on the Arduino. I think I messed something up with the pipes. There was one instance where it seemed to connect well, it went about 15 times before stopping. Then the next time I tried it, the pipe address was different and had only 2 outputs.

With the serial print on you can tell that the code is constantly sending data, just when you turn it off just isn't sending anything.

bjarne-hansen commented 3 years ago

Dear Periphetez

Good to see that it is working out for you. Pipe addressing can be tricky. Another thing to watch out for is the memcpy statements - a slight error there may cause your Arduino to reboot.

Best regards Bjarne

-- Bjarne Hansen ● skype: bjarne.hansen ● MeetMe: https://doodle.com/bjarne.hansen

On Sun, 6 Dec 2020 at 16:53, Periphetez notifications@github.com wrote:

[image: 20201206_084459.jpg] https://user-images.githubusercontent.com/68820730/101284854-6ba16880-379f-11eb-9a73-b6fbd8bd1b72.jpg[image: 20201206_084455.jpg] https://user-images.githubusercontent.com/68820730/101284858-71974980-379f-11eb-81d0-89286f6dacb0.jpg[image: 20201206_084519.jpg] https://user-images.githubusercontent.com/68820730/101284861-765bfd80-379f-11eb-9f17-884e958fffd2.jpg

Added some serial print statements the data does seem to be correct on the Arduino. I think I messed something up with the pipes. There was one instance where it seemed to connect well, it went about 15 times before stopping. Then the next time I tried it, the pipe address was different and had only 2 outputs.

With the serial print on you can tell that the code is constantly sending data, just when you turn it off just isn't sending anything.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/bjarne-hansen/py-nrf24/issues/20#issuecomment-739522112, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACSOYVCVMJLTBLHANUYFEKLSTOSG5ANCNFSM4TN4OGFQ .

AluAlbi93 commented 3 years ago

Hi, I have raspberry pi 4 model B(master) with me. I like to connect nrf24L01 to it so that it can communicate with other arduino who also has nrf24L01. I am new to programming and I tried to follow your steps on my pi and getting errors... I am entirely working on pi and not using any pc. My plan is to learn python too.

I got the error when I type the command on raspberry pi terminal pip install nrf24

"Could not find a version that satisfies the requirement nrf24 (from versions: ) No matching distribution found for nrf24"

is it because I have something missing or i should have typed the command somewhere else

This is your reply to the first guy raised this problem My workflow for a new project is typically: $ python3 -m virtualenv venv $ source venv/bin/activate $ python -m pip install nrf24

can i type this in raspberry pi terminal straight away? i did and didnot work

hoping to get a solution from any of you people engaged with this

bjarne-hansen commented 3 years ago

Hi AluAlbi93

Yes, the commands shown there are for running on the command line on the Raspberry Pi. You will need to open a shell and type the commands one after another (the $ sign denotes the prompt - do not enter that).

For example, if you want to create a test project:

$ cd ~/ $ mkdir prj $ cd prj $ mkdir test $ cd test $ python3 -m venv venv $ source venv/bin/activate $ python -m pip install nrf24

Try to do the above - and please let me know the result. You can add a screenshot or copy the text here.

Best regards Bjarne

AluAlbi93 commented 3 years ago

Hi AluAlbi93

Yes, the commands shown there are for running on the command line on the Raspberry Pi. You will need to open a shell and type the commands one after another (the $ sign denotes the prompt - do not enter that).

For example, if you want to create a test project:

$ cd ~/ $ mkdir prj $ cd prj $ mkdir test $ cd test $ python3 -m venv venv $ source venv/bin/activate $ python -m pip install nrf24

Try to do the above - and please let me know the result. You can add a screenshot or copy the text here.

Best regards Bjarne

HI, I have tried it and got the result 1613165122293 My next question is when I run the code below

import pigpio import nrf24 import os.environ as env

Connect to Raspberry Pi

pi = pigpio.pi(env['PIGPIO_HOST'])

Set up NRF24L01 module for reading.

radio = NRF24(pi, ce=25, payload_size=RF24_PAYLOAD.DYNAMIC) radio.open_reading_pipe(RF24_RX_ADDR.P1, [0x01, 0xCE, 0xFA, 0xBE, 0xBA])

while True: while radio.data_ready():

Get pipe, payload.

    pipe = radio.data_pipe()
    payload = radio.get_payload()

    # Convert data to hex.
    hex = ':'.join(f'{i:02x}' for i in payload)

    print(f'Data received on pipe {pipe}: {hex}')

    # Unpack protocol, temperature, and humidity.
    (p, t, h) = struct.unpack('<Bff', payload)

    # Report
    print(f'Temperature: {t}, humidity: {h}')

Traceback (most recent call last): File "test.py", line 3, in import os.environ as env ModuleNotFoundError: No module named 'os.environ'; 'os' is not a package...

should I do something before or WHat is the next step?

AluAlbi93 commented 3 years ago

import pigpio import time from datetime import datetime from nrf24 import * import struct from os import environ as env

if name == "main":

print("Python NRF24 Receiver 01")

# Connect to pigpiod
print("Connecting to:", env.get('PIGPIO_HOST', 'localhost'), env.get('PIGPIO_PORT', 8888))
pi = pigpio.pi(env.get('PIGPIO_HOST', 'localhost'), env.get('PIGPIO_PORT', 8888))
if not pi.connected:
    print("Not connected to Raspberry PI...goodbye.")
    exit()

# Create NRF24L01 communication object.
# On a Raspberry Pi with multiple nrf24l01 transceiver modules we can use one or the other.  Actually, several can be installed and used.
# Please refer to https://pinout.xyz/pinout/spi for information on SPI0: CE0 and CE1, SPI1: CE0, CE1, and CE2 (up to 5 in total).

nrf = NRF24(pi, ce=4, payload_size=RF24_PAYLOAD.DYNAMIC, channel=100, data_rate=RF24_DATA_RATE.RATE_250KBPS)

nrf = NRF24(pi, ce=12, payload_size=RF24_PAYLOAD.DYNAMIC, channel=100, data_rate=RF24_DATA_RATE.RATE_250KBPS, spi_channel=SPI_CHANNEL.AUX_CE2)

# Listen on a bunch of adresses.
nrf.open_reading_pipe(RF24_RX_ADDR.P1, [0x01, 0xCE, 0xFA, 0xBE, 0xBA])
nrf.open_reading_pipe(RF24_RX_ADDR.P2, [0x02, 0xCE, 0xFA, 0xBE, 0xBA])
nrf.open_reading_pipe(RF24_RX_ADDR.P3, [0x03, 0xCE, 0xFA, 0xBE, 0xBA])
nrf.open_reading_pipe(RF24_RX_ADDR.P4, [0x04, 0xCE, 0xFA, 0xBE, 0xBA])

# Wait for device to settle and display the content of device registers.
time.sleep(0.5)
nrf.show_registers()

When I run this code on my rpi directly, I get the following error ...

Python NRF24 Receiver 01 Connecting to: localhost 8888 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Can't connect to pigpio at localhost(8888)

Did you start the pigpio daemon? E.g. sudo pigpiod

Did you specify the correct Pi host/port in the environment variables PIGPIO_ADDR/PIGPIO_PORT? E.g. export PIGPIO_ADDR=soft, export PIGPIO_PORT=8888

Did you specify the correct Pi host/port in the pigpio.pi() function? E.g. pigpio.pi('soft', 8888) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Not connected to Raspberry PI...goodbye.

MY question is When you run the code directly on rpi how does the code change? also the connection to module(nrf24L01), I mean pin...I currently use only one nrf24L01 module and want to communicate with an arduino

bjarne-hansen commented 3 years ago

Dear AluAlbi93

As the error says, you need to have the pigpio daemon running on your Raspberry. The README.md states that the "nrf24" package depends on "pigpiod". However, this seems not to have been totally clear, so I have updated the README.md with the following information:

Before installing and running any of the code and examples below, please make sure you the pigpid daemon running on your Raspberry. This is a library/server that provides access to the GPIO ports of the Raspberry.

Details avalable at http://abyz.me.uk/rpi/pigpio/download.html

Quick installation on Raspbian:

sudo apt-get update
sudo apt-get install pigpio python-pigpio python3-pigpio

Please make sure to install and run the pigpiod daemon. There is good information available on http://abyz.me.uk/rpi/pigpio and on the Internet in general on how to install and use it.

Good luck and happy coding!

//bjarne