ESP32/RPI Adapter – Ground Plane Check

A trick I use is that I connect GND to the ground plane to avoid ground loops. But, what I need to watch out for is isolated icelands that is not connected. I realized that the EDA don’t check this, so I check it manually by using MSPaint to paint the ground plane. In this case it is ok as all areas used actually are connected to ground.

 

Model Train Control System – Part 4 Connectors

The illustration above show the number of connectors we could need on the Train Control System. I intend to use 1.25mm JST Micro connectors, but space is very limited so this will be a challenge.

  • #1 is the 6 pin programmer port. It is no way to get the programmer with USB connection on the controller so I create a 6 pin program port and a separate programmer board. The intention is to wire this up so we have access to the port below the train. Once this is coded we can also use the Wifi for updates. 
  • #2 is the 2 pin power port
  • #3 is the 2 pin Motor port. 
  • #4 is the 2 pin Super-Cap port. Super cap is like a small battery that will keep the system alive as we move over track gaps. 
  • #5 is the extension port to a 2nd controller board.

To optimize this I plan to reduce this to two connectors. One for Motor, Power and Super-Cap and a 2nd for Programming/Extension. I believe 2 connectors are doable, but I need to draw the packages and make a PCB layout before I actually know.

ESP32/RPI Adapter

This is an early mockup of a ESP32 based adapter for Raspberry PI. I like this early mock-up’s because they give me an idea about what we can get away with. in this case I can add 3-4 connectors top-left to get some extra IO, but I will still have plenty of space.

I need to connect and experiment with CAN and UART’s on ESP32 before I finalize this board. But, I do like this form-factor. I can probably also squeeze this down to a smaller format dropping the IO connectors.

I added 1 x CAN, 1xRS485 and 1xUART. The later is perfect for HMI etc. This will as mentioned work as a RPI Hat or stand-alone Wifi connector. The good thing about ESP32 is that it is still a decent, low cost breakout even if you do not use Bluetooth or Wifi.

Raspberry PI PLC Adapter

The release of Raspberry PI 3A+ is a good host for a mini level system due to it’s powerfully 4 x 64 bit CPU, but as the RPI itself do not contain any com connectors we need to use an adapter card. I decided to try ESP32 because that makes it dual purpose. ESP32 can act stand-alone using it’s own Wifi or just gateway to Raspberry PI for more power and to enable a RS232, RS485 and CAN port.

I use the GPIO and SPI port to communicate with Raspberry PI and CAN or RS485 for the rest of the network – or I just use the ESP32 as host for lower cost – depending on Application.

Raspberry PI PLC

This new addition to Raspberry PI is interesting. I have a few hat’s laying around and the form factor is a bit larger than what I recently plan for a modular PLC, but it is not horrible.

In fact, this is what I started out with. All my Hat’s will fit onto a A+ making a PLC alike system. The reason I wanted to increase size was mostly space for galvanic isolation and connectors, but as I made the prototype I also realized this would be far to big for my usage. I is still very attractive to have a powerfully Linux computer as a module, thought I do admit that ESP32 is much better low cost wifi solution.

Raspberry PI have come a long way and it is actually only 2 weak sides of this design. (1) it’s IO is limited, and (2) it lack Flash booting. Booting from a SD or Micro SD makes it vulnerable for vibrations that we have a lot of in robotics.

I already have a 5 port Serial/CAN adapter for this, so I will brush the dust of that one regardless of what I do. Using this format is doable, and both RPI3A+ and RPI3B+ are great for heavier processing and larger HMI units.

Returning to Raspberry PI versus ESP32 versus STM32 my choice will probably be not to chose. I can use them all. I made a ES32 Zero clone and I can easily make a A+ clone that provide Wifi at a lower cost with a few IO options.

Model Train Control System – Part 3 Programmer

Part 3 of the Train Controller will go to a separate USB card we need to connect for initial programming of the ESP32. On this we connect GPIO0, ChipPU and the default UART. This is needed to program and develop the FW on ESP32.

The USB chip is a CH340G. Most other designs will use a FTDI chip, but you will not see a FTDI chip in any of my designs. That Scottish company bricked my 3D printer a few years back and I simply dot trust them + CH340G is low cost, well supported and always work.

This schematics is borrowed from the utility driver. I think I can use it “as is”, but I will add a separate 3.3V regulator to feed the ESP32 power from the USB while programming. This means I need a 6 pin programmer port with +3.3V, RX, TX, GPIO0,ChipPU and GND. I will make a micro JST on the board and maybe an optional connector board that can be available under the train so we can connect without direct access to the control system. This is because I need some flexibility around hiding parts of the system in small locomotimes.

 

Model Train Control System – Part 2 H-Bridge

The second part of the Train control system is it’s motor driver. This is based on a classic L9110 H-Bridge chip. This allows us to drive a 500mA DC motor in both direction and we regulate speed with PWM duty. We need to return to speed adjustments later but we will be using the PWM signals on the ESP32 for this purpose.

This is where I went wrong on my previous version as I connected M1A and M1B to Inpu only capable ports. I discovered the error later as I tested the utility driver.

R1 & R2 is pull up’s that in this case is needed so the motor don’t accidentally start as we power up. C4 is to clip away DC motor noise.

Model Train Control System – Part 1 PSU

It’s time to get my train controller right. Starting with the PSU.

The power feed for a model train is the rail track that on some old systems can be AC, but mostly is 12V DC. To cover both these i use a classic rectifier MB6S. This will allow the 12V to be connected any way we please.

The next step is a bit trickier because I need 3.3V. This is easy using SPX3819 that comes in SO23-5 format and cover 16V with 500mA out. Just make sure you use a 3.3V Version.

The tricky part is that we will lose power as the train move over track gaps. Some old model trains had weights to give the train mechanical energy, but I am adding a 0.33F supercap on the 3.3V. These are small and aand using a small JST micro Connector we can hide this somewhere on the Train. The supercap will not drive the model train, but it will keep the ESP32 alive about 0,5 sec while the PSU have a glitch in Power. Without this the ESP32 will stop while it reboots and reconnect on Wifi.

Micro PLC – New format

These are just drawings of my new Micro PLC formats. I am considering 20x50mm, 30x50mm and 50x50mm formats. This discussion started as I received my previous PLC bus design and realized the actual size of it. The reality is that I need things much, much smaller and having a big backbone bus is very expensive.

As I accidentally made some 20×50 boards and by pure accident stacked them together I also make the observation that it would be easy to actually use that format as I can fit a stack almost everywhere, But, ok – 20×50 is a bit tight, so maybe 30×50, 40×50 or 50×50? Or maybe all of them as per need?

The way I want to stack them is with a bus cable and connectors. This way I can create a stack or simply mount them Distributed.

SW4STM32 – Short Review

System Workshop for STM32 or ac6wb or SW4STM32 is an Eclipse based, free IDE supported by ST. I started using this a while ago and the great thing about this is that CubeMX generate start-up code, project and everything for this. It makes it ideal for doing initial testing and to get off ground fast.

One word about CubeMX is that you can download different versions of their library and some simply do not contain all files as Project are generated. So the projects don’t compile. You just have to find a version that works for you. Except for that it is great.

As for SW4STM32 the best I can say is that it works – it is ok. A decent editor, debugger is decent and it’s a all-in-one that allow you to write code, compile, debug, download it etc. It is all you need and it’s free and supported from CubeMX and ST.

Sometimes as I download SW4STM32 lock up and I basically have to stop it and start again. It is annoying, but I can live with that. Using SW4STM32 is an option and as CubeMX integrate middleware including FreeRTOS you really get off ground with your projects fast with a standard CMSIS based project.

Another annoying issue is that messages as you can’t connect to SWD can be confusing. I can often have a it of connection issues before I get started, while CoIDE always was straight up. But, this is mostly me being more used to CoIDE than SW4STM32.

As an embedded C/C++ developer I usually have 1 comment – where is the C++ support? SW4STM32 have a button that change your project to C++. And this is GCC toolchain, so it will support C++, but CubeMX generate C so you need to convert that manually. I have not bothered digging into that because my usage have been electronics testing so far.

The example above is for MC3X60 running the motor Trapzoidal. What I did was to grab a FreeRTOS task and just run in a loop with a delay between the steps. Took me around 5 minutes to have the motor running.

The main limitation in SW4STM32 is STM32 – it only support STM32 out of the Box.

The project organization is a bit dictated from CubeMX. I live with that for now, but I would recommend that you organize your own projects and even support multiple IDE’s or build tools. Don’t let an IDE rule your life.