Go Down

Topic: Need Help: ANT7-T-M24SR64  (Read 155 times) previous topic - next topic

berkayozbek

Hello everyone,

Im trying to send data to M24SR64 Tag via its tool ANT7-T-M24SR64. And i want to read sent data from the telephone. Data will be sensor outcomes, i mean integer values.

But i have no idea how to write these integer values to M24SR64 Tag. I searched a lot but couldn't find anything.

I found the library of STM " https://github.com/stm32duino/M24SR64-Y " but got a lot of error while compiling. Its examples like "WriteText" might be helpful for me but cannot even run the code.

On the other hand, I tried the library " https://github.com/rena2019/ArduinoM24SR/tree/master/examples" but its writing example didn't work as i expected. I cannot write anything payload or record.

Any help will make me happy.

Thank you so much.

pylon

It would help if you tell us what kind of problem you have. So post the errors you get from the compiler (if there are any) and the serial output of the sketch if it compiles.

As you didn't specify your Arduino model we expect you to have an UNO.

berkayozbek

Hi,

Thank you so much for your answer. Yes, it is uno. Actually im going to use atmega328p as standalone but first im working with arduino to set the logic.

I can write the text to record and get the written text on the mobile phone (instead of writing urirecord, i used textrecord). Here is my code;



Code: [Select]


#include <PN532.h>
#include <NfcAdapter.h>
#include <Wire.h>
#include <crc16.h>
#include <M24SR.h>

#define gpo_pin 7
M24SR m24sr(gpo_pin);

//http://playground.arduino.cc/Code/AvailableMemory
int freeRam () {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
int x=5;
const char URI1[] PROGMEM = "http://regnerischernachmittag.wordpress.com/?writesample";
const char URI2[] PROGMEM = "https://github.com/rena2019/ArduinoM24SR";
const char URI3[] PROGMEM = "https://twitter.com/regnerischerTag";

void setup()
{
   Serial.begin(9600);
   randomSeed(analogRead(0));
   //for debug purpose
   //m24sr._verbose = true;
   //m24sr._cmds = true;
   m24sr._setup();
   displayFreeRAM();
   NdefMessage message = NdefMessage();
   switch (x==5) {
     case 0:  message.addTextRecord("Hello, Arduino!");
              break;
     case 1:  message.addTextRecord("xxxxxx");
              break;
     default: message.addTextRecord("yyyyyyyy");
              break;
   }
           
   displayFreeRAM();
   m24sr.writeNdefMessage(&message);
   Serial.print(F("\r\nUse NFC phone/reader to read out NFC tag content!"));
}


 
   
void loop()
{
}

void displayFreeRAM() {
  Serial.print(F("\r\nfree RAM: "));
  Serial.println(freeRam(), DEC);
}





But, i have variables instead of texts, i mean the sensor variables. How can i edit the code to write the variables on the screen of mobile phone ?

For example: x=5

message.addTextRecord("x", DEC);  etc.


Thank you.


pylon

You may use dtostrf (for floats) or snprintf (for integers) to convert number variables to strings.

berkayozbek

#4
Jul 23, 2018, 09:31 pm Last Edit: Jul 23, 2018, 09:33 pm by berkayozbek
Hi,

I solved my problem with the codes below for those who might have the same problem :

Code: [Select]

String try1 = dtostrf(Now, 1, 0, buffer);
String try2 = (try1);
message.addUriRecord(try2);



By this way, i could write the variables to the NFC.


However, i have another problem. I am sensing the capacitance between A0 and A2 and getting time information via millis(). I need to set another variable which must have the millis value. For example, let say, the sensing capacitance value exceeds 2uF when millis = 100000. I have to flag this millis value in another variable and hold it. How can i do it ?

Lastly, in my code i have displayFreeRAM command. However, the free ram decreases in each second up to 150. After this 150 value, the serial monitor stops and cannot perform any operation. How can i solve this problem ? Is there any way to clear the ram ?

Thank you

pylon

Quote
or example, let say, the sensing capacitance value exceeds 2uF when millis = 100000. I have to flag this millis value in another variable and hold it. How can i do it ?
I may have misunderstood your question, in that case just ask again and explain in more detail.
The millis() function returns a 32bit value, so you may store the current value in a variable of type uint32_t.

Quote
Lastly, in my code i have displayFreeRAM command. However, the free ram decreases in each second up to 150. After this 150 value, the serial monitor stops and cannot perform any operation. How can i solve this problem ? Is there any way to clear the ram ?
That means you have a memory leak. A haven't seen the complete code but from the tiny excerpt above I can see that you're using the String class. This class fragments your memory and in no time you end with having no free RAM space anymore.
There may be other leaks (post your complete code if you need help finding the leak) but removing the String class and working with C-style strings (character arrays) instead is a good starting point.

Go Up