Skip to content

Low Baud Rate #28

@filipcoja

Description

@filipcoja

I'm using this library with my two Arduinos, the controller (arduino nano) and an airplane. (arduino mega)

I'm using NeoSWSerial on the controller, and the Serial1 on the airplane. Now I'm using the HC-12 to communicate between these two devices (with echo, so airplane => controller => airplane => controller) while always sending new messages if nothing has been received for the last 5 seconds.

The HC-12 has an baud rate of 9600 configured on default, but to increase range, I have to lower it, after configuring everything correctly, I just cant get it to work with a baud rate of 4800 and lower (so everything below 9600), while 9600 works like a charm.

I tried it with a basic example without PacketSerial, and it works, so there has to be a bug or something like that.

Expected Behavior

Current Behavior

Possible Solution

Steps to Reproduce (for bugs)

CONTROLLER

void onPacketReceived(const uint8_t* buffer, size_t size) {
    if (size == sizeof(sensors)) {
        /** Update controls **/
        memcpy(&sensors, buffer, size);
        last_sensor_update = millis();

        /** Send current telemetry back **/
        HC12.send((uint8_t *)&controls, sizeof(controls));
        last_control_broadcast = millis();

        print_all_data();
    }
}

void setup() {
    Serial.begin(9600);             // Serial port to computer
    HC12neo.begin(4800);               // Serial port to HC12
    HC12.setStream(&HC12neo);
    HC12.setPacketHandler(&onPacketReceived);
}

void loop() {
    update_control_data();
    HC12.update();

    if (millis() - last_control_broadcast > 5000) {
        HC12.send((uint8_t *)&controls, sizeof(controls));
        last_control_broadcast = millis();
        Serial.println("send");
    }
}

AIRPLANE

void onPacketReceived(const uint8_t* buffer, size_t size) {
    if (size == sizeof(controls)) {
        set_update_led(HIGH);

        /** Update controls **/
        memcpy(&controls, buffer, size);
        /** Set new gotten controls **/
        set_throttle(controls.throttle);
        set_pitch(controls.x_joy);
        last_control_update = millis();

        /** Send current telemetry back **/
        HC12.send((uint8_t *)&sensors, sizeof(sensors));

        set_update_led(LOW);
    }
//    else {
//        buzz();
//        delay(1000);
//        stop_buzz();
//    }
}

/* SETUP METHOD */
void setup() {
    Serial.begin(9600);
    Serial1.begin(4800);
    HC12.setStream(&Serial1);
    HC12.setPacketHandler(&onPacketReceived);
    Wire.begin();
    Wire.setClock(400000);

    /** Setup sensors etc. **/
    setup_sensors();
    setup_servos();
    setup_leds();

    /* Set Power LED */
    set_power_led(HIGH);
}

void loop() {
    handle_servo_change();
    update_power_led(last_control_update);
    update_sensor_data();

    /** Incoming Throttle from Controller **/
    HC12.update();

//    Serial.print(sensors.x_angle);
//    Serial.print(";");
//    Serial.print(sensors.x_angle);
//    Serial.print(";");
//    Serial.println(sensors.x_angle);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions