Show Posts
Pages: 1 ... 50 51 [52] 53 54 ... 146
766  Using Arduino / Networking, Protocols, and Devices / Re: Error when printing insanely long strings in HW serial on: December 15, 2013, 05:28:21 pm
There is a PROGMEM attribute, use that keyword to search the forums/google on reading flash memory so you can use it.

Code:
char myStr[] PROGMEM = "This is a flash string";

For ease of printing you can do this:
Code:
Serial.println( (__FlashStringHelper *) myStr  );

Here is a link to the API for custom control.
http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html
767  Using Arduino / Networking, Protocols, and Devices / Re: posted data not read by php script on: December 15, 2013, 05:14:42 pm
You need to have the same name/value pairs for POST data too. Using the Print library you can convert/output integers/floats as text.

I would use GET as you don't have the same security requirements as a browser where its preferable to use POST to hide the data from users viewing the URL. If you have more complex text ( not a-z, 0-9 ) you can send it with the help of the URI encoder. Binary data can be converted to text first using the base64 encoder. You do not need encoding on simple name value pairs that are just letters and numbers.

GET is easy to debug using log files ( can see data passed ), once complete converting to POST is an option. With POST you should make sure never to use ( or use carefully ) the PHP $_REQUEST global as someone could override POST data with GET style values in a URL. Stick with the $_GET and $_POST global's.

To begin with, I think this should be a simple comparison of a GET vs POST.

Get:
Code:
client.print( "GET /Arduino/sendmail.php?data=" );
client.print( data, DEC );
client.println( " HTTP/1.0" );
client.println( "Connection: close" );

Post:
Code:
client.println("POST /Arduino/sendmail.php HTTP/1.0");
client.println("Host: 123.123.123.123");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Connection: close\r\n\r\ndata=");
client.print( data, DEC );


Here is the request for comments document regarding the HTTP/1.1 protocol: http://www.w3.org/Protocols/rfc2616/rfc2616.html
768  Using Arduino / Programming Questions / Re: Question about Arrays. on: December 15, 2013, 06:59:58 am
It used to be the case that your array in the first post could be declared as

Code:
char keys[][COLS] = {
   {'1','2','3'},
   {'4','5','6'},
   {'7','8','9'},
   {'*','0','#'}
};

because the compiler could figure the first dimension out.  I'm not sure if this is still legal.   Anyway, it doesn't make much sense
to do it,  if you know what the dimension is,  unless you are trying to confuse someone looking at your code.

Its correct, its also valid for array types in function parameter lists. Its because the compiler only needs to know the last dimension to be able to traverse a whole array ( more than one dimension ). This also means Its valid to pass arrays that only have a unique size on the last dimension to the same prototype.

Consider this example:
Code:
char a[][4] = {
  { 'a', 'a', 'a', 0 },
  { 'b', 'b', 'b', 0 },
  { 'c', 'c', 'c', 0 },
  { 'd', 'd', 'd', 0 },
};

char b[][4] = {
  { 'e', 'e', 'e', 0 },
  { 'f', 'f', 'f', 0 },
  { 'g', 'g', 'g', 0 },
};

void foo( char Arr[][4], int inner )
  {
    int temp = inner - 1;
    while( --inner >= 0 ){
      Serial.println( Arr[ temp - inner ] );
    }
  }

void setup() {
  Serial.begin( 9600 );
  foo( a, 4 );
  foo( b, 3 );
}

void loop() {}

The template version of this function is even better as it provides the actual missing values. However it probably still has the same overhead as hard coding each value ( overloading for different lengths )

EDIT: the template version proved to be better equal with a small test ( not thorough ).
769  Using Arduino / Networking, Protocols, and Devices / Re: Distance and direction with RF on: December 15, 2013, 06:35:55 am
Could put a single xbee in a directional antenna ( dish ) then spin it looking for the strongest signal, but its also no location finder.

EDIT: Maybe incorporate a ping to discover transmit times.
770  Using Arduino / Programming Questions / Re: Serial.print error 0x80 on: December 15, 2013, 05:43:09 am
Null terminate your data as pauls pointed out its absence is the problem:

Code:
char c[5]={0x80,0x55,0x6d,0xb0,0x00};

Also the String only needs to reserve the number of characters needed (4), the String lib handles the +1 for the terminator.
771  Using Arduino / Networking, Protocols, and Devices / Re: Distance and direction with RF on: December 15, 2013, 04:59:12 am
I would first jump at triangulation, three radios placed far enough apart should give either one or two dominant strengths depending on weather the target is on an edge or face of the triangle.
772  Using Arduino / Networking, Protocols, and Devices / Re: Error when printing insanely long strings in HW serial on: December 15, 2013, 03:59:49 am
That string ( define ) will be in ram if used, there are things you need to set for data to reside in flash. However if you have that part sorted already I might have an answer for you.

I had errors printing from flash using the ethernet shield, it was due to the flash print code outputting one char at a time, therefore there was an overload of packets being sent. To solve the problem I created a buffered printer which collects x bytes before sending it on, so  packets became a reasonable size:

For a detailed explanation:
http://forum.arduino.cc/index.php?topic=197103.msg1475339#msg1475339

This is a possible way of using it:
Code:
uint8_t buff[ 10 ];
  EthernetClient c; //c would be your EthernetClient.

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

The code:
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;
};
773  Using Arduino / Networking, Protocols, and Devices / Re: posted data not read by php script on: December 15, 2013, 02:45:53 am
What does data contain?

Also, if you use HTTP/1.1 you cannot end a POST request with a new line, Content-Length must also be sent in the header ( length of 'data'/POST data ).

Respond using HTTP/1.0 if easier.

I have written a URI/Percent encoder so you could send your request as a GET easily: http://forum.arduino.cc/index.php?topic=202264.msg1490639#msg1490639

I also have a Base64 encoder which can be useful for POST & GET requests: http://forum.arduino.cc/index.php?topic=201007.msg1481810#msg1481810
774  Using Arduino / Programming Questions / Re: How to pass an I/O device "object" to a function. on: December 13, 2013, 07:50:46 pm
As far as functionality, I won't even be using Print. As I said in the OP, what I ultimately want to do is pass the pointer to FDEV_SETUP_STREAM() and create a standard "FILE *" data type to use with fprintf, fread, fwrite, etc...

You might as well just use print, the writing functions fprintf and fwrite use will have to call print, so you can avoid the overhead by removing the entire file handling ( sd libs support print as well. ), majenko explains well what my DualWriter class is using.
775  Using Arduino / Programming Questions / Re: How to pass an I/O device "object" to a function. on: December 13, 2013, 07:23:44 pm
That has just wrapped the object in another object, might as well just assign to a pointer or reference:

Code:
Stream *S = &Serial;
Stream &s = Serial;

Pointers are also required:
Quote
If so, that won't work because Noritake..... may not exist. This needs to be generic.


776  Using Arduino / Programming Questions / Re: How to pass an I/O device "object" to a function. on: December 13, 2013, 06:39:26 pm
You could use a pointer or reference type for this:

Code:
void my_function ( Noritake_VFD_GUU100 *pointer, char *string)
  {
        pointer->print( string );
  }

Or

Code:
void my_function ( Noritake_VFD_GUU100 &ref, char *string)
  {
        ref.print(string);
  }

However if it is only the print functionality you want ( and it supports the builtin Print library )
Code:
void my_function ( Print &printObj, char *string)
  {
        printObj.print(string);
  }

This method can accept any print/stream object ( Serial, EthernetClient, Wire,... )

Any of these objects can be cast to an intermediate reference or pointer also:
Code:
Print *p = ( Print* ) &Serial;

p->println( "Over Serial" );

p = ( Print* ) &VFD;

p->println( "Over VFD" );

Here is a solution for writing to multiple print targets, maybe it can be modified to suit your needs:
http://forum.arduino.cc/index.php?topic=200975.msg1481633#msg1481633
777  Using Arduino / Programming Questions / Re: Converting a unsigned long into 4 byte array on: December 13, 2013, 10:39:51 am
But, you can simply cast yourLong to a byte pointer, using (byte *)yourLong, and the compiler knows how to send the 4 bytes.

Remember to take the address of the object first:
Code:
(byte *) &yourLong
778  Using Arduino / Networking, Protocols, and Devices / Re: SPI with multiple slave devices problem (Ehternet, SD, RFM69W) on: December 13, 2013, 05:40:07 am
Pick any unused standard digital pin. Set it to output and high, this is disabled. To use it set output value to low ( most SPI devices are active low, check the data sheet for verification ).

The Ethernet shield designers have also just picked random pins they thought looked good at the time ( 4, 10 ).

SS is just the name for slave select, which any output can do, if you have a pin that takes over the world you could label it WD for world domination. Its just more logical than using numbers ( differing layouts for different devices, however SS is always part of SPI terminology ).
779  Using Arduino / Networking, Protocols, and Devices / Re: SPI with multiple slave devices problem (Ehternet, SD, RFM69W) on: December 12, 2013, 02:14:22 am
No it needs its own SS pin, the SPI control lines are also exposed in the uno pins d11-d13 if you cannot use the ICSP header (which the ethernet shield uses).
780  Development / Other Software Development / Re: Compile Arduino Code on iOS on: December 10, 2013, 09:27:53 pm
The key part is getting avr-gcc to run,
Found this after some googling, http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=127960

down the bottom of the thread, it seems someone had some luck.
Pages: 1 ... 50 51 [52] 53 54 ... 146