Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can't save the value of the function on the ext file

Status
Not open for further replies.

senior-student

Newbie level 4
Newbie level 4
Joined
Dec 7, 2012
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,319
Hi every one,

I am using a wireless sensoe, and it has its own compiler with c language.
what i want is to save the accelerometer value on a text file on the SD card of the wireless.
The sensor has an accelerometer library.
my problem is when i want to write to the text value the value of the function not the value of the function.
so i tried another manner and i got an error.

Here is my code:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const char* filename="data.txt";
void setup(){
  //setup for Serial port
  USB.begin();
 
 SD.ON();
  // setup the GPS module
  USB.println("Setting up GPS...");
  
   ACC.ON();
  
  // waiting for GPS is connected to satellites
  while( !ACC.check()) delay(1000);
  
  USB.println("Connected");
 
}
 
void loop(){
 byte check = ACC.check();
  // Getting Time
 uint8_t x_acc = ACC.getX();
 
  //----------Y Values-----------------------
  int y_acc = ACC.getY();
 
  //----------Z Values-----------------------
  int z_acc = ACC.getZ();
  USB.print("\n------------------------------\nCheck: 0x"); 
  USB.println(check, HEX);
  USB.println("\n \t0X\t0Y\t0Z"); 
  USB.print(" ACC\t"); 
  USB.print(x_acc, DEC);
  USB.print("\t"); 
  USB.print(y_acc, DEC);
  USB.print("\t"); 
  USB.println(z_acc, DEC);
  
  SD.appendln("data.txt",":"); 
  SD.appendln("data.txt",x_acc);
  SD.appendln("data.txt",":");
  SD.appendln("data.txt",y_acc);
  SD.appendln("data.txt",":");
  SD.appendln("data.txt",z_acc);
  
  
  USB.println("Write to 'data.txt' ");
 
}


and here is the error what i got:
Code:
In function 'void loop()':
error: call of overloaded 'appendln(const char [9], uint8_t&)' is ambiguousC:\Users\Administrator.hkfong-PC\Desktop\waspmote-ide-v.02-windows\waspmote-ide-v.02-windows\hardware\cores\waspmote-api-v.029/WaspSD.h:593: note: candidates are: uint8_t WaspSD::appendln(const char*, const char*) <near match>
C:\Users\Administrator.hkfong-PC\Desktop\waspmote-ide-v.02-windows\waspmote-ide-v.02-windows\hardware\cores\waspmote-api-v.029/WaspSD.h:602: note:                 uint8_t WaspSD::appendln(const char*, uint8_t*) <near match>
hope you can help me.
thanks and regards
 
Last edited by a moderator:

I think appendln() function takes strings as arguments. You are passing x-acc, y_acc, z_acc to the function. They are integer variables. So you have to convert x_acc, y_acc, and z_acc to strings and pass the strings as arguments to appendln() function.
 

I think appendln() function takes strings as arguments. You are passing x-acc, y_acc, z_acc to the function. They are integer variables. So you have to convert x_acc, y_acc, and z_acc to strings and pass the strings as arguments to appendln() function.


Can u please provide for me a simple example of converting integer to string
 

Any one can help me by telling me how to convert integer to string please?

- - - Updated - - -

Any one can help me by telling me how to convert integer to string please?
 

Code:
string[0] = (number/1000) + 48;
string[1] = (number/100)%10 + 48;
string[2] = (number/10)%10 + 48;
string[3] = (number/1)%10 + 48;
string[4] = '\0'


SD.appendln("data.txt",":"); 
SD.appendln("data.txt",string);
SD.appendln("data.txt",":");
SD.appendln("data.txt",string);
SD.appendln("data.txt",":");
SD.appendln("data.txt",string);
 
Last edited:

when i tried what you wrote i got this error:
Code:
In function 'void loop()':
error: 'string' was not declared in this scope
and this is my code:
Code:
const char* filename="data.txt";
void setup(){
  //setup for Serial port
  USB.begin();
 
 SD.ON();
  // setup the Accelerometer module
  USB.println("Setting up Accelerometer...");
  
   ACC.ON();
  
  // waiting for Accelerometer is connected to satellites
  while( !ACC.check()) delay(1000);
  
  USB.println("Connected");
 
}
 
void loop(){
 byte check = ACC.check();
 //----------X Values-----------------------
 uint8_t x_acc = ACC.getX();
 
  //----------Y Values-----------------------
  int y_acc = ACC.getY();
 
  //----------Z Values-----------------------
  int z_acc = ACC.getZ();
  USB.print("\n------------------------------\nCheck: 0x"); 
  USB.println(check, HEX);
  USB.println("\n \t0X\t0Y\t0Z"); 
  USB.print(" ACC\t"); 
  USB.print(x_acc, DEC);
  USB.print("\t"); 
  USB.print(y_acc, DEC);
  USB.print("\t"); 
  USB.println(z_acc, DEC);
  
        string[0] = (x_acc/1000) + 48;
        string[1] = (x_acc/100)%10 + 48;
	string[2] = (x_acc/10)%10 + 48;
	string[3] = (x_acc/1)%10 + 48;
	string[4] = '\0'
  
	SD.appendln("data.txt",":"); 
	SD.appendln("data.txt",string);
	SD.appendln("data.txt",":");
	SD.appendln("data.txt",string);
	SD.appendln("data.txt",":");
	SD.appendln("data.txt",string);
  
  
  USB.println("Write to 'data.txt' ");
 
}
 

If string is not declared then declare it like this

Code:
 unsigned char string[5];

Declare it in Void Main() { } or as global variable.

Code:
unsigned char str_x_acc[5], str_y_acc[5], str_z_acc[5];



str_x_acc[0] = (x_acc/1000) + 48;
str_x_acc[1] = (x_acc/100)%10 + 48;
str_x_acc[2] = (x_acc/10)%10 + 48;
str_x_acc[3] = (x_acc/1)%10 + 48;
str_x_acc[4] = '\0'
  
SD.appendln("data.txt",":"); 
SD.appendln("data.txt",str_x_acc);

str_y_acc[0] = (y_acc/1000) + 48;
str_y_acc[1] = (y_acc/100)%10 + 48;
str_y_acc[2] = (y_acc/10)%10 + 48;
str_y_acc[3] = (y_acc/1)%10 + 48;
str_y_acc[4] = '\0'

SD.appendln("data.txt",":");
SD.appendln("data.txt",str_y_acc);

str_z_acc[0] = (z_acc/1000) + 48;
str_z_acc[1] = (z_acc/100)%10 + 48;
str_z_acc[2] = (z_acc/10)%10 + 48;
str_z_acc[3] = (z_acc/1)%10 + 48;
str_z_acc[4] = '\0'

SD.appendln("data.txt",":");
SD.appendln("data.txt",str_z_acc);
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top