SD - prgramming

Everything about programming the platform and using the Waspmote API
Post Reply
nazerke
Posts: 27
Joined: Fri Jun 23, 2017 11:20 am

SD - prgramming

Post by nazerke » Tue Oct 24, 2017 10:11 am

Hello!

I would like to append data to SD card: my code looks like this

char filename[] = "REC1.TXT";

uint8_t first;
uint8_t secon;
uint8_t third;
uint8_t fourth;
uint8_t fifth;
uint8_t sixth;
uint8_t seventh;
uint8_t eight;
....
void loop(){

SD.append(filename, first);
SD.append(filename, secon);
SD.append(filename, third);
SD.append(filename, fourth);
SD.append(filename, fifth);
SD.append(filename, sixth);
SD.append(filename, seventh);
SD.append(filename, eight);

SD.append(filename, xbee802.scannedBrothers.RSSI*(-1),DEC);

.....
}
it shows error.
how can I add this information to the SD-card?

thank you!

regards

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: SD - prgramming

Post by libelium-dev » Tue Oct 24, 2017 12:50 pm

Hi,

What error do you get? Could you try to declare the variables as uint8_t*?

Code: Select all

uint8_t* first;
uint8_t* secon;
...
Regards

nazerke
Posts: 27
Joined: Fri Jun 23, 2017 11:20 am

Re: SD - prgramming

Post by nazerke » Thu Oct 26, 2017 11:22 am

my code:

Code: Select all


#include <WaspXBee802.h>
char filename[] = "REC1.TXT";

uint8_t* first;
uint8_t* secon;
uint8_t* third;
uint8_t* fourth;
uint8_t* fifth;
uint8_t* sixth;
uint8_t* seventh;
uint8_t* eight;
int rssi;
uint8_t sd_answer;

void setup()
{ 
  // init USB port
  USB.ON();
  RTC.ON();
  SD.ON();
  sd_answer = SD.create(filename);
  xbee802.ON();
}

void loop()
{ 
  xbee802.scanNetwork(); 
  SD.appendln(filename, "\n");
  printScanInfo();  
}  

void printScanInfo()
{  
/*    RTC.getTime();
    snprintf(own_time, sizeof(own_time), " %02d:%02d:%02d ", RTC.hour, RTC.minute, RTC.second );
    USB.print(own_time);
    sd_answer = SD.append(filename, own_time);
  */
    for(int i=0; i<xbee802.totalScannedBrothers; i++)
  {  
    USB.print(F(" "));
    first = xbee802.scannedBrothers[i].SH[0];  
    secon = xbee802.scannedBrothers[i].SH[1]; 
    third = xbee802.scannedBrothers[i].SH[2]; 
    fourth = xbee802.scannedBrothers[i].SH[3];
    fifth = xbee802.scannedBrothers[i].SL[0]; 
    sixth = xbee802.scannedBrothers[i].SL[1]; 
    seventh = xbee802.scannedBrothers[i].SL[2]; 
    eight = xbee802.scannedBrothers[i].SL[3];

    USB.printHex(first);  
    USB.printHex(secon); 
    USB.printHex(third); 
    USB.printHex(fourth);
    USB.printHex(fifth); 
    USB.printHex(sixth); 
    USB.printHex(seventh); 
    USB.printHex(eight);

    SD.append(filename, first);  
    SD.append(filename, secon); 
    SD.append(filename, third); 
    SD.append(filename, fourth);
    SD.append(filename, fifth); 
    SD.append(filename, sixth); 
    SD.append(filename, seventh); 
    SD.append(filename, eight);
  
    USB.print(F(" "));
    USB.print(xbee802.scannedBrothers[i].RSSI*(-1),DEC);
  }
}
and error that I have:
Arduino: Waspmote PRO IDE (Windows 10), Board: "Waspmote API v028"

C:\Users\w\Documents\Waspmote\test1\test1.pde: In function 'void printScanInfo()':

test1:42: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

first = xbee802.scannedBrothers.SH[0];

^

test1:43: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

secon = xbee802.scannedBrothers.SH[1];

^

test1:44: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

third = xbee802.scannedBrothers.SH[2];

^

test1:45: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

fourth = xbee802.scannedBrothers.SH[3];

^

test1:46: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

fifth = xbee802.scannedBrothers.SL[0];

^

test1:47: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

sixth = xbee802.scannedBrothers.SL[1];

^

test1:48: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

seventh = xbee802.scannedBrothers.SL[2];

^

test1:49: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

eight = xbee802.scannedBrothers.SL[3];

^

test1:51: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(first);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

test1:52: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(secon);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

test1:53: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(third);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

test1:54: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(fourth);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

test1:55: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(fifth);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

test1:56: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(sixth);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

test1:57: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(seventh);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

test1:58: error: invalid conversion from 'uint8_t* {aka unsigned char*}' to 'char' [-fpermissive]

USB.printHex(eight);

^

In file included from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspClasses.h:48:0,

from C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/Waspmote.h:28,

from sketch\test1.pde.cpp:1:

C:\Users\w\Documents\waspmote-pro-ide-v06.02\hardware\waspmote\avr\cores\waspmote-api/WaspUSB.h:218:7: note: initializing argument 1 of 'void WaspUSB::printHex(char)'

void printHex(char n);

^

C:\Users\w\Documents\Waspmote\test1\test1.pde: At global scope:

test1:72: error: expected declaration before '}' token

}}

^

exit status 1
invalid conversion from 'uint8_t {aka unsigned char}' to 'uint8_t* {aka unsigned char*}' [-fpermissive]

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.



THank you in advance

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: SD - prgramming

Post by libelium-dev » Thu Oct 26, 2017 12:56 pm

Hi,

There are some inconsistencies in the variable types. Could you try with the following code?

Code: Select all

#include <WaspXBee802.h>
char filename[] = "REC1.TXT";

uint8_t first;
uint8_t secon;
uint8_t third;
uint8_t fourth;
uint8_t fifth;
uint8_t sixth;
uint8_t seventh;
uint8_t eight;
int rssi;
uint8_t sd_answer;

void setup()
{ 
  // init USB port
  USB.ON();
  RTC.ON();
  SD.ON();
  sd_answer = SD.create(filename);
  xbee802.ON();
}

void loop()
{ 
  xbee802.scanNetwork(); 
  SD.appendln(filename, "\n");
  printScanInfo();  
}  

void printScanInfo()
{  
/*    RTC.getTime();
    snprintf(own_time, sizeof(own_time), " %02d:%02d:%02d ", RTC.hour, RTC.minute, RTC.second );
    USB.print(own_time);
    sd_answer = SD.append(filename, own_time);
  */
    for(int i=0; i<xbee802.totalScannedBrothers; i++)
  {  
    USB.print(F(" "));
    first = xbee802.scannedBrothers[i].SH[0];  
    secon = xbee802.scannedBrothers[i].SH[1]; 
    third = xbee802.scannedBrothers[i].SH[2]; 
    fourth = xbee802.scannedBrothers[i].SH[3];
    fifth = xbee802.scannedBrothers[i].SL[0]; 
    sixth = xbee802.scannedBrothers[i].SL[1]; 
    seventh = xbee802.scannedBrothers[i].SL[2]; 
    eight = xbee802.scannedBrothers[i].SL[3];

    USB.printHex(first);  
    USB.printHex(secon); 
    USB.printHex(third); 
    USB.printHex(fourth);
    USB.printHex(fifth); 
    USB.printHex(sixth); 
    USB.printHex(seventh); 
    USB.printHex(eight);

    SD.append(filename, (uint8_t*) first);  
    SD.append(filename, (uint8_t*) secon); 
    SD.append(filename, (uint8_t*) third); 
    SD.append(filename, (uint8_t*) fourth);
    SD.append(filename, (uint8_t*) fifth); 
    SD.append(filename, (uint8_t*) sixth); 
    SD.append(filename, (uint8_t*) seventh); 
    SD.append(filename, (uint8_t*) eight);
  
    USB.print(F(" "));
    USB.print(xbee802.scannedBrothers[i].RSSI*(-1),DEC);
  }
}
Regards

nazerke
Posts: 27
Joined: Fri Jun 23, 2017 11:20 am

Re: SD - prgramming

Post by nazerke » Fri Oct 27, 2017 12:55 pm

Thank you for your reply!

The code runs. But it does not append any data to SD card.

What might be the reason?

Thank you in advance

Regards,
Nazerke

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: SD - prgramming

Post by libelium-dev » Mon Oct 30, 2017 9:45 am

Hi,

Then please try to create a string with the MAC of the scanned brothers. It would be something like this

Code: Select all

    first = xbee802.scannedBrothers[i].SH[0];  
    secon = xbee802.scannedBrothers[i].SH[1]; 
    third = xbee802.scannedBrothers[i].SH[2]; 
    fourth = xbee802.scannedBrothers[i].SH[3];
    fifth = xbee802.scannedBrothers[i].SL[0]; 
    sixth = xbee802.scannedBrothers[i].SL[1]; 
    seventh = xbee802.scannedBrothers[i].SL[2]; 
    eight = xbee802.scannedBrothers[i].SL[3]

    char message[20];
    snprintf( message, sizeof(message), "%d%d%d%d%d%d%d%d", first,secon,third,fourth,fifth,sixth,seventh,eight);

    SD.append(filename, message);  
Hope finally if solve the issue.
Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest