Adding Wireless Connectivity to DCC++ Mega Base Station

LMSFan72 Jan 20, 2019

  1. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    I have an Arduino Mega with a Pololu motor shield that is currently directly connected to a RaspberryPi. I want to replace the direct connection and RaspberryPi with a wireless connection to a more powerful computer. I currently use the Mega because of its many available GPIO pins which I use to connect multiple loco detection sensors, point/switch position indicator sensors, etc..

    I have just successfully built an ESP32 base station which has convinced me wireless is the way to go. However, the ESP32 doesn't have the pins for each of my sensors (I use one pin per sensor plus a common ground).

    I understand I have some options:

    1. Just add the wireless by attaching an ESP8266 to the basestation (I don't know how yet)
    2. Use an ESP32 basestation but implement some sort of bus to reduce the pin requirements on the basestation
    3. Some other combination of the 2!

    As I mentioned I have no experience of setting up buses nor do I know how I would connect an ESP8266 to the Mega (I have one but it is not on a shield that fits an Arduino) and then update the basestation to use it.

    So, tackling option 1 first...

    a. Which pins do I need to connect between the Mega and the ESP8266. I have the "HiLetgo New Version ESP8266 NodeMCU LUA CP2102 ESP-12E":

    [​IMG]
    b. What project/sketch do I need to load to each board?

    Then, tackling 2:

    a. If I were to implement a bus would I be able to use my existing detection sensors? - they basically have a common ground and each has a single 5V high/low logic wire that I connect to the Arduino directly
    b. How difficult is it - any practical guides would be very helpful!

    Many Thanks
     
  2. Pieter

    Pieter TrainBoard Member

    152
    46
    10
  3. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Thanks Pieter I will take a look at that
     
  4. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
  5. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Thanks Mike

    If I understand this, then, I have to upload DCCpp_ESP to the ESP chip and DCCpp_Uno to the Mega. Is that correct?

    I just tried loading DCCpp_ESP to the ESP in Platform but it fails to compile due to the following missing libraries in the Platformio Registry:

    ESP826WiFi
    ESP8266mDNS
    ESPAsyncWebServer

    I have tried searching for these but they are not found. Am I missing something?

    Thanks
     
  6. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    You will need to update the platformio.ini to rename "ESPAsyncWebServer" to "ESP Async WebServer" (PIO renamed it at some point). The other two are provided by the ESP8266 arduino core code and PIO shouldn't have any issues with finding those. Also make sure it picks up the right version of ArduinoJson, it should be the 5.x version and not the 6.x version.
     
  7. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Thanks again. The rename cleared that one. Now, sorry to be a pain..... How do I check the version of ArduinoJson
     
  8. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    It should likely be picking up the 5.x version by default but you can force it to the last stable version in platformio.ini as "ArduinoJson@5.13.4" to be safe.
     
  9. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Still struggling here. This is the terminal output when I try to build:

    > Executing task: C:\Users\andre.DESKTOP-TLMQMS5\.platformio\penv\Scripts\platformio.exe run <
    Processing esp8266 (platform: https://github.com/platformio/platform-espressif8266.git#feature/stage; board: d1_mini; framework: arduino)
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Warning! Library `{'requirements': None, 'name': 'ESP8266WiFi'}` has not been found in PlatformIO Registry.
    You can ignore this message, if `{'requirements': None, 'name': 'ESP8266WiFi'}` is a built-in library (included in framework, SDK). E.g., SPI, Wire, etc.
    Warning! Library `{'requirements': None, 'name': 'ESP8266mDNS'}` has not been found in PlatformIO Registry.
    You can ignore this message, if `{'requirements': None, 'name': 'ESP8266mDNS'}` is a built-in library (included in framework, SDK). E.g., SPI, Wire, etc.
    LibraryManager: Installing id=721
    Unpacking [##########################----------] 72%
    Unpacking...
    Error: Traceback (most recent call last):
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\__main__.py", line 120, in main
    cli(None, None, None)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\core.py", line 700, in __call__
    return self.main(*args, **kwargs)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\core.py", line 680, in main
    rv = self.invoke(ctx)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\core.py", line 1027, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\core.py", line 508, in invoke
    return callback(*args, **kwargs)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\decorators.py", line 16, in new_func
    return f(get_current_context(), *args, **kwargs)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\commands\run.py", line 107, in cli
    result = (envname, ep.process())
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\commands\run.py", line 207, in process
    result = self._run()
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\commands\run.py", line 302, in _run
    self.verbose)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\commands\run.py", line 325, in _autoinstall_libdeps
    ctx.invoke(cmd_lib_install, libraries=[lib], silent=not verbose)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\core.py", line 508, in invoke
    return callback(*args, **kwargs)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context().obj, *args, **kwargs)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\commands\lib.py", line 103, in lib_install
    library, silent=silent, interactive=interactive, force=force)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\managers\lib.py", line 352, in install
    force=force)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\managers\package.py", line 723, in install
    pkg_dir = self._install_from_piorepo(name, requirements)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\managers\lib.py", line 213, in _install_from_piorepo
    if app.get_setting("enable_ssl") else dl_data['url'], requirements)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\managers\package.py", line 510, in _install_from_url
    self.unpack(dlpath, tmp_dir)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\managers\package.py", line 224, in unpack
    return fu.unpack(dest_dir, with_progress=False)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\unpacker.py", line 112, in unpack
    self._unpacker.extract_item(item, dest_dir)
    File "c:\users\andre.desktop-tlmqms5\.platformio\penv\lib\site-packages\platformio\unpacker.py", line 38, in extract_item
    self._afo.extract(item, dest_dir)
    File "C:\Users\andre.DESKTOP-TLMQMS5\.platformio\python27\Lib\tarfile.py", line 2118, in extract
    self._extract_member(tarinfo, os.path.join(path, tarinfo.name))
    File "C:\Users\andre.DESKTOP-TLMQMS5\.platformio\python27\Lib\tarfile.py", line 2194, in _extract_member
    self.makefile(tarinfo, targetpath)
    File "C:\Users\andre.DESKTOP-TLMQMS5\.platformio\python27\Lib\tarfile.py", line 2234, in makefile
    with bltn_open(targetpath, "wb") as target:
    IOError: [Errno 2] No such file or directory: 'c:\\Users\\andre.DESKTOP-TLMQMS5\\Downloads\\BaseStation-master\\BaseStation-master\\DCCpp_ESP\\.piolibdeps\\_tmp_installing-hf8gjz-package\\.\\examples\\Scheduler_example20_StatusRequest_LTS_WDT_Timeout_Object\\Scheduler_example20_StatusRequest_LTS_WDT_Timeout_Object.ino'
    ============================================================
    An unexpected error occurred. Further steps:
    * Verify that you have the latest version of PlatformIO using
    `pip install -U platformio` command
    * Try to find answer in FAQ Troubleshooting section
    https://docs.platformio.org/page/faq.html
    * Report this problem to the developers
    https://github.com/platformio/platformio-core/issues
    ============================================================
    The terminal process terminated with exit code: 1
     
  10. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    I also get this error:

    upload_2019-1-22_20-20-47.png
     
  11. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    It looks like the library didn't install correctly... I'd say try again or go into the platformio library manager (click on home then libraries) and try installing it from there. This is for the TaskScheduler library.

    As for the other error, not sure what that is coming from but it looks like you have two plugins providing intellisense. Which plugins do you have installed?
     
  12. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Well, I have tried it every way I can think of and no joy! If I use the command "platformio lib install "TaskScheduler" -f" I get the same error.

    As for plugins:

    upload_2019-1-22_21-0-20.png
     
  13. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    I'd suggest drop both of the Arduino plugins (they aren't really needed with PIO) and the same for "C++ Intellisense". The only plugins I have installed are C/C++ (third in your list), PlatformIO IDE and Python.

    As for the TaskScheduler issue, you might want to try moving the base station code out of your downloads folder in the event that maybe PIO has some limitation on path length (it wouldn't surprise me really). Perhaps c:\trains\BaseStation as a top level directory.
     
  14. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Thanks Mike. It does seem that path length was the issue. It now seems to build fine.
     
    Atani likes this.
  15. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    SO, I spoke too soon, it hadn't finished. I am now getting some different errors.

    Here is my platformio.ini

    [env:esp12e]
    platform = espressif8266
    board = esp12e
    framework = arduino
    lib_deps=
    ESP8266WiFi
    ESP8266mDNS
    ArduinoOTA
    ESPAsyncTCP@1.1.1
    ESP Async WebServer
    ArduinoJson@5.13.4
    TaskScheduler
    Hash
    SPIFFS

    Here are the errors:

    upload_2019-1-22_21-38-21.png
     
  16. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    try ESPAsyncTCP@1.2.0 instead of the old 1.1.1 version (there have been a couple releases since that version) ?
     
  17. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Great, that resolved it. Thanks Mike
     
    Atani likes this.
  18. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    ...and now the next step.. I am trying to determine the pin outs to use and how to connect the ESP8266 to the Mega. I have the NodeMCU ESP12E development board, with the pin-outs below:

    [​IMG]

    Is it as simple as:

    Arduino GND -> NodeMCU GND
    Arduino 3V3 -> NodeMCU Vin
    Arduino TX0 -> NodeMCU RXD0 (GPIO3)
    Arduino RX0 -> NodeMCU TXD0 (GPIO1)

    I had read that the ESP8266 may not be 5V tolerant so does that mean I need to do something different?

    Thanks again
     
    Atani likes this.
  19. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Yes, it is just that simple. And you are right on the 3.3v issue, you probably will want a 3.3V 5V Logic Level Converter (cheaply sourced online usually).

    Sent from my ONEPLUS A5010 using Tapatalk
     
  20. LMSFan72

    LMSFan72 TrainBoard Member

    118
    18
    9
    Terrific, thank you
     
    Atani likes this.

Share This Page