Geoff Bunza geoffb
Model railroaders running JMRI have the capability of connecting  their cell phone or wireless tablets as a remote throttle for DCC control. I have often heard modelers who would like newcomers to operate their layouts with a simplified throttle, with a speed control knob.  Also reducing the possibility of inadvertently changing things visitors know nothing about. This article describes the construction of a simple WiFi throttle that connects directly to the JMRI WiFi server. It is not dependent on your DCC base station connected to JMRI. It will support loco address selection, six (or more) function switches, speed and direction control, running on a standard nine volt battery. While providing basic throttle functions, it can be customized and expanded by the inventive modeler to perform multiple functions at the touch of a button. You can also limit its functionality as you wish. It uses simple readily available parts for a one or two evening project. Throttle sketch updated 7 May 2019 to V5.2 minor bug fix.
_Opening.jpg 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 3
Geoff Bunza geoffb

Build The Simplified WiFi Throttle

The heart of the throttle is a relatively new module, the ESP32, or more accurately, the ESP32 Development board from EzSBC.com. It is a much more powerful module than the typical Arduino board, but uses many of the same Arduino tools. It has impressive technical specs for a low cost part (under $10):

  • 240 MHz dual core Tensilica LX6 microcontroller 80 MHz
  • Integrated 520 KB SRAM
  • Integrated 802.11BGN HT40 Wi-Fi transceiver
  • Integrated dual mode Bluetooth (classic and BLE)
  • 4 MByte flash memory
  • 3 x UARTs, including hardware flow control
  • 3 x SPI, 2 x I2C, 12 x analog inputs, 2 analog outputs,
  • PWM/timer input/output available on every GPIO pin
  • Supports external SPI flash up to 16 MB
  • SD-card interface support
SP32_Top.JPG 

ESP32 Dev Board from Ezsbc.com

(A cautionary note: there are no less than 4 different ESP32 Dev Module for sale on the web. I recommend EzSbc.com's board -- simply because I know it works, and it is a quality product. I have tried 2 others and run into problems. Perhaps you will have different experiences.)

It needs to be loaded in a very similar manner as an Arduino controller, with nearly the very same tools. The ESP32 has a small voltage regulator on board so you can power it with a 6-12 Volt battery (I use a standard 9 Volt battery).  The higher voltage is lowered to 3.3 Volts for the ESP32. As with most of my projects, you don’t need to know any programming to use this. Everything is pre-built for you.

I used a momentary pushbutton (SPDT) for DCC Function 2 which I use for the whistle or horn on my locos. You can use a toggle switch if you prefer. The five toggle switches fit neatly in my throttle box and I didn’t want any more. You can assign any function you want to each switch, and the current sketch will easily support 8 distinct DCC functions as is.

Additional instructions will guide you if you want to make changes. If you can solder and run an editor, you can build your own throttle – and more than one can be used simultaneously with JMRI.  Let’s get started.

The Basic Throttle

Step 1. Gather your parts

Here are the materials you will need:

Qty 

Description

 

1

ESP32-01 Breakout and Development Board

https://www.ezsbc.com/index.php/wifi01-35.html

6

SPDT Sub Miniature Toggle Switches

https://www.allelectronics.com/item/smts-4/spdt-on-on-sub-min-toggle-switch/1.html

1

SPDT Mini Toggle Switch Center Off

https://www.allelectronics.com/item/mts-5pc/spdt-on-off-on-mini-toggle-switch-pc-terminals/1.html

1

10K Linear Mini Potentiometer

https://www.allelectronics.com/item/ptw-10k/10k-bourns-pot-pre-wired/1.html

1

Knob for Potentiometer

Consider your choice well – This is the “feel” of the throttle*

1

0.96 Inch OLED Display White (or other color)

With SSD1306 controller & I2C interface

https://www.ebay.com/itm/382557870211

1

Plastic case

https://www.ebay.com/itm/131978994077

2

Micro JST 1.25mm 6-Pin Connector sets wired

https://www.ebay.com/itm/302746030692

1

9 volt Battery Holder Snap

https://www.ebay.com/itm/163376406979

*Use whatever knob fits your 10K Pot.

The JST connectors are optional. Anytime I want  disassembly ease I use these.

Step 2. Lay out your case and prepare it

Here is the general layout of my throttle. I installed only 5 subminiature toggle switches and one push button for the six functions (F0-F5) I wanted. You can add more or use fewer. The code has one value to set depending on how many you use:

int num_functions = 6;     // Number of functions supported by this throttle UP TO 8 MAX
 

eledTemp.JPG     hLabeled.JPG 

Figure 2. Simplified throttle internal names      Figure 3. Simplified throttle functions assigned

Your component choice may be somewhat different than mine. Layout the switch holes and small window for the OLED display. I started my mimicking the Digitrax throttles which power on when the battery is inserted. But I later added a small switch to turn the battery on and off – quite simple.

Step 3. Install your components

Once you decide where everything goes, drill all your holes, insert, and lock down your components. Figures 3. And 4. show my internal layout. Many people like a large knob for their throttle. It is not a big deal to me, but in the box I chose there is plenty of room for a bigger knob, and even a bigger potentiometer. If you want to mount a six inch knob, simply use a bigger enclosure (try digikey.co, mouser.com, or allelectronics.com).

Shell2.JPG 
Figure 4. Component placement inside 
 
Shell1.JPG 

Figure 5. Wiring harnesses connected

Step 4. Wire everything

I found it easier to wire after installing all the switches. Since I knew I would take this apart again and again (this was the prototype remember), I used small connectors with pre-attached wires to connect everything. Figure 6.  shows the basic interconnections, color coded. The on-off switch is optional, but I recommend it to save battery life in the long run. The battery connector is hidden behind the cover of the battery compartment. Note that the connections to the SPDT push button need to connect to the common-middle and the normally closed connection. You should take note that the ESP32 is a 3.3 Volt part. All digital connections are therefore 3.3 Volts maximum. Also realize that you can light most any “normal” LED with the 3.3 Volts and a small dropping resistor (like 220 Ohms ¼ Watt).
 
_Diagram.jpg 

Figure 6. WIFi Throttle Diagram

Step 5. Download the Arduino development editor and software

I have previously written before about installing and loading Arduino software: in MRH December 2016, A modeler’s introduction to the Arduino http://mrhpub.com/2016-12-dec/online/ and here: in MRH March 2017, DCC projects using the Arduino  http://mrhpub.com/2017-03-mar/online/html5/  The ESP32 is a different controller that will make use of the Arduino editor and loading environment, but with a different configuration and library. The same free tools that can be downloaded here:  https://www.arduino.cc/en/Main/Software Download and install this if you have not already done so.

Step 6. Load the ESP32 library

Start up the Arduino application you installed. On the top left menu click File -> Preferences.

In the field after “Additional Boards Manager URLs:”  paste:  https://dl.espressif.com/dl/package_esp32_index.json

And click OK.

Go back to the top menu bar and click: Tools-> Board -> Boards Manager…

Looks towards the bottom in the new Boards Manager list that opens, and find the entry labeled “esp32 by Expessif Systems” and click on that entry. A small label “Install” should appear on the lower right of the entry. Click on “Install.” After it finishes installing, click “Close” in the lower right corner of the window.

Now click on Tools-> Board-> Esp32 Dev Module  from the board list (likely near the bottom).

Close the Arduino IDE application.

Step 7. Download the Simple Throttle sketch

Download the throttle sketches from here:    zip Throttle_Sketches5-4.zip     
and unzip.

Move the folders and their contents labeled ESP32_Throttle and Blink7f_ESP32 into your …\Documents\Arduino\ folder and move the folder esp-oled-ssd1306 into your …\Documents\Arduino\libraries\ folder. Do not use another SSD1306 library.

Step 8. Load the ESP32 controller with the Simple Throttle sketch

Connect the micro USB connector to your ESP32, and the other end to your Windows machine. As of this writing, all the Arduino/ESP32 software should work on a Windows PC, and an Apple PC. I know this will not work on a Raspberry Pi.

Start up the Arduino editor, making sure you have selected the ESP32 Dev Board from the Tool-> Board menu.

Next, select from Tools-> Board-> Port menu the Port your ESP32 is connected to.

I have tested all this with Windows10 and Windows7. If a “Port” number does not show up after you plug in your ESP32, the Win10 and Win7 current Silicon Labs USB drivers can be found here:
so you don’t have to hunt for them.

I included a special “Blink7f_ESP32” sketch you can use for testing your setup to the ESP32.

Open the sketch on the folder Blink7f_ESP32 and download it onto your ESP32. After a short delay two LEDs should blink in succession red, green, blue and blue. When this succeeds, open the folder labeled ESP32_Throttle and download the throttle sketch onto your ESP32.  If you are using a Windows 7 machine you will have an additional step. After the download starts, at the bottom of the Arduino editor window you will see a message like:

Connecting....._____...

As soon as you see this on screen hold down the “Enable” (EN) button to the left of the USB micro connector (it is immediately next to the pin marked “EN” (shown in Figure 7.) and release the button as soon as the text changes in the window. I have not been able to get around this method on Windows 7. I have not tried this on a Mac nor on any other Linux machine other than an RPi.
 
ESP32_EN.JPG 

Fig 7. Enable Button

Step 9. Connecting to your Wireless Server

If my Wireless Server is not powered up, I get the message on the small OLED screen:
766A0216.JPG 

Figure 8. Start-Up Screen

Which means that my  Simple Throttle has started up and is looking to connect to my WiFi named (ssid) model-rr.
When it finds the model-rr WiFi server it will then display in sequence:
 
766A0219.JPG   766A0223.JPG 

Figure 9. Loco Assigned & Functions Test           Figure 10. Loco 3 Selected Speed is 0 and Fwd toggle is set

When you flip a function switch “ON,” the function number will be displayed like this:
 
Start4.JPG 
Figure 11. Operating Loco Functions 0,1,3,4,and 5 ON
 
Step 9. Special Operations
 
Direction Neutral (Center Off): When the direction switch is set to center off during normal operation, then the speed control know will be ignored, and the last known speed sent to JMRI will be displayed. If you change the speed setting while in Neutral, then set the Direction to either FWD or REV, the current knob setting will be sent to JMRI as the new speed setting.
 
Changing addresses: Even if you are using this throttle for a young visitor, you may want to change the address of the throttle occasionally, without having to re-program the ESP32. This can easily be done with the following sequence:
 
1. Start with the throttle powered off and the Direction switch set to center off.
2. Push and hold down the push button normally used for F2, then power  the throttle on.
3. Release the push button and the screen should blink: “SET ADDR?” with the last address set displayed.
4. Set  the Direction switch to increment up (FWD) or down (REV) and push the button to change the address.
5. When done setting the address, release the button, place the Direction switch to center off, and hold the button down for one second. The new address is saved and you can start running the loco at this address.
 
Turning DCC Power ON: Before you release the button in the previous step, and after placing the Direction switch in the center off position, if you flip all function switch up (ON), then when you release the button the command will be sent to JMRI to turn on DCC power. This is not something one would normally expect a novice user to do on his/her/its throttle but it is provided here for your convenience
 
If you are not changing the loco address, then:
1. Before powering on
2. Set the Direction switch to center off
3. Turn all function switches up (ON)
4. Turn Power On or connect your battery
The command will be sent to JMRI to turn on DCC power.
 
Step 9: Changing your throttle configuration
 
You can change your throttle to work with any JMRI WiFi server.
Near the beginning of the sketch you loaded into your ESP32 you will find the statements:
 
// WiFi Server Definitions
const char* ssid       = "model-rr";
const char* password   = "model-rr";
const char* host = "192.168.6.1";
const int tpPort = 12090;
 
With the Arduino editor you can change the name (ssid) of the WiFi server, the password to access the server, the server’s network (IP) address, and the Port number for the server access. When you edit them be sure to change only what is between the double quote marks (“   “).
 
You can also limit the number of Function switches that can be used by the throttle from 1-8 by changing the “6” in the statement:
int num_functions = 6;     // Number of functions supported by this throttle UP TO 8 MAX
 
You can also change the switch/button assignments to their respective functions by changing:
#define F0_pin         TA   // Function 0 pin assignment
#define F1_pin         TB   // Function 1 pin assignment
#define F2_pin         PB   // Function 2 pin assignment
#define F3_pin         TC   // Function 3 pin assignment
#define F4_pin         TD   // Function 4 pin assignment
#define F5_pin         TE   // Function 5 pin assignment
#define F6_pin         TF   // Function 5 pin assignment
#define F7_pin         TG   // Function 5 pin assignment
 
You can see the pins assigned to each label here:
#define  PB           26   // Pushbotton Active LOW usually assigned to F2
#define  TA            2     // SPDT toggle active HIGH
#define  TB            4     // SPDT toggle active HIGH
#define  TC            5     // SPDT toggle active HIGH
#define  TD            12   // SPDT toggle active HIGH
#define  TE            13   // SPDT toggle active HIGH
#define  TF            14   // SPDT toggle active HIGH
#define  TG           15   // SPDT toggle active HIGH
 
This gives you the ability to assign the push button to a different function, and to rearrange the order of all functions any way you want. You could even implement a sequence of DCC commands, (like taking up coupler slack, stopping, backing pausing and forward for uncoupling moves, etc.) and even "side animation sequences" to alternate decoder addresses at switch or button command.
 
There are many more variations you can build into your throttle. This article should get you started on a whole series of new adventures in model railroading, quickly, and for relatively low cost!
Appropriate questions, comments, and suggestions are always welcome.
Have fun!  [smile]
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 2
HVT Dave

WOW, You've done it again!!!

Geoff, your just keep finding more and better ways to improve the layout using inexpensive and fun electronic projects.  I am ordering the components this afternoon.

Thanks for sharing your expertise!!! 

Dave

Member of the Four Amigos

 

Reply 1
vggrek

(No subject)

Reply 0
Tom Edwards edwardstd

Nice project!

Looks like something that might keep me busy this winter.

 

--- Tom

Tom Edwards

N scale - C&NW/M&StL - Modeling the C&NW's Alco Line

HO scale - Running on the Minnesota Central (Roundhouse Model RR Club, St. James, MN)

12" to the foot - Member of the Osceola & St. Croix Valley crew (Minnesota Transportation Museum)

Blog Index

Reply 0
Brent Ciccone Brentglen

Just what I was Looking For!

This is just what I was looking for! I even have a couple ESP32 modules on order, although they are not the same ones used here. Hopefully, I can make them work! I want to see if I can get it to work with a Digitrax LNWI module, that way I won’t need the computer. Although I am torn between the LNWI and getting a raspberry PI, cost is about the same.

Brent Ciccone

Calgary

Reply 0
Geoff Bunza geoffb

@Brent re:LNWI and RPi

Hi Brent,

I have heard good things about the LNWI but don't use one myself. I am using a couple of RPi 3 B+ based JMRI WiFi servers and they work great -- really great! There is an article in the MRH funnel for such right now. I've used this WiFi throttle with the RPi setup for several months now. The throttle can transmit from any corner of my house to the RPi, as I found out quite by chance!
Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 1
Prof_Klyzlr

ESP I/O pin count?

Dear Dr Geoff,

Very interesting, and impeccably presented as always!

A question, what's the I/O pin count on the ESP board?
It's on a holding pattern anyway, but my "Project OCU",
which was looking to use an IOIO GPIO USB interface to a Droid phone (running Enginedriver), had stalled.

This could well replace the thorny IOIO/Droid part of the equation,
Assuming there's enough I/O.

Happy modelling,
Aim to Improve,
Prof Klyzlr

PS for any Aussies following along, the ESP32 Dev board is available via littlebird.com.au for AUD$30 + postage
https://www.littlebird.com.au/espressif-esp32-development-board-developer-edition

Reply 1
rickwade

Wow

Rick

img_4768.jpg 

The Richlawn Railroad Website - Featuring the L&N in HO  / MRH Blog  / MRM #123

Mt. 22: 37- 40

Reply 0
Geoff Bunza geoffb

@Prof re: ESP32 Pins

Hi Prof,

Quote:

what's the I/O pin count on the ESP board?

From this diagram:
_Pinouts.jpg 
You can see all the pins in this module. You need to be care ful about the use of IO0 and IO5. They have meaning during the boot process. all the pins labeled IOxx can be used for digital IO (0-3.3V). There are 16 pins capable of Analog input. Besides the USB connection, there is a second serial port (IO1,IO3). There are 2 built in 3 color LEDs. You can power the module with 4-12V input at Vin. The dual processor .internally runs at about 80MHz (Arduinos typically operate at 16MHz give or take a bit). It has more memory too.
Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Rick

Hi Rick,

I just knew you needed another project to keep you busy! 
Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Logger01

Great Development and Post

Geoff,

As usual a great intro to these very capable modules. I have been working with the ESP32U-01 Breakout and Development Board which costs a couple of $'s more but has a UFL antenna connector. I need more range in the garden.

For those wishing to dig a little deeper (Prof K) the EzSBC ESP32-01 Breakout and Development Board page includes the following links:

If anyone wants to dig deeper into the actual ESP module(s) used on these boards the following links can provide additional guidance (or heaps of frustration):

ESP32-WROOM-32U Info

ESP32-WROOM-32 Datasheet (pdf)

Ken K

gSkidder.GIF 

Reply 0
Geoff Bunza geoffb

@Ken re: Add on antenna

Hi Ken,

Thanks!

Have you tried this antenna: 2.4GHz Mini Flexible WiFi Antenna with uFL Connector from Adafruit.com
It's supposed to offer reasonable gain and is not expensive.
 
Added Comment: I just looked at the EzSbc.com reference you provided and it looks like they include the very same antenna with the board you use!
 
How have you found the effective distance increased with the antenna?
 
Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Mark67

Truely amazing - I highly

Truely amazing - I highly appreciate the SMA series!

Would it be possible to develop something similar, that interfaces into the Digitrax system? I assume for this both would be required, the throttle and the wireless receiver interfacing into DCC.

Have a good weekend!
Mark

Duct tape turns a NO into a Hm-hm.

Reply 0
Prof_Klyzlr

Pin Hell

Dear Dr Geoff, Ken,

Thanks for the pin-out details of the ESP32 Dev board. I won't spew details here as it's waaaaay OT for the thread,
but it appears the ESP32 is a little light-on against the "Project OCU" requirements...

...unless...

"Project OCU" uses multi discrete-stepped controls for both Throttle and Brake controls,
(the donor is a prototype bellypack)

and I think the actual unit has existing built-in multi-contact switches under the physical "rotating lever" controls,
(naively I thought that discrete switch contacts --> explicit speed step values would be simpler)

but if I can convert both controls to a potentiometer while maintaining the existing stepped-rotation and spring-back feel, this would drop the Input-Pin count by at-least 8,...

...well, back to the drawing board...

 Happy Modelling,
Aim to Improve,
Prof Klyzlr

Reply 0
Yaron Bandell ybandell

Multi contact to potentiometer

At the risk of derailing this thread: Prof, why don't you convert the multi position contacts into an resistor voltage division network like the Protothrottle light selection switches and feed the resulting voltage into one of the Analog to Digital pins of the ESP? Gets you multiple set values on the Analog pin that correspond to the desired speedstep.
Reply 0
Prof_Klyzlr

Many Thanks...

Dear Yaron,

Many thanks for the suggestion, I'll definitely investigate that when I next unearth the donor OCU...

(cue radio-announcer voice)
...and now, back to your regularly scheduled prograaaamm,
Dr Geoff, take it away...

Happy Modelling,
Aim to Improve,
Prof Klyzlr

Reply 0
ncliffe

interesting - loco selection

Geoff, this is very interesting.

Have you considered getting a list of locos from the WiThrottle server process, and presenting them as a list to scroll through ?  Or storing an array (local roster) within the device to scroll through.  Either might be quicker than going through the 9999 potential DCC addresses.  Or have I mis-read the loco selection process ?

Nigel

Reply 0
Babbo_Enzo

Some additional links for Novice readers on ESP32

Absolutely GREAT post, agree!

Some additional links for Novice readers on ESP32 , also:

https://randomnerdtutorials.com/esp32-web-server-arduino-ide/

https://www.espressif.com/en/products/hardware/esp32/overview

https://github.com/espressif/arduino-esp32/issues/544

https://makeradvisor.com/tools/esp32-dev-board-wi-fi-bluetooth/

 

Reply 0
Geoff Bunza geoffb

@Mark re: Digitrax LNWI interface

Hi Mark,

I don't have the Digitrax LNWI so I can't speak to interfacing to it.

As presented, this throttle is dependent on the JMRI wireless protocol. You would need to adapt the code to the LNWI protocol, if it is published.

Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Nigel re:Loco selection

Hi Nigel,

What you suggest is entirely possible, although I might have to add a button or two for selecting.
 
The JMRI protocol sends the list of locos defined in the roster with addresses to the throttle, when it first starts communicating with the JMRI wireless server! I opted to ignore the list to simplify the operation and the sketch.
 
The rest is left as an exercise to the reader!!   (I always wanted to use this line!)
 
Have fun! 
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Enzo Thanks!

Hi Enzo,
 
I haven't seen your posts in a while. Thanks for your contribution.
Have fun! 
Best regards,
Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Babbo_Enzo

Geoff drop a fantastic idea

Geoff drop a fantastic idea on other site ....

You should also note you could even implement a sequence of DCC command sequences, (like taking up coupler slack, stopping, backing pausing and forward for uncoupling moves, etc.) and even "side animation sequences" to alternate decoder addresses at switch or button command.

The rest is left as an exercise to the reader!!   

Reply 0
KHaus41369

Couple of basic simple questions.

So it's just a build the controller and load the software. No coding involved technically to make it work other than changing password, wifi name such...function switch assignments?? Will this work with Steve Todd's RPi wifi/jmri setup?? Does our roster listing from jmri show up on the LCD screen for address selection or we flipping thru numbers to program the loco we want address?

Kevin

Modeling something to do with the Grand Trunk Western.

Reply 0
Babbo_Enzo

You Welcome Geoff! Always

You Welcome Geoff! Always amazing projects that shake my imagination!

unfortunately my activity in last years are mostly chair limted but I wait next year my retirement, so ... please wait me to join the company????

Reply 0
Reply