nfc et écran lcd

Bonjour,

je tente de récupérer l'UUID d'une carte RFID pour ensuite l'afficher par ex sur un écran LCD ou mieux l'envoyer à un pc sans passer par l'usb.

Donc j'utilise ce module NFC : http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=90_93&products_id=2205

Le bout de code ci-dessous affiche dans le terminal le code UUID :

Serial.print("UUID:");
nfc.puthex(buf+1, buf[0]);

Si je comprends bien puthex envoie les infos sur le port série.
Je voudrais pouvoir récupérer cette info pour la mettre dans une variable.

Comment pourrais je faire ?

Merci

Loic

Le code :

#include <Wire.h>

/**
  @file    nfc_mifare_mf1s50_reader.ino
  @author  www.elechouse.com
  @brief   example of reading mf1s50 card for NFC_MODULE
  
    For this demo, waiting for a MF1S50 card or tag, after reading a card/tag UID,
    then try to read the block 4/5/6/7 ..
  
  @section  HISTORY
  
  V1.0 initial version
  
    Copyright (c) 2012 www.elechouse.com  All right reserved.
*/

/** include library */
#include "nfc.h"

/** define a nfc class */
NFC_Module nfc;

void setup(void)
{
  Serial.begin(9600);
  nfc.begin();
  Serial.println("MF1S50 Reader Demo From Elechouse!");
  
  uint32_t versiondata = nfc.get_version();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  /** Set normal mode, and disable SAM */
  nfc.SAMConfiguration();
}

void loop(void)
{
  u8 buf[32],sta;
  
  
  /** Polling the mifar card, buf[0] is the length of the UID */
  sta = nfc.InListPassiveTarget(buf);
  
  /** check state and UID length */
  if(sta && buf[0] == 4){
    /** the card may be Mifare Classic card, try to read the block */  
    Serial.print("UUID length:");
    Serial.print(buf[0], DEC);
    Serial.println();
    Serial.print("UUID:");
    nfc.puthex(buf+1, buf[0]);
    Serial.println();
    /** factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF */
    u8 key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
    u8 blocknum = 4;
    /** Authentication blok 4 */
    sta = nfc.MifareAuthentication(0, blocknum, buf+1, buf[0], key);
    if(sta){
      /** save read block data */
      u8 block[16];
      Serial.println("Authentication success.");
      
      // uncomment following lines for writing data to blok 4
/*      
      strcpy((char*)block, "Elechoues - NFC");
      sta = nfc.MifareWriteBlock(blocknum, block);
      if(sta){
        Serial.println("Write block successfully:");
      }
*/  

      /** read block 4 */
      sta = nfc.MifareReadBlock(blocknum, block);
      if(sta){
        Serial.println("Read block successfully:");
        
        nfc.puthex(block, 16);
        Serial.println();
      }
      
      /** read block 5 */
      sta = nfc.MifareReadBlock(blocknum+1, block);
      if(sta){
        Serial.println("Read block successfully:");
        
        nfc.puthex(block, 16);
        Serial.println();
      }
      
      /** read block 6 */
      sta = nfc.MifareReadBlock(blocknum+2, block);
      if(sta){
        Serial.println("Read block successfully:");
        
        nfc.puthex(block, 16);
        Serial.println();
      }
      
      /** read block 7 */
      sta = nfc.MifareReadBlock(blocknum+3, block);
      if(sta){
        Serial.println("Read block successfully:");
        
        nfc.puthex(block, 16);
        Serial.println();
      }
    }  
  }
}

Bonjour, tu dois stocker la valeur "nfc.puthex(buf+1, buf[0])" dans une variable pour ensuite la comparer avec une autre et déclencher des actions en fonction du resultat, ou ce que tu voudras. ..

int id_badge = nfc.puthex(buf+1, buf[0]);// c'est cette ligne qui t'intéresse
If (id_badge == id_ok){
//action...
}

Id_ok etant une variable contenent un id de badge identifié
Pour le type de variable je te dis "int" mais ça peut être autre...

C'est écrit dans les commentaires du programme que tu donnes
buf[0] contient la longueur de l'UID
et l'UID est disponible à partir de buf[1] et sur longueur octets

Par exemple pour afficher les valeurs

Serial.print("Longueur :");
Serial.print(buf[0],DEC);
for (int i=1; i<=buf[0];i++){
    Serial.print(buf[i],HEX);
}
Serial.println();

Pour mettre la donnée dans une variable je ne suis pas certain que ce soit facile si la longueur est variable.
Par contre rien ne t'empêche de stocker des UID dans un tableau à 2 dimensions.

Merci pour vos réponses

@cutprod : Effectivement j'ai tenté ca au début mais ca donne une erreur :

sketch_aug13c.ino: In function ‘void loop()’:
sketch_aug13c:95: error: void value not ignored as it ought to be

@fdufnews :
En persévérant un peu j'ai trouvé qu'on pouvait récupérer ces valeurs : C = buf[1];

Ton script fonctionne nickel, juste un petit bémol, il indique au début la valeur lengh :

UUID length:4
UUID:0B 6C C0 7F

Longueur :4B6CC07F

Et pour la valeur 0B, il n'affiche pas le zéro. A quoi est ce du ?

Merci

Ton script fonctionne nickel, juste un petit bémol, il indique au début la valeur lengh

C'est pas un bémol, c'est voulu.
Par contre j'ai oublié un saut de ligne
Pour le 0 manquant c'est lié au print. Volà une correction.

Serial.print("Longueur :");
Serial.println(buf[0],DEC);
for (int i=1; i<=buf[0];i++){
    if (buf[i]<0x10){
        Serial.print("0");
    }
    Serial.print(buf[i],HEX);
}
Serial.println();

ok merci.
Je vais tester ca. il me reste plus qu'à trouver un moyen d'envoyer l'info à un autre pc.