Open-source News

Vulkanised 2023 Vulkan Conference Slides/Videos Available

Phoronix - Tue, 03/14/2023 - 19:00
Taking place last month in the most wonderful city of Munich, The Khronos Group hosted Vulkanised 2023 as their Vulkan Developers' Conference and Meetup. The slides and videos from the event are now available, including talks on Valve's RADV effort and more...

AMD Launches The EPYC Embedded 9004 Series

Phoronix - Tue, 03/14/2023 - 18:45
AMD is using Embedded World 2023 in Nürnberg to launch the EPYC Embedded 9004 series as their 4th Gen EPYC processors intended for telecommunications, edge computing, automation, and IoT applications...

How Cloudflare Updates The BIOS & Firmware Across Thousands Of Servers

Phoronix - Tue, 03/14/2023 - 18:28
For those wondering how Cloudflare keeps their thousands of servers around the world up-to-date for the latest BIOS and firmware, Cloudflare's engineering blog has put out an interesting post that outlines their process of handling system BIOS updates as well as various other firmware updates...

KDE KWin's Move Away From GBM Surfaces

Phoronix - Tue, 03/14/2023 - 18:02
KDE developer Xaver Hugl has written a blog post how the KWin compositor's DRM back-end has been working to move itself off GBM surfaces (gbm_surfaces) to instead allocate buffers directly and import them into EGL. This ultimately should be a win for the KWin compositor once everything is complete...

5 of the most curious uses of the Raspberry Pi

opensource.com - Tue, 03/14/2023 - 15:00
5 of the most curious uses of the Raspberry Pi AmyJune Tue, 03/14/2023 - 03:00

Recently, I was on a call where it was said that the open source community is a combination of curiosity and a culture of solutions. And curiosity is the basis of our problem-solving. We use a lot of open source when solving problems of all sizes, and that includes Linux running on the supremely convenient Raspberry Pi.

We all have such different lived experiences, so I asked our community of writers about the most curious use of a Raspberry Pi they've ever encountered. I have a hunch that some of these fantastic builds will spark an idea for others.

Experimentation with the Raspberry Pi

For me, the Raspberry Pi has been a great tool to add extra development resources on my home network. If I want to create a new website or experiment with a new software tool, I don't have to bog down my desktop Linux machine with a bunch of packages that I might only use once while experimenting. Instead, I set it up on my Raspberry Pi.

If I think I'm going to do something risky, I use a backup boot environment. I have two microSD cards, which allows me to have one plugged into the Raspberry Pi while I set up the second microSD to do whatever experimenting I want to do. The extra microSD doesn't cost that much, but it saves a ton of time for the times when I want to experiment on a second image. Just shutdown, swap microSD cards, reboot, and immediately I'm working on a dedicated test system.

When I'm not experimenting, my Raspberry Pi acts as a print server to put my non-WiFi printer on our home network. It is also a handy file server over SSH so that I can make quick backups of my important files.

Jim Hall

The popularity of the Raspberry Pi

The most amazing thing I've seen about the Raspberry Pi is that it normalized and commoditized the idea of the small-board computers and made them genuinely and practically available to folks.

Before the Raspberry Pi, we had small-board computers in a similar fashion, but they tended to be niche, expensive, and nigh unapproachable from a software perspective. The Raspberry Pi was cheap, and cheap to the point of making it trivial for anyone to get one for a project (ignoring the current round of unobtainium it's been going through). Once it was cheap, people worked around the software challenges and made it good enough to solve many basic computing tasks, down to being able to dedicate a full and real computer to a task, not just a microcontroller.

We've got a plethora of good, cheap-ish, small-board computers, and this gives way to tinkering, toying, and experimenting. People are willing to try new ideas, even spurring more hobbyist hardware development to support these ideas.

Honestly, that is by far the most amazing and radical thing I've seen from the Raspberry Pi: how it's fundamentally changed everyone's perception of what computing, at the level of what the Raspberry Pi excels at anyway, is and given rise not only to its own ecosystem but now countless others in diversity.

John ‘Warthog9' Hawley

Raspberry Pi for the bees

In 2018, my younger brother and I used to have several beehives and used a Raspberry Pi and various sensors to monitor the temperature and humidity of our hives. We also planned to implement a hive scale to observe honey production in summer and measure the weight in winter to see if the bees had enough food left. We never got around to doing that.

Our little monitoring solution was based on a Raspberry Pi 2 Model B, ran Raspbian Stretch (based on Debian 9), and had a temperature and humidity sensor connected (DHT11). We had three or four of those sensors in the hives to measure the temperature at the entrance hole, under the lid, and in the lowest frame. We connected the sensor directly to the Pi and used the Python_DHT sensor library to read the data. We also set up InfluxDB, Telegraf, and finally, Grafana to visualize the data.

If you want to know more about our setup, we published an article on our little monitoring solution in Linux Magazine.

Heike Jurzik

More on Raspberry Pi What is Raspberry Pi? eBook: Guide to Raspberry Pi Getting started with Raspberry Pi cheat sheet eBook: Running Kubernetes on your Raspberry Pi Whitepaper: Data-intensive intelligent applications in a hybrid cloud blueprint Understanding edge computing Our latest on Raspberry Pi Go retro with the Raspberry Pi

One thing I would love to create with the Raspberry Pi is a simulation of how to program machine language into an old-style computer using "switches and lights." This looks to be fairly straightforward using the GPIO pins on the Raspberry Pi. For example, their online manual shows examples of how to use GPIO to switch an LED on and off or to use buttons to get input. I think it should be possible with some LEDs and switches, plus a small program running on the Raspberry Pi to emulate the old-style computer. But I lack the free time to work on a project like this, which is why I wrote the Toy CPU to emulate it.

Jim Hall

Build a toy with the Raspberry Pi

When my daughter was four, she asked for a "Trolls music box" for Christmas. She could picture it perfectly in her head. It would be pink and sparkly with her name on it. When she opened the box, the theme song from the popular movie would play. She could store her trolls and other treasures in the box. After searching everywhere online and in stores, I could not find one that measured up to her imagination. My husband and I decided we could build one ourselves in our own toyshop (i.e., his home office). The center of it all was, of course, the Raspberry Pi. He used light sensors and a Python script to make the song play at just the right moment. We placed the tech discreetly in the bottom of the music box and decorated it with her aesthetic in mind. That year, holiday magic was made possible with open source! 

Lauren Pritchett

People use the Raspberry Pi for all kinds of things. What's caught your attention?

Image by:

Dwight Sipler on Flickr

Raspberry Pi Opensource.com community What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. 5566 points Minnesota

Jim Hall is an open source software advocate and developer, best known for usability testing in GNOME and as the founder + project coordinator of FreeDOS. At work, Jim is CEO of Hallmentum, an IT executive consulting company that provides hands-on IT Leadership training, workshops, and coaching.

| Connect jimfhall User Attributes Correspondent Open Sourcerer People's Choice Award People's Choice Award 2018 Author Correspondent Contributor Club 289 points Cologne/Luebeck, Germany

Heike is a FLOSS enthusiast, technical writer and author of several Linux books:

www.heikejurzik.de

www.yuki-likes-snow.de

Heike discovered Linux in 1996, while she was working at the University's Center for Applied Computer Science. In her spare time Heike hangs out at Folk and Bluegrass sessions, playing the fiddle.

| Follow heikejurzik | Connect heike-jurzik Open Minded Author Linux Debian Geek Contributor Club 96 points Oregon

John works for VMware in the Open Source Program Office on upstream open source projects. In a previous life he's worked on the MinnowBoard open source hardware project, led the system administration team on kernel.org, and built desktop clusters before they were cool. For fun he's built multiple star ship bridges, a replica of K-9 from a popular British TV show, done in flight computer vision processing from UAVs, designed and built a pile of his own hardware.

He's cooked delicious meals for friends, and is a connoisseur of campy 'bad' movies. He's a Perl programmer who's been maliciously accused of being a Python developer as well.

| Follow warty9 Open Enthusiast SysAdmin CentOS Community Manager Developer Fedora Geek Author DevOps Gamer Linux Maker Open hardware Python 2208 points Raleigh, NC

Lauren is the managing editor for Opensource.com. When she's not organizing the editorial calendar or digging into the data, she can be found going on adventures with her family and German shepherd rescue dog, Quailford. She is passionate about spreading awareness of how open source technology and principles can be applied to areas outside the tech industry such as education and government.

User Attributes Team Open Source Champion Author Open access Contributor Club Register or Login to post a comment.

Calculate pi by counting pixels

opensource.com - Tue, 03/14/2023 - 15:00
Calculate pi by counting pixels Jim Hall Tue, 03/14/2023 - 03:00

For Pi Day this year, I wanted to write a program to calculate pi by drawing a circle in FreeDOS graphics mode, then counting pixels to estimate the circumference. I naively assumed that this would give me an approximation of pi. I didn't expect to get 3.14, but I thought the value would be somewhat close to 3.0.

I was wrong. Estimating the circumference of a circle by counting the pixels required to draw it will give you the wrong result. No matter what resolution I tried, the final pi calculation of circumference divided by diameter was always around 2.8.

You can't count pixels to calculate pi

I wrote a FreeDOS program using OpenWatcom C that draws a circle to the screen, then counts the pixels that make up that circle. I wrote it in FreeDOS because DOS programs can easily enter graphics mode by using the OpenWatcom _setvideomode function. The _VRES16COLOR video mode puts the display into 640×680 resolution at 16 colors, a common "classic VGA" screen resolution. In the standard 16 color DOS palette, color 0 is black, color 1 is blue, color 7 is a low intensity white, and color 15 is a high intensity white.

In graphics mode, you can use the _ellipse function to draw an ellipse to the screen, from some starting x,y coordinate in the upper left to a final x,y coordinate in the lower right. If the height and width are the same, the ellipse is a circle. Note that in graphics mode, x and y count from zero, so the upper left corner is always 0,0.

Image by:

(Jim Hall, CC BY-SA 4.0)

You can use the _getpixel function to get the color of a pixel at a specified x,y coordinate on the screen. To show the progress in my program, I also used the _setpixel function to paint a single pixel at any x,y on the screen. When the program found a pixel that defined the circle, I changed that pixel to bright white. For other pixels, I set the color to blue.

Image by:

(Jim Hall, CC BY-SA 4.0)

With these graphics functions, you can write a program that draws a circle to the screen, then iterates over all the x,y coordinates of the circle to count the pixels. For any pixel that is color 7 (the color of the circle), add one to the pixel count. At the end, you can use the total pixel count as an estimate of the circumference:

#include #include int main() { unsigned long count; int x, y; /* draw a circle */ _setvideomode(_VRES16COLOR); /* 640x480 */ _setcolor(7); /* white */ _ellipse(_GBORDER, 0, 0, 479, 479); /* count pixels */ count = 0; for (x = 0; x <= 479; x++) { for (y = 0; y <= 479; y++) { if (_getpixel(x, y) == 7) { count++; /* highlight the pixel */ _setcolor(15); /* br white */ _setpixel(x, y); } else { /* highlight the pixel */ _setcolor(1); /* blue */ _setpixel(x, y); } } } /* done */ _setvideomode(_DEFAULTMODE); printf("pixel count (circumference?) = %lu\n", count); puts("diameter = 480"); printf("pi = c/d = %f\n", (double) count / 480.0); return 0; }

But counting pixels to determine the circumference underestimates the actual circumference of the circle. Because pi is the ratio of the circumference of a circle to its diameter, my pi calculation was noticeably lower than 3.14. I tried several video resolutions, and I always got a final result of about 2.8:

pixel count (circumference?) = 1356 diameter = 480 pi = c/d = 2.825000

Open science and sustainability Video series: ChRIS (ChRIS Research Integration System) Explore Red Hat Research projects 6 articles to inspire open source sustainability How Linux rescues slow computers (and the planet) Latest articles about open science Latest articles about open education Latest articles about sustainability You need to measure the distance between pixels to get pi

The problem with counting pixels to estimate the circumference is that the pixels are only a sample of a circular drawing. Pixels are discrete points in a grid, while a circle is a continuous drawing. To provide a better estimate of the circumference, you must measure the distance between pixels and use that total measurement for the circumference.

To update the program, you must write a function that calculates the distance between any two pixels: x0,y0 and x,y. You don't need a bunch of fancy math or algorithms here, just the knowledge that the OpenWatcom _ellipse function draws only solid pixels in the color you set for the circle. The function doesn't attempt to provide antialiasing by drawing nearby pixels in some intermediate color. That allows you to simplify the math. In a circle, pixels are always directly adjacent to one another: vertically, horizontally, or diagonally.

For pixels that are vertically or horizontally adjacent, the pixel "distance" is simple. It's a distance of 1.

For pixels that are diagonally adjacent, you can use the Pythagorean theorem of a²+b²=c² to calculate the distance between two diagonal pixels as the square root of 2, or approximately 1.414.

double pixel_dist(int x0, int y0, int x, int y) { if (((x - x0) == 0) && ((y0 - y) == 1)) { return 1.0; } if (((y0 - y) == 0) && ((x - x0) == 1)) { return 1.0; } /* if ( ((y0-y)==1) && ((x-x0)==1) ) { */ return 1.414; /* } */ }

I wrapped the last "if" statement in comments so you can see what the condition is supposed to represent.

To measure the circumference, we don't need to examine the entire circle. We can save a little time and effort by working on only the upper left quadrant. This also allows us to know the starting coordinate of the first pixel in the circle; we'll skip the first pixel at 0,239 and instead assume that as our first x0,y0 coordinate in measuring the quarter-circumference.

Image by:

(Jim Hall, CC BY-SA 4.0)

The final program is similar to our "count the pixels" program, but instead measures the tiny distances between pixels in the upper left quadrant of the circle. You may notice that the program counts down the y coordinates, from 238 to 0. This accommodates the assumption that the known starting x0,y0 coordinate in the quarter-circle is 0,239. With that assumption, the program only needs to evaluate the y coordinates between 0 and 238. To estimate the total circumference of the circle, multiply the quarter-measurement by 4:

#include #include double pixel_dist(int x0, int y0, int x, int y) { ... } int main() { double circum; int x, y; int x0, y0; /* draw a circle */ _setvideomode(_VRES16COLOR); /* 640x480 */ _setcolor(7); /* white */ _ellipse(_GBORDER, 0, 0, 479, 479); /* calculate circumference, use upper left quadrant only */ circum = 0.0; x0 = 0; y0 = 479 / 2; for (x = 0; x <= 479 / 2; x++) { for (y = (479 / 2) - 1; y >= 0; y--) { if (_getpixel(x, y) == 7) { circum += pixel_dist(x0, y0, x, y); x0 = x; y0 = y; /* highlight the pixel */ _setcolor(15); /* br white */ _setpixel(x, y); } else { /* highlight the pixel */ _setcolor(1); /* blue */ _setpixel(x, y); } } } circum *= 4.0; /* done */ _setvideomode(_DEFAULTMODE); printf("circumference = %f\n", circum); puts("diameter = 480"); printf("pi = c/d = %f\n", circum / 480.0); return 0; }

This provides a better estimate of the circumference. It's still off by a bit, because measuring a circle using pixels is still a pretty rough approximation, but the final pi calculation is much closer to the expected value of 3.14:

circumference = 1583.840000 diameter = 480 pi = c/d = 3.299667

Happy Pi Day! Does counting pixels get you the circumference of a circle?

Image by:

Opensource.com

Education What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

How I destroyed my Raspberry Pi

opensource.com - Tue, 03/14/2023 - 15:00
How I destroyed my Raspberry Pi hANSIc99 Tue, 03/14/2023 - 03:00

I wanted to write an article demonstrating "How to automate XYZ with the Raspberry Pi" or some other interesting, curious, or useful application around the Raspberry Pi. As you might realize from the title, I cannot offer such an article anymore because I destroyed my beloved Raspberry Pi.

The Raspberry Pi is a standard device on every technology enthusiast's desk. As a result, tons of tutorials and articles tell you what you can do with it. This article instead covers the dark side: I describe what you had better not do!

More on Raspberry Pi What is Raspberry Pi? eBook: Guide to Raspberry Pi Getting started with Raspberry Pi cheat sheet eBook: Running Kubernetes on your Raspberry Pi Whitepaper: Data-intensive intelligent applications in a hybrid cloud blueprint Understanding edge computing Our latest on Raspberry Pi Cable colors

I want to provide some background before I get to the actual point of destruction. You have to deal with different cable colors when doing electrical work in and around the house. Here in Germany, each house connects to the three-phase AC supply grid, and you usually find the following cable colors:

  • Neutral conductor: Blue
  • (PE) Protective conductor: Yellow-green
  • (L1) Phase 1: Brown
  • (L2) Phase 2: Black
  • (L3) Phase 3: Grey

For example, when wiring a lamp, you pick up neutral (N, blue) and phase (L, 1/3 chance that it is brown), and you get 230V AC between them.

Wiring the Raspberry Pi

Earlier this year, I wrote an article about OpenWrt, an open source alternative to firmware for home routers. In the article, I used a TP-link router device. However, the original plan was to use my Raspberry Pi model 4.

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

The idea was to build a travel router that I could install in my caravan to improve the internet connectivity at a campsite (I'm the kind of camper who can't do without the internet). To do so, I added a separate USB-Wifi-dongle to my Raspberry Pi to connect a second Wifi antenna and installed OpenWrt. Additionally, I added a 12V-to-5V DC/DC converter to connect with the 12V wiring in the caravan. I tested this setup with a 12V vehicle battery on my desk, and it worked as expected. After everything was set up and configured, I started to install it in my caravan.

In my caravan, I found a blue and a brown wire, connected it with the 12V-to-5V DC/DC converter, put the fuses back in, and…

Image by:

(Stephan Avenwedde, CC BY-SA 4.0)

The chip, which disassembled itself, is the actual step-down transformer. I was so confident that the blue wire was on 0V potential and the brown one was on 12V that I didn't even measure. I have since learned that the blue cable is on 12V, and the brown cable is on ground potential (which is pretty common in vehicle electronics).

Wrap up

Since this accident, my Raspberry Pi has never booted up. Because the prices for the Raspberry Pi have skyrocketed, I had to find an alternative. Luckily, I came across the TP-Link travel router, which can also run Open-WRT and does its job satisfactorily. In closing: It's better to measure too often than one time too few.

It's better to measure too often than one time too few. I learned the hard way, so you don't have to.

Image by:

kris krüg

Raspberry Pi What to read next This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Control your Raspberry Pi with Lua

opensource.com - Tue, 03/14/2023 - 15:00
Control your Raspberry Pi with Lua alansmithee Tue, 03/14/2023 - 03:00

Lua is a sometimes misunderstood language. It’s different from other languages, like Python, but it’s a versatile extension language that’s widely used in game engines, frameworks, and more. Overall, I find Lua to be a valuable tool for developers, letting them enhance and expand their projects in some powerful ways.

You can download and run stock Lua as Seth Kenlon explained in his article Is Lua worth learning, which includes simple Lua code examples. However, to get the most out of Lua, it’s best to use it with a framework that has already adopted the language. In this tutorial, I demonstrate how to use a framework called Mako Server, which is designed for enabling Lua programmers to easily code IoT and web applications. I also show you how to extend this framework with an API for working with the Raspberry Pi’s GPIO pins.

Requirements

Before following this tutorial, you need a running Raspberry Pi that you can log into. While I will be compiling C code in this tutorial, you do not need any prior experience with C code. However, you do need some experience with a POSIX terminal.

Install

To start, open a terminal window on your Raspberry Pi and install the following tools for downloading code using Git and for compiling C code:

$ sudo apt install git unzip gcc make

Next, compile the open source Mako Server code and the Lua-periphery library (the Raspberry Pi GPIO library) by running the following command:

$ wget -O Mako-Server-Build.sh https://raw.githubusercontent.com/RealTimeLogic/BAS/main/LinuxBuild.sh \

Review the script to see what it does, and run it once you’re comfortable with it:

$ sh ./Mako-Server-Build.sh

The compilation process may take some time, especially on an older Raspberry Pi. Once the compilation is complete, the script asks you to install the Mako Server and the lua-periphery module to /usr/local/bin/. I recommend installing it to simplify using the software. Don’t worry, if you no longer need it, you can uninstall it:

$ cd /usr/local/bin/ $ sudo rm mako mako.zip periphery.so

To test the installation, type mako into your terminal. This starts the Mako Server, and see some output in your terminal. You can stop the server by pressing CTRL+C.

IoT and Lua

Now that the Mako Server is set up on your Raspberry Pi, you can start programming IoT and web applications and working with the Raspberry Pi’s GPIO pins using Lua. The Mako Server framework provides a powerful and easy API for Lua developers to create IoT applications and the lua-periphery module lets Lua developers interact with the Raspberry Pi’s GPIO pins and other peripheral devices.

Start by creating an application directory and a .preload script, which inserts Lua code for testing the GPIO. The .preload script is a Mako Server extension that’s loaded and run as a Lua script when an application is started.

$ mkdir gpiotst $ nano gpiotst/.preload

Copy the following into the Nano editor and save the file:

-- Load periphery.so and access the LED interface local LED = require('periphery').LED local function doled() local led = LED("led0") -- Open LED led0 trace"Turn LED on" led:write(true) -- Turn on LED (set max brightness) ba.sleep(3000) -- 3 seconds trace"Turn LED off" led:write(false) -- Turn off LED (set zero brightness) led:close() end ba.thread.run(doled) -- Defer execution -- to after Mako has started

More on Raspberry Pi What is Raspberry Pi? eBook: Guide to Raspberry Pi Getting started with Raspberry Pi cheat sheet eBook: Running Kubernetes on your Raspberry Pi Whitepaper: Data-intensive intelligent applications in a hybrid cloud blueprint Understanding edge computing Our latest on Raspberry Pi

The above Lua code controls the main Raspberry Pi LED using the Lua-periphery library you compiled and included with the Mako Server. The script defines a single function called doled that controls the LED. The script begins by loading the periphery library (the shared library periphery.so) using the Lua require function. The returned data is a Lua table with all GPIO API functions. However, you only need the LED API, and you directly access that by appending .LED after calling require. Next, the code defines a function called doled that does the following:

  1. Opens the Raspberry Pi main LED identified as led0 by calling the LED function from the periphery library and by passing it the string led0.
  2. Prints the message Turn LED on to the trace (the console).
  3. Activates the LED by calling the write method on the LED object and passing it the Boolean value true, which sets the maximum brightness of the LED.
  4. Waits for 3 seconds by calling ba.sleep(3000).
  5. Prints the message Turn LED off to the trace.
  6. Deactivates the LED by calling the write method on the LED object and passing it the Boolean value false, which sets zero brightness of the LED.
  7. Closes the LED by calling the close function on the LED object.

At the end of the .preload script, the doled function is passed in as argument to function ba.thread.run. This allows the execution of the doled function to be deferred until after Mako Server has started.

To start the gpiotst application, run the Mako Server as follows:

$ mako -l::gpiotst

The following text is printed in the console:

Opening LED: opening 'brightness': Permission denied.

Accessing GPIO requires root access, so stop the server by pressing CTRL+C and restart the Mako Server as follows:

$ sudo mako -l::gpiotst

Now the Raspberry Pi LED turns on for 3 seconds. Success!

Lua unlocks IoT

In this primer, you learned how to compile the Mako Server, including the GPIO Lua module, and how to write a basic Lua script for turning the Raspberry Pi LED on and off. I’ll cover further IoT functions, building upon this article, in future articles.

You may in the meantime delve deeper into the Lua-periphery GPIO library by reading its documentation to understand more about its functions and how to use it with different peripherals. To get the most out of this tutorial, consider following the interactive Mako Server Lua tutorial to get a better understanding of Lua, web, and IoT. Happy coding!

Learn how to use the Lua programming language to program Internet of Things (IoT) devices and interact with General Purpose Input/Output (GPIO) pins on a Raspberry Pi.

Image by:

Dwight Sipler on Flickr

Raspberry Pi Programming Internet of Things (IoT) Download the eBook A guide to Lua This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License. Register or Login to post a comment.

Pages