ebook img

Smart computing with open source platforms PDF

263 Pages·2019·8.726 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Smart computing with open source platforms

Smart Computing with Open Source Platforms Smart Computing with Open Source Platforms Amartya Mukherjee and Nilanjan Dey CRC Press Taylor & Francis Group 52 Vanderbilt Avenue, New York, NY 10017 © 2019 by Taylor & Francis Group, LLC CRC Press is an imprint of Taylor & Francis Group, an Informa business No claim to original U.S. Government works Printed on acid-free paper International Standard Book Number-13: 978-0-8153-5952-4 (Paperback) International Standard Book Number-13: 978-0-8153-5955-5 (Hardback) This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been made to publish reliable data and information, but the author and publisher cannot assume responsibility for the validity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may rectify in any future reprint. Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. For permission to photocopy or use material electronically from this work, please access www. copyright.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged. Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for identification and explanation without intent to infringe. Visit the Taylor & Francis Web site at http://www.taylorandfrancis.com and the CRC Press Web site at http://www.crcpress.com Contents Preface ...................................................................................................................xiii Acknowledgment ..................................................................................................xv Authors ................................................................................................................xvii Introduction .........................................................................................................xix 1. Introduction to Open Source Hardware ....................................................1 1.1 Open Source Hardware Concept ........................................................1 1.2 Arduino Ecosystem and Its Types ......................................................1 1.3 Features of Arduino Hardware ..........................................................3 1.4 Features of Arduino Software .............................................................3 1.5 How to Set Up ........................................................................................6 1.6 Arduino DUE Environment ................................................................9 1.7 Arduino Development Community and Social Coding ...............10 1.8 Concepts Covered in This Chapter ..................................................10 References .......................................................................................................11 2. Arduino Hardware .......................................................................................13 2.1 System Architecture ...........................................................................13 2.2 Microcontroller ....................................................................................14 2.2.1 Power Unit ..............................................................................16 2.2.2 Digital I/O of Arduino ..........................................................16 2.2.3 ADC Inputs .............................................................................16 2.2.4 Peripherals in Arduino .........................................................17 2.2.5 Detailed Board Configuration .............................................17 2.3 Arduino Interrupts .............................................................................18 2.3.1 Comparison Register .............................................................18 2.4 Peripheral Devices and Interfacing ..................................................18 2.4.1 Arduino TFT Interfacing ......................................................19 2.4.2 Using the Library ...................................................................20 2.4.3 Using the Arduino Esplora and the TFT Library ..............20 2.4.4 Similarities in Processing .....................................................21 2.5 Concepts Covered in This Chapter ..................................................21 References .......................................................................................................21 3. Data Types, Operators, and Expressions .................................................23 3.1 Primitive Data Types ..........................................................................23 3.1.1 Integer ......................................................................................23 3.1.2 Byte ..........................................................................................24 3.1.3 O ther Types of int ..................................................................24 3.1.4 I nteger Constant .....................................................................24 v vi Contents 3.1.5 Characters ...............................................................................24 3.1.6 Floating Point Data ................................................................25 3.1.7 Array and String in Arduino ...............................................25 3.1.8 Strings ......................................................................................26 3.2 User-Defined Data Types ...................................................................28 3.3 Declaration of a Variable ....................................................................29 3.4 Operators ..............................................................................................30 3.5 Precedence and Associativity ...........................................................31 3.6 Concepts Covered in This Chapter ..................................................32 References .......................................................................................................32 4. Functions in Arduino ...................................................................................33 4.1 setup() and loop() Functions .......................................................33 4.2 User-Defined Functions .....................................................................34 4.3 Recursive Function Calls ...................................................................35 4.4 Library ..................................................................................................38 4.4.1 EEPROM Library....................................................................39 4.4.1.1 read() .....................................................................39 4.4.1.2 write() ...................................................................40 4.4.1.3 put() ........................................................................40 4.4.1.4 get() ........................................................................41 4.4.1.5 update() .................................................................41 4.4.2 Firmata Library ......................................................................42 4.5 Concepts Covered in This Chapter ..................................................44 References .......................................................................................................44 5. Conditional Statements ...............................................................................45 5.1 If-Else Conditional Statements ..........................................................45 5.1.1 Else ...........................................................................................46 5.1.2 If-Else-If Ladder .....................................................................46 5.2 Switch-Case Statement .......................................................................46 5.3 Loops in Arduino ................................................................................47 5.3.1 For loop ....................................................................................47 5.4 While and Do-While Loops ...............................................................48 5.4.1 While Loop .............................................................................48 5.4.2 Do-While Loop .......................................................................49 5.5 loop() in Arduino .............................................................................49 5.6 Concepts Covered in This Chapter ..................................................50 References .......................................................................................................50 6. Arduino Input Systems ...............................................................................51 6.1 pinMode() Function ..........................................................................51 6.2 INPUT and INPUT_PULLUP Configuration ..................................52 6.3 digitalRead() Function .................................................................53 Contents vii 6.4 analogRead() Function ...................................................................54 6.5 Inputs for Firmata Library .................................................................55 6.6 Input Device Interfacing ....................................................................56 6.6.1 Input Pin Properties ..............................................................56 6.7 Concepts Covered in This Chapter ..................................................57 References .......................................................................................................57 7. Arduino Output Systems ............................................................................59 7.1 digitalWrite() Function ...............................................................59 7.2 analogWrite() Function .................................................................60 7.2.1 Operation ................................................................................60 7.2.2 PWM details ...........................................................................61 7.2.3 ATmega PWM Access ...........................................................61 7.3 An Input–Output Example ................................................................64 7.4 Concepts Covered in This Chapter ..................................................67 References .......................................................................................................68 8. Arduino with Processing ............................................................................69 8.1 Overview of Processing Language ...................................................69 8.1.1 G eneral Overview ..................................................................69 8.1.2 P rocessing Software ..............................................................70 8.2 Code Structure.....................................................................................72 8.2.1 P rocessing Code .....................................................................72 8.2.2 D rawing the Objects ..............................................................73 8.3 Libraries and Functions .....................................................................74 8.3.1 S erial Library ..........................................................................74 8.4 Visualization of an LDR Output .......................................................75 8.5 Interaction with Arduino and Firmata ............................................77 8.6 Mouse Handling in Processing .........................................................84 8.7 Colors in Processing ...........................................................................88 8.8 Concepts Covered in This Chapter ..................................................90 References .......................................................................................................90 9. Real-Life Code Examples ............................................................................91 9.1 Automated Rail Gate Control ............................................................91 9.1.1 Stepwise Procedure ...............................................................91 9.1.2 Circuit Diagram .....................................................................92 9.2 Arduino-Based Heartrate Monitoring System ...............................94 9.2.1 Working Methodology ..........................................................95 9.3 Arduino-Based LPG Detector System ..............................................98 9.3.1 Working Principle ..................................................................98 9.4 Conclusion ..........................................................................................100 9.5 Concepts Covered in This Chapter ................................................100 References .....................................................................................................100 viii Contents 10. Introduction to Python Language ...........................................................101 10.1 Features of Python Language .........................................................101 10.2 Python Versions ................................................................................102 10.3 Python Installation ...........................................................................103 10.3.1 D etailed Installation Procedure in Windows ..................104 10.3.2 I nstalling Python in Ubuntu Linux ..................................104 10.3.3 I nstallation of Python Using the Source in Ubuntu .......104 10.4 Writing Some Basic Programs .........................................................105 10.5 Installation Using pip .......................................................................107 10.6 Concepts Covered in This Chapter ................................................109 References .....................................................................................................109 11. Operators, Variables, and Expressions ...................................................111 11.1 Operators in Python .........................................................................111 11.1.1 Arithmetic Operators ..........................................................111 11.1.2 Comparison Operators ........................................................112 11.1.3 Logical Operators.................................................................112 11.1.4 Bitwise Operators ................................................................113 11.1.5 Identity Operators in Python .............................................114 11.1.6 Membership Operators .......................................................115 11.1.7 Assignment Operators ........................................................115 11.2 Clearing the Screen of the Console ................................................116 11.3 Concepts Covered in This Chapter ................................................116 References .....................................................................................................117 12. Decision-Making and Control Flow .......................................................119 12.1 if Statement ......................................................................................119 12.2 If-elif-else Ladder......................................................................120 12.2.1 Ladder Representation ........................................................120 12.2.2 Ternary Operator .................................................................121 12.3 Loops in Python ................................................................................122 12.3.1 while Loop ..........................................................................122 12.3.2 for Loop ...............................................................................124 12.3.3 Nested Loops ........................................................................125 12.3.4 Odd Loops ............................................................................125 12.3.5 break and continue Statements .....................................125 12.4 Concepts Covered in This Chapter ................................................126 References .....................................................................................................126 13. Functions in Python ...................................................................................127 13.1 Standard Rule of Definition .............................................................127 13.2 Function Invocation ..........................................................................128 13.2.1 Invocation Methodology .....................................................128 13.2.2 Argument Passing Mechanisms ........................................129 Contents ix 13.3 Keyword Argument Concept ..........................................................130 13.4 Lambda Function ..............................................................................131 13.5 Modules in Python ...........................................................................132 13.5.1 from Statement ....................................................................132 13.5.2 dir() Function ....................................................................133 13.6 Package in Python .............................................................................133 13.7 reload(), global(), and local() .........................................134 13.8 Concepts Covered in This Chapter ................................................134 References .....................................................................................................134 14. More Examples of Modules and Functions with APIs .......................135 14.1 Accessing CSV Files ..........................................................................135 14.1.1 Reading CSV Data ...............................................................136 14.1.2 Loading CSV Using Pandas ...............................................136 14.2 Parsing JSON Data ............................................................................136 14.3 Working with MongoDB ..................................................................138 14.4 MongoDB Client Management Tools .............................................141 14.5 Concepts Covered in This Chapter ................................................142 References .....................................................................................................142 15. Implementation of Data Structures ........................................................143 15.1 Lists in Python ...................................................................................143 15.1.1 Updating and Deleting List Elements ..............................144 15.1.2 Fundamental List Operation ..............................................145 15.2 Tuples in Python................................................................................145 15.3 Dictionary Structure .........................................................................146 15.4 Sorting of Data Structures ...............................................................147 15.5 Date and Time in Python .................................................................149 15.6 Strings in Python ..............................................................................150 15.7 Concepts Covered in This Chapter ................................................151 References .....................................................................................................152 16. Object-Oriented Programming in Python ............................................153 16.1 Class in Python ..................................................................................153 16.2 Constructor ........................................................................................154 16.3 Creation of Methods in Class ..........................................................155 16.4 Polymorphism in Python .................................................................155 16.5 Inheritance Concept ..........................................................................157 16.6 Method Overriding Concept ...........................................................159 16.7 Concepts Covered in This Chapter ................................................160 References .....................................................................................................160 17. Input and Output in Python .....................................................................161 17.1 input() and raw_input() Functions ........................................161

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.