Show Posts
Pages: 1 ... 23 24 [25] 26 27 ... 143
361  Using Arduino / Displays / Re: Strange bug with myGLCD.drawBitmap when called 6 times on: April 14, 2014, 02:43:04 pm
Creating your own extension to the glcd library makes it easy.

Code:
class GlcdEx : public glcd{
 
  public:
 
    void DrawBitmapFar( uint_farptr_t bitmap, uint8_t x, uint8_t y, uint8_t color= BLACK ){

      uint8_t width, height;
      uint8_t i, j;

      width = pgm_read_byte_far(bitmap++);
      height = pgm_read_byte_far(bitmap++);

      #ifdef BITMAP_FIX
        if( (y & 7) || (height & 7))
        {
        this->FillRect(x, y, width, height, WHITE);
        }
      #endif

      for(j = 0; j < height / 8; j++) {
        glcd_Device::GotoXY(x, y + (j*8) );
        for(i = 0; i < width; i++) {
  uint8_t displayData = pgm_read_byte_far(bitmap++);
  if(color == BLACK)
      this->WriteData(displayData);
          else
            this->WriteData(~displayData);
      }
      }
    }
};

GlcdEx GLCDEX;

byte data0[] PROGMEM = { 3,3,1,2,3,4,5,6,7,8,9 };
byte data1[] PROGMEM = { 3,3,1,2,3,4,5,6,7,8,9 };
byte data2[] PROGMEM_FAR = { 3,3,1,2,3,4,5,6,7,8,9 };

void setup() {
 
    GLCDEX.Init();
    GLCDEX.DrawBitmap( data0, 0, 0 );
    GLCDEX.DrawBitmap( data1, 0, 3 );
    GLCDEX.DrawBitmapFar( GET_FAR_ADDRESS( data2 ), 0, 6 );
}

void loop() {}
362  Using Arduino / Displays / Re: Strange bug with myGLCD.drawBitmap when called 6 times on: April 14, 2014, 02:06:15 pm
Your 6 icons in PROGMEM are 41kb

If your sketch size is close to, or greater than 64kb, you could be pushing certain functions to far into memory.
You can work around it by putting some or all icons into far progmem space ( you are using near progmem space. ), which leaves the near range free for code.

Your 6th icon is most probably removed during compilation when you do not reference it. By adding the myGLCD.drawBitmap it is left in pushing the sketch over 64k.

The code below shows how to read from the FAR PROGMEM range. The GET_FAR_ADDRESS macro converts the 16bit pointer to a 32bit pointer.

Like the SD card option, you probably will have to manually write the image. Or you could modify the glcd function to accept another parameter to decide weather to use near or far progmem.

Code:
//#include <avr\pgmspace.h>

#define GET_FAR_ADDRESS(var)                          \
({                                                    \
    uint_farptr_t tmp;                                \
                                                      \
    __asm__ __volatile__(                             \
                                                      \
            "ldi    %A0, lo8(%1)"           "\n\t"    \
            "ldi    %B0, hi8(%1)"           "\n\t"    \
            "ldi    %C0, hh8(%1)"           "\n\t"    \
            "clr    %D0"                    "\n\t"    \
        :                                             \
            "=d" (tmp)                                \
        :                                             \
            "p"  (&(var))                             \
    );                                                \
    tmp;                                              \
})

#define PROGMEM_FAR  __attribute__((section(".fini7")))

char pgmData[] PROGMEM_FAR = { 'T', 'e', 's', 't', 'i', 'n', 'g', ' ', 'P', 'G', 'M', '\0' };

void setup() {
  Serial.begin( 9600 ); 

  byte c, i =0;
  while( c = pgm_read_byte_far( GET_FAR_ADDRESS( pgmData  ) + i++ ) ){
     Serial.print( ( char ) c );
  }
}

void loop() {}
363  Using Arduino / Programming Questions / Re: How many Sketches can be loaded onto Uno on: April 14, 2014, 12:40:08 pm
A sketch is the Arduino term for project, it can have many files ( .ino, .cpp, .h ). You cannot load multiple whole sketches, however you can combine the functionality into one large sketch.

Each module/component could be implemented in a .h/.cpp combo, you can also write re-usable libraries to extend your projects/sketches.
364  Using Arduino / Programming Questions / Re: missing compiler directive __AVR_ATtinyX5__ on: April 13, 2014, 11:52:40 pm
Yeah, good call.

The EEPROM address register L/H are at 0x1E & 0x1F, so the check could be useful ( and requires '<=' ). The Uno registers are out of range, and can also be used to check for a tiny.
365  Using Arduino / Programming Questions / Re: missing compiler directive __AVR_ATtinyX5__ on: April 13, 2014, 06:28:20 am
Sorry this is a bit late, had a cyclone and power went out. Just turned my PC on and chrome asked if I want to reopen the last pages, which was this smiley

I have a solution maybe.

I have been using the GP registers for some optimized routines and one thing I've noticed is all/most AVR chips have 3 GPIO registers, but only one is within range of sbi/cbi. However all GPIO registers are in range on an ATTiny

Code:
#include "Arduino.h"
const bool IsTiny = &GPIOR1 < ( uint8_t*) 0x1f || &GPIOR2 < ( uint8_t*) 0x1f;

void setup() {
  Serial.begin( 9600 );
  Serial.println( ( IsTiny ? F( "Using ATTiny" ) : F( "Using Different" ) ) );
}

void loop() {}

This worked fine in IDE 1.0.5.
However this code did not work in the 1.5.5 r2 IDE, the Atmel provided GPIORx defines seem to be missing or renamed to something else, will investigate later.
366  Using Arduino / Programming Questions / Re: How to solve this problem ?Libraries that i download wont compile . on: April 11, 2014, 06:30:13 am
Haha, no problem.

A while ago this was a very common error.
367  Using Arduino / Programming Questions / Re: How to solve this problem ?Libraries that i download wont compile . on: April 11, 2014, 06:03:44 am
Quote
C:\Users\gissagiswara\Documents\Arduino\libraries\LCDKeypad\LCDKeypad.cpp:5:22: error: WProgram.h: No such file or directory

In LCDKeypad.cpp
Change the #include "WProgram.h" to #include "Arduino.h"

WProgram.h is from pre 1.0 versions, now Arduino.h is used.
368  Using Arduino / Programming Questions / Re: Problem with array scope and array content on: April 11, 2014, 04:10:55 am
Quote
    int msgSize = (strlen(data) + 10);

    char packetData[msgSize];

You can't do this in C/C++. The array size must be known at compile time. I am surprised you did not get a compile error. See http://www.cplusplus.com/doc/tutorial/arrays/


Not quite. GCC, which  Arduino uses may be old, however it supports features that are in the C++14 specification. The below code is valid.

Code:
void Func( int msgSize ){
  char packetData[msgSize];
}
//...
void setup(){
  Func(strlen(data) + 10);
}

msgSize is not a compile time constant.
369  Using Arduino / Programming Questions / Re: library erased! on: April 11, 2014, 03:58:20 am
If you know where your sketch directory is, you can manually extract the files and place them in the libraries folder.

Windows?
370  Using Arduino / Programming Questions / Re: How to solve this problem ?Libraries that i download wont compile . on: April 11, 2014, 03:29:16 am
Does DFR_key include any other libraries, either built-in or installed yourself?
371  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 08, 2014, 02:26:06 am
And just to satisfy your demands here is function that takes a reference to any size array smiley

Code:
template< typename T, size_t N >  void Foo( T (&t)[N] ){
    Serial.write( t, N );
  }

And the pointer version
Code:
template< typename T, size_t N >  void Foo( T (*t)[N] ){
    Serial.write( *t, N );
  }

And if you look closely there is no need for sizeof to get the length.
372  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 08, 2014, 02:22:20 am
Quote
I showed clearly how to pass a pointer to an array and get the correct size using sizeof.
Code:
void Foo( arr_t *arrp ){
But that's not a pointer to an array; it's a pointer to a PARTICULAR SIZE of array.

There is no other definition of an array. The last index must always be sized.
373  Using Arduino / Programming Questions / Re: Controlling How a Library Compiles From Within a Project on: April 08, 2014, 02:07:47 am
None of this is addressing the OP's basic issue.

I agree with him,  I have had the same issues.   Unfortunately,  I think this is an inherent weakness of the Arduino IDE scheme.  perhaps a necessary and reasonable one in the interests of perceived "simplicity" and the inherent project scale limitations of microcontrollers.

Well actually as I pointed out, using a template design would allow selective compiling of components or debugging. And tgsuperspec pointed out how defines could select what to use in the header file. Wandered a bit off topic, however there are solutions to investigate. And neither are out of reach using the IDE.
374  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 08, 2014, 01:57:06 am
But in that situation, the size is known at compile time - it is know to be: sizeof(int)*n - of course it is known, otherwise it wouldn't be able to do malloc() for the array. Clearly during execution it has to do that multiplication.
n isn't known at compile time, only the sizeof int. Also its stored on the stack.

Code:
typedef int arr_t[ 10 ];
And that one is definitely known at compile time as sizeof(arr_t) is a type. Doing that is no different from passing an array to a function defined as:
void someFunc (int array[10]);

Yup, thats what I was showing.

In fact if you were to do this the size ceases to be known:
Code:
void someOtherFunc(int* arr){
  sizeof(arr); //=sizeof(pointer)
}
arr_t array = {1,2,3,4,5,6,7,8,9,0};
someOtherFunc((int*)array_t);

Yup, thats exactly what I've pointed out. int*arr is not the array and never will be, it only holds the address of the first element.
I showed clearly above how to pass a pointer to an array and get the correct size using sizeof.

Code:
void Foo( arr_t *arrp ){
 
  Serial.println( sizeof( *arrp ) / sizeof( **arrp ) );
}
375  Using Arduino / Programming Questions / Re: Library and array on: April 07, 2014, 11:34:57 pm
Ok, I think I understand.

The simplest way is to pass a pointer and length. Then you can use those bits of info to access the values.

Code:
//A library
class lib{
  public:
    //Constructor with initializer list.
    lib( char *ptr, int len ) : ptr( ptr ), len( len ) {}

    void Foo(){

      for( int idx = 0 ; idx < len ; ++idx ){

        Serial.println( ptr[ idx ] );
      }
    }

  protected:
    char *ptr;
    int len;
};

Code:
//In IDE
char array[ 5 ];

lib l( array, 5 ); //Pass pointer to first element & length

l.Foo(); //Foo uses a pointer passed into the constructor.
Pages: 1 ... 23 24 [25] 26 27 ... 143