Zum Hauptinhalt springen
Nicht aus der Schweiz? Besuchen Sie lehmanns.de

Raspberry Pi Zero Cookbook (eBook)

Over 80 practical and interesting recipes that explore the plethora of functionalities and opportunities available with Raspberry Pi Zero
eBook Download: EPUB
2017
422 Seiten
Packt Publishing Limited (Verlag)
978-1-78646-647-1 (ISBN)

Lese- und Medienproben

Raspberry Pi Zero Cookbook -  Snajder Edward Snajder
Systemvoraussetzungen
29,99 inkl. MwSt
(CHF 29,30)
Der eBook-Verkauf erfolgt durch die Lehmanns Media GmbH (Berlin) zum Preis in Euro inkl. MwSt.
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

The Raspberry Pi Zero, one of the most inexpensive, fully-functional computers available, is a powerful and revolutionary product developed by the Raspberry Pi Foundation. The Raspberry Pi Zero opens up a new world for the makers out there. This book will give you expertise with the Raspberry Pi Zero, providing all the necessary recipes that will get you up and running.
In this book, you will learn how to prepare your own circuits rather than buying the expensive add-ons available in the market. We start by showing you how to set up and manage the Pi Zero and then move on to configuring the hardware, running it with Linux, and programming it with Python scripts. Later, we integrate the Raspberry Pi Zero with sensors, motors, and other hardware. You will also get hands-on with interesting projects in media centers, IoT, and more.


Over 80 practical and interesting recipes that explore the plethora of functionalities and opportunities available with Raspberry Pi ZeroAbout This BookDeep dive into the components of the small yet powerful Raspberry Pi ZeroGet into grips with integrating various hardware, programming, and networking concepts with the so-called "e;cheapest computer"e;Explore the functionalities of this $5 chip through practical recipesWho This Book Is ForThis book is for programmers and hobbyists who are eager to dive deep into the Raspberry Pi Zero. If you have basic or zero knowledge of the Raspberry Pi Zero, or if you looking for examples of ways to utilize the Raspberry Pi's GPIO interface, then this book is ideal for you. Basic knowledge of Python will be beneficial, and experience with circuitry and electronics will be needed for the later chapters in the book.What You Will LearnSet up your Raspberry Pi Zero with the operating system, networking, and different interfacesGet a hands-on introduction to Linux, Python, and shell scripts with the Raspberry Pi ZeroBecome a master at driving GPIOs and controlling relays, motors, transistors, buzzers, audio, read switches, and interrupts with the Raspberry Pi ZeroControl GPIOs using the web interface and Node.jsConnect displays, LED matrixes, analog sensors, and digital sensorsHack the Ethernet on the Raspberry Pi ZeroMake your Raspberry Pi Zero an IoT-based sensor node and remotely monitor your dataIn DetailThe Raspberry Pi Zero, one of the most inexpensive, fully-functional computers available, is a powerful and revolutionary product developed by the Raspberry Pi Foundation. The Raspberry Pi Zero opens up a new world for the makers out there. This book will give you expertise with the Raspberry Pi Zero, providing all the necessary recipes that will get you up and running.In this book, you will learn how to prepare your own circuits rather than buying the expensive add-ons available in the market. We start by showing you how to set up and manage the Pi Zero and then move on to configuring the hardware, running it with Linux, and programming it with Python scripts. Later, we integrate the Raspberry Pi Zero with sensors, motors, and other hardware. You will also get hands-on with interesting projects in media centers, IoT, and more.Style and approachThis recipe-based book will ensure you gain an intermediate-level knowledge of the Raspberry Pi Zero. This book contains comprehensive illustrations with specific schematics for each circuit diagram.

Logging in to the RPZ desktop for the first time, creating users, and rebooting


We've taken care of the initial configuration; let's wrap up this chapter by covering a few finishing touches in the configuration, creating users, and giving them power!

How to do it...


  1. After you select Finish on the raspi-config tool, it will ask whether you'd like to reboot. Select Yes, and the Raspberry Pi Zero will begin its power-down process. When it starts back up, it will take you right back to the Raspbian desktop. You can reboot the Pi anytime with this command: sudo reboot now
  2. Boot Options: After your reboot completes, reopen the Terminal screen and run sudo raspi-config again. Select the third option, Boot Options. There are four different boot mode options to choose from:

    The Boot Options menu

  3. Here, you can choose to start the Raspbian desktop or just boot into a command-line interface. It also gives you choices on requiring logins or not; if automatic login is chosen, you won't need to enter the password, so if you want a little bit of security, select one of the options that require the user to log in. My preference is Text console, requiring user to login, because it gives you a bit of security and requires less CPU and memory than running the desktop. If I need the desktop, it is simple to start it with startx. You can do a lot with Linux just from the command line, so a lot of the time, the desktop GUI isn't necessary.
  4. Overclocking: Option 8, Overclocking, returns a rather un-fun message to the user. I'm not sure whether this is the latest version of Raspian's raspi-config program or whether it applies to both the Raspberry Pi Zero and the Raspberry Pi 3, but the same message was returned on both.

    An attempt to overclock from raspi-config does not return an optimistic response:

    No overclock for you!

    It was discovered in late 2015 that overclocking options on the Raspberry Pi Zero only caused it to slow down, so the latest version of raspi-config does not assist with overclocking. This doesn't mean it is impossible, however-just not advised.

  5. Open the following file: $ sudo grep arm /boot/config.txt #uncomment to overclock the arm. 700 MHz is the default. #arm_freq=800
  6. This does hint that overclocking is still possible at startup using the config.txt file. Commenting out arm_freq=800 in the /boot/config.txt file to a higher frequency should work, although the Raspberry Pi community suggests that it doesn't, and perhaps even reduces performance. Even more interestingly, looking at the running settings of a Raspberry Pi Zero suggests that it is already being overclocked to 1 GHz, compared to the former setting of 700 MHz on older Raspberry Pi models: $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq 1000000 $ cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq 1000000 $ cat /sys/devices/system/cpu/cpu0/cpufreq/ scaling_available_frequencies 700000 1000000

    This output suggests that it is already running at 1 GHz and has options to run from 700 MHz to 1 GHz. You can play around with overclocking, and I suppose it was possible to push the B+ Pis to the 1.1 GHz range-you will probably see too much instability from setting it to anything much higher than that. If it becomes unusable, you should be able to recover by commenting out your arm_freq change in the config.txt file from a stable machine. Now let's work on creating new users:

  7. Creating new users is very easy on Raspbian. Here, we will create one named rpz with a home directory located in /home/rpz: pi@raspberrypi:~ $ sudo adduser rpz --home /home/rpz Adding user `rpz' ... Adding new group `rpz' (1002) ... Adding new user `rpz' (1002) with group `rpz' ... Creating home directory `/home/rpz' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for rpz Enter the new value, or press ENTER for the default Full Name []: Raspberry Pi Cookbook Room Number []: Work Phone []: 123-456-7890 Home Phone []: 234-456-7890 Other []: Is the information correct? [Y/n] y
  8. This will create the new user's home directory and prompt you for the password. Once you have this set up, you can log on as this user. This will give the user their own home directory in /home/username and the ability to execute applications. The users are stored in a file called /etc/passwd.
  9. To look at your user, you can look at the end of this file: pi@rpz14101:~ $ cat /etc/passwd | tail -5 lightdm:x:109:114:Light Display Manager:/var/lib/lightdm:/bin/false pulse:x:110:116:PulseAudio daemon,,,:/var/run/pulse:/bin/false rtkit:x:111:118:RealtimeKit,,,:/proc:/bin/false ed:x:1001:1001::/home/ed:/bin/bash rpz:x:1002:1002:Raspberry Pi Cookbook,,123-456 -7890,234-456-7890:/home/rpz:/bin/bash
  10. The last entry is the user just created: rpz:x:1002:1002:Raspberry Pi Cookbook,,123-456- 7890,234-456-7890:/home/rpz:/bin/bash

This breaks down to fields separated by a colon (:):

  • rpz is the name
  • x indicates that there is an encrypted password stored in the /etc/shadow file
  • 1002 is the user ID
  • 1002 is also the group ID, automatically generated when the user was created
  • The next few fields are user ID Information
  • /home/rpz is the home directory-the location the user will start in when they log on
  • /bin/bash is the default command shell-the shell that the user will use when logging in.

There's more...


Before logging on as your new user, you might want to give them the ability to do superuser things, like the pi account does. Let's take a look at how to give your new user more powers!

Note


What is this sudo thing anyway? If you are new to Linux, it probably seems strange to see a lot of these commands start with sudo. This command means superuser-do, which puts the command in a temporary elevated state. sudo is intended to prevent regular users from being able to do something they shouldn't (such as formatting a disk or deleting a filesystem), but it gives certain users powers to do those things if they specifically ask for elevation. It also logs attempts at trying to run things with elevated permissions that users were not given permission to do. It should become more clear as we move through the cookbook, but if you find yourself typing a command, failing, and then typing it again with sudo when you realize your mistake, you are already living the life of many experienced Linux users.

To give your user the ability to run as a superuser, use the visudo tool:

sudo visudo

This opens an edit window of the sudoers file, which will allow you to give your new user special permissions. Look down to where the pi user is already set up, and add rpz ALL=(ALL) ALL, like this:

#includedir /etc/sudoers.d pi ALL=(ALL) NOPASSWD: ALL rpz ALL=(ALL) ALL

This gives your user the same permissions as the pi user, but requires that you enter a password when executing something that requires elevated permissions. This way, you can prevent the unauthorized execution of things that only a superuser should execute.

You can try logging in as our new user and trying to sudo. The touch command creates an empty file wherever you tell it to. If you don't have permissions to write, the touch command will fail. We will try logging on as our rpz user and trying touch with and without sudo, in a directory that requires elevated permission to write to. Use the su command to log on as another...

Erscheint lt. Verlag 24.3.2017
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Programmiersprachen / -werkzeuge
Informatik Weitere Themen Hardware
ISBN-10 1-78646-647-3 / 1786466473
ISBN-13 978-1-78646-647-1 / 9781786466471
Informationen gemäß Produktsicherheitsverordnung (GPSR)
Haben Sie eine Frage zum Produkt?
EPUBEPUB (Ohne DRM)

Digital Rights Management: ohne DRM
Dieses eBook enthält kein DRM oder Kopier­schutz. Eine Weiter­gabe an Dritte ist jedoch rechtlich nicht zulässig, weil Sie beim Kauf nur die Rechte an der persön­lichen Nutzung erwerben.

Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür die kostenlose Software Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich