Hi, I'm a newbie for Arduino. I have a problem with sending temperature between nrf24l01
who can give me a code TT(TX,RX libaries and how to connect pin with Uno R3) and explain how it work? i'm stuck with this about 2 week. help me plasessss
Hi, I'm a newbie for Arduino. I have a problem with sending temperature between nrf24l01
who can give me a code TT(TX,RX libaries and how to connect pin with Uno R3) and explain how it work? i'm stuck with this about 2 week. help me plasessss
this is a place to start: Arduino Playground - Nrf24L01
If u cannot solve this:
Download the mirf-library, unpack it in the library-folder where arduino is installed..
restart the IDE.
Connect as comments in the code shows..:
Run this code on transmitter:
/**
* SENDEREN / TRANSMITTER
* Hardware SPI:
* Radio MO -> Arduino pin 11 (MOSI)
* Radio MI -> Arduino pin 12 (MISO)
* Radio SCK-> Arduino pin 13 (SCK)
* options:
* Radio CE -> Arduino pin 8 (default - kan endres/can be altered)
* Radio CSN-> Arduino pin 7 (default - kan endres/can be altered)
*/
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
const byte payload=10; // max 32
union {
byte ch[payload];
int val[payload/2];
} buffer; // buffer for 10 bytes => 5 analog values
void setup()
{
Serial.begin(9600);
Mirf.csnPin = 7; // kan endres etter behov. Kan utelates hvis default
Mirf.cePin = 8; // kan endres etter behov. Kan utelates hvis default
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = payload;
Mirf.channel=110; // any channel: 1..120
Mirf.config();
}
void loop()
{
Mirf.setTADDR((byte *)"team1");
for (int i=0;i<5;i++) buffer.val[i]=analogRead(i); // analoRead pin A0..A4
Mirf.send(buffer.ch); // or one can use: Mirf.send((byte *)&buffer);
while (Mirf.isSending()){}; // waut for data sent / vent til data er sendt
delay(200); // pause - thin of receiver capacity to handle incoming data
}
and this on your receiver
/**
* Dette er MOTTAKEREN / RECEIVER
* Hardware SPI:
* Radio MO -> Arduino pin 11 (MOSI)
* Rasio MI -> Arduino pin 12 (MISO)
* Radio SCK-> Arduino pin 13 (SCK)
* Valgvare:
* Radio CE -> Arduino pin 8 (dette er defaultverdier. kan endres)
* Radio CSN-> Arduino pin 7 (dette er defaultverdier. kan endres)
*/
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h> //uvisst hva denne gjør !!
const byte payload=10; // max 32
union {
byte ch[payload];
int val[payload/2];
} buffer; // buffer for 10 bytes => 5 analog values
void setup()
{
Serial.begin(9600);
Mirf.csnPin = 7; // kan endres etter behov. Kan utelates hvis default
Mirf.cePin = 8; // kan endres etter behov. Kan utelates hvis default
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = payload;
Mirf.channel=110; // match sender
Mirf.config();
}
void loop()
{
Mirf.setRADDR((byte *)"team1"); // nettnavn=nettadresse
while(!Mirf.dataReady()){}; // vent til data er mottatt
Mirf.getData(buffer.ch); // or Mirf.getData((byte *)&buffer);
for (int i=0; i<5; i++)
{
Serial.print(buffer.val[i]) ;
Serial.print("\t");
}
Serial.println();
}
Thank you very much,It's work. But there have some error ex. when dht11(at tx) get temperature 32 c but rx recive 8 c, I don't know why ,and humidity has also same problem.(sorry for my eng. skill)
post link to the library - and the code for the tansmitter
I found this one ? GitHub - adafruit/DHT-sensor-library: Arduino library for DHT11, DHT22, etc Temperature & Humidity Sensors
uses float, which requires 4 bytes, compiled for an "uno"
solve this by changing datastructure.
for transmitter: complete example:
/**
* SENDEREN / TRANSMITTER
* Hardware SPI:
* Radio MO -> Arduino pin 11 (MOSI)
* Radio MI -> Arduino pin 12 (MISO)
* Radio SCK-> Arduino pin 13 (SCK)
* options:
* Radio CE -> Arduino pin 8 (default - kan endres/can be altered)
* Radio CSN-> Arduino pin 7 (default - kan endres/can be altered)
*/
#include <SPI.h>
#include <Mirf.h>
#include <nRF24L01.h>
#include <MirfHardwareSpiDriver.h>
#include <MirfSpiDriver.h>
const byte payload=10; // max 32
union
{
byte ch[payload]; // 10 bytes
struct
{
float temp; // 4 bytes
float humi; // 4 bytes
int extra; // 2 bytes
};
} buffer; // buffer for 10 bytes => 5 analog values
void setup()
{
Serial.begin(9600);
Mirf.csnPin = 7; // kan endres etter behov. Kan utelates hvis default
Mirf.cePin = 8; // kan endres etter behov. Kan utelates hvis default
Mirf.spi = &MirfHardwareSpi;
Mirf.init();
Mirf.payload = payload;
Mirf.channel=110; // any channel: 1..120
Mirf.config();
}
void loop()
{
Mirf.setTADDR((byte *)"team1");
buffer.temp=25.2; //example.. read from dht11
buffer.humi=40.5; //example.. read from dht11
Mirf.send(buffer.ch); // or one can use: Mirf.send((byte *)&buffer);
while (Mirf.isSending()){}; // waut for data sent / vent til data er sendt
delay(200); // pause - thin of receiver capacity to handle incoming data
}
same change for reveiver.
Thank you again, humidity work pretty fine but temp is not (ex.ght11 get 25c and send but rx get8.50)how can i fix this or must i connect capacitor to the nrf24l01.