S
S
sdvdio2014-05-12 22:35:26
Arduino
sdvdio, 2014-05-12 22:35:26

How to transfer data via nrf24l01+?

Need help ! This is the last place I can turn to for help, they refused everywhere ! I want to assemble the following construction: PROCESSING takes some information from the virtual midi port and sends it to the serialport

//Import libraries
import processing.serial.*;
import promidi.*;

Serial myPort;
MidiIO midiIO;
//Message to be sent
int message=0;

void setup() {  
  myPort = new Serial(this, "COM4", 9600);
  midiIO = MidiIO.getInstance(this);
  //Line that prints I/O devices in console
  midiIO.printDevices();
  //Receive input from Virtual MIDI Ports
  midiIO.openInput(0,0);
}

void draw() {}
void noteOn(Note note, int deviceNum, int midiChan){
  int vel = note.getVelocity();
  int pitch = note.getPitch();
  if(vel>0){ // If velocity > 0 set message value to note's pitch
   if(pitch==60){ message=1; } else 
   if(pitch==61){ message=2; } else 
   if(pitch==62){ message=3; } else 
   if(pitch==63){ message=4; } else
   if(pitch==64){ message=5; } else 
   if(pitch==65){ message=6; } else
   if(pitch==66){ message=7; } else
   if(pitch==67){ message=8; } else message=0;
    } else { message=0;}
  //Send message to Arduino
  myPort.write(message);
}

arduino with NRF24I01+ radio module on board connected to PC listening to serialport receiving data { message=1; }{message=2; }{message=3; }.... and sends them to the next arduino with the same construct. It receives data and performs a certain action (on/off LED).
Now the question is if you do not use the radio module and work directly through the serialport, everything works fine "PROCESSING ---->>> ARDUINO" (arduino code):
// Data received from the serial port
 int val; 
 //LEDs are connected to the following pins
 int pins[] = {1,2,3,4,5,6,7,8}; 
 
 void setup() {{
   pinMode(pins[1], OUTPUT); // Set pins as OUTPUTs
   pinMode(pins[2], OUTPUT); // Set pins as OUTPUTs
   pinMode(pins[3], OUTPUT); // Set pins as OUTPUTs
   pinMode(pins[4], OUTPUT); // Set pins as OUTPUTs
   pinMode(pins[5], OUTPUT); // Set pins as OUTPUTs
   pinMode(pins[6], OUTPUT); // Set pins as OUTPUTs
   pinMode(pins[7], OUTPUT); // Set pins as OUTPUTs
   pinMode(pins[8], OUTPUT); // Set pins as OUTPUTs
   }
   Serial.begin(9600); // Start serial communication at 9600 bps
 }
 
 void loop() {
 if (Serial.available()) { // If data is available to read,
 val = Serial.read(); // read it and store it in val
 // Turn on LEDs, depending on pitches received
  if (val == 1) { digitalWrite(pins[1],HIGH); } else
  if (val == 2) { digitalWrite(pins[2],HIGH); } else
  if (val == 3) { digitalWrite(pins[3],HIGH); } else
  if (val == 4) { digitalWrite(pins[4],HIGH); } else
  if (val == 5) { digitalWrite(pins[5],HIGH); } else
  if (val == 6) { digitalWrite(pins[6],HIGH); } else
  if (val == 7) { digitalWrite(pins[7],HIGH); } else
  if (val == 8) { digitalWrite(pins[8],HIGH); } else
  if (val==0) { resetLEDs(); }
 }
 }
 //Function that turns all the LEDs off
 void resetLEDs(){{
   digitalWrite(pins[1],LOW);
   digitalWrite(pins[2],LOW);
   digitalWrite(pins[3],LOW);
   digitalWrite(pins[4],LOW);
   digitalWrite(pins[5],LOW);
   digitalWrite(pins[6],LOW);
   digitalWrite(pins[7],LOW);
   digitalWrite(pins[8],LOW);
  } 
 }

Now I hook NRF24I01 + and get the following construction "PROCESSING -->> ARDUINO transmits ---->> ARDUINO receives and executes" the processing code, I leave the same
ARDUINO transmitter code:
#include <SPI.h>
#include "RF24.h"
RF24 radio(9, 10);
const uint64_t pipe= {
0xF0F0F0F000LL};// адреса каналов приема и передачи
void setup(){
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_250KBPS); // Скорость передачи
radio.setChannel(100); // Номер канала от 0 до 127
radio.setRetries(15,15); // Кол-во попыток и время между попытками
radio.openWritingPipe(pipe); // Открываем канал передачи
radio.startListening(); // Начинаем слушать эфир
}

void loop(){
if(Serial.available()){
char data[32] = "";
byte i = 0;
while(Serial.available()){
data[i] = Serial.read(); //получаем данные из сериал.
i++;
delay(2);
}
data[i] = 0;
radio.stopListening();
radio.write(&data, 32); //и отправляем их в Arduino №2
radio.startListening();
}
}

ARDUINO receiver code:
#include <SPI.h>
#include "RF24.h"
RF24 radio(9, 10);
//пины куда подключены светодиоды
int pins[] = {1,2,3,4,5,6,7,8}; 
const uint64_t pipe = {
0xF0F0F0F000LL};// адреса каналов приема и передачи

void setup(){
  for(int i=0; i<8; i++){
  pinMode(pins[i], OUTPUT); // Set pins as OUTPUTs
  }
radio.begin();
radio.setDataRate(RF24_250KBPS); // Скорость передачи
radio.setChannel(100); // Номер канала от 0 до 127
radio.setRetries(15,15); // Кол-во попыток и время между попытками
radio.openReadingPipe(1,pipe); // Открываем один из 6-ти каналов приема
radio.startListening(); // Начинаем слушать эфир
}

void loop(){
if(radio.available()){
char data[32] = "";
radio.read(&data, 32); //принимает пакет с Arduino №1
//Если пришла цифра 1 включаем светодиод
if (data[0] == '1') { digitalWrite(pins[0],HIGH); } else
if (data[0] == '2') { digitalWrite(pins[1],HIGH); } else
if (data[0] == '3') { digitalWrite(pins[2],HIGH); } else
if (data[0] == '4') { digitalWrite(pins[3],HIGH); } else
if (data[0] == '5') { digitalWrite(pins[4],HIGH); } else
if (data[0] == '6') { digitalWrite(pins[5],HIGH); } else
if (data[0] == '7') { digitalWrite(pins[6],HIGH); } else
if (data[0] == '8') { digitalWrite(pins[7],HIGH); } else
if (data[0] == '0') { resetLEDs(); }
}
}

void resetLEDs(){
for(int i=0; i<8; i++){
digitalWrite(pins[i],LOW);
  } 
 }

I start, and the receiver is silent. It only works when you transfer data yourself through
4b5d6889595f4865a01b65a507b61516.pngHelp fix the code!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Chernysh, 2015-10-08
@chernish2

Or maybe it's not in the code?
They say that these radio modules are sensitive to power, they work at 3.3V and not at 5V.
What food do you have?
They also say that a capacitor must be soldered there: forum.amperka.ru/threads/nrf24l01-%D0%BF%D0%BE%D0%...
I myself struggle with the same until I can make it work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question