Advices to complete this project

Hi,

I'm working on a little project made of several parts :

  • a webserver
  • a ESP32 connected to WIFI
  • some ESP32 controlled hardware : sensors, LED and servo motors

All the software parts are working.

I'm made some tests to experiment the hardware parts one by one (tested a step motor, then tested to control I2C input/outputs...)

Now I'm trying to finish the whole project by connecting all together, and here the problems begins.

Here is a schematics of the whole circuit, which should be controlled by the ESP 32 :

This is made of several parts :

  • 1 MCP23017 : I2C 16 I/O expander
  • 8 photointerrupters, powered thru a resistor and connected to the MCP23017 inputs using a pull-down resistor
  • 8 LED, powered thru the MCP23017 outputs using a resistor (about 10 mA current per LED)
  • 5 servo motors, powered by 5V

There is 3 connectors :

  • 1 power connector (GND/5V)
  • 1 I2C connector
  • 1 servo control connector (5 channels)

Basically, I would like :

  • connect the I2C connector to the I2C output of the ESP32
  • connect each servo control channel to one of the ESP32 output
  • control the power (on/off) of all devices on the schematics above from an ESP32 output

To power the whole thing, I plan to use a 5V/2A power supply :

  • connected to the ESP32 USB input : ESP32 always powered
  • connected to the above circuit power input thru a ESP32-controlled switch : the above circuit is powered only when needed

Finally, my ESP32 software works as this :

  • if there is something to do, do it
  • if nothing happen during 1 minute, the ESP32 set the devices power to "OFF" and go to deep sleep mode
  • when the ESP32 is waken up, the ESP32 set the devices power to "ON"

Now, I have several questions :

1/ Is the whole circuit above valid ? Is there any errors in it ? (I've tested it part by part, but not all together)

2/ Can I connect the ESP32 I2C output (which is 3.3V) to the MCP23017 I2C input (the MCP23017 is powered by 5V) or should I use a level shifter ?

3/ Can I connect the ESP32 outputs (3.3V) directly to the servo control inputs ?

4/ What is the best way to design the ESP32 controlled power switch ?

Thanks !

Parts used references :

  • I2C IO expander : "MCP23017"
  • photo-interrupters : "ITR9608"
  • servo motors : "SG90" 9G mini servo

orel:

  • some ESP32 controlled hardware : sensors, LED and step motors

Are you using servos or stepper motors?

...R

Servo, sorry for the typo, I edit my message now.

5 servos implies a separate 5V 6A supply... Unless you know they don't all move at the same
time in which case some supply derating will be possible. And the 1A per servo is only a rough
ballpark figure. Anything with motors tends to take loads of peak current.

Thanks, I didn't figure out that I need so much current.

Can I still use the same PSU (a 5V/6A one) to power both the motors and the ESP32, like described in my first message ?

Can I still use the same PSU (a 5V/6A one) to power both the motors and the ESP32

Seeing as the ESP32 takes sod all current in comparison with even one motor then in theory yes.
In practice you will need some good supply decoupling to isolate interference form the motors affecting the way the processor runs, like resting it.

I want to use some ESP32 controlled switch (transistor, MOSFET, relay... ?) to power ON/OFF the motors, the sensors and the LEDs.

Is that enought to isolate from interference or do I need a specific circuit for this ?

I'm thinking about something like the one described in the first answer of this post : Power supply circuit for powering SG90 servo. How to handle high current requirements? - Electrical Engineering Stack Exchange

Is that enought to isolate from interference

That does nothing to isolate interference.
I said decoupling De-coupling you need several of the Pi circuits which is the last one on that page. One for your ESP 32 and I would have one for every four or five servos.

I'm thinking about something like the one described in the first answer of this post :

No that is just a homemade linear regulator. It will burn off excess current as heat.

Ok, so I guess I should think about building a "real" power unit :slight_smile:

My specs are the followings :

  • input from a simple 5V 6A adapter
  • main output : 5V 500mA permanent output to power ESP32
  • additionnal outputs :
  • 5v 500mA for I2C chip, sensor and leds
  • 5x5V 1A for 5 servos

The additionnal outputs should be activated/deactivated from a logic output from the ESP32.

The 5x5V servos outputs should use a decoupling circuit from the other ones.

Is that the right way to design my power supply unit ?

Is that the right way to design my power supply unit ?

No, you are not defining a power supply here you are simply defining the specification and doing it wrong anyway.

You specify the voltage you need and the voltage you have and the current you need as well. So all the “need 5V at this and 5V at that and so on means you need 5V that’s all.

Turning stuff of to save power is a lot more complex than you know at the present so forget about it until you have a better grasp of electric circuits.

Turning stuff of to save power is a lot more complex than you know at the present so forget about it until you have a better grasp of electric circuits.

The whole project is working : distant webserver "in the cloud", ESP32 web client, input/outputs management, I2C communication...

I have 2 task to do before completing the project in a "real thing" : a good looking case and an intelligent/stable power unit.

So maybe I can now try to learn how to build this ? Or maybe it's so difficult that I have to forget about it without even trying to understand and learn ?

Hi,
If you have the whole project working can you post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

But not a Fritzy picture.
Please label components and pins and include power supplies.

Do your servos work against a force. if so how will you make sure that the arm will not move under that force when you remove power?

Thanks.. Tom.. :slight_smile:

I don't have any "real" CAD or hand drawn circuit, I use frizzy as a "draft design" software.

In the frizzy picture posted in my first post, everything is exactly like on my real circuit (I can post you pictures tonight, after work).

The resistors values are the same, the I2C pining is correct (adresse selection connections, power supply, reset...)

The sensor and leds pinning are the same.

All my sensors are working properly and soldered on a separate PCB with a large IO connector
All my LED are working properly and soldered on a separate PCB with a large IO connector
My I2C component is working properly on a proto board connected to the ESP32, the sensors module and the LED modules but not yet soldered.

The only difference between this schematics and my real prototype is :

  • in my prototype, the servo control channels ar connected to the ESP 32
  • in my prototype, the I2C connector is connected to the ESP 32
  • in my prototype, I have connected only one servo motor at a time to avoid anything to fry (and I don'y play with it for a too long time)
  • in my prototype, I have permanent 5V 2A power supply for everything (servo, leds, sensors, ESP32...) without any protection, or decoupling

In fact, in the above picture, only the ESP32 is not drawn : I'm trying to understand how and why to connect the above picture to the ESP32 properly. Including needed protections, decoupling...

The reason why I don't have any hand draw schematics or calculations is because I'm a software developper : I've built all "logic" parts of the project because I knew how to do it : some IC, some pulldown resistor, some code... easy for me, this is my job since 15 years now.

I understand now that I should draw circuits and do calculation for the power supply : it's more complex than I believed and it involve "analogic computation" (I don't know how to call that) to determine the correct values to use for all involved capacitors, resistors, transistors...

I'm currenty studying the tutorials written by Grumpy_mike, here : Tutorials

They seems to be clear and easy to understand, so maybe in a near future I will be able to draw a correct power supply circuit, and maybe even compute the correct values :slight_smile:

Sorry, I forgot to answer to this :

Do your servos work against a force. if so how will you make sure that the arm will not move under that force when you remove power?

No, there is no force involved.

The servo are used to move indicators arrows : think about the speed-meter in your car. The background will be made of wood, and static. The arrow will bu turned by the servo to the correct position, and will be very light (probably made of plastic or carton).

I know the servo position may be not realy accurate, but this is not a problem in y use case.

OK, you said

  • control the power (on/off) of all devices on the schematics above from an ESP32 output

Is that each individual component in that layout diagram?

Why do you want to do this as you have a 5V 2A power supply? It is not a normal thing to do.
The control of power to each device will require a transistor and an output pin of your ESP 32,so you have that many spair or will you need another port expander?

Why do you have opto slots when you have a servo?

Is that each individual component in that layout diagram?

Not really : all at a time or each individual, what is the best idea ?
In my use case, I need to power off everyhing (to save power) but I can power off one by one if needed.

Why do you want to do this as you have a 5V 2A power supply? It is not a normal thing to do.

I don't want to use a 5V 2A power supply. I want to understand what to use, how to use it, and additionnally (if I can, but I'm not sure) why use it like that.

For my early prototype, I used a 5V 2A, powering only 1 sevo at a time, because I have that available in my house. For my final project, I plan to buy something like a 5V 6A power adapter. But what I'll buy will depend on what I need.

Why do you have opto slots when you have a servo?

To get user input. The user move a "slider" which triggers the opto slots.

The servo are used to display data taken from a webservice I host on a distant server.
The "slider" (which is not realy a slider) is used by the user to select which data should be display by the servos.

The whole thing will be powered 7/24, ready to be used.
3 or 4 times a day, the user push a button to "awake" the ESP32, which request data from the web, display it by moving the servo, wait a little (the user can move the slider to select another data to be diusplayed) and then go to sleep.

Since the "working" time is only about 5x5 minutes a day, I want to save power :

  • turn ESP32 to deep sleep (easy, just some code)
  • turn off power of LEDs, sensors, servo (the hard part)

@Grumpy_Mike :

By reading your tutorial here De-coupling I'm under the impression that I can use this kind of circuit to power my 5 motors :

  • each 0.1 uF capacitor in parralel to each motor suppress the high frequency noise produced by the motor
  • the 47 uF capacitor suppress the low frequency noise in the whole circuit
  • the inductor and the 0.1uF wil prevent noise generated by the motors to go into the rest of the circuit

I will not build this exactly like this before understanding a little more how it works, but is it the right way to design it ? or do I need a full isolating circuit (2 capacitor + 1 inductor) per motor ?

What is the purpose of the 470uF capacitor ?

I had electronic classes during my studies, but it's a loooong time ago.
So I remember the basic about capacitors and noise filtering, but I don't really understand how the inductor is working here.

Thanks

Why do you use that port expander? The 28 IO of the ESP32 should be plenty for your project.

About that schematic: The 470µ capacitor is to provide the start-up current peak to the motors. The inductor tries to keep the overall supply current constant, while the caps try to keep the voltage constant.

I'm using a similar way to isolate motors and other noise-inducing stuff from my processor, but with one major difference: it's the processor that's behind the inductor, not the motors. Reason: my power supply is already noisy (there are other pumps on it), and to have in inductor in the motor power supply you need a much bigger one (thicker wire to handle all the current) than when placing one in the supply leading to the processor. It's the power supply to the microprocessor that's got to be as clean as possible.

The motors should also get a flyback diode, by the way.

I'm using a port expander because I use more I/O than I said :slight_smile:

I have 6 status leds (sleep status, 2x Wifi status/error code, 3xDistant server status/error code) connected directly to the ESP32.

So this is : 8 outputs (LED) + 8 inputs (sensors) + 5 servos + 6 status = 27 I/O

And I also need an :

  • 1 input to awake the ESP32
  • 1 or maybe 2 outputs to power on/off the servo, sensors and LED

So before running out of I/O i decided to add a port expander.

About the flyback dioide : I've seen that in nearly every circuit where a motor or a solenoid is involved. I was suprised that the Grupy_Mike's tutorial doesnt have this.

Could you post a schematics of your circuit ?

Thanks

The motors should also get a flyback diode, by the way.

It is badly drawn as those are not motors but servos.

The ESP32 is a 3V3 device, that is it gives only either 3V3 or 0V on the digital output. This according to the data sheets is not sufficient to drive the servos or the port expander, but is just under the edge of of being alright. Having said this it will probably function but you might get reliability issues.

To switch power to a divice you have to do two things.

  1. Top switch the power, this is with a PNP transistor or a P-channel FET if you have over 500mA to switch. As you only have a 3V3 signal then most likely you need to boost it up to a 5V signal first, with an NPN, before applying it to the switch transistor.

  2. Remove any input to the chips you turn off. This would involve turning the output pins into inputs. The servos might twitch when the ESP32 comes out of standby.

As to the decoupling, note that this is more of an art than a science and their are lots of factors that are impossible to calculate, like the effect of layout and the electrical environment to name but two. That schematic is good for a start but I would also have another Pi circuit pointing into the electronics as well.

A lot depends on the peak and running currents of the servos, you need to know this.