Python Programming for Arduino
eBook - ePub

Python Programming for Arduino

Pratik Desai

Share book
  1. 400 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Python Programming for Arduino

Pratik Desai

Book details
Book preview
Table of contents
Citations

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Python Programming for Arduino an online PDF/ePUB?
Yes, you can access Python Programming for Arduino by Pratik Desai in PDF and/or ePUB format, as well as other popular books in Computer Science & Programming Languages. We have over one million books available in our catalogue for you to explore.

Information

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 th...

Table of contents