Wiki

Reso-nance numérique | Arts et cultures libres

Outils du site


Panneau latéral

materiel:mcp3008:accueil

Ceci est une ancienne révision du document !


Table des matières

MCP 3008

<blockquote>Le Raspberry pi est doté des GPIO, capables de servir d’entrées(tuto) ou de sorties(tuto) numériques. On peut donc lire des signaux logiques hauts ou bas (des 0 ou des 1). Il n’est en revanche pas possible de lire directement des valeurs analogiques. Pour cela, il faut utiliser un ADC, pour “Analog to Digital Converter”, ou convertisseur analogique vers numérique en français, dont le Raspberry Pi n’est pas doté. L’objet de ce tutoriel sera justement de connecter une puce, la MCP3008, au Raspberry pi via le bus SPI pour ajouter huit entrées analogiques.</blockquote>

Ressources

Connection

Connections SPI (logiciel) :

  • MCP3008 VDD to Raspberry Pi 3.3V ou 5V
  • MCP3008 VREF to Raspberry Pi 3.3V ou 5V
  • MCP3008 AGND to Raspberry Pi GND
  • MCP3008 DGND to Raspberry Pi GND
  • MCP3008 CLK to Raspberry Pi pin 18
  • MCP3008 DOUT to Raspberry Pi pin 23
  • MCP3008 DIN to Raspberry Pi pin 24
  • MCP3008 CS/SHDN to Raspberry Pi pin 25

Autres connections possibles en mode “hardware”.

Installation

sudo apt-get update
sudo apt-get install build-essential python-pip python-dev python-smbus git
sudo pip3 install python-osc

GPIO

git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO
sudo python3 setup.py install

MCP3008

git clone https://github.com/adafruit/Adafruit_Python_MCP3008.git
cd Adafruit_Python_MCP3008
sudo python3 setup.py install

Code

Code pour recevoir via python dans pdextended les valeurs analogiques du MCP3008

"""
Get Analog sensors from mcp3008 and send to OSC
 
"""
 
import time
from pythonosc import udp_client
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008
 
 
# Software SPI configuration:
CLK  = 18
MISO = 23
MOSI = 24
CS   = 25
SECONDS = 0.02
 
 
if __name__ == "__main__":
    mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)
    client = udp_client.SimpleUDPClient("127.0.0.1", 8000)
 
    # Main program loop.
    while True:
        # Read all the ADC channel values in a list.
        values = [0]*8
        for i in range(8):
            # The read_adc function will get the value of the specified channel (0-7).
            values[i] = mcp.read_adc(i)
            client.send_message("/ana"+str(i), values[i])
        # Pause for half a second.
        time.sleep(SECONDS)
/home/resonancg/www/wiki/data/attic/materiel/mcp3008/accueil.1505059446.txt.gz · Dernière modification: 2017/09/10 18:04 de resonance