I am having trouble making those two libraries work together. I've been browsing the internet for an hour now and still can't find anyone with similar trouble. And since I haven't really worked with either of those libraries I can't find the problem myself.
Basically, when I divide the code into two parts with one library each(Accelstepper, Rf24) everything works just fine, but as soon as I try to combine those two my radio module doesn't pick up any signal. In the main code you can see I have only defined the stepper motor pins and that was enough for the NRF24l01 module to stop working.
//Libraries
#include <nRF24L01.h>
#include <RF24.h>
#include <SPI.h>
#include <AccelStepper.h>
//
//Code variables
const int stepPin = 12;
const int dirPin = 14;
const int stepPin1 = 10;
const int dirPin1 = 8;
int del;
int motorSpeed1;
int motorSpeed2;
//
//Stepper motors setup
AccelStepper leftWheel(1, stepPin, dirPin);
AccelStepper rightWheel(1, stepPin1, dirPin1);
//
//Radio module setup and variables
RF24 radio(53, 49);
const byte address = "00001";
byte data[14];
//
void setup()
{
Serial.begin(9600);
pinMode(2, OUTPUT);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.startListening();
pinMode(47, OUTPUT);
}
void loop()
{
if (radio.available())
{
radio.read(&data, sizeof(data));
digitalWrite(47, HIGH);
}
for (int x = 0; x < 14; x++)
{
Serial.print(data[x]);
Serial.print(",");
}
Serial.println();
}
Here is the transmitter code. I don't know if it will help you troubleshoot my code though.
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
RF24 radio(53, 49);
const byte address = "00001";
byte data[14];
void setup()
{
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_250KBPS);
radio.stopListening();
}
void loop()
{
if (digitalRead(1) == 1)
{
data[0] = 0;
}
else {
data[0] = 1;
}
if (digitalRead(2) == 1)
{
data[1] = 0;
}
else {
data[1] = 1;
}
data[2] = digitalRead(3);
data[3] = digitalRead(4);
data[4] = digitalRead(5);
data[5] = digitalRead(6);
data[6] = digitalRead(7);
data[7] = digitalRead(8);
data[8] = map(analogRead(0), 0, 1023, 0, 255);
data[9] = map(analogRead(1), 0, 1023, 0, 255);
data[10] = map(analogRead(2), 0, 1023, 0, 255);
data[11] = map(analogRead(3), 0, 1023, 0, 255);
data[12] = map(analogRead(4), 0, 1023, 0, 255);
data[13] = map(analogRead(5), 0, 1023, 0, 255);
radio.write(&data, sizeof(data));
}
Thank you in advance for your responses.