You are here

Can't get motor to run using COMM port on vesc 6 MKVI and arduino mega with a potentiometer and SolidGeeks UART library

2 posts / 0 new
Last post
Kokonenen
Offline
Last seen: 1 year 6 days ago
Joined: 2023-02-16 08:41
Posts: 12
Can't get motor to run using COMM port on vesc 6 MKVI and arduino mega with a potentiometer and SolidGeeks UART library

Hey, I am trying to control my motor with an arduino and a potentiometer lever, but I can't get any control at all, I have no issue revving the motor with vesc tool, and I have no issue reading values from the potentiometer on the mega. But connecting them is where nothing happens. I am using UART communication with Serial1 port on the arduino mega (18 and 19 for TX and RX) to the COMM port on the vesc 6 MKVI. The vesc is powering the arduino board and the vesc is powered by a 12v battery.

I would really appreciate some help if you've got any experience with this, have been tinkering for hours

Here is my connection: https://i.imgur.com/9GowH8M.jpg

The vesc tool has UART set as app to use and baud rate to 115200, just like the arduino 
Here is my code:

    // #include <SoftwareSerial.h>
    #include <VescUart.h>
    
    // const byte rxPin = 2;
    // const byte txPin = 4;
    
    //SoftwareSerial mySerial (rxPin, txPin);
    
    VescUart UART;
    
    
    uint32_t LastTime = 0; 
    
    // SoftwareSerial mySerial(2, 3); // RX, TX
    
    // the setup routine runs once when you press reset:
    void setup() {
      // initialize serial communication at 115200 bits per second:
      Serial1.begin(115200);
     // mySerial.begin(115200);
    
      UART.setSerialPort(&Serial1);
    }
    
    // the loop routine runs over and over again forever:
    void loop() {
      if((millis() - LastTime) > 10){
        
      // read the input on analog pin 1:
      int sensorValue = analogRead(A0);
      if (sensorValue >= 511) {
        sensorValue = map(sensorValue, 511, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
        
        UART.nunchuck.valueY = sensorValue;
    
        UART.setNunchuckValues();
    
        
      }
      else {
        sensorValue = map(sensorValue, 511, 0, 0, 0); //Map value 0-1023 to 0-0 (PWM)
      }
      // print out the value you read:
      LastTime = millis();
    
      byte incomingByte = Serial1.read();
      Serial.println("Värden skickade");
      Serial.println(incomingByte);
      
      UART.getVescValues();
     // Serial1.println(sensorValue);
      //Serial1.println(UART.data.rpm);
      //Serial1.println(UART.data.inpVoltage);
     // Serial1.println(UART.data.ampHours);
      
      
      }
      
     
    }

Kokonenen
Offline
Last seen: 1 year 6 days ago
Joined: 2023-02-16 08:41
Posts: 12

Update! Got it to accelerate by changing three things:

I redownloaded the SolidGeek library and added to arduino

I added these three lines to the code: 
#include <buffer.h>
#include <crc.h>
#include <datatypes.h>

and I changed the connection on the COMM port from "VCC" to "5V" (the white wire going to the VESC on the picture)