User avatar
DougieLawson
Posts: 36813
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: DS18b20 rx on pi

Wed Apr 01, 2015 11:40 pm

I wrote the bug fix code for spidev for the 3.18 kernel.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

lawfix
Posts: 19
Joined: Sun Jan 11, 2015 10:58 pm

Re: DS18b20 rx on pi

Thu Apr 02, 2015 9:24 pm

Dear all,

First i check is my SPI was on, and everything is ok.

I install all the app that's you recommand :

apt-get install python-dev
apt-get install python3-dev
apt-get install python-pip
apt-get install python3-pip
pip install spidev
pip-3.2 install spidev

So now, the error is different :

[email protected]:~# python nRF24Reader.py
Traceback (most recent call last):
File "nRF24Reader.py", line 172, in <module>
radio.begin(0, 17)
File "/root/lib_nrf24.py", line 384, in begin
self.write_register(NRF24.SETUP_RETR, (0b0100 << NRF24.ARD) | 0b1111)
File "/root/lib_nrf24.py", line 245, in write_register
return self.spidev.xfer2(buf)[0]
IOError: [Errno 22] Invalid argument


I check my wires and the program ./gettingstarted with the Arduino with the Gettingstarted program and everything is ok

danjperron
Posts: 3431
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18b20 rx on pi

Thu Apr 02, 2015 10:25 pm

can't do it without sudo unless PI has permission to handle /dev/spidev0.0

danjperron
Posts: 3431
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18b20 rx on pi

Thu Apr 02, 2015 11:23 pm

Also what is your connection between the nRF24L01 to the PI?

Could you put your schematic?

User avatar
DougieLawson
Posts: 36813
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: DS18b20 rx on pi

Thu Apr 02, 2015 11:33 pm

danjperron wrote:can't do it without sudo unless PI has permission to handle /dev/spidev0.0
Latest versions of Raspbian have user pi in group spi and i2c so it can access those buses without needing sudo.

sudo apt-get update && sudo apt-get dist-upgrade
should make that happen with the 3.18.7 kernel.

If not
sudo adduser pi spi
sudo adduser pi i2c
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

danjperron
Posts: 3431
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18b20 rx on pi

Thu Apr 02, 2015 11:58 pm

Thank's Dougie for this clarification.

But I think that I need his schematic first. I should put mine But I just got my Arduino pro mini at 3.3V and I'm making the module right now, solder and all that stuff. I will put it later.

I will try the update and upgrade bevause right now I really need to have the sudo .

I'm using the PI2 there and I just launch the upgrade right now!

danjperron
Posts: 3431
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18b20 rx on pi

Fri Apr 03, 2015 2:25 am

OK this is the pin out on How I connect the nRF24L01 to the Raspberry PI GPIO

Code: Select all

nRF24L01       Raspberry PI
PIN                  PIN      description
1                      1          GND
2                      6          3.3V power
3                      17        3.3V     nRF24L01 CE
4                      24        SPI CE0 N
5                      23        SPI CLK
6                      19        SPI MOSI
7                      21        SPI MISO
I just finish to assemble my prototype using a DS18B20. I did decide to use 3 x 357 cell type just for fun. The batteries are old . The package specify better before 2008 but I just want to see if I could use this type. And Yes it is running!

Image

P.S. Capacitor on the transmitter is needed otherwise it won't work. I put a 10uF there.

danjperron
Posts: 3431
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18b20 rx on pi

Fri Apr 03, 2015 2:36 am

The lib_nrf24.py library uses the GPIO. This is why you need the sudo prefix.

Since we are not using the CE pin, it is possible to modify the class and remove the GPIO. Then you won't need GPIO access and the sudo prefix won't be needed.


Daniel

danjperron
Posts: 3431
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18b20 rx on pi

Fri Apr 03, 2015 3:07 am

I just update the DS18B20 in the github.

https://github.com/danjperron/nRF24L01_With_Sensor.git

It is now using the sleep mode. Check the schematic.

When Arduino is reading the sensor and is waiting to send , the current is around 16 ma and the rest of the time it will be around 28µA.

Daniel

lawfix
Posts: 19
Joined: Sun Jan 11, 2015 10:58 pm

Re: DS18b20 rx on pi

Fri Apr 03, 2015 8:58 am

Hello,

This is my pin :

Raspberry ====> NRF24L01

3v3 ==> VCC
GND ===> GND
CE0 ===> CSN
SCLK ===> SCK
MISO ==> MISO
MOSI ==> MOSI
GPIO22 => CE

I don't need to do sudo command because i'm running my pi in root mode.

I think i just need to adapt the program to my wire, don't you ?

danjperron
Posts: 3431
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: DS18b20 rx on pi

Fri Apr 03, 2015 1:18 pm

Try to put CE at 3.3V like I did.

You will need to check the lib_nrf24.py for correct operation if you use CE with a GPIO.

This is your error code anyway. The application doesn't see the transmitter.

lawfix
Posts: 19
Joined: Sun Jan 11, 2015 10:58 pm

Re: DS18b20 rx on pi

Tue Apr 14, 2015 9:55 pm

Dear all !!

I came back to you after some travels for business.

Since this long time i find a way with this new code found on the internet

Arduino Side

Code: Select all

#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>

OneWire oneWire(2);

DallasTemperature sensors(&oneWire);

// ce,csn pins
RF24 radio(9,10);

unsigned char data[3] = {
  0};
unsigned long count=0;
void setup(void)
{
  sensors.begin();  
  Serial.begin(57600);
  Serial.println("**************V1 Send Sensor Data***********");
  radio.begin();
  radio.setPALevel(RF24_PA_LOW);
  radio.setChannel(0x4c);

  // open pipe for writing
  radio.openWritingPipe(0xF0F0F0F0E1LL);

  radio.enableDynamicPayloads();
  radio.setAutoAck(true);
  radio.powerUp();
  Serial.println("...Sending");
}

void loop(void)
{
  sensors.requestTemperatures();
  float currentTemp;
  currentTemp = sensors.getTempCByIndex(0);

  //assign 'T' to represent a Temperature reading
  data[0] = 'T';
  data[1] = currentTemp;
  count++;
  // print and increment the counter
  radio.write(data, sizeof(float)+1);
  Serial.print("Temperature sent:  ");
  Serial.println(currentTemp);
  // pause a second
  delay(500);
}
And on the other side i used the Rpi-hub with some modification :

Code: Select all


/* 
 *
 *  Filename : rpi-hub.cpp
 *
 *  This program makes the RPi as a hub listening to all six pipes from the remote sensor nodes ( usually Arduino )
 *  and will return the packet back to the sensor on pipe0 so that the sender can calculate the round trip delays
 *  when the payload matches.
 *  
 *  I encounter that at times, it also receive from pipe7 ( or pipe0 ) with content of FFFFFFFFF that I will not sent
 *  back to the sender
 *
 *  Refer to RF24/examples/rpi_hub_arduino/ for the corresponding Arduino sketches to work with this code.
 * 
 *  
 *  CE is not used and CSN is GPIO25 (not pinout)
 *
 *  Refer to RPi docs for GPIO numbers
 *
 *  Author : Stanley Seow
 *  e-mail : [email protected]
 *  date   : 6th Mar 2013
 *
 * 03/17/2013 : Charles-Henri Hallard (http://hallard.me)
 *              Modified to use with Arduipi board http://hallard.me/arduipi
 *						  Changed to use modified bcm2835 and RF24 library 
 *
 *
 */

#include <cstdlib>
#include <iostream>
#include <RF24/RF24.h>

using namespace std;

// Radio pipe addresses for the 2 nodes to communicate.
// First pipe is for writing, 2nd, 3rd, 4th, 5th & 6th is for reading...
const uint64_t pipes[6] = 
					{ 0xF0F0F0F0D2LL, 0xF0F0F0F0E1LL, 
						0xF0F0F0F0E2LL, 0xF0F0F0F0E3LL, 
						0xF0F0F0F0F1, 0xF0F0F0F0F2 
					};

// CE Pin, CSN Pin, SPI Speed

// Setup for GPIO 22 CE and GPIO 25 CSN with SPI Speed @ 1Mhz
//RF24 radio(RPI_V2_GPIO_P1_22, RPI_V2_GPIO_P1_18, BCM2835_SPI_SPEED_1MHZ);

// Setup for GPIO 22 CE and CE0 CSN with SPI Speed @ 4Mhz
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); 

// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);  


void setup(void)
{
    // init radio for reading
    radio.begin();
    radio.enableDynamicPayloads();
    radio.setAutoAck(1);
    radio.setRetries(15,15);
    radio.setDataRate(RF24_1MBPS);
    radio.setPALevel(RF24_PA_MAX);
    radio.setChannel(76);
    radio.setCRCLength(RF24_CRC_16);
    radio.openReadingPipe(1,0xF0F0F0F0E1LL);
    radio.startListening();
}

void loop(void)
{
    // 32 byte character array is max payload
    char receivePayload[32];
    time_t t = time(0);   // get time now
    struct tm * now = localtime( & t ); // Get curret Time.

    while (radio.available())
    {
         // read from radio until payload size is reached
        uint8_t len = radio.getDynamicPayloadSize();
        radio.read(receivePayload, len);

        // display payload
        cout << (now->tm_year + 1900) << '-' 
        << (now->tm_mon + 1) << '-'
        <<  now->tm_mday << ' '
        << now->tm_hour << ':'
        << now->tm_min << ' '
        << receivePayload << endl;
    }
}

int main(int argc, char** argv) 
{
    setup();
    while(1)
        loop();

    return 0;
}

But it's wird because the result is :

Image

I wonder what is wrong with the code because unless he send the temperature, he send a big T !

warwolf7
Posts: 6
Joined: Wed Dec 23, 2015 8:41 pm

Re: DS18b20 rx on pi

Wed Aug 31, 2016 1:50 am

Hi,

I just want to say a Big thank you

enabling SPI in raspi-config
and
installing

Code: Select all

sudo bash
apt-get install python-dev
apt-get install python3-dev
apt-get install python-pip
apt-get install python3-pip
pip install spidev
pip-3.2 install spidev
exit
solved my error

Code: Select all

Traceback (most recent call last):
File "nRF24Reader.py", line 172, in <module>
radio.begin(0,17)
File "/root/lib_nrf24.py", line 373, in begin
self.spidev.open(0, csn_pin)
IOError: [Errno 2] No such file or directory
Thank you very much. I don't write a lot on forum, but one day, I'll be able to help someone like you do.

Return to “Python”