Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding LedBar Animation for Visual effects of OpenEVSE activity and status #899

Merged
merged 7 commits into from
Sep 1, 2024

Conversation

jdgarcia99
Copy link
Contributor

@jdgarcia99 jdgarcia99 commented Aug 22, 2024

Here is my modification to the original OpenEVSE project to introduce a led bar as most commercial EVSEs have as seen in this discussion thread #891

I'm based on WS2812FX library to perform animations and visual effects.

My first intention is to show visually the status of the EVSE without using the screen nor the web interface and know quickly what is happening in the EVSE as follows:

If the EVSE is not charging the car, the bar have the same color code as the EVSE led (screen, buttons, etc) based on EVSE status
If the EVSE has any error, the led is blinking with corresponding color code
IF the EVSE is loading the car, the led will perform a "loading bar" animation to show this status. Also the speed of the animation will correspond with the intensity in Amps being provided to the car based on max Amp configured.
Led Bar bright can be configured directly from EVSE web interface Led brightness slider, so it is very intuitive to use and naturally integrated

Source code changed for this mod has been mainly done in LedManagerTask to create the integration

Notes for the implementation:

  1. My Led Bar uses 15 pixels (you can configure num of pixels based on your own requirements for your bar) Param: NEO_PIXEL_LENGTH=15
  2. I'm using the board WT32-ETH01 for the implementation. Thus I'm using some specific pin to communicate with the LED Bar. Change this configuration based on your own esp32 board. Param: NEO_PIXEL_PIN=12
  3. An extra parameter has been created to use this functionality on the EVSE. Param: ENABLE_WS2812FX
  4. In my use case, I'm also using a PN532 RFID reader to authorize session. Comment this param if not needed.
  5. In the event of using PN532 reader with WT32-ETH01 board through I2C You need to comment pin definition for this board in the Arduino.h. Otherwise it will give you an error due to conflict with pins used for I2C
  6. Due to the low power of OpenEVSE AC Transformer I decided to use an external AC/DC power source to not overload OpenEVSE power source when full brightness (in future releases of the HW a more amp capable transformer can be used)

New animations and status can be introduced in the future based on this initial implementation.

Some pictures of the OpenEVSE working with this new functionality:

358303679-9548fec4-9b10-4377-ae12-56da410b780c.mov

358304596-50391d9d-2dcd-44c9-bacd-6c80bb85f7b4

358304602-dcb84136-a5da-4086-a372-7aa2f38df942

@jdgarcia99 jdgarcia99 closed this Aug 22, 2024
@jdgarcia99 jdgarcia99 reopened this Aug 22, 2024
src/main.cpp Outdated
Comment on lines 218 to 220
#if defined(NEO_PIXEL_PIN) && defined(NEO_PIXEL_LENGTH) && defined(ENABLE_WS2812FX)
ledManager_loop();
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be needed, the MicroTask and the LedManagerTask instance provide the equivelant without the need to add lots of loop calls to the main loop function.

If you can't use the LedManagerTask you could setup another task just for running the animations.

Copy link
Contributor Author

@jdgarcia99 jdgarcia99 Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Jeremy.
Understood. However the main reason to call this is to invoke the ws2812fx.service() method which refreshes the led status bar.

I'm not sure about the Microtasks architecture as I could not find much information about.
The problem I have is that the service() method need to be invoked regularly to update the bar and If I do not force the call the bar is not updated. I could find any way within ledManagertask to execute this regularly. Only when the EVSE changes status that invokes the service just once and then the animation is stopped

Should I call from main loop just a service method directly instead?
I mean:
create a method within the ledManagerTask called service and then launch from the main loop? (that is in essence what this ledManager_loop call is doing)

Thanks in advance

@jdgarcia99
Copy link
Contributor Author

jdgarcia99 commented Aug 30, 2024

Alright. Just solved by adding a new method for ledManagerTask to invoke the ws2812fx.service method to run the animation. Then added a call to this method from main loop to refresh effect as ws2812fx.service needs to be invoked in each loop run to perform the animation

In my OpenEVSE is running smoothly

Let me know your thoughts

Thanks

@jeremypoulter
Copy link
Collaborator

Please can you update all the DEBUG.printf calls?

On the looping there are two ways you can do it, the return of LedManagerTask::loop gives the amount of time before that method is called again so to make that function be called repeatedly you can just return a small value like 40, that should be sufficiaent for 25 fps, but what might b cleaner could be an separate task for just running the animations, something like:

class LedAnimatorTask : public MicroTasks::Task
{
  public:
    void setup() {
    }
    unsigned long loop(MicroTasks::WakeReason reason) {
      ws2812fx.service();
      return 40;
    }
};

LedAnimatorTask animator;

Then in LedManager::setup you would call icroTask.startTask(&animator); to start the task. See 5c19231

@jdgarcia99
Copy link
Contributor Author

OK, Thank for your input Jeremy. Already tested your code and works perfect. 40ms seem enough to run the animation smoothly.
Also Cleaned the DEBUG calls

IMG_2756.2.MOV

@jeremypoulter
Copy link
Collaborator

Looks good, a little jitter sometimes so maybe 20 might be better.

@jdgarcia99
Copy link
Contributor Author

jdgarcia99 commented Aug 31, 2024

Tried different refresh times for the task and found that 10ms is visually the best (although 20 ms is enough). Find videos:

40ms:

IMG_2758.mov

20ms:

IMG_2759.mov

10 ms:

IMG_2760.mov

I'll let mine in 10 ms as I thing is best (at least visually in person) and the general behaviour is responsive without any effectt on the EVSE

BTW: I would like to test other effects i.e. when the EVSE is sleeping either with connected vehicle or not. How can I know from LedManagerTask this status in the EVSE? I've been looking at the code but I'm struggling to find a method.

I the future I would also be able to manage configuration for this from the web gui. Any recommendation where to start looking at?

Thanks

@jeremypoulter
Copy link
Collaborator

Great, 10ms is good. Thanks for testing

@jeremypoulter jeremypoulter merged commit cf9fbd4 into OpenEVSE:master Sep 1, 2024
23 checks passed
@jeremypoulter
Copy link
Collaborator

All looks good, thank you for your contribution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants