Forum: Mikrocontroller und Digitale Elektronik Datenübertragung mit NRF24le1 auf A. Nano als interrupt


von Constantin T. (cosmonaut)


Lesenswert?

Hey liebe Gemeinde.
Ich versuche eine drahtlose Steuerung eines LED Stripe zu bauen.
Dafür benutze ich 2 Arduino Nano´s die mit einem NRF24le1 Chip 
miteinander kommunizieren sollen.
Arduino 1 dient als Controller/Master und hat 3 buttons und 1 fader, die 
für die Wahl des jeweiligen Lichtmodus/Blackout, sowie  die 
Lichtintensität dienen sollen.
Die Werte möchte ich als 6 Byte ( button1, button2, button3, 
faderintensiät) übertragen und auf dem 2. Arduino empfangen.
Es werden nicht nicht konstant Werte geschickt, sondern nur bei 
Veränderung der Values.
Auf dem 2. Nano sollen dann jeweils per interupt Flags aktiviert werden, 
wenn ein Button gedrückt wurde und die aktuelle Value vom Fader gehalten 
werden, damit der Loop frei bleibt und dort über den RGBW Led Stripe, je 
nachdem welche flag gewählt ist, iteriert werden kann.

Leider kommt beim Receiver nicht das an was ankommen soll, bzw, seitdem 
ich den attachInterrupt mit eingebaut habe, auch gar kein Interrupt.

Gibt es Probleme weil ich uint8_t values übertrage?
Und wie kann ich den Interrupt auslösen?


Mein Code für den Controller sieht wie folgt aus:
//-----------------------------
[c]

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define NUM_BUTTONS  3
//Constants
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";     //Byte of array representing the 
address. This is the address where we will send the data. This should be 
same on the receiving side.
//-----------------------------
//---------Must be hardware implemented

const uint8_t button1 = 2;
const uint8_t button2 = 3;
const uint8_t button3 = 4;

const int intensityPot = 0;

const uint8_t buttons[NUM_BUTTONS] = {button1, button2, button3};
//-----------------------------

//Variables
boolean button_state [NUM_BUTTONS] = {0, 0, 0};
uint8_t message_old[6] = {0, 0, 0, 0, 0, 0};
uint8_t message[6] = {0, 0, 0, 0, 0, 0};



uint8_t intensity;

void setup() {
  Serial.begin(9600);

  for (int i = 0; i < NUM_BUTTONS; i++)
    pinMode(buttons[i], INPUT_PULLUP);
  //pinMode(potPin, INPUT);

  radio.begin();                  //Starting the Wireless communication
  radio.openWritingPipe(address); //Setting the address where we will 
send the data
  radio.setPALevel(RF24_PA_MIN);  //You can set it as minimum or maximum 
depending on the distance between the transmitter and receiver.
  radio.stopListening();          //This sets the module as transmitter
}

void loop() {
  readButtons();
  readIntensity();
  if(updateMessage() == true){
    for(int i=0; i<6; i++){
      message_old[i] = message[i];
    }
    printMessage();
    sendMessage();
  }

}

void sendMessage(){
  radio.write(&message, sizeof(message));
}


void printMessage(){
  for(int i = 0; i < 6; i++){
    Serial.print(message[i]);//Sending the message to receiver
  }
  Serial.println("");

}


boolean updateMessage(){
  for(int i = 0; i < 6 ; i++){
    if(message[i] != message_old[i]){
      return true;
    }
  }
  return false;
}


void readButtons(){
  for (int i = 0; i < NUM_BUTTONS; i++)
  {
    if (digitalRead(buttons[i]) == LOW)
    {
      /*
      Serial.print("button ");
      Serial.print(i);//Sending the message to receiver
      Serial.println(" pressed." );
      */
      //bitWrite(pressedButtons, i, 1);
      button_state[i] = 1;
      message[i] = 1;
    }
    else{
      button_state[i] = 0;
      message[i] = 0;
    }
  }
  delay(50);

}

void readIntensity()
{
  int val = analogRead(intensityPot);
  intensity = (uint8_t) (map(val, 0, 1023, 0, 255));
  uint8_t intensity_001 = intensity % 10;
  uint8_t intensity_010 = ((intensity-intensity_001)%100)/10;
  uint8_t intensity_100 = (intensity-intensity_010-intensity_001)/100;
  message[3] = intensity_100;
  message[4] = intensity_010;
  message[5] = intensity_001;
  //Serial.print("fader intensity: ");
  //Serial.println(intensity);//Sending the message to receiver
}

[c]



//-----------------------------

für den Receiver habe ich folgenden Code geschrieben:
//-----------------------------

[c]

#include <Adafruit_NeoPixel.h>
#ifdef _AVR_
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define LED_PIN 3
#define LED_COUNT 228

uint8_t BRIGHTNESS = 60;

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);

RF24 radio(7, 8); // CE, CSN

#define PinIRQ 3  // Arduino Uno, Mega und Nano: Pin 3
#define IRQ 1

const byte address[6] = "00001";

boolean button_state = 0;
boolean button_state2 = 0;
boolean button_state3 = 0;


boolean light_on = false;
boolean mode_a_active;

boolean receivedMessage = false;


uint8_t settings[6] = {0, 0, 0, 0, 0, 0};                 //Saving the 
incoming data


void setup() {
  pinMode(6, OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);   //Setting the address at which we 
will receive the data
  radio.setPALevel(RF24_PA_MIN);       //You can set this as minimum or 
maximum depending on the distance between the transmitter and receiver.
  radio.startListening();              //This sets the module as 
receiver

  strip.begin();           // INITIALIZE NeoPixel strip object 
(REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)

  attachInterrupt(IRQ, incommingmessage, HIGH);
}

void loop()
{
  if(receivedMessage == true){
    Serial.println("messange on interupt received");
    Serial.print(settings[0]);
    Serial.print(settings[1]);
    Serial.print(settings[2]);
    Serial.print(settings[3]);
    Serial.print(settings[4]);
    Serial.println(settings[5]);
    receivedMessage = false;
  }
}

void incommingmessage()
{
  radio.read(&settings, sizeof(settings));  //Reading the data
  receivedMessage = true;    // Variable setzen, dass eine neue 
Nachricht zur Auswertung bereit steht
}

//void attachSettings(){}


void colorWipe(uint32_t color, int wait) {
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
    strip.setPixelColor(i, color);         //  Set pixel's color (in 
RAM)
    strip.show();                          //  Update strip to match
    //delay(wait);                           //  Pause for a moment
  }
}
[c]

Falls ihr Ideen habt woran es liegen könnte und wie ich weiter kommen 
kann würde ich mich sehr freuen!
Einen schönen Abend euch!

: Bearbeitet durch User
von Jim M. (turboj)


Lesenswert?

Mach mal das radio.read() innerhalb von loop() - und nicht im Interrupt 
Handler. Ich vermute nämlich das das selbst Interrupts verwendet.

von Constantin T. (cosmonaut)


Lesenswert?

habe ich probiert, da gibt es leider keine veränderung.

monitor output habe ich folgenden nach reset:


19:45:51.437 -> messange on interupt received
19:45:51.437 -> 000000


dannn keine weitere Reaktion mehr auf neue sends....


beim controller sieht der stream wiefolgt aus, wobei die 255 die value 
vom faderpoti ist


000255
000254
000253
000255
...

wenn ein button gedrückt wird

100255

bzw

010255

001255
....

das sind die werte die ich eigentlich empfangen sollte


ich habe den IRQ Pin vom NRF mit dem Pin 3 vom Nano verbunden ist das 
soweit richtig?

: Bearbeitet durch User
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.