0

Maybe someone has a code example or knows how to switch the frequency on akk alpha via esp32. I currently have VTX akk alpha 25w.

I have already tried all possible options, but I got to the point that the desired frequency turns on for 1 second, and then resets to factory settings.

I'm using an EPS32 esp32 ttgo t-display. But I don't think the problem is due to the board's hardware.

What's strange is that there's a response to changing the frequency, but for some reason the VTX immediately resets the frequency to the one I manually set using the button on the VTX.

I apologize in advance for my English) I would be glad to any help.

Code:

#include <HardwareSerial.h>

#ifndef SA_TX_PIN
#define SA_TX_PIN 17
#endif

// BOSCAM A/B/E стандартні частоти (МГц)
static const uint16_t VTX_FREQ[3][8] = {
  {5865, 5845, 5825, 5805, 5785, 5765, 5745, 5725}, // A
  {5733, 5752, 5771, 5790, 5809, 5828, 5847, 5866}, // B
  {5705, 5685, 5665, 5645, 5885, 5905, 5925, 5945}  // E
};

static HardwareSerial SA(2);

static uint8_t currentBand = 0;
static uint8_t currentChannel = 0;
static bool switchedOnce = false;
static unsigned long startMs = 0;
static unsigned long lastFreqSet = 0;

static uint8_t crc8_d5(const uint8_t *data, size_t len) {
  uint8_t crc = 0x00;
  for (size_t i = 0; i < len; i++) {
    crc ^= data[i];
    for (int b = 0; b < 8; b++) {
      if (crc & 0x80) crc = (uint8_t)((crc << 1) ^ 0xD5);
      else crc <<= 1;
    }
  }
  return crc;
}

// Коди команд SmartAudio (часто зустрічаються у v2/v2.1)
#define SA_CMD_SET_FREQUENCY  0x03

static void saRebegin(uint32_t config, bool invert) {
  SA.end();
  SA.begin(4800, config, -1, SA_TX_PIN, invert);
}

static void saWriteFrameOnce(const uint8_t *frame, uint8_t framelen) {
  SA.write((uint8_t)0x00); // префікс для притиску лінії вниз
  delay(2);
  SA.write(frame, framelen);
  SA.write((uint8_t)0x00); // суфікс нульовим байтом
  SA.flush();
}

static void saSend(uint8_t cmd, const uint8_t *payload, uint8_t len) {
  uint8_t frame[4 + 8 + 1];
  frame[0] = 0xAA;
  frame[1] = 0x55;
  frame[2] = cmd;
  frame[3] = len;
  for (uint8_t i = 0; i < len; i++) frame[4 + i] = payload ? payload[i] : 0x00;
  uint8_t crc = crc8_d5(&frame[2], 2 + len);
  frame[4 + len] = crc;
  uint8_t framelen = 5 + len;

  // Використовуємо тільки один формат: 8E2, без інверсії
  saRebegin(SERIAL_8E2, false);
  saWriteFrameOnce(frame, framelen);
  delay(20);
  saWriteFrameOnce(frame, framelen);  // Повтор для надійності
}

// Встановити частоту напряму (МГц, little-endian)
static void saSetFrequency(uint16_t mhz) {
  uint8_t payload[2] = { (uint8_t)(mhz & 0xFF), (uint8_t)((mhz >> 8) & 0xFF) };
  saSend(SA_CMD_SET_FREQUENCY, payload, 2);
}

void setup() {
  Serial.begin(115200);
  SA.begin(4800, SERIAL_8E2, -1, SA_TX_PIN, false);
  Serial.println("SmartAudio init");

  // Початково: A CH3 (індекс 2)
  currentBand = 0;       // A
  currentChannel = 2;    // CH3
  saSetFrequency(VTX_FREQ[currentBand][currentChannel]);
  Serial.println("Set A CH3 via frequency");
  startMs = millis();
}

void loop() {
  // Перевіряємо, чи потрібно перемкнути частоту
  if (!switchedOnce && (millis() - startMs >= 10000UL)) {
    currentBand = 0;    // A
    currentChannel = 7; // CH8
    saSetFrequency(VTX_FREQ[currentBand][currentChannel]);
    Serial.println("Switched to A CH8");
    switchedOnce = true;
  }

  // Періодично оновлюємо частоту, щоб "утримувати" її
  if (millis() - lastFreqSet > 1000UL) {  // Кожну секунду
    saSetFrequency(VTX_FREQ[currentBand][currentChannel]);
    lastFreqSet = millis();
  }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.