ohmpy_v_1_00.py 8.96 KB
Newer Older
Clement Remi's avatar
Clement Remi committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
"""
23/08/2019
OHMPY_code is a program to control the low-cost and open source resistivity meter
OHMPY, it has been developed by Rémi CLEMENT, Nicolas FORQUET (IRSTEA) and Yannick FARGIER (IFSTTAR).
Version 1.00 23/08/2019 modified by Remi CLEMENT
multiplexer development for electrode selection for each quadripole
from the quadripole file ABMN.txt
"""

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import board
import busio
import numpy
import os
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
print('Import library')

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
 
#i2c = busio.I2C(board.SCL, board.SDA)
# Create the ADC object using the I2C bus
#ads = ADS.ADS1115(i2c)
#chan = AnalogIn(ads, ADS.P0)
"""
Initialization of multiplexer channels
"""
pinList = [12,16,20,21,26,18,23,24,25,19] # List of GPIOs enabled for relay cards (electrodes)
for i in pinList: 
    GPIO.setup(i, GPIO.OUT) 
    GPIO.output(i, GPIO.HIGH)
"""
Measurement settings
"""
injection_time = 1 # Current injection time in second
nbr_meas= 900 # Number of times the quadrupole sequence is repeated
sequence_delay= 30 # Delay in Second between 2 sequences
stack= 1 # repetition of the current injection for each quadrupole

"""
Reading the quadrupole file
"""
N=numpy.loadtxt("ABMN3.txt", delimiter=" ",dtype=int) # load quadripole file
M=open("ABMN3.txt",'r') # open quadripole file
listM=list(M) # Transform M as a list
M.close() # Close M

for g in range(0,nbr_mesure): # for time-lapse monitoring
  
    """
    Selection electrode activées pour chaque quadripole
    """
    for i in range(0,len(listM)): # boucle sur les quadripôles, qui tient compte du nombre de quadripole dans le fichier ABMN

        for j in range(0,3):
                if j=0: # electrode A
                    n1=12; n2=16; n3=20; n4=21; n5=26
                elif j=1: # electrode B
                    n1=18; n2=23; n3=24; n4=25; n5=19 # à modifier
                elif j=2: # electrode M
                    n1=2; n2=3; n3=4; n4=17; n5=27 # à modifier
                elif j=3: # electrode N
                    n1=22; n2=10; n3=9; n4=11; n5=5 # à modifier


                if N[i][j]==1:
                 GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW); GPIO.output(n5, GPIO.LOW);   
                elif N[i][j]==2:            
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW); GPIO.output(n5, GPIO.HIGH);       
                elif N[i][j]==3:            
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==4:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==5:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==6:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.HIGH);
                elif N[i][j]==7:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);
                elif N[i][j]==8:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==9:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==10:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==11:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==12:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==13:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.LOW);   
                elif N[i][j]==14:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==15:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==16:
                GPIO.output(n1, GPIO.HIGH);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==17:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW); GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==18:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW); GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==19:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==20:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==21:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==22:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==23:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==24:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.HIGH);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==25:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==26:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==27:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==28:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.HIGH); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);    
                elif N[i][j]==29:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==30:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.LOW);GPIO.output(n5, GPIO.LOW);   
                elif N[i][j]==31:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.HIGH);    
                elif N[i][j]==32:
                GPIO.output(n1, GPIO.LOW);GPIO.output(n2, GPIO.LOW);GPIO.output(n3, GPIO.LOW); GPIO.output(n4, GPIO.HIGH);GPIO.output(n5, GPIO.LOW);    
        
        time.sleep(injection_time);  
        n1=22; n2=10; n3=9; n4=11; n5=5 # à modifier
        GPIO.output(12, GPIO.HIGH); GPIO.output(16, GPIO.HIGH); GPIO.output(20, GPIO.HIGH); GPIO.output(21, GPIO.HIGH); GPIO.output(26, GPIO.HIGH)              
        GPIO.output(18, GPIO.HIGH); GPIO.output(23, GPIO.HIGH); GPIO.output(24, GPIO.HIGH); GPIO.output(25, GPIO.HIGH); GPIO.output(19, GPIO.HIGH) 
        GPIO.output(2, GPIO.HIGH); GPIO.output(3, GPIO.HIGH); GPIO.output(4, GPIO.HIGH); GPIO.output(17, GPIO.HIGH); GPIO.output(27, GPIO.HIGH)
        GPIO.output(22, GPIO.HIGH); GPIO.output(10, GPIO.HIGH); GPIO.output(9, GPIO.HIGH); GPIO.output(11, GPIO.HIGH); GPIO.output(5, GPIO.HIGH)
    
    time.sleep(sequence_delay);

'''
Showing results
'''


'''
Save result in txt file
'''

    GPIO.output(12, GPIO.HIGH)
    GPIO.output(16, GPIO.HIGH)
    GPIO.output(20, GPIO.HIGH)
    GPIO.output(21, GPIO.HIGH)
    GPIO.output(26, GPIO.HIGH)