Getting Started with Sensors by Kimmo Karvinen and Tero Karvinen
Author:Kimmo Karvinen and Tero Karvinen
Language: eng
Format: mobi, epub
Tags: COMPUTERS / Programming / Open Source
ISBN: 9781449367039
Publisher: Maker Media, Inc
Published: 2014-08-25T04:00:00+00:00
In the following projects, we’ll show you how to use the GPIO pins from a Python program. All of the sensor projects in this book use Python.
Python is one of the easiest languages to learn. When we code for fun, most often it’s in Python. Before we get into programming GPIOs with Python, let’s get you up and running with the language.
Hello, Python World
Traditionally, the first program to write in any language is “Hello, world.” It lets you test to confirm that everything is working. If you are a beginner, you’ll also get assurance that you know how to write a Python program!
Whenever you start programming, you should always start with a “Hello, world” — on any language, on any platform.
You’ll write your Python program just like any text file. The best place to store your program files is in your home directory (/home/pi). If you’re not already in your home directory, you can change to it with the terminal (LXTerminal) command cd:
$ cd /home/pi
Start editing a new file with nano, a command-line text editor for editing plain-text files. Its purpose is similar to other plain-text editors such as Notepad, gedit, vi, and Emacs. Type this command:
$ nano hello.py
The file needs only one line. This is Python for you: easy things are so easy, but hard things are still possible. Add this line to the file:
print("Hello, world!")
The code has just one line. print() is a command, but it behaves like a function. It gets one argument, the string “Hello, world!” As you probably guessed, you are asking the computer to print the string to the terminal.
Now save your work by pressing Ctrl-X (exit). When prompted about whether you want to save, type “y” for yes. Finally, confirm the name, “hello.py”, by pressing Enter or Return.
Now it’s time to run your Python program. This is a big moment if this is your first step in Python. Type the command shown after the $ prompt. You’ll see the output as soon as you press Enter:
$ python hello.py Hello, world!
Your Python program printed the string “Hello, world!” Now you know you can write Python, and that your Python environment works.
Download
Getting Started with Sensors by Kimmo Karvinen and Tero Karvinen.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Automotive | Engineering |
Transportation |
Whiskies Galore by Ian Buxton(41491)
Introduction to Aircraft Design (Cambridge Aerospace Series) by John P. Fielding(32858)
Small Unmanned Fixed-wing Aircraft Design by Andrew J. Keane Andras Sobester James P. Scanlan & András Sóbester & James P. Scanlan(32535)
Craft Beer for the Homebrewer by Michael Agnew(17903)
Turbulence by E. J. Noyes(7661)
The Complete Stick Figure Physics Tutorials by Allen Sarah(7098)
Kaplan MCAT General Chemistry Review by Kaplan(6549)
The Thirst by Nesbo Jo(6408)
Bad Blood by John Carreyrou(6246)
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6208)
Learning SQL by Alan Beaulieu(5996)
Weapons of Math Destruction by Cathy O'Neil(5780)
Man-made Catastrophes and Risk Information Concealment by Dmitry Chernov & Didier Sornette(5594)
Digital Minimalism by Cal Newport;(5327)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5150)
iGen by Jean M. Twenge(5128)
Secrets of Antigravity Propulsion: Tesla, UFOs, and Classified Aerospace Technology by Ph.D. Paul A. Laviolette(4864)
Design of Trajectory Optimization Approach for Space Maneuver Vehicle Skip Entry Problems by Runqi Chai & Al Savvaris & Antonios Tsourdos & Senchun Chai(4808)
Electronic Devices & Circuits by Jacob Millman & Christos C. Halkias(4705)
