ciao a tutti ho un rfid rc522 , arduino e un servomotore.. ora devo creare il codice della rfid in modo che quando accetta la carta inizia a girare il servomotore .. questo mi serve per il progetto di scuola ma purtroppo non riesco a trovare un codice fatto bene che tratti ciò..
cortesemente qualcuno sa come fare ? oppure se lo possiamo fare insieme perchè mi serve il prima possibile ![]()
grazie a tutti ![]()
Questa libreria l'hai vista ?
grazie per la risposta.. si ho già vista ma non ci sono i servo ..
sapresti un'altro sito ? ![]()
Impara ad usare la libreria dell'rfid, poi quella del servo, poi si tratta solo di modificare una variabile quando passi l'rfid.
grazie per la risposta ma il problema purtroppo è proprio questo.. adattare le librerie del rfid con quelle del servo..
ti andrebbe magari di assemblare il codice insieme ? ![]()
non vedo perche' la libreria SPI possa andare in conflitto con quella SERVO
come ti diceva @DAB, impara a usare l'RFID, poi aggiungerci il movimento di un servo sono due righe
no guarda forse mi sono sbagliato ad esprimermi .. non è che deve andare in conflitto è che sono io che non riesco ad unire i due codici insieme ossia quello dell'rfid e quello del servo..
il codice dell'rfid è questo
#include <MFRC522.h>
#include <SPI.h>
#define SAD 10
#define RST 5
MFRC522 nfc(SAD, RST);
void setup() {
SPI.begin();
// Read a fast as possible. There is a limit for how long we are
// allowed to read from the tags.
Serial.begin(115200);
Serial.println("Looking for MFRC522.");
nfc.begin();
// Get the firmware version of the RFID chip
byte version = nfc.getFirmwareVersion();
if (! version) {
Serial.print("Didn't find MFRC522 board.");
while(1); //halt
}
Serial.print("Found chip MFRC522 ");
Serial.print("Firmware ver. 0x");
Serial.print(version, HEX);
Serial.println(".");
}
byte keyA[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, };
byte keyB[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, };
void loop() {
byte status;
byte data[MAX_LEN];
byte serial[5];
int i, j, pos;
// Send a general request out into the aether. If there is a tag in
// the area it will respond and the status will be MI_OK.
status = nfc.requestTag(MF1_REQIDL, data);
if (status == MI_OK) {
Serial.println("Tag detected.");
Serial.print("Type: ");
Serial.print(data[0], HEX);
Serial.print(", ");
Serial.println(data[1], HEX);
// calculate the anti-collision value for the currently detected
// tag and write the serial into the data array.
status = nfc.antiCollision(data);
memcpy(serial, data, 5);
Serial.println("The serial nb of the tag is:");
for (i = 0; i < 3; i++) {
Serial.print(serial[i], HEX);
Serial.print(", ");
}
Serial.println(serial[3], HEX);
// Select the tag that we want to talk to. If we don't do this the
// chip does not know which tag it should talk if there should be
// any other tags in the area..
nfc.selectTag(serial);
// Assuming that there are only 64 blocks of memory in this chip.
for (i = 0; i < 64; i++) {
// Try to authenticate each block first with the A key.
status = nfc.authenticate(MF1_AUTHENT1A, i, keyA, serial);
if (status == MI_OK) {
Serial.print("Authenticated block nb. 0x");
Serial.print(i, HEX);
Serial.println(" with key A.");
// Reading block i from the tag into data.
status = nfc.readFromTag(i, data);
if (status == MI_OK) {
// If there was no error when reading; print all the hex
// values in the data.
for (j = 0; j < 15; j++) {
Serial.print(data[j], HEX);
Serial.print(", ");
}
Serial.println(data[15], HEX);
} else {
Serial.println("Read failed.");
}
} else {
// If we could not authenticate with the A key, we will try
// the B key.
status = nfc.authenticate(MF1_AUTHENT1B, i, keyB, serial);
if (status == MI_OK) {
Serial.print("Authenticated block nb. 0x");
Serial.print(i, HEX);
Serial.println(" with key B.");
status = nfc.readFromTag(i, data);
if (status == MI_OK) {
for (j = 0; j < 15; j++) {
Serial.print(data[j], HEX);
Serial.print(", ");
}
Serial.println(data[15], HEX);
} else {
Serial.println("Read failed.");
}
} else {
Serial.print("Access denied at block nb. 0x");
Serial.println(i, HEX);
}
}
}
// Stop the tag and get ready for reading a new tag.
nfc.haltTag();
}
delay(2000);
}
mentre quello del servo è questo
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
ora come li unisco questi due codici ? ![]()
unire i codici non e' niente, il problema e' capire
codici uniti
#include <MFRC522.h>
#include <SPI.h>
#include <Servo.h>
#define SAD 10
#define RST 5
MFRC522 nfc(SAD, RST);
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup() {
SPI.begin();
// Read a fast as possible. There is a limit for how long we are
// allowed to read from the tags.
myservo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(115200);
Serial.println("Looking for MFRC522.");
nfc.begin();
// Get the firmware version of the RFID chip
byte version = nfc.getFirmwareVersion();
if (! version) {
Serial.print("Didn't find MFRC522 board.");
while(1); //halt
}
Serial.print("Found chip MFRC522 ");
Serial.print("Firmware ver. 0x");
Serial.print(version, HEX);
Serial.println(".");
}
byte keyA[6] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, };
byte keyB[6] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, };
void loop() {
byte status;
byte data[MAX_LEN];
byte serial[5];
int i, j, pos;
// Send a general request out into the aether. If there is a tag in
// the area it will respond and the status will be MI_OK.
status = nfc.requestTag(MF1_REQIDL, data);
if (status == MI_OK) {
Serial.println("Tag detected.");
Serial.print("Type: ");
Serial.print(data[0], HEX);
Serial.print(", ");
Serial.println(data[1], HEX);
//**************************************************************
Gira_servo(); // gira servo quando si passa una carta
//**************************************************************
// calculate the anti-collision value for the currently detected
// tag and write the serial into the data array.
status = nfc.antiCollision(data);
memcpy(serial, data, 5);
Serial.println("The serial nb of the tag is:");
for (i = 0; i < 3; i++) {
Serial.print(serial[i], HEX);
Serial.print(", ");
}
Serial.println(serial[3], HEX);
// Select the tag that we want to talk to. If we don't do this the
// chip does not know which tag it should talk if there should be
// any other tags in the area..
nfc.selectTag(serial);
// Assuming that there are only 64 blocks of memory in this chip.
for (i = 0; i < 64; i++) {
// Try to authenticate each block first with the A key.
status = nfc.authenticate(MF1_AUTHENT1A, i, keyA, serial);
if (status == MI_OK) {
Serial.print("Authenticated block nb. 0x");
Serial.print(i, HEX);
Serial.println(" with key A.");
// Reading block i from the tag into data.
status = nfc.readFromTag(i, data);
if (status == MI_OK) {
// If there was no error when reading; print all the hex
// values in the data.
for (j = 0; j < 15; j++) {
Serial.print(data[j], HEX);
Serial.print(", ");
}
Serial.println(data[15], HEX);
//**********************************************************************
Gira_servo(); // carta A riconosciuta, gira il servo
//**********************************************************************
}
else {
Serial.println("Read failed.");
}
}
else {
// If we could not authenticate with the A key, we will try
// the B key.
status = nfc.authenticate(MF1_AUTHENT1B, i, keyB, serial);
if (status == MI_OK) {
Serial.print("Authenticated block nb. 0x");
Serial.print(i, HEX);
Serial.println(" with key B.");
status = nfc.readFromTag(i, data);
if (status == MI_OK) {
for (j = 0; j < 15; j++) {
Serial.print(data[j], HEX);
Serial.print(", ");
}
Serial.println(data[15], HEX);
}
else {
Serial.println("Read failed.");
}
}
else {
Serial.print("Access denied at block nb. 0x");
Serial.println(i, HEX);
}
}
}
// Stop the tag and get ready for reading a new tag.
nfc.haltTag();
}
delay(2000);
}
void Gira_servo()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
grazie per il codice. perchè però quando clicco su verifica mi da errore " mfrc522 does not name a type " ?
non riesco proprio a capire
ohi ohi...
e io che presumevoi tu avessi gia' testato gli esempi
ti da' quell'errrore perche' non hai installato la libreria
e come potrei risolvere ? dove si caricano le libreirie ?
libreria
cliccare in basso a destra su Download ZIP
scompattare lo zip in una cartella con il nome MFRC522 ( senza la scritta master )
istruzioni d'uso su come installare una libreria
segui le istruzioni - Manual installation
grazie l'ho installato e non mi da errore.. mi resta solo che provarlo mercoledì ![]()
poi ti faccio sapere ![]()
un'altra cosa che volevo sapere è : siccome questo rfid mi serve per aprire un piccolo cancello in legno ( 30*20) fatto da me volevo sapere se con un microservo tipo questo http://www.ebay.it/itm/Micro-servo-9g-SG90-per-modellismo-RC-elicotteri-aerei-robotica-amatoriale-ardui-/221388433659?pt=Modellismo_Dinamico&hash=item338bc768fb riuscivo a far girare il tutto oppure è troppo debole ?
riuscivo a far girare il tutto oppure è troppo debole ?
quel MICRO servo pesa 9grammi
a meno che il cancelletto non sia assemblato in modo che si sposti quasi alitandoci sopra, e' un po' dura
E comunque va' visto che tipo di apertura ha
ma cosa vuoi fare, una porta per il gatto ?
Guarda il cancelletto è piccolissimo ed è fatto di compensato.. no questo progetto mi serve per l'esame di maturità in poche parole quando passa un oggetto si deve aprire il mini cancelletto ovviamente con la tessera ![]()
ok, ma come si apre ?
a Bandiera, a battente, scorrevole,......
Sara' incernierato da qualche parte o lo volevi incollare sul servo ?
il cancello è scorrevole.. avevo deciso di utilizzare una ruota dentata per il servo in modo che possa scorrere sulla cremagliera come questa qua https://www.google.it/search?q=ruota+dentata+servomotore&source=lnms&tbm=isch&sa=X&ei=7j5NU8zxM-iP4gT89YDACQ&ved=0CAYQ_AUoAQ&biw=1360&bih=665#facrc=_&imgdii=_&imgrc=3eeaqQYIXlMeFM%253A%3BHRshamf9e-QhaM%3Bhttp%253A%252F%252Fimg.directindustry.it%252Fimages_di%252Fphoto-m%252Fruote-dentate-16008-4572699.jpg%3Bhttp%253A%252F%252Fwww.directindustry.it%252Ffabbricante-industriale%252Fruota-dentata-61012.html%3B210%3B210
cosa ne pensi ? sai dirmi altri consigli ? ![]()
guarda che i servo ( almeno che tu non li smonti e li modifichi ) vanno da 0 a 180 Gradi
cioe' ti fanno fare mezzo giro a codesta ruota
si infatti solo ora me ne sono accorto.. ho trovato invece questo che fa 360°
http://www.amazon.it/SM-S4303R-Servomotore-Elicotteri-Robot-Ricambio/dp/B00EYYQ61K/ref=sr_1_13?ie=UTF8&qid=1397576229&sr=8-13&keywords=servomotore
ma secondo te è una buona idea ciò che sto facendo o è meglio che cambio tipo di motore ?