nrf24l01 not working in mixed environment
Posted: Tue May 15, 2018 8:38 am
I have a simple sensorbox that communicates using nrf24l01-PA-LNA modules. Using Arduino sketches for sending/receiving works but I would like to switch to MicroPython. So I got an ESP board that can run MicroPython to test the connectivity with the sensorbox using the nrf24l01 driver. I can not get it to work.
For the sensorbox I use a simple Arduino Compatible Pro Mini and for the receiving side I've now got the MicroPython capable ESP12F board. The sender (Pro Mini) runs the Arduino code. When I use Arduino code on the receiver side (ESP12) it works. However, using MicroPython at the receiver side doesn't.
I really would like to use MicroPython. I hoped to get started with it on the receiver side only so I can leave my sensor code in place. But is that the problem? Can I not mix Arduino on sender and MicroPython on receiver? Why? Or am I missing something here?
By the way, the SPI setup is working. And I use the exact same pins for both Arduino/MicroPython.
See code below.
Thnx,
Majodi
This is the simplified test code:
===> Arduino code on sender:
#include "nRF24L01.h"
#include "RF24.h"
// Pro-Mini
#define CE 7
#define CSN 8
RF24 radio(CE, CSN);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup() {
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.setDataRate( RF24_250KBPS );
radio.setChannel(100);
radio.powerUp() ;
}
void loop() {
Serial.println("AA");
radio.write("AA", 2);
delay(3000);
}
===> Working Arduino code on receiver:
#include "nRF24L01.h"
#include "RF24.h"
// Nano or ESP12F DEVKIT V3
#define CE 2 //nano 7 - esp12f 4 of 2 (dit zijn GPIO nummers!)
#define CSN 15 //nano 8 - esp12f 15 (dit zijn GPIO nummers!)
RF24 radio(CE, CSN);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup() {
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.setDataRate( RF24_250KBPS );
radio.setChannel(100);
radio.powerUp() ;
radio.startListening();
Serial.println("RX ready...");
}
void loop() {
while (radio.available()) {
Serial.println("available!!");
char inStr[15] = {0};
radio.read(&inStr, 2);
Serial.println(inStr);
}
}
===> Now the NOT Working MicroPython code on receiver:
import utime
from machine import Pin, SPI
from nrf24l01 import NRF24L01
pipes = (b'\xf0\xf0\xf0\xf0\xe1', b'\xf0\xf0\xf0\xf0\xd2')
def readSensorLoop():
spi = SPI(1)
csn = Pin(15, mode=Pin.OUT, value=1) # 4
ce = Pin(2, mode=Pin.OUT, value=0) # 5
nrf = NRF24L01(spi, csn, ce, channel=100)
nrf.open_tx_pipe(pipes[1])
nrf.open_rx_pipe(1, pipes[0])
nrf.start_listening()
print('readSensorLoop, waiting for packets... (ctrl-C to stop)')
while True:
utime.sleep(1)
if nrf.any():
print('received something!!')
readSensorLoop()
For the sensorbox I use a simple Arduino Compatible Pro Mini and for the receiving side I've now got the MicroPython capable ESP12F board. The sender (Pro Mini) runs the Arduino code. When I use Arduino code on the receiver side (ESP12) it works. However, using MicroPython at the receiver side doesn't.
I really would like to use MicroPython. I hoped to get started with it on the receiver side only so I can leave my sensor code in place. But is that the problem? Can I not mix Arduino on sender and MicroPython on receiver? Why? Or am I missing something here?
By the way, the SPI setup is working. And I use the exact same pins for both Arduino/MicroPython.
See code below.
Thnx,
Majodi
This is the simplified test code:
===> Arduino code on sender:
#include "nRF24L01.h"
#include "RF24.h"
// Pro-Mini
#define CE 7
#define CSN 8
RF24 radio(CE, CSN);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup() {
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.setDataRate( RF24_250KBPS );
radio.setChannel(100);
radio.powerUp() ;
}
void loop() {
Serial.println("AA");
radio.write("AA", 2);
delay(3000);
}
===> Working Arduino code on receiver:
#include "nRF24L01.h"
#include "RF24.h"
// Nano or ESP12F DEVKIT V3
#define CE 2 //nano 7 - esp12f 4 of 2 (dit zijn GPIO nummers!)
#define CSN 15 //nano 8 - esp12f 15 (dit zijn GPIO nummers!)
RF24 radio(CE, CSN);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup() {
Serial.begin(115200);
radio.begin();
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.setDataRate( RF24_250KBPS );
radio.setChannel(100);
radio.powerUp() ;
radio.startListening();
Serial.println("RX ready...");
}
void loop() {
while (radio.available()) {
Serial.println("available!!");
char inStr[15] = {0};
radio.read(&inStr, 2);
Serial.println(inStr);
}
}
===> Now the NOT Working MicroPython code on receiver:
import utime
from machine import Pin, SPI
from nrf24l01 import NRF24L01
pipes = (b'\xf0\xf0\xf0\xf0\xe1', b'\xf0\xf0\xf0\xf0\xd2')
def readSensorLoop():
spi = SPI(1)
csn = Pin(15, mode=Pin.OUT, value=1) # 4
ce = Pin(2, mode=Pin.OUT, value=0) # 5
nrf = NRF24L01(spi, csn, ce, channel=100)
nrf.open_tx_pipe(pipes[1])
nrf.open_rx_pipe(1, pipes[0])
nrf.start_listening()
print('readSensorLoop, waiting for packets... (ctrl-C to stop)')
while True:
utime.sleep(1)
if nrf.any():
print('received something!!')
readSensorLoop()