You are reading a single comment by @Gordon and its replies. Click here to read the full conversation.
  • what happens if you just do:

    Bluetooth.setConsole(1);
    Serial1.setup(9600,{rx:D14});
    Serial1.on('data', function(d) {
      console.log("SERIAL:"+JSON.stringify(d))­;
    });
    
  • First it complains that i have to define both tx and rx pin, then it just prints undefined once and no data is arriving.

  • 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();
    
  • 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;
    	}
    }
    
About

Avatar for Gordon @Gordon started