User Tools

Site Tools


ESP8266 Rocnet Nodes

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


Setting up the Node Software

Full documentation with illustrations is in Node Setup.pdf

This includes full details on:

  • Programming the NodeMCU/ESP8266
  • How Rocrail addresses Ports
  • Wireless Debugging
  • Wireless Updating
  • Updating the code
  • Updating the sounds:


Selecting Pins as Inputs or Outputs

The code use settings from BOTH Pi02 and Pi03 settings tables to determine the functionality of each pin.

  • If Pi02 Is set as "INPUT" then the pin is an input (and automatically has the weak pull-up switched on)
  • If Pi02 is set as "OUTPUT", then the output can be either a Digital, PWM or Servo output, depending on the Pi03 settings.
  • With Pi02 as "Output, if Pi03 "Blink" is set, the output will be PWM.
  • With Pi02 as "Output, if Pi03 "Servo" is set, the output will be a Servo pulse.
  • With Pi02 as "Output, if neither Pi03 "Blink" nor "Servod" are set, the output will digital.

Setting "Pio2 Blink" enables a flashing mode, whose rate is determined by the Pio2 "delay".

In PWM and Servo modes, the Pio3 Delay*10ms and Left and Right Steps will determine how fast the servo moves to the new position.

Set Delay = 0 and steps to 0 for the fastest movement.

"FIXED" Functionality

If you are using the code as a mobile decoder, then some pins will have "fixed" functionality. In this case, changing their functions or characteristics using the rocrail tabs will have no effect. You can confirm that their functionality is fixed by observing the Arduino serial terminal as the device initialises. As the device initialises, it checks its port definitions and sends a summary that looks like this: From it you can see if I/O is "fixed", and why.

* Port :0 is SignalLED  Output (FIXED) NodePortType :0  Pi03_Setting_options0
* Port :1 used as LOCO MOTOR (FIXED) NodePortType :0  Pi03_Setting_options42
* Port :2 is BACKLight  Output (FIXED) NodePortType :0  Pi03_Setting_options0
* Port :3 is FRONTLight  Output (FIXED) NodePortType :0  Pi03_Setting_options0
* Port :4 is Output NodePortType :0  Pi03_Setting_options0
* Port :5 is Output NodePortType :0  Pi03_Setting_options0
* Port :6 is Input with pullup NodePortType :1  Pi03_Setting_options0
* Port :7 is SteamPulse  Output (FIXED) NodePortType :0 
* Port :8 is Servo NodePortType :0  Pi03_Setting_options32 

(As a very simplistic overview, NodePortType Determines if the port is Input or Output, Pi03_Setting_options determine the Pi03 settings.)

Use the Rocrail Rocnet Programming tabs to get a much clearer picture of exactly how the ports are set)

When set as a Loco, the code expects LEDS connected to 3v3 and the Back or Frontlight pins (D2 and D5). Currently the "fixed" nodes cannot have their phase altered using the Rocrail Rocnet Programming PI02 tab.


CV settings for Mobile Decoder

Clicking on “Programming” will open the Rocrail CV Programming interface. To make this work, you need to select “POM” and the loco to be programmed in the top left box, and Rocrail will interrogate the set loco address and get the main CV settings:

Changing the Loco address can be done with this interface, but care needs to be taken to ensure the programming interface loco address and the loco address stay in synch.

To change from a Short Loco address to a Long loco address, First set the Loco "long" address to the Current Short address. Then change the Loco so it reads the Long address, and then chang ethe Loco address to the desired Long address.

Sound CV settings

The volume of each "F" effect is controlled by a CV: These are defaulted to 127, but can be changed using normal DCC "CV change" procedures:

* CV[100]=127; // Overall volume control 
* CV[101]=127; //volume for F1
* CV[102]=127; // F2
* CV[103]=127; //F3 
* CV[104]=127; //F4
* CV[105]=127;
* CV[106]=127;
* CV[107]=127;
* CV[108]=127; // Volume for F8  
* CV[110]=127; // volume for chuffs
* CV[111]=127; // volume for Brake Squeal

Speed settings:

  • CV[2]; Minimum speed setting (not MPH!..) Will have CV 66 or 95 added to set power at minimum speed demand
  • CV[5]; Multiplier for speed setting, is multiplied by required speed to set power to motor
  • CV[66]; Forward speed trim Added to CV 2 when in "forward"
  • CV[95]; Reverse speed trim Added to CV 2 when in "reverse"
  • CV[65]; Kick start sets duration of high speed motor setting when starting.

To set for best performance, first set CV2 so motor is running reliably at a "minimum speed" of 3 mph. (The code assumes this is the minimum the loco can do , but the "3" min speed value can be changed in the code).

Set CV 66 and CV 95 if needed to trim for equal speed forward and reverse.

Set the kick start CV65 to a value so that the motor reliably starts without a visible kick. If it kicks noticeably then lower the value. If it does not start, increase the value.

Set the loco to 10 mph and adjust CV5 so the loco travels at 10 mph.

Some examples using Rocrail Rocnet programming

Go to Rocrail and select "Programming / Rocnet / Setup" and then press “Query”. This will bring up a page that shows all the nodes connected to the MQTT broker. (Note this does not update actively so may show nodes that are currently off or not powered up).

If you press "Show", the built-in LED on the highlighted node will flash to help identify / find the node. (As shown here, Node "Shed1" / ID 10" will flash)

The decoder we were looking at via the Arduino Serial monitor is ID 28, and has the nickname “NoDAC”. The Roc Node address was set initially to the last byte of the IP address because of the _ForceRocnetNodeID_to_subIPL directive. This prevents nodes being on the same “node” address. Once the unit is reprogrammed with the directive disabled, you can set the Node Address via the Rocrail “Rocnet” ID interface, and also the node “nickname or “UID-Name” as Rocrail calls it. I would recommend leaving the Node ID as the IP address as it may help debugging later, but the "Shed1" and Swing" nodes have been set in this example with RocID's of 10 and 12, but their WiFi sub ip's are 19 and 20.

If we now highlight node ID 28, and Click “Pi02 Port Setup”, it will show us how the various ports are set up:

Port 6 is an input, but all others are outputs. If any of the Pi02 ports were set with “Blink”, they will blink/flash with a delay set by the Delay setting. “Invert” would invert the port phase. Note Rocrail does not know that some ports are “FIXED”, but if you try to modify them they will revert to their “FIXED” settngs.

Pressing “Pi03 Channel Setup” shows further information about our 8 io pins:

Here we see that Pin 1 and 8 are defined as a servos.. Pin 1 is actually the “FIXED” Motor drive servo, and is a special case where Left Right, Left steps Right steps etc are defined by CV values so these values cannot be changed here. Pin 5 has Blink set, so will be a PWM output, switching between the Left and Right PWM settings of 160 and 600. Pin 8 is a “normal” Servo output and will switch between positions 236 and 457. Note that in Rocrail, Min and Max positions for a servo are 150 and 600.

Because this example is a “loco” at address 7 we can look at the throttle: I have set this one in the Rocrail “Locomotives table” with some default sound effect names.

Clicking on “programming” will open the CV programming interface. To make this work, you need to select “POM” and the loco to be programmed in the top left box, and Rocrail will interrogate the set loco address and get the main CV settings:

users/dagnall53/node_setup.txt · Last modified: 2018/11/12 08:56 (external edit)