Book Image

Internet of Things Programming with JavaScript

Book Image

Internet of Things Programming with JavaScript

Overview of this book

The Internet of Things is taking the tech world by storm, and JavaScript is at its helm. This book will get you to grips with this exciting new technology. Where do Node.js, HTML5 and Windows 10 IoT Core come in with JavaScript and IoT? Why Raspberry Pi Zero rather than Arduino? How do you configure and build an IoT network from scratch? All your IoT JavaScript questions are answered in this book.
Table of Contents (15 chapters)
Internet of Things Programming with JavaScript
Credits
About the Author
www.packtpub.com
Customer Feedback
Preface

Connecting analog inputs using an MCP3008 ADC Converter


If we want to connect analog sensors to the Raspberry Pi, we need to use an Analog-to-Digital Converter (ADC). The board doesn't have analog inputs; we use the MCP3008 to connect analog sensors. This is a 10-bit ADC and has eight channels. This means that you can connect up to eight sensors that can be read from the Raspberry Pi Zero. We don't need special components to connect them. They can be connected with SPI to the Raspberry Pi's GPIOs.

The first step is to enable SPI communication:

  1. Access the Raspberry Pi terminal and type the following command:

    sudo raspi-config
    
  2. Select Advanced Options, as shown in the following screenshot:

  3. Enable SPI communication by selecting the SPI option:

  4. Select <Yes> to enable the SPI interface:

  5. The final screen looks like the following screenshot when we enable the SPI interface. Select <Ok>: