BARRAUX Arthur 2 years ago
parent
commit
526f84bf57
  1. 173
      Test extension RPI.py
  2. 0
      get_temp.sh

173
Test extension RPI.py

@ -0,0 +1,173 @@
# pour installer la librairie MCP9808 :
# cd ~
# git clone https://github.com/adafruit/Adafruit_Python_MCP9808.git
# Attention à la version de python par défaut ( python --version)
# Si ce n'est pas la bonne :
# sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
# cd Adafruit_Python_MCP9808
# sudo python setup.py install
import RPi.GPIO as GP
import time
import Adafruit_MCP9808.MCP9808 as mcp
import serial
import threading
# initialisation du raspberry
capteurTemp = mcp.MCP9808()
GP.setwarnings(False)
GP.setmode(GP.BOARD)
GP.setup(7,GP.OUT, initial=GP.LOW) # D1, a1
GP.setup(11,GP.OUT, initial=GP.LOW) # D2, b1
GP.setup(13,GP.OUT, initial=GP.LOW) # D3, c1
GP.setup(15,GP.OUT, initial=GP.LOW) # D4, d1
GP.setup(19,GP.OUT, initial=GP.LOW) # D5, e1
GP.setup(21,GP.OUT, initial=GP.LOW) # D6, f1
GP.setup(23,GP.OUT, initial=GP.LOW) # D7, g1
GP.setup(22,GP.OUT, initial=GP.LOW) # D8, DP1
GP.setup(29,GP.OUT, initial=GP.LOW) # a2, RVB rouge
GP.setup(31,GP.OUT, initial=GP.LOW) # b2, RVB bleu
GP.setup(33,GP.OUT, initial=GP.LOW) # c2, RVB vert
GP.setup(35,GP.OUT, initial=GP.LOW) # d2
GP.setup(37,GP.OUT, initial=GP.LOW) # e2
GP.setup(16,GP.OUT, initial=GP.LOW) # f2
GP.setup(18,GP.OUT, initial=GP.LOW) # g2
GP.setup(24,GP.OUT, initial=GP.LOW) # DP2
GP.setup(26,GP.IN) # Bouton poussoir 1
GP.setup(32,GP.IN) # Bouton poussoir 2
#Ouverture et configuration du port UART
monPort = serial.Serial(
port='/dev/ttyS0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
# Lancement d'un thread pour répliquer les octets reçus sur l'uart
def Lire_port():
""" écoute le port UART et renvoie les octets reçus"""
while monPort.isOpen(): # tant que le port est ouvert le thread fonctionne
data = (monPort.read())
if len(data) !=0:
print(data)
monPort.write(data)
threadLectureUART = threading.Thread(target=Lire_port, args=())
threadLectureUART.start()
#Test des boutons poussoir
print ("appuyer sur le bouton poussoir 1")
while GP.input(26):
pass
print("BP1 OK")
print ("appuyer sur le bouton poussoir 2")
while GP.input(32):
pass
print("BP2 OK")
#Test des leds
print("mettre le cavalier en position LED puis appuyer sur BP1 pour lancer le test")
while GP.input(26):
pass
for i in range(5):
GP.output(7, GP.HIGH)
GP.output(11, GP.HIGH)
GP.output(13, GP.HIGH)
GP.output(15, GP.HIGH)
GP.output(19, GP.HIGH)
GP.output(21, GP.HIGH)
GP.output(23, GP.HIGH)
GP.output(22, GP.HIGH)
time.sleep(0.5)
GP.output(7, GP.LOW)
GP.output(11, GP.LOW)
GP.output(13, GP.LOW)
GP.output(15, GP.LOW)
GP.output(19, GP.LOW)
GP.output(21, GP.LOW)
GP.output(23, GP.LOW)
GP.output(22, GP.LOW)
time.sleep(0.5)
#Test afficheurs
print("mettre le cavalier en position afficheur puis appuyer sur BP1 pour lancer le test")
while GP.input(26):
pass
for i in range(5):
GP.output(7, GP.HIGH)
GP.output(11, GP.HIGH)
GP.output(13, GP.HIGH)
GP.output(15, GP.HIGH)
GP.output(19, GP.HIGH)
GP.output(21, GP.HIGH)
GP.output(23, GP.HIGH)
GP.output(22, GP.HIGH)
GP.output(29, GP.HIGH)
GP.output(31, GP.HIGH)
GP.output(33, GP.HIGH)
GP.output(35, GP.HIGH)
GP.output(37, GP.HIGH)
GP.output(16, GP.HIGH)
GP.output(18, GP.HIGH)
GP.output(24, GP.HIGH)
time.sleep(0.5)
GP.output(7, GP.LOW)
GP.output(11, GP.LOW)
GP.output(13, GP.LOW)
GP.output(15, GP.LOW)
GP.output(19, GP.LOW)
GP.output(21, GP.LOW)
GP.output(23, GP.LOW)
GP.output(22, GP.LOW)
GP.output(29, GP.LOW)
GP.output(31, GP.LOW)
GP.output(33, GP.LOW)
GP.output(35, GP.LOW)
GP.output(37, GP.LOW)
GP.output(16, GP.LOW)
GP.output(18, GP.LOW)
GP.output(24, GP.LOW)
time.sleep(0.5)
#Test Led RVB
print("mettre le cavalier en position Led RVB puis appuyer sur BP1 pour lancer le test Led RVB")
while GP.input(26):
pass
GP.output(29, GP.LOW)
time.sleep(0.5)
GP.output(29, GP.HIGH)
GP.output(31, GP.LOW)
time.sleep(0.5)
GP.output(31, GP.HIGH)
GP.output(33, GP.LOW)
time.sleep(0.5)
GP.output(31, GP.LOW)
time.sleep(0.5)
GP.output(31, GP.HIGH)
GP.output(29, GP.LOW)
time.sleep(0.5)
GP.output(29, GP.HIGH)
GP.output(33, GP.LOW)
time.sleep(0.5)
GP.output(29, GP.LOW)
GP.output(31, GP.LOW)
GP.output(33, GP.LOW)
time.sleep(0.5)
GP.output(29, GP.HIGH)
GP.output(31, GP.HIGH)
GP.output(33, GP.HIGH)
# Test capteur de température
print("appuyer sur BP1 pour lancer le test capteur de température")
while GP.input(26):
pass
capteurTemp.begin()
for i in range(5):
temperature = capteurTemp.readTempC()
print("Température = ",temperature, " °C")
time.sleep(0.5)

0
get_temp.sh

Loading…
Cancel
Save