How to use variables in ST25DV NFC message?

HI
I am trying to do a (probably) simple project, well I thought.
All I want to do is send a variable value from a poti ( on A0) to the ST25DV NFC message.
however I cant get the analogread value transformed to anything the message will accept..
The ST25DV is connected to a Adafruit QT PY Stemma. with the stemma QT cable.

I tried to modifiy the simple example: but fails..
whats wrong?
thanks



#include "ST25DVSensor.h"

#define SerialPort Serial

#if defined(ARDUINO_B_L4S5I_IOT01A)
// Pin definitions for board B-L4S5I_IOT01A
#define GPO_PIN PE4
#define LPD_PIN PE2
#define SDA_PIN PB11
#define SCL_PIN PB10
#define WireNFC MyWire
TwoWire MyWire(SDA_PIN, SCL_PIN);
ST25DV st25dv(12, -1, &MyWire);
#else
#define DEV_I2C Wire
ST25DV st25dv(12, -1, &DEV_I2C);
#endif

void setup() {
const char uri_write_message[] = "st.com/st25"; // Uri message to write in the tag
const char uri_write_protocol[] = URI_ID_0x01_STRING; // Uri protocol to write in the tag
String uri_write = String(uri_write_protocol) + String(uri_write_message);

// Initialize serial for output.
SerialPort.begin(9600);

// The wire instance used can be omitted in case you use default Wire instance
if(st25dv.begin() == 0) {
SerialPort.println("System Init done!");
} else {
SerialPort.println("System Init failed!");
while(1);
}

if(st25dv.writeURI(uri_write_protocol, uri_write_message, "")) {
SerialPort.println("Write failed!");
while(1);
}

}

void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);


char cstr[10];
itoa(sensorValue, cstr, 10);


char uri_write_message[] = {cstr}; // Uri message to write in the tag
const char uri_write_protocol[] = URI_ID_0x01_STRING; // Uri protocol to write in the tag
String uri_write = String(uri_write_protocol) + String(uri_write_message);

if(st25dv.writeURI(uri_write_protocol, uri_write_message, "")) {
SerialPort.println("Write failed!");
while(1);
}

delay(1000);
}

How, exactly, does it "fail" ?

Have you got the unmodified example working?

It will not accept the modified variable in the loop: uri_write_message

here the original unmodified example:


#include "ST25DVSensor.h"

#define SerialPort      Serial

#if defined(ARDUINO_B_L4S5I_IOT01A)
// Pin definitions for board B-L4S5I_IOT01A
  #define GPO_PIN PE4
  #define LPD_PIN PE2
  #define SDA_PIN PB11
  #define SCL_PIN PB10
  #define WireNFC MyWire
  TwoWire MyWire(SDA_PIN, SCL_PIN);
  ST25DV st25dv(12, -1, &MyWire);
#else
  #define DEV_I2C         Wire
  ST25DV st25dv(12, -1, &DEV_I2C);
#endif

void setup() {
  const char uri_write_message[] = "st.com/st25";       // Uri message to write in the tag
  const char uri_write_protocol[] = URI_ID_0x01_STRING; // Uri protocol to write in the tag
  String uri_write = String(uri_write_protocol) + String(uri_write_message);

  // Initialize serial for output.
  SerialPort.begin(115200);

  // The wire instance used can be omitted in case you use default Wire instance
  if(st25dv.begin() == 0) {
    SerialPort.println("System Init done!");
  } else {
    SerialPort.println("System Init failed!");
    while(1);
  }

  if(st25dv.writeURI(uri_write_protocol, uri_write_message, "")) {
    SerialPort.println("Write failed!");
    while(1);
  }

}

void loop() {  
  //empty loop
} 

What do you mean by that? Do you get a compiler error? A runtime error? Or what?

here the errors :
auge.ino: In function 'void loop()':
auge.ino:53:31: error: invalid conversion from 'char*' to 'char' [-fpermissive]
53 | char uri_write_message[] = {cstr}; // Uri message to write in the tag
| ^~~~
| |
| char*

exit status 1

Compilation error: invalid conversion from 'char*' to 'char' [-fpermissive]

You need to post the message using the <CODE/> button - then the little arrow would line-up to point at the error it's referring to.

But the problem is:

auge.ino:53:31: error: invalid conversion from 'char*' to 'char'

ie, it wants something of type char, but you given it something of type char* - ie, a pointer to a char.

Not quite sure what you're intending here;

char cstr[10];
itoa(sensorValue, cstr, 10);

char uri_write_message[] = {cstr}; 

The itoa loads your sensor value as a string into the char array cstr - so why not just use that directly?

String uri_write = String(uri_write_protocol) + String(cstr);

I you wanted to copy the contents of cstr into another array, you would need to use strcpy or similar.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.