DAVEga: Battery monitor, odometer, speedometer

Hehe, you guys exaggerate. It’s really nothing. Compare to, say, how much time Vedder must have put into the VESC and you’ll see how small the DAVEga is.

3 Likes

People drastically underestimate the amount of time it took to write the VESC 2.18 firmware.

3 Likes

Just wanted to say thanks to @janpom for awesome idea and all your work! I’ve uploaded code to arduino nano, using “current” branch. Seems to work with 2.2 screen, but I haven’t had a chance to connect it to vesc yet. Should buttons work (to change screens) without vesc connected? I have them wired to pins A2, A3 and A4, of course I updated davega.ino with these pins before uploading it to arduino. Is here someone less busy :wink: than janpom, who also knows programming well enough to make some little changes in what parameter is displayed on the screen with battery current? I’d be very happy, if someone could replace trip and total miles with mah used and motor temp. I don’t need to see the speed or mileage at all, as in my case vesc is mounted on electric bike (with different gears being used, so the speed shown will never be true). Thanks.

Hi, thanks for the nice compliments. The buttons don’t work until you connect to a VESC.

I’ll send you some guidelines on how to customize the screens later.

1 Like

Thank you, I’d really appreciate it. I’ve already connected DaVeGa to VESC and all worked first time :grin: My friend calls me cheater after we went for a ride today, for using my 2.8kW mid drive I’ve built from scratch on single track, but when I have shown him DaVeGa screen, he was speechless lol

1 Like

Alright, guys. It’s time to teach you some fishing since I don’t have enough fish for everyone.

Currently, there are 4 DAVEga screen layouts:

  • default

DSC01596

  • simple vertical

IMG_1550

  • simple horizontal

IMG_1583

  • text

IMG_1596

The layouts to be used can be configured here and then you can toggle between them with button 3. Normally you’ll want to enable 2 layouts: the text and one of the graphical ones. It doesn’t really make sense to enable more than 2 though you could.

The code is modular and each screen layout is one class:

You can customize existing layout by editing its class. (You can even add your own new layout. Just use any of the existing layouts as a template. This is not completely straightforward so I only recommend it to people with some coding experience.)

Now, let’s have a look how to get basic things done. To display a value, you’ll want to do two things:

  1. create a label for it
  2. display the actual value

Say that we want to modify the simple vertical screen such that it shows BATTERY AMPS instead of TRIP KM.

First, we’ll go to the reset() method where the labels are drawn. We’ll want to change the following line:

_tft->drawText(0, 130, _config->imperial_units ? "TRIP MI" : "TRIP KM", COLOR_WHITE);

to the following:

_tft->drawText(0, 130, "BATTERY AMPS", COLOR_WHITE);

By that we’re simply saying to write the text BATTERY AMPS in white color at coordinates [0, 130]. In the original, the ternary expression may look scary:

_config->imperial_units ? "TRIP MI" : "TRIP KM"

This simply says: write TRIP MI if the _config->imperial_units flag is true; write TRIP KM otherwise.

Second, we’ll go to the update() method where the values are displayed. The reset() is only called at the screen layout initialization whereas the update() is called periodically several times a second.

There we’ll want to locate the following code, which displays the trip distance:

    // trip distance
    dtostrf(convert_distance(data->trip_km, _config->imperial_units), 5, 2, fmt);
    tft_util_draw_number(_tft, fmt, 0, 140, progress_to_color(data->session_reset_progress, _tft), COLOR_BLACK, 2, 6);

and change it to something like this:

    // battery amps
    dtostrf(data->battery_amps, 5, 1, fmt);
    tft_util_draw_number(_tft, fmt, 0, 140, COLOR_WHITE, COLOR_BLACK, 2, 6);

Now, let me explain what all of that means. The first line is just a comment. On the second line, we convert the float value data->battery_amps to a string value in fmt

    dtostrf(data->battery_amps, 5, 1, fmt);

The 5 is the total number of characters including the decimal point; the 1 is the number of decimal places. For example, the value of

123.4466666666

would be formatted as

123.4

That’s 5 characters and 1 decimal point precision. If the value is less than 100, there will be leading spaces. For example:

5.339999999999

would be formatted as

__5.3

(two leading spaces). This ensures the value is right-aligned.

On the third line, we display the value stored in the fmt variable.

tft_util_draw_number(_tft, fmt, 0, 140, COLOR_WHITE, COLOR_BLACK, 2, 6);

The parameters are as follows:

  • _tft - reference to the display instance (don’t worry about it)
  • fmt - the string to display
  • 0 - x coordinate
  • 140 - y coordinate
  • COLOR_WHITE - text color
  • COLOR_BLACK - background color
  • 2 - number of pixels between characters
  • 6 - font size

In the original code, instead of COLOR_WHITE for text color, there’s the following expression:

progress_to_color(data->session_reset_progress, _tft)

This is to dim the text when the session data is about to be reset. As you press and hold the button 1, the data->session_reset_progress value will gradually increase from 0.0 to 1.0 and the progress_to_color() function translates the value into appropriate color (higher = darker). Once the data->session_reset_progress reaches the value of 1.0, the session data is reset and the value becomes completely black. You don’t need to worry about this. It’s just to explain what’s going on.

The last thing you need to know is what values are available in the data. You’ll find the list here. For example:

data->speed_kph

will give you the current speed in km/h. Session data can be accessed using double dereference. For example, this is how to get the max speed in km/h:

data->session->max_speed_kph

The list of values available in the session is here.

I hope this is helpful and I’m looking forward to seeing many customized screen layouts. :slight_smile:

20 Likes

Sir, you are a Legend! Thank you for that explanation. I’ve been going through every line of your code and I had basic understanding what relates to what. But as I haven’t had a chance to learn even the basic of programming, I was pretty sure I will screw it up. Now it looks much clearer :blush:

1 Like

Can’t wait to get mine and set it all up !! @janpom how’s the unity support going ?

@venom121212 @PickSix24 Here’s a picture for you that you might like. :slight_smile:

DSC01892

10 Likes

Here’s the unity_support branch for the impatient ones. Note that the Dave FW has to be specifically compiled for the Unity. To enable that, you currently need to uncomment the following line. I’ll try to make a config option for that instead before merging to master. It’s unfortunately not completely trivial.

Also, you will want to set the VESC_COUNT config option to 1 with the Unity unless you actually have more than 1 (e.g. 2 for dual Unity for 4WD). There’s a note in the config.

5 Likes

Oh no! 404.

Hopefully that means you’re merging into the master :smiley:

1 Like

Already merged. I also moved enabling Unity to the config. You no longer need to touch any other files. (I spent 2 bloody hours getting that working. Totally not worth it. I hate C++.)

5 Likes

You are the best! I can’t wait to get this working

1 Like

I don’t see an option for unity in the config tab. This is in the main v0.6 release found here?

It’s not yet released. You have to grab the master version. Will make a release soon. I’d like to do a few more changes and maybe finally call it v1.0.

3 Likes

I have done some reformatting of the text screen following the suggestions from @lrdesigns and @b264. IMO it looks cleaner and is easier to read now. I hope you guys like it. (Never mind the motor temp. That’s what you get if you don’t have motor temperature sensor.)

IMG_1797

6 Likes

Hi

I am In South Africa and interested in your project. Still trying to figure out how to get a unit from you so please advise.

Would your display support the flipsky vescs?

Regards

@Romain, see here: https://www.electric-skateboard.builders/t/davega-second-batch/82070

And yes, it will work with fipsky as well as any other VESC.

This is awesome

Tried search but couldn’t find the answer. Did anyone find a faster shipping source for the LCD screen? DHL shipping to Canada is $30 from Aliexpress