Show Posts
Pages: 1 ... 69 70 [71] 72 73 ... 143
1051  Using Arduino / Programming Questions / Re: can you see what I am doing wrong? on: April 16, 2013, 07:04:25 pm
It appears b1yel1 is a pin number not a LOW/HIGH value, so the if statement will fail on any pin number that isn't 1 and skip line 7

5      digitalWrite(b1yel1, HIGH);   //  I have put this line in to prove b1yel1 is high
6      if (b1yel1 == HIGH)  
7        digitalWrite(b1yel2, HIGH);

You could check the pin is high, but you just set it high, so only an interrupt could change it, which you probably aren't using.
1052  Using Arduino / Programming Questions / Re: Undefined reference compilation error on: April 16, 2013, 04:14:08 am
The sketch is compiled as C++, your other.c is C.
rename the file to .cpp or look at this:
1053  Using Arduino / Programming Questions / Re: Issue with variable declaration on: April 16, 2013, 01:06:31 am
Ah, I see whats happening, not used scanf at all really.
I just had a look at the documentation for scanf:

format specifier for scanf follows this prototype:


Seeing as you use 'u', which is integer ( 2 bytes ), do you need to specify a width/length of 1 for one byte. like '%1u' instead of '%u'
1054  Using Arduino / Programming Questions / Re: Issue with variable declaration on: April 15, 2013, 08:42:44 pm
Drop the '&' character.

If 'mydns' is an array:
byte mydns[4] = {1,1,1,1};
//or any other type
int mydns[4] = {1,1,1,1};

You access its elements like:
mydns[ index ]


&mydns[ index ]

But IPAddress supports using '[]' operators so this code below is fine:

IPAddress mydns;

//No '&' infront of element.
mydns[0] = 192;
mydns[1] = 168;
mydns[2] = 0;
mydns[3] = 1;
1055  Using Arduino / Programming Questions / Re: EEPROM read and write on: April 15, 2013, 10:48:11 am
That library is fairly easy to use.

unsigned long int hiscore[8];

for( int index = 0 ; index < 8 ; ++index ){
  EEPROM_writeAnything( index * sizeof( unsigned long int ), hiscore[ index ] );

for( int index = 0 ; index < 8 ; ++index ){
  EEPROM_readAnything( index * sizeof( unsigned long int ), hiscore[ index ] );

Edit: you could extend the life of your eeprom when writing by using the method below:
for( int index = 0 ; index < 8 ; ++index ){

  unsigned long int temp;
  EEPROM_readAnything( index * sizeof( unsigned long int ), temp );

  if( temp != hiscore[ index ] ){

    EEPROM_writeAnything( index * sizeof( unsigned long int ), hiscore[ index ] );
1056  Using Arduino / Programming Questions / Re: Instruction set reference for Leonardo's ATmega32U4? on: April 15, 2013, 08:06:34 am
It's a standard assembly language instruction. You do have an assembly language programming manual, right?

I've not used assembly too much, but from what I gather an 'assembly language' is architecture defined. As in: there are no standard assembly instructions, they are specific to a CPU's machine codes.
1057  Using Arduino / Programming Questions / Re: Communication "Packet" design by using "union" (Suggestion required) on: April 15, 2013, 07:42:43 am
In short, I just wanted to make sure that use of union is not harmful for embedded systems in this case.
It depends in what way you intend to use the members.
What you are really doing by defining data as one type and aliasing it as another is type-punning.

As GCC supports its use ( mostly ) you can use it here in Arduino land, however:
* The C99 and C11 standards allow it.
* The C++99  and C++11 standards do not.

As you are using a char type as the second member things are different. C++ explicitly allows type-punning to a char type, whereas the other way around is undefined behaviour.

So if you write to the struct member, then read/write the array member its fine. But writing the array, then reading the struct can break strict-aliasing rules.

This makes your union usage more or less implementation defined, and therefore cannot really be considered portable: Even through future revisions. GCC currently says this:

*A member of a union object is accessed using a member of a different type.
The relevant bytes of the representation of the object are treated as an object of the type used for the access. See Type-punning. This may be a trap representation.

What this means is you can use your union fine as you have it laid out there, but consider this example:

union a{
  uint16_t b;
  uint32_t c;
  char d[ 4  ];

a A = { 0xFFFF };

Initialising the smaller type of a union with unequal sized members means you can only safely access d upto d[sizeof(b)-1], and c cannot be touched at all.
Whereas if c or d is the active member, reading the others is fine.

The active member is the last written to member:
Quote from: C++99: 9.5 class.union
In a union, at most one of the non-static data members can be active at any time, that is, the value of at
most one of the non-static data members can be stored in a union at any time.

1058  Using Arduino / Programming Questions / Re: "objdump --source" doesn't intermix source code on: April 15, 2013, 06:33:23 am
Hmm, I just tested my v1.5.1r2 and it does add the source, but my 1.0.4 does not. Very strange!
Maybe one of the new compiler/linker options prematurely removes symbols necessary to produce the output.
1059  Using Arduino / Programming Questions / Re: which C++, and is there a specification of just how the IDE tries to "help" one? on: April 13, 2013, 09:45:28 pm
The arduino IDE uses old software, and C++11 is not really at all supported, just a few experimental tidbits:

You can write your own main, then you don't need setup() and loop(). Just remember to call init() before you use certain Arduino specific features like delay() or millis().

The IDE adding stuff is the price we pay for ease of use. Atmel studio 6 supports gcc 4.6.x, might even be 4.7.x now; and has c++11 support.

If multiple declarations are causing errors ( declared in header, defined in sketch ), inside the sketch just wrap you function declarations in #if blocks that never get entered, then the IDE will see them, but the compiler won't.
1060  Using Arduino / Programming Questions / Re: #define vs. static const on: April 13, 2013, 02:17:13 am
Remember, const isn't always a compile time constant.

If you really have constant values, and and want to guarantee they are compile time constants: simply use an enum.
Then the values aren't cast if the datatypes don't match, they will be natural type of the L-Value.

  EPROM = 0xB600,  //EEPROM Location
  EXTRAM2 = 0xB800,  //EXTRAM Location
  LCD_CTL = 0x3000,  //Control register of LCD
  LCD_DATA = 0x3001, //Data register of LCD
  HIRAM = 0xBFFF ,   //Highest address for 32k * 8 RAM
1061  Using Arduino / Programming Questions / Re: TASKS on: April 12, 2013, 09:15:37 am
You keep asking the same questions, is there some more info you want to provide so more concise answers can be given?

PLC C programming
Real Time programming
1062  Using Arduino / Programming Questions / Re: Update LCD display when potentiometer changes on: April 11, 2013, 07:35:52 pm
A trick a lot of people use with various displays is,
You need to display a max of 3 chars ( 100? ) so if the number is less than 100 add a space at the end, if less than 10 add two spaces. Might save tracking numbers.

This is easy to do if you concatenate your string before printing. (itoa)
1063  Using Arduino / Programming Questions / Re: Set Contents of Struct After Initialization on: April 10, 2013, 09:22:31 pm
It is fine how you have it there. Seems there is some conflicting code you haven't posted.

Do you have this line below anywhere?
String options[50];
1064  Using Arduino / Programming Questions / Re: Compile err: not declared in this scope on: April 10, 2013, 08:43:42 pm
An arduino IDE quirk requires the sketch to include all additional libraries that any library may include.

Just add #include <I2C.h> to the sketch also.
1065  Using Arduino / Programming Questions / Re: Function fails with passed in variable, but works if set manually. on: April 10, 2013, 08:34:52 pm
I really believe it's a compiler issue.

Because your flasharray is an array of progmem pointers, not data. You must use pgm_read_word to retrieve the pointer.


This is reading the i'th value in sram, you placed the data in PROGMEM. I can see that it works on occasion for you ( and my test ), but it is still wrong.

Use this:
Serial.println((__FlashStringHelper*) pgm_read_word( &flashArray[i] ) );

Or change your flasharray to this ( no PROGMEM ):

const char * flashArray[] = { string1, string2, string3 };
Pages: 1 ... 69 70 [71] 72 73 ... 143