Seven Segment Digits in Python  - Page 1
Forum section: electronics / projects

author: Swaroop 21
author_rank: Regular Contributor
timestamp: November 28, 2024, 11:22:14 am
content: I am making a GUI for a external Power Supply which can be controlled via PC. I want the GUI to look like a Display of a Power Supply or a Multimeter for displaying Voltage and Current. It should look like Seven Segment or LCD Digits. Is there any Library, Font or link which may help me to replicate it in Python ?

author: mariush
author_rank: Super Contributor
timestamp: November 28, 2024, 11:27:00 am
content: Have a look onhttps://www.dafont.comCheck the LCD and Bitmap/Pixelart categoriesLCD :https://www.dafont.com/theme.php?cat=302Bitmap :https://www.dafont.com/bitmap.php

author: Swaroop 21
author_rank: Regular Contributor
timestamp: November 28, 2024, 11:57:51 am
content: Thank You!!! The LCD DS-Digital Font is the exact one. I will try to implement it.

author: brucehoult
author_rank: Super Contributor
timestamp: November 28, 2024, 12:34:13 pm
content: Quote from: Swaroop 21 on November 28, 2024, 11:57:51 amWhat's to implement? It's a TrueType font (well, four of them, including bold and italic and boldItalic) so you simply install it on you Mac/PC/Linux machine and in your code choose the font and ... print on the screen. In a text field or raw or whatever.Just like any other text.

author: Nominal Animal
author_rank: Super Contributor
timestamp: November 29, 2024, 01:46:57 am
content: Another approach is to draw the entire display in e.g. Inkscape, saving it as an SVG file, and then display it dynamically (showing and hiding elements as needed) using QtSvg (when using Qt for the UI). For Gtk+, you'll want to split the SVG file into components, and convert each one separately to Pixbufs, since it does not support direct SVG rendering (only conversion to pixbuf either directly, or via Rsvg). With slightly more work, if you limit to flat fills and no filters, you can convert the SVG to Canvas paint operations for "native" Gtk+ rendering (similar to the Gtk+ clock example).This is particularly useful if you want to duplicate the physical UI of the device, in a scaleable window (keeping aspect ratio, so padding either horizontally or vertically, but never both). Because SVG is a vector format, it stays sharp at all sizes and resolutions.The same can be done online, as a web page, if you have an IoT or HTTP(S) server with a WebSocket interface to the power supply. That server converts the native supply controls to a websocket interface, and the web page connects to the WebSocket, updating the user interface SVG properties to reflect the power supply state. (You can check outmy home pageto check if your browser would support that. All current ones do.) The same SVG UI can be used for the web page one as for the Qt one. WithPytjon websockets library, you can write that server in Python, even stand-alone.Example of simple five-digit "display" in SVG I just drew, all "LEDs" on:(Click to embiggen)One useful trick in Inkscape is to configureFile>Document Properties...so thatFormatunits arepx, andScaleis 1.000. TheViewboxthen tells you the displayed size in logical units (for maximum compatibility, keepXandYzero; thenWidthandHeightmatch the correspondingPageones). It will also then scale to the maximum available area while keeping the aspect ratio (circles as circles and squares as squares, not turning them into ellipses or rectangles). I heavily useGrids(another tab in the same window) to ensure precise alignment; stuff like typical 8-segment LED displays are very easy to construct. If you add normal text labels (silkscreen or fixed text), convert those to Paths, so that users do not need to have those fonts installed, and everyone sees the exact same visual interface.

author: brucehoult
author_rank: Super Contributor
timestamp: November 29, 2024, 02:54:14 am
content: Quote from: Nominal Animal on November 29, 2024, 01:46:57 amThe DS-DIGI.TTF already pointed to has the same properties, but includes a full charset in 24 KB. All major OSes support TTF.

author: Nominal Animal
author_rank: Super Contributor
timestamp: November 29, 2024, 04:36:31 am
content: Quote from: brucehoult on November 29, 2024, 02:54:14 amThat is true! So, if you like its digits, it's definitely the easiest option. You can also create or edit your own usingFontForgeand similar applications; I've even shown an example modification to DejaVu Sans Mono (the one used forteletypeand code blocks here) fortiming diagrams here, and describedherehow to convert such modified fonts to COFF/COFF2 format for web page use (the TTF+COFF2+COFF2 triplet basically quaranteeing the font will work in all browsers). That example is to "prove" that it is not difficult to do at all; drawing what you want is the "hard" part.I called the SVG one a different approach, because it allows one to duplicate the look-and-feel of the physical interface, using whatever shapes for the LED segments you want. And it doesn't take long to draw it in Inkscape, either; best starting point would be a photo taken directly in front, centered, perpendicular to the face plane, placed on a locked bottom layer in Inkscape that is deleted when complete, with segments and "silkscreen"/"printed" graphics drawn on top with other vector elements and then converted to paths.Code-wise it is also quite different. The segment font will use Label widgets, with the widget font specifically using the TrueType font local to the application –– I do believe it doesn't need to be installed as a system-wide font in Qt at least ––, but the content as ordinary text (or numbers and values converted to text); theming will be a bit tricky, as you want to specify the font, but let it be scaled according to the current theme and/or user settings. The SVG approach will use a graphics scene or canvas for the interface, a single widget (or a scene widget with many graphics sub-widgets), and no text, and will therefore not be affected by UI themes.Finally, the two are notexclusive, either. One can use both, even in the same application. To me, it is important that others are aware of the different possibilities in achieving the kind of user interface that works for them best. It was not my intention to dismiss the TrueType font approach at all; apologies if it seemed that way.

author: shabaz
author_rank: Frequent Contributor
timestamp: November 29, 2024, 04:46:12 am
content: Quote from: Swaroop 21 on November 28, 2024, 11:22:14 amWhy? Why not make it look something more readable (e.g. Keysight DMMs have a nice font).

author: Swaroop 21
author_rank: Regular Contributor
timestamp: November 30, 2024, 02:12:58 pm
content: Quote from: shabaz on November 29, 2024, 04:46:12 amNot much really, I just like this type of LCD / Seven Segment Digits. More like the Rigol DP832 Power Supply.

author: Swaroop 21
author_rank: Regular Contributor
timestamp: November 30, 2024, 02:22:56 pm
content: Quote from: Nominal Animal on November 29, 2024, 01:46:57 amThanks for giving your time !!I am not sure how much space this would take. My original Idea was this .exe should be portable and if it is possible then to fit it on a ESP32 or Rpi Pico or to have a SD card Externally (No space constrains then). So it doesn't matter in which PC or laptop I plug it in it would open a .exe and then I can control it via that GUI.I don't know how feasible this is though as it would probably require Good USB speeds not sure if ESP32 or Pi Pico could handle both USB and ADCs, GPIOs etc. Currently I am surfing the web to find similar thing.

author: Nominal Animal
author_rank: Super Contributor
timestamp: December 04, 2024, 05:07:53 am
content: With ESP32, you could omit Python altogether and create a web page (using HTML+CSS+JavaScript) that implements the interface. Then, the ESP32 acts as the web server –– either WiFi, or via USB ECM or RNDIS (seeExpressIf usb_dongle example) ––, and interfaces directly to the power supply device.The SVG file(s) themselves aren't large, and it can even be constructed dynamically from digit segment coordinates in JavaScript. ESP32 would serve the related static files (you can stuff everything into a single one, though), plus implement a WebSocket client (seeExpressIf ESP32 API reference) that talks to the JavaScript running on the user browser, to transfer commands and responses and events between the webpage JavaScript and the ESP32.Based on my experiments with all-in-one webpages with included SVG –– myhomepageis 21749 bytes, thefinite impulse response spectrumpage is 3072 bytes, theglyph selectionpage is 4208 bytes; these are all pages that work even locally, self-contained, in any browser ––, you might need something like 60kbytes to 120kbytes of static file storage, so depending on which ESP32 you pick, you may have enough built-in Flash available already.The question is, how exactly do you control the power supply?

author: Swaroop 21
author_rank: Regular Contributor
timestamp: December 07, 2024, 07:49:20 am
content: Quote from: Nominal Animal on December 04, 2024, 05:07:53 amI am trying build a prototype similar to that of Dave's uSupply. But instead of High Power I will be using it to power Breadboard Circuits. Currently the limitation is that I only have the 10W of a USB-A port. The reason to go with this instead of type C -PD is that, I would take it to my university where they have those very old Dell Workstations which I probably think would only have USB 2.0 or USB 3.0. However I am not only planning to have a power supply but also a inbuilt current meter (INA219 as the sensor but it wont work with separate grounds) and a few GPIOs.The power supply side of things is just 3 Individual channels (Non - Isolated) wont be a fully variable but instead have common preset voltages such as Ex. 1.8V, 3V3, 5V, 9V and 12V. and 200mA max current limit per Channel. (I would some how try to add variable current limit feature too if possible) but I want the basic to be sorted first.Currently I have a ESP32-WROOM 32D with 4MB Flash. The Idea of having a webpage is very good but there's a problem, I'll be using it in my Uni where they don't have WiFi Cards in their workstations. Maybe I can use one of those USB WiFi Dongle thingy. Hence USB would be nice !I found thishttps://github.com/nicokorn/STM32F4XX_RNDIS_DEMObut its on a STM32, is there any such library for ESP or Arduino ?

author: brucehoult
author_rank: Super Contributor
timestamp: December 07, 2024, 08:54:53 am
content: Quote from: Swaroop 21 on December 07, 2024, 07:49:20 amDid you miss the link in the above quote?

author: Nominal Animal
author_rank: Super Contributor
timestamp: December 07, 2024, 10:06:11 am
content: Quote from: Swaroop 21 on December 07, 2024, 07:49:20 amUSB 2.0 is limited to 500mA = 0.5A at 4.5V–5.5V, or about 2.5W.If you don't mind being limited to Chrome, Chromium, Edge, and Opera browsers, you could useWebUSB. All it requires is that your microcontroller has native USB, and not a USB-Serial bridge like FTDI chips as used on most Arduinos.Some microcontrollers, like dirt-cheapWCH CH32X035RISC-V MCU, do have USB-C PD support, so you could make a device capable of USB-C, falling back to USB 2.0. You could also use an ADuM3160 USB isolator, and one or more isolated DC-DC converters, to isolate the microcontroller from the computer and any supplies. One possibility would be to use multiple power-only USB A connectors, via isolated DC-DC converters, to exceed the 2.5W power limit of one port. (Then, if you have access to mains, you could use an USB wall wart to provide an additional typical 2.1A maximum, for the 10W power budget. The trick is to keep track of the grounds, and not assume the wall warts' GND/0V is at the same potential as the computer/USB GND is.)Metering is simple, since you basically only need an instrumentation amplifier and a suitable shunt resistor, and an ADC input. INA219 integrates all of these, providing an I²C interface. For power control, use a high-side switch: P-channel high-side MOSFET with gate pulled to supply via a high-value resistor, say 100k, and a logic-level MOSFET like BSS138 or NX138AKR to pull the gate to ground to enable the switch, its own gate connected to an I/O pin via a suitable peak current limiting resistor, say 1kΩ (or maybe 220Ω if you want to do PWM up to 100kHz or so).The interesting part is the filtering and noise reduction of the supplies. USB can be surprisingly noisy. (My own laptop audio circuits' bypass capacitors have aged so badly, that in a very quiet room I can nowhearwhenever my touch registers on the touchpads, as the related USB data transfers cause a regulartickingor droning sound.) Dave has a nice video about capacitance multipliers; that and CLC filter should do very well, if you use low-noise linear regulators for each of the output voltages. Note that you can then put the current measurementbeforethe regulator.Quote from: Swaroop 21 on December 07, 2024, 07:49:20 amYou could use an adjustable linear regulator, and a DAC to adjust the precise voltage. You can find many interesting threads here if you use the Search (keywords:DAC "linear regulator")Quote from: Swaroop 21 on December 07, 2024, 07:49:20 amWiFi? No, I meant you program the ESP32 to look like an USB WiFi dongle, except that it provides only a simple IPv4 stack. No WiFi needed.However, with a cheap USB WiFi dongle you could power the ESP32 from an USB wall wart, or better yet something like a laptop 19V supply (these tend to be properly grounded) with ample current. The ESP32 would not be directly connected to any computer at all – which kinda-sorta also reduces your liability if you're anything like I am, a butterfinger who occasionally shorts things that do not like to be shorted.For ESP32, take a look atEspressIf ESP-IDF Programming Guide, and especially theiresp-protocols GitHub repository, which includes even a WebSocket example (if you decide to go with an externally powered ESP32, and an USB WiFi dongle to connect to it from any computer).The ESP32 Wroom32D does not have USB support, so cannot support RNDIS/NCM/etc., and even WebUSB support will be, uh, questionable. (I'm not sure if WebUSB allows connection to an USB serial port.) The dev boards use an USB to serial bridge, so their USB connection is not native and will always look like a serial port to any host OS.I warmly recommend you don't take too large bites at once. Advance step by step.Even when writing code, that applies: make local changes, then recompile, check, test, and don't add any new code until everything you've written thus far works.Never, ever leave error checking for later.Document things as you go. Even a plain text file is okay; it doesn't need to be pretty. You will not remember any of the details half a year later, so writing them down is paramount for anything complex.What I'd do, is connect a couple of the GPIO pins of your Wroom32D module to LED cathodes, and their anodes to current-limiting resistors (say, 1k, 2.2k, 4.7k) connected to +3.3V or +5V supply. Then, get a cheap USB WiFi dongle –– my local store has a dozen different models to choose from in the below 15€ price range. Next, create a simple firmware for the Wroom32D to blink those LEDs, and make sure it works, when the Wroom32D is powered from a wall wart, and is not connected to any computer. After that, start looking at the EspressIf documentation, to implement a single-file web server and a WebSocket server. Create a simple page that allows you to click buttons to turn each LED on and off. I would also add a button to the Wroom32D (pulling a GPIO input pin to ground when pressed), so that you work out how to ensure interesting happenings on the Wroom32D cause stuff to happen on the page using WebSockets. Use WebSockets properly, with each end able to send events/messages at any point, instead of the web page actively polling for events: that polling generates LOTS of extra traffic, and just slows EVERYTHING down.When you get that working, that alone is something you can add to your portfolio/CV: it is very worthwhile experience in IoT land.Only after you get that working, should you advance towards controlling a complex power supply. Of course, you can –– and I definitely would –– develop the adjustable supply circuits in parallel, at the same time, but in a completely separate isolated project!I personally test everything I'm interested in separately, before attempting to combine them. That way, I can work in units I can completely understand, document,and test. The integration of the various parts is the final step, and at that point, I already know (have verified!) that the individual parts work. (I archive these tests, each one in their own directory, with a README file, any related documentation, some test cases, and the source code. I've gotthousandsof these by now. Some say I'm wasting my time; I love it, because not only do I have actual experience with some quite esoteric stuff, but it also helps me hone my problem-solving and design skills.) Pure win-win, in my opinion.

author: janoc
author_rank: Super Contributor
timestamp: December 07, 2024, 02:30:10 pm
content: Don't reinvent the wheel.If you are doing UI in Python, use something like PyQt or PySide Qt toolkit bindings and then you have QLCDNumber class right there:https://doc.qt.io/qt-6/qlcdnumber.html

author: Swaroop 21
author_rank: Regular Contributor
timestamp: December 08, 2024, 06:37:26 am
content: Quote from: brucehoult on December 07, 2024, 08:54:53 amSorry I missed it

author: Swaroop 21
author_rank: Regular Contributor
timestamp: December 08, 2024, 10:31:12 am
content: Quote from: Nominal Animal on December 07, 2024, 10:06:11 amThank You for Explaining in Detail !! I am new to these USB RNDIS/NCM Thingy, will have to learn more about it seems very interesting.I do have an External DC jack for more power but mostly I'll be using this to just power small circuits and uC from it hence I am not to worried about it. Thank you for your advice, I do the same I test things in parts.