User Tools

Site Tools


users:dagnall53:node_programming

Index

Programming the Hardware

Arduino Libraries and Dependencies

It is vital that you have the correct libraries installed in your Arduino to allow it to compile the code. You should have


Programming a Stationary Node

From WiRocS V 15, I have been saving the Sketch files with them setup for Stationary Nodes. It should be possible to simply compile the code and upload it (and the SPIFFS sketch data) to your ESP 8266 or ESP32. See Direct Binary Upload

But If you wish to change the way the code compiles and works, there are a number of Directives set in directives.h that affect the coding.

  1. I now recommend the Audio be left on, but the Audio directives can be switched off if required.
  2. Assuming you have Audio , you will need the SPIFFS to be populated with the example .wav Files.(see below)
  3. I program the ESP8266 with the Arduino 'NodeMCU 1.0 ESP12-E' board option, and it must be set to "Flash Size (4M,2M Spiffs)
  4. For the ESP32, I use the 'WEMOS Lolin32' board option.
  5. Make sure you "UPLOAD" the "Sketch Data" to the ESP. (see below)
  6. WiRocS will default to Rocnet ID 50.
    1. YOU MUST change the Rocnet ID after programming to a spare ID, as RocRail needs each node to have separate RocNet ID's
    2. Use (RocView, Programming, Rocnet)

Programming a LOCO decoder

  1. To use the WiRocS Code for a "Mobile" (Loco) controller, you will need to use the Directive '#define _LOCO_SERVO_Driven_Port 1
    1. By Its-self, this sets up a RC servo controller on D1 as a Loco Speed Control.
  2. If the LOCO uses a PWM speed controller, then #define _LocoPWMDirPort 3 will also need to be uncommented.
  3. These two defines set up the board with PWM drives on ports D1 and D3, and FrontLight and BackLight on pins D2 and D5.
  4. Sound effects for synchronised chuffs and bells, whistles, etc are stored in the SPIFFS and may be edited to match your loco.
  5. Just like theStationary nodes, the RocNet ID must also be changed to a spare ID, or Rocrail will have problems!
  6. Once programmed, you can use the standard "RocView Loco Programming" system to change the Loco CVs, to modify the loco address and other behaviours.

Forcing compiler options if there are setup issues

I have tried to make the code react sensibly when programmed to a blank board, but it is difficult to cover all eventualities. So, if you have any problems with the code repeatedly crashing after your upload, it may be that it is having trouble with internally set (wrongly or not at all) EEprom settings. If you are experiencing this issue, I have some "Force" defines to set internal variables. These are probably not required, but:

  1. You can set your own Router and Password settings in the Secrets.h file.
  2. #define _ForceRocnetNodeID_to_subIPL
  3. #define _ForceDefaultEEPROM T
    1. NOTE this should force "sensible" values into the EEprom– BUT will STOP you saving any new settings!!- including the WiFi SSID etc!
  4. #define _Force_Loco_Addr 3 (if using the Loco Mode this sets the loco to address 3)
  5. IF you have to use these "FORCE" defines MAKE SURE that you then comment out these defines and reprogram the unit so you can set and change things for your specific application.

SPIFFS Data Upload

WiRocS stores all its sound effects in a "SPIFFS" (Serial Peripheral Interface Flash File System) To make my code "work as expected" , it needs to have all the sketch programmed on the board, including the Sketch data upload.

  • SPIFFS is a small (2Mb) disk drive set up inside the ESP, that can have many files stored, just like a normal disk drive or SD card.
    • The size of the SPIFFS is set when you program the main ino. I (now) use the "2M SPIFFS" option
  • You can send files (or read) these files in the code, OR send to the "disk drive" using a "File Transfer Protocol" (FTP) program.
  • In an Arduino sketch, files that are expected to be stored in the "SPIFFS" are stored in a special "data" directory.
    • As part of the ESP programming, you need to separately do a "Sketch Data Upload". Arduino will then upload all the files in the "data" directory to the ESP. This takes quite a while, and only works if the Arduino Serial Monitor is switched OFF.. It is not smart enough to switch it Off by its-self.
  • If you ever change the SPIFFS size when re-programming the ESP, you will need to re-upload files to the SPIFFS.
    • (This is important because I started programming using "3M SPIFFS", but changed to "2M SPIFFS" around version 15 to give more room for the main program)[*]
  • When you want to change or update the stored Wav files, you can use a FTP program like Filezilla, and just do drag and drop. This can be incredibly useful to change sound effects.

Programming using OTA

Once they have been programmed once via the serial port, the nodes can be updated by Arduino using OTA (Over the Air) wireless programming.\ To do this you must know the node IP address. Then, in Arduino, in "tools": port", select the node you wish to update.
Then proceed with Sketch:upload as you would if the node was connected physically.

Known Limitation

I have noticed that the Node may need to be powered down and then re-powered after an OTA upload.
Because the MQTT find broker code blocks all other operations, the Node should be successfully connected to a MQTT broker before the update can be undertaken. Also note that, depending on what #defines you have used, after updating, you may still need to physically connect to the node to set SSID and Passwords etc. - But the update should not affect the saved values, so in general, if the code worked before you updated, it should do so again afterwards.


Direct Write using Binary Files

It is possible to directly write a compiled Binary file to an ESP 8266 without using Arduino. For the ESP8266, you can use the NodeMCU Firmware Programmer. https://github.com/nodemcu/nodemcu-flasher

  • If you use this, make sure you do not have any other programs opening the com port (like arduino monitor).
  • Set the com port by typing COM4 in the Com Port tab (the pull down does not work).
  • Copy the Binary you need from the Github and save it (make sure it is the ESP8266/nodemcu version)
  • In the Programmer, select the file (wherever you saved it), set "offset" to 0.
  • Deselect the "INTERNAL: NODEMCU" test program
  • Press flash.
  • RESET the Node manually after programming.

You Will still need to upload the SPIFFS data files to the hardware (or have already uploaded them)

users/dagnall53/node_programming.txt · Last modified: 2019/03/27 12:26 by dagnall53