售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Python Programming for Arduino
Table of Contents
Python Programming for Arduino
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with Python and Arduino
Introduction to Python
Why we use Python
When do we use other languages
Installing Python and Setuptools
Installing Python
Linux
Ubuntu
Fedora and Red Hat
Windows
Mac OS X
Installing Setuptools
Linux
Windows
Mac OS X
Installing pip
Installing Python packages
The fundamentals of Python programming
Python operators and built-in types
Operators
Built-in types
Data structures
Lists
Tuples
Sets
Dictionaries
Controlling the flow of your program
The if statement
The for statement
The while statement
Built-in functions
Conversions
Math operations
String operations
Introduction to Arduino
History
Why Arduino?
Arduino variants
The Arduino Uno board
Installing the Arduino IDE
Linux
Mac OS X
Windows
Getting started with the Arduino IDE
What is an Arduino sketch?
Working with libraries
Using Arduino examples
Compiling and uploading sketches
Using the Serial Monitor window
Introduction to Arduino programming
Comments
Variables
Constants
Data types
Conversions
Functions and statements
The setup() function
The loop() function
The pinMode() function
Working with pins
Statements
Summary
2. Working with the Firmata Protocol and the pySerial Library
Connecting the Arduino board
Linux
Mac OS X
Windows
Troubleshooting
Introducing the Firmata protocol
What is Firmata?
Uploading a Firmata sketch to the Arduino board
Testing the Firmata protocol
Getting started with pySerial
Installing pySerial
Playing with a pySerial example
Bridging pySerial and Firmata
Summary
3. The First Project – Motion-triggered LEDs
Motion-triggered LEDs – the project description
The project goal
The list of components
The software flow design
The hardware system design
Introducing Fritzing – a hardware prototyping software
Working with the breadboard
Designing the hardware prototype
Testing hardware connections
Method 1 – using a standalone Arduino sketch
The project setup
The Arduino sketch
The setup() function
The loop() function
Working with custom Arduino functions
Testing
Troubleshooting
Method 2 – using Python and Firmata
The project setup
Working with Python executable files
The Python code
Working with pyFirmata methods
Working with Python functions
Testing
Troubleshooting
Summary
4. Diving into Python-Arduino Prototyping
Prototyping
Working with pyFirmata methods
Setting up the Arduino board
Configuring Arduino pins
The direct method
Assigning pin modes
Working with pins
Reporting data
Manual operations
The write() method
The read() method
Additional functions
Upcoming functions
Prototyping templates using Firmata
Potentiometer – continuous observation from an analog input
Connections
The Python code
Buzzer – generating sound alarm pattern
Connections
The Python code
DC motor – controlling motor speed using PWM
Connections
The Python code
LED – controlling LED brightness using PWM
Connections
The Python code
Servomotor – moving the motor to a certain angle
Connections
The Python code
Prototyping with the I2C protocol
Arduino examples for I2C interfacing
Arduino coding for the TMP102 temperature sensor
Arduino coding for the BH1750 light sensor
PyMata for quick I2C prototyping
Interfacing TMP102 using PyMata
Interfacing BH1750 using PyMata
Useful pySerial commands
Connecting with the serial port
Reading a line from the port
Flushing the port to avoid buffer overflow
Closing the port
Summary
5. Working with the Python GUI
Learning Tkinter for GUI design
Your first Python GUI program
The root widget Tk() and the top-level methods
The Label() widget
The Pack geometry manager
The Button() widget – interfacing GUI with Arduino and LEDs
The Entry() widget – providing manual user inputs
The Scale() widget – adjusting the brightness of an LED
The Grid geometry manager
The Checkbutton() widget – selecting LEDs
The Label() widget – monitoring I/O pins
Remaking your first Python-Arduino project with a GUI
Summary
6. Storing and Plotting Arduino Data
Working with files in Python
The open() method
The write() method
The close() method
The read() method
The with statement – Python context manager
Using CSV files to store data
Storing Arduino data in a CSV file
Getting started with matplotlib
Configuring matplotlib on Windows
Configuring matplotlib on Mac OS X
Upgrading matplotlib
Troubleshooting installation errors
Setting up matplotlib on Ubuntu
Plotting random numbers using matplotlib
Plotting data from a CSV file
Plotting real-time Arduino data
Integrating plots in the Tkinter window
Summary
7. The Midterm Project – a Portable DIY Thermostat
Thermostat – the project description
Project background
Project goals and stages
The list of required components
Hardware design
Software flow for user experience design
Stage 1 – prototyping the thermostat
The Arduino sketch for the thermostat
Interfacing the temperature sensor
Interfacing the humidity sensor
Interfacing the light sensor
Using Arduino interrupts
Designing the GUI and plot in Python
Using pySerial to stream sensor data in your Python program
Designing the GUI using Tkinter
Plotting percentage humidity using matplotlib
Using button interrupts to control the parameters
Changing the temperature unit by pressing a button
Swapping between the GUI and the plot by pressing a button
Troubleshooting
Stage 2 – using a Raspberry Pi for the deployable thermostat
What is a Raspberry Pi?
Installing the operating system and configuring the Raspberry Pi
What do you need to begin using the Raspberry Pi?
Preparing an SD card
The Raspberry Pi setup process
Using a portable TFT LCD display with the Raspberry Pi
Connecting the TFT LCD using GPIO
Configuring the TFT LCD with the Raspberry Pi OS
Optimizing the GUI for the TFT LCD screen
Troubleshooting
Summary
8. Introduction to Arduino Networking
Arduino and the computer networking
Networking fundamentals
Obtaining the IP address of your computer
Windows
Mac OS X
Linux
Networking extensions for Arduino
Arduino Ethernet Shield
Arduino WiFi Shield
Arduino Yún
Arduino Ethernet library
The Ethernet class
The IPAddress class
The Server class
The Client class
Exercise 1 – a web server, your first Arduino network program
Developing web applications using Python
Python web framework – web.py
Installing web.py
Your first Python web application
Essential web.py concepts for developing complex web applications
Handling URLs
The GET and POST methods
Templates
Forms
Exercise 2 – playing with web.py concepts using the Arduino serial interface
RESTful web applications with Arduino and Python
Designing REST-based Arduino applications
Working with the GET request from Arduino
The Arduino code to generate the GET request
The HTTP server using web.py to handle the GET request
Working with the POST request from Arduino
The Arduino code to generate the POST request
The HTTP server using web.py to handle the POST request
Exercise 3 – a RESTful Arduino web application
The Arduino sketch for the exercise
The web.py application to support REST requests
Why do we need a resource-constrained messaging protocol?
MQTT – A lightweight messaging protocol
Introduction to MQTT
Mosquitto – an open source MQTT broker
Setting up Mosquitto
Getting familiar with Mosquitto
Getting started with MQTT on Arduino and Python
MQTT on Arduino using the PubSubClient library
Installing the PubSubClient library
Developing the Arduino MQTT client
MQTT on Python using paho-mqtt
Installing paho-mqtt
Using the paho-mqtt Python library
Exercise 4 – MQTT Gateway for Arduino
Developing Arduino as the MQTT client
Developing the MQTT Gateway using Mosquitto
Extending the MQTT Gateway using web.py
Testing your Mosquitto Gateway
Summary
9. Arduino and the Internet of Things
Getting started with the IoT
Architecture of IoT web applications
Hardware design
The IoT cloud platforms
Xively – a cloud platform for the IoT
Setting up an account on Xively
Working with Xively
Alternative IoT platforms
ThingSpeak
Carriots
Developing cloud applications using Python and Xively
Interfacing Arduino with Xively
Uploading Arduino data to Xively
Downloading data to Arduino from Xively
Advanced code to upload and download data using Arduino
Python – uploading data to Xively
The basic method for sending data
Uploading data using a web interface based on web.py
Python – downloading data from Xively
The basic method for retrieving data from Xively
Retrieving data from the web.py web interface
Triggers – custom notifications from Xively
Your own cloud platform for the IoT
Getting familiar with the Amazon AWS platform
Setting up an account on AWS
Creating a virtual instance on the AWS EC2 service
Logging into your virtual instance
Creating an IoT platform on the EC2 instance
Installing the necessary packages on AWS
Configuring the security of the virtual instance
Testing your cloud platform
Testing the Mosquitto service
Configuring and testing basic security
Uploading and testing a project on the instance
Summary
10. The Final Project – a Remote Home Monitoring System
The design methodology for IoT projects
Project overview
The project goals
The project requirements
Designing system architecture
The monitoring station
The control center
The cloud services
Defining UX flow
The list of required components
Defining the project development stages
Stage 1 – a monitoring station using Arduino
Designing the monitoring station
The Arduino sketch for the monitoring station
Publishing sensor information
Subscribing to actuator actions
Programming an interrupt to handle the press of a button
Testing
Stage 2 – a control center using Python and the Raspberry Pi
The control center architecture
The Python code for the control center
Creating the GUI using Tkinter
Communicating with the Mosquitto broker
Calculating the system's status and situation awareness
Communicating with Xively
Checking and updating the buzzer's status
Testing the control center with the monitoring station
Setting up the control center on the Raspberry Pi
Stage 3 – a web application using Xively, Python, and Amazon cloud service
Architecture of the cloud services
Python web application hosted on Amazon AWS
Testing the web application
Testing and troubleshooting
Extending your remote home monitoring system
Utilizing multiple monitoring stations
Extending sensory capabilities
Improving UX
Expanding cloud-based features
Improving intelligence for situation awareness
Creating an enclosure for hardware components
Summary
11. Tweet-a-PowerStrip
Project overview
Project requirements
System architecture
Required hardware components
Relays
PowerSwitch Tail
User experience flow
Development and deployment stages
Stage 1 – a smart power strip with Arduino and relays
Hardware design
The Arduino code
Stage 2 – the Python code to process tweets
Python software flow
Setting up the Twitter application
The Python code
Testing and troubleshooting
Extending the project with additional features
Summary
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜