ESP8266 Rocnet Nodes

RocClient Experiments
Rocrail Client experiments using the Wemos Oled Battery board.



The ESP8266 Code can be run on any ESP8266 ESP-12 modules. This includes the NodeMCU and WeMOS mini modules:


The NodeMCU module is on the left, and is fitted in a “NodeMCU Motor Shield” The Wemos Mini is a smaller equivalent to the NODEMCU, and is shown right, Note both have the same “ESP8266 ESP-12 module on board. The smaller board by the WEMOS Mini is an ADAfruit MAX 98357 board that is one option for the audio output. Below the NodeMCU is a 3D printed housing for the Hall effect switch that is used for sensing trains. The 3d file for this is included in my thingyverse item: Sensor

Stationary Decoder

The NodeMCU Motor Shield is very useful as the basis of a stationary decoder because it provides a Servo like three pin connection for each “D” output. This allows simple connection of hall effect switches or servos. However, the Central V+ rail of these pinouts is connected as standard to the NodeMCU 3.3V supply, which is not suitable for driving most servos. To overcome this I would recommend connecting a 5V regulator with input to the V Motor input, and the regulated 5V out to the “Vin” input. Then disconnect the 3.3v drive to the connection rail by cutting the single track on the rear of the board. You can then connect the 5V power (on Vin) to the (cut) 3v3 rail on the line oof pins by adding a link jumper to the “Vin/3v3” pins.


The motor shield is designed to allow you to use the inbuilt “293” motor driver IC to power high powered items like motors or lights.

These are connected to the D1-D3 and D2-D4 pins, which will need to be set up as outputs on the ESP module (and as PWM if you like). However please note that the 293 on the shield is NOT connected as four independent half bridges, but as a “direction” and PWM inputs. The direction input includes an inverter to one of the half bridges.

This means that the board can drive only two motors or two lights, and not four lights that would be possible if it did not include these inverters.

Mobile Decoder and Sound

There are two options to get sound.

The first uses the AdaFruit MAX98357 which provides high quality sound and onboard amplifier.

This board needs the _AudioDAC definition set, and then uses these connections :

  • I2SDAC_DIN 9 D9(/rx) Data
  • I2SDAC_LRC 4 D4 used as Left Right Control
  • I2SDAC_CLK 8 D8 used by DAC as clock.

The alternative is to use the definition _AudioNODAC. This creates a Class D amplifier output stage that uses D9/RX to drive a transistor base that then drives the loudspeaker.

  • I2SDAC_DIN 9 D9/rx (data) used to drive transistor base
  • I2SDAC_LRC 4 D4 used as LRC or i2s clock (?)

In this configuration D4 is initially set as a clock output, but it can be resused once the DAC has been setup although my code currently does not do this. I recommend placing 1k resistor between D9 and the NPN transistor base. This ensues that the serial programming is still possible. The transistor collector is connected to the loudspeaker and the emitter to ground. The Loudpseaker is connected to the collector and V+. An electrolytic across V+ to Gnd is recommended to support the high pulse currents.

The “NODAC” output system uses oversampling, so to try and prevent timing issues, I limited my sound samples to 11K sample rate, rather than the 44k possible. I have not done tests to find the limits.


One mobile sound decoder configuration is to use the WEMOS mini with a RC servo dc motor controller and the Adafruit DAC.


In this configuration, the Battery eliminator in the RC servo DC motor controller powers the WEMOS Mini and the DAC.

The Code can also be used to drive a PWM motor control directly, in which case the RC DC motor controller is replaced by a motor shield with the 293 chip or (much better!) a TB6612FNG Dual DC Stepper Motor Drive Controller Board Module.

The TB6612 has MOS drivers so does not have the losses of the bipolar 293, and I found it runs cool driving my loco motors, where the 293 gets hot. BUT!.

NOTE that the WEMOS Mini input voltage is limited to 6.5V, so must not be connected directly to a 2S LIPO. A small 5V regulator must therefore be added for this purpose.

(The NodeMCU module can take slightly higher unregulated voltages as it uses a different 3.3v regulator).

If you use the 6612, you can use one set of drivers to replace the single transistor AudioNODAC drive. Connect RX to one of the PWM inputs, and the loudspeaker (via a 10uf electrolytic) to the output.

I also connected a 100k resistor from 3V3 to the Standby pin, with 10uf from standby to Gnd. This provides a very short delay before the drivers are turned on. Without this, the wheels do a powerful spin on turn on that can be disconcerting or damaging.

The illustration below shows a 6612 board with the PWM Channel A driving to the motor, and one half of Channel B to drive the loudspeaker via the electrolytic, (but note that the standby pin did not yet have the Resistor-Capacitor delay added at the time of the photo).


Personal Tools