[{"content":"Introduction The BBC micro:bit is a tiny, powerful microcontroller that makes learning programming fun and accessible. By combining Python with Visual Studio Code (VS Code), you can write, test, and flash code to your micro:bit easily. In this guide, I\u0026rsquo;ll walk you through setting up a complete development environment so you can start creating projects in MicroPython, the Python variant that works on micro:bit.\nNote: micro:bit offers their own official editor for Python. Although it is easy to use, I recommend you set up VS Code as it is more customizable and provides additional features.\n1. Prerequisites Before diving into coding, you’ll need a few essentials:\nHardware\nA Windows or Mac computer A BBC micro:bit A USB cable (must support data transfer) A USB C to USB A adapter (only if your computer does not provide full-sized USB ports) If you don\u0026rsquo;t have a micro:bit, you can attain a kit here which includes all components to get started (including a USB cable).\nThis guide will cover setup for both Windows and macOS.\n2. Installing Python Windows Download Python from the official website.\nRun the installer and check Add Python to PATH when prompted.\nFollow the installation prompts and wait for completion.\nVerify installation in Command Prompt:\npython --version You should see something like Python 3.x.x.\nmacOS Open Terminal and check for Python:\npython3 --version Note: macOS sometimes ships with an older version of Python called Python 2. This version will not work, so if that version is installed, you will need to install the latest version of Python 3.\nIf this command does not work, download the latest installer from python.org and double click it to launch it. Follow the installation instructions.\nVerify installation:\npython3 --version 3. Installing Visual Studio Code Windows Download VS Code from code.visualstudio.com.\nRun the installer. Recommended options:\nAdd “Open with Code” to Explorer context menu Add VS Code to PATH Register VS Code as editor for supported file types Launch VS Code after installation.\nmacOS Download VS Code from code.visualstudio.com. Drag Visual Studio Code from Finder (the smiley blue and white icon) into Applications. Launch VS Code. 4. Installing VS Code Extensions Extensions add powerful features to VS Code for Python and micro:bit development.\nOpen VS Code and click Extensions (or use the keyboard shortcut Ctrl+Shift+X on Windows/Command+Shift+X on Mac).\nInstall the following extensions:\nSearch for the extension called Python (by Microsoft) and click Install. This extension provides a number of excellent Python-related functions. Search for Black Formatter (by Microsoft) and click Install. This extension will allow you to format your code to standard with a specific key combination (For Windows it is usually Shift + Alt + F. For Mac, it is typically Shift + Command + I) Search microbit (by Statped) and click Install. This extension will allow you to have micro:bit specific Python intellisense. 5. Installing uflash and black formatter uflash is a Python tool that flashes Python programs you develop to your micro:bit, copying the MicroPython runtime. We will install it. Additionally to complete setup, we will install the final command-line tool Black to make the Black Formatter extension work.\nInstall uflash and black Use the following steps depending on your computer type to install uflash and black. You may need to type y and then press the Enter key to confirm the installation:\nWindows\npip install uflash black macOS\npython3 -m pip install uflash black Verify Installation of uflash For Windows, use:\npython -m uflash --help For Mac, use:\npython3 -m uflash --help You should see usage instructions for uflash, confirming successful installation.\n6. Creating Your First Python micro:bit Project Create a Project Folder Create a new folder in your system\u0026rsquo;s file manager, e.g., microbit-project. Open VS Code and click on the File option located in the top menu bar. Select Open Folder in the menu that appears, navigating to the folder you just created. Now click the explorer button: Select the new file button which should appear if you hover over the space in the explorer drawer, and name it main.py: Open the file you just created in VS Code and enter the following program in VS Code\u0026rsquo;s text editor: from microbit import * while True: display.scroll(\u0026#34;Hello World!\u0026#34;) sleep(1000) 7. Flashing Code to the micro:bit Connect the micro:bit via USB.\nOpen VS Code\u0026rsquo;s terminal using Ctrl + Shift + Backtick (Ctrl+Shift+`)\nRun uflash in the VS Code terminal:\nFor Windows, use:\npython -m uflash main.py For Mac, use:\npython3 -m uflash main.py The micro:bit should appear as a USB drive and automatically update with the new code, displaying a message.\nTroubleshooting\nEnsure the USB cable you are using supports data transfer. If the micro:bit isn’t detected, try unplugging and reconnecting it. Restart VS Code and try again if flashing fails. 8. Debugging and Common Issues Python not recognized: Ensure Python is added to PATH (Only relevant to Windows users). If it isn\u0026rsquo;t, you can uninstall and reinstall Python, making sure to check Add Python to PATH during installation. uflash errors: Try reinstalling uflash with pip install --force-reinstall uflash (Windows) or python3 -m pip install --force-reinstall uflash (Mac). Micro:bit not appearing: Use a different USB port or cable if it is faulty. 9. Conclusion Congratulations! You have now set up a fully functional Python development environment for use with the micro:bit. With VS Code, Python, and uflash ready, you can start creating interactive projects with the micro:bit. The micro:bit opens the door to endless experimentation, so start coding and see what you can create!\nCheck back on TitusJTech and subscribe to my RSS Feed to stay up to date with the latest tech articles and tutorials.\n","permalink":"https://titusjtech.com/how-to-set-up-visual-studio-code-for-powerful-python-microbit-development/","summary":"\u003ch2 id=\"introduction\"\u003eIntroduction\u003c/h2\u003e\n\u003cp\u003eThe BBC micro:bit is a tiny, powerful microcontroller that makes learning programming fun and accessible. By combining Python with Visual Studio Code (VS Code), you can write, test, and flash code to your micro:bit easily. In this guide, I\u0026rsquo;ll walk you through setting up a complete development environment so you can start creating projects in MicroPython, the Python variant that works on micro:bit.\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003eNote: micro:bit offers their own official editor for Python. Although it is easy to use, I recommend you set up VS Code as it is more customizable and provides additional features.\u003c/p\u003e","title":"How to Set Up Visual Studio Code for Powerful Python micro:bit Development"},{"content":" Introduction The default Bash shell in Linux/older versions of MacOS is simple and minimalistic, but there is another alternative I recommend you try\u0026hellip;\nIn this guide I will show you how to create a high quality shell environment using Oh My Zsh. Even if you don\u0026rsquo;t have Bash on your Linux or Mac computer, if you are looking for a boost to the look of your shell environment, I highly recommend you still go through this tutorial.\nInstall Zsh First of all, install Zsh.\nThe steps for Ubuntu Linux, Fedora Linux, and MacOS are below.\nOn Ubuntu Linux, run the following command, and then enter your password to confirm:\nsudo apt install zsh -y On Fedora Linux, run the following command, and then enter your password to confirm:\nsudo dnf install zsh -y On MacOS, if you computer did not come preinstalled with Zsh, first install Homebrew. To do that, run the following command:\nsh -c \u0026#34;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\u0026#34; Now install Zsh using the brew command:\nbrew install zsh Oh My Zsh and Powerlevel10k Setup If you run the Zsh command, it looks quite plain, so let\u0026rsquo;s change that by installing Oh My Zsh (a Zsh customization framework) and Powerlevel10k (a Zsh Theme).\nTo install Oh My Zsh, run the following command in the terminal:\nsh -c \u0026#34;$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)\u0026#34; \u0026#34;\u0026#34; --unattended After the above command is complete, install the Meslo LGS Nerd Font TTFs (true type font files) for Powerlevel10k to make it look fancier when we install it. Here are the steps:\nDownload the TTF files. Meslo LGS Nerd Font Regular Meslo LGS Nerd Font Bold Meslo LGS Nerd Font Italic For each TTF file, double click it and then a font manager will appear. Follow the prompts to install the TTF file. Note: If you are using KDE with Wayland on Linux, you may need to install gnome-font-viewer to install the fonts, since kfontview doesn\u0026rsquo;t have complete support for Wayland yet, and may have errors reading the fonts.\nChange your terminal\u0026rsquo;s font to MesloLGS NF by following the step below which corresponds to your platform. I have included Linux with KDE, Linux with Gnome, and MacOS. If you are using another platform, it is likely the steps are similar, for example it will probably be something like preferences followed by appearance .\nFor Linux using KDE, create a new terminal profile in Konsole, set it to the default profile, and then use this answer on fedoraforum.org to change the terminal font.\nFor Linux using Gnome, use this section of an official Gnome guide to set the font in Gnome terminal.\nFor MacOS, select your MacOS version, read the top text, and then scroll down to the font section on this offical Apple guide to change the terminal font.\nAfter you have installed the fonts and set them up for the terminal, install Powerlevel10k using the following command:\ngit clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k Now change the value of \u0026quot;ZSH_THEME\u0026quot; in .zshrc to ZSH_THEME=\u0026quot;powerlevel10k/powerlevel10k\u0026quot; using your text editor.\nNow clone and install the ZSH syntax hightlighting plugin for great terminal syntax highlighting and the ZSH auto suggestions plugin for terminal auto completion. The code to clone both of these repositories is below.\n# Syntax Highlighting` git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting # Auto Completion git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions Now, replace the line starting with plugins=() in .zshrc with plugins=( git zsh-syntax-highlighting zsh-autosuggestions ) , to enable syntax hightlighting and auto completion.\nLaunch zsh by running the zsh command.\nWhen you launch zsh , your shell will look drastically different and colorful. This is a good sign because it means that Powerlevel10k is enabled.\nRun the p10k configure command. You will be greeted with a configuration wizard. Answer the shape questions correctly. For example, if it says does this look like a diamond, answer \u0026ldquo;y\u0026rdquo; for yes or \u0026ldquo;n\u0026rdquo; for no if does not look like a diamond. After you have answered all the shape questions correctly, you can choose your prompt style and the level of minimalism you want through another series of questions. For example, one of the questions asks you whether you want to show the time on the terminal in 24-hour or 12-hour format, or not at all.\nAfter you have answered all the questions, set the default shell to zsh using the following command and then enter your password to confirm:\nchsh -s $(which zsh) Now logout of your current desktop session or restart your computer and then launch terminal.\nIf you see the ZSH prompt you configured, you did everything correct and can enjoy your awesome new shell environment.\nIf you ever want to change the look of the prompt you configured, you can always run the p10k configure command like you did to originally configure your prompt, and the setup wizard will guide you through the process once again.\nVS Code Configuration If you are using VS Code, the VS Code terminal will look empty without icons since the Meslo LGS Nerd Font is not used by default. To change the VS Code terminal font, open settings and type terminal.integrated.fontFamily into the search box. Change the blank value to \u0026ldquo;MesloLGS NF\u0026rdquo;. Now restart VS Code. Open terminal using CTRL-~ (Control-Tilde). You should see your customized ZSH shell with the icons. If it is not displaying correctly, you may need to run the p10k configure command again to reconfigure the prompt and enable the Meslo LGS Nerd Font.\nConclusion Congratulations, you have just created a beautiful shell environment with Oh My Zsh!\nCheck back on TitusJTech and subscribe to my RSS feed to stay up to date on my latest tech articles, tutorials, and guides.\n","permalink":"https://titusjtech.com/posts/create-a-beautiful-shell-with-ohmyzsh/","summary":"This article describes how to create a beautiful shell environment with Oh My Zsh and Powerlevel10k.","title":"Create a Beautiful Shell Environment with Oh My Zsh"},{"content":"Introduction In this tutorial of my Python and Linux series, you will learn how to create Python code that retrieves the display server type of your Linux computer and returns the value as x11, wayland, or tty.\nStarter Code Start by creating a file called display_server.py . To edit the file, I recommend using the free Visual Studio Code (VS Code). If you would like to set up Visual Studio Code for Python development, follow my tutorial.\nOn the first line of the Python file, import the os module:\nimport os Next, set a variable for the current session id of the loginctl command:\nsession_id = os.popen(\u0026#34;loginctl\u0026#34;).read().replace(\u0026#34;-\u0026#34;, \u0026#34;\u0026#34;).split()[5] This code gets data from the loginctl command and then formats the results.\nThe next code pythonically gives the loginctl command the session id given from the last code snippet so that it can give back the type of display server your Linux computer is running.\nsession = ( os.popen(f\u0026#34;loginctl show-session {session_id} -p Type\u0026#34;) .read() .lower() .replace(\u0026#34;type=\u0026#34;, \u0026#34;\u0026#34;) .rstrip() ) Finally, print the session variable to get the result.\nprint(session) Your code should now be exactly like this:\nimport os session_id = os.popen(\u0026#34;loginctl\u0026#34;).read().replace(\u0026#34;-\u0026#34;, \u0026#34;\u0026#34;).split()[5] session = ( os.popen(f\u0026#34;loginctl show-session {session_id} -p Type\u0026#34;) .read() .lower() .replace(\u0026#34;type=\u0026#34;, \u0026#34;\u0026#34;) .rstrip() ) print(session) Running Your Code To run your code, open terminal and run this command:\npython display_server.py If you are using VS Code, you can optionally use the keyboard shortcut ctrl-~ (Control-Tilde) to open the VS Code Terminal and run the code there instead of opening the regular Linux terminal.\nImproving Your Code If you would like to improve your code a little bit, you can check whether the system is Linux or not and create a custom warning message, so that Windows and Mac users don\u0026rsquo;t run the code and get thrown default Python errors, but instead are given a warning message about the code only being able to run on Linux.\nAt the top of your Python file, below import os , add this code to import Platform and the Warnings module:\nimport platform import warnings Next, add the following code below your import statements to create a custom warning type of PlatformWarning:\nclass PlatformWarning(UserWarning): pass Next, add this code directly above the session_id variable to check whether the system running the code is Linux:\nif platform.system() == \u0026#34;Linux\u0026#34;: Finally, add this code below print(session) to show a warning to non-Linux users.\nelse: warnings.warn(\u0026#34;Code should only be run on Linux.\u0026#34;, PlatformWarning) I have formatted the completed code including the advanced code and have included the result below:\nimport os import platform import warnings class PlatformWarning(UserWarning): pass if platform.system() == \u0026#34;Linux\u0026#34;: session_id = os.popen(\u0026#34;loginctl\u0026#34;).read().replace(\u0026#34;-\u0026#34;, \u0026#34;\u0026#34;).split()[5] session = ( os.popen(f\u0026#34;loginctl show-session {session_id} -p Type\u0026#34;) .read() .lower() .replace(\u0026#34;type=\u0026#34;, \u0026#34;\u0026#34;) .rstrip() ) print(session) else: warnings.warn(\u0026#34;This code can only be run on Linux.\u0026#34;, PlatformWarning) Conclusion That\u0026rsquo;s all there is to it\u0026hellip; you have completed Python code that checks the type of display server on Linux computers. I hope you have enjoyed this article!\nCheck back on TitusJTech for more articles! 😎\n","permalink":"https://titusjtech.com/posts/get-linux-display-server-python/","summary":"This article describes how to get the display server type in Python on Linux.","title":"How to Get Display Server Type in Python on Linux"},{"content":" Introduction Distrobox makes it possible to run applications not available for your current Linux distribution. It does this through running on top of another Linux distribution in a container, which is tightly integrated with the host computer. The Distrobox container provides graphical app support, sound, and can share USB devices with the host. It also shares your home directory, so you can access the files of your host computer from the container. Distrobox can either utilize Docker or Podman.\nInstall Prerequisites Install Docker or Podman if you don\u0026rsquo;t have one of them installed.\nTo install Docker on Ubuntu, run this command:\nsudo apt install docker -y To install Podman on Ubuntu, run this command:\nsudo apt install podman -y Install Distrobox Execute this command to install Distrobox:\ncurl https://raw.githubusercontent.com/89luca89/distrobox/main/install | sudo sh Set Up Container Execute this command to download an image and create a container:\ndistrobox-create --name fedora-distrobox --image fedora:latest You can customize the command above to fit your needs. For example, you can download Debian instead of Fedora. For that, replace fedora:latest with debian:latest . You can also change fedora-distrobox to another name of your choice but be sure to use the new name consistently in the following commands.\nAfter the container is created, run this command to launch into the Distrobox container shell.\ndistrobox-enter --name fedora-distrobox Test Out Distrobox Run the command below in the currently running Distrobox shell to print information about the currently running container OS:\n$ cat /etc/os-release | grep -i name NAME=\u0026#34;Fedora Linux (Container Image)\u0026#34; ... Install a graphical app in your container to test the working GUI. I installed Gnome Chess using the following command:\nsudo dnf install gnome-chess We can then launch Gnome Chess:\ngnome-chess \u0026amp; Lo and behold, Gnome Chess launches and is fully functional!\nExport Apps to Linux Menu You can export apps from the Fedora Distrobox container you created into your host computer\u0026rsquo;s menu using the command below in the Distrobox shell:\ndistrobox-export --app gnome-chess If you installed a different app, replace gnome-chess with your app name. I have included a screenshot of the icon of Gnome Chess in my menu:\nStop the Container Exit the Distrobox terminal by typing exit at the prompt.\nIf you are using Docker, the command to stop the Fedora container is:\ndocker stop fedora-distrobox If you are using Podman, the command is:\npodman stop fedora-distrobox Conclusion There you have it\u0026hellip; a way to run apps not available for your Linux Distribution. Be sure to check back for more articles on TitusJTech!\n","permalink":"https://titusjtech.com/posts/getting-started-distrobox-linux/","summary":"This article describes how to install Distrobox on Linux.","title":"Getting Started with Distrobox in Linux"},{"content":"Introduction Python is a great general-purpose language that is pretty easy to learn. Visual Studio Code (VS Code) is an excellent code editor, and Python pairs wonderfully with it. In this article, I will be helping you get started with Python and VS Code to create a productive development environment.\nSetup Install Python If you are using MacOS or Windows, visit the Python website to download the installer for your platform, and then install Python. If you are on Linux, Python is most likely already installed. If not, install Python through your package manager or compile from source. On Windows make sure to check Add Python to Path during setup. Install VS Code Now that you have Python installed, it is time to install VS Code. Visit the VS Code download page and download the installer for your platform, and then install it the way you normally install apps. If you are on Linux, you could also install it through Snap, Flatpak, or through your graphical software manager. Install Useful VS Code Extensions Open command prompt or PowerShell on Windows, or Terminal on MacOS and Linux, and run the commands below. You could also do this manually, but this automates the process so that it takes less time. The code below installs some useful VS Code extensions and then installs the Python formatter called black .\nBlack is an awesome Python formatter that can be accessed by using the keyboard shortcut Ctrl-Shift-P and then typing format document, followed by pressing enter. You can also access it by using the keyboard shortcut for your platform. The Python extension and Pylance are amazing VS Code extensions to help boost your coding productivity. As noted on its extension page, the Intellicode Extension provides AI-assisted IntelliSense by showing recommended completion items for your code context. Finally, the Better Comments extension helps you with better syntax highlighting for comments. For example a comment you enter starting with the word \u0026ldquo;todo\u0026rdquo; will be highlighted in an orange color. code --install-extension ms-python.python code --install-extension ms-python.vscode-pylance code --install-extension VisualStudioExptTeam.vscodeintellicode code --install-extension aaron-bond.better-comments pip install black If you would like to install the extensions manually, here are the links:\nPython Extension\nPylance Extension\nVisual Studio Intellicode\nBetter Comments\nAfter you have run the code above or have installed the extensions manually, follow these steps.\nOpen VS Code and select the gear icon.\nSelect Settings. On the search box, type Python Formatting Provider and press enter.\nChange the value from autopep8 to black.\nTest Out VS Code Now that VS Code is set up, we will test it out to make sure it works.\nOpen up VS Code if you closed it or you can use the window you already have open. Click on the explorer icon.\nSelect the new file button.\nIn the textbox that appears, type hello.py and press enter. Open up the created file in VS Code and paste print(\u0026#34;hello world\u0026#34;) Use the keyboard shortcut Ctrl+S to save your file.\nNow use the keyboard shortcut ctr+~ (Control-Tilde) to launch the terminal and type the following:\npython hello.py After this, press enter. Hello world should appear in the terminal.\nGreat Job! 🙌 Everything should be set up!\nConclusion You have just installed VS Code and created a development for Python!\nCheck back on TitusJTech and subscribe to my RSS feed for more tech articles, tutorials, and guides.\n","permalink":"https://titusjtech.com/posts/getting-started-vscode-python/","summary":"This article describes how to install Python and VS Code to create a productive development environment.","title":"Getting Started with Python in VS Code"}]