Hallo Leute ,
ich muß mein Python Programm zwingend mit sudo starten, also so:
sudo phyton Kompressor.py
Starte ich es ohne sudo bekomme ich folgende Fehlermeldung:
Traceback (most recent call last):File "Kompressor.py", line 228, in <module>
lcd_byte(0x01, LCD_CMD)
File "Kompressor.py", line 167, in lcd_byte
GPIO.output(LCD_RS, mode) # RS
RuntimeError: The GPIO channel has not been set up as an OUTPUT
Man könnte nun natürlich sagen, start es halt mit sudo, aber das geht leider nicht.
Ich muß das Program in der rc.lokal starten und da bekomme ich immer die
Fehlermeldung !
Ich werde noch wahnsinnig !!!!!!
Hier der Code:
Code
H:\Kompressor\Neuste2\Kompressor.py
Seite 1 von 4 23.05.2016 19:23:01
1 #!/usr/bin/python
2 #--------------------------------------
3 #
4 # Author : Nurmi Paavo
5 # Date : 09/08/15
6 # Projekt: Kompressorsteuerung
7 #
8 #--------------------------------------
9
10 # Anschluesse des LCD Displays:
11 # 1 : GND
12 # 2 : 5V
13 # 3 : Contrast (0-5V)*
14 # 4 : RS (Register Select)
15 # 5 : R/W (Read Write) - GROUND THIS PIN
16 # 6 : Enable or Strobe
17 # 7 : Data Bit 0 - NOT USED
18 # 8 : Data Bit 1 - NOT USED
19 # 9 : Data Bit 2 - NOT USED
20 # 10: Data Bit 3 - NOT USED
21 # 11: Data Bit 4
22 # 12: Data Bit 5
23 # 13: Data Bit 6
24 # 14: Data Bit 7
25 # 15: LCD Backlight +5V**
26 # 16: LCD Backlight GND
27
28
29
30
31 #import
32 import RPi.GPIO as GPIO
33 import time
34 import sqlite3
35
36
37 # Define GPIO to LCD mapping
38 LCD_RS = 7
39 LCD_E = 8
40 LCD_D4 = 25
41 LCD_D5 = 24
42 LCD_D6 = 23
43 LCD_D7 = 18
44
45 # Define some device constants
46 LCD_WIDTH = 16 # Maximum characters per line
47 LCD_CHR = True
48 LCD_CMD = False
49
50 LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
51 LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
52
53 # Timing constants
54 E_PULSE = 0.0005
55 E_DELAY = 0.0005
56
57 def main():
58 # Main program block
59
60 GPIO.setmode(GPIO.BCM) # Use BCM GPIO numbers
61 GPIO.setup(LCD_E, GPIO.OUT) # E
62 GPIO.setup(LCD_RS, GPIO.OUT) # RS
63 GPIO.setup(LCD_D4, GPIO.OUT) # DB4
64 GPIO.setup(LCD_D5, GPIO.OUT) # DB5
65 GPIO.setup(LCD_D6, GPIO.OUT) # DB6
66 GPIO.setup(LCD_D7, GPIO.OUT) # DB7
67 relaise = 22
68 GPIO.setup (relaise, GPIO.OUT) #GPIO 22 als Ausgang
69 GPIO.output (relaise, GPIO.HIGH)
70
71
72
73
74 # Initialise display
75 lcd_init()
76
77 while True:
78
79
80 # Sendet diesen Text
81 lcd_string("TSC MaLu",LCD_LINE_1)
82 lcd_string("Chip vorhalten",LCD_LINE_2)
83
84 DatenAbfrage()
85 #ChipEinlesen()
86
87
88
89 def lcd_init():
90 # Initialise display
91 lcd_byte(0x33,LCD_CMD) # 110011 Initialise
92 lcd_byte(0x32,LCD_CMD) # 110010 Initialise
93 lcd_byte(0x06,LCD_CMD) # 000110 Cursor move direction
94 lcd_byte(0x0C,LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
95 lcd_byte(0x28,LCD_CMD) # 101000 Data length, number of lines, font size
96 lcd_byte(0x01,LCD_CMD) # 000001 Clear display
97 time.sleep(E_DELAY)
98
99
100
101 def DatenAbfrage():
102
103 con = sqlite3.connect("nutzer.db")
104 dbcursor = con.cursor()
105
106
107 ke = input() # Liest den Chip ein
108
109 dbcursor.execute('SELECT * FROM fueller WHERE kennung=?', (ke,))
110
111 a = (dbcursor.fetchone())
112
113 if a == None:
114 ZugangVerweigert()
115 else:
116 ZugangErlaubt()
117
118
119
120 con.close()
121
122
123 def ZugangVerweigert():
124
125
126 # Sendet diesen Text
127 lcd_string("TSC MaLu",LCD_LINE_1)
128 lcd_string("Zugang verboten",LCD_LINE_2)
129
130 time.sleep(3) # 3 second delay
131
132
133
134
135
136
137 def ZugangErlaubt():
138
139
140 relaise = 22
141
142 #GPIO.output (relaise, GPIO.HIGH)
143
144 # Sendet diesen Text
145 lcd_string("TSC MaLu",LCD_LINE_1)
146 lcd_string("Fuellen erlaubt",LCD_LINE_2)
147
148 #Chip = input() # Liest den Chip ein
149
150 # Sendet diesen Text
151 #lcd_string("Chip Zahl",LCD_LINE_1)
152 #lcd_string(Chip ,LCD_LINE_2)
153
154 GPIO.output (relaise, GPIO.LOW)
155
156 time.sleep(3) # 3 second delay
157
158 GPIO.output (relaise, GPIO.HIGH)
159
160
161 def lcd_byte(bits, mode):
162 # Send byte to data pins
163 # bits = data
164 # mode = True for character
165 # False for command
166
167 GPIO.output(LCD_RS, mode) # RS
168
169 # High bits
170 GPIO.output(LCD_D4, False)
171 GPIO.output(LCD_D5, False)
172 GPIO.output(LCD_D6, False)
173 GPIO.output(LCD_D7, False)
174 if bits&0x10==0x10:
175 GPIO.output(LCD_D4, True)
176 if bits&0x20==0x20:
177 GPIO.output(LCD_D5, True)
178 if bits&0x40==0x40:
179 GPIO.output(LCD_D6, True)
180 if bits&0x80==0x80:
181 GPIO.output(LCD_D7, True)
182
183 # Toggle 'Enable' pin
184 lcd_toggle_enable()
185
186 # Low bits
187 GPIO.output(LCD_D4, False)
188 GPIO.output(LCD_D5, False)
189 GPIO.output(LCD_D6, False)
190 GPIO.output(LCD_D7, False)
191 if bits&0x01==0x01:
192 GPIO.output(LCD_D4, True)
193 if bits&0x02==0x02:
194 GPIO.output(LCD_D5, True)
195 if bits&0x04==0x04:
196 GPIO.output(LCD_D6, True)
197 if bits&0x08==0x08:
198 GPIO.output(LCD_D7, True)
199
200 # Toggle 'Enable' pin
201 lcd_toggle_enable()
202
203 def lcd_toggle_enable():
204 # Toggle enable
205 time.sleep(E_DELAY)
206 GPIO.output(LCD_E, True)
207 time.sleep(E_PULSE)
208 GPIO.output(LCD_E, False)
209 time.sleep(E_DELAY)
210
211 def lcd_string(message,line):
212 # Send string to display
213
214 message = message.ljust(LCD_WIDTH," ")
215
216 lcd_byte(line, LCD_CMD)
217
218 for i in range(LCD_WIDTH):
219 lcd_byte(ord(message[i]),LCD_CHR)
220
221 if __name__ == '__main__':
222
223 try:
224 main()
225 except KeyboardInterrupt:
226 pass
227 finally:
228 lcd_byte(0x01, LCD_CMD)
229 lcd_string("Goodbye!",LCD_LINE_1)
230 GPIO.cleanup()
231
Display More