Show Posts
Pages: [1] 2 3 ... 358
1  Using Arduino / Programming Questions / Re: How to share code? on: Today at 07:54:17 am
I saw your code from github. to make your code easy for beginner like us to use. you need to write simple examples using your code. still, if you think your code is great. write a book about it.

That takes a lot. The book is likely more effort than the code.
But if 2 or more were to collaborate successfully, a group project of shared skills might go easier or devolve into a mess and fights, it's hard to say.  smiley-eek-blue

2  Using Arduino / Programming Questions / Re: Non linear list and sensor values (that are not Integers) on: Today at 06:28:57 am
You can make a linear based table easily enough. Question is would you have room to store it? And does it need to cover how many kinds of refrigerant?

You can get more flash and RAM with a bigger chip. You can build or buy that. Just keep in mind that you're not stuck with one set of limits when you're looking at approaches to solutions. A $7 (if you're just buying one) ATmega1284P chip has 128K flash, 16K RAM and 2 serial ports. A less than $3 ATmega328P (the UNO chip) has 32K flash, 2K RAM and 1 serial port (software serial can be used for more). Both are covered in build your own tutorials, both are covered in kits and sold on assembled and tested boards. And those are just 2 choices out of a very wide range.

What you explore for techniques now can likely be taken farther through easy choices down the road.
So definitely explore before you choose!

You can use an external flash chip or EEPROM as easily as an SD adapter and get away with a smaller AVR.

Half a second is a long time to Arduino, 8 million CPU cycles. But with the wrong code that spends most of the time waiting for things to finish it can be hardly any time at all, 500 milliseconds to fritter and waste. The right code can run a small circus of devices smoothly simultaneously.

Lookup tables are a great way to save computation. If the pressure you look up in the table is going to be used to calculate PWM values to run a servo or motor and nothing else, store those instead of pressure! PWM is only 8 bits!

Here's an example of using a lookup table of integer sine x 10000 (Y = radius x value / 10000) vs using sin() to generate floats. It does the process many times for each (adding every value and printing it to keep the compiler from optimizing the calculations away and providing result checks in the process) to take long enough to notice  smiley-mr-green then shows that calculating just the sines with floats takes 100x as long. Tables work.
It runs on a bare UNO just fine and it is not the fastest or most efficient code for what it does.

Code:
// Getting 16 bit unsigned vars in and out of PROGMEM (flash)
// Written for public domain by GoForSmoke 2014


// this program also compares the time to do table lookup vs using floats and sin()
// sorry about having to add and print the totals but otherwise the compiler optimizes the test to nothing

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <math.h>

const word PROGMEM PROGTBL[ 91 ] = { // sine * 10000 by degree 0 to 90
  0U,  175U,  349U,  523U,  698U,  872U, 1045U, 1219U, 1392U, 1564U,
  1736U, 1908U, 2079U, 2250U, 2419U, 2588U, 2756U, 2924U, 3090U, 3256U,
  3420U, 3584U, 3746U, 3907U, 4067U, 4226U, 4384U, 4540U, 4695U, 4848U,
  5000U, 5150U, 5299U, 5446U, 5592U, 5736U, 5878U, 6018U, 6157U, 6293U,
  6428U, 6561U, 6691U, 6820U, 6947U, 7071U, 7193U, 7314U, 7431U, 7547U,
  7660U, 7771U, 7880U, 7986U, 8090U, 8192U, 8290U, 8387U, 8480U, 8572U,
  8660U, 8746U, 8829U, 8910U, 8988U, 9063U, 9135U, 9205U, 9272U, 9336U,
  9397U, 9455U, 9511U, 9563U, 9613U, 9659U, 9703U, 9744U, 9781U, 9816U,
  9848U, 9877U, 9903U, 9925U, 9945U, 9962U, 9976U, 9986U, 9994U, 9998U,
  10000U, };

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

  char  formatted[ 8 ];

  word  W;

  PGM_P  Addr; // define a const prog_char pointer named Addr
  Addr = (const prog_char *) PROGTBL; // cast the table address to fit Addr

  for ( byte i = 0; i < 91; i++ )
  {
    W = pgm_read_word( Addr + 2 * i ); // read unsigned 16 bits at Addr
    sprintf( formatted, "%6u", W );
    Serial.print( formatted );
    if ( i < 90 ) Serial.print( ", " );
    if (( i % 5 ) == 4 ) Serial.println( );
  }
  Serial.println( "\n\n Timed test" );
 
  Serial.flush(); // getting serial interrupts out before time test
  delay( 1000 );  // making sure of it

  unsigned long accum = 0UL; // to make the compiler use all the lines below

  unsigned long mics = micros();
  for ( byte i = 0; i < 91; i++ )
  {
    W = pgm_read_word( Addr + i * 2 );
    accum += (unsigned long) W;
  }
  unsigned long tookMics = micros() - mics;
 
  Serial.print( "\n accum = " );
  Serial.print( accum );
  Serial.print( " took " );
  Serial.print( tookMics );
  Serial.print( " micros to add up" );
  Serial.println( );
 
  Serial.flush(); // getting serial interrupts out before time test
  delay( 1000 );  // making sure of it
 
  float fAccum = 0.0;
 
  mics = micros();
  float T = sin( M_PI * 30.0 / 180.0 );
  for ( byte i = 0; i < 91; i++ )
  {
    T = sin( M_PI * (float) i / 180.0 );
    fAccum += T;
  }
  tookMics = micros() - mics;
 
  Serial.print( "\n float accum = " );
  Serial.print( fAccum );
  Serial.print( " took " );
  Serial.print( tookMics );
  Serial.print( " micros to add up" );
  Serial.println( );
 
}

void loop( void )
{
}

3  Using Arduino / Programming Questions / Re: Non linear list and sensor values (that are not Integers) on: July 29, 2014, 11:14:17 pm
If your table goes by linear temperature, you only need to store pressure for each and use temperature to get the index.
You may have room for 1/10th degree steps for integer values in Pa instead of kPa.

Another route from flash is to use data store in an SD card. It's slower but still fast and the limits are sky high.


4  Using Arduino / Project Guidance / Re: program to find rpm on: July 29, 2014, 05:59:57 pm
Bulldog has the right of it. He keeps his units straight.

To scale from revs per second to revs per minute:
10 revs / 1 second =  ( 10 revs / 1 second ) * ( 60 seconds / 1 minute )
10 revs / 1 second = ( 10 revs * 60 seconds ) / ( 1 second * 1 minute ) = 600 revs / minute

To scale from revs per Y ms
X revs / Y ms = ( X revs / Y ms ) * ( 60000 ms / 1 minute )
X revs / Y ms = ( X revs * 60000 ms ) / ( Y ms * minute ) = X * ( 60000 ms / Y ms )  revs / minute
When Y = 5000, rpm = X * 12

5  Using Arduino / Programming Questions / Re: How to find number of "rows" in an array of strings? on: July 29, 2014, 10:27:33 am
No problem, but I am still intrigued by the dynamic creation of the strings/Strings and not knowing how many there are.  Either the array will need to be declared large enough to hold the maximum number of strings to be created, in which case the sizeof() trick will not work, or declared just big enough to hold the strings in which case you will know how many of them there are.

You can do buffer management with C strings but by design, C++ Strings are a can of worms.
6  Using Arduino / Programming Questions / Re: How to find number of "rows" in an array of strings? on: July 29, 2014, 10:22:47 am
Quote
LOL, what Arduino are you planning to run dynamic String arrays on?

you know you kinda come off as arrogant when you do this, lets say I don't know why running dynamic arrays is bad, instead of telling me why, you laugh in my face. I realize you're tired of answering newbie questions, but you could just ignore the whole thing if you don't want to deal with that. As it is you've contributed little to the whole discussion.

I realize dynamic strings are memory expensive, but it's not my choice to do it, all I needed to know is how to know how many entries there are and econjack has answered that with explicit detail. So thanks to him for answering the question.

Look, a number of people tried to reason with you and I did try an point out the obvious and I did give other information but you stepped on and over every bit of that and not just what I gave.

So fine, I'm looking at someone who knows better while being unable to understand why what he is trying Doesn't Work even as he misses and rejects true answers over and over on a quest to even more and bigger problems then get this...

I'm supposed to be arrogant for laughing about the futility that this person Insists Upon!

You blew through so much, you shouldn't toss the arrogant label much less play victim.
7  Using Arduino / Project Guidance / Re: Arduino UNO Pinout Diagram on: July 29, 2014, 07:32:48 am
MUCH Appreciated!
Karma to you! Perhaps others will follow suit.
8  Using Arduino / Project Guidance / Re: program to find rpm on: July 29, 2014, 07:22:15 am
i need to submit it to other person.... completely working program

How do you know?

Or is that a request for someone to hand you a complete solution immediately?

Damn, my set of that hardware must be in the same place as my mind reading cap.
I can look and look but you just know all those things will be in last place I look, never the first!
9  Using Arduino / Programming Questions / Re: Serial Monitor: garbish in output on: July 29, 2014, 06:15:36 am
Hi,

sorry for not mentioning: Arduino Mega 2560

Are there differences in serial behavior?

thx Alexander

Not that one. I don't have a Leonardo but I recall some wait-around with serial for those.

Another thing to check is serial monitor has the same speed (baud rate).

I sometimes get some screen trash on starting serial monitor but I can't remember any fix.
It usually precedes what my program sends.
So yes, I am interested too!
10  Using Arduino / Programming Questions / Re: How to find number of "rows" in an array of strings? on: July 29, 2014, 12:17:20 am
I've gotten tired of telling new people why.
This one is so confident and maybe has a Due or will be really careful which kind of defeats the whole dynamic objects and container classes view.

It's bathtub on a bicycle time.
11  Using Arduino / Programming Questions / Re: multiple if or for loop with if inside on: July 28, 2014, 11:30:06 pm
In those cases it doesn't matter but

i = 5;

x = --i;  // i is pre-decremented here, i = i - 1 before i is copied to x
                // x is now 4 and i is now 4

y = i--; // i is post-decremented here, i = i - 1 after i is copied to y
               // y is now 4 and i is now 3
12  Using Arduino / Programming Questions / Re: How to find number of "rows" in an array of strings? on: July 28, 2014, 11:25:10 pm
I could point out that if String arrays are to be created dynamically that counters can too but I'm waiting to see if when the other shoe drops the whole house doesn't come down soon after. But maybe it won't. Maybe an Arduino with lots of RAM will run it or only short strings and very limited arrays will be used.

I'd go with C strings and reuse of buffer space, see how much can stay in flash and think SD card.

13  Using Arduino / Programming Questions / Re: multiple if or for loop with if inside on: July 28, 2014, 11:12:31 pm
Break is a good solution to your stop variable, however as the code is fairly straight forward, we can do it with out any if statements at all:

Code:
char counterTest = 0;
for(int i = 16 ; i && array[i-1] ; --i, ++counterTest );

If you enable C++11 in IDE 1.5.7, you could also do this:
Code:
for( auto i : array ){
  if( i == LOW ) break;  
  ++counterTest;
}
Nice... could you point me where I could read an example of that for syntax? I don't understand the && array[i-1] and the comma before ++counterTest.

 i && array[i-1]  ..... the loop runs as long as this is true. && is a logical as opposed to bitwise AND

Look about halfway down the Reference on the left side for Boolean and Bitwise Operators
http://arduino.cc/en/Reference/HomePage

 --i, ++counterTest  ........ it's a comma separated list of actions done when the loop loops
14  Using Arduino / Programming Questions / Re: How to find number of "rows" in an array of strings? on: July 28, 2014, 06:10:19 pm
the strings are not part of the code, this is just an example. They are being created in another part of the code and are variable.

i don't think (sizeof(myString) / sizeof(myString[0])) would work because sizeof(myString) returns 8

LOL, what Arduino are you planning to run dynamic String arrays on?
15  Using Arduino / Programming Questions / Re: Timer0 issue on: July 28, 2014, 06:06:56 pm
Quote
no, i don't

Not sure what you mean or if you know what I meant.

Due is an 84MHz Arduino. It will handle 0.25 us resolution if you don't try too much else.
http://arduino.cc/en/Main/ArduinoBoardDue
Pages: [1] 2 3 ... 358