1 / 9
Modifications for "Remote compatible with Lego Duplo Train using ESP32" — zdjęcie 1
1 / 9

Modifications for "Remote compatible with Lego Duplo Train using ESP32"

Zamów wydruk tego modelu

Obliczymy ostateczną cenę na podstawie wybranego pliku. Sprawdzisz ją i zaakceptujesz przed płatnością.

Zapisane na tym urządzeniu.

Informacje o modelu

Źródło
Printables
Kategoria
Building Toys
Licencja
Creative Commons — Attribution — Noncommercial — Share Alike

Follow instructions of the original post. Changes are described here:

It is recommended to use M2 inserts with 3.5mm diameter for mounting the top plate, the button holder and the throttle stick holder. 3.2mm is too lose. 

I used M2.5 inserts with 3.5mm diameter for mounting the PCB and M3 inserts with 5mm diameter for the hanger loops.

The USB panel jack is soldered to GND (black wire) and the 5V (red wire) which is connected to the 5V of the original USB jack and pin 5 of the TP5400 charger IC on the PCB. Bought from Amazon: https://www.amazon.de/RUNCCI-YUN-wasserdichte-Typ-C-Buchse%EF%BC%8CUSB-C-Buchse-Panelmontage-mit-Muttern-Sicherungsplatte/dp/B0CDC1X4BY/ref=sr_1_5

I ordered the ESP32 with 18650 Battery holder (ESP-Wroom-ESP32) from AliExpress.

ANSMANN 18650 Li-Ion accu with 4x protection (1307-0001) was used for safety reasons which just fits in the holder.

I already had a bag (without label) of Push Buttons 12x12x7.3mm with two pins on the bottom, so I modified the button holder accordingly. In the end I still needed some washers to place the holder further away so that the buttons were working. To close the gap between the button caps and the top plate I printed 4 button rings (see STL).

The panel hole size for the power switch is still 18x11.5mm as in the original file.

I needed to modify the ADC raw values for the throttle stick in the code. Activate the serial monitor output in the code (Serial.println(ptiSpeed);) to get the new values. The values are only outputed with a train connected. And remember that the train stops after a second if the color sensor is pointing in the air. This fooled me several times while testing.

Software hints:

Create project from platform.ini.

platform.ini

  • with these lib versions it worked (especially NimBLE V1.4.2 (V1.4.3 did not work))
  • adapt COM port to yours

--------------

[env:nodemcu-32s] 
platform= espressif32 
board= nodemcu-32s 
framework= arduino 
monitor_speed= 115200 
lib_extra_dirs= ${workspacedir}/lib/legoino-master 
lib_deps= 
    h2zero/NimBLE-Arduino@^1.4.2 
    thomasfredericks/Bounce2@^2.72 
lib_ldf_mode= chain+ 
upload_port= com7

=========================================

 

main.cpp (just the changed parts)

  • I changed the AIN port to 12 to use the pin next to the buttons
  • I used serial output to adapt the raw values of the potentiometer
    • uncomment Serial.println(ptiSpeed);// only for inital setup
    • serial output and programming does not work over the exposed charging USB port in my design

-----------

#define PTI_SPEED 12 //15

//…

voidhandlePoti() 
{ 
  intptiSpeed=analogRead(PTI_SPEED); 
  gLastStatePtiSpeed=ptiSpeed; 
  Serial.println(ptiSpeed);// only for inital setup 
  intspeed=0; 
  // my raw settings 
  if( ptiSpeed>2400) speed=64; 
  //Fast foreward 
  elseif(ptiSpeed>2100) speed=32; //normal foreward 
  elseif(ptiSpeed>1900) speed=16; //slow foreward (might not work on low battery) 
  elseif(ptiSpeed>1550) speed=0;  //stop 
  elseif(ptiSpeed>1300) speed=-32;//slow backward 
  elsespeed=-64;                     //fast backward 
  /* 
  // Original 
  if ( ptiSpeed > 1100) speed = 64;     //Fast foreward 
  else if (ptiSpeed > 800) speed = 32;  //normal foreward 
  else if (ptiSpeed > 600) speed = 16;  //slow foreward (might not work on low battery) 
  else if (ptiSpeed > 400) speed = 0;   //stop 
  else if (ptiSpeed > 200) speed = -32; //slow backward 
  else speed = -64;                     //fast backward 
  */

 //…