Arama butonu
Bu konudaki kullanıcılar: 1 misafir
1
Cevap
222
Tıklama
0
Öne Çıkarma
arduino nRF24L alıcı verici kodlarına ekleme yaparken hata
C
7 yıl
Er
Konu Sahibi

merhaba arkadaşlar. bır sitede buldugum alıcı verci kodlarında nRF24L ile bir servo motoru e 2 dc motoru kontrol ediyorum. fakat servo olarak extradan 1 servo bağlamam gerekiyor. ne yaptım ne ettimse bir türlü kodlarda gerekli eklemeyi yapamadım. yardımcı olacak arkadaşlar varsa senvinirim.

alıcı kodu :
/*

*/

#include <Servo.h> //the library which helps us to control the servo motor
#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem (nRF24L)

//define our L298N control pins
//Motor A
const int RightMotorForward = 2; // IN1
const int RightMotorBackward = 3; // IN2
//Motor B
const int LeftMotorForward = 4; // IN3
const int LeftMotorBackward = 6; // IN4

//define the servo name
Servo myServo;


RF24 radio(5,10); /*This object represents a modem connected to the Arduino.
Arguments 5 and 10 are a digital pin numbers to which signals
CE and CSN are connected.*/

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem,that will receive data from the Arduino.

int data[1];


void setup(){
pinMode(RightMotorForward, OUTPUT);
pinMode(LeftMotorForward, OUTPUT);
pinMode(LeftMotorBackward, OUTPUT);
pinMode(RightMotorBackward, OUTPUT);

//define the servo input pins
myServo.attach(14); //A0

radio.begin(); //it activates the modem.
radio.openReadingPipe(1, pipe); //determines the address of our modem which receive data.
radio.startListening(); //enable receiving data via modem
}

void loop(){
if(radio.available()){
radio.read(data, 1);

if(data[0] < 11 && data[0] > 6){
// This is backward
// Set a Motor A backward
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, HIGH);
// Set a Motor B backward
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, HIGH);
}
if(data[0] > -1 && data[0] < 4){
// This is forward
// Set a Motor A forward
digitalWrite(RightMotorForward, HIGH);
digitalWrite(RightMotorBackward, LOW);
// Set a Motor B forward
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(LeftMotorBackward, LOW);
}
if (data[0] == 5){
// Stop Motors
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, LOW);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, LOW);
}
// This is Backward
// Set a Motor A Backward
if(data[0] < 21 && data[0] > 16){
digitalWrite(RightMotorForward, HIGH);
digitalWrite(RightMotorBackward, LOW);
// Set a Motor B Backward
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, HIGH);
}
// Turn Right
if(data[0] > 10 && data[0] < 14){
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, HIGH);
digitalWrite(LeftMotorForward, HIGH);
digitalWrite(LeftMotorBackward, LOW);
}
// Turn Left
if(data[0] == 15){
digitalWrite(RightMotorForward, LOW);
digitalWrite(RightMotorBackward, LOW);
digitalWrite(LeftMotorForward, LOW);
digitalWrite(LeftMotorBackward, LOW);
}
// for the servo motor
if(data[0] < 31 && data[0] > 21){
int potValue = data[0];
int potPos = map(potValue, 21, 30, 10, 170);
myServo.write(potPos);
}
}
}


verici kodu

*/

#include <SPI.h> //the communication interface with the modem
#include "RF24.h" //the library which helps us to control the radio modem

//define the input pins
int x_axis = A0;
int y_axis = A1;
int potPin = A2;

//define variable values
int xValue;
int yValue;
int potValue;


int data[1];

RF24 radio(5,10); //5 and 10 are a digital pin numbers to which signals CE and CSN are connected.

const uint64_t pipe = 0xE8E8F0F0E1LL; //the address of the modem, that will receive data from Arduino.


void setup(void){
Serial.begin(9600);
radio.begin(); //it activates the modem.
radio.openWritingPipe(pipe); //sets the address of the receiver to which the program will send data.
}

void loop(){

//Send X-axis data
xValue = analogRead(x_axis);
xValue = map(xValue, 0, 1023, 0, 10);
data[0] = xValue;
radio.write(data, 1);

//Send Y-axis data
yValue = analogRead(y_axis);
yValue = map(yValue, 0, 1023, 11, 20);
data[0] = yValue;
radio.write(data, 1);

//Send Potentiometer data
potValue = analogRead(potPin);
potValue = map(potValue, 0, 1023, 21, 30);
data[0] = potValue;
radio.write(data, 1);
}

DH forumlarında vakit geçirmekten keyif alıyor gibisin ancak giriş yapmadığını görüyoruz.

Üye olduğunda özel mesaj gönderebilir, beğendiğin konuları favorilerine ekleyip takibe alabilir ve daha önce gezdiğin konulara hızlıca erişebilirsin.

Üye Ol Şimdi Değil



O
7 yıl
Yüzbaşı

Siz bundan onceki kosları calıstırabildinimi? Ben bilgisayar baglayacagım birini ve diğer 2 sininde verici olarak kullanacagım. 3 tanesini haberlestiremedim. Birde mesafe olarak ta test yapmam lazım. Siz ne kadar mesafede çalıştırabildiniz? Açık alanda 50-100m de çalışırmı?



DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.