ATMEGA48 + NRF24L01 SPI to I2C
1 min read

ATMEGA48 + NRF24L01 SPI to I2C

Recently i buy a pair of ATMEGA48 + NRF24L01 modules, to experiment wireless communication without wifi. Before that, i have try many other modules, such as blutooth to uart, 433MHZ to uart, but never i2c。

the setup is here.

nrf24l01-i2c

The only example code i can found is simple echo with only one byte at a time, which is not every useful. i would like to send a stream of data.

the code is here

sender

#include <Arduino.h>
#include <Wire.h>
const char* msg = "hello world";
void setup(){
        Wire.begin();
}
void loop(){
        size_t len = strlen(msg);
        size_t i = 0;
        while(i< len){
                Wire.beginTransmission(35);
                Wire.write(msg[i]);
                if(Wire.endTransmission()){
                        continue;   //retry!
                }
                i++;
        }
        delay(1000);
}

receiver

#include <Arduino.h>
#include <Wire.h>
void setup(){
        Serial.begin(115200);
        Wire.begin();
}
void loop(){
        Wire.requestFrom(35, 1);
        if(Wire.available()){
                char c = Wire.read();
                if(c != 0x47)
                        Serial.print(c);
        }
        delay(10);
}

the console output is

hello worldhello worldhello worldhelllo worldhello worldhello worldhello worldhello worldhelllo worldhello worldhello worldhello worldhelloo  worldhhelloo worldhello worldhello worldhello worldhelllo worlddhello 

As you may see, there are duplicated datas! After many debug, i have to conclude that is came from the modules, may be caused by the internal resend mechanism! It is a bad thing, as you have to verify the data yourself.

And the transfer speed is low, even close to each other. it drop even further, when take apart a few meters. maybe one byte per second.