Communication between brain and arduino through rs485

Hello, I am looking to connect an Arduino to the V5 brain so I can use certain sensors for the VEX AI Robotics competition. My intention for the arduino is to essentially act as a middleman between these sensors and the V5 brain. Anyway, I understand that you must use some rs485 board to communicate between a V5 port and the Arduino. However, I have no idea how to do this. Could anyone give me guidance here (and perhaps provide a schematic)? Thank you for your help in advance!

perhaps this as a starting point

However, I would avoid using the C APIs such as vexGenericSerialEnable and instead use the vexlink class in VEXcode setup for raw communication.

vexlink raw example
/*----------------------------------------------------------------------------*/
/*                                                                            */
/*    Module:       main.cpp                                                  */
/*    Author:       james                                                     */
/*    Created:      11/22/2024, 4:12:19 PM                                    */
/*    Description:  V5 project                                                */
/*                                                                            */
/*----------------------------------------------------------------------------*/
#include "vex.h"

using namespace vex;

// A global instance of vex::brain used for printing to the V5 brain screen
vex::brain       Brain;

// subclass serial_link to allow access to baudrate set function
class sensor_link : public vex::serial_link {
    public:
      // name not used
      // isWired not used, can only be wired if raw link
      sensor_link(int32_t index) : serial_link(index, "name", vex::linkType::raw, true) {
        baud( 115200 );
      }
      virtual ~sensor_link() {
      }
};

// setup ports to send and receive data
sensor_link    tx_link( PORT1 );
sensor_link    rx_link( PORT2 );

int
tx_thread() {
    char *tx_buf = "Hello";

    while(1) {
      tx_link.send(tx_buf, strlen(tx_buf) );

      this_thread::sleep_for(100);
    }

    return 0;
}

int
rx_thread() {
    uint8_t rx_buffer[128];
    
    while(1) {
      if( rx_link.isReceiving() ) {
        int nRead = rx_link.receive( rx_buffer, sizeof(rx_buffer), 50 );

        if( nRead > 0 ) {
          for(int i=0;i<nRead;i++) {
            printf("%02X(%c) ", rx_buffer[i], rx_buffer[i] );
          }
          printf("\n");
        }
      }
      else {
        this_thread::sleep_for(10);
      }
    }

    return 0;
}

int main() {
    thread tx( tx_thread );
    thread rx( rx_thread );

    while(1) {
        
        // Allow other tasks to run
        this_thread::sleep_for(10);
    }
}
1 Like

This is really great! And helpful! Does anyone work this through?