Loading...
  Show Posts
Pages: 1 ... 8 9 [10] 11 12 13
136  Using Arduino / Programming Questions / Re: sending data from one Arduino to another via xbee on: November 19, 2012, 01:05:47 am
Code:
if(Serial.available()) {          // Is serial data available?
    char outgoing = Serial.read();  // Read character, send to XBee
    Xbee.print(outgoing);
  }


May be this is problem

Code:
if(Serial.available()) {          // Is serial data available?
    while(Serial.available()){
    char outgoing = Serial.read();  // Read character, send to XBee
    Xbee.print(outgoing);
    }
  }

And use insert # (code options)
Code:
 
137  Using Arduino / Programming Questions / Re: Controller Hang whenever execute both functions(Parsing File and Writing File) on: November 17, 2012, 04:13:37 am
Quote
How big is this file?

At this time less than 300 bytes.
138  Using Arduino / Programming Questions / Re: Controller Hang whenever execute both functions(Parsing File and Writing File) on: November 17, 2012, 04:06:19 am
Thnx Nick Gammon

Quote
I recommend reworking your code to manage without String. Use C-style strings instead (strcpy, strcat, strcmp, etc.).

Ok.  One more question
Is this is a way about which you are suggesting? 
Code:
  myFile = SD.open("config2.txt", FILE_READ);

  Serial.println(myFile.size());
  char* buf = (char*) malloc(myFile.size());
  readed = myFile.read(buf,myFile.size());
  Serial.println(readed);
  myFile.close();
139  Using Arduino / Programming Questions / Controller Hang whenever execute both functions(Parsing File and Writing File) on: November 17, 2012, 03:01:29 am
I am trying to create database by using JSON and SD library.
But i stuck in a problem "Controller hanging" after removing lot of stuff to make Memory Efficent Solution still i happens again.

Specifications
Flash 128k
SRAM 16k

Hardware
Offical Arduino Ethernet Shield
Zigduino board

To debug problem four tests were perform

Test 1 Only Parsing funtion Call
Status Ok
Test 2 Only Writng funtion Call
Status Ok
Test 3 Only Parsing funtion Call
Status Ok
Test 4 Both funtion Call
Status Hang

This the code and outputs of all tests attached .Status ok in zip file due limitation of 4 files

Code:
#include <aJSON.h>
#include <SD.h>

File myFile;

char* readFile(char* file)
{
  Serial.println(FreeRam(),DEC);
  char buf[30];
  char strFile[600];
  int16_t  readed;

  myFile = SD.open(file,FILE_READ);
  if(myFile)
  {
    readed = myFile.read(buf,30);
    buf[readed] = '\0';
    String stringOne =  String(buf);
    while( readed > 0) {
      readed = myFile.read(buf,30);
      buf[readed] = '\0';
      stringOne += String(buf);
    }
    myFile.close();
    stringOne.toCharArray(strFile,stringOne.length()+1);
    //Serial.println(strFile);
    return strFile;
  }
  else
    Serial.println("Fail to open file");
}
void parseFile(char* object)
{
  Serial.println(FreeRam(),DEC);
  char* pch =readFile("test.txt");
  Serial.println(pch);
  aJsonObject* root = aJson.parse(pch);
  
  if (root != NULL) {
    Serial.println(F("Parsed successfully 1 "));
    aJsonObject* query = aJson.getObjectItem(root, object);
    
    char *json_String=aJson.print(query);
    
    Serial.println(json_String);
    Serial.println(F("**"));
    free(json_String);
    free(pch);
  }
  else
    Serial.println(F("Parsed unsuccessfully 1"));
  aJson.deleteItem(root);
}

void writeDb(char* object)
{
  char* buff = readFile("test.txt");
  //Serial.println(buff);
  Serial.println(FreeRam(),DEC);
  Serial.println(F("HANG POINT"));
  aJsonObject* root = aJson.parse(buff);

  if (root != NULL) {
    Serial.println(F("writdb successfully 1 "));

    aJsonObject *tmp = aJson.createObject();
    aJson.addStringToObject(tmp, "value1","1101");
    aJson.addStringToObject(tmp, "value2","1102");
    aJson.addStringToObject(tmp, "value3","1103");
    aJson.replaceItemInObject(root, object, tmp);

    SD.remove("test.txt");
    delay(100);
    myFile = SD.open("test.txt", FILE_WRITE);

    // if the file opened okay, write to it:
    if (myFile) {
      char* json_String = aJson.print(root);
      
      myFile.print(json_String);
      myFile.close();
      Serial.println(F("FileClosed"));
      Serial.println(F("WR**"));

      //aJson.deleteItem(tmp);
      free(json_String);
      free(buff);
    }
    else
      Serial.println(F("File Not Truncate"));
  }
  else
    Serial.println(F("wrtidb unsuccessfully 1 "));
  aJson.deleteItem(root);
}
void setup() {
  Serial.begin(9600);

  pinMode(SS, OUTPUT);                       // set the SS pin as an output (necessary!)
  digitalWrite(SS, HIGH);                    // but turn off the W5100 chip!
  if (!SD.begin(4)) {
    Serial.println(F("initialization failed!"));
    return;
  }
  Serial.println(FreeRam(),DEC);
  parseFile("config0");
  Serial.println(F("Parse done"));
  writeDb("config0");
  Serial.println(F("Write done"));
  Serial.println(FreeRam(),DEC);
}

void loop() {
  // Nothing to do
  ;
}


I really need suggestion because after playing 10 hours with this now i am in Blackout Stage. smiley-cool
140  Using Arduino / Programming Questions / Re: arduino mega serial talking with strings on: November 16, 2012, 09:16:56 am
[code][/code] use insert code.

Moderator edit: Dummy code tags corrected.
141  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 16, 2012, 08:50:36 am
Quote
That would have the additional advantage to be able to tweak the table without modifying verifying and re-uploading the sketch

EEPROM Or SD card best options.
142  Using Arduino / Programming Questions / Re: GoogleMaps/Earth, Coding, TinyGPS, EM406a, UNO on: November 16, 2012, 08:47:46 am
Quote
I would like to use google map on pc so later i move to presenting my data on mobile phone. And no i don't know how to display gps data on other platforms , i tried mini gps and SirfDemo but didn't manage to display anything 

http://www.sourcecodester.com/visual-basic/how-use-google-map-api-and-google-earth-plug-vb6.html
143  Using Arduino / Programming Questions / Re: Importing a large lookup table on: November 16, 2012, 08:41:39 am
Put it in Flash memory of controller
144  Using Arduino / Programming Questions / Re: RFID Question on: November 16, 2012, 08:35:58 am
Quote
I was pretty sure that it was a dude with an all lower case name that Grumpy_Mike was posting about in the Website and Forum category, but now I'm not so sure.

??????

Quote
NULL terminated.

yep ok. i miss this point
145  Using Arduino / Programming Questions / Re: Problem with reading voltages and possible code faults. on: November 16, 2012, 01:42:12 am
Oops but not a big problem

Use Pin 0 (to blink led) to check if() statements

first time in this
Code:
if (finalval >= 700) {Blink}

and so on one by one


146  Using Arduino / Programming Questions / Re: Problem with reading voltages and possible code faults. on: November 16, 2012, 01:13:27 am
lets start trouble shooting by using Serial

In setup()
Code:
Serial.begin(9600);
finalval = addfloat / 2;
Serial.print(finalval);

if (finalval >= 700) {
    Serial.print("Greater Than 700");
    buzz = 591;
    cut = 570;
  }
  else if ( finalval >= 450) {
    Serial.print("Greater Than 450");
    buzz = 398;
    cut = 367;
  }

In loop
Code:
finalval = addfloat / 4;
Serial.print(finalval);

if (finalval <= buzz && !buzzed) {
      Serial.print("finalval <= buzz && !buzzed" TRUE);
      tone(1, 4500);
      delay(250);
      noTone(1);
      delay(250);
      tone(1, 4500);
      delay(250);
      noTone(1);
      delay(250);
      tone(1, 4500);
      delay(1000);
      noTone(1);
      buzzed = true;
    }

Add these statments and find the reason and one important thing also share with me smiley-cool
147  Using Arduino / Programming Questions / Re: AS3 to Arduino - Passing Strings on: November 16, 2012, 12:49:01 am
change this
Code:
while(Serial.available() == 0);
 
  //readCommand();
  //Serial.println(command);
 
 
  readCommand();
to
Code:
if(Serial.available() > 0)
{
readCommand();
}

this
Code:
while (!Serial.available())
;
c = Serial.read();
to
Code:
while(Serial.available() > 0)
{
c = Serial.read();
if (c == '\r' || c == '\n') {
break;
}
commandBuffer[i] = c;
i++;
}
148  Using Arduino / Programming Questions / Re: Using SD library with analog pins on: November 16, 2012, 12:29:36 am
SD pin assignments in the Sd2PinMap.h
this is path but check according your library path
\arduino-1\libraries\SD\utility
149  Using Arduino / Programming Questions / Re: Problem with reading voltages and possible code faults. on: November 16, 2012, 12:24:59 am
Code:
val = analogRead(2);
delay(500);
val1 = analogRead(2);
What is the status of your battery when you run this first time? because setup() execute only one time.
150  Using Arduino / Programming Questions / Re: PS2KeyBoard Library string or char convert to float so calculations may be made? on: November 16, 2012, 12:21:42 am
Code:
String StepDistance = "";
float FStepDistance ='';

StepDistance = StepDistance + c;
FStepDistance = float(StepDistance);

Float Conversion

Code:
char *StepDistance = "1.900";
float FStepDistance = atof(StepDistance);

OR
char *StepDistance = "1.900";
float FStepDistance ;

sscanf(StepDistance, "%f", FStepDistance);
Pages: 1 ... 8 9 [10] 11 12 13