Skip to content

Commit cec52c6

Browse files
committed
Add examples: HelloWorld and SimpleWrite
1 parent bfcccb3 commit cec52c6

3 files changed

Lines changed: 273 additions & 0 deletions

File tree

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ It is then possible to read/write NFC URI:
2727
```
2828
2929
30+
## Examples
31+
32+
There are 2 examples with the ST25DV library:
33+
* ST25DV_HelloWorld: This application writes a URI tag on the device. It records an URI.
34+
35+
When the NFC module is started and ready, the message "Sytstem init done!" is displayed on the monitor window.
36+
Next, the tag is written, we wait few seconds, we read the same tag and print it on the monitor window.
37+
38+
You can test this application by connecting it with your smartphone.
39+
On Android, download a NFC Tools. Then start the app, check if NFC is activated
40+
on your smartphone. Put your smartphone near the tag, you can read it. You can
41+
write a tag with this app.
42+
43+
* ST25DV_SimpleWrite: This application writes a NDEF message, containing a URI record, to the tag.
44+
45+
When the NFC module is started and ready, the message "System init done!" is displayed on the monitor window.
46+
Next, the tag is written with a URI.
47+
48+
You can test this application by tapping the tag with your smartphone.
49+
On Android, check if NFC is activated on your smartphone.
50+
Put your smartphone near the tag to read it.
51+
The preferred Internet Browser is automatically opened with the provided URI.
52+
53+
3054
## Documentation
3155
3256
You can find the source files at
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/**
2+
******************************************************************************
3+
* @file ST25DV_HelloWorld.ino
4+
* @author STMicroelectronics
5+
* @version V1.0.0
6+
* @date 22 November 2017
7+
* @brief Arduino test application for the STMicrolectronics
8+
* ST25DV NFC device.
9+
* This application makes use of C++ classes obtained from the C
10+
* components' drivers.
11+
******************************************************************************
12+
* @attention
13+
*
14+
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15+
*
16+
* Redistribution and use in source and binary forms, with or without modification,
17+
* are permitted provided that the following conditions are met:
18+
* 1. Redistributions of source code must retain the above copyright notice,
19+
* this list of conditions and the following disclaimer.
20+
* 2. Redistributions in binary form must reproduce the above copyright notice,
21+
* this list of conditions and the following disclaimer in the documentation
22+
* and/or other materials provided with the distribution.
23+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
24+
* may be used to endorse or promote products derived from this software
25+
* without specific prior written permission.
26+
*
27+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
******************************************************************************
39+
*/
40+
41+
/**
42+
******************************************************************************
43+
* How to use this sketch
44+
*
45+
* This sketch uses the I2C interface to communicate with the NFC device.
46+
* It writes an NFC tag type URI (Uniform Resource Identifier) and reads this same tag.
47+
* Choose the uri by changing the content of uri_write.
48+
*
49+
* When the NFC module is started and ready, the message "Sytstem init done!" is
50+
* displayed on the monitor window. Next, the tag is written, read and printed on
51+
* the monitor window.
52+
*
53+
* You can also use your smartphone to read/write a tag.
54+
* On Android, download a NFC Tools. Then start the app, check if NFC is activated
55+
* on your smartphone. Put your smartphone near the tag, you can read it. You can
56+
* write a tag with this app.
57+
******************************************************************************
58+
*/
59+
60+
#include "ST25DVSensor.h"
61+
62+
#define SerialPort Serial
63+
64+
#if defined(ARDUINO_B_L4S5I_IOT01A)
65+
// Pin definitions for board B-L4S5I_IOT01A
66+
#define GPO_PIN PE4
67+
#define LPD_PIN PE2
68+
#define SDA_PIN PB11
69+
#define SCL_PIN PB10
70+
71+
#define WireNFC MyWire
72+
TwoWire MyWire(SDA_PIN, SCL_PIN);
73+
74+
#else
75+
// Please define the pin and wire instance used for your board
76+
// #define GPO_PIN PE4
77+
// #define LPD_PIN PE2
78+
// #define SDA_PIN PB11
79+
// #define SCL_PIN PB10
80+
81+
#define WireNFC Wire // Default wire instance
82+
83+
#endif
84+
85+
#if !defined(GPO_PIN) || !defined(LPD_PIN)
86+
#error define the pin and wire instance used for your board
87+
#endif
88+
89+
90+
void setup() {
91+
const char uri_write_message[] = "st.com/st25"; // Uri message to write in the tag
92+
const char uri_write_protocol[] = URI_ID_0x01_STRING; // Uri protocol to write in the tag
93+
String uri_write = String(uri_write_protocol) + String(uri_write_message);
94+
String uri_read;
95+
96+
// Initialize serial for output.
97+
SerialPort.begin(115200);
98+
99+
// The wire instance used can be omited in case you use default Wire instance
100+
if(st25dv.begin(GPO_PIN, LPD_PIN, &WireNFC) == 0) {
101+
SerialPort.println("System Init done!");
102+
} else {
103+
SerialPort.println("System Init failed!");
104+
while(1);
105+
}
106+
107+
if(st25dv.writeURI(uri_write_protocol, uri_write_message, "")) {
108+
SerialPort.println("Write failed!");
109+
while(1);
110+
}
111+
112+
delay(100);
113+
114+
if(st25dv.readURI(&uri_read)) {
115+
SerialPort.println("Read failed!");
116+
while(1);
117+
}
118+
119+
SerialPort.println(uri_read.c_str());
120+
121+
if(strcmp(uri_read.c_str(), uri_write.c_str()) == 0) {
122+
SerialPort.println("Successfully written and read!");
123+
} else {
124+
SerialPort.println("Read bad string!");
125+
}
126+
}
127+
128+
void loop() {
129+
//empty loop
130+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
******************************************************************************
3+
* @file ST25DV_SimpleWrite.ino
4+
* @author STMicroelectronics
5+
* @version V1.0.0
6+
* @date 22 November 2017
7+
* @brief Arduino test application for the STMicrolectronics
8+
* ST25DV NFC device.
9+
* This application makes use of C++ classes obtained from the C
10+
* components' drivers.
11+
******************************************************************************
12+
* @attention
13+
*
14+
* <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15+
*
16+
* Redistribution and use in source and binary forms, with or without modification,
17+
* are permitted provided that the following conditions are met:
18+
* 1. Redistributions of source code must retain the above copyright notice,
19+
* this list of conditions and the following disclaimer.
20+
* 2. Redistributions in binary form must reproduce the above copyright notice,
21+
* this list of conditions and the following disclaimer in the documentation
22+
* and/or other materials provided with the distribution.
23+
* 3. Neither the name of STMicroelectronics nor the names of its contributors
24+
* may be used to endorse or promote products derived from this software
25+
* without specific prior written permission.
26+
*
27+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+
*
38+
******************************************************************************
39+
*/
40+
41+
/**
42+
******************************************************************************
43+
* How to use this sketch
44+
*
45+
* This sketch uses the I2C interface to communicate with the NFC device.
46+
* It writes an NFC tag type URI (Uniform Resource Identifier).
47+
* Choose the uri by changing the content of uri_write.
48+
*
49+
* When the NFC module is started and ready, the message "Sytstem init done!" is
50+
* displayed on the monitor window. Next, the tag is written with the content
51+
* printed on the monitor window.
52+
*
53+
* You can use your smartphone to read the tag.
54+
* On Android, check if NFC is activated on your smartphone.
55+
* Put your smartphone near the tag to natively read it.
56+
* The preferred Internet Browser is automatically opened with the provided URI.
57+
******************************************************************************
58+
*/
59+
60+
61+
#include "ST25DVSensor.h"
62+
63+
#define SerialPort Serial
64+
65+
#if defined(ARDUINO_B_L4S5I_IOT01A)
66+
// Pin definitions for board B-L4S5I_IOT01A
67+
#define GPO_PIN PE4
68+
#define LPD_PIN PE2
69+
#define SDA_PIN PB11
70+
#define SCL_PIN PB10
71+
72+
#define WireNFC MyWire
73+
TwoWire MyWire(SDA_PIN, SCL_PIN);
74+
75+
#else
76+
// Please define the pin and wire instance used for your board
77+
// #define GPO_PIN PE4
78+
// #define LPD_PIN PE2
79+
// #define SDA_PIN PB11
80+
// #define SCL_PIN PB10
81+
82+
#define WireNFC Wire // Default wire instance
83+
84+
#endif
85+
86+
#if !defined(GPO_PIN) || !defined(LPD_PIN)
87+
#error define the pin and wire instance used for your board
88+
#endif
89+
90+
#if !defined(GPO_PIN) || !defined(LPD_PIN)
91+
#error define the pin and wire instance used for your board
92+
#endif
93+
94+
void setup() {
95+
const char uri_write_message[] = "st.com/st25"; // Uri message to write in the tag
96+
const char uri_write_protocol[] = URI_ID_0x01_STRING; // Uri protocol to write in the tag
97+
String uri_write = String(uri_write_protocol) + String(uri_write_message);
98+
99+
// Initialize serial for output.
100+
SerialPort.begin(115200);
101+
102+
// The wire instance used can be omited in case you use default Wire instance
103+
if(st25dv.begin(GPO_PIN, LPD_PIN, &WireNFC) == 0) {
104+
SerialPort.println("System Init done!");
105+
} else {
106+
SerialPort.println("System Init failed!");
107+
while(1);
108+
}
109+
110+
if(st25dv.writeURI(uri_write_protocol, uri_write_message, "")) {
111+
SerialPort.println("Write failed!");
112+
while(1);
113+
}
114+
115+
}
116+
117+
void loop() {
118+
//empty loop
119+
}

0 commit comments

Comments
 (0)