Wifi control with ESP8266

What is your latest project?
User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Wifi control with ESP8266

Post by drewzero1 » Wed Feb 21, 2024 4:24 pm

Since the beginning of my garden railway ambitions I've planned to use wifi for remote control of my trains, either by some kind of homebrew ESP8266 or ESP32 solution, or a commercial offering like LocoRemote. Last year as I was building Thornas I ordered some ESP-01 modules and a couple of L298N dual H-bridge motor drivers. The L298N module turned out to be a tight fit inside the boiler and I'm only using one motor, so I may try to find or make a smaller board and save these modules for a larger loco-- but for now it works as a proof-of-concept.
L298N_Thornas.jpg
L298N_Thornas.jpg (365.55 KiB) Viewed 1067 times
Note: the small geared motor on the heatsink is just there for testing.

For the software, I'm using this project as a starting point: https://github.com/KushagraK7/ESP-Motor ... on-Control
I know just enough Arduino programming that I think I can modify it to make a more suitable locomotive control. Ideally in the future I'd like to build a standalone controller that uses a dial and switches instead of a touch screen, but that's a project for another day. (Month? Year?)

Here's the wiring diagram I came up with after some trial-and-error (and a mix-up that led to it almost working, but not quite as expected!):
ESP-01_L298N_connections_v2.jpg
ESP-01_L298N_connections_v2.jpg (32.81 KiB) Viewed 1020 times
Edited to add connection between VIN 3.3v and CH_PD on the ESP-01; CH_PD must be pulled high to operate.

This isn't necessarily a how-to, more just trying to remember what I did so I don't forget it all again for next time! :kermit:
To be continued...

Trevor Thompson
Trainee Driver
Trainee Driver
Posts: 978
Joined: Fri Oct 05, 2018 6:30 pm
Location: South West Wales

Re: Wifi control with ESP8266

Post by Trevor Thompson » Wed Feb 21, 2024 7:57 pm

I will follow this with interest!

Trevor

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Thu Feb 22, 2024 2:17 am

After a bit of research it looks like I'll be replacing the L298N with the DRV8833, which is reported to be more power-efficient, cooler-running, and (most importantly) smaller. I'll keep working with this one until the replacement arrives at the end of March.

Meanwhile, the interface as written by KushagraK7 on GitHub:
Screenshot_20240221-195211.jpg
Screenshot_20240221-195211.jpg (76.22 KiB) Viewed 1025 times
It's actually pretty close to what I think I'd like. There's some inertia built in so the motor gradually responds to the slider, but I'm thinking it might be useful to add an emergency stop button that stops immediately instead of ramping down. An overly ambitious part of me wants to replace the direction buttons with a reverser to simulate steam loco controls, at least for steam-outline models, and a brake control. Since I'll be using this on more than one loco it'd be nice to display the name of the current loco somewhere on the page. Light and sound are definitely on my list but will require a microcontroller board with more than two GPIO, such as the ESP-12.

At this point I should probably note that all of my experience driving trains comes from the MRC Tech-II controller that I use for my HO scale, DC track power... so I'm open to feature/design suggestions!

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Thu Feb 22, 2024 3:53 am

After puzzling for a while over why the ESP would boot on the programmer but not on the ribbon cable I made for it, I realized that the CH_PD pin also needed to be pulled high to boot, and modified the ribbon cable accordingly. (See updated diagram in the first post!) With the L298N connected to a 12v wall adapter and the ESP-01 getting 3.3v from the programmer, this is the result:
0505aa3a-c633-454c-b027-173da8425544.gif
0505aa3a-c633-454c-b027-173da8425544.gif (5.89 MiB) Viewed 1019 times
Note, the blue flashing light indicates that the ESP is receiving input on the web interface.

So far so good! I should be able to get that to work on batteries. :mrgreen:

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Fri Feb 23, 2024 5:01 am

drewzero1 wrote: Thu Feb 22, 2024 3:53 am I should be able to get that to work on batteries. :mrgreen:
Technically true :lol: I wired up a 2S pack of 18650s to run the motor and a USB power bank with the ESP programmer to provide the 3.3v for the ESP, and the little monstrosity chugs happily around the track. (Edit: video at 100% throttle.)
9af2aeab-d130-471e-8e67-d19004b8a7d6.gif
9af2aeab-d130-471e-8e67-d19004b8a7d6.gif (4.01 MiB) Viewed 957 times
This confirms that a 2S pack can power the loco, so a bit more permanent wiring and miniaturization is in order before I can put the boiler back together.

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Sat Feb 24, 2024 3:07 pm

I felt pretty productive last night and checked off two to-dos:
  • Switched the ESP to AP mode, meaning it appears as a wireless access point for devices to connect to independent of my home wifi network (or any other). This wasn't necessary for home use as my entire railway site is well-covered by wifi, but will allow me to run the loco elsewhere.
  • Added an indicator of the loco name and a crude image. Originally this was a multicolor 28x20px gif (around 650 bytes) but I couldn't figure out how to use #include on that file type, so I hastily converted it to SVG to embed within the text of the control page (HTML). The result added around 1.5KB which still leaves around 600KB free in the flash, but I'd like to try redrawing it in SVG directly and at least make it look better if the jagged pixels aren't helping save any space.
Screenshot_20240223-225946__01.jpg
Screenshot_20240223-225946__01.jpg (93.37 KiB) Viewed 899 times
I also attempted to set up a captive portal that would simply redirect to the control page, so the user doesn't have to enter an IP address once they're connected to the AP, but need to learn more about the ESP8266 DNS libraries to get that working. For now I settled for a static IP to avoid the need for a network scan or serial monitor to find out the IP every time it starts.

Southern188
Cleaner
Cleaner
Posts: 40
Joined: Thu Jan 11, 2018 8:37 am
Location: Dorset

Re: Wifi control with ESP8266

Post by Southern188 » Sun Feb 25, 2024 10:48 am

Good luck with your project.

I started using Arduinos in my garden rail locos in 2013 and and moved to ESP8266s in 2018. I use the Wemos D1 mini rather than the basic ESPs like the ESP01 that you are using. They have more I/O ports, an analogue input which I use for battery voltage and are easier to program (simple cable to PC).

Everything still works well in 2024.

You can see my system on this forum at:

https://gardenrails.org/viewtopic.php?t=11702

and on another forum on how I modified an LGB 24140 KJF loco:

https://www.gscalecentral.net/threads/b ... co.314042/

A useful read is the loco-remote website that also uses the the D1 mini.

https://locoremote.co.uk/


Michael

User avatar
-steves-
Administrator
Administrator
Posts: 2444
Joined: Thu Jul 28, 2011 1:50 pm
Location: Cambridge & Peterborough

Re: Wifi control with ESP8266

Post by -steves- » Sun Feb 25, 2024 11:09 am

Southern188 wrote: Sun Feb 25, 2024 10:48 am Good luck with your project.

I started using Arduinos in my garden rail locos in 2013 and and moved to ESP8266s in 2018. I use the Wemos D1 mini rather than the basic ESPs like the ESP01 that you are using. They have more I/O ports, an analogue input which I use for battery voltage and are easier to program (simple cable to PC).

Everything still works well in 2024.

You can see my system on this forum at:

https://gardenrails.org/viewtopic.php?t=11702

and on another forum on how I modified an LGB 24140 KJF loco:

https://www.gscalecentral.net/threads/b ... co.314042/

A useful read is the loco-remote website that also uses the the D1 mini.

https://locoremote.co.uk/


Michael
I missed the topic you first did this on and have just had a read through it. Along with those at the time and now, I am super impressed with what you guys have achieved, but alas, way out of my skill set.
The buck stops here .......

Ditton Meadow Light Railway (DMLR)
Member of Peterborough and District Association
http://peterborough.16mm.org.uk/

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Sun Feb 25, 2024 1:57 pm

Southern188 wrote: Sun Feb 25, 2024 10:48 am Good luck with your project.

I started using Arduinos in my garden rail locos in 2013 and and moved to ESP8266s in 2018. I use the Wemos D1 mini rather than the basic ESPs like the ESP01 that you are using. They have more I/O ports, an analogue input which I use for battery voltage and are easier to program (simple cable to PC).

Everything still works well in 2024.

You can see my system on this forum at:

https://gardenrails.org/viewtopic.php?t=11702

and on another forum on how I modified an LGB 24140 KJF loco:

https://www.gscalecentral.net/threads/b ... co.314042/

A useful read is the loco-remote website that also uses the the D1 mini.

https://locoremote.co.uk/


Michael
Thanks for the links! I do plan to upgrade to the D1 at some point for more I/O, but had a spare ESP-01 around for now. (Battery voltage monitoring would be very useful!)

This project has been very much inspired by LocoRemote, having discovered them early in my garden railway journey because of their very compact 3D printable track. My earliest rolling stock all fits around that track, until I joined here and started building bigger kits from the 3D printing section. :mrgreen:

I really like your handheld controller. I'm hoping I can figure out something like that eventually! :thumbup:

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Mon Feb 26, 2024 3:20 pm

Played around with some SVGs yesterday and managed to get Thornas down to about 900 bytes and Moke (the little diesel) under 800. Looks a little less lumpy too.
Screenshot_20240226-085646.jpg
Screenshot_20240226-085646.jpg (74.39 KiB) Viewed 778 times
I've also been experimenting with using the button color to indicate selected direction. As I'm modifying this existing code I'm getting a better idea of what it does, and getting more ideas of how to make it work.

User avatar
-steves-
Administrator
Administrator
Posts: 2444
Joined: Thu Jul 28, 2011 1:50 pm
Location: Cambridge & Peterborough

Re: Wifi control with ESP8266

Post by -steves- » Mon Feb 26, 2024 3:27 pm

drewzero1 wrote: Mon Feb 26, 2024 3:20 pm Played around with some SVGs yesterday and managed to get Thornas down to about 900 bytes and Moke (the little diesel) under 800. Looks a little less lumpy too.


I've also been experimenting with using the button color to indicate selected direction. As I'm modifying this existing code I'm getting a better idea of what it does, and getting more ideas of how to make it work.
Looks really good, getter better and better with each revision. The SVG's are soooo much better :thumbup:
The buck stops here .......

Ditton Meadow Light Railway (DMLR)
Member of Peterborough and District Association
http://peterborough.16mm.org.uk/

HugoFitz
Cleaner
Cleaner
Posts: 48
Joined: Mon May 08, 2017 3:08 pm

Re: Wifi control with ESP8266

Post by HugoFitz » Tue Feb 27, 2024 7:06 am

I'm definetly following this as I'd really like to use ESP to control my diesel loco I'm planning.

Seen this and thought people might find this interesting as a sound option.



His github is here www.github.com/TheDIYGuy999
Last edited by HugoFitz on Tue Feb 27, 2024 9:24 am, edited 1 time in total.

User avatar
ge_rik
Administrator
Administrator
Posts: 6580
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Wifi control with ESP8266

Post by ge_rik » Tue Feb 27, 2024 8:14 am

Wow, that does look interesting. I've not used ESP32 but assume I can transfer my knowledge of Arduino.

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

HugoFitz
Cleaner
Cleaner
Posts: 48
Joined: Mon May 08, 2017 3:08 pm

Re: Wifi control with ESP8266

Post by HugoFitz » Tue Feb 27, 2024 5:08 pm

Rik, I’ll start a new thread when I start playing around with it.

User avatar
ge_rik
Administrator
Administrator
Posts: 6580
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Wifi control with ESP8266

Post by ge_rik » Tue Feb 27, 2024 6:40 pm

HugoFitz wrote: Tue Feb 27, 2024 5:08 pm Rik, I’ll start a new thread when I start playing around with it.
:thumbup:

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Tue Feb 27, 2024 6:58 pm

Thanks HugoFitz! I hadn't seen that one before, definitely something to look into for both controller input and sound.

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Mon Mar 04, 2024 2:34 am

The 7333-A regulators and DRV8833 boards came a few days ago (earlier than expected!) and I've just finished working them up. Now most of the electronics fit in the boiler, with some overhang into the cab. There's a lot of extra wiring that needs to be cleaned up, and some that I'll need to add... It ain't pretty, but it works!
Screenshot_20240303-202043.jpg
Screenshot_20240303-202043.jpg (182.64 KiB) Viewed 387 times
Something's not quite right with the power supply to the ESP... it may need some kind of smoothing capacitor to keep the power steady, but most of the time it seems fine.
d7040993-df23-4911-94e5-8fad04bf0d69.gif
d7040993-df23-4911-94e5-8fad04bf0d69.gif (8.79 MiB) Viewed 387 times
I set up the indoor test track and shunted some wagons. My first RC loco, very exciting!

User avatar
ge_rik
Administrator
Administrator
Posts: 6580
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Wifi control with ESP8266

Post by ge_rik » Mon Mar 04, 2024 7:38 am

:thumbup:

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Wed Mar 06, 2024 3:24 am

Did some more tweaking, mostly UI modifications to make touch control work better. After playing around with it a little, this is the best I've got for now-- though upon further reflection I think I should probably rearrange the controls to the edges where the thumbs naturally fall.
Screenshot_20240305-210910__01.jpg
Screenshot_20240305-210910__01.jpg (82.82 KiB) Viewed 227 times
The locomotive image ends up below the fold on my phone in landscape mode, but fits perfectly on my iPad screen.

A physical controller would of course be better in every way, but that may have to be a project for next winter!

User avatar
drewzero1
Administrator
Administrator
Posts: 486
Joined: Fri Apr 21, 2023 4:35 pm
Location: WI, US

Re: Wifi control with ESP8266

Post by drewzero1 » Wed Mar 06, 2024 3:49 am

If anybody's got a spare ESP8266 and wants to play around with it, here's the Arduino project so far. It is based on the original project "ESP Motor Speed and Direction Control" from KushagraK7 on Instructables. https://www.instructables.com/member/Ku ... ructables/
https://github.com/KushagraK7/ESP-Motor ... on-Control

MIT License

Portions Copyright (c) 2024 Drew Knoll-Owen
Portions Copyright (c) 2021 Kushagra Keshari

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Attachments
lococontrol.zip
(3.98 KiB) Downloaded 9 times

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests