UDP is an excellent protocol for sending messages between nodes in a system with Ethernet or Wifi. It’s speed and behavior on a modern PC’s allows in the region of 100,000 messages per sec, which should be sufficient for most applications.To make a Connection you only need two end-Points of which one need to have a known (fixed) address so the other cand send to it. The receiver get the sender address so it can send back. Sending is also fire & forget as UDP will send regardless wherever the receiver is there or not.

To create a client/server is equally simple. You simple create one client on a fixed address and the the others can contact this.

The true power of UDP is however that it is a “mail-box” on Ethernet that anyone can send to. You can send to any UDP port and receive from any UDP port. UDP bind to the local ip-address and port you use for sending, but it is connectionless so it’s not affected if the receiver drops down, reconnect or simply is not there.

easyUDP is only a thin wrapper on top of UDP to provide a standard, easy, event driven interface. To use the interface you need to do 3 Things

  1. Decide what socket to use and Open the connection. This can be fixed or you can let the computers UDP stack decide automatically. To send a message somewhere you need to know that address, so at least one of the end-points in a UDP connection need a kown address. Address here is ip-address and port number. One concern on modern networks is firewalls as the ports must be opened through firewalls.
  2. Send messages. One UDP connection can send to multiple other UDP connections by setting remote ip-address and port. But, sending here is fire & forget. UDP will send the message intact, but it gives no guarantee that anyone receive the message or what sequence messages arrives in. Sequence will be intact on a single network, but on a more complex network you might experience that packages uses different paths and arrive in a different order. Your protocol using UDP need to handle this.
  3. Receive messages. The technique I use it to establish a reader thread that call back for every message received. As you receive you also need to grab the sender address so you know where to respond back to.

UDP is very lightweight and you need to add you own protocol to maintain sequence and ack messages etc. But, UDP will maintain message integrity since the packet you send is 1:1 with what is received on the other side. The lower interface of easyUDP is different from platform to platform. I currently use a test implementation in C# on Windows that obviously will have only design and interface in common with one in C++ or one on a STM32. UDP/TCP already have a “standard” socket interface, but easyUDP uses a simpler approach of Open(), Close(), Send() and OnMessage().

UDP packets consist of UDP + IP Header + payload. easyUDP will in addition add it’s own little header to support streams. Basically we pack multiple easyIPC messages into the same UDP packet using the standard easyIPC format per Message.

easyIPC Stack

easyIPC is the protocol and collection libraries I use to communicate cross various networks. easyIPC is not bound to a special technology as it provides universal device to device access through a variety of technologies including Ethernet/Wife, RS485, CAN, and SPI and in time others.

UDP, SPI, UART and CAN are examples of technologies I use and they all require a different lower protocol to take advantage of the underlying bus architecture. This is dealt with in AL (Abstraction Layer). UDP (as an example) will have a generic UDP interface, but the one I am interested in here is easyUDP and accordingly easySPI, easySerial and easyCAN. These layers are specially adapted to the easyIPC concept and each module has an identical interface so we don’t need to care about the underlying bus/stack complexity.

The concept is simple – we connect, send and receive messages as if everything is local using a common addressing scheme. Only the sender and receiver need to understand the messages. Message sequences are dealt with in easyIPC or user modules. Lets briefly discuss the technologies and why they are on this list.

easySPI We use a control system composed of Raspberry PI and multiple STM32F405 MCU using high speed Half Duplex SPI as the backbone bus. This gives a speed of 30-42Mbps which in reality makes it very comparable to a 100Mbps Ethernet.
easyI2C This is the same as easySPI using I2C bus. This is currently not supported.
easySerial Using RS485 or RS232 as bus. RS485 implement the TDM bus. Specially RS485 is well suited for distributed control systems as it covers up to 1km wired and as such allows a none-wireless interface to fixed locations.
easyCAN Using CAN as bus.
easyUDP Allows Ethernet and Wifi using the UDP protocol as carrier.
easyBluetooth Allows IPC over Bluetooth.
easyLoRa Allows IPC over LoRa Technologies. Long Range radio allowing up to 12km coverage.
easyNBIoT Allows IPC over NB IoT Technologies. This is basically a low cost phone line allowing you to communicate in all areas With GSM,3G,4G, 5G etc.
easyShockburst Allows 2.4Ghz Shockburst as IPC. Max range is 100 meters, but it is an awesome Wireless protocol With bandwidth up to 2Mbps.



RS485 Hub 3D draft

First 3D draft of the RS485 Hub. I have moved all connectors to left and top because it will be attractive to use this together with RPI 3B+ that have Ethernet/USB at right. As mentioned I could have used XPortHub for this, but I often need exactly RS485/Ethernet in higher density because RS485 is very attractive connecting to small, remote sensors/actuators. The drawback With what I do here is lack of galvanic isolation, but I will add a separate Hat for that purpose later. In an ideal world we would add galvanic isolation everywhere, but it comes at a huge size and performance cost (slower Serials), so it makes more sense to add isolation between nodes or then connecting to long wires or special Equipment.

  1. CAN Port 1
  2. CAN Port 2
  3. RS485 port 1
  4. RS485 port 2
  5. RS485 port 3
  6. SWD port
  7. RS485 port 4
  8. RS485 port 5
  9. RS485 port 6
  10. USB port
  11. Power Connector 5 external Power.
  12. 3.3V PSU
  13. Status Led’s – I admit I went a bit over the top here With 1 status for each RS485 and CAN. 
  14. 8 or 16Mhz Murata x-tal with capacitors.
  15. Serial Flash. I just added this because I had a spare SPI port.
  16. MCU
  17. RPI Connector. I basically use 5V and SPI pins on this Connector.
  18. Terminator jumper

The actual board will probably change a bit. I like doing these mock-up’s placing connectors and components, but as I start routing I also end up changing things to adapt. Schematics is done, so it will take me a few mornings to get routing done. I find PCB routing to be a relaxing mind game – so yes – this is my form for relaxing.

You probably feel the site have slowed down a bit, and yes it has. To much happening Real Life at the moment so it will be a bit like this for a while. It is also a consequence of me digging deeper into SW as I have an large backlog of things I need to code up.

RS485 Hub

XPortHub is great if you need a combination of ports, but I often need a high density of one port type so I made RS485Hub with 6 x RS485 ports, 2 x CAN ports and 1 x USB.

This is basically a simple Hat where I take advantage of the high number of RS485 ports on F405. The 2xCAN is added because they are available.

AL – Abstraction Layer

The main objective with an Abstraction Layer is to protect user modules from changes between platforms. Code on user level should be portable and plug & play after you done a 10 minute task of soft-wiring. I decided on the name “Abtraction Layer” because HAL (Hardware Abstraction Layer) is missued to much and was not a good fit.

The figure above illustrate what I want to achieve. The interface on AL should be identical, while we know that each AL module will need to be specially adapted to the technology in usage. In this case I will point out that easyIPC’s version of SPI is not a generic SPI interface. The easyIPC version is a TDM protocol that needs to be tightly integrated with hardware.

Free Electricity – Windmill

I decided to try out a windmill costing ca 180.- USD that will arrive any day soon. It is quite windy here I live, so I should get a decent 500-1000W out of this and with a decent battery bank I should be able to drive a lot of out-door electricity – not connected to the grid. This is actually part of a larger project because I want to monitor the effect I get from this small windmill. It is 130cm in diameter, and I can hide quite a few of these in my garden if they give the expected effect.

We are offered contracts in this area meaning that you can sell electricity back to the power company. In my case I would save 120 ore (ca 0,20 USD) per KWH – so assuming this windmill generate between 500-1000W in average that is 8760 KWH per year. The actual rating is 1500W, but I hope for 500W in average which is 4380 KWH/year – so I could save from 500.- to 1000.- USD a year from an investment costing me 180.- USD. My yearly consumption is ca 20KWH, so that is 25% of my electricity bill. Basically with a few of these I could be selling electricity to the power company – what is not to like?

It is two numbers that I need – one is the average effect I get out of this windmill and two is the noise-levels. The windmill is stated to be noiseless, so lets see – or more correctly hear! The later is important because I can get away with a noiseless windmill, but if this generate noise the project is dead. To put up several of these I will need to get permission.

Yet Another 3D Printer

I feel bad about my 300.- USD 3D Printer collecting dust in my lab, so I want to do something about it. This was a Prusa i3 Gen 1 clone and it ha loads of issues that came with Gen 1 printers – that said, it actually work and do a decent job for what it is.

The control system is Atmega2560 based (Arduino) and does it’s job. The advantage of this is the wealth of open source alternatives running G-Code. The drawback is that the control system is “all in one board”, meaning it is hard to expand and experiment with, so I want to replace this with a modular and more capable one.

The block diagram above illustrate a possible system. The core here is that I use my RPI modules to create a modular control system.

Current slicer SW mostly operate through Serial USB and XPortHub is excellent as G-Code Server – it has USB, Flash/SD-Card, HMI port and can drive the rest of the CNC machinery.

I could have done G-Code from raspberry PI as well, but suggest that RPI is optional for Wifi/Ethernet and print spooling.

To control stepper motors I use 2 of my 12xPWM cards that can drive 4 steppers each. The 2nd card drives 2 steppers and PWM channels for heat. Each channel support 2A, but keep in mind that I can combine channels and add a 3rd board if I need to.

The last board is a 32xIO Hat to connect to analogue sensors and digital sensors.

But, what do I want to achieve? I am obviously interested in building this as a test-case for my control system, but I also have some objectives.

  • Rebuild the mechanics into a more robust printer.
  • Insert mechanical end-stops and use current sensors to detect them to avoid a lot of wires and failing detectors.
  • Add Z-sensor to automatically detect plate tilting.
  • Add a 2nd extruder for support material.



3KW 3-Phase Motor Controller Rev 1.2

It’s been a while since I designed this 3KW 3-Phase Motor Controller without doing anything with it so I decided to give it an upgrade. The size of this is 100x25mm. It is very smal for it’s capacity and Perfect for larger drones.

  • Removed 3rd current sensor.
  • Remove the output holes at right and take the output directly from between the MOSFET’s.
  • Added 2 temperature sensor.
  • Modify power input so one wire comes at top and one at bottom. This enables me to easier mount the capacitor directly on the wires.
  • Strengthen power paths to support 50A++. The MOSFET is capable of 160A and 400A phase currents, so it is all about heat dissipation and current paths.
  • Removed some electronic filters replacing them with SW.

This design is very different to the 4 channel version due to it’s DRV8301 that contains DC/DC, Gate Drivers and current amplifiers. From a functional perspective it is less capable, but it is also much smaller size.

It is also perfect for running the outrunner above. I really liked this motor (power, size, cost), so I might buy a few more to create a drone.

Raster Graphics Integer Errors

A common problem with plotting lines in raster graphics is visualization errors as we display the graphics. Most times we can just ignore these, but as I am drawing scrolling real-time plots I also receive the side effect of an integer error.

This show a line that due to integer rounding is a straight line in the left plot, cover two pixel rows in the second before it is straight again in the third. As you move this over the screen it don’t look good or smooth at all.

The solution is quite simple – the error comes because you calculate x/y from double or float. Depending on position the conversion to pixel xy end up different as a line moves – so you can pre-compute a x and scroll this by adding/subtracting offset. The concept is that integer errors stay constant and your line looks like is moves more smoothly – no jumping between positions.

C++ vs C# Performance – Part 1

I have so far never seen a performance test where C/C++ did not win an easy victory due to it’s nature, but I am very curious about what I see in front of me now. The failure I pointed out earlier is how .NET or Windows behave then you push it to it’s limits, but the plot above is still 10 x Oscilloscope level plots at 27 FPS on a 1980xx1080 screen. That is Heavy raster Graphics behaving with video quality update – it is amazing to watch and open some usage opportunities that interest me.

Most developers will agree that raster graphics like .NET Forms is not the way to develop heavy graphics applications these days, but it still have some good usage schenarios and I like to test boundaries for my own education. In this case I will spend a little time and do the exact same plot in Qt and C++/MFC to compare 1:1 + I have a few bits of code that I have written in C++ and converted to C# so they can be used for comparisons as well.

So will C/C++ win an easy performance victory yet again? I expect it will, but the answer is not given. C/C++ compiles into static code while languages like C# compiles into a virtual machine’s assembly code and run on top of an interpreter called a “Virtual Machine”. Java uses Java VM, while C# compiles to a format called “MSIL” and run on .NET. What you need to be aware of is that computers are not single cores anymore and these interpreters are getting smarter using various technologies. The VM’s might also have a better C/C++ library and better usage of multiple cores out of the Box and the interpreters on some of these VM’s do a JIT to native machine code.

I will state that you can always win a performance game using C/C++ if you are willing to spend the time, but the question is more and more what do you get straight out of the box? My expectations right now is that C# .NET 4.6.2 might very well outperform Qt and C++/MFC on 1:1 raster graphics, but it will still be far behind on algorithmic speed. In reality we will be comparing Qt, MFC’s and .NET’s implementations of C/C++ raster graphics libraries because guess what – .NET is still written in C/C++.

Stay tuned.