VESC Open Source - Android App Features?!?!

HI,

SoftwareSerial should work. I've currently running it on an MEGA2560. There I've enough serial ports and didn't test it yet.

With 9600 Baud check if you have set also on the VESC the UART speed to 9600. By default it is at 115200. Turn on the application UART or UART +PWM.
If you still have no luck try to increase the delay. I've one implemented between sending the request and waiting for the answer:

Code:
bool VescUartGetValue(bldcMeasure& values) {
	uint8_t command[1] = { COMM_GET_VALUES };
	uint8_t payload[256];
	PackSendPayload(command, 1);
	delay(100); //needed, otherwise data is not read
	int lenPayload = ReceiveUartMessage(payload);
	if (lenPayload > 0) {
		bool read = ProcessReadPacket(payload, values, lenPayload); //returns true if sucessfull
		return read;
	}
	else
	{
		return false;

delay(100); //needed, otherwise data is not read
 
Thanks dude, appreciate the response.

Yep I have set everything to 9600 including the VESC. It's almost like the mySerial.available() is never called (mySerial is my SoftwareSerial port).

I can send commands and control the VESC no problem, with the same hardware...so transmit to the VESC is great, but receive is staying quiet on me :? Gonna play with the UART friend module for a bit and see if I get joy on that.
 
Thanks alot, but don't worry too much - sounds like you've got your hands full with your project, and I'm pretty sure this must be my LightBlue Bean MCU messing me about.

Here's a zip with 3 sketches in it: http://gourmetpixel.com/tests/bens/VESC/BensVESCSketches.zip

They have all been setup to use SoftwareSerial on pins D0 and D1. They are meant to work on the LightBlue Bean, where the Serial definition is the BLE port. I am using a serial monitor to look for response.

The sketches are:
- A super simple bridge that just pipes one serial to the other (serial.available to serial.write and vice-versa). Using this I can control the VESC, but nothing back.
- Vedders code http://vedder.se/2015/10/communicating-with-the-vesc-using-uart/. With this, any serial comms seems to freeze up the Arduino
- Your code https://github.com/RollingGecko/VescUartControl. With this I only get "Failed to get data!". 0 bytes coming back to ReceiveUartMessage

None of these work, so I can only deduce 3 things:
1) The SoftwareSerial library is crapping out somehow on the Bean (although I've read it should work up to 19200 baud on this 8mhz chip)
2) The VESC isn't working at 9600 baud, or isn't listening to the baud rate set in BLDC tool
3) I'm just an idiot

:p
 
hi subcreative, that's a good suggestion since a lot of ppl (like myself) have not touched c in ages. i've started a hybrid cordova app. the realtime dash is about 80% done but the config and serial/bt is still w.i.p. (haven't pushed it to github yet because it's still undergoing some major refactoring). goal is to keep it very modular so ppl can extend with custom layouts/styling. my first version was written on ionic/angularjs but i scrapped that in favor of cordova/jquery/vanillajs (in angular, the code was getting too bloated and hard to read/debug).

the advantage of not using a framework is it lowers the learning requirements (ie. accessible to more developers). i'd consider meteor or reactjs for this type of project. reactjs has a good support community, non-opinionated structure and jsx--really nice to use. unfortunately, meteor still doesn't have windows support for their mobile build tools.

SubCreative said:
jacoby have you ever considered making this cross platform using something like meteor.js? I did cross platform mobile development at a startup using meteor.js and think it could be really powerful opening up to both android and iphone. Using meteor you still have native access to the device hardware and information via cordova, just something to consider.

Edit: This would make the bluetooth layer pretty easy to integrate also, I'd be willing to help start the project on github if anyone is interested.
 
hey guys i could use some help. i'm trying to implement vedder's packet protocol into my app but i am having a difficult time getting a response. my app is hybrid cordova/html5/javascript.

i am using cordova plugin that exposes bluetooth on android to the webview (that is accessible in the html/javascript). the plugin can write string or uint8array:

https://github.com/don/BluetoothSerial

in my app i am able to scan and connect to the HC-06 bluetooth module (that is connected to the VESC uart). ppm + uart is enabled on the vesc and both set to 9600 baud.

since i am not sure of my crc16 implementation, i used a serial monitor to capture the packets from bldc_tool to vesc. to get values, i see it is sending "terminal cmd" and "get values cmd" together (17 & 4):

02 01 17 62 D6 03 02 01 04 40 84 03

if i use a pc terminal to send this to the HC-06 i get a response:

02 38 04 01 4E 01 4F 01 4F 01 4F 01 4F 01 4F 01 4F
FF FF F7 17 FF FF FF F9 00 02 00 00 00 00 00 94
00 00 00 00 00 00 00 1E 00 00 00 00 00 00 01 C0
00 00 00 00 00 00 00 00 00 D9 0D 03

however, in my javascript code, if i write this out to the HC-06 i get no response at all. HC-06 seems to be working as i've been able to echo to it (with HC-06 connected to an arduino running serial monitor). i've tried changing the HC-06 baud rate to 115200 just in case bldc_tool isn't using the uart user setting...but still no go.

javascript code:

var msg = new Uint8Array([0x02 0x01 0x17 0x62 0xD6 0x03, 0x02, 0x01, 0x04, 0x40, 0x84, 0x03]);
bluetoothSerial.write(msg);
write() is successful, but read() always comes back empty.

any help would be appreciated.
 
So...

I need help making an app for my eboard product in development (promise I'm not inboard). Have some leads, but now I see a bunch of you sphericals already have basically done what I need, just need to massage it a bit to work with my controller. Any chance you guys would do a build for me? Needs to work for iOS and android.. Over Bluetooth. Have CAN or UART connection available

Also, what drew you guys to the Bluetooth hardware you selected over the alternatives? I was hoping to have a little <$10 daughter board I could connect directly to UART
 
thanks i'll try that. btw, this would make a nice addition for those of us developing client apps for the vesc (if anyone wants to take a shot at integrating it into the firmware :)

https://developers.google.com/protocol-buffers/

language agnostic serialization/deserialization of objects consumable in c++, java, python and even pure js:

https://github.com/dcodeIO/ProtoBuf.js

we live in exciting times. i believe open source technology such as vedder's vesc/bldc really help accelerate the adoption of ev's by empowering the ppl. if we could further lower the barriers to entry using the latest development tools, we could achieve critical mass. htm5/javascript is accessible to many ppl and there are tons of gui libraries available to build incredibly rich cross-platform apps. we have github which is an awesome social network to share/contribute code. now with facebook's new reactjs framework, high performance ui components can be easily reused. google's chromium engine running in the latest flavors of android is fast (and improving with each iteration). this is why i've decided to migrate my old code base (which was native android biased) to a pure html5/js implementation. for those of you ev enthusiasts (but non-programmers), now is the time to roll up your sleeves and start designing your future!


RollingGecko said:
Hi,

Try to set the vesc to a lower baud rate. I'm not sure if the hc06 likes 115200.
 
hi hillz, i'll push my app to github after i get the serial working (https://github.com/bchiu).
you can fork the code and do as you like (i'm all for personal commercial development---ppl need to eat). which controller are you using? i think it will require more than a little massaging. at this point, apps for vesc or ev's in general are very scarce/immature/non-existent.

HC-05 and HC-06 are very cheap. i paid $5 bucks for mine. they are indeed directly connected to uart. however, please note the differences between the two: http://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/?ALLSTEPS

hillzofvalp said:
So...

I need help making an app for my eboard product in development (promise I'm not inboard). Have some leads, but now I see a bunch of you sphericals already have basically done what I need, just need to massage it a bit to work with my controller. Any chance you guys would do a build for me? Needs to work for iOS and android.. Over Bluetooth. Have CAN or UART connection available

Also, what drew you guys to the Bluetooth hardware you selected over the alternatives? I was hoping to have a little <$10 daughter board I could connect directly to UART
 
Hi,
02 01 17 62 D6 03 02 01 04 40 84 03 : this is actually 2 frames. From the packet.c file in bldc-master sources, the first frame is
02: start
01: length
17: data
62 D6: CRC
03: stop
The datatypes.h gives Communication commands
typedef enum {
COMM_FW_VERSION = 0,
COMM_JUMP_TO_BOOTLOADER,
COMM_ERASE_NEW_APP,
COMM_GET_VALUES, -> this is 0x04 (04 décimal, command of the second message
....
COMM_ALIVE, -> this is 0x17 (23 décimal)
....
} COMM_PACKET_ID;
Maybe you can send only the second message 02 01 04 40 84 03, or leave some time between the 2 messages.
Otherwise, I use the HC06 at 115200 bauds for other applications. You need to configure the HC06 to change baud rate (using AT+BAUD8 for 115200) - by default, you can only use 9600 bauds. https://www.olimex.com/Products/Components/RF/BLUETOOTH-SERIAL-HC-06/resources/hc06.pdf
As for reading the response in Javascript, maybe you need to wait before reading ?
 
I mean basically all I would need is someone to build the GUI how I want and demonstrate serial read/write capability and cross platform compatibility. Simple enough that it probably won't break with OS updates, right? I can code somewhat, but only in C.. my experience is solely in arduino IDE.

My controller is custom, but like I said, it has CAN
 
hi pf26. i've tried sending only the 2nd frame 02 01 04 40 84 03...no reply. i will try sending the 2 frames spaced a few ms apart. i am using setTimeout(function() { bluetoothSerial.read(0 }, 3000) after the write success. i have also tried read() in a delayed loop, bluetooth.readUntil('\n'), bluetooth.subscribe() and bluetooth.subscribeRawData() which should trigger callbacks on any data received...but so far nothing. i've also tried HC-06 at 115200 & 9600 along with corresponding bldc_tool setting...nothing.

i may have to dig into the bluetoothSerial plugin code to see if my js uint8array object is being correctly marshalled across. surprisingly, there are not many examples of this use case. is there a terminal command on the bldc_tool to watch the serial comms?

pf26 said:
Hi,
02 01 17 62 D6 03 02 01 04 40 84 03 : this is actually 2 frames. From the packet.c file in bldc-master sources, the first frame is
02: start
01: length
17: data
62 D6: CRC
03: stop
The datatypes.h gives Communication commands
typedef enum {
COMM_FW_VERSION = 0,
COMM_JUMP_TO_BOOTLOADER,
COMM_ERASE_NEW_APP,
COMM_GET_VALUES, -> this is 0x04 (04 décimal, command of the second message
....
COMM_ALIVE, -> this is 0x17 (23 décimal)
....
} COMM_PACKET_ID;
Maybe you can send only the second message 02 01 04 40 84 03, or leave some time between the 2 messages.
Otherwise, I use the HC06 at 115200 bauds for other applications. You need to configure the HC06 to change baud rate (using AT+BAUD8 for 115200) - by default, you can only use 9600 bauds. https://www.olimex.com/Products/Components/RF/BLUETOOTH-SERIAL-HC-06/resources/hc06.pdf
As for reading the response in Javascript, maybe you need to wait before reading ?
 
Hi j3tch1u,
If I understood well, you managed to get a response from VESC using a terminal program on a PC connected via bluetooth to the HC06?
Now did you try an Android bluetooth terminal freeware to check if it works using the same frame ?
With your implementation, possibly you could try using an HC06 with Tx and Rx tied together, just to see if you get responses (if you get a response, but not corresponding to what you sent, then probably the baudrate or other serial parameters are incorrect).
If you can post your code, I would be happy to help with tests - I have Android device, HC06 and VESC waiting...
 
Using VESC firmware 1.6 and HC06 (=BtBee from iteadStudio), I could communicate with a PC via bluetooth. VESC application set to ADC + UART (in bldc-tools)
First, at 9600 bauds setup the HC06 for 115200, sending AT+BAUD8 (upcase, no CRLF), you receive OK115200 (this requires a USB serial converter and a terminal soft to connect the HC06 RX and Tx to a PC COM port)
Then connect PWR_COMM port of VESC pin 1 to HC06-Tx, pin2 to HC06-Rx, pin 4 = 0V and pin5 = 3.3V.
Using hterm.exe on the PC, I create a bluetooth COM port and send (hexadecimal) 02 01 04 40 84 03 (no CRLF) and I receive 02 38 04 ... 03 from VESC.
Now if I use the "bluetooth terminal" on Android (setting input mode = hex, ending None), send 02 01 04 40 84 03 , I see that the VESC receives 02 01 04 40 84 03 00 00 00 00 00 00 (that is 6 times unwanted 00 after the fram), but still, the VESC does answer 02 38 04 ... 03 (seen at the HC06 input).
But the bluetooth terminal reports nothing. I think bluetooth terminal only reports answer ending by CR-LF (13 10 in hexadecimal).
 
I don't know about the terminal you are using. As I experimented arround with the VESC, I get a continuous stream without LF.

The useless 00 00 00 came for sure from the array used. The array is to big for the message.
 
pf26 said:
But the bluetooth terminal reports nothing. I think bluetooth terminal only reports answer ending by CR-LF (13 10 in hexadecimal).

Yep, that could be it. There isn't a CR-LF, you just need to read the packet start and stop bits, and check the datasize is correct. You explained it yourself above:

02: start
38: payload byte length
[payload]
03: stop

Have you tried running your payload through the unpacker to see if the actual reported payload values look OK?
 
The returned packet (seen from the PC) seems ok (size, start, stop, stable values..) I didn't really check the content. I tried bldc video logger, but it failed to open my Bluetooth serial port (possibly not waiting long enough).
 
OH SNAP!! it never occurred to me to check my pins. turns out i had the Rx and Tx shifted 1 pin over. (Tx was in the ADC...should be empty ADC between GND & Tx)...my bad :oops:

yay i'm getting a response now :D here is my test code:

Code:
	function handleError(error) {
		console.log(error);
	}

	function connectDevice() {
		bluetoothSerial.isConnected(
			function() {
				console.log("already connected");
			},
			function() {
			    bluetoothSerial.connect("98:D3:31:20:57:E0",
			    	function() {
			    		console.log("connected");
						bluetoothSerial.subscribe(
							function(data) {
								if (data=='') console.log('no reply');
								else { console.log(data) }
							}, handleError
						);
			    	}, handleError
			    );
			}
		);
	}

	function sendRequest(event) {
		var msg = new Uint8Array([0x02, 0x01, 0x04, 0x40, 0x84, 0x03]);
		bluetoothSerial.write(msg);
		console.log(msg);

		setTimeout(function() {
			bluetoothSerial.available(
				function (numBytes) {
					console.log(numBytes + " bytes available to read");
				}, handleError
			);
			bluetoothSerial.read( 
				function(data) {
					if (data=='') console.log('no reply');
					else { log(data); console.log(data) }
				}, handleError
			);
		}, 3000);
	}

	$('#serial_btn').click(sendRequest);

	document.addEventListener('deviceready', function() {
		connectDevice();
	}, false);
this is how the HC-06 - UART connector should look:

2015-10-27 01.10.46.jpg
 
one step closer but now...another problem. my crc16 ccitt implementation doesn't seem to yield the same values as vedder:

Code:
	crc16: function(s) {

		var crc16_tab = [0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0];

		var crc = 0xffff;

		for (var i = 0; i < s.length; i++) {
			var c = s[i];
			//var c = s.charCodeAt(i);
			crc = (crc16_tab[((crc >> 8) ^ c) & 0xff] ^ (crc << 8)) & 0xffff;
		}
		return crc;
	}
 
thanks pf26. the code i posted is a function and i'm only passing the payload "4" as a string into the function so it's basically a 1 char length array ['4']. i am not that familiar with crc. am i making a mistake in passing the literal decimal value character?

pf26 said:
CRC calculation starts from the data byte (3rd byte of the frame). For instance, only the 04 byte is used in 02 01 -04- 40 84 03 frame.
You can use the following site to check, line CRC-CCITT (XModem), input type hex, just enter 04.
http://www.lammertbies.nl/comm/info/crc-calculation.html
So, you may want to start your loop with i=2..
 
Back
Top