Arduino VESC Remote

Forum dedicated to electrical projects
User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Arduino VESC Remote

Postby Josh Hess » Sat Jun 25, 2016 1:25 am

Original Project Topic: https://endless-sphere.com/forums/viewt ... f&start=75

As I began my planning for my electric longboard build, I noticed that there aren't a lot of good quality remotes for the diy electric longboard community. The two most common remotes I saw were modified wireless Wii nunchucks and modified rc car remotes. These both utilize potentiometers and are not very compact. Also they have very limited customization options and offer no way of seeing real time info from the board. Right around this time I happened to see @RollingGecko on endless sphere.com start a topic on an open source remote he was working on. He had a lot of the software figured out but was trying to integrate it into a wii nunchuck. I decided this was a perfect opportunity to create the best possible remote for electric longboards.

I started with a sketch. My original plan was to use parts I knew existed. This included a small Arduino, sparkfun charging board, sparkfun battery, joystick assembly, old display and a Bluetooth module. The housing was to be designed and 3d printed. Here is a picture of my original sketch:

image.jpg


After doing some more research, I decided it would be best to switch to a Hall effect based sensor and use the Adafruit feather. This board was very small, had a built in battery charger, and also a built in Bluetooth module. Here are some of my models and the design progression and refinement:

Early Model:

youtu.be/Lzt_KDR6STA

Mark II Model:

youtu.be/i6yhbGvQOHs

Accelerator/Brake Control Mechanism:

youtu.be/fJ5PC7hjBZw

Hall Effect Sensor Testing:

youtu.be/hwvrnLCFMQc

I acquired all the parts and began 3d printing the housing. The first print had errors on the printer side. The second print was good for the most part but there were several minor adjustments that were made.
Here is a log of the first revision adjustments:
- Raised Hall effect sensor for added range
- Lessened distance between magnets
- Added additional tolerance between thumb plate and housing
- Removed spring plate top peg
- Redesigned trigger with rotational movement instead of linear
- Tac switch mounts tolerance adjusted

The third print verified some new changes and the fourth had all the features fully working as intended.
Second revision change log:
- Trigger button tolerance adjusted
- Feather stand offs shortened
- Housing internal chamfer added

Here is a video of the third prototype:


youtu.be/QyOyW1gBfec

The next steps will be to wire everything else together and implement the Hall effect sensor code with RollingGecko's. Then I will hopefully have my Vescs and I can begin doing full tests.

That's it for now, updates to come!
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Sun Jun 26, 2016 2:17 am

An update with regards to the housing. I have let several people hold and use the prototype and asked them for their opinion on the ergonomics of it. Each person had slightly different comments but the most prevalent were "it feels too thin and too wide" and "the thumb wheel is slippery".

I designed the remote to be thin so that it can fit in pockets comfortably when not using. However, right now it is just over 15mm thick so adding a few mm of thickens would be fine. Also it would give a bit more breathing room for wiring inside. The width was square and uniform on the initial design as I wanted to leave room for components and wiring. Since it will be thickened vertically, there will be more room for wiring there and some width can be taken off the sides. I am planning on doing a taper from the screen to the bottom. This should make it more comftorable to hold.
The thumb wheel was printed with no grip design and this was something I planned to revisit after initial testing, The next iteration will have an aggressive grip design so it can be used easily and reliably even if the user is wearing gloves or has sweaty hands.

In addition to these revisions, I will also be adding a fifth housing screw adjacent the trigger so that the middle portion of the housing is held together. In my tests, four screws on each end left the middle slightly saggy. I will also be exploring ribbing options to add even more rigidity and strength.

Here is the log of things to be updated in the next revision:
- Increased total housing thickness ~ 2mm
- Added grip design to thumb wheel
- Spring plate updated to accommodate screw post
- Ribbing for added reinforcement
- Support posts for tac switches
- Adjusted screen position for center fit
- Tapered housing width for better grip and feel

Updates to come!
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Tue Jun 28, 2016 1:45 pm

I completed all of the above changes and printed the new remote. Since there was so much change about the design I am calling this a new mark and thus this is mark III. Let's take a look at the changes up close.

Here is a short video showing some of the changes:

youtu.be/bIVFoIzQGSQ

First off, let's start with the ergonomic changes. The housing was tapered from the screen down about an 8th of an inch on both sides. Although this doesn't sound like much, it make a huge difference with the feel of the remote. I also adjusted the trigger area so that it didn't "hook" you index finger as much. Also the trigger was updated to be lower profile and feel better with these changes. Here are some side by side pictures of it next to the last iteration.

image.jpeg


A close up of the trigger:

image.jpeg


Also the indentations around the two buttons were increased in depth for easier button pushing. Finally, the thumb lever pad was modified with an aggressive grip pattern. This works great even with oily hands or gloves.

image.jpeg


Overall, these external changes made the remote much more ergonomic and easier to hold and use. Here is is in my hand:

image.jpeg



Moving on to the changes on the inside. The internal chamfer was thickened for added support and rigidity. Ribs were added in places that could use support (more will be added later) and another screw hole was added to ensure the middle of the housing remained completely closed. Pins were added to support push buttons and a hole was added on the back of the housing for easy access to the feathers reset button.
image.jpeg
image.jpeg

image.jpeg
image.jpeg

image.jpeg


Also the display was adjusted so it is now perfectly centered.
image.jpeg


The internal changes really made this remote feel solid. There is no flex on the sides no matter how hard you squeeze.There are a few things I still need to tweak. There are a few places that the 3d printer leaves gaps (specifically on the screw standoffs) and this is problematic as substantial strength is lost. I will try to fix this by widening these areas. Also I will add another pin to come down and hold the trigger button in place as it fell out during one of my impact tests. Other than that, everything looks good. I have given this new remote to a few people that held the last iteration and they said it felt much better.
Anyway, that's it for now!
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Wed Jun 29, 2016 2:33 pm

Ok so a quick update on the remote. I did a few drop tests and noticed a small problem with the housing. The screw standoffs for the housing were too thin and failed. The printer actually printed a tube inside a tube instead of printing one larger tube like it should have. I think the wall thickness was too thin and the printer could not fill. I have revised the model and thickened these screw standoffs. I also added ribs for increased strength. Another thing I added was a lip where the display goes. This will allow the display mounting screws to better thread and also adds more rigidity around the display (a place where the most flex was previously).

I will begin printing shortly and will post another update by the end of the day.
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Thu Jun 30, 2016 5:30 pm

An update on the remote. I was able to beef up the screw headers and also raise the feather and oled such that the screws thread well. I had to move the trigger over a bit and ended up remodeling it so it is lower profile. Also a pin was added over the trigger button such that it is held securely in place. More ribs were added around screw posts and an attachment point was created for a wrist strap could be added if desired.

Here is a video of the updated remote:

youtu.be/VU7m9DUfVic

I have also been working on a pinout for all the electronics to keep track of all the pins used.
Here is the google doc for that: https://drive.google.com/open?id=0BzqjX ... GItUk1jajQ

That's about it for now. Next I will be looking into writable memory options for storing telemetry, settings, and more. I will have to be creative to fit it into the existing remote. Updates to come.
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Fri Jul 01, 2016 2:39 pm

I began working on some code for testing purposes. I made a little program to measure the hall effect sensor and battery and display info about them on the screen.
Here is a video of the remote running the test program:

youtu.be/1jJkVAt6YOw

Most of the code is modified from examples I found online. I also included a very basic calibration routine which I will be working on more later for the final remote. Here is the code:

Code: Select all

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

// If using software SPI (the default case):
#define OLED_MOSI   6
#define OLED_CLK   10
#define OLED_DC    11
#define OLED_CS    12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

#define XRANGE  19

int x,gss,y;

const int sensorPin = A0;

int sensorValue = 0;         // the sensor value
int sensorMin = 700;        // minimum sensor value
int sensorMax = 200;           // maximum sensor value


void setup()   {               
  Serial.begin(9600);
 
  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);
  // init done
 
  // Show image buffer on the display hardware.
  // Since the buffer is intialized with an Adafruit splashscreen
  // internally, this will display the splashscreen.
  display.display();
  delay(2000);

  // Clear the buffer.

  display.clearDisplay();

  while (millis() < 10000) {
    sensorValue = analogRead(sensorPin);
 
    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }
 
    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }
  }
}


void loop() {

  #define VBATPIN A7
   
float measuredvbat = analogRead(VBATPIN);
measuredvbat *= 2;    // we divided by 2, so multiply back
measuredvbat *= 3.3;  // Multiply by 3.3V, our reference voltage
measuredvbat /= 1024; // convert to voltage

int percent;
const float lipoDc[2][11] = { { 3.2, 3.680,3.740,3.780,3.810,3.850,3.870,3.960,4.02,4.100,4.200 } ,{ 0.000, 0.100,0.200,0.300,0.400,0.500,0.600,0.700,0.800,0.900,1.000 } };
int ind;
  if(measuredvbat>=4.2)
    percent=100;
  else
  {
    while (!(measuredvbat<=lipoDc[0][ind+1] && measuredvbat > lipoDc[0][ind])&& ind<=10)
    {
      ind++;
    }
 

    if (measuredvbat <= lipoDc[0][ind + 1] && measuredvbat > lipoDc[0][ind])
    {
      float CapacPers = (((lipoDc[1][ind + 1] - lipoDc[1][ind])/ (lipoDc[0][ind + 1] - lipoDc[0][ind]))*(measuredvbat - lipoDc[0][ind])) + lipoDc[1][ind];
    //  int intCapacPers = (int)(CapacPers * 100);
      percent = (int)(CapacPers*100.0);
    }
  }

  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(48,0);
  display.clearDisplay();
  display.print(percent);
  //display.print(measuredvbat);
  display.println("%");

  display.setCursor(0,30);
  display.setTextSize(1);
 
   
  int aValue =analogRead(0);
 
  y = map(aValue, sensorMax, sensorMin, 0, 1024);

  if (y < 552 && y > 472)
    y = 512;

  x = map(y, 0, 1024, 0, XRANGE);


 
  display.print("|");
  for (int i=0;i<x;i++){
    if(i==XRANGE/2)display.print("|");
    else display.print("-");
  }
  display.print("O");
  for (int i=x+1;i<XRANGE;i++){
    if(i==XRANGE/2)display.print("|");
    else display.print("-");
  }
  display.print("|");

  display.setCursor(53,50);
  display.print(y);

 display.display();
 
}



So lets break up the code and explain what's going on.

Hall Effect Calibration
Starting off, in the setup, there are a few initiations for the display and serial but the main thing is the calibration bit:

Code: Select all

while (millis() < 10000) {
    sensorValue = analogRead(sensorPin);
 
    // record the maximum sensor value
    if (sensorValue > sensorMax) {
      sensorMax = sensorValue;
    }
 
    // record the minimum sensor value
    if (sensorValue < sensorMin) {
      sensorMin = sensorValue;
    }

After to two second screen splash, this bit of code looks at the min and max value from the hall effect sensor. In the video, you will see me rest the remote and push the thumb leaver to full throttle and full brake. This is so this bit of code can adjust the absolute min and max of the control. This information is used later in the program, and we will revisit this later.

Reading the Battery
So adafruit did a nice job with their battery system on the feather. Not only is there a charging system, but they actually have a built in voltage divider tied to pin 9 from the battery. This means you can read that pin to get the battery voltage. Here is the code I used to do just that:

Code: Select all

#define VBATPIN A7
   
float measuredvbat = analogRead(VBATPIN);
measuredvbat *= 2;    // we divided by 2, so multiply back
measuredvbat *= 3.3;  // Multiply by 3.3V, our reference voltage
measuredvbat /= 1024; // convert to voltage


Correlating Voltage to Capacity
I wanted to know the percentage of the battery, not its voltage. Although it is not extremely accurate, you can match a given voltage of the battery to a percentage of capacity. Using an array to do this, you can also have some estimation between point values. See the code here:

Code: Select all

int percent;
const float lipoDc[2][11] = { { 3.2, 3.680,3.740,3.780,3.810,3.850,3.870,3.960,4.02,4.100,4.200 } ,{ 0.000, 0.100,0.200,0.300,0.400,0.500,0.600,0.700,0.800,0.900,1.000 } };
int ind;
  if(measuredvbat>=4.2)
    percent=100;
  else
  {
    while (!(measuredvbat<=lipoDc[0][ind+1] && measuredvbat > lipoDc[0][ind])&& ind<=10)
    {
      ind++;
    }
 

    if (measuredvbat <= lipoDc[0][ind + 1] && measuredvbat > lipoDc[0][ind])
    {
      float CapacPers = (((lipoDc[1][ind + 1] - lipoDc[1][ind])/ (lipoDc[0][ind + 1] - lipoDc[0][ind]))*(measuredvbat - lipoDc[0][ind])) + lipoDc[1][ind];
    //  int intCapacPers = (int)(CapacPers * 100);
      percent = (int)(CapacPers*100.0);
    }
  }


We can now print this info out to the display using this code:

Code: Select all

display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(48,0);
  display.clearDisplay();
  display.print(percent);
  //display.print(measuredvbat);
  display.println("%");


Remapping and Visualizing Hall Effect
Now revisiting the hall effect code from earlier, we need to remap it to a standard range. In this case I decided to map it to 1024 to be used later for throttle control. I also gave a 40 unit margin around the middle point. If it is plus or minus 40 from 512, it returns as 512. I also wanted a way to visualize the readings. I did another map from our new 1024 map but this time I mapped it to XRANGE which was defined as 19. This was the largest value I could find that would fit the full width of the OLED display. This new map info is used to print a visualizing bar. I also decided to print out y (the current value in our 1024 range) for reference.

Code: Select all

  int aValue =analogRead(0);
 
  y = map(aValue, sensorMax, sensorMin, 0, 1024);

  if (y < 552 && y > 472)
    y = 512;

  x = map(y, 0, 1024, 0, XRANGE);


 
  display.print("|");
  for (int i=0;i<x;i++){
    if(i==XRANGE/2)display.print("|");
    else display.print("-");
  }
  display.print("O");
  for (int i=x+1;i<XRANGE;i++){
    if(i==XRANGE/2)display.print("|");
    else display.print("-");
  }
  display.print("|");

  display.setCursor(53,50);
  display.print(y);

 display.display();


Well that's it for now, I will continue fiddling with code and hopefully I can get a nice calibration program written in a timely manner. On a side note, I ordered another set of arduino parts so I can have one remote for development and one for hardware testing, ie durability testing.

Updates to come!
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Sun Jul 24, 2016 2:03 am

Since the last update, a few things have happened. I continued tweaking the remote housing so it feels better in the hand. The most notable change was its thickness was increased by 4mm for a total of about 19mm. The external and internal chamfers were adjusted for both a better feel and added strength. Other minor changes included updated screw posts with reinforced bottoms, adjusted Hall effect sensor placement, and updated throttle spring plate. As far as the housing goes, it is well.

Unfortunately, it has been brought to my attention that the BLE module does not support central mode (a master connection type) and thus can only be used as a peripheral device. This is a huge problem as that is what we need it to use. It turns out that Adafruit loads their own firmware on the Bluetooth and the firmware is the limiter In this case.

More research is needed and I have since attempted to contact Adafruit to ask them for a firmware update. I will most likely have to use a different Bluetooth module or flash it myself if I am to continue.

Updates to come.
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Tue Aug 30, 2016 10:54 pm

After about a month of research and collaboration, I have excellent news!
I have been working with someone on the feather BLE module and we have successfully flashed and tested firmware with central mode functionality!!! :D :D :D We used an existing stack (heartbeat) used for fitness devices and was able to communicate with a usb bluetooth module which was configured as a peripheral device. This proves the feather can work for what we need!!!

The next step will be to load a UART stack and play with that. I will have more details as progress is made.

Updates to come!
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Thu Oct 13, 2016 9:45 am

Ok so a lot has happened recently. I had to put the project on hold for a little bit to catch up on some other work but I am now back to working on this. I have done a fair amount of work over the last two days.

Firstly, I rewired the OLED display from SPI to I2C to conserve digital pins. While I had it open, I also wired up the FRAM module via I2C and the trigger button. At this point, the only things left to wire are the two front buttons which I will get to today.
I adjusted my code for the new display and tested out the memory and trigger button. I also made a nice little case to hold the remote and extra parts and I wrote an outline for the remote functions, menu system and features.
Some pictures:
image.jpeg
image.jpeg
image.jpeg


The main thing I need to work out (other than the ble) is power management. I.e. How to turn it on and off. There are essentially two ways to do this with this board. Add an external switch or circuit to tie the EN pin to ground to shut off the 3.3v rail, or implement low power mode/sleep mode to all power consuming components with an interrupt routine to wake.
The first rout would be easiest, all that would be required is a small toggle switch, however this poses two issues in my mind. One, there is a major safety concern with a mechanical switch as it could accidentally be switched off when riding. Second, it takes up extra space and would make the remote slightly less elegant. Alternatively, a latching circuit with logic input from the feather could be used to solve this, but that would add expense and require internal space which is running very low. (This would not be an issue later with a pcb)
So for now, I am going to go with the second option and see how low I can get the power draw. I have started by adding code to turn off the display after 20 seconds. Just this resulted in a battery drop from 2-3 percent/hour to around 1 percent per hour. Putting the ble module and main cpu in a low power state or sleep state could reduce this battery drain to less than a percent every 12 hours. If I can get it to this point, that will be acceptable for the final design. However, if not, I will revisit the first option with the latching circuit and implement that later when it is pcb'd.

So in conclusion, I will be working on the ble, power management, and code until the next update.
Science may set limits to knowledge, but should not set limits to imagination.

User avatar
Josh Hess
Site Admin
Posts: 125
Joined: Sun May 24, 2015 6:00 pm
Location: Orlando, FL
Areas of Knowledge: Electronics, Product Design, Manufacturing
School/University: UCF

Re: Arduino VESC Remote

Postby Josh Hess » Sat Dec 31, 2016 7:46 pm

Since the last update, I have done a lot of code work. The remote now has a fully functioning menu system that is object based. I had to get a lot of help to learn how to do this as the original method I was using (array) was getting very messy. I have also made a few minor revisions to the housing and printed it in black. It looks very good in black! :D
1.jpg

3.jpg

4.jpg


There are a few things I am sorting out before moving to the BLE when I get back from break. Firstly, the tactile switches I got from amazon seem to be low quality and don't always remain activated even when clicked. This presents a safety concern especially with the trigger button as it will cut the throttle if not pressed (or not pressed hard enough). I have looked at a few different types I had laying around the house and they all don't seem to have this issue. I have just placed an order from Mouser for a few different types of switches from Panasonic with low actuation force so I will spend some time trying these different ones.
Another thing I want to do is rewire the display and buttons. The display is currently running over I2C and it has a fair bit of latency compared to SPI. I have it in I2C to conserve digital pins for the buttons, but I forgot I can do a digital read from the analog pins as well. :roll:
The last thing I want to work out is the font for the menu and main display screen. Right now I am using the default font from the GFX library and it's fine but when you want to make it bigger, the only way is to scale it and it looks very low res and blocky. There are other fonts but whenever I call them, they are much bigger than I would like (even the 9pt). I have played with it for hours and looked it up with no avail. I will have to make a post about it on the Adafruit forums to get it sorted out. :?

Anyway, as usual, updates to come!
Cheers!
Science may set limits to knowledge, but should not set limits to imagination.


Return to “Electrical”

Who is online

Users browsing this forum: No registered users and 1 guest