Show Posts
Pages: 1 ... 48 49 [50] 51 52 ... 143
736  Using Arduino / Networking, Protocols, and Devices / Re: nRF24L01+ - which library to use? on: December 09, 2013, 09:04:59 pm
Why is the (byte *) and "&" operator used here?  I thought the * means "value of" and the & means "address of".

If I have a variable that denotes distance (an int) that I'm trying to send, would I simply put in this?

Quote
Mirf.send((byte *)&distance);

both *, & have multiple meanings, you are correct in this instance with &, it is the address of operator.
The * is denoting a pointer type, and a type in brackets is a cast.

Your version would be fine, however the Mirf requires a payload size to be set. Looking at the code you should be able to set the payload size like this:

Code:
Mirf.payload = sizeof( int );

//Then send.
Mirf.send((byte *)&distance);
737  Using Arduino / Networking, Protocols, and Devices / Re: Wifi shield and avrdude: stk500_getsync(): not in sync: resp=0x1c on: December 09, 2013, 10:58:25 am
In the link you provided, it says the software pins are d6 & d7, not d2 & d3. Not sure if I'm reading the right text though, haven't got a wifi shield.
738  Using Arduino / Programming Questions / Re: Polymorphic classes not behaving as expected. on: December 09, 2013, 01:06:54 am
From what I can see with quick glance, the code looks fine.
However declare the initial updateColor() prototype as pure virtual, this should hopefully fix the issue:

Quote
virtual void updateColor() = 0;

Also have you considered the updateColor as a pure virtual member of colorSource ( no implementation, leave that in colorGenerator ).
739  Using Arduino / Programming Questions / Re: byte mirror code don't work on: December 08, 2013, 02:01:07 am
Nice, I'll add it in.
740  Using Arduino / Programming Questions / Re: typedef struct problem on: December 08, 2013, 01:54:01 am
I've used my own prototypes since 0021, never had a problem of duplicate prototypes.

Remember the signature must match exactly:

Pretend sketch:
Code:
void Foo(){
 Serial.print( "HI" );
}

void setup() {
  Foo();
}

void loop() { }

Adding the prototype:
Code:
void Foo();

produces:
Code:
#line 1 "BareMinimum.ino"

#include "Arduino.h"
void setup();
void loop();
#line 2
void Foo();

void Foo(){
 Serial.print( "HI" );
}

void setup() {
  Foo();
}

void loop() { }

If I add the same prototype ( but not a textual match )
Code:
void  Foo (); //Two spaces instead of one.

this produces:
Code:
#line 1 "BareMinimum.ino"

#include "Arduino.h"
void Foo();
void setup();
void loop();
#line 2
void  Foo ();

void Foo(){
 Serial.print( "HI" );
}

void setup() {
  Foo();
}

void loop() { }

The multiple definitions are fine unless using a struct, as the object is still not seen before use.
However like I said I have had no problem with duplicate prototypes appearing and breaking structs.
I have used 0021 to 1.0.5 and tested 1.5.2.

Download my test sketch and try it. If it works, there is no duplicates.
741  Using Arduino / Programming Questions / Re: byte mirror code don't work on: December 08, 2013, 12:58:59 am
Quote
Anyone interested in a seventh assembly version?

Give me all the version you have got, I'll add it into the sketch. Then we can have a large set of methods for all different usage/learning purposes.

Also, ppl, with new versions, comment each line that my not be so straight forward to newbies.

Quote
Hey Pyro, after changing "byte table[16]" to "static const byte table[16]" I was able to beat your time by almost 177,084 us

Cool, I'll go fix up my sketch and add in a few others. I still like the idea of not using pre-calculated data, especially static data that will never relinquish its memory, I will have to see how well yours performs as a compile time constant, mine completely evaporates to an LDI.
742  Using Arduino / Programming Questions / Re: byte mirror code don't work on: December 07, 2013, 09:40:42 am
The results are in, they were partly as I expected.

There are six algorithms used. I named each one under the person who posted it, not who wrote it.

Order of appearence in thread:

Here are the results.
The fastest function is 28% faster than its closest alternative.
It is 98% faster than the slowest.

If you are tight on flash memory MarkT's version is 68% smaller than the next version,
if you are after speed, my version takes the cake.

Order by speed ( On Uno ).
743  Using Arduino / Programming Questions / Re: Arduino : get the complete generated code by Arduino IDE on: December 07, 2013, 05:49:38 am
In windows you can make your own shortcut.
Open Explorer type 'shell:sendto' in that folder create a .bat file with the below text, fix the path to your IDE.

Code:
D:\arduino-1.5.2\hardware\tools\avr\bin\avr-objdump.exe -S %1 > %1%.txt

Then once compiled the IDE will give you the temp compile path ( with verbose option on ), in that folder right click on XXX.elf and choose 'Send To->yourbat.bat'

it will generate XXX.elf.txt.

The same for RAM usage can be done using this in a bat file:
Code:
D:\arduino-1.5.2\hardware\tools\avr\bin\avr-nm.exe -n -S %1 >nm_out.txt

Outputs nm_out.txt ( use also on XXX.elf )

No need to construct command lines out of file paths once setup.
744  Using Arduino / Programming Questions / Re: byte mirror code don't work on: December 07, 2013, 05:25:57 am
So I made that mirror function like it is, (I did not Google it) and it seems to work rather well.

Yes, same goes here. I tried to do it without a loop, which was easier than I thought.

Its good however that others have posted their own and excerpts from Sean Anderson's bit hacks. Out of curiosity, I'm going to profile them to see what each one can do. I want to make an assumption that the short and sweet 64-bit versions will not pull though in a timely fashion, i'm curious to see what the three non-looped versions can do compared to a loop.
745  Using Arduino / Programming Questions / Re: problem with struct in Arduino IDE on: December 06, 2013, 09:33:28 am
I don't think that will work either, you are defining a struct as queue, then trying to alias to the same name.

By providing your own prototype ( below struct ) the IDE will not put one at the top.

Code:
int put ( queue* p ,int x);
746  Using Arduino / Programming Questions / Re: byte mirror code don't work on: December 06, 2013, 07:39:42 am
I had a go at my own and shaved a few bytes off the compiled size. Without a loop it may also be faster, gonna test soon.

EDIT: appears it is heavily inlined. Still not sure on the timing, but would be quite large in a function.

Code:
struct BitByte{
 int A : 1;
 int B : 1;
 int C : 1;
 int D : 1;
 int E : 1;
 int F : 1;
 int T : 1;
 int P : 1;
};

const char MirrorByte( const char c ){

  union{
    char b;
    BitByte a;
  } f = {c};
  
  union{
    BitByte g;
    char h;
  } i = { f.a.P, f.a.T, f.a.F, f.a.E, f.a.D, f.a.C, f.a.B, f.a.A };  
  
  return i.h;
}

void setup() {
  Serial.begin( 9600 );
  char c = 0xFE;
  Serial.println( ( unsigned char ) c, HEX );
  Serial.println( ( unsigned char ) MirrorByte(  c ), HEX );
}

void loop() {}
747  Using Arduino / Programming Questions / Re: Variables scope on: December 06, 2013, 05:40:39 am
Here is a post I made some time ago which shows how globals can come back and bite you, without even so much as a warning from the compiler... very hard to trace in a big application:

http://forum.arduino.cc/index.php?topic=124367.msg939621#msg939621

748  Using Arduino / Storage / Re: sdFat library error code need help on: December 05, 2013, 10:08:16 pm
Can you just save the data to an image file extension ( .jpg, .png )? <<EDIT: just saw post above.
To beat the size, can you place a chuck of empty data in it, or does it go on dimensions?

If its dimensions, you could place a bitmap header reserving a block of data represented by the width and height, then fill in the blank pixel data with your logging.

Kind of similar to packing the data into a 'packet' for network transmission.
749  Using Arduino / Programming Questions / Re: Variables scope on: December 05, 2013, 09:50:42 pm
Quote
Uh oh!  Before you know it, someone's going to install a homebrew channel on your quad-copter.   smiley-wink

That'll be the day.

The code I posted above your post and the stack discussion are in no way unique to AVR, it has consequences in both Harvard and Von-neumann architectures. In fact its even worse on Von-neumann as code memory is not separate, and can lead to code injection.
750  Using Arduino / Programming Questions / Re: Variables scope on: December 05, 2013, 09:39:17 pm
Got it, here is a nice proof of concept about stack variables, and how the memory is reused.

There are two function calls, one has an initialised value, the other doesn't. This is a security nightmare scenario.

Tested on an Uno
Code:
void A(){
  uint64_t a = uint64_t( 0xaabbccdd ) << 32 | 0x11223344;
  Serial.print( "Pointer Address: " );
  Serial.println( (unsigned int )&a );
  Serial.print( "Lower 32: " );
  Serial.println( (unsigned long )a, HEX );
  Serial.print( "Upper 32: " );
  Serial.println( (unsigned long )(a >> 32), HEX );
}

void B(){
  uint64_t b;
  Serial.print( "Pointer Address: " );
  Serial.println( (unsigned int )&b );
  Serial.print( "Lower 32: " );
  Serial.println( (unsigned long )b, HEX );
  Serial.print( "Upper 32: " );
  Serial.println( (unsigned long )(b >> 32), HEX );
}

void setup (){
  Serial.begin (115200);
  A();
  B();
}

void loop () { }
Pages: 1 ... 48 49 [50] 51 52 ... 143