Send Packets from nRF24L01+ to micro:bit (nRF52833)

Hi,

my son is starting to learn programming and wants to do something hardware related. We found out about the BBC Micro:Bit which can be programmed with Python via a variant of Micropython.

I had a old development Board (r0cket) containing a nRF24L01+ around and I thought it would be nice to make them communicate.

The Problem is, that I can't get the micro:bit receive packets send by the r0cket. I looked into the initalization code of the microbit and the one of the r0cket and I think that I configured both endpoints correctly. You can find my code of both sides below. As a proof of conecpt my first goal is to show the char send by the r0cket on the micro:bit screen.

I am relativly fluent in C and hardware near programming and therefore not fixed on the library on the nRF24L01+ side of things. I would however prefer to stay with this setup. On the micro:bit side of things I would prefer not to overload the learning curve with switching away from the micro:bit micropython environment.

I hope someone can point me into the right direction.

Here is my Micro:Bit code:

from microbit import *
import radio

display.scroll("i")
radio.config(channel=7,length=1,address=0xE7E7E7E7,group=0xE7,data_rate=radio.RATE_2MBIT)
radio.on()
display.scroll("d")
display.set_pixel(0,0,9)
while True:
    message = radio.receive_bytes()
    if message:
        display.scroll("r:"+str(message))

And this is my r0cket code:

#include <sysinit.h>
#include <string.h>

#include "basic/basic.h"
#include "basic/config.h"

#include "lcd/render.h"
#include "lcd/print.h"

#include "funk/nrf24l01p.h"
#include "filesystem/ff.h"

#include "usetable.h"

/****************************************************************/
/* r0ket l0dable to send keys as an Microsoft keyboard          */
/* expects a KBD.MAC file containing lines with channel and mac */
/* expects a KBD.TXT file containing <stuff to send>            */
/*                                                              */
/* crsr right/left changes through channel/mac                  */
/* crsr enter      exits                                        */
/****************************************************************/

#define MAC_TABLE_SIZE 50

typedef uint16_t crc;

void setup_send();
void blink(int count);

unsigned char left_char = 'l';
unsigned char right_char = 'r';
unsigned char up_char = 'u';
unsigned char down_char = 'd';
unsigned char enter_char = 'e';
unsigned char none_char = 'n';

struct NRF_CFG config =
{
   .channel= 7,
   .txmac= "\xE7E7E7E7E7",
   .nrmacs=1,
   .mac0=  "\xE7E7E7E7E7",
   .maclen = 1,
};

//This is called by the environment
void ram(void) {
    uint8_t last_key = BTN_NONE;
    blink(2);
    nrf_init();
    nrf_config_set(&config);
    nrf_write_reg(R_CONFIG,
            R_CONFIG_PWR_UP|  // Power on
            R_CONFIG_EN_CRC|  // CRC on, double byte
            R_CONFIG_CRCO
            );
    nrf_write_reg(R_FEATURE,
            R_FEATURE_EN_DPL | R_FEATURE_EN_DYN_ACK | R_FEATURE_EN_ACK_PAY // Enable dynamic payload length
            );
    nrf_write_reg(R_DYNPD,
            R_DYNPD_DPL_P0 // Enable dynamic payload length
            );
    blink(2);
    while(true) {
        uint8_t key;

        key=getInputRaw();

        if(key!=last_key){
            last_key = key;
                        gpioSetValue (RB_LED0, key == BTN_LEFT || key == BTN_DOWN || key == BTN_ENTER);
                        gpioSetValue (RB_LED1, key == BTN_LEFT || key == BTN_UP || key == BTN_ENTER);
                        gpioSetValue (RB_LED3, key == BTN_UP || key == BTN_RIGHT || key == BTN_ENTER);
                        gpioSetValue (RB_LED2, key == BTN_RIGHT || key == BTN_DOWN || key == BTN_ENTER);

            if(key == BTN_LEFT) nrf_snd_pkt(1,&left_char);
            if(key == BTN_RIGHT) nrf_snd_pkt(1,&right_char);
            if(key == BTN_UP) nrf_snd_pkt(1,&up_char);
            if(key == BTN_DOWN) nrf_snd_pkt_crc(1,&down_char);
            if(key == BTN_ENTER) nrf_snd_pkt_crc(1,&enter_char);
            if(key == BTN_NONE) nrf_snd_pkt_crc(1,&none_char);
        };
        delayms(100);
    }
}

void blink(int count){
    gpioSetValue (RB_LED0, 0);
    delayms(200);
    for(int i=1; i<=count; i++){
      gpioSetValue (RB_LED0, 1);
      delayms(100);
      gpioSetValue (RB_LED0, 0);
      delayms(100);
    }
}

Related