Show Posts
Pages: [1] 2 3 ... 121
1  Development / Other Software Development / Re: Board name with COM number in windows on: Today at 05:37:00 am
I agree names should be used.

Quote
Is there a way to not create unique COM port numbers for each connected arduino
They can't all have the same port. The settings are stored in the registry, which you can try modify, it is a nightmare to find the assignments as they are stored using their component ID. Not to mention each port is cluttered with data from every other device ever connected.

How about making  a 'middle man' Arduino that other duinos connect to. Then you'll only have one device connected.

If you can use the windows API, you can write an application that creates its own virtual com port and simply pipes the data to the Arduino's port or even many Ardunos at once.
2  Using Arduino / Programming Questions / Re: if else or switch case? on: April 19, 2014, 06:25:30 am
@winner10920, Haven't seen you around in a while.
I agree, post it.

I also have seen comments in the Arduino core explaining that a large if set was used over a switch because the switch apparently used SRAM ( local ).

However switch statements can be used for far more logical things than simple case matching. I'm quite happy to bet that there are many situations where a switch is the superior choice. Even though Arduinos compiler is old, GCC supports C++11 ranged switch statements, which expand its use dramatically.

A lot of times where I have employed a switch for optimization reasons, the code surrounding it changes to suit the logic. And sometimes has proven to be far more efficient regardless of the ram overhead imposed by the switch. But still, the result is a product of your design, not so much a single component used to build it.

That being said there are differences that separate the two ( that are mostly overlooked ), and can therefore be exploited differently. For instance, a switch does not implicitly give scope, an if does, however the switch can have multiple statements. If you wish to use more than a single line in an if you must explicitly give it scope using '{}'.

Conversely a switch cannot instantiate new objects without explicit scope. Whereas an if can...

Code:
if( char data = Serial.read() )
  someFunc( data );

Is equivalent to, but ( can be ) more efficient than:
Code:
char data = Serial.read();
if( data  )
  someFunc( data );

You can see a good exploitation of the switch statements lack of scope in the http://en.wikipedia.org/wiki/Duff's_device. ( its possible because all cases have the same scope as the switch itself ).

EDIT: made a small edit above.
3  Using Arduino / Programming Questions / Re: Passing pointer to char array into function on: April 19, 2014, 04:51:02 am
Code:
     byte x  = menu(*menu_mainTable);
menu_mainTable IS a pointer.
*menu_mainTable is a pointer to a pointer, which is not what the function expects. Why did you include the *?
The function expects a pointer to char. menu_mainTable is NOT a pointer to char or a char array.

Oops, your thinking of a declaration. 'menu_mainTable' returns a pointer to the first element which is a char*, so the pointer returned is char**.
The * used in the function call is a dreference, not an 'address of' operator. The dereference moves the pointer returned from the array to a char*, which the function accepts.

@OP
However even though the code is valid, you are only passing the first element. You need to pass the whole array, or to stick with pointers, the pointer returned by the array.

Hint: Arrays aren't pointers, they implicitly cast / decay to pointers of their first element. Here is a changed version of your code ( missing stuff stripped )

Code:
#include <avr/pgmspace.h>
prog_char menu_1[] PROGMEM = "option1";   
prog_char menu_2[] PROGMEM = "option2";
prog_char menu_3[] PROGMEM = "option3";

char buffer[8];

PROGMEM const char *menu_mainTable[] =    
{   
 menu_1,
 menu_2,
 menu_3
};
 
byte menu(const char** inputs) {
  byte currRecord = 0;
  byte maxValue = 2;  //set as function input later
 
  while(true) { //not selected
    strcpy_P(buffer, (char*) pgm_read_word(&(inputs[currRecord])));
    Serial.println( buffer ); //display currently viewed option

    currRecord++;
    if (currRecord > maxValue) currRecord = 0;
    else if (currRecord < 0) currRecord = maxValue;
  }
  return 0;
}

void menuMain() {
  while(true){
     byte x  = menu( menu_mainTable );
     Serial.println(x);  //display ouput
     delay(100);
  }
}

void setup(){}
void loop(){}

4  Using Arduino / Programming Questions / Re: C++ class data in flash on: April 19, 2014, 04:13:32 am
Yup,

All class/struct/union data in flash:
Code:
struct Foo{
  int a;
  bool b;
  float c;
};

Foo f PROGMEM = { 1234, true, 3.14f };

//Access members using their address.
pgm_read_word( &f.a );
pgm_read_byte( &f.b );
pgm_read_dword( &f.c );


For individual elements, use static members.
Code:
struct Foo{
  int a;
  bool b;
  static float c;
};

float Foo::c PROGMEM = 3.14f;
//...
Foo f = { 1234, true };

float temp = ( float ) pgm_read_dword( &f.c );

This is the most basic way, and is really no different to using primitives in PROGMEM.
You can even design your class so you can use it as normal and hide the PGM functionality in the background. Which may be closer to what you where imagining.
5  Using Arduino / Programming Questions / Re: How to find source of high .bss usage? on: April 18, 2014, 03:51:56 am
Need your code or your .elf file

Otherwise there is a tool in the avr bin directory which you can use called avr-nm.

This is what I use to see a breakdown of the memory sections.
Quote
avr-nm.exe -n -S
6  Using Arduino / Programming Questions / Re: max payload ? on: April 18, 2014, 03:13:03 am
I agree with @PaulS.

What 32 byte array?

...R

Maximum payload size for NRF24l01 is 32 bytes.
7  Using Arduino / Programming Questions / Re: Strange error message on: April 18, 2014, 01:07:24 am
Hi, had a test of your project. The results where... fine.

  • IDE 1.0.5
    • Uno: Binary sketch size: 28,316 bytes
    • Mega: Binary sketch size: 30,168 bytes
  • IDE 1.5.5 r2
    • Uno: Sketch uses 28,234 bytes (87%)
    • Mega: Sketch uses 29,970 bytes (11%)

The Uno versions use more than 2k ram, so will not work. But the point is, your error did not appear.
I'm downloading the new 1.5.6 to see if there is any difference, however my connection is stupidly slow today and its timed out once already.
----------------------------------------------------------
EDIT:

The results for 1.5.6 r2 where the same:
Quote from: PoolController.ino
Sketch uses 28,872 bytes (11%) of program storage space. Maximum is 258,048 bytes.
Global variables use 2,159 bytes (26%) of dynamic memory, leaving 6,033 bytes for local variables. Maximum is 8,192 bytes.

The .hex & .elf are attached.
8  Development / Other Software Development / Re: I think I found a bug in the HardwareSerial.cpp Library. on: April 17, 2014, 11:28:06 pm
Looks like they where onto it. Some big changes to the source for 1.5.6.

The current source has been fixed.
https://github.com/arduino/Arduino/blob/ide-1.5.x/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp#L75
Code:
void serialEventRun(void)
{
#if defined(HAVE_HWSERIAL0)
  if (Serial0_available && serialEvent && Serial0_available()) serialEvent();
#endif
#if defined(HAVE_HWSERIAL1)
  if (Serial1_available && serialEvent1 && Serial1_available()) serialEvent1();
#endif
#if defined(HAVE_HWSERIAL2)
  if (Serial2_available && serialEvent2 && Serial2_available()) serialEvent2();
#endif
#if defined(HAVE_HWSERIAL3)
  if (Serial3_available && serialEvent3 && Serial3_available()) serialEvent3();
#endif
}
9  Using Arduino / Programming Questions / Re: Switch and Case question on: April 16, 2014, 08:57:28 pm
What values do you see over serial. Or is the switch case not even entering?
10  Development / Suggestions for the Arduino Project / Re: Need mechanism to pass defines to library cpp files on: April 16, 2014, 08:30:55 pm
Quote
Yeh, this library works even on some of the small tiny avr's (2313), but only if none of the code for floating point is included since that brings in additional 'library' code that really bulks up an application.  However, for some applications, and on the appropriate chips, floating point random numbers can be very useful, so I want to include the capability in the library, but only if the user needs it...

I thought if you used some of a classes code, then all of it were included.
No overhead for unused data. To achieve what you want, no mods are needed.

The defines I provided hide them from the user. I use templates frequently, however they are overkill for this. The floating point data is compiled, but not linked in unless you use it. Which means there is no additional code impact if the user decides not to use it.

Also they work if the user wants, just like you wanted.
11  Development / Suggestions for the Arduino Project / Re: Need mechanism to pass defines to library cpp files on: April 16, 2014, 07:02:44 pm
What you want can be achieved, however is it necessary.

Do the new features add overhead even when unused?
Or will the methods have alternate functionality depending on the value of ENTROPY_FLOAT?

If you want the functions unavailable, you could simply add this to your header.
Code:
#ifndef ENTROPY_FLOAT
  #ifdef ENTROPY_FLOAT_COMPILE
#define ENTROPY_FLOAT  //Include for compilation, sketch must define to use.
  #endif
#endif

And modify the .cpp
Code:
#include <Arduino.h>
#define ENTROPY_FLOAT_COMPILE
#include <Entropy.h>

This way, the library is compiled with full functionality, and the sketch will only see the float functions if they explicity add #define ENTROPY_FLOAT. The compiler should be able to remove the unused pieces.

If you want to prevent compiling of the float features altogether, that can still be achieved.
12  Using Arduino / Programming Questions / Re: multiple buttons on analog input on: April 16, 2014, 05:52:59 pm

ASCII code for "q"=81
ASCII code for "w"=119

I know what it means only because I googled but I still want the OP to put those comments in because I shouldn't have to remember what "119" means.

Can avoid the comment or confusion by simply putting the character in.

Code:
Keyboard.press( 'w' );

Remember the single quotes though.
13  Using Arduino / Programming Questions / Re: Variable changed without code on: April 16, 2014, 04:23:50 pm
No comparison!

You are assigning 'not B' to A
Code:
A=!B

B == 0 == FALSE
!B == TRUE

A is assigned TRUE and the if always succeeds.

Try
Code:
A == !B

Or like tom said, the more intuitive version:
Code:
A != B
14  Development / Other Software Development / Re: New TFT Extension Library on: April 16, 2014, 03:57:43 pm
- smiley(mood);  // simplified -  yellow circle with some basic lines.

I've designed a manuscript with notes, however a smiley interface is not one I've thought of. Might inspire a chat program of sorts.

15  Development / Suggestions for the Arduino Project / Re: Arduino stickers on: April 16, 2014, 03:50:45 pm
You are allowed to produce non-commercial gear like t-shirts and stickers using the Arduino community logo.
The main Arduino logo is a trademark.

http://arduino.cc/en/Trademark/CommunityLogo
Pages: [1] 2 3 ... 121