You are here

UART Arduino Monitor

1 post / 0 new
arranto12
Offline
Last seen: 2 years 10 months ago
Joined: 2021-10-31 19:29
Posts: 7
UART Arduino Monitor

Hi all,

 

does anyone have a working setup or know of a working setup of an Arduino and a VESC 4.2? yes I know there are websites that detail how to do this, however, those examples either implement microcontrollers which I don't have or just doesn't have any information on how to get it working. I've found the VescUart library it doesn't seem to be working for my Arduino nano and my VESC. nothing seems to happen between them. is there anything I need to do I the vesctool settings or does this work regardless??

here is the code I have as a base to work from. 

#include <VescUart.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
// The pins for I2C are defined by the Wire-library.
// On an arduino UNO:       A4(SDA), A5(SCL)
// On an arduino MEGA 2560: 20(SDA), 21(SCL)
// On an arduino LEONARDO:   2(SDA),  3(SCL), ...
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

/** Initiate VescUart class */
VescUart UART;

void setup() {
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    //Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  display.clearDisplay();

  /** Setup UART port (Serial1 on Atmega32u4) */
  Serial.begin(115200);
  while (!Serial) {
    ;
  }
  /** Define which ports to use as UART */
  UART.setSerialPort(&Serial);
  
  display.setTextSize(2);
  display.setCursor(10, 10);
  display.setTextColor(WHITE);
  display.print("hello");
  display.display();
  delay(2000);

}

void loop() {

  /** Call the function getVescValues() to acquire data from VESC */
  if ( UART.getVescValues() ) {
    display.clearDisplay();
    display.setTextSize(2);
    display.setCursor(10, 10);
    display.setTextColor(WHITE);
    display.print(UART.data.rpm);

    display.display();

    /*
      Serial.println(UART.data.rpm);
      Serial.println(UART.data.inpVoltage);
      Serial.println(UART.data.ampHours);
      Serial.println(UART.data.tachometerAbs); */

  }
  else
  {
    display.clearDisplay();
    display.setTextSize(2);
    display.setCursor(10, 10);
    display.setTextColor(WHITE);
    display.print("Error");

    display.display();
  }

  delay(50);
}

 

thanks,

Arran.