GianCann

Powered Up Hub emulator with ESP32

Recommended Posts

Great! I just ordered the book on FreeRTOS from Elektror for the ESP32. Maybe I should order some ESP32 modules. On the other hand I might use your example to do the same using an nRF52 / SAMD21 combination.

Share this post


Link to post
Share on other sites

Hi @JopieK,

There is a lot of work to be do, starting from move the parsing of incoming message in the loop () function.

But for made some test, it work also if isn't so beautiful code :wink:

Share this post


Link to post
Share on other sites

Haha, I noticed, but the start is there. Code can always be improved. We plan to give our embedded systems students six Uncle Bob lectures, but I myself also struggle to get clean code and clean architecture in an embedded setting. Using FreeRTOS might help but I am also not at the point yet that I'm satisfied with my own typical code. E.g. in Swift it is much easier to do that than in C/C++.

Share this post


Link to post
Share on other sites

Take a mind that I'm an autodidact in the embedded development.
So, some thing can be made more better and efficient of how I made at this time.

I came from desktop/database programming...

Share this post


Link to post
Share on other sites

Same for me I only got normal formal (general) software engineering training. Believe me, 'normal' software engineering deals much more with the topics Martin hammers on. I started working at my current school (even though I worked in the same college for quite some years now) and even while we have some good programmers, they much more focus on the micro level than on the macro level of programming (I think both are important especially if we need to prepare undergraduate students for a solid embedded software engineering career). But on the other hand I also see gaps in the industry, some embedded companies e.g. already include CI/CD but most don't.

Share this post


Link to post
Share on other sites

Hi @GianCann

I'm more than impressed.

And never saw such a piece of HW.
To undertstand it properly:
- This is a complete ESP32 including display and touch sensor and BT?
- Including BLE ?
- it's ready to use ?
- it's about 10-15 €
- a programm can be stored permanetly ?
- only 5V needed ?
- a sensation ?

Thanks for answering "yes" to all my questions.

Share this post


Link to post
Share on other sites
7 minutes ago, Lok24 said:

This is a complete ESP32 including display and touch sensor and BT?

Yes. 5x5 RGB LED matrix, one button (the same "matrix" is clickable)

7 minutes ago, Lok24 said:

- Including BLE ?

ESP32 support WiFi, BT Classic and Bluetooth Low Energy.

7 minutes ago, Lok24 said:

it's ready to use ?

You only need to install the right board information (with Arduino board manager). The board has the USB Type-C connector with USB/serial interface. So, yes... I can answer that is ready to use ;)

7 minutes ago, Lok24 said:

it's about 10-15 

about 8$

7 minutes ago, Lok24 said:

a programm can be stored permanetly ?

Yes

8 minutes ago, Lok24 said:

only 5V needed ?

You can use 5 or 3.3v.

Share this post


Link to post
Share on other sites

Thanks a lot.

Sorry for such simple questions, just saw a video how to install micro-python on Mac or Windows.
And yes, there is the selction for something that might be the board...

Is it that what you meant?

What you did: let it act as a hub.

My idea is: act like the app, that means: connect to a hub and a handheld, and then the program could do nothing else but use the buttons and send motor commands to both parts, one in reverse, in 10 Steps, for every type of motor.  The classic train application.

Share this post


Link to post
Share on other sites
20 hours ago, JopieK said:

On the other hand I might use your example to do the same using an nRF52 / SAMD21 combination

Of course it is possible with a number of microcontrollers asl long as see support BLE at least to 4.1 spec. The pitfalls are more about the midleware/framework used. It depends o the way the advertsing mechanisms are implemented.For example the "ArduinoBLE" still having some issues about that, Adadfruit Bluefruit as well as BLE implementation for ESP Arduino packagage works fine so far,

All systems based on nRF52480 are always a good development base because you can:

 - use ArduinoBLE or Adafrui Bluefruit = Aduino Framework

 - use "MBED" if you like

or even use a "bare metal C" development system  like segger embedded studio ., and use NORDIC SDK from scretch if someone wants to dig deaper or in case that a "higer level" framework does not wok as expected Tip: Have a look The NORDIC nRF52840 Development Kit , it comes with integrated Segger Programmer that is available thru pin header for other NRF52840 boards in addition, like Arduino Nano 33 BLE (based on Nrf52840 too)) It also includes a non commercial licence for segger embedded studio full version, There are special firmware versions to use this board as debug tool in combination with nrf connect or even as a BLE Sniffer togeter with wireshark.

 

 

15 hours ago, Lok24 said:

And never saw such a piece of HW.

@Lok24 You may have a look at here in adition https://m5stack.com 

 

The "Atom" https://www.adafruit.com/product/4497 looks ike a feature reduced version of the "odinary" M5 Basis as shown here, https://www.adafruit.com/product/4177

It is also awailable witha set oc control faces: https://www.adafruit.com/product/4176

I prefer the M5 BAsis because it has a sdcard slot that may be usefull to implement a lean recoder/ player for poweredup json programms / Programes  as discussed on "1000 steine"

Tip: It is also available in a well known elceronic store with a capital "C" in its name, Here you can have a closer look if you have sucha store nearby your home.

In adition : If someone looks for a good ESP32 Hardware package to start with and does have any components so far this may be also an alternative;

https://www.hardkernel.com/shop/odroid-go/

https://wiki.odroid.com/odroid_go/odroid_go

Note: It comes as a kit and has to be assembled first (no soldering) as you can see on the product description.

 

 

 

 

Edited by ruppie

Share this post


Link to post
Share on other sites
19 hours ago, JopieK said:

t I'm satisfied with my own typical code.

You are right,that is the only thing that count's at the end of the day.

The most imporatnt lessons i have learned from  Mr. Robert C. Martin during his "Clean code lectures and by reading his book".

1. Software a software paradigm, method rule, always is an idea advise, working guide of someone he wanted to share. It never is alaw or religion. You may follow or not it is up to you .                                                                                        2. No one else, except the devloper can make the decision what is right or wrong because he (typically)  is the only one who knows all the deatils why code is made in this specific way.                                                                                            3. Software architecture never is a religion (even if some discussions may loo like) ;-)

Conclusion: Software quality is measured by the international unit :WTF/M = "What the megabluck per Minute".  It does not depend on any programming style or paradigm ;-) 

Note: Microcontroller programming only is a hobby i am a self didact in this field, too 

Share this post


Link to post
Share on other sites

I just finished programming the headlights of my 10277 Croc using an Attiny1616 and put the Eagle files and Arduino code on GitHub: https://github.com/jakorten/10277_lights/.

B.t.w. That is part of the fortunates of being a software teacher, we can 'enforce' such a rules at least to some point ;) A colleague of mine uses the MBED with Keil in his advanced microcontroller course. We might go for the SAMD21 or something in our introduction course, now we are still using the Atmega328 (Xplained Mini) with Atmel Studio and the latter is obsolete. We let the students do everything themselves though, no Arduino allowed (although we allow it in higher year courses though). 

Share this post


Link to post
Share on other sites
22 hours ago, Lok24 said:

But: which board to choose for the M5Stack Atom Matrix?

I used a € 8,50 ESP32 nodeMCU dev board from JoyIt - works like a charm with the Arduino IDE + and the required additional things installed + legoino.

This thing is unbelievable powerful - when comparing to e.g. an Arduino Uno. Which is no surprise of course.

As well is legoino.

All the best,
Thorsten

P.S.: The legoino header files define WHITE as a color for the built-in hub LED. This may interfere with other include files, e.g. Adafruit OLED display handlers, which used WHITE as alias for "drawing" color as well. I just renamed it to HubWHITE. (Etc.)

 

Edited by Toastie

Share this post


Link to post
Share on other sites

Hi,

I think you missunderstood my question :classic:
I use the  "M5Stack Atom Matrix" .

But I have to choose via "Board Manager" in IDE the correct board for this product... which one?

Share this post


Link to post
Share on other sites
7 hours ago, Lok24 said:

M5Stack Atom Matrix

I am very sorry!

(I am more into the dev type boards - so many GPIO pins ... it fits my purposes better, I guess. The Atom Matrix looks very slick and cool though!)

Best,
Thorsten

Share this post


Link to post
Share on other sites

Hi Thorsten,

my idea is just to replace the SmartDevice by another piece of HW without soldering or something else.

 

 

 

Share this post


Link to post
Share on other sites
1 hour ago, Lok24 said:

replace the SmartDevice

and that is soo nice! For some reason, I can't get into using a tablet/cell phone for controlling PoweredUp devices. My fault, but it is what it is.

Plus: With the small BLE equipped controllers and their cost of < 10 € (the small dev boards that is) one of them can be used to control one Pup device at minimal cost. Plus the multiple connectivity problem(s) becomes obsolete. I'd rather have 10

I am just now making a small thingy with for push buttons (manual/auto control) and a very small OLED display to control my Crocodile simply running back and forth - with acceleration and deceleration periods, which are in turn fired by 4 IR b/w detectors. The Croc was 100 €, the electronics stuff in total 25 € ...

Good luck on your project(s)!!!

Best
Thorsten 

Share this post


Link to post
Share on other sites
On 8/19/2020 at 10:36 AM, Toastie said:

which are in turn fired by 4 IR b/w detectors. The Croc was 100 €, the electronics stuff in total 25 € ...

Best
Thorsten 

Hello Thorten,

and  qauestion of interest about your project; why you are uing 4 IR detectors ?

Marc

Share this post


Link to post
Share on other sites

Hi Marc,

well, the Crocodile locomotive (#10277) is relatively "packed". And this is the engine I'd like to control with a 2I/O hub and NO smart device:pir-thumb: - but rather an ESP32 dev board. Plus the track stretch the Croc will run on is rather "lofty" and I need some safety measures to not crash it (https://www.eurobricks.com/forum/index.php?/forums/topic/179240-mod-10277-and-on-and-on-another-crocodile-mod-%E2%80%A6/), as this would most probably cause severe damage :pir-sick:.

So I can't think of installing e.g. a color sensor on the Croc without compromising its beautiful design too much. In turn, I am planning on having (well, I have, but blew one:pir-murder:) 4 b/w sensors (actually these are line tracking sensors; e.g., https://eckstein-shop.de/TCRT5000-IR-Barrier-Line-Track-sensor-Infrared-Reflective-Photoelectric-Switch). They are residing between the PF/9V track sleepers looking upward. The loco has a white plate (https://www.bricklink.com/v2/catalog/catalogitem.page?P=2654#T=C) on the cabin frame, facing downward.

The program on the ESP32 lets you locate the right end sensor (#1), then you can start the sequence: Accelerate to full speed. Sensor #3 (left) causes the Croc to decelerate and then slowly move on to the left stop sensor #4. When that is triggered, the Croc stops, waits, reverses and accelerates again toward right. Sensor right (#2) causes deceleration, sensor right stop (#1) stops the Croc, waits, reverses and so on ...

Yes, you can do that with timing and only two stop sensors. But that may accumulate temporal errors over several sequences. And: I like to play around ...

The whole thing works, is in the workshop.Will post in 2 weeks; as said blew a sensor and they have a delivery delay.

All the best,
Thorsten

 

Edited by Toastie

Share this post


Link to post
Share on other sites

Hello,
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

Share this post


Link to post
Share on other sites

Hi Rasto,

I am a bit confused. I am using the ESP32 as a client for the Hub as server. The ESP32 is directly talking to the Hub. I believe there is a way to connect to the LEGO app as well, but folks as @Lok24 do know much more about that!
As far as I have any minute knowledge, it would be to test communication of the ESP32 with a Hub.

Sorry for that.

And good luck on your project!!!

Best
Thorsten

(BTW: When you hit the @button and then further keys, select the user-name entry you target from the drop down list provided. Then the user selected gets a notification right away, even when not following a particular thread)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.