THIS IS THE TEST SITE OF EUROBRICKS!
-
Powered Up Hub emulator with ESP32
Smotek7 replied to GianCann's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingThis is probably my latest version. It's just a modified example, I don't have a description there. I think only 4 outings can be made. It's a limited Lego app. Only add more pieces of ESP2, it can be distinguished in the app. #include "Lpf2HubEmulation.h" #include "PowerFunctions.h" #include "LegoinoCommon.h" #include <Servo.h> // create a hub instance Lpf2HubEmulation myEmulatedHub("CONTROL_PLUS_HUB", HubType::CONTROL_PLUS_HUB); //Lpf2HubEmulation myEmulatedHub("TrainHub", HubType::CONTROL_PLUS_HUB); // create a power functions instance (IR LED on Pin 12, IR Channel 0) //PowerFunctions pf(12, 0); static const int servoPin = 4; Servo servo1; Servo servo2; Servo servo3; Servo servo4; int Hod; void writeValueCallback(byte port, byte value) { Serial.print("writeValueCallback: "); Serial.print(" PORT: "); Serial.print(port); Serial.print(" Hod: "); Serial.print(value); Serial.println(" ----------------------------"); if (value < 101) { Hod = value * 0.9; Hod = Hod + 90; } if (value > 150) { Hod = value - 256; Hod = Hod * 0.9; Hod = Hod + 90; } if (value == 127) { Hod = 90; } if (port == 0x00) { //pf.single_pwm(PowerFunctionsPort::RED, pf.speedToPwm(value)); Serial.print("motor A "); Serial.print("Value: "); Serial.print(value); Serial.print(" Hod: "); Serial.println(Hod); servo1.write(Hod); } if (port == 0x01) { // pf.single_pwm(PowerFunctionsPort::BLUE, pf.speedToPwm(value)); Serial.print("motor B "); Serial.print("Value: "); Serial.print(value); Serial.print(" Hod: "); Serial.println(Hod); servo2.write(Hod); } if (port == 0x02) { // pf.single_pwm(PowerFunctionsPort::RED, pf.speedToPwm(value)); Serial.print("motor C "); Serial.print("Value: "); Serial.print(value); Serial.print(" Hod: "); Serial.println(Hod); servo3.write(Hod); } if (port == 0x03) { // pf.single_pwm(PowerFunctionsPort::RED, pf.speedToPwm(value)); Serial.print("motor D "); Serial.print("Value: "); Serial.print(value); Serial.print(" Hod: "); Serial.println(Hod); servo4.write(Hod); } if (port == 0x32) { Serial.print("Hub LED command received with color: "); Serial.println(LegoinoCommon::ColorStringFromColor(value).c_str()); } } void setup() { Serial.begin(115200); // define the callback function if a write message event on the characteristic occurs myEmulatedHub.setWritePortCallback(&writeValueCallback); myEmulatedHub.start(); servo1.attach(13); servo2.attach(14); servo3.attach(4); servo4.attach(15); } // main loop void loop() { // if an app is connected, attach some devices on the ports to signalize // the app that values could be received/written to that ports if (myEmulatedHub.isConnected && !myEmulatedHub.isPortInitialized) { delay(1000); myEmulatedHub.isPortInitialized = true; delay(1000); myEmulatedHub.attachDevice((byte)ControlPlusHubPort::A, DeviceType::TRAIN_MOTOR); delay(1000); myEmulatedHub.attachDevice((byte)ControlPlusHubPort::B, DeviceType::TRAIN_MOTOR); delay(1000); myEmulatedHub.attachDevice((byte)ControlPlusHubPort::C, DeviceType::TRAIN_MOTOR); delay(1000); myEmulatedHub.attachDevice((byte)ControlPlusHubPort::D, DeviceType::TRAIN_MOTOR); delay(1000); myEmulatedHub.attachDevice((byte)ControlPlusHubPort::LED, DeviceType::HUB_LED); delay(1000); } } // End of loop
-
Powered Up Hub emulator with ESP32
Smotek7 replied to GianCann's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingToday I created a prototype HW for LEGO servo HUB. 4 output ports for RC servo. Just wait for the SW modification.
-
Powered Up Hub emulator with ESP32
Smotek7 replied to GianCann's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingSo far, like this, one port.
-
Powered Up Hub emulator with ESP32
Smotek7 replied to GianCann's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingHi @Lok24, i need HUB emulation. Today I managed to test legoino as a HUB emulation. It's what I need, it's just for City HUB as I understand it. I managed to control 1 piece of RC servo with LEGO app. PORT A doesn't work, I wrote on github. When I have something new, I will write. Rasto
-
Smotek7 started following Powered Up Hub emulator with ESP32
-
Powered Up Hub emulator with ESP32
Smotek7 replied to GianCann's post in a topic in LEGO Technic, Mindstorms, Model Team and Scale ModelingHello, I need advice. I want to create a train switch driver for my son. I want to control it using the Powered UP app. That's why I was looking for a way to emulate HUB. I want to use an RC servo for switching. @toastie Up in the post you write that you have an emulator in nodeMcu ESP32. I have this board. Can you please advise me how to edit the code so that I can upload the code to NodeMcu? I have Arduino IDE installed and ESP32 boards installed. My first step is to test NodeMcu communication with the Powered UP app. Thank you for any advice. Rasto
Sponsored Links