Help required for m...
 
Notifications
Clear all

[Solved] Help required for model railway project

229 Posts
9 Users
12 Reactions
3,646 Views
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2171
 

@imillard 

For some reason your code printout loses its indents and also some spaces so,

void setup()

has become,

voidsetup()

Do you copy the text in the IDE and then use the <> button to insert code in the post?

Your code will not compile for reasons I will not go into unless you decide you want to learn to code.

Change

int galvoServo = 19;  // GPIO 19

to

int galvoServoPin = 19;  // GPIO 19

and

galvoServo.attach(galvoServo);

to

galvoServo.attach(galvoServoPin);

 

At the moment I am powering the board from the USB port but would need to power it one of two ways without the USB port.

Using unregulated voltage between 5v and 12v, connected to the 5v and GND pins. This voltage is regulated on-board.

or

Using regulated 3.3v voltage, connected to the 3.3v and GND pins. Do not exceed the 3.3v limit or the ESP32 module will be damaged.

 

This post was modified 1 week ago 2 times by robotBuilder

   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

@robotbuilder

Posted by: @robotbuilder

For some reason your code printout loses its indents and also some spaces so,

void setup()

has become,

voidsetup()

Hi John,

Not sure what happened there.

Do you copy the text in the IDE and then use the <> button to insert code in the post?

Yes, I did do that, after following Bill's example on how to post code, but as it was my first time, I may have done something wrong.

Change

int galvoServo = 19;  // GPIO 19

to

int galvoServoPin = 19;  // GPIO 19

and

galvoServo.attach(galvoServo);

to

galvoServo.attach(galvoServoPin);

 

I was wondering about the "Pin" part.  I had noticed it as part of the "lockServo" definition, but was unsure if you had intentionally left it off your original "servoDisplay" definition until we got up to that point.

At the moment I am powering the board from the USB port but would need to power it one of two ways without the USB port.

Using unregulated voltage between 5v and 12v, connected to the 5v and GND pins. This voltage is regulated on-board.

or

Using regulated 3.3v voltage, connected to the 3.3v and GND pins. Do not exceed the 3.3v limit or the ESP32 module will be damaged.

Powering the board away from USB was going to be another question for you.  My plan was to maybe design a custom PCB where the ESP module, servos and switch inputs plug into, and either incorporates a power supply or if I just use the MB102 module.  I am open to suggestions here.

Cheers,

Ian

 

 

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2171
 

@imillard 

The MB102 3.3V/5V Power Supply Module looks very tempting. It can provide 5v and 3.3v regulated voltage at the same time and a choice of a USB Type-A port or DC jack to your power supply source. It has a LED to say your machine is on and an on/off switch. Unlikely you could solder up your own version for the same price. I see they are about $7.50 online in Australia.

https://osoyoo.com/zh/2017/07/19/mb102-3-3v5v-power-supply-module-with-usb-to-usb-power-cable/

Your esp32 board is shorter than mine so it would fit nicely I think on a half length breadboard (or soldered version) on the back of the machine?

esp32PowerSupply

 


   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

@robotbuilder 

John,

I got my 2 MB102 boards as part of a breadboard kit from Aliexpress, but you can get them separately for around $2.50.

https://www.aliexpress.com/item/1005007163844165.html?spm=a2g0o.home.0.0.650c76dbmluHq6&mp=1

BTW, I have the galvo servos working now too.  I'll see if I can take a short video and post here.

I worked out my D1302 nano servo needed 3.7 to 4.2V, but seem to be working fine on the 3.3V from the MB102.

Cheers,

Ian

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

With many thanks to @robotbuilder, I now have a working hardware & software solution for my project.

The final thing for me is to work on the fitment of the momentary switch within the machine head.

Here is a short video.

The ESP32s are communicating via the ESP-NOW protocol.  When the switch is operated from either machine to simulate the removal of a staff, both machines' tumbler drums are locked preventing removal of further staffs.  When the staff is returned to the other machine, the switch is again triggered in the opposite direction and unlocks the drums.  At the same time, a separate servo drives a small needle to indicate if a staff is IN or OUT of the machines.

You will notice I am operating the switch at one machine only, but the other machine does the same job.

Cheers,

Ian

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

Hi everyone.

I ran into some power supply issues today whilst trying to power the ESP, 1xSG90 servo and 1xD1302 nano servo using an MB102 breadboard power supply.

Everything runs fine when the ESP is powered by the USB lead and with the MB102 powering the SG90 from the 5V bus and the D1302 from the 3.3V bus.

As soon as I connected the ESP to the 3.3V bus, the regulator chips on the MB102 got very hot, and the ESP was doing strange things, no doubt from voltage drop on the 3.3V bus.  The specs on the MB102 say its maximum output load is 700mA.

So, my question is - what other ready made power supply boards are available that I could use to power all the hardware above?  For the final working solution of my model, I don't want to have to power the ESP via USB.

Any suggestions welcome.

Cheers,

Ian

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2171
 

@imillard 

As soon as I connected the ESP to the 3.3V bus, the regulator chips on the MB102 got very hot, and the ESP was doing strange things, no doubt from voltage drop on the 3.3V bus.  The specs on the MB102 say its maximum output load is 700mA.

I added the other servo (I only have the 9g servos) and connected everything to the 5volt.

It all worked as expected so your problem is probably related to the 3.3v

Have you tried powering the esp32 from the 5v connection (it has a 3.3v regulator on the board for the esp32).

Just use the 3.3v line for powering the other servo not the esp32 board. Or maybe the small servo will work with 5v. Maybe add a resistor in series between the 5v and the servo to drop some of the 5v to a value more suitable for the small servo.

Of course if you have damaged anything that will be a problem.

esp32PeerToPeer

 

This post was modified 1 week ago 3 times by robotBuilder

   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

Posted by: @robotbuilder


As soon as I connected the ESP to the 3.3V bus, the regulator chips on the MB102 got very hot, and the ESP was doing strange things, no doubt from voltage drop on the 3.3V bus.  The specs on the MB102 say its maximum output load is 700mA.

I added the other servo (I only have the 9g servos) and connected everything to the 5volt.

It all worked as expected so your problem is probably related to the 3.3v

Have you tried powering the esp32 from the 5v connection (it has a 3.3v regulator on the board for the esp32).

Just use the 3.3v line for powering the other servo not the esp32 board. Or maybe the small servo will work with 5v. Maybe add a resistor in series between the 5v and the servo to drop some of the 5v to a value more suitable for the small servo. 

@robotbuilder

Thanks John.

I was thinking the same thing this afternoon of trying the ESP from the 5V line.  Will test that tomorrow.

Cheers,

Ian

 

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 5 years ago
Posts: 2171
 

@imillard 

It would still be interesting to know what the issue was. I see no reason the ESP32 cannot be run from the 3.3v line instead of the usb connection without any overheating of the MB102.

Was the USB cord disconnected when you connected the ESP32 to the 3.3v from the MB102?

Were the jumper pins on the MB102 correct?

I imagine if a 5v was accidently connected to the 3.3v pin of an ESP32 it would fry the chip unless it had voltage overload protection. A power supply should also have protection from a short in the device being powered. A lack of such a protection is why cheap illegal lithium batteries catch alight when being charged. Robot vaccuum cleaners have proper charging circuits and heat sensors in the battery pack.

Not related to the overheating issue but worth considering: I have seen a suggestion when the ESP32 and servo motors use the same power supply it is wise to connect a 100uF electrolyte capacitor between the terminals of the power supply probably to protect the ESP32 from voltage spikes.

wiring

 

This post was modified 1 week ago 6 times by robotBuilder

   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

@robotbuilder

Posted by: @robotbuilder

It would still be interesting to know what the issue was. I see no reason the ESP32 cannot be run from the 3.3v line instead of the usb connection without any overheating of the MB102.

Was the USB cord disconnected when you connected the ESP32 to the 3.3v from the MB102?

Yes.  I made sure of that.

Were the jumper pins on the MB102 correct?

Yes.

This morning I did some more tests.  I'll add that I'm supplying the MB102s from a 12V "wall plug" type supply, and at the moment I have no way of measuring the current draw.

With the MB102 powered on but nothing connected, no heat from the regulator chips.

I then connected just the ESP via the 5V line.  No noticeable heat dissipation.

I then connected the 9G servo to the 5V line and did not operate the servo.  Maybe a slight increase in heat dissipation.

I then initiated an operation of the 9G servo, waited a few mins, then another operation as it would occur on the model railway.  There was quite an increase in heat on the MB102, enough to not be able to hold my finger there for more than 5 secs.

I then connected the nano servo to the 3V3 line and again initiated an operation, waited a few mins, then another operation.

The MB102 regulator chips were still quite warm to the touch.

My observations.

1. I'm wondering if the heat is due to the 12V supply to the MB102, and having to drop it significantly down to 5V.  Would I be better with say a 9V or 7.5V supply to the MB102?

2. What would be the typical current draw on the ESP with nothing happening?  When communicating via ESP-NOW, is it always talking to the other board, or only when required, ie, when a switch is activated forcing the ESPs to talk?

3. With the ESP connected and the two servos just sitting there not doing anything, why would the MB102 still be getting hot?

4. Is it normal for the MB102 regulator chips to get hot?

Cheers,

Ian

 

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
(@bruceg)
Member
Joined: 4 weeks ago
Posts: 4
 

@imillard

Some info about mixing motor and data power.  Don't !  (That was a bit harsh 😉)

But you can use a single power supply - IF you separate each power using group with a one-way isolating diode and a local power storage capacitor.  A 1N4002 (2A) diode into a 25V 100uF capacitor is usually all that is needed to prevent interference and brownouts causing glitches and resets.  And it will ensure motors have maximum torque available each time they start turning.

Why a 25V capacitor for a 3.3/5V system ?  Plain DC motors and electromagnets store power in magnetic fields while in use.  When turned off that magnetism collapses back into an uncontrolled voltage spike that should be steered through a 'fly-back' diode into the local storage capacitor (and blocked from the other systems by the isolating diode).

I also saw that you are manually adjusting the servo motor's stroke.  Don't !

You have an analog to digital converter in the ESP32, so place a 0.1 ohm, 10 watt resistor between the servo motor and the shared ground for your system and measure the current through it (V = I * R) from the servo's (now slightly lifted) ground.  Add a calibration routine to your code that only runs when a jumper is in place at power up; get it to charactorize the servo's power usage - startup, steady and locked (<1A), for both directions and store a servo position value (just before locked) in (the ESP32's faked) EEPROM.

If you replace the power supply or the servo, just put the jumper in place and power up.  Wait for the servo(s) to stop moving, power down and remove the jumper.

Don't try to draw too much power at any one time -

In a low power system you need to separate high power draws; wait for ~250ms between different motor movements to allow the 100uf capacitor to fully recharge.  Humans will barely notice the delay, the system however will always be ready-to-go.

Servo motors use a worm drive gear system that will hold them in-place when the power is off.  So if possible, only power them on when in actual use (PNP power transistors or relays).

bye.

This post was modified 1 week ago by bruceg

   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

@robotbuilder

Hi John,

Not sure if you'll be able to answer this question since you are still learning ESP-NOW, but I have another scenario with the staff machines where I need a third machine to perform the same as the other two, ie, can I add another ESP32 in 'parallel" so when a staff is removed/inserted on that machine, the other two lock/unlock.  Is it just a matter of adding the third ESPs MAC address to the original sketches etc?

I've started watching some YT videos on ESP-NOW, but thought I'd ask you as well.

Cheers,

Ian

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
imillard
(@imillard)
Member
Joined: 2 months ago
Posts: 77
Topic starter  

Hi everyone,

Now that I have my project pretty much working, I am starting to look at getting some more ESP32 boards, and have been looking at these boards.

https://core-electronics.com.au/esp32-c3-mini-dev-board-risc-v-processor-wi-fi-bt5-smd-compatible.html

image

Can anyone confirm if these would be suitable to drive 2 x servos, be ESP-NOW compatible, and what board I would select in the Arduino IDE, as I couldn't see anything with the exact description.

Cheers,

Ian

Ian Millard
Port Macquarie, NSW, Australia
ESP32/Arduino etc novice


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7632
 

@imillard ESP-NOW is built in to every ESP32, it's part of the core. It's a nice little protocol, very simple and easy to use just not meant for a lot of data but better than LORA datawise.

That is a nice little board, but it's by Waveshare. I have lots of Waveshare products, but beware documentation is often very old and not updated so you need to know what is BS and what isn't.

They do document (see pics) this board. NOTE you select a ESP32S3 Dev module, NOT C3. This is what I mean by having the experience to know what to look for. There is also a second setting pointed out there for USB CDC, the 2nd picture has both settings, 1st and 4th.

The C3 part may give you difficulty, actually the 3 part, did you check the migration document for ESP-NOW and any other libraries you may need? OR just arbitrarily set the esp32 boards back to 2.0.17. I just tried that and the ESP32S3 Dev board entry is still there.

As to if it can do the stuff other than ESP-NOW, I leave that as an exercise for the reader, surely you have advanced at least that far by now, plus you know the requirements, I do not. It's most likely just fine, but check, maybe try one before buying 10 as these will be expensive since they are Waveshare and new.

 

Screenshot 2024 10 01 at 07.02.34
Screenshot 2024 10 01 at 07.02.57

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 4 years ago
Posts: 7632
 

@imillard @robotbuilder I stumbled across some ESP-NOW info. This is the link to the API doc and I am screen grabbing some info that you will need to be aware of. Pay attention to data types in the payload and arrange for the best boundaries so data access speeds are the fastest.

Here is the link

Screenshot 2024 10 01 at 11.47.10
Screenshot 2024 10 01 at 11.50.23

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
My personal scorecard is now 1 PC hardware fix (circa 1982), 1 open source fix (at age 82), and 2 zero day bugs in a major OS.


   
ReplyQuote
Page 15 / 16