
For Raspberry Pi users, Xonsh [1] offers many opportunities to write some extremely lightweight scripts, with Python connecting to physical devices and Bash utilities accessing system and file resources.
In this article, we look at two lean Xonsh projects for the Raspberry Pi. The first program connects to a DHT11 temperature and humidity sensor and shows the results in a Bash dialog in just five lines. The second project calls the Bash top utility in a lean eight lines to show the Raspberry Pi idle time and user time on a 16x2 LCD screen.
Getting Started
Xonsh has two requirements: Python 3.8 or greater and a Bash shell. To install and run Xonsh on a Raspberry Pi, Ubuntu, or Debian system, enter:
sudo apt install xonsh
xonsh
When the Xonsh shell opens, the terminal label changes so you can see that you are working in Xonsh rather than a standard Bash shell (Figure 1). When the shell first starts up, two options are presented: xonfig tutorial, which opens a browser help window, and xonfig web, which allows users to tweek the xonsh shell configuration.
Within the Xonsh shell, you can enter both Bash and Python statements, such as:
$ # Mix Bash and Python Lines
$ echo "Time is:" $(date +%T) ; # Bash
Time is: 12:59:51
$ print("%d + %d = %d" % U
(2,3,2+3)) ; # Python
2 + 3 = 5
Xonsh in the Terminal
Esta historia es de la edición MakerSpace #03 de MakerSpace.
Comience su prueba gratuita de Magzter GOLD de 7 días para acceder a miles de historias premium seleccionadas y a más de 9,000 revistas y periódicos.
Ya eres suscriptor ? Conectar
Esta historia es de la edición MakerSpace #03 de MakerSpace.
Comience su prueba gratuita de Magzter GOLD de 7 días para acceder a miles de historias premium seleccionadas y a más de 9,000 revistas y periódicos.
Ya eres suscriptor? Conectar

Access the Raspberry Pi's GPIO Pig Pen
The wiringPi library, which many Raspberry Pi fans have grown attached to over the years, is no longer under maintenance by its developer. An alternative, in the form of Pigpio, has arrived just in time

Playing old DOS games on the Raspberry Pi Retro Gamer
Play old DOS games on the Dosbian operating system, which turns the Raspberry Pi into an 80486 PC

Home Assistant makes the Raspberry Pi fit for the Z-Wave world Home Automaton
Z-Wave components, a RaZberry module, and the free Home Assistant software make the Raspberry Pi a powerful smart home control center

Water your plants with a Raspberry Pi Watering Pi
With a Pi Zero and a few components, you can build an inexpensive and reliable automatic watering system for your plants in next to no time

Raspberry Pi automated fish feeder Fish Food
Whether at work or on vacation, every pet lover worries about how to take care of their little roommates in their absence. What aquarium owners need is an automatic feeder

Integrate hardware components with pluggable systems Plugged In
Ecosystems with pluggable Raspberry Pi modules, sensors, and displays are a great choice if you don’t want to – or can’t – solder but still want to extend your hardware

Change internal logic from relays to an Arduino Redo
An electronic project at a local science center was showing its age, calling for a refresh: in this case, rebuilding it almost from scratch with an Arduino instead of relays

Get creative with the FLUX beamo laser and open source software Beam Me Up, Fluxy!
With the FLUX beamo laser and a Raspberry Pi Board B10001, you can execute your own laser cutting projects on a wide range of materials

Power your Pi Pico with solar Self-Sufficient
Powering your Pi Pico with solar may not solve the current energy crisis, but it will save you from changing or recharging batteries