Show Posts
Pages: [1] 2 3 ... 48
1  Development / Suggestions for the Arduino Project / Re: Need mechanism to pass defines to library cpp files on: April 16, 2014, 08:17:41 pm
All the other Arduino libraries like your Entropy library are still being treated like a library by the IDE.
The IDE doesn't create a library .a archive file for it but otherwise the library is being handled
very similar to a "normal" library.
The files in the library are each compiled separately from the users code (sketch files) and then
then the library objects are linked in with the users code.
(The library files are not included or merged into the same compilation unit as the users sketch)
The only difference between "real" libraries and what the IDE is doing
is that with the exception of the Arduino core library, the compiled objects in the other libraries
are not archived into a .a archive file before they are linked in.

--- bill

It doesn't appear to me that the Arduino IDE is treating them as libraries, but rather as additional source files included in a make like environment.  In that environment I would feed defines to my make file to control the compilation of the executable.  That is what I am looking for here; however, I think the template specialization may make a cleaner solution, or perhaps I can simply rely on the linker to not include any methods which aren't used as you described above; however, that behavior wasn't what I thought occurred.  I thought if you used some of a classes code, then all of it were included.
2  Development / Suggestions for the Arduino Project / Re: Need mechanism to pass defines to library cpp files on: April 16, 2014, 07:29:03 pm
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.

After reading the references on template specialization, that seems like a likely solution, though I will also try pyro_65's solution as well.  Ultimately, I want the library to be useable outside of the Arduino environment as well, since I occasionally use straight c/c++ as well.
3  Development / Suggestions for the Arduino Project / Re: Need mechanism to pass defines to library cpp files on: April 16, 2014, 06:41:25 pm
the simplest solution I can think of is to provide two libraries but that is a burden for the developer.

Another way is to use a templates. A very short intro see
- - at the end of the page
- -

Thanks for the references!  My c++ experience predates the inclusion of templates in the language, and I have never had a need for that feature before.  I will look at the references provided and see about incorporating that solution into the library.
4  Development / Suggestions for the Arduino Project / Re: Need mechanism to pass defines to library cpp files on: April 16, 2014, 06:39:53 pm
Libraries are not slaves to the user of the library.
The library code is compiled separately and the behavior you are seeing is
the expected behavior. This is how libraries work.

Yes, and if the Arduino environment was actually using libraries I would understand that I would have to use a different method to get around the problem, for instance letting a define specify which vesion of the library to link into the code; however, as you point out below, the Arduino libaries are not really libraries, but module of code that get included in the compile process.

As such something simply like would be nice.

#include <Entropy.h>

The Arduino build methodology is not all that smart and does not save things like the compiled libraries
for re-use across different sketches. However, in the Arduno environment, even though the libraries
are not being saved for other sketches to use
, the libraries are still actual libraries and
since a library is a separate entity from the code that uses it, there is no way to do what you are wanting.

--- bill
5  Development / Suggestions for the Arduino Project / Re: Need mechanism to pass defines to library cpp files on: April 16, 2014, 06:34:43 pm
Where is the source with the floating point functions in. I tried this one but  you must have a newer version.

EDIT: found the 0.72 version, no luck there either.

I am currently alpha testing the changes and have not published the new version yet.  If you would like to try out the alpha version send me a message and I will email you a zip file.
6  Development / Suggestions for the Arduino Project / Need mechanism to pass defines to library cpp files on: April 15, 2014, 10:15:13 am
I am attempting to modify my Entropy library to allow the user to decide if they want to include floating point functions for the library.  I placed conditional defines around the relavent code; however, it wouldn't link.  I determined that the source level #define was not being passed to the libraries cpp compile, though it was passed to the libraries header file.

My current solution is to require the user to comment/uncomment the header file for the library, but this is cumbersome, and problematic.  It would be nice if the compilation for library code included the defines made by the Arduino sketch.
7  Products / Arduino Due / Re: Due ARM equivalent of ATOMIC_BLOCK(ATOMIC_RESTORESTATE) [SOLVED] on: April 13, 2014, 07:32:13 pm
Well after an afternoon of searching I found an ARM assembly language commands to turn global interrupts on or off.  The following little code snippet will add two inline functions to perform the procedure.

__inline__ static void disable_interrupts( void )
  __asm__ __volatile__ ("cli" ::);

__inline__ static void enable_interrupts( void )
  __asm__ __volatile__ ("sei" ::);
8  Products / Arduino Due / Due ARM equivalent of ATOMIC_BLOCK(ATOMIC_RESTORESTATE) [SOLVED] on: April 13, 2014, 02:19:59 pm
I am working on updating my Entropy library to work on the Due platform, using the trng instead of timer jitter as the entropy source.

I need to make a small block of code atomic and can't find any way other than some references I found online to two functions __disable_interrupts() and __enable_interrupts().  The only definition I found in the Arduino 1.5.x directory tree for those is for a Wifi related library, so I don't think they exist for my purpose.  I would appreciate any suggestions.

Here is my current test code
#include <sam.h>
#include <sam3xa/include/component/component_trng.h>

const uint8_t ENTROPY_POOL_SIZE=32;
volatile uint8_t g_entropy_pool_start;
volatile uint8_t g_entropy_pool_end;
volatile uint32_t g_entropy_pool[ENTROPY_POOL_SIZE+1];

uint32_t test_random(void)
  uint32_t retVal;
  retVal = g_entropy_pool[0];  // Place holder until atomic issue addressed
//  __disable_interrupt();    //  NEED TO MAKE THIS BLOCK ATTOMIC
//    retVal = g_entropy_pool[g_entropy_pool_start];
      //  g_entropy_pool_start = (g_entropy_pool_start + 1) % ENTROPY_POOL_SIZE;
      // --g_entropy_pool_count;
//  __enable_interrupt();   // NEED TO MAKE ABOVE BLOCK ATOMIC

void TRNG_Handler(void)
  uint32_t tmp;
//  g_entropy_pool[0] = TRNG->TRNG_ODATA;
  g_entropy_pool[g_entropy_pool_end] = TRNG->TRNG_ODATA;
  // g_entropy_pool_end = (g_entropy_pool_end + 1) % ENTROPY_POOL_SIZE;

// As it stands if the following two lines are uncommented the program ceases to produce output.
  // if (g_entropy_pool_end == g_entropy_pool_start) // The entropy pool is full
  //  g_entropy_pool_start = (g_entropy_pool_start + 1) % ENTROPY_POOL_SIZE;  
  tmp = TRNG->TRNG_ISR;  // Need to read the status register to clear it

void setup_trng(void)
  // Circular buffer pointers for entropy
  g_entropy_pool_start = 0;
  g_entropy_pool_end = 0;

  pmc_enable_periph_clk(ID_TRNG);                        // Turn on the trng peripheral clock
  TRNG->TRNG_IER = 0xFFFFFFFF;                           // Set the interrupt enable register
  TRNG->TRNG_CR = TRNG_CR_KEY(0x524e47) | TRNG_CR_ENABLE;// Turn on the generator
  NVIC_EnableIRQ(TRNG_IRQn);                             // Activate the TRNG Interrupts

void setup()

void loop()
9  Products / Arduino Due / Re: Arduino Due on: April 07, 2014, 04:20:07 pm
Try adding #include <Arduino.h> at the top of your program.  If that doesn't work, verify that the Liquid Crystal library version your using works with the Due--perhaps download the most recent version.
10  Community / Exhibition / Gallery / Re: Example sketch for seeding the libraries pseudo-random number generator on: April 06, 2014, 09:06:14 am
Thanks for the heads up!  I modified both the included sketch and the gist hub version to address the problem!
11  Community / Exhibition / Gallery / Example sketch for seeding the libraries pseudo-random number generator on: April 05, 2014, 11:54:59 pm
I received an email request from someone today who wanted to have a sketch that had a different seed value for the seedRandom() function every time the sketch ran, but found the standard seedRandom(analogRead(0)) didn't work, and the example from my true random number generation library, Entropy added too much overhead for their sketch.  So I created a sketch which uses the same basic technique used as the entropy source in my library, but dropped all of the other overhead, and disables the interrupt after the seed is created.  A link to this sketch is now on the Arduino Playground or it can be found on my  entropy site here:

// TrueRandomSeed.ino
// This example sketch shows how to provide a truly random seed value to the built in
// library pseudo random number generator. This ensures that your sketch will be
// using a different sequence of random numbers every time it runs. Unlike the
// usually suggested randomSeed(analogRead(0)) this method will provide a much more
// uniform and varied seed value. For more information about the basic technique used
// here to produce a random number or if you need more than one such number you can
// find a library, Entropy from the following web site along with documentation of how
// the library has been tested to provide TRUE random numbers on a variety of AVR
// chips and arduino environments.
// timer-jitter-entropy-sources/entropy-library
// Copyright 2014 by Walter Anderson, wandrson01 at gmail dot com
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <util/atomic.h>
// The following addresses a problem in version 1.0.5 and earlier of the Arduino IDE
// that prevents randomSeed from working properly.
#define randomSeed(s) srandom(s)
volatile uint32_t seed; // These two variables can be reused in your program after the
volatile int8_t nrot; // function CreateTrulyRandomSeed()executes in the setup()
                     // function.
void CreateTrulyRandomSeed()
seed = 0;
nrot = 32; // Must be at least 4, but more increased the uniformity of the produced
// seeds entropy.
// The following five lines of code turn on the watch dog timer interrupt to create
// the seed value
MCUSR = 0;
while (nrot > 0); // wait here until seed is created
// The following five lines turn off the watch dog timer interrupt
MCUSR = 0;
seed = seed << 8;
seed = seed ^ TCNT1L;
void setup()
// The preceeding two function calls will take approximately 0.5 second to execute if
// nrot is set to 32 ... the rest of your setup code should FOLLOW from here.
void loop()
12  Using Arduino / Programming Questions / Re: Arduino-Python : problem... on: April 03, 2014, 03:05:43 pm
I have a similar functional example that may help you.  I am including the arduino sketch and the client side python

13  Topics / Science and Measurement / Re: Portable Arduino Seismograph Detection and Graphing Unit on: March 29, 2014, 10:06:04 am


(any chance to see source code/schematics?)

14  Using Arduino / Programming Questions / Re: Generate Unique Random Numbers from a range of values on: March 27, 2014, 02:43:13 pm
A problem with the examples are that the built in library random function will produce the exact same sequence of numbers, and using the analog 0 to seed the generator doesn't perform much better.  I added a code snippet to the General section of the Arduino playground here;

Or you can access it directly here;
15  Development / Other Software Development / Re: Hosting libraries and project codes? on: March 27, 2014, 11:47:26 am
One possibility would be to use a combination of Google Site hosting (for indexes, links, and descriptions, while using Google docs to host the actual files. 

Although I hope that Google relents on the uploading of files to google code sites.  I don't mind restrictions to relatively small sizes (code zips), but do miss this feature!
Pages: [1] 2 3 ... 48