Sectional Control For esp 32

I have tried many many times to down load a section sketch that I can get to work with AGIO. Every time it comes up with a new and more foreign error code. No such file or directory is common. Ive worked at getting it from down loads into a file with extract all but i must be missing a step. Ive looked for how to videos on downloading files from git hub but I have nothing. I understand this is a difficult question given I could be doing many steps wrong but is there a simple sketch that is somewhat fool proof ?

I don’t know any specifics about section control but put your errors into grok and it will tell you what they mean.

/ Improved ESP32 Section Control for AgOpenGPS - 8 sections
// Tested logic for PGN 239 Machine Data

#define VERSION "2.66"

const uint8_t relayPinArray[8] = {25, 26, 27, 32, 33, 13, 14, 16};   // IN1 to IN8

#define PinAogReady   2
#define AutoSwitch    17
#define ManuelSwitch  5

const uint8_t switchPinArray[8] = {25, 26, 27, 32, 33, 13, 14, 16};

bool relayIsActive = LOW;      // Your relays turn ON at LOW (confirmed by blink test)
bool readyIsActive = HIGH;

uint8_t loopTime = 100;
uint32_t lastTime = 0;
uint8_t watchdogTimer = 50;

bool aogConnected = false;
uint8_t relayLo = 0;           // sections 1-8 from AOG

void setup() {
  Serial.begin(38400);
  delay(200);

  Serial.println("\n=== ESP32 8-Section Control v2.66 ===");
  Serial.println("Relay pins: 25, 26, 27, 32, 33, 13, 14, 16");

  for (int i = 0; i < 8; i++) {
    pinMode(relayPinArray[i], OUTPUT);
    digitalWrite(relayPinArray[i], !relayIsActive);   // All OFF
  }

  pinMode(PinAogReady, OUTPUT);
  digitalWrite(PinAogReady, !readyIsActive);

  pinMode(AutoSwitch, INPUT_PULLUP);
  pinMode(ManuelSwitch, INPUT_PULLUP);
  for (int i = 0; i < 8; i++) pinMode(switchPinArray[i], INPUT_PULLUP);

  Serial.println("Ready - Waiting for AgOpenGPS...");
}

void loop() {
  if (millis() - lastTime >= loopTime) {
    lastTime = millis();
    watchdogTimer++;

    if (watchdogTimer > 80) {
      allRelaysOff();
      if (aogConnected) {
        aogConnected = false;
        digitalWrite(PinAogReady, !readyIsActive);
        Serial.println("AOG timeout - disconnected");
      }
    }

    bool autoMode = !digitalRead(AutoSwitch);

    if (autoMode && aogConnected) {
      runAutoMode();
    } else {
      runManualMode();
    }

    sendBasicStatus();
  }

  parseAOGData();
}

// ====================== CORE FUNCTIONS ======================

void allRelaysOff() {
  for (int i = 0; i < 8; i++) {
    digitalWrite(relayPinArray[i], !relayIsActive);
  }
}

void runAutoMode() {
  for (int i = 0; i < 8; i++) {
    bool aogWantsSectionOn = bitRead(relayLo, i);

    // If section switch is closed (LOW), follow AOG
    if (digitalRead(switchPinArray[i]) == LOW) {
      digitalWrite(relayPinArray[i], aogWantsSectionOn ? relayIsActive : !relayIsActive);
    } else {
      digitalWrite(relayPinArray[i], !relayIsActive);   // force OFF
    }
  }
}

void runManualMode() {
  if (digitalRead(ManuelSwitch) == LOW) {   // Manual mode active
    for (int i = 0; i < 8; i++) {
      if (digitalRead(switchPinArray[i]) == LOW) {
        digitalWrite(relayPinArray[i], relayIsActive);   // ON
      } else {
        digitalWrite(relayPinArray[i], !relayIsActive);
      }
    }
  } else {
    allRelaysOff();
  }
}

void sendBasicStatus() {
  uint8_t packet[14] = {0x80, 0x81, 0x7B, 0xEA, 8, 1, 0, 0, 0, 0, 0, 0, 0, 0};
  uint8_t sum = 0;
  for (int i = 2; i < 13; i++) sum += packet[i];
  packet[13] = sum;
  Serial.write(packet, 14);
}

void parseAOGData() {
  static uint8_t buffer[40];
  static int count = 0;

  while (Serial.available() > 0) {
    uint8_t incoming = Serial.read();
    if (count < 39) buffer[count++] = incoming;

    // Look for header 0x80 0x81 0x7F (FromAOG) + PGN 0xEF (239)
    if (count >= 14 && buffer[0] == 0x80 && buffer[1] == 0x81 && buffer[2] == 0x7F && buffer[3] == 0xEF) {
      relayLo = buffer[9];        // SC1to8 byte is at position 9 in PGN 239
      watchdogTimer = 0;

      if (!aogConnected) {
        aogConnected = true;
        digitalWrite(PinAogReady, readyIsActive);
        Serial.println("*** AOG CONNECTED - Receiving section commands ***");
      }

      // Debug: show what AOG is sending
      Serial.print("Sections from AOG (binary): ");
      for (int b = 7; b >= 0; b--) Serial.print(bitRead(relayLo, b));
      Serial.println();
      
      count = 0;
    }
  }
}

This is a better explanation of the code i was using. I can get the AGio to recognize the machine board but it never seems to send it a package it the esp can under stand. I have tested it with other code and the relay board functions as it should. Can anyone see why I would get communication from AgIo to the board ?

Is there a way to watch the serial monitor while being connected to AGIO ?

I don’t know from where you have this code but the parseAOGdata() doesn’t seems robust.

You have better ways if you look at the USB autosteer modules.

Maybe I read it the wrong way but it seems to me that your code will not recover if you miss some data.

For some reason i was not able to get MTZ code to work. I found a very simple sectional control and was able to get it to function properly. https://discourse.agopengps.com/uploads/short-url/c2K5JW6OpeRyqp7wHc5LjgBwyx.zip. I struggled getting the code to work. Handling downloaded files is not a strong suit of mine i seem to put them into files incorrectly and then it doesn’t like parts of the code being missing from the correct folder