Book Image

Internet of Things with Python

By : Gaston C. Hillar
Book Image

Internet of Things with Python

By: Gaston C. Hillar

Overview of this book

Internet of Things (IoT) is revolutionizing the way devices/things interact with each other. And when you have IoT with Python on your side, you'll be able to build interactive objects and design them. This book lets you stay at the forefront of cutting-edge research on IoT. We'll open up the possibilities using tools that enable you to interact with the world, such as Intel Galileo Gen 2, sensors, and other hardware. You will learn how to read, write, and convert digital values to generate analog output by programming Pulse Width Modulation (PWM) in Python. You will get familiar with the complex communication system included in the board, so you can interact with any shield, actuator, or sensor. Later on, you will not only see how to work with data received from the sensors, but also perform actions by sending them to a specific shield. You'll be able to connect your IoT device to the entire world, by integrating WiFi, Bluetooth, and Internet settings. With everything ready, you will see how to work in real time on your IoT device using the MQTT protocol in python. By the end of the book, you will be able to develop IoT prototypes with Python, libraries, and tools.
Table of Contents (19 chapters)
Internet of Things with Python
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Using the I2C bus to control a digital accelerometer with the mraa library


Sometimes, the features included in the upm library for a specific sensor do not include all of its possible usages and configurations. An example of this situation is the upmAdxl345.Adxl345 class that we used in our previous example. This class doesn't allow us to configure the desired scale for the accelerometer while the sensor supports the following four selectable measurement ranges: ±2g, ±4g, ±8g and ±16g. If we want to use specific features that aren't included in the upm module, we can use the appropriate mraa class to interact with the sensor, in this case, we can use mraa.I2c to control the digital accelerometer through the I2C bus.

We will use the C++ source code for the upm module as a baseline to write our own Python code that controls the accelerometer through the I2C bus using the mraa.I2c class. The C++ source code file is adxl1345.cxx and it can be found in the following GitHub URL: http://github.com...