Wifi control with ESP8266
Wifi control with ESP8266
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.
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!): 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!
To be continued...
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!): 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!
To be continued...
-
- Trainee Driver
- Posts: 997
- Joined: Fri Oct 05, 2018 6:30 pm
- Location: South West Wales
Re: Wifi control with ESP8266
I will follow this with interest!
Trevor
Trevor
Re: Wifi control with ESP8266
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: 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!
Meanwhile, the interface as written by KushagraK7 on GitHub: 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!
Re: Wifi control with ESP8266
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:
So far so good! I should be able to get that to work on batteries.
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.
Re: Wifi control with ESP8266
Technically true 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.)
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.
Re: Wifi control with ESP8266
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.
-
- Cleaner
- Posts: 40
- Joined: Thu Jan 11, 2018 8:37 am
- Location: Dorset
Re: Wifi control with ESP8266
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 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
- -steves-
- Administrator
- Posts: 2445
- Joined: Thu Jul 28, 2011 1:50 pm
- Location: Cambridge & Peterborough
Re: Wifi control with ESP8266
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.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
The buck stops here .......
Ditton Meadow Light Railway (DMLR)
Member of Peterborough and District Association
http://peterborough.16mm.org.uk/
Ditton Meadow Light Railway (DMLR)
Member of Peterborough and District Association
http://peterborough.16mm.org.uk/
Re: Wifi control with ESP8266
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!)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
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.
I really like your handheld controller. I'm hoping I can figure out something like that eventually!
Re: Wifi control with ESP8266
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.
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.
- -steves-
- Administrator
- Posts: 2445
- Joined: Thu Jul 28, 2011 1:50 pm
- Location: Cambridge & Peterborough
Re: Wifi control with ESP8266
Looks really good, getter better and better with each revision. The SVG's are soooo much betterdrewzero1 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.
The buck stops here .......
Ditton Meadow Light Railway (DMLR)
Member of Peterborough and District Association
http://peterborough.16mm.org.uk/
Ditton Meadow Light Railway (DMLR)
Member of Peterborough and District Association
http://peterborough.16mm.org.uk/
Re: Wifi control with ESP8266
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
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.
Re: Wifi control with ESP8266
Wow, that does look interesting. I've not used ESP32 but assume I can transfer my knowledge of Arduino.
Rik
Rik
Re: Wifi control with ESP8266
Rik, I’ll start a new thread when I start playing around with it.
Re: Wifi control with ESP8266
Thanks HugoFitz! I hadn't seen that one before, definitely something to look into for both controller input and sound.
Re: Wifi control with ESP8266
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!
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.
I set up the indoor test track and shunted some wagons. My first RC loco, very exciting!
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.
I set up the indoor test track and shunted some wagons. My first RC loco, very exciting!
Re: Wifi control with ESP8266
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.
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!
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!
Re: Wifi control with ESP8266
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.
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 16 times
Who is online
Users browsing this forum: No registered users and 0 guests