Show Posts
Pages: 1 ... 52 53 [54] 55 56 ... 143
796  Using Arduino / Programming Questions / Re: Memory and SD library problem on: November 23, 2013, 11:28:06 pm
You should try sdFat, it is a new and improved SD.h https://code.google.com/p/sdfatlib/

Both implementations of the SD library use at least a 512 byte buffer. Analyse your variable usage and see what you can do more efficiently, don't use Strings if you are currently, make int's the smallest size you can.

Post your code for quality help, I'm sure your problem can be solved trivially.
797  Using Arduino / Networking, Protocols, and Devices / Re: RF24: one loop takes 30ms :( on: November 23, 2013, 08:24:52 pm
Maybe there are lots of errors and the packets are re-sent, if the RF24 doesn't return until sent, then errors could slow things down. I'm starting to use these modules so I'll have a peek in the library code.

Just out of curiosity, have you tried using the radio at a higher speed ( RF24_2MBPS ). And quite possibly a faster SPI speed.
798  Using Arduino / Programming Questions / Re: manually parse json on: November 22, 2013, 05:16:16 am
You cannot assign to arrays, only initialise them.

If you want to initialise the array you could do this:

Code:
char cadena_temperatura[255] = { "{\"SENSOR_ID\":\"ID_SEN\",\"H_DEV\":\"H_DISPOSITIVO\",\"H_SENSOR\":\"H_SEN\",\"DESCRIPTION\":\"DESCTEMP\",\"ACCESS\":\"ACCESSTEMP\",\"VALOR\":temperatura,\"MIN01\":tmin,\"MAX01\":tmax,\"PERIODO\":PERIOD,\"UNITS\":\"UNITSTEMP\"}" };

In this code, ID_SEN, H_DISPOSITIVO and H_SEN aren't variables, they are just text in the string. More of a task ahead if you want the arrays contents in their place.
799  Using Arduino / Programming Questions / Re: Moving Functions to External Libraries on: November 22, 2013, 04:50:08 am
Quote
I might want to recompile to only bring in c.cpp and d.cpp  I don't want to load a/b/c/d.cpp at the same time if main.cpp only needs c.cpp and d.cpp.

Your sketch should only be including header files, there are only select reasons why one would need to control/include the cpp files. The library header that your sketch includes should contain or include the same headers the cpp files require.

The compiler will see what you aren't using and leave it out of the final product. What you want probably isn't needed for your situation, and is very difficult to achieve without templates as the library source files are compiled before your sketch so no compile time flag in the sketch will make a difference. What needs to happen essentially is the library must require something from the sketch effectively postponing the compilation. And the process may be far more involved that what your library is.
800  Using Arduino / Programming Questions / Re: Moving Functions to External Libraries on: November 21, 2013, 12:59:22 am
explain more, do you wan't the data that is not flagged in the global to be left out when compiled?

Or do you wish to set a flag (during runtime) which specifies which data set to use, and this selection can be changed (at runtime)?
801  Using Arduino / Programming Questions / Re: Moving Functions to External Libraries on: November 20, 2013, 08:57:21 pm
using the same extern approach posted above, or use a class with static members:

A.h
Code:
#ifndef HEADER_A
  #define HEADER_A
  class MyGlobals{
    public:
      static char myArr[ 5 ];
  };
#endif

A.cpp
Code:
#include "A.h"
char MyGlobals::myArr[ 5 ] = { 1,2,3,4,5 };

Then include A.h in your other headers/cpp files and access like:
Code:
char c = MyGlobals::myArr[ 0 ];
//c = 1

For less SRAM use look as storing data in PROGMEM ( forum search will find loads of info )
802  Using Arduino / Storage / Re: string format in SD card library on: November 20, 2013, 08:01:23 pm
A simple cast should fix:

Code:
File.write( ( uint8_t* ) &datasensor[0], datasensor.length() );

&datasensor[0] returns a char*, the function just needs its unsigned counterpart. ( unsigned char == uint8_t )
803  Using Arduino / Networking, Protocols, and Devices / Re: about connecting to Arduino Server with Ethernet through Processing on: November 20, 2013, 07:42:07 pm
I personally think  a web page is a far better medium for remote control, web technologies are very flexible and powerful these days. I haven't used processing so I'm not much help, however I did find this: http://processing.org/reference/libraries/net/
804  Using Arduino / Networking, Protocols, and Devices / Re: about connecting to Arduino Server with Ethernet through Processing on: November 20, 2013, 07:17:35 pm
If you are using the mega as a server, why not have it as aweb server and provide a config page to a browser, rather than trying to connect to processing.

Javascript and ajax will allow you to talk to the Arduino from the web page.

As a web page you can even use your phone to control the Arduino.
805  Using Arduino / Networking, Protocols, and Devices / Re: Thumbs way down for Arduino WiFi shield. Read before you buy on: November 20, 2013, 07:04:44 pm
The FLASH string helper F() uses String object to allocate memory so it takes more SRAM. The write(char*) simply calls write(char) repeatedly.

No it does not!

F(), uses PSTR
Code:
class __FlashStringHelper;
#define F(string_literal) (reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))

This writes byte by byte to 'write'.
Code:
size_t Print::print(const __FlashStringHelper *ifsh)
{
  const char PROGMEM *p = (const char PROGMEM *)ifsh;
  size_t n = 0;
  while (1) {
    unsigned char c = pgm_read_byte(p++);
    if (c == 0) break;
    n += write(c);
  }
  return n;
}
806  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield server test (new code Uno ok) on: November 20, 2013, 07:42:43 am
No those strings are in global SRAM all the time, all of them.

Try my library with this code, you may be surprised.

Code:

char buff[ 10 ];
BufferedPrinter b( client, buff, 10 );

b.print( F("HTTP/1.1 200 OK\r\nContent-Type: ") );
// send Content-Type
if(strcmp(fileType,"HTM") == 0) b.print( F("text/html\r\n") );
else if(strcmp(fileType,"PHP") == 0) b.print( F("text/html\r\n") );
else if(strcmp(fileType,"TXT") == 0) b.print( F("text/plain\r\n") );
else if(strcmp(fileType,"CSS") == 0) b.print( F("text/css\r\n") );
else if(strcmp(fileType,"GIF") == 0) b.print( F("image/gif\r\n") );
else if(strcmp(fileType,"JPG") == 0) b.print( F("image/jpeg\r\n") );
else if(strcmp(fileType,"JS") == 0) b.print( F("application/javascript\r\n") );
else if(strcmp(fileType,"ICO") == 0) b.print( F("image/x-icon\r\n") );
else if(strcmp(fileType,"PNG") == 0) b.print( F("image/png\r\n") );
else if(strcmp(fileType,"PDF") == 0) b.print( F("application/pdf\r\n") );
else if(strcmp(fileType,"ZIP") == 0) b.print( F("application/zip\r\n") );
else b.print( F("text/plain\r\n") );

b.flush();
807  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield server test (new code Uno ok) on: November 20, 2013, 07:25:49 am
All the strings passed to client.write are going to be in SRAM though.
My little class allows you to use write and progmem strings.
808  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield server test (new code Uno ok) on: November 20, 2013, 07:08:09 am
I just changed my code, I had the version using print, now the internals are all using write!
809  Using Arduino / Networking, Protocols, and Devices / Re: Ethernet shield server test (new code Uno ok) on: November 20, 2013, 07:00:00 am
Here is  a simple buffer I just whipped up, hopefully a good solution to your packet problem ( any size you can spare ):

Code:
class BufferedPrinter : public Print{

  public:
 
    BufferedPrinter( Print &p_Out, uint8_t *u_Buff, char c_Len ) : Output( p_Out ), Buff( u_Buff ), Cursor( 0x00 ), Max( c_Len ) {}
     
    ~BufferedPrinter( void ) { flush(); }
     
    void flush()
      {
        if( Cursor )
          Output.write( Buff, Cursor );
 
        Cursor = 0x00;
      }
     
    size_t write( uint8_t u_Data )
      {
        if( Cursor == Max ){
       
          Output.write( Buff, Cursor );
          Cursor = 0x00;
        }
        Buff[ Cursor++ ] = u_Data;
        return 0x01;
      }
     
  protected:
 
    Print &Output;
    uint8_t *Buff;
    char Cursor;
    char Max;
};

It has simple use like this:

Code:
 uint8_t buff[ 10 ];

  BufferedPrinter b( Serial, buff, 10 );
  b.print( F("This is a buffered string read from progmem!") );
  b.flush();

Or for an inline approach:

Code:
BufferedPrinter( Serial, buff, 10 ).print( F("This is a buffered string read from progmem!") );

You can use any Print object as output:

Code:
 uint8_t buff[ 10 ];
  EthernetClient c;

  BufferedPrinter b( c, buff, 10 );
  b.print( F("This is a buffered string read from progmem!") );
  b.flush();

Have fun.

EDIT: no dynamic memory allocations either, it can all be on the stack.
810  Using Arduino / Storage / Re: string format in SD card library on: November 20, 2013, 04:57:40 am
Could do this:

Code:
File.write( &datasensor[0], datasensor.length() );
Pages: 1 ... 52 53 [54] 55 56 ... 143