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
5cb86003
Commit
5cb86003
authored
Jan 17, 2025
by
matteo perini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test con due lettori rfid
parent
7b6127f7
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
153 additions
and
29 deletions
+153
-29
applicazione.py
applicazione.py
+23
-11
ledd.py
ledd.py
+10
-0
my_lib.py
my_lib.py
+120
-18
No files found.
applicazione.py
View file @
5cb86003
import
time
import
os
import
RPi.GPIO
as
GPIO
#from mfrc522 import SimpleMFRC522
#import sqlite3
from
termcolor
import
colored
from
my_lib
import
registra_cliente
,
registra_prodotto
,
cerca_cliente_per_prodotto
,
scarica_prodotto
,
lista_clienti
,
scarica_cliente
,
lista_prodotti
,
cerca_cliente_per_tessera
#from my_lib import NFC
def
mostra_menu
():
os
.
system
(
'cls'
if
os
.
name
==
'nt'
else
'clear'
)
# questa riga serve per cancellare il terminale
...
...
@@ -26,35 +30,35 @@ def mostra_menu():
return
0
#serve per uscire dalla funzione
elif
int
(
n
)
==
1
:
registra_cliente
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
elif
int
(
n
)
==
2
:
registra_prodotto
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
elif
int
(
n
)
==
3
:
scarica_prodotto
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
elif
int
(
n
)
==
4
:
lista_clienti
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
elif
int
(
n
)
==
5
:
cerca_cliente_per_prodotto
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
elif
int
(
n
)
==
6
:
scarica_cliente
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
elif
int
(
n
)
==
7
:
lista_prodotti
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
elif
int
(
n
)
==
8
:
cerca_cliente_per_tessera
()
time
.
sleep
(
3
)
input
(
)
mostra_menu
()
else
:
print
(
"ok"
)
...
...
@@ -62,12 +66,20 @@ def mostra_menu():
mostra_menu
()
else
:
print
(
"Numero selezionato non valido. Riprova!"
)
#se il numero non è tra quelli previsti
time
.
sleep
(
3
)
#aspetto tre secondi
input
(
)
#aspetto tre secondi
mostra_menu
()
#faccio ripartire la funzione del menù
else
:
print
(
"Scelta non corretta. Deve essere un numero. Riprova!"
)
#se l'immissione non è un numero
time
.
sleep
(
3
)
#aspetto tre secondi
input
(
)
#aspetto tre secondi
mostra_menu
()
#faccio ripartire la funzione del menù
if
__name__
==
"__main__"
:
#se sto chiamando il programma principale
#GPIO.setmode(GPIO.BCM)
#GPIO.setup(25, GPIO.OUT)
#global nfc
#nfc = NFC()
#nfc.addBoard("rfid_cassa",25) #GPIO 25 -> pin 22
mostra_menu
()
# avvia la funzione per mostrare il menù
\ No newline at end of file
ledd.py
0 → 100644
View file @
5cb86003
from
gpiozero
import
LED
from
time
import
sleep
led
=
LED
(
27
)
while
True
:
led
.
on
()
sleep
(
1
)
led
.
off
()
sleep
(
1
)
my_lib.py
View file @
5cb86003
import
RPi.GPIO
as
GPIO
from
mfrc522
import
SimpleMFRC522
from
mfrc522
import
SimpleMFRC522
,
MFRC522
import
sqlite3
import
time
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
()
...
...
@@ -35,16 +110,38 @@ def cerca_cliente_per_prodotto():
else
:
print
(
"Prodotto non associato a nessun cliente"
)
def
cerca_cliente_per_tessera
():
reader
=
SimpleMFRC522
()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
class
PatchedSimpleMFRC522
(
SimpleMFRC522
):
def
__init__
(
self
,
**
kwargs
):
self
.
READER
=
MFRC522
(
**
kwargs
)
def
leggi_rfid
(
testo
,
pin
):
if
pin
==
5
:
lettore
=
LED
(
5
)
nonlettore
=
LED
(
6
)
lettore
.
on
()
nonlettore
.
off
()
elif
pin
==
6
:
lettore
=
LED
(
6
)
nonlettore
=
LED
(
5
)
lettore
.
on
()
nonlettore
.
off
()
else
:
print
(
"error"
)
return
1
def
leggi_cliente
():
reader
=
SimpleMFRC522
()
#reader = PatchedSimpleMFRC522(bus=1, pin_rst=pin)
print
()
try
:
print
(
"Ciao, avvicina il tag del cliente al ricevitore!"
)
id
,
text
=
reader
.
read
()
print
(
id
)
print
(
testo
)
#id,text = reader.read()
data
=
None
#led_verde.on()
while
data
==
None
:
id
,
data
=
reader
.
read
()
#id, data = nfc.read()
sleep
(
0.2
)
#print(id)
#print(text)
except
:
pass
...
...
@@ -52,7 +149,12 @@ def cerca_cliente_per_tessera():
GPIO
.
cleanup
()
return
int
(
id
)
n
=
leggi_cliente
()
def
cerca_cliente_per_tessera
():
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
n
=
leggi_rfid
(
"Ciao, avvicina il tag del cliente al ricevitore!"
,
5
)
database
=
cur
.
execute
(
'SELECT * FROM persone WHERE n_card=?;'
,(
n
,))
yy
=
database
.
fetchall
()
...
...
@@ -119,7 +221,7 @@ def registra_prodotto():
def
scarica_prodotto
():
reader
=
SimpleMFRC522
()
#
reader = SimpleMFRC522()
con
=
sqlite3
.
connect
(
"mydb.db"
)
cur
=
con
.
cursor
()
...
...
@@ -157,11 +259,11 @@ def scarica_prodotto():
#c = input("Quale e il tuo cognome?")
#codice_cliente = leggi_cliente()
#time.sleep(2)
codice_prodotto
=
leggi_
prodotto
(
)
codice_prodotto
=
leggi_
rfid
(
"Ciao, avvicina il prodotto al ricevitore!"
,
6
)
try
:
cur
.
execute
(
"DELETE FROM prodotti WHERE n_rfid=?;"
,(
codice_prodotto
,))
#print("ciao
")
print
(
"Il prodotto col codice : "
,
codice_prodotto
,
" è stato correttamente smaltito.
"
)
#print("Ciao ", codice_cliente , " abbiamo registrato il prodotto numero : ", codice_prodotto)
con
.
commit
()
cur
.
close
()
...
...
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