Arduino NRF24l01 R C ничего не отправляет - PullRequest
0 голосов
/ 01 марта 2020

Я пытаюсь выполнить следующий источник на моем передатчике и приемнике R C, который использует модуль NRF24. Сегодня я загрузил тот же скетч, что и полугодовой отчет go, и он перестал получать какие-либо данные от передатчика, в разделах DEBUG_PRINT ничего не печатается. На передатчике NRF24 подключен к 7, 8. На приемнике NRF24 подключен к 9, 10. Проводка проверена 7 раз, правильная, напряжение питания приемника 7,4 В на VIN, источник питания передатчика - источник USB. Работает на Arduino Nano.

Источник для передатчика:

// Flash for self-diy NRF24lo* transmiter controller.
// 6 buttons, 4-way sticks, based on CX-10c controller.

#include <EEPROM.h>
#include <SPI.h>
#include "RF24.h"

 #define DEBUG_PRINT
// #define DEBUG_PRINT_RAW
#ifdef DEBUG_PRINT
#include <printf.h>
#endif

// IO mappings

#define STICK0 A3
#define STICK1 A2
#define STICK2 A0
#define STICK3 A1

#define BTN0 3
#define BTN1 6
#define BTN2 5
#define BTN3 4
#define BTN4 9
#define BTN5 A4

#define STLED 2

// Optional moddings

#define BTN_LONG_PRESS 1000

#define LED_ST_OFF        0
#define LED_ST_CONST      1
#define LED_ST_FLASH      2
#define LED_ST_FAST_FLASH 3

#define LED_ST_FLASH_TIME      250
#define LED_ST_FAST_FLASH_TIME 100

#define LED_POWER 150

// Package types
#define PACKAGE_STICKS 3
#define PACKAGE_BUTTON 5
#define PACKAGE_PING   7

#define PACKAGE_TIMEOUT 100

// Amount of packages should be dropped sequently to detect disconnect
#define TX_DROP_EDGE 16


// Long press stick 0 to start calibration, long press to stop
// Struct with min/max calibration values
struct STICK_CALIBRATION {
    int stmx[4];
    int stmn[4];
};

// Struct with info of button presses
struct BTN_STATE {
    int press[6];
    unsigned long time[6];
    // Used in long press to avoid multiple pressing
    int acted[6];
};

// Struct with state of flashing/idle/working LED
// FLASH --> CONST/OFF
// FAST_FLASH --> CONST/OFF
struct LED_STATE {
    // Previous type (for FLASH return to OFF/CONST state)
    int ptype;
    // Type of operation
    int type;
    // ON/OFF
    int state;
    // Time since action
    unsigned long time;
    // Count of flashes
    int count;
};

// Sender package type.
// Contains type and values for button or values for sticks
struct Package {
    int type;
    union {
        struct {
            int number;
            int lpress;
            int dummy[2];
        } button;
        struct {
            int sticks[4];
        } sticks;
    } data;
};

// Info of sticks calibration
STICK_CALIBRATION calibration;
bool calibration_mode = 0;

int sticks[4];

// When entering lock mode, stick data is not updating from input
bool lock_mode = 0;

// info of buttons states
BTN_STATE buttons;
LED_STATE led_state;

// Use NRF24lo1 transmitter on pins 7, 8
RF24 radio(7, 8);

byte addresses[][6] = { "TRAAA", "REEEE" };

// Amount of sequently dropped packages. Used to detect disconnect
int tx_dropped = 0;

// Used to prevent longpress repeat
// On long press button could be used as sticky press function, 
//  to avoid button sticking and long press act once during while push down, 
//  use this function to mark button as acted
void btn_act(int nubmer);

// Called on button press/longpress
void btn_action(int number, int lpress);

// Set led ON/OFF with change of state flag
void led_set_state(int state);
// Set led action type (FLAST, CONST, e.t.c.)
void led_set(int type, int count);

// Sends single package with given amount of attempts.
// Allows waiting for responce of receiver. The response should be 0.
// Returns 1 on success, 0 on failture.
int send_package(byte* pack, int size);

void setup() {
#ifdef DEBUG_PRINT
    Serial.begin(115200);
#endif

    // Set up transmitter
    radio.begin();

    radio.setChannel(77);
    radio.enableAckPayload();
    radio.setPALevel(RF24_PA_MAX);
    radio.openWritingPipe(addresses[1]);
    radio.openReadingPipe(1, addresses[0]);

#ifdef DEBUG_PRINT
    printf_begin();
    radio.printDetails();
#endif

    // Read calibration values
    byte* cal_struct = (byte*) &calibration;
    for (int i = 0; i < sizeof(STICK_CALIBRATION); ++i)
        cal_struct[i] = EEPROM.read(i);

#ifdef DEBUG_PRINT
    Serial.println("CALIBRATION: ");
    for (int i = 0; i < 4; ++i) {
        Serial.print('(');
        Serial.print(calibration.stmn[i]);
        Serial.print(", ");
        Serial.print(calibration.stmx[i]);
        Serial.print(") ");
    }
    Serial.println();
#endif

    buttons = {{0,0,0,0,0,0}, {0,0,0,0,0,0}, {0,0,0,0,0,0}};

    // Clear LED state
    led_state.ptype = 0;
    led_state.type  = 0;
    led_state.state = 0;
    led_state.time  = 0;
    led_state.count = 0;

    // Prepare pinout
    pinMode(STLED, OUTPUT);

    pinMode(STICK0, INPUT_PULLUP);
    pinMode(STICK1, INPUT_PULLUP);
    pinMode(STICK2, INPUT_PULLUP);
    pinMode(STICK3, INPUT_PULLUP);

    pinMode(BTN0, INPUT_PULLUP);
    pinMode(BTN1, INPUT_PULLUP);

    pinMode(BTN2, INPUT_PULLUP);
    pinMode(BTN3, INPUT_PULLUP);
    pinMode(BTN4, INPUT_PULLUP);
    pinMode(BTN5, INPUT_PULLUP);
}

void loop() {
    // Read sticks & map to calibration
    if (!lock_mode) {
        sticks[0] = analogRead(STICK0);       
        sticks[1] = analogRead(STICK1);       
        sticks[2] = 1024 - analogRead(STICK2);
        sticks[3] = 1024 - analogRead(STICK3);
    }

    // Read stick buttons
    int rbtn[6];
    rbtn[0] = !digitalRead(BTN0);
    rbtn[1] = !digitalRead(BTN1);

    // read optional buttons
    rbtn[2] = !digitalRead(BTN2);
    rbtn[3] = !digitalRead(BTN3);
    rbtn[4] = !digitalRead(BTN4);
    rbtn[5] = !digitalRead(BTN5);

#ifdef DEBUG_PRINT
#ifdef DEBUG_PRINT_RAW
    // Debug out
    Serial.print(sticks[0]); Serial.print(' ');
    Serial.print(sticks[1]); Serial.print(' ');
    Serial.print(sticks[2]); Serial.print(' ');
    Serial.print(sticks[3]); Serial.print(' ');

    Serial.print(rbtn[0]); Serial.print(' ');
    Serial.print(rbtn[1]); Serial.print(' ');

    Serial.print(rbtn[2]); Serial.print(' ');
    Serial.print(rbtn[3]); Serial.print(' ');
    Serial.print(rbtn[4]); Serial.print(' ');
    Serial.print(rbtn[5]); Serial.print(' ');
    Serial.println();
#endif
#endif

    // Map to calibration
    if (!calibration_mode && !lock_mode) {      
        sticks[0] = map(sticks[0], calibration.stmn[0], calibration.stmx[0], 0, 1023);
        sticks[1] = map(sticks[1], calibration.stmn[1], calibration.stmx[1], 0, 1023);
        sticks[2] = map(sticks[2], calibration.stmn[2], calibration.stmx[2], 0, 1023);
        sticks[3] = map(sticks[3], calibration.stmn[3], calibration.stmx[3], 0, 1023);
    }

    // Check buttons states and update timings
    for (int i = 0; i < 6; ++i) {
        if (buttons.press[i] && !rbtn[i]) { // Button released
            if (!buttons.acted[i])
                btn_action(i, (millis() - buttons.time[i]) > BTN_LONG_PRESS);
            buttons.press[i] = 0;
            buttons.time[i]  = 0;
        } else if (buttons.press[i]) { // Button keeps down
            if ((millis() - buttons.time[i]) > BTN_LONG_PRESS && !buttons.acted[i]) { // Toggle long press
                btn_action(i, 1);
                // buttons.press[i] = 0;
                buttons.time[i]  = 0;
            }
        } else if (rbtn[i]) { // Button pressed
            buttons.press[i] = 1;
            buttons.acted[i] = 0;
            buttons.time[i]  = millis();
        }
    }

    // Update LED
    if (led_state.type == LED_ST_FLASH && (led_state.time + LED_ST_FLASH_TIME) < millis()
        ||
        led_state.type == LED_ST_FAST_FLASH && (led_state.time + LED_ST_FAST_FLASH_TIME) < millis()) { // Flash period done

        if (!led_state.state) { // Count cycle as finished, try to begin another one
            --led_state.count;
            if (led_state.count <= 0) { // Flashing cycles is done
                led_state.type = led_state.ptype;
                led_set_state(led_state.type == LED_ST_CONST);
            } else { // Turn led ON again, begin next flash cycle
                led_state.time = millis();
                led_set_state(1);
            }
        } else { // Just turn the led OFF
            led_state.time = millis();
            led_set_state(0);
        }
    }

    // Update led flashing
    if (led_state.type != LED_ST_FLASH && led_state.type != LED_ST_FAST_FLASH) {
         if (calibration_mode)
            led_set(LED_ST_FAST_FLASH, 4);
        else {
            // Update led lighting
            if (lock_mode)
                led_set(LED_ST_CONST, 0);
            else
                led_set(LED_ST_OFF, 0);
        }
    }


    // If !paired
    if (calibration_mode) {
        for (int i = 0; i < 4; ++i) {
            if (calibration.stmn[i] > sticks[i])
                calibration.stmn[i] = sticks[i];

            if (calibration.stmx[i] < sticks[i])
                calibration.stmx[i] = sticks[i];
        }
    } else {
        // Sending package with sticks

        Package pack;
        pack.type = PACKAGE_STICKS;
        pack.data.sticks.sticks[0] = sticks[0];
        pack.data.sticks.sticks[1] = sticks[1];
        pack.data.sticks.sticks[2] = sticks[2];
        pack.data.sticks.sticks[3] = sticks[3];

        bool result = send_package((byte*) &pack, sizeof(Package));

        if (!result) {
            if (tx_dropped > TX_DROP_EDGE && led_state.type != LED_ST_FLASH && led_state.type != LED_ST_FAST_FLASH) 
                led_set(LED_ST_FLASH, 4);

#ifdef DEBUG_PRINT
            Serial.println("TX failed");
#endif
        }
    }
}

int send_package(byte* pack, int size) {
    if (!radio.write(pack, size)) {
        ++tx_dropped;
        return 0;
    } else {
        byte payload;
        if (radio.isAckPayloadAvailable()) {
            radio.read(&payload, sizeof(byte));
            tx_dropped = 0;
            return 1;
        }
        ++tx_dropped;
        return 0;
    }
};

void led_set_state(int state) {
    if (led_state.state && !state) {
        digitalWrite(STLED, 0);
        led_state.state = !led_state.state;
    } else if (!led_state.state && state) {
        analogWrite(STLED, LED_POWER);
        led_state.state = !led_state.state;
    }
};

void led_set(int type, int count) { 
    if (type == LED_ST_CONST || type == LED_ST_OFF) {
        led_set_state(type == LED_ST_CONST);
        led_state.type = type;
    } else {
        // if was flashing --> rewrite
        // if was constant --> move type to ptype & do flashing
        if (led_state.type == LED_ST_CONST || led_state.type == LED_ST_OFF) 
            led_state.ptype = led_state.type;

        led_state.type  = type;
        led_state.count = count;
        led_state.time  = millis();
        led_set_state(1);
    }
};

void btn_act(int number) {
    buttons.acted[number] = 1;
};

// Override calls for button presses
void btn_action(int number, int lpress) {
#ifdef DEBUG_PRINT
    Serial.print("Press for "); Serial.println(number);
#endif

    switch(number) {
        // calibration
        case 0: { 
            // press  = ?
            // Lpress = calibration mode

            if (lpress) {
                if (calibration_mode && !lock_mode) {
                    // Write calibration values
                    byte* cal_struct = (byte*) &calibration;
                    for (int i = 0; i < sizeof(STICK_CALIBRATION); ++i)
                        EEPROM.write(i, cal_struct[i]);

                    calibration_mode = 0;

#ifdef DEBUG_PRINT
                    Serial.println("NEW CALIBRATION: ");
                    for (int i = 0; i < 4; ++i) {
                        Serial.print('(');
                        Serial.print(calibration.stmn[i]);
                        Serial.print(", ");
                        Serial.print(calibration.stmx[i]);
                        Serial.print(") ");
                    }
                    Serial.println();
#endif
                } else {
                    for (int i = 0; i < 4; ++i) {
                        calibration.stmn[i] = 1024;
                        calibration.stmx[i] = 0;
                    }

                    calibration_mode = 1;
                }
            }
            break;
        }

        case 1: { 
            // press  = ?
            // Lpress = lock mode

            if (lpress) {
                lock_mode = !lock_mode;
            }

            break;
        }
    }
    led_set(LED_ST_FAST_FLASH, 2);
    btn_act(number);

    Package pack;
    pack.type = PACKAGE_BUTTON;
    pack.data.button.number = number;
    pack.data.button.lpress = lpress;

    bool result = send_package((byte*) &pack, sizeof(Package));

#ifdef DEBUG_PRINT
    if (!result)
        Serial.println("Button TX failed");
#endif
};

Источник для приемника:

// Flash for self-diy NRF24lo* receiver controller.
// 6 buttons, 4-way sticks.

#include <Servo.h>
#include <SPI.h>
#include "RF24.h"

 #define DEBUG_PRINT
#ifdef DEBUG_PRINT
#include <printf.h>
#endif

// IO mappings

#define CONNECT_0 2
#define CONNECT_1 3
#define CONNECT_2 4
#define CONNECT_3 5
#define CONNECT_4 6
#define CONNECT_5 7
#define CONNECT_6 8

#define CONNECT_A0 A0
#define CONNECT_A1 A1
#define CONNECT_A2 A2
#define CONNECT_A3 A3
#define CONNECT_A4 A4
#define CONNECT_A5 A5
// A6, A7 on nano are only analog input
#define CONNECT_A6 A6
#define CONNECT_A7 A7

// Inverters for sticks
#define INVERT_STICK0 0
#define INVERT_STICK1 0
#define INVERT_STICK2 0
#define INVERT_STICK3 0

// Mappings for sticks
#define SERVO_MAP_STICK0 0, 180
#define SERVO_MAP_STICK1 0, 180
#define SERVO_MAP_STICK2 0, 180
#define SERVO_MAP_STICK3 60, 120

#define ANALOG_MAP_STICK0 0, 255
#define ANALOG_MAP_STICK1 0, 255
#define ANALOG_MAP_STICK2 0, 255
#define ANALOG_MAP_STICK3 0, 255

// Optional moddings


// Package types
#define PACKAGE_STICKS 3
#define PACKAGE_BUTTON 5
#define PACKAGE_PING   7

// Used to detect disconnect from the controller
#define CONNECTION_TIMEOUT 100

// Mpdes for output of the motor
// #define MODE_2_DIGITAL_1_ANALOG
#define MODE_2_ANALOG


// Receiver package struct.
// Contains type and values for button or values for sticks
struct Package {
    int type;
    union {
        struct {
            int number;
            int lpress;
            // Used to complete size of the package.
            // Without it, payload is not sending for sticks.
            int dummy[2];
        } button;
        struct {
            int sticks[4];
        } sticks;
    } data;
};

// Describes state of a single buttons on controller
// Single press -> 1
// Second press -> 0
struct Button {
    bool state;
    bool lstate;
};

// Use NRF24lo1 transmitter on pins 7, 8
RF24 radio(9, 10);

byte addresses[][6] = { "TRAAA", "REEEE" };

// Used to detect timed disconnection from the controller
unsigned long last_receive_time;
bool disconnected;

// Servos mapped to sticks
Servo servo[4];

// Buttons states 
Button buttons[6];

// Called on connection restored after drop
void on_connection();

// Called on connection dropped
void on_disconnection();

// Called on button state received
void button_action(int button, int lpress);

// Called on sticks state received
void sticks_action(int sticks[4]);

void setPWMNanofrequency(int freq) {
    TCCR2B = TCCR2B & 0b11111000 | freq;
    TCCR1B = TCCR1B & 0b11111000 | freq;
}

void setup() {
#ifdef DEBUG_PRINT
    Serial.begin(115200);
#endif

    // Set up receiver
    radio.begin();

    radio.setChannel(77);
    //radio.setAutoAck(1);
    //radio.setRetries(0, 8);
    radio.enableAckPayload();
    radio.setPALevel(RF24_PA_MAX);
    //radio.setCRCLength(RF24_CRC_8);
    radio.openWritingPipe(addresses[0]);
    radio.openReadingPipe(1, addresses[1]);

#ifdef DEBUG_PRINT
    // Debugger output
    printf_begin();
    radio.printDetails();
#endif

    radio.startListening();

    // Init buttons with 0
    buttons[0] = { 0, 0 };
    buttons[1] = { 0, 0 };
    buttons[2] = { 0, 0 };
    buttons[3] = { 0, 0 };
    buttons[4] = { 0, 0 };
    buttons[5] = { 0, 0 };

    // Set up pinout
    pinMode(CONNECT_0, OUTPUT);
    pinMode(CONNECT_2, OUTPUT);
    pinMode(CONNECT_3, OUTPUT);
    pinMode(CONNECT_4, OUTPUT);
    pinMode(CONNECT_5, OUTPUT);
    pinMode(CONNECT_6, OUTPUT);

    pinMode(CONNECT_A0, OUTPUT);
    pinMode(CONNECT_A1, OUTPUT);
    pinMode(CONNECT_A2, OUTPUT);
    pinMode(CONNECT_A3, OUTPUT);
    pinMode(CONNECT_A4, OUTPUT);
    pinMode(CONNECT_A5, OUTPUT);
    pinMode(CONNECT_A6, INPUT);
    pinMode(CONNECT_A7, INPUT);

    // setPWMNanofrequency(0x02);

    // Set up servos
    servo[0].attach(CONNECT_A4); // Remapped servos to leave three PWM pins
    servo[1].attach(CONNECT_A5);
    servo[2].attach(CONNECT_5);
    servo[3].attach(CONNECT_6);

    // Clear disconnect trigger
    last_receive_time = millis();
    disconnected = 0;

    // Reset outputs
    digitalWrite(CONNECT_0, LOW);
    digitalWrite(CONNECT_2, LOW);
    digitalWrite(CONNECT_3, LOW);
    digitalWrite(CONNECT_4, LOW);
    digitalWrite(CONNECT_5, LOW);
    digitalWrite(CONNECT_6, LOW);

    digitalWrite(CONNECT_A0, LOW);
    digitalWrite(CONNECT_A1, LOW);
    digitalWrite(CONNECT_A2, LOW);
    digitalWrite(CONNECT_A3, LOW);
    digitalWrite(CONNECT_A4, LOW);
    digitalWrite(CONNECT_A5, LOW);
    // digitalWrite(CONNECT_A6, LOW);
    // digitalWrite(CONNECT_A7, LOW);
}

void loop() {
    byte payload = 13;
    radio.writeAckPayload(1, &payload, sizeof(byte));
    if (radio.available()) {
        Package pack;
        radio.read((byte*) &pack, sizeof(Package));

        // Update trigger
        last_receive_time = millis();
        if (disconnected)
            on_connection();
        disconnected = 0;

        switch(pack.type) {
            case PACKAGE_STICKS: {
#ifdef DEBUG_PRINT
                Serial.print(pack.data.sticks.sticks[0]); Serial.print(' ');
                Serial.print(pack.data.sticks.sticks[1]); Serial.print(' ');
                Serial.print(pack.data.sticks.sticks[2]); Serial.print(' ');
                Serial.print(pack.data.sticks.sticks[3]); Serial.println();
#endif

                if (INVERT_STICK0) pack.data.sticks.sticks[0] = 1024 - pack.data.sticks.sticks[0];
                if (INVERT_STICK1) pack.data.sticks.sticks[1] = 1024 - pack.data.sticks.sticks[1];
                if (INVERT_STICK2) pack.data.sticks.sticks[2] = 1024 - pack.data.sticks.sticks[2];
                if (INVERT_STICK3) pack.data.sticks.sticks[3] = 1024 - pack.data.sticks.sticks[3];

                int ssticks[4];
                ssticks[0] = map(pack.data.sticks.sticks[0], 0, 1023, SERVO_MAP_STICK0);
                ssticks[1] = map(pack.data.sticks.sticks[1], 0, 1023, SERVO_MAP_STICK1);
                ssticks[2] = map(pack.data.sticks.sticks[2], 0, 1023, SERVO_MAP_STICK2);
                ssticks[3] = map(pack.data.sticks.sticks[3], 0, 1023, SERVO_MAP_STICK3);

                int asticks[4];
                asticks[0] = map(pack.data.sticks.sticks[0], 0, 1023, ANALOG_MAP_STICK0);
                asticks[1] = map(pack.data.sticks.sticks[1], 0, 1023, ANALOG_MAP_STICK1);
                asticks[2] = map(pack.data.sticks.sticks[2], 0, 1023, ANALOG_MAP_STICK2);
                asticks[3] = map(pack.data.sticks.sticks[3], 0, 1023, ANALOG_MAP_STICK3);

#ifdef DEBUG_PRINT
                Serial.print("Servo data: ");
                Serial.print(ssticks[0]); Serial.print(' ');
                Serial.print(ssticks[1]); Serial.print(' ');
                Serial.print(ssticks[2]); Serial.print(' ');
                Serial.print(ssticks[3]); Serial.println();

                Serial.print("Analog data: ");
                Serial.print(asticks[0]); Serial.print(' ');
                Serial.print(asticks[1]); Serial.print(' ');
                Serial.print(asticks[2]); Serial.print(' ');
                Serial.print(asticks[3]); Serial.println();
#endif

                sticks_action(pack.data.sticks.sticks, ssticks, asticks);
                break;
            }

            case PACKAGE_BUTTON: {
#ifdef DEBUG_PRINT
                Serial.print(pack.data.button.number); Serial.print(' ');
                Serial.print(pack.data.button.lpress); Serial.println();
#endif              

                // Update states of the buttons
                if (pack.data.button.lpress)
                    buttons[pack.data.button.number].lstate = !buttons[pack.data.button.number].lstate;
                else
                    buttons[pack.data.button.number].state = !buttons[pack.data.button.number].state;

                button_action(pack.data.button.number, pack.data.button.lpress);
                break;
            }
        }
    } else if (!disconnected && millis() - last_receive_time > CONNECTION_TIMEOUT) {
        disconnected = 1;
        on_disconnection();
    }
}

void on_connection() {

};

void on_disconnection() {
    // servo[0].write(0);
    // servo[1].write(0);
    // servo[2].write(0);
    // servo[3].write(0);

    // analogWrite(CONNECT_A0, 0);
    // analogWrite(CONNECT_A1, 0);
    // analogWrite(CONNECT_A2, 0);
    // analogWrite(CONNECT_A3, 0);
#ifdef MODE_2_DIGITAL_1_ANALOG
    digitalWrite(CONNECT_1, LOW);
    digitalWrite(CONNECT_2, LOW);
    digitalWrite(CONNECT_3, LOW);
#endif
#ifdef MODE_2_ANALOG
    digitalWrite(CONNECT_3, LOW);
    digitalWrite(CONNECT_4, LOW);
    digitalWrite(CONNECT_0, LOW);
#endif
};

void button_action(int button, int lpress) {
    switch (button) {
        case 0:
        case 1:
            break;

        case 2: {
            digitalWrite(CONNECT_A0, buttons[button].state);
            break;
        }

        case 3: {
            digitalWrite(CONNECT_A1, buttons[button].state);
            break;
        }

        case 4: {
            digitalWrite(CONNECT_A2, buttons[button].state);
            break;
        }

        case 5: {
            digitalWrite(CONNECT_A3, buttons[button].state);
            break;
        }
    }
};

void sticks_action(int sticks[4], int ssticks[4], int asticks[4]) { 
    servo[0].write(ssticks[0]);
    servo[1].write(ssticks[1]);
    servo[2].write(ssticks[2]);
    servo[3].write(ssticks[3]);

    // analogWrite(CONNECT_A0, asticks[0]);
    // analogWrite(CONNECT_A1, asticks[1]);
    // analogWrite(CONNECT_A2, asticks[2]);
    // analogWrite(CONNECT_A3, asticks[3]);

    // Control H-Bridge over 3, 4 outputs with right stick
    int value = (sticks[2] > 500) ? (sticks[2] - 500) : (sticks[2] < 480) ? (480 - sticks[2]) : (0);

    if (value < 500)
        value = map(value, 0, 480, 0, 255);
    else
        value = map(value, 0, 1023 - 500, 0, 255);

    value = (value > 255) ? 255 : (value < 0) ? 0 : value;

    // connecting 2 digital pins as HIGH,LOW / LOW,HIGH and analog as speed value (used in bts79603 bridge)
#ifdef MODE_2_DIGITAL_1_ANALOG
    if (sticks[2] > 500) {
        digitalWrite(CONNECT_1, HIGH);
        digitalWrite(CONNECT_2, LOW);
        analogWrite(CONNECT_3, value);
    } else if (sticks[2] < 480) {
        digitalWrite(CONNECT_1, LOW);
        digitalWrite(CONNECT_2, HIGH);
        analogWrite(CONNECT_3, value);
    } else {
        digitalWrite(CONNECT_1, LOW);
        digitalWrite(CONNECT_2, LOW);
        analogWrite(CONNECT_3, 0);
    }
#endif

    // connecting 2 analog pins to simple H-Bridge
#ifdef MODE_2_ANALOG
    analogWrite(CONNECT_3, sticks[2] > 500 ? value : 0);
    analogWrite(CONNECT_4, sticks[2] < 480 ? value : 0);
    analogWrite(CONNECT_0, sticks[2] > 500 || sticks[2] < 480);
#endif
};

Печать передатчикаДетали:

STATUS       = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0x4141415254 0x4545454552
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR      = 0x4141415254
RX_PW_P0-6   = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA        = 0x3f
EN_RXADDR    = 0x03
RF_CH        = 0x4d
RF_SETUP     = 0x07
CONFIG       = 0x0e
DYNPD/FEATURE    = 0x00 0x00
Data Rate    = 1MBPS
Model        = nRF24L01+
CRC Length   = 16 bits
PA Power     = PA_MAX

Печать приемникаДетали:

STATUS           = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1     = 0x4545454552 0x4141415254
RX_ADDR_P2-5     = 0xc3 0xc4 0xc5 0xc6
TX_ADDR          = 0x4545454552
RX_PW_P0-6       = 0x20 0x20 0x00 0x00 0x00 0x00
EN_AA            = 0x3f
EN_RXADDR        = 0x02
RF_CH            = 0x4d
RF_SETUP         = 0x07
CONFIG           = 0x0e
DYNPD/FEATURE    = 0x00 0x00
Data Rate        = 1MBPS
Model            = nRF24L01+
CRC Length       = 16 bits
PA Power         = PA_MAX

Используемый код

1 Ответ

0 голосов
/ 01 марта 2020

Следующий код на приемнике вызвал разрыв ввода-вывода.

pinMode(CONNECT_A6, INPUT);
pinMode(CONNECT_A7, INPUT);

A6, контакты A7 НЕ поддерживают изменение режима, и эта проблема привела к сбою соединения NRF24.

...