Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
robogroup
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
matteo perini
robogroup
Commits
c6a7c16e
Commit
c6a7c16e
authored
Jan 29, 2025
by
matteo perini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aggiunti led e servo
parent
db29311c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
223 deletions
+69
-223
applicazione.py
applicazione.py
+2
-2
ledd.py
ledd.py
+21
-6
my_lib.py
my_lib.py
+40
-207
servo.py
servo.py
+6
-8
No files found.
applicazione.py
View file @
c6a7c16e
...
@@ -4,7 +4,7 @@ import RPi.GPIO as GPIO
...
@@ -4,7 +4,7 @@ import RPi.GPIO as GPIO
#from mfrc522 import SimpleMFRC522
#from mfrc522 import SimpleMFRC522
#import sqlite3
#import sqlite3
from
termcolor
import
colored
from
termcolor
import
colored
from
my_lib
import
registra_cliente
,
registra_prodotto
,
cerca_cliente_per_prodotto
,
scarica_prodotto
,
lista_clienti
,
scaric
a_cliente
,
lista_prodotti
,
cerca_cliente_per_tessera
from
my_lib
import
registra_cliente
,
registra_prodotto
,
cerca_cliente_per_prodotto
,
scarica_prodotto
,
lista_clienti
,
cancell
a_cliente
,
lista_prodotti
,
cerca_cliente_per_tessera
#from my_lib import NFC
#from my_lib import NFC
def
mostra_menu
():
def
mostra_menu
():
...
@@ -49,7 +49,7 @@ def mostra_menu():
...
@@ -49,7 +49,7 @@ def mostra_menu():
input
()
input
()
mostra_menu
()
mostra_menu
()
elif
int
(
n
)
==
6
:
elif
int
(
n
)
==
6
:
scaric
a_cliente
()
cancell
a_cliente
()
input
()
input
()
mostra_menu
()
mostra_menu
()
elif
int
(
n
)
==
7
:
elif
int
(
n
)
==
7
:
...
...
ledd.py
View file @
c6a7c16e
from
gpiozero
import
LED
from
gpiozero
import
LED
from
time
import
sleep
from
time
import
sleep
led
=
LED
(
"BOARD40"
)
led
1
=
LED
(
13
)
led2
=
LED
(
19
)
led2
=
LED
(
19
)
led3
=
LED
(
26
)
while
True
:
while
True
:
led
.
on
()
led1
.
on
()
led2
.
off
()
sleep
(
0.1
)
led1
.
off
()
#accendo il primo led
sleep
(
1
)
sleep
(
0.
1
)
led
.
off
()
#accendo il primo led
led2
.
on
()
led2
.
on
()
sleep
(
1
)
sleep
(
0.1
)
led2
.
off
()
sleep
(
0.1
)
led3
.
on
()
sleep
(
0.1
)
led3
.
off
()
sleep
(
0.1
)
my_lib.py
View file @
c6a7c16e
import
RPi.GPIO
as
GPIO
import
RPi.GPIO
as
GPIO
from
mfrc522
import
SimpleMFRC522
,
MFRC522
from
mfrc522
import
SimpleMFRC522
import
sqlite3
import
sqlite3
import
time
import
time
from
gpiozero
import
LED
from
gpiozero
import
LED
#import RPi.GPIO as GPIO
#from mfrc522 import SimpleMFRC522
import
spidev
class
NFC
():
def
__init__
(
self
,
bus
=
0
,
device
=
0
,
spd
=
1000000
):
self
.
reader
=
SimpleMFRC522
()
self
.
close
()
#self.bus = bus
self
.
boards
=
{}
self
.
bus
=
bus
self
.
device
=
device
self
.
spd
=
spd
def
reinit
(
self
):
self
.
reader
.
READER
.
spi
=
spidev
.
SpiDev
()
self
.
reader
.
READER
.
spi
.
open
(
self
.
bus
,
self
.
device
)
self
.
reader
.
READER
.
spi
.
max_speed_hz
=
self
.
spd
self
.
reader
.
READER
.
MFRC522_Init
()
def
close
(
self
):
self
.
reader
.
READER
.
spi
.
close
()
def
addBoard
(
self
,
rid
,
pin
):
self
.
rid
=
rid
self
.
boards
[
rid
]
=
pin
def
selectBoard
(
self
,
rid
):
if
not
rid
in
self
.
boards
:
print
(
"readerid "
+
rid
+
" not found"
)
return
False
for
loop_id
in
self
.
boards
:
GPIO
.
output
(
self
.
boards
[
loop_id
],
loop_id
==
rid
)
return
True
def
read
(
self
,
rid
):
if
not
self
.
selectBoard
(
rid
):
return
None
self
.
reinit
()
cid
,
val
=
self
.
reader
.
read_no_block
()
self
.
close
()
return
cid
,
val
def
readd
(
self
):
if
not
self
.
selectBoard
(
self
.
rid
):
return
None
self
.
reinit
()
cid
,
val
=
self
.
reader
.
read_no_block
()
self
.
close
()
return
cid
,
val
def
write
(
self
,
rid
,
value
):
if
not
self
.
selectBoard
(
rid
):
return
False
self
.
reinit
()
self
.
reader
.
write_no_block
(
value
)
self
.
close
()
return
True
# if __name__ == "__main__":
# nfc = NFC()
# nfc.addBoard("reader1",5)
# nfc.addBoard("reader2",6)
# data = nfc.read("reader1")
# nfc.write("reader2",data)
def
cerca_cliente_per_prodotto
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
def
leggi_prodotto
():
try
:
print
(
"Ciao, avvicina il prodotto al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
n
=
leggi_prodotto
()
database
=
cur
.
execute
(
'SELECT n_cliente FROM prodotti WHERE n_rfid=?;'
,(
n
,))
yy
=
database
.
fetchall
()
if
len
(
yy
)
>
0
:
for
row
in
yy
:
xx
=
row
[
0
]
print
(
xx
)
cliente
=
cur
.
execute
(
'SELECT * FROM persone WHERE n_card=?;'
,(
xx
,))
#for i in cliente:
print
(
cliente
.
fetchone
())
else
:
print
(
"Prodotto non associato a nessun cliente"
)
class
PatchedSimpleMFRC522
(
SimpleMFRC522
):
def
__init__
(
self
,
**
kwargs
):
self
.
READER
=
MFRC522
(
**
kwargs
)
def
leggi_rfid
(
testo
,
pin
):
def
leggi_rfid
(
testo
,
pin
):
if
pin
==
5
:
if
pin
==
5
:
lettore
=
LED
(
5
)
lettore
=
LED
(
5
)
...
@@ -130,32 +20,41 @@ def leggi_rfid(testo,pin):
...
@@ -130,32 +20,41 @@ def leggi_rfid(testo,pin):
return
1
return
1
reader
=
SimpleMFRC522
()
reader
=
SimpleMFRC522
()
#reader = PatchedSimpleMFRC522(bus=1, pin_rst=pin)
print
()
print
()
try
:
try
:
print
(
testo
)
print
(
testo
)
#id,text = reader.read()
data
=
None
data
=
None
#led_verde.on()
while
data
==
None
:
while
data
==
None
:
id
,
data
=
reader
.
read
()
id
,
data
=
reader
.
read
()
#id, data = nfc.read()
time
.
sleep
(
0.2
)
sleep
(
0.2
)
#print(id)
#print(text)
except
:
except
:
pass
pass
finally
:
finally
:
GPIO
.
cleanup
()
GPIO
.
cleanup
()
return
int
(
id
)
return
int
(
id
),
data
def
cerca_cliente_per_tessera
():
def
cerca_cliente_per_prodotto
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
cur
=
con
.
cursor
()
n
=
leggi_rfid
(
"Ciao, avvicina il tag del cliente al ricevitore!"
,
5
)
n
,
d
=
leggi_rfid
(
"Ciao, avvicina il prodotto al ricevitore!"
,
6
)
database
=
cur
.
execute
(
'SELECT n_cliente FROM prodotti WHERE n_rfid=?;'
,(
n
,))
yy
=
database
.
fetchall
()
if
len
(
yy
)
>
0
:
for
row
in
yy
:
xx
=
row
[
0
]
print
(
xx
)
cliente
=
cur
.
execute
(
'SELECT * FROM persone WHERE n_card=?;'
,(
xx
,))
print
(
cliente
.
fetchone
())
else
:
print
(
"Prodotto non associato a nessun cliente"
)
def
cerca_cliente_per_tessera
():
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
n
,
data
=
leggi_rfid
(
"Ciao, avvicina la tessera del cliente al ricevitore!"
,
6
)
database
=
cur
.
execute
(
'SELECT * FROM persone WHERE n_card=?;'
,(
n
,))
database
=
cur
.
execute
(
'SELECT * FROM persone WHERE n_card=?;'
,(
n
,))
yy
=
database
.
fetchall
()
yy
=
database
.
fetchall
()
if
len
(
yy
)
>
0
:
if
len
(
yy
)
>
0
:
...
@@ -163,11 +62,10 @@ def cerca_cliente_per_tessera():
...
@@ -163,11 +62,10 @@ def cerca_cliente_per_tessera():
xx
=
row
[
0
]
xx
=
row
[
0
]
print
(
row
)
print
(
row
)
print
(
"La tessera numero "
,
row
[
3
],
" è intestata a : "
,
row
[
1
],
" "
,
row
[
2
]
)
print
(
"La tessera numero "
,
row
[
3
],
" è intestata a : "
,
row
[
1
],
" "
,
row
[
2
]
)
#cliente = cur.execute('SELECT * FROM persone WHERE n_card=?;',(xx,))
return
n
#for i in cliente:
#print(cliente.fetchone())
else
:
else
:
print
(
"Tag non associato a nessun cliente"
)
print
(
"Tessera non associata a nessun cliente"
)
return
None
def
registra_prodotto
():
def
registra_prodotto
():
reader
=
SimpleMFRC522
()
reader
=
SimpleMFRC522
()
...
@@ -179,108 +77,43 @@ def registra_prodotto():
...
@@ -179,108 +77,43 @@ def registra_prodotto():
n_rfid TEXT NOT NULL UNIQUE,
n_rfid TEXT NOT NULL UNIQUE,
n_cliente TEXT NOT NULL);"""
)
n_cliente TEXT NOT NULL);"""
)
def
leggi_cliente
():
codice_cliente
=
cerca_cliente_per_tessera
()
try
:
if
codice_cliente
!=
None
:
print
(
"Ciao, avvicina il tag del cliente al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
def
leggi_prodotto
():
try
:
print
(
"Ciao, avvicina il prodotto al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
codice_cliente
=
leggi_cliente
()
time
.
sleep
(
2
)
time
.
sleep
(
2
)
codice_prodotto
=
leggi_prodotto
(
)
codice_prodotto
,
d
=
leggi_rfid
(
"Ciao, avvicina il prodotto al ricevitore!"
,
6
)
try
:
try
:
cur
.
execute
(
"INSERT INTO prodotti(n_rfid, n_cliente) VALUES(?, ?)"
,(
codice_prodotto
,
codice_cliente
))
cur
.
execute
(
"INSERT INTO prodotti(n_rfid, n_cliente) VALUES(?, ?)"
,(
codice_prodotto
,
codice_cliente
))
#print("ciao")
print
(
"Il prodotto numero : "
,
codice_prodotto
,
" è stato attribuito al cliente : "
,
codice_cliente
)
print
(
"Ciao "
,
codice_cliente
,
" abbiamo registrato il prodotto numero : "
,
codice_prodotto
)
con
.
commit
()
con
.
commit
()
cur
.
close
()
cur
.
close
()
except
:
except
:
print
(
"Codice non corretto"
)
print
(
"Codice prodotto non corretto o prodotto già registrato"
)
else
:
print
(
"Registra il cliente prima di riprovare."
)
def
scarica_prodotto
():
def
scarica_prodotto
():
#reader = SimpleMFRC522()
con
=
sqlite3
.
connect
(
"mydb.db"
)
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
cur
=
con
.
cursor
()
#cur.execute("""CREATE TABLE IF NOT EXISTS prodotti (
codice_prodotto
=
leggi_rfid
(
"Ciao, avvicina il prodotto al ricevitore!"
,
5
)
#id INTEGER PRIMARY KEY,
#n_rfid TEXT NOT NULL UNIQUE,
#n_cliente TEXT NOT NULL);""")
# def leggi_cliente():
# try:
# print("Ciao, avvicina il tag del cliente al ricevitore!")
# id,text = reader.read()
# print(id)
# #print(text)
# except:
# pass
# finally:
# GPIO.cleanup()
# return int(id)
def
leggi_prodotto
():
try
:
print
(
"Ciao, avvicina il prodotto al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
#print(text)
except
:
pass
finally
:
GPIO
.
cleanup
()
return
int
(
id
)
#n = input("Quale e il tuo nome?")
#c = input("Quale e il tuo cognome?")
#codice_cliente = leggi_cliente()
#time.sleep(2)
codice_prodotto
=
leggi_rfid
(
"Ciao, avvicina il prodotto al ricevitore!"
,
6
)
try
:
try
:
cur
.
execute
(
"DELETE FROM prodotti WHERE n_rfid=?;"
,(
codice_prodotto
,))
cur
.
execute
(
"DELETE FROM prodotti WHERE n_rfid=?;"
,(
codice_prodotto
,))
print
(
"Il prodotto col codice : "
,
codice_prodotto
,
" è stato correttamente smaltito."
)
print
(
"Il prodotto col codice : "
,
codice_prodotto
,
" è stato correttamente smaltito."
)
#print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
con
.
commit
()
con
.
commit
()
cur
.
close
()
cur
.
close
()
except
:
except
:
print
(
"Codice non corretto"
)
print
(
"Codice non corretto"
)
def
scaric
a_cliente
():
def
cancell
a_cliente
():
reader
=
SimpleMFRC522
()
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
cur
=
con
.
cursor
()
#cur.execute("""CREATE TABLE IF NOT EXISTS prodotti (
#id INTEGER PRIMARY KEY,
#n_rfid TEXT NOT NULL UNIQUE,
#n_cliente TEXT NOT NULL);""")
def
leggi_cliente
():
def
leggi_cliente
():
try
:
try
:
print
(
"Ciao, avvicina il tag del cliente al ricevitore!"
)
print
(
"Ciao, avvicina il tag del cliente al ricevitore!"
)
...
...
servo.py
View file @
c6a7c16e
from
gpiozero
import
Servo
from
gpiozero
import
Angular
Servo
from
time
import
sleep
from
time
import
sleep
s
=
Servo
(
4
)
s
=
AngularServo
(
4
,
min_angle
=-
90
,
max_angle
=
0
)
while
True
:
while
True
:
s
.
min
()
s
.
angle
=
0
sleep
(
2
)
sleep
(
3
)
s
.
mid
()
s
.
angle
=
-
90
sleep
(
2
)
sleep
(
1
)
s
.
max
()
sleep
(
2
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment