Modifications

Sauter à la navigation Sauter à la recherche
2 585 octets ajoutés ,  11 juillet 2016 à 10:27
aucun résumé de modification
Ligne 2 : Ligne 2 :     
{{traduction}}
 
{{traduction}}
 +
 +
== Entrée Analogique ==
 +
 +
{{ADFImage|RASP-PYGAME-GUI-Analogique-00.jpg}}
 +
 +
This example uses a 10K potentiometer to provide a varying voltage. For analog to digital I normally use an [http://jeremyblythe.blogspot.co.uk/2012/09/raspberry-pi-hardware-spi-analog-inputs.html MCP3008 over SPI]. That's not possible here though because the PiTFT uses both SPI channels on the Pi. So I've switched to an I2C ADC: [http://www.adafruit.com/product/1085 ADS1115 16-Bit ADC - 4 Channel with Programmable Gain Amplifier].
 +
 +
Get the Adafruit Python library:
 +
 +
<syntaxhighlight lang="bash">
 +
cd /home/pi
 +
git clone https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git
 +
</syntaxhighlight>
 +
 +
If you need to enable i2c follow this guide: Configuring I2C
 +
 +
{{ADFImage|RASP-PYGAME-GUI-Analogique-01.jpg}}
 +
 +
== Démarrage ==
 +
 +
At the top of this script now we have some more imports for the threading and ADC.
 +
 +
The gain and sample rate are configured and the ADC initialized.
 +
 +
<syntaxhighlight lang="python">
 +
import sys
 +
sys.path.append('/home/pi/Adafruit-Raspberry-Pi-Python-Code/Adafruit_ADS1x15')
 +
 +
import pygame
 +
import os
 +
import pygameui as ui
 +
import logging
 +
import RPi.GPIO as GPIO
 +
import signal
 +
from Adafruit_ADS1x15 import ADS1x15
 +
import threading
 +
import time
 +
 +
ADS1015 = 0x00  # 12-bit ADC
 +
ADS1115 = 0x01  # 16-bit ADC
 +
 +
# Select the gain
 +
# gain = 6144  # +/- 6.144V
 +
gain = 4096  # +/- 4.096V
 +
# gain = 2048  # +/- 2.048V
 +
# gain = 1024  # +/- 1.024V
 +
# gain = 512  # +/- 0.512V
 +
# gain = 256  # +/- 0.256V
 +
 +
# Select the sample rate
 +
sps = 8    # 8 samples per second
 +
# sps = 16  # 16 samples per second
 +
# sps = 32  # 32 samples per second
 +
# sps = 64  # 64 samples per second
 +
# sps = 128  # 128 samples per second
 +
# sps = 250  # 250 samples per second
 +
# sps = 475  # 475 samples per second
 +
# sps = 860  # 860 samples per second
 +
 +
# Initialise the ADC using the default mode (use default I2C address)
 +
# Set this to ADS1015 or ADS1115 depending on the ADC you are using!
 +
adc = ADS1x15(ic=ADS1115)
 +
 +
#Setup the GPIOs as outputs - only 4 and 17 are available
 +
GPIO.setmode(GPIO.BCM)
 +
GPIO.setup(4, GPIO.OUT)
 +
GPIO.setup(17, GPIO.OUT)
 +
 +
log_format = '%(asctime)-6s: %(name)s - %(levelname)s - %(message)s'
 +
console_handler = logging.StreamHandler()
 +
console_handler.setFormatter(logging.Formatter(log_format))
 +
logger = logging.getLogger()
 +
logger.setLevel(logging.DEBUG)
 +
logger.addHandler(console_handler)
 +
 +
os.putenv('SDL_FBDEV', '/dev/fb1')
 +
os.putenv('SDL_MOUSEDRV', 'TSLIB')
 +
os.putenv('SDL_MOUSEDEV', '/dev/input/touchscreen')
 +
 +
MARGIN = 20
 +
</syntaxhighlight>
 +
 +
== Le thread du potentiomètre ==
 +
xxx
 +
    
{{RASP-PYGAME-GUI-TRAILER}}
 
{{RASP-PYGAME-GUI-TRAILER}}
29 918

modifications

Menu de navigation