Yes, I put capacitor between GND and 3.3V and nRF24 works great when I deleted "void reciveEvent(int HowMany). It isn't problem with power supply, but with program I think. Here you are all codes which I use.
ethernet program:
#include <EtherCard.h>
#include <Wire.h>
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,1,22 };
static byte gwip[] = { 192,168,1,1 };
byte Ethernet::buffer[700];
const char page[] PROGMEM =
"HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<html>"
"<head><title>"
"Ardiuno"
"</title></head>"
"<body>"
"<h3>Hello</h3>"
"<p><em>"
"Working
"
"Everything OK"
"</em></p>"
"</body>"
"</html>"
;
int lederror = 4;
void setup ()
{
Wire.begin();
Serial.begin(9600);
pinMode(lederror, OUTPUT);
Serial.println("Ethernet chip");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println("Ethernet not available");
#if STATIC
Serial.println( "Setting static IP");
if (!ether.staticSetup(myip, gwip))
{
Serial.println( "Static IP no available");
Error(); // blink forever to indicate a problem
}
#else
Serial.println("Setting IP using DHCP");
if (!ether.dhcpSetup())
{
Serial.println("DHCP error");
Error(); // blink forever to indicate a problem
}
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(strstr((char *)Ethernet::buffer + pos, "GET /light") != 0)
{
Wire.beginTransmission(2);
Wire.write(1);
Wire.endTransmission();
}
// show some data to the user
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
}
void Error()
{
while (true)
{
digitalWrite(lederror, HIGH);
}
}
nRF24 writer:
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <Wire.h>
#include <SPI.h>
RF24 radio(9,10);
const uint64_t pipe = 0xDEDEDEDAA2LL;
int status_led = 4;
int rx[1];
int x;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(pipe);
Wire.begin(2);
Wire.onReceive(receiveEvent);
Serial.println("nRF24 chip");
pinMode(status_led, OUTPUT);
}
void loop()
{
radio.write(rx, sizeof(rx));
delay(1000);
}
void receiveEvent(int howMany)
{
x = Wire.read();
Serial.println(x);
rx[0] = x;
}
Client nRF24:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
int swiatlo = 3;
int lederror = 6;
int rx[1];
RF24 radio(9,10);
const uint64_t pipe = 0xDEDEDEDAA2LL;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
Serial.println("Client chip (RECEIVE)");
pinMode(swiatlo, OUTPUT);
pinMode(lederror, OUTPUT);
}
void loop()
{
if (radio.available())
{
Serial.println("radio dostepne");
digitalWrite(lederror, LOW);
radio.read(rx, sizeof(rx));
Serial.print("X = ");
Serial.print(rx[0]);
Serial.println();
if (rx[0] == 1)
{
digitalWrite(swiatlo, HIGH);
Serial.println(" swiatlo ON");
}
else
{
digitalWrite(swiatlo, LOW);
Serial.println("swiatlo OFF");
}
}
else
{
Serial.println("radio niedostepne");
digitalWrite(lederror, HIGH);
}
delay(1000);
}