Linux — Raspberry Pi (raspbian) tick rate in HZ — Raspberry Pi Stack Exchange

Raspberry Pi (raspbian) tick rate in HZ

How can I find the Linux tick rate of my Raspberry Pi 2. I have a Raspberry Pi 2 with Raspbian OS.

Is it 100 or 1000 HZ ? Can I read it from the command line or a C program ?

I want to know this value because I am using some timers which need precision.

1 Answer 1

I want to know this value because I am using some timers which need precision.

The precision of timers is not constrained by HZ or USER_HZ (see man 7 time ); you’ve probably looked at /proc/timer_list by now and recognized there is a nanosecond resolution timer in the kernel, whereas USER_HZ is normally 100 or 1000 and HZ is 100 or 250. There’s also CLOCKS_PER_SEC in userspace, which is stipulated by POSIX to be 1000000 and is used by clock() .

Again, USER_HZ and HZ are probably irrelevant to your purposes. The normative way to time an event is via clock() (or the newer clock_gettime() , see below) or gettimeofday() , which also has microsecond resolution. It should be pretty accurate; although the latency of system calls on a multitasking OS may be a factor, you should still at least get a precise measurement in milliseconds.

Latency for sleep operations is greater, so despite the existence of nanosleep() , don’t bother with anything finer than milliseconds and don’t expect that to always be bang on either (I believe this is the point where HZ comes into play, as it determines the granularity of the scheduler).

You can experiment with this by arranging sleeps and measuring the actual time elapsed. Here’s an example using clock_gettime() , which uses the nanosecond resolution clock on the pi. Note this may have to be compiled:

Since this clock function is a POSIX extension.

I think this is clear; if you don’t provide an argument, it will sleep for 2.5 s. If you do, it is interpreted in nanoseconds.

On an intel 64-bit desktop I get an accuracy in the sub millisecond range (variation shows up in the 5th decimal place). On a pi B it shows up in the 4th decimal place.

As always, see the relevant man pages for more explanation.

raspberrypi.stackexchange.com

How to Fight Coronavirus With Your Raspberry Pi

By Avram Piltch 06 April 2020

Donate Pi’s processing power to medical research.

(Image credit: Shutterstock)

With the coronavirus pandemic raging, many PC users have dedicated CPU cycles to medical research using [email protected] (we’re even doing a fold-off competition with AnandTech). Though [email protected] does not run on a Raspberry Pi, you can participate in [email protected], a similar project that’s also researching COVID-19, by installing a free Linux app called BOINC.

BOINC has been around for a long time and supports many different research projects, including [email protected], which does space research, and some of these projects will work on Raspbian, Raspberry Pi’s official OS. However, the addition of [email protected] is new, and if you want to join that project, you need to run BOINC on a 64-bit operating system (OS), such as Ubuntu (64-bit). [email protected] will not give you any workloads if you try it in Raspbian.

Here’s how to use your Raspberry Pi to fight coronavirus with BOINC and [email protected]

Before You Get Started

While these instructions should work on any Raspberry Pi that can run Ubuntu (64-bit), which includes both Raspberry Pi 3 and 4 models, we’ve only tested on a Raspberry Pi 4 (with 4GB). Given how resource-hungry both the BOINC workload and the Ubuntu OS are, we recommend using a Raspberry Pi 4 with at least 2GB of RAM, preferably 4GB (our system had 2.7GB used). If you don’t have one already, you’ll want a heatsink or fan, such as the Pimoroni Fan Shim, because without proper thermal dissipation, your Pi 4 may throttle.

How to Use Raspberry Pi to Fight Coronavirus

1. Set up Ubuntu (64-bit) on your Raspberry Pi. If you haven’t done this before, check out our tutorial on how to install Ubuntu on your Raspberry Pi. In short, you’ll want to make sure you burn a card with 64-bit Ubuntu server and install a desktop manager (we used Xubuntu for this tutorial).

2. Disable auto suspend in Ubuntu so it doesn’t go to sleep. To do this, launch the settings app, navigate to the Power tab and toggle “auto suspend” to off. If you want to keep a close eye on your progress, you might also want to disable screen blanking.

Set ‘Auto Suspend’ to Off screen. (Image credit: Tom’s Hardware)

3. Enter sudo apt-get install boinc at the command line to install boinc. Confirm when prompted. You can open a terminal to get to the command line in Ubuntu by hitting CTRL+ALT+T.

4. Launch BOINC Manager from Ubuntu’s app menu. You can get to the app menu by clicking the icon with the 9 dots on it.

BOINC Manager icon on Desktop (Image credit: Tom’s Hardware)

5. Select [email protected] from the projects menu, which appears as soon as you launch BOINC Manager for the first time. Click Next.

BOINC Manager ‘Choose a project’ screen. (Image credit: Tom’s Hardware)

6. Select Yes if BOINC warns you that the project “may not have work for your type of computer.” It may not have work for you right away, but [email protected] works with 64-bit Ubuntu on Raspberry Pi.

BOINC Manager ‘work’ notification. (Image credit: Tom’s Hardware)

7. Register an account for [email protected] or log in if you already have one. You will be asked for your email address and to set a password.

BOINC Manager registration screen. (Image credit: Tom’s Hardware)

8. Click Finish after the project has been added.

9. Complete your registration if necessary. After you click Finish, a browser window will pop up, taking you to [email protected]’s site, asking for more information and preferences, at minimum a username. You will also get the option to join a team if you would like to compete against other teams.

Account setup completion. (Image credit: Tom’s Hardware)

That’s it. As long as BOINC Manager is running, it will attempt to get work from the [email protected] project.

BOINC Manager status screen. (Image credit: Tom’s Hardware)

Keep in mind that it may take several hours before BOINC Manager gets work to do, and when you use the Raspberry Pi for something else, even a simple thing like opening a file manager, BOINC may pause its work until you are done. If you really want to help, your best bet is to leave your Raspberry Pi alone and let it go.

www.tomshardware.com

Running the TICK Stack on a Raspberry Pi

Since its introduction in 2013, the Raspberry Pi platform has grown by leaps and bounds, gaining popularity and showing up in projects all over world, from quick hacks to fully commercialized products. It’s an inexpensive, low power, open-source, single-board computer with a variety of interfaces for connecting with sensors and actuators that can be used to interact with the physical world.

It’s also a solid choice when you need an always-on device for collecting data, and it’s powerful enough to run the complete TICK Stack. In fact, one of the most popular posts on our community site is about running the TICK Stack on a Raspberry Pi, so we wanted to provide some update instructions for installing and things to consider while operating the stack.

The Hardware

Your Choice of Pi

The first thing you’ll need to do is decide which Pi you’re going to use. The Raspberry Pi platform has gone through a few iterations since it was first released in 2013:

Model Cores Clock Speed RAM
Zero 1, 32-bit 1000 MHz 512 MB
A/B/+ 1, 32-bit 500 MHz 256 MB
2B 4, 32-bit 900 MHz 1024 MB
3B 4, 64-bit 1200 MHz 1024 MB
3B+ 4, 64-bit 1400 MHz 1024 MB

There have been some significant architectural improvements over the years, and your best bet is to go with one of the model 3 boards, with quad-core, 64-bit CPUs for the database itself, although I’ve tested running the complete TICK Stack on the model 2 B, 3 B, and 3 B+. In addition, the single-core Zero makes a great platform for collecting sensor data with Telegraf.

Storage

The storage system on the Raspberry Pi, which uses an SD or microSD card, is the slowest by far relative to the systems on a laptop or desktop computer, so it’s important to keep in mind storage performance when you’re considering a Raspberry Pi for your application. Which SD card you choose will have a major impact on the performance of your Raspberry Pi, especially if you’re planning on running a database like InfluxDB.

Get at least a Class 10 Card—the faster, the better. But understand that even with the fastest SD card, performance won’t come close to what you would get with an SSD, and this can often be the bottleneck for your applications.

Some manufacturers are also releasing “High Endurance” SD cards; I haven’t had a chance to do much research about them, but if you plan on writing large volumes of data, it might be worth investigating.

The Raspberry Pi 3 B and B+ also have the ability to enable a USB boot mode, although this is a permanent change for your device. While you’ll still be constrained by the speed of a USB 2.0 port, this would enable you to run a large-capacity SSD with better speed and performance.

Installation

The most common way to use a Pi is with the Raspbian operating system provided by the Raspberry Pi foundation, so that’s what we’ll be using in this blog post. Raspbian is based off the Debian distribution of Linux, with some modifications and utilities like raspi-config that contain functionality specific to the hardware. The latest version of Raspbian is April release based on Debian Stretch.

You can download Raspbian and find installation instructions on the Raspberry Pi foundation’s website.

Recommended: Install from the Official InfluxData Repository

The easiest way to install the TICK Stack is to set up the InfluxData package repository (repo) and use your platform’s package manager, which on Raspbian is apt . Packages contain the application binaries themselves, as well as some information about where and how to install and configure the application on your system. That means you can get everything up and running with just a few commands, and InfluxData regularly publishes the latest versions of the TICK Stack to its repository, so applying updates is easy as well.

The first step is to set up the InfluxData repo. You’ll need to identify which version of Raspbian you’re running, which you can do by taking a look at the /etc/os-release file. Run the following command:

We need the version codename, which you can find in the VERSION field, in parentheses. For the version I’m running, 9, the code name is stretch . We’ll use that when we set up our repo so that we can get the correct versions for our OS.

Next, add the repo’s GPG key and add the repo itself:

and then add the repository:

Finally, run sudo apt-get update to refresh the package list with data from the new repository, and install the TICK Stack using sudo apt-get install telegraf influxdb chronograf kapacitor . If you want to only install some components of the stack, you can exclude the applications you don’t want from that command.

It’s also possible to download packages and install them yourself, without setting up the InfluxData repository. You probably don’t have a good reason for doing this, but for those who do, head over to our downloads page.

Docker

Docker is another great option for running the TICK Stack on a Raspberry Pi, and is what I use at home. Docker is an OS-level virtualization technology, which means that it isolates various applications by making it appear as though they each have their own Linux kernel and environment to run in. This provides isolation for your applications, while the Docker runtime provides easy-to-use tooling for creating and managing containers.

The recommended method for installing Docker on Raspbian is using the convenience script; you’ll also probably want to install docker compose.

You can refer to my Docker blog post from last week for more details about running TICK in docker containers, and I’ve written a simple Docker Compose file to help you get started.

Manual Options: Binaries and Building from Source

A few other options exist which provide additional level of manual control over how you want to build and install your applications. You can download a Linux binary from influxdata.com/downloads, or you can visit the respective Git repositories (Telegraf, InfluxDB, Chronograf, and Kapacitor), check out the code, and build the applications yourself.

Other Considerations

Since the Pi is a relatively constrained computing environment, you might have to make some tradeoffs in terms of how much software you can run and how much data you can process and store.

One thing to consider is that you don’t have to run Chronograf on the Pi; you can run a local copy on your primary computer, and set it up to talk to the InfluxDB instance on your Raspberry Pi over the network. This is the setup I’m currently running at home, and I find that it gives a nice performance bump over running everything on the Pi.

Another thing to keep in mind is the amount of storage space you have on your SD card. While InfluxDB is quite efficient at storing data, depending on the size of your card, the other software you have installed, and how much data you’re writing, it is possible to run out of space. You should definitely set up some kind of monitoring and alerting so that you can be informed when you run out of space. Telegraf’s disk plugin and Kapacitor’s alerts functionality would be a good fit for this!

You also might not need to keep your data around forever; a few weeks or months might be good enough for your use case. We often see users taking advantage of into InfluxData’s downsampling and retention policy functionality to reduce the resolution of their data and automatically delete it when it has reached a certain age. For more information on why you might want to do this, check out our recent training webinar, Downsampling Your Data.

www.influxdata.com

How to Build a Beginner’s Robot Using Raspberry Pi

Hardware
Raspberry Pi B/B+ or 2 and basic peripherals: SD card, keyboard, mouse, etc.
1 IR sensor modules
1 Geared DC motors
1 L293D driver board
1 Robot chassis and wheels
1 Caster wheel
1 Breadboard and double-sided tape
1 Male-to-male/female-to-male jumpers
1 9V Battery and connectors
1 Push button and 220R resistor

If you are a beginner to Raspberry Pi and are looking for a simple hardware project, look no further. This tutorial will show you to develop a Python-based robot that avoids obstacles and navigates freely.

Obstacle-avoiding robots are fairly common and easy to make. Here, you can use this project to add object avoidance functionality to your robot. Or simply use it to start messing around with Python and the hardware peripherals on Raspberry Pi. This system uses IR modules to detect objects, but we will get to the technical side later. So, if you have a Raspberry Pi and want to build something based on hardware using it, just scroll down and have fun.

Check out the video at the bottom to see how the Raspberry Pi robot works. And if you are a true beginner, you can always use our free eBook on Raspberry Pi and Arduino to get started from step 0. You can also read this tutorial on Basic Linux Commands to familiarize yourself with the Raspberry Pi terminal.

Raspberry Pi robot components

How Does the Robot Work?

So how do these IR sensors work? IR stands for infrared, which is a wavelength of light not visible to the human eye. (But it can be seen through our smartphone cameras!) These modules consist of a pair of receiver and transmitter IR LEDs. When an object gets in front of the IR sensor, the surface of the object reflects a part of the IR light back to the receiver. Thus, the receiver then outputs a LOW signal notifying that an object is in front of the sensor.

These sensors are wired to the GPIO input pins of the raspberry pi. The pi then using a python script checks whether the GPIO pins connected to the IR sensor modules goes low. If it does go low, then it commands the DC motors to move in the reverse direction first and then turn. Moreover, this robot is initially activated when we push the button on the breadboard, after which the raspberry pi commands the DC motors to move forward via the L293D driver board. You can check out the demo video at the bottom of this page to see how this robot works.

Connecting the IR Sensors for the Raspberry Pi Robot

Raspberry Pi GPIO pinout

First, you need to turn ON your Raspberry Pi after connecting it to the monitor, keyboard, etc. Then we need to check the IR sensor modules. To do this, connect the IR modules to your Raspberry Pi as shown in the following diagram. Power the sensor by providing 5V (+ pin), GND (- pin) from the Raspberry Pi. And connect the B pin on the sensors to Raspberry Pi’s GPIO pins 3 and 16. You can check out the Raspberry Pi GPIO pinout as per the pin diagram here. We are using the GPIO.BOARD configuration, which means the pins are numbered based on their normal order on the board (1,2,3, . ). Read the pin configuration on the sensor module and connect correspondingly.

Connection diagram — Raspberry Pi IR sensor

Next, you need to copy and paste the following code and save it as a Python file- irtest.py:

After saving and running this file, «sudo python irtest.py», you will notice that when you block the sensor with your hand, the following output prints on the screen:

IR sensor output from python

Connecting the Motors With L293D

Raspberry Pi robot connection diagram

Next, you have to provide the inputs to the board. Four output GPIO pins from the Raspberry Pi control the direction of rotation of the two motors. The two terminals of the motors are then connected to the four output terminals of the board. The motors, based on the command from the Raspberry Pi, are powered by the 9V battery. The logic for controlling the motors from the Raspberry Pi is as given below:

L293D Raspberry Pi control logic

Here, HIGH means a 5V signal or digital 1, and LOW is a 0V signal or digital 0. For example, GPIO.output(5,1) — this command sends a HIGH signal (digital 1) to pin no 5 on the Raspberry Pi. Thus, each motor’s direction can be controlled by writing HIGH/LOW signals through two GPIO pins from the Raspberry Pi.

Raspberry Pi robot assembly

After connecting the motors, you need to check them. Use the code below to check the motors and the L293D. Make sure you have powered the driver board (L293D) and given the connections as per the above diagram. After that, copy the code below and save it as a Python file, motor.py, on your Raspberry Pi. Then run it using the command sudo python motor.py. You will notice that both the motors rotate in one direction first, then after a second rotate in the opposite direction. This process repeats until you interrupt it.

Uploading the Code for the Raspberry Pi Robot

Raspberry Pi robot

This program is very simple. The robot is activated when the user presses the push button, and after that, the robot moves forward and checks whether any obstacles show up in front of it. Whenever your IR modules detect an object within 5cm in front of it, it tells the Raspberry Pi that an object is near it (sending digital LOW signals). Then the Pi sends commands to the motor, making it move in the reverse direction and then turning right or left, and again the robot moves forward by dodging the object. The robot is deactivated when you press the push button again.

After copying the code to your Raspberry Pi, you can make it truly wireless by using a smartphone battery bank to power it and a USB Wi-Fi dongle to communicate with it. You can extend the display of your laptop via VNC server and a LAN cable. Or use SSH to connect remotely to your Pi from the terminal wirelessly.

Check out the video showing the Raspberry Pi robot in action:

maker.pro

How to Fight Coronavirus With Your Raspberry Pi

By Avram Piltch 06 April 2020

Donate Pi’s processing power to medical research.

(Image credit: Shutterstock)

With the coronavirus pandemic raging, many PC users have dedicated CPU cycles to medical research using [email protected] (we’re even doing a fold-off competition with AnandTech). Though [email protected] does not run on a Raspberry Pi, you can participate in [email protected], a similar project that’s also researching COVID-19, by installing a free Linux app called BOINC.

BOINC has been around for a long time and supports many different research projects, including [email protected], which does space research, and some of these projects will work on Raspbian, Raspberry Pi’s official OS. However, the addition of [email protected] is new, and if you want to join that project, you need to run BOINC on a 64-bit operating system (OS), such as Ubuntu (64-bit). [email protected] will not give you any workloads if you try it in Raspbian.

Here’s how to use your Raspberry Pi to fight coronavirus with BOINC and [email protected]

Before You Get Started

While these instructions should work on any Raspberry Pi that can run Ubuntu (64-bit), which includes both Raspberry Pi 3 and 4 models, we’ve only tested on a Raspberry Pi 4 (with 4GB). Given how resource-hungry both the BOINC workload and the Ubuntu OS are, we recommend using a Raspberry Pi 4 with at least 2GB of RAM, preferably 4GB (our system had 2.7GB used). If you don’t have one already, you’ll want a heatsink or fan, such as the Pimoroni Fan Shim, because without proper thermal dissipation, your Pi 4 may throttle.

How to Use Raspberry Pi to Fight Coronavirus

1. Set up Ubuntu (64-bit) on your Raspberry Pi. If you haven’t done this before, check out our tutorial on how to install Ubuntu on your Raspberry Pi. In short, you’ll want to make sure you burn a card with 64-bit Ubuntu server and install a desktop manager (we used Xubuntu for this tutorial).

2. Disable auto suspend in Ubuntu so it doesn’t go to sleep. To do this, launch the settings app, navigate to the Power tab and toggle “auto suspend” to off. If you want to keep a close eye on your progress, you might also want to disable screen blanking.

Set ‘Auto Suspend’ to Off screen. (Image credit: Tom’s Hardware)

3. Enter sudo apt-get install boinc at the command line to install boinc. Confirm when prompted. You can open a terminal to get to the command line in Ubuntu by hitting CTRL+ALT+T.

4. Launch BOINC Manager from Ubuntu’s app menu. You can get to the app menu by clicking the icon with the 9 dots on it.

BOINC Manager icon on Desktop (Image credit: Tom’s Hardware)

5. Select [email protected] from the projects menu, which appears as soon as you launch BOINC Manager for the first time. Click Next.

BOINC Manager ‘Choose a project’ screen. (Image credit: Tom’s Hardware)

6. Select Yes if BOINC warns you that the project “may not have work for your type of computer.” It may not have work for you right away, but [email protected] works with 64-bit Ubuntu on Raspberry Pi.

BOINC Manager ‘work’ notification. (Image credit: Tom’s Hardware)

7. Register an account for [email protected] or log in if you already have one. You will be asked for your email address and to set a password.

BOINC Manager registration screen. (Image credit: Tom’s Hardware)

8. Click Finish after the project has been added.

9. Complete your registration if necessary. After you click Finish, a browser window will pop up, taking you to [email protected]’s site, asking for more information and preferences, at minimum a username. You will also get the option to join a team if you would like to compete against other teams.

Account setup completion. (Image credit: Tom’s Hardware)

That’s it. As long as BOINC Manager is running, it will attempt to get work from the [email protected] project.

BOINC Manager status screen. (Image credit: Tom’s Hardware)

Keep in mind that it may take several hours before BOINC Manager gets work to do, and when you use the Raspberry Pi for something else, even a simple thing like opening a file manager, BOINC may pause its work until you are done. If you really want to help, your best bet is to leave your Raspberry Pi alone and let it go.

www.tomshardware.com

Share:
No comments

Добавить комментарий

Your e-mail will not be published. All fields are required.

×
Recommend
Adblock
detector