Advertisement
j0h

NFC_tag_prog

j0h
Feb 8th, 2025
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***** DONT Listen to Adafruit.com. This runs fine on an arduino uno R3. 40% mem use.**/
  2.  
  3. /*****************************************************************************
  4. * How to use this sketch
  5. *
  6. * This sketch uses the I2C interface to communicate with the NFC device.
  7. * It writes an NFC tag type URI (Uniform Resource Identifier).
  8. * Choose the uri by changing the content of uri_write.
  9. *
  10. * When the NFC module is started and ready, the message "Sytstem init done!" is
  11. * displayed on the monitor window. Next, the tag is written with the content
  12. * printed on the monitor window.
  13. *
  14. * You can use your smartphone to read the tag.
  15. * On Android, check if NFC is activated on your smartphone.
  16. * Put your smartphone near the tag to natively read it.
  17. * The preferred Internet Browser is automatically opened with the provided URI.
  18. ******************************************************************************
  19. */
  20.  
  21.  
  22. #include "ST25DVSensor.h"
  23.  
  24. #define SerialPort      Serial
  25. #define GPO_PIN 7       //GPO pin on chip can detect scans
  26.  
  27. #if defined(ARDUINO_B_L4S5I_IOT01A)
  28. // Pin definitions for board B-L4S5I_IOT01A
  29.   #define GPO_PIN PE4
  30.   #define LPD_PIN PE2
  31.   #define SDA_PIN PB11
  32.   #define SCL_PIN PB10
  33.   #define WireNFC MyWire
  34.   TwoWire MyWire(SDA_PIN, SCL_PIN);
  35.   ST25DV st25dv(12, -1, &MyWire);
  36. #else
  37.   #define DEV_I2C         Wire
  38.   ST25DV st25dv(12, -1, &DEV_I2C);
  39. #endif
  40.  
  41. void setup() {
  42.   const char uri_write_message[] = "nyle.com";       // Uri message to write in the tag
  43.   const char uri_write_protocol[] = URI_ID_0x01_STRING; // writes https://wwww into the msg
  44.   String uri_write = String(uri_write_protocol) + String(uri_write_message);
  45.   //String uri_write = String(uri_write_message);
  46.   // Initialize serial for output.
  47.   pinMode(GPO_PIN, INPUT);
  48.   SerialPort.begin(115200);
  49.  
  50.   // The wire instance used can be omitted in case you use default Wire instance
  51.   if(st25dv.begin() == 0) {
  52.     SerialPort.println("System Init done!");
  53.      SerialPort.println(uri_write);
  54.   } else {
  55.     SerialPort.println("System Init failed!");
  56.     while(1);
  57.   }
  58.  
  59.   if(st25dv.writeURI(uri_write, uri_write_message, "")) {
  60.     SerialPort.println("Write failed!");
  61.     while(1);
  62.   }
  63. digitalWrite(GPO_PIN, LOW); //makes sure IO is low
  64. delay(1000);
  65. }
  66. int count = 0;
  67. void loop() {  
  68.  // when it reads, it hits multiple times. one scan might itterate the counter by 10 or more times.
  69.     if (digitalRead(GPO_PIN) == HIGH) {
  70.     count +=1;
  71.     Serial.print("NFC tag accessed ");
  72.     Serial.print(count);
  73.     Serial.println(" times");
  74.     digitalWrite(GPO_PIN, LOW);
  75.     delay(1000);
  76.     } else {
  77.    ;    
  78.   }
  79. }
  80.  
  81. /***** DONT Listen to Adafruit.com. This runs fine on an arduino uno R3. 40% mem use.
  82.  ******************************************************************************
  83.  * @file    ST25DV_SimpleWrite.ino
  84.  * @author  STMicroelectronics
  85.  * @version V1.0.0
  86.  * @date    22 November 2017
  87.  * @brief   Arduino test application for the STMicrolectronics
  88.  *          ST25DV NFC device.
  89.  *          This application makes use of C++ classes obtained from the C
  90.  *          components' drivers.
  91.  ******************************************************************************
  92.  * @attention
  93.  *
  94.  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  95.  *
  96.  * Redistribution and use in source and binary forms, with or without modification,
  97.  * are permitted provided that the following conditions are met:
  98.  *   1. Redistributions of source code must retain the above copyright notice,
  99.  *      this list of conditions and the following disclaimer.
  100.  *   2. Redistributions in binary form must reproduce the above copyright notice,
  101.  *      this list of conditions and the following disclaimer in the documentation
  102.  *      and/or other materials provided with the distribution.
  103.  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  104.  *      may be used to endorse or promote products derived from this software
  105.  *      without specific prior written permission.
  106.  *
  107.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  108.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  109.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  110.  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  111.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  112.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  113.  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  114.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  115.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  116.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  117.  *
  118.  ******************************************************************************
  119.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement