Şimdi Ara

arduino nRF24L alıcı verici kodlarına ekleme yaparken hata

Daha Fazla
Bu Konudaki Kullanıcılar: Daha Az
2 Misafir - 2 Masaüstü
5 sn
3
Cevap
0
Favori
192
Tıklama
Daha Fazla
İstatistik
  • Konu İstatistikleri Yükleniyor
0 oy
Öne Çıkar
Sayfa: 1
Giriş
Mesaj
  • 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 //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);
    }







  • 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ı?
  • 
Sayfa: 1
- x
Bildirim
mesajınız kopyalandı (ctrl+v) yapıştırmak istediğiniz yere yapıştırabilirsiniz.