DRV8833 + ESP Easy

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

DRV8833 + ESP Easy

#1 Post by okite » 28 Apr 2023, 10:16

Hi, any experience with ESP Easy? Want to use it to control damaged (original circuit) pet doors with ESP8266.
Thanks for any advice.

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#2 Post by TD-er » 28 Apr 2023, 11:47

It looks like a very basic H-bridge chip without any internal logic inside.

There isn't a plugin for driving the stepper motor logic.
No idea if this chip also manages the coil current, as you also may need to make sure no coil is left powered for a long time.

Driving it from rules is probably way too slow, since that would result in several tens of steps per second at most.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#3 Post by okite » 28 Apr 2023, 13:08

Its not stepper, its ordinary DC motor.

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#4 Post by TD-er » 28 Apr 2023, 14:08

Then you could have a look at P098 PWM Motor plugin.

I do see I still need to make documentation for it.
It does support an (optional) encoder for position input and limit switches.

The available commands are:

pwmmotorhome - Run the motor in reverse till limit A switch is reached
pwmmotorend - Run the motor forward till limit B switch is reached
pwmmotorforward - Run the motor N steps forward. With N <= 0: Move till limit B switch is reached
pwmmotorreverse - Run the motor N steps in reverse
pwmmotorstop - Stop moving
pwmmotormovetopos - Run the motor in the required direction to position N

There is a pending pull request ( https://github.com/letscontrolit/ESPEasy/pull/4519 ) to add functionality to this plugin to run the motor for a set amount of time, when no encoder is present.
But running till the limit switches is already usable without encoder.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#5 Post by okite » 28 Apr 2023, 22:45

Thanks!
Original circuit has no limit switches, and add them to the hardware would be too complicated. I am newcomer to the Espeasy, so I thouhgt it would be possible just to set time period or number of revolutions to define movement. It seems to be more complicated. I have old "yellow" esp8266 board ("IoT") with photo sensor, which I tested with ESP Easy, working great, powered by 5 volts (doors have 3xAA batteries), so it looked as "simple" task ;)

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#6 Post by TD-er » 29 Apr 2023, 10:25

You can of course always handle basic GPIO operations in rules.

I think the longpulse command would be great for this.

Let's assume the GPIO pin for "up" is GPIO13, "down" is 14.

Code: Select all

on Clock#Time=All,%sunrise% do //will run at sunrise  
  longpulse,13,1,10  // GPIO 13 high for 10 seconds
endon

on Clock#Time=All,%sunset% do //will run at sunrise  
  longpulse,14,1,10  // GPIO 14 high for 10 seconds
endon
For sunrise/sunset to be correct, your ESP should be aware of the time and the GPS coordinates on the tools->Advanced page.

You can also add or subtract some time from sunrise/sunset like this: %sunrise+10m% to add 10 minutes.

Not sure how long an ESP will last on AA batteries though.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#7 Post by okite » 29 Apr 2023, 10:40

Thanks a LOT!
I will test it. I intend to use photovoltaic panel + charger.

:idea: Thanks!

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#8 Post by okite » 23 Jun 2023, 15:39

Hi, I, finally, tested, motor runs, but pulse/longpulse not.
Probably must open GPIO for given time only once after change of the A0 change... I am playing with timer but not quite sure I understand the principle how to set timer for one time period once after state change...

Thanks

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#9 Post by okite » 24 Jun 2023, 09:53

TD-er wrote: 29 Apr 2023, 10:25 Not sure how long an ESP will last on AA batteries though.
You've right, minimal voltage for this setup with controller is 5,5V.

Thanks.

bidrohini
Normal user
Posts: 117
Joined: 03 Nov 2022, 16:24

Re: DRV8833 + ESP Easy

#10 Post by bidrohini » 25 Jun 2023, 00:10

Here is something similar: https://www.youtube.com/watch?v=_omEluWFqsU
I think for ESPeasy, the procedure is the same. You can see it if you already have not.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#11 Post by okite » 25 Jun 2023, 15:58

Hi, thanks, I have found soulution for Tasmota, but I wanna use ESPEasy: https://github.com/arendst/Tasmota/discussions/10387
I changed rules struct, so I am approaching the end :-D.

bidrohini
Normal user
Posts: 117
Joined: 03 Nov 2022, 16:24

Re: DRV8833 + ESP Easy

#12 Post by bidrohini » 26 Jun 2023, 10:01

okite wrote: 25 Jun 2023, 15:58 Hi, thanks, I have found soulution for Tasmota, but I wanna use ESPEasy: https://github.com/arendst/Tasmota/discussions/10387
I changed rules struct, so I am approaching the end :-D.
Good to know that. Please post the update when you're done. That will help many of us.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#13 Post by okite » 26 Jun 2023, 12:53

"Final" WittyCloud rules; playing with OLED too. Test run on timer, real operation will use TD-er recommendation - sunset/sunrise Clock#Time (thanks!):

Code: Select all

on System#Boot do
 LoopTimerSet,1,10
  GPIO,12,0
  GPIO,13,0
  GPIO,14,0
  OLEDCMD,clear
 Endon
on Rules#Timer=1 do
OLEDCMD,on
//on Clock#Time=All,%sunset% do //will run at sunset
  if [LightSensor#Analog]<10 and [DoorsStatus#open]=1
   GPIO,14,1 //motor wakeup
   GPIO,13,0
    LongPulse,12,1,5 //GREEN LED
    TaskValueSet 2,1,0 //doors close
    GPIO,14,0 //motor sleep
   Endif
 //Endon
 //on Clock#Time=All,%sunrise% do //will run at sunrise 
   if [LightSensor#Analog]>30 and [DoorsStatus#open]=0
    GPIO,14,1 //motor wakeup
    GPIO,12,0
    LongPulse,13,1,5 //BLUE LED
  TaskValueSet 2,1,1 //doors open
  GPIO,14,0 //motor sleep
  Endif
 //Endon
 Endon //timer 1
ESP_Easy_devices.png
ESP_Easy_devices.png (89.39 KiB) Viewed 4051 times

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#14 Post by okite » 26 Jun 2023, 13:01

OLED info screen:
OLED.jpg
OLED.jpg (223.78 KiB) Viewed 4049 times

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#15 Post by TD-er » 26 Jun 2023, 13:17

Just keep in mind that acting on events for a specific time of day (e.g. sunrise/sunset) will only be triggered when the unit is running at that time.

So maybe you also want to check the current state/time of day when the system boots (on system#boot do...) or when the system time is set.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#16 Post by okite » 28 Jun 2023, 13:54

Thanks for advice again! :idea:

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#17 Post by okite » 16 Jul 2023, 23:19

TD-er wrote: 26 Jun 2023, 13:17 Just keep in mind that acting on events for a specific time of day (e.g. sunrise/sunset) will only be triggered when the unit is running at that time.

So maybe you also want to check the current state/time of day when the system boots (on system#boot do...) or when the system time is set.
I probably have to control open/close by photosensor according to the light level, as on sunset it is a lot of light, and hen are still somewhere out... maybe some combination with the sunset + some time added...

I understand that it is necessary to check
- Time#Set (using NTP) is done?
- WiFi#Connected is valid?
Maybe the TaskValueSet Dummy Device can loose the value during restart/boot?
i guess that combination light sensor and sunset will prevent not closing doors during fool moon...for example.

Thanks again for any advices.

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#18 Post by TD-er » 17 Jul 2023, 11:47

When acting on a specific time of day, you need to make sure the time has been set.
So you can check the system variable %isntp%
This way you know you can rely on the system time.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#19 Post by okite » 21 Jul 2023, 19:54

TD-er wrote: 17 Jul 2023, 11:47 When acting on a specific time of day, you need to make sure the time has been set.
So you can check the system variable %isntp%
This way you know you can rely on the system time.
Thanks!

I added

Code: Select all

on Rules#Timer=1 do
 if %isntp% = 0
  reboot
 endif
OLEDCMD,on
//on Clock#Time=All,%sunset% do //will run at sunset
  if [LightSensor#Analog]<22 and [DoorsStatus#open]=1
  ...
:idea:

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#20 Post by TD-er » 22 Jul 2023, 10:22

No idea how long it takes to hit this timer #1.
Do you set it at the event "WiFi#connected" ?

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#21 Post by okite » 23 Jul 2023, 11:52

I tuned the code a little:

Code: Select all

on System#Boot do
 LoopTimerSet,1,10
  GPIO,12,0
  GPIO,13,0
  //GPIO,14,0  DRV8833
  OLEDCMD,clear
  OLEDCMD,on
 Endon //System#Boot
 on Rules#Timer=1 do   //top loop
   if WiFi#Connected=0 and [DoorsStatus#open]=0
   LongPulse,12,1,34 //open doors
  TaskValueSet 2,1,1 //doors open
  endif
on WiFi#Connected do //connected to wifi loop
 if %isntp%=0
  reboot
 endif
OLEDCMD,on
//on Clock#Time=All,%sunset% do //will run at sunset
  if [LightSensor#Analog]<5 and [DoorsStatus#open]=1
   // GPIO,14,1 //motor wakeup for DRV8833
   GPIO,12,0
    LongPulse,13,1,34 //close doors
    TaskValueSet 2,1,0 //doors closed
    // GPIO,14,0 //mtor sleep for DRV8833
   Endif
 //Endon Clock#Time
 //on Clock#Time=All,%sunrise% do //will run at sunrise 
   if [LightSensor#Analog]>60 and [DoorsStatus#open]=0
    // GPIO,14,1 //motor wakeup for DRV8833
    GPIO,13,0
    LongPulse,12,1,34 //open doors
  TaskValueSet 2,1,1 //doors open
  // GPIO,14,0 //motor sleep for DRV8833
  Endif
 //Endon Clock#Time
 Endon //wifi#connected
 Endon //Rules#Timer 1
I had some problems with wifi connectivity, so now I check wifi connection and open doors if not connected, as hen has large cage (as a "semi space" if I need to keep them out of the big open area), and its better for them to be in the cage than to be closed in the coop.

Second test is for time set, but for the time being I control doors by light level only and later I plan to "merge" it with sunrise/sunset (winter time?).

Thanks for your valuable advices!

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#22 Post by TD-er » 23 Jul 2023, 12:29

You had mismatches between on...do and endon

Changed it:

Code: Select all

on System#Boot do
  LoopTimerSet,1,10
  GPIO,12,0
  GPIO,13,0
  //GPIO,14,0  DRV8833
  OLEDCMD,clear
  OLEDCMD,on
Endon //System#Boot

on Rules#Timer=1 do   //top loop
  if WiFi#Connected=0 and [DoorsStatus#open]=0
    LongPulse,12,1,34 //open doors
    TaskValueSet 2,1,1 //doors open
  endif
endon

on WiFi#Connected do //connected to wifi loop
  if %isntp%=0
    reboot
  endif
  OLEDCMD,on
//on Clock#Time=All,%sunset% do //will run at sunset
  if [LightSensor#Analog]<5 and [DoorsStatus#open]=1
    // GPIO,14,1 //motor wakeup for DRV8833
    GPIO,12,0
    LongPulse,13,1,34 //close doors
    TaskValueSet 2,1,0 //doors closed
    // GPIO,14,0 //mtor sleep for DRV8833
   Endif
 //Endon Clock#Time
 //on Clock#Time=All,%sunrise% do //will run at sunrise 
   if [LightSensor#Analog]>60 and [DoorsStatus#open]=0
     // GPIO,14,1 //motor wakeup for DRV8833
     GPIO,13,0
     LongPulse,12,1,34 //open doors
     TaskValueSet 2,1,1 //doors open
     // GPIO,14,0 //motor sleep for DRV8833
    Endif
 //Endon Clock#Time
 Endon //wifi#connected
 

User avatar
Ath
Normal user
Posts: 3918
Joined: 10 Jun 2018, 12:06
Location: NL

Re: DRV8833 + ESP Easy

#23 Post by Ath » 23 Jul 2023, 12:55

okite wrote: 23 Jul 2023, 11:52

Code: Select all

   if WiFi#Connected=0 and [DoorsStatus#open]=0
That if statement is [s]missing a set of square brackets around [WiFi#Connected]...[/s] using the wrong variable, should be %iswifi%
/Ton (PayPal.me)

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#24 Post by okite » 23 Jul 2023, 13:03

Thanks, as I tune it, I find how many I have to learn yet :-)

TD-er
Core team member
Posts: 9221
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: DRV8833 + ESP Easy

#25 Post by TD-er » 23 Jul 2023, 13:21

WiFi#connected is an event.
So that should be handled in on...do...endon blocks

The system variables can be found on the system variables page (button on the Tools page)
Variables are written like %bla%

Task values should be accessed like [taskname#taskvaluename]

And since new task values also generate an event, you get the slightly confusing notation where you need to match the event (thus without []) and you can access the task value with using []

It isn't that complex, but you need to be aware of these little details.

Just keep in mind this very simple idea:
When parsing the rules, everything enclosed in either [] or %% will be replaced by whatever it can be replaced before executing the rules.

Thus the value of task foo with value bar can be used like this:
[foo#bar]
And the rules parser will replace this with the current value of that task value.

okite
Normal user
Posts: 15
Joined: 30 May 2016, 23:51

Re: DRV8833 + ESP Easy

#26 Post by okite » 23 Jul 2023, 14:18

Repaired...

Code: Select all

on System#Boot do
 LoopTimerSet,1,10
  GPIO,12,0
  GPIO,13,0
  //GPIO,14,0  DRV8833
  OLEDCMD,clear
  OLEDCMD,on
 Endon //System#Boot
 
 on Rules#Timer=1 do   //top loop
 OLEDCMD,on
 
  If  %iswifi% !=0 And %isntp%=0 // connected but got no time, then reboot to get time
  reboot
  Endif

  If %iswifi%=0 and [DoorsStatus#open]=0 //not connected, thus open the door, if not at night
   if [LightSensor#Analog]>60
    LongPulse,12,1,34 //open doors
    TaskValueSet 2,1,1 //doors open
    Endif
  Endif
 
//on Clock#Time=All,%sunset% do //will run at sunset
  if [LightSensor#Analog]<5 and [DoorsStatus#open]=1
   // GPIO,14,1 //motor wakeup for DRV8833
    GPIO,12,0
    LongPulse,13,1,33 //close doors
    TaskValueSet 2,1,0 //doors closed
    // GPIO,14,0 //motor sleep for DRV8833
   Endif
 //Endon Clock#Time
 //on Clock#Time=All,%sunrise% do //will run at sunrise 
   if [LightSensor#Analog]>60 and [DoorsStatus#open]=0
    // GPIO,14,1 //motor wakeup for DRV8833
    GPIO,13,0
    LongPulse,12,1,36 //open doors
  TaskValueSet 2,1,1 //doors open
  // GPIO,14,0 //motor sleep for DRV8833
  //Endon Clock#Time
  Endif
 Endon //Rules#Timer 1

Thanks for all advices!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests