Avatar for Gustav

Gustav

Member since Nov 2017 • Last active May 2019
  • 8 conversations
  • 28 comments

Most recent activity

    • 11 comments
    • 126 views
  • in Interfacing
    Avatar for Gustav

    Yeah. Quiestion is how do i send the correct data ?
    Tested this without good result;

    const packLength =  E.toUint8Array("COMM_GET_VALUES").length­;
    const sendData = E.toUint8Array(2, packLength, "COMM_GET_VALUES", 3);
    Serial1.write(sendData);
    
  • in Interfacing
    Avatar for Gustav

    Here is some C code that i think does what im trying to do.

    int VescUart::packSendPayload(uint8_t * payload, int lenPay) {
    
        uint16_t crcPayload = crc16(payload, lenPay);
        int count = 0;
        uint8_t messageSend[256];
    
        if (lenPay <= 256)
        {
            messageSend[count++] = 2;
            messageSend[count++] = lenPay;
        }
        else
        {
            messageSend[count++] = 3;
            messageSend[count++] = (uint8_t)(lenPay >> 8);
            messageSend[count++] = (uint8_t)(lenPay & 0xFF);
        }
    
        memcpy(&messageSend[count], payload, lenPay);
    
        count += lenPay;
        messageSend[count++] = (uint8_t)(crcPayload >> 8);
        messageSend[count++] = (uint8_t)(crcPayload & 0xFF);
        messageSend[count++] = 3;
        messageSend[count] = '\0';
    
        if(debugPort!=NULL){
            debugPort->print("UART package send: "); serialPrint(messageSend, count);
        }
    
        // Sending package
        serialPort->write(messageSend, count);
    
        // Returns number of send bytes
        return count;
    }
    
    bool VescUart::getVescValues(uint8_t comm) {
    
        uint8_t command[1] = { comm }; // COMM_GET_VALUES or COMM_GET_UNITY_VALUE
    
        uint8_t payload[256];
    
        packSendPayload(command, 1);
        // delay(1); //needed, otherwise data is not read
    
        int lenPayload = receiveUartMessage(payload);
    
        if (lenPayload > 55) {
            bool read = processReadPacket(payload); //returns true if sucessful
            return read;
        }
        else
        {
            return false;
        }
    }
    
  • in Interfacing
    Avatar for Gustav

    Found some useful information

    Reading data is done with getter functions and callback function pointers. For example, to get realtime data from the VESC, first set a callback to your function for handling the data using bldc_interface_set_rx_value_func and then request the data with bldc_interface_get_values.

    // Every time you want to read the realtime data you call the corresponding getter.
    // This will send the get command to the VESC and return. When the data is received
    // the callback will be called from the UART interface.
    bldc_interface_get_values();
    
  • in Interfacing
    Avatar for Gustav

    First it complains that i have to define both tx and rx pin, then it just prints undefined once and no data is arriving.

  • in Interfacing
    Avatar for Gustav

    Thanks for your answer, no luck sadly. My guess is that i probably need to write some data to get some data.

  • in Interfacing
    Avatar for Gustav

    Hello everyone.

    I really want to get some data from the VESC (Vedders electronic speed control) via UART to a MDBT42Q Official Espruino breakout board. My only issue is that i dont realy know where to begin.

    There are a few libraries already written in C. Im not so familiar with C so its hard to get some useful info out of it;
    LIB1
    LIB2
    STM32F4 C Implementation

    What i do know; the VESC communicates over UART using packets with the following format:

    One Start byte (value 2 for short packets and 3 for long packets)
    One or two bytes specifying the packet length
    The payload of the packet
    Two bytes with a CRC checksum on the payload
    One stop byte (value 3)
    

    More detailed information here

    I would like some help with where to start basicly, i just want to get data from the VESC with espruino.

    There is a bluetooth module that i can hook on to the VESC aswell that has RX and TX characteristics pre programmed, so there is also a option to communicate via BLEUART.

    VESC Source code
    Thanks
    / G

    • 9 comments
    • 142 views
  • in Electronics
    Avatar for Gustav

    Awesome thank you both ! It works like a charm.

  • in Electronics
    Avatar for Gustav

    Alright, so its output is calibrated on 5v ? and because it reaches 3.3v rather quick, thats a 100% for the microcontroller ?
    Now the joystick is connected to Vin which is 4.2, but you mean that it will work if i connect it to 3.3v on microcontroller ?

Actions