Différences entre versions de « Rasp-Hack-PiAnalog »

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche
Ligne 35 : Ligne 35 :
 
We'll do that by wiring up an MCP3008 chip to it. The MCP3008 acts like a 'bridge' between digital and analog. It has 8 analog inputs and the Pi can query it using 4 digital pins. That makes it a perfect addition to the Pi for integrating simple sensors like photocells, FSRs or potentiometers, thermistors, etc.!
 
We'll do that by wiring up an MCP3008 chip to it. The MCP3008 acts like a 'bridge' between digital and analog. It has 8 analog inputs and the Pi can query it using 4 digital pins. That makes it a perfect addition to the Pi for integrating simple sensors like photocells, FSRs or potentiometers, thermistors, etc.!
  
Lets check the datasheet of the MCP3008 chip. On the first page in the lower right corner there's a pinout diagram showing the names of the pins  
+
Lets check the [http://www.mchobby.be/data-files/datasheet/MCP3008.pdf datasheet of the MCP3008 chip]. On the first page in the lower right corner there's a pinout diagram showing the names of the pins  
  
 
[[Fichier:MCP3008.jpg]]
 
[[Fichier:MCP3008.jpg]]

Version du 10 novembre 2012 à 22:53

Introduction

Apprendre comment lire une tension analogique à l'aide d'un Raspberry Pi pourrait être plus facile que vous ne le pensez!

MCP3008-PiDemo.jpg

Le Pi n'inclus pas de convertisseur Analogique/Digital mais un convertisseur ADC externe tel que le MCP3008 peut être utilisé avec du code Python pour faire une lecture analogique en utilisant le protocole SPI.

Voici une liste de quelques entrées analogiques qui peuvent être lue avec ce montage:

Ce guide utilise un potentiomètre pour controler le volume d'un MP3 en cours de de lecture, mais ce code peut être utilisé comme base pour n'importe quelle lecture analogique.

Le Pi Cobbler d'AdaFruit (disponible chez MC Hobby) est utiliser pour faciliter le montage.

Prérequis

Assurez-vous d'avoir mis votre environnement Python à jour.

Matériel

Pourquoi avons nous besoin d'un ADC?

ADC signifie "Analog to Digital Converter" autrement dit "Convertisseur Analogique vers Digital".

The Raspberry Pi computer does not have a way to read analog inputs. It's a digital-only computer. Compare this to the Arduino, AVR or PIC microcontrollers that often have 6 or more analog inputs! Analog inputs are handy because many sensors are analog outputs, so we need a way to make the Pi analog-friendly.

We'll do that by wiring up an MCP3008 chip to it. The MCP3008 acts like a 'bridge' between digital and analog. It has 8 analog inputs and the Pi can query it using 4 digital pins. That makes it a perfect addition to the Pi for integrating simple sensors like photocells, FSRs or potentiometers, thermistors, etc.!

Lets check the datasheet of the MCP3008 chip. On the first page in the lower right corner there's a pinout diagram showing the names of the pins

MCP3008.jpg

Montage

Voici le détail du montage

Fichier:Pi-MCP3008-Analog.jpg

Source: AdaFruit.com

Code

Voici notre exemple Rasp-PiAnalog.py écrit en python.

#!/usr/bin/env python
# -*- coding: latin-1 -*-

Pour savoir comment télécharger et exécuter ce programme sur votre Py, nous vous proposons de prendre connaissance de notre premiers articles sur Raspberry Pi et LED

Source: AdaFruit Learning System

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com