Python coding

last updated: 2022-01-21

For Python coding see also the Python with Raspberry Pi tutorial (in German) or the Buses chapter of the sensors2bus tutorial (in English).

I can't guaranty a faultless project, so using the information is at one's own risk.

My first bigger Python project was a program to generate this website without JavaScript or PHP. Python is a really cool programming language and especially with modules like TKinter (GUI), NumPy, Pandas, Matplotlib or OpenCV. So here I will document some of my Python projects.

PYthon Simple HomePage CREATOR

I like a website without JavaScript or PHP. But to add new pages to my site took too much time. So I wrote a little Python program to simplify the task. For my pages I use Markdown which gives a very readable file, and helps to focus on the content.
The structure of the homepage is given by the directory tree. The names of the directories are also the names and links in menu and sidebar. A simple configuration file allows to change CSS properties like the font-size or background colour.
PYthon Simple HomePage CREATOR

Ping The Thing

Ping the Thing Ping The Thing is a simple Python script that checks if all your devices are connected to the net and is sending a mail if not.

OpenCV basics

As a reminder for me (and others :)) I will document here simple code snippets and functions of OpenCV. This will cover:

+ how tor read an image and show it
+ working with images (get dimensions, reduce size and write an image to a file, creating a copy, cropping (slicing),
 copying parts and setting pixels)
+ create an image and drawing with OpenCV
+ thresholding, filtering and working with masks
+ getting lines with cv.HoughLinesP() and finding circles with cv.HoughCircles()
OpenCV basics

Read an analogue gauge with OpenCV

pointers I needed a program to read pointer-type dials on an analogue gauge. To read the two pointers I used python 3 and opencv. Here you see the result:

Ecowitt to MQTT: Get the data from the weather station

My old weather station died. So I got a new one, this time with WiFi (instead of USB).
It's named WH3000 SE PRO. The station can upload the weather data to my own weather server using the ecowitt protocol. As I want to use the data in OpenHAB, I wrote a little Python script to parse the data and send it to my MQTT server.
ecowitt2mqtt

Drawing with matplotlib

lowpass For my tutorials and my webpage I need drawings. For this I like to use Inkscape, first because it is open source and second because it is performant. The Inkscape files (.svg) are vector graphics and are fully scalable. For circuits I use KiCad, also open source. KiCad plots to svg. For formulas I use KLatexFormula, exporting to svg. But to draw mathematical functions I needed a good solution exporting to svg, and I found that python 3 with the libraries numpy, matplotlib and sometimes scipy or pandas is a very good and cool solution. On this page I will toss some code snippets to remember them for later use.