Show Posts
Pages: 1 ... 155 156 [157] 158 159 ... 352
2341  Using Arduino / Programming Questions / Re: Problems with loading and reading an array on: April 19, 2013, 01:11:58 am
Instead of randoms, fill the array with ordered values for test/debug and then you will know when you have it right instead of trying to guess.

Make the array global and you can get at it with functions besides the one it was declared in.

2342  Using Arduino / Project Guidance / Re: smallest & compatible components for USB, SIM & MicroSD on: April 18, 2013, 12:31:45 pm
You would have to run wires between the wee little Teensy and big big shield. That for me is the scary part because I am not that good at soldering which is why I get the "with pins". But for you, those pins increase the height greatly so you'd have to bend em or leave them out.

2343  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 18, 2013, 12:25:53 pm
I won't have time to look into the code you posted until later, but if you haven't already done so I suggest it would be worth your time writing a minimal sketch that demonstrates the problem in the simplest way you can.

I assume that a simple sketch that just calls millis() repeatedly and prints the result won't reproduce the problem, because it didn't for me.

Something else you're doing within the sketch must be triggering it, and the suggestions that it's interrupt overflow seem like the most likely explanation. However, that would not occur on a well-behaved system.

You may find it's something that can be provoked by doing SPI writes, or SPI reads, or something else. If you can figure out by trial and error what the key factor is, that would help us understand the cause and get us closer to finding a resolution.

Exactly. He's getting way too much variation to conclude that millis() are the cause.
2344  Using Arduino / Project Guidance / Re: Accurate rangefinding with two sensors? on: April 18, 2013, 12:14:22 pm
I looked at car bumper ultrasonic sensors. One the way I found that ultrasonics don't work off hair much at all so don't expect one to 'see' a dog or person in soft clothes with them.

Other than that, you have separate sensors giving data that could be defined as fuzzy shapes at distance. How about use Processing to graphic fuzzy shapes on your PC screen and see where the data suggests exploits? Just saying, as a tool to let you see which ways you can step.

2345  Using Arduino / Programming Questions / Re: Problems with loading and reading an array on: April 18, 2013, 12:06:30 pm
By the way, randomSeed() should be called once, not every time you want a random number.

Once in a while. After a while down the trail of pseudorandoms generated by a seed, the pattern does repeat. I've used the lower bits of time between user keystrokes for seeds before, generating and occasionally using random seeds might well be a task of its own with comparisons to prevent the same seed being used over and over. Who'da thunk that making data with more disorder could be harder than having it fall out in patterns? There's a study in that, I'm sure.

2346  Using Arduino / Project Guidance / Re: A Digital Beehive: A scientific study proposal. on: April 18, 2013, 11:57:51 am
The cheap sensors are 2x closer at detecting change as they are at  absolute temperature.

If your school has an Electronic Engineer department or a Physics department then check with them, they might know or cook up something you can use.

A pyrometer is based on rock that electrically polarizes when exposed to heat with the amount of polarization dependent on the temperature, sensitive enough to detect body heat. The expensive part is the electronics to read that as absolute temperature yet a PIR detector that uses the same principle gets around that expense by comparing output from 2 different pyrometers to look for difference. Suppose you had one looking in the hive and one outside, then if you have outside temperature known closely (1 expensive sensor) you can work with the comparative readings of many cheaper sensors inside versus the well known outside -- which would need calibration. You won't be able to use the PIR movement sensors as the two eyes on those are too close, but the principle may be something the physicists and EE's might get their own project out of.

2347  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 18, 2013, 04:46:18 am
Your homebrew version uses the AVR clock, it should have the same trouble. The source is *internal*.

I doubt that you understand about one ISR finishing and the one queued up starting either. Most ISR's I've seen run in a few microseconds or less considering the average instruction runs in 1 or 2 cycles at 16 cycles per microsecond. Gee, 1 clock edge being off by .5% or less, and the error is not cumulative... that clock to trigger an ISR to change a variable that your code doesn't check every microsecond anyway.

How did you do with that random atan() version I posted? The values wandered between 1063 and 1062 if I didn't interact with my PC. If I did then every so often I'd see 1062. What did you get?

The ceramic resonator is accurate to .5% (5000ppm).  At room temperature, no device should be this much off.  Being 5000ppm in error is worst case due to temp, age etc....

Problem's in the software and we don't see all the code so it's like an Easter Egg hunt without the back yard.

2348  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 18, 2013, 03:37:58 am
2) Everything I read is that millis() shouldn't lose so much time.  But I see what I see.  My laptop clock could be wrong (even though its actively NTP-syncing).  But the telescope tracking is off, and this is detectable by watching a star (the ultimate reference).  So I know the Arduino is forcing the tracking off, which can only be explained by its losing time.
No, I'm saying that the SOFTWARE won't lose time. Everyone knows the resonator is only accurate to 0.5%, which could be up to be seven minutes over a day or 18 seconds per hour or 6 seconds per 1200 second period (twice what you measured)

Accuracy is within +/-5%.

Some at the right temperature have a chance of being very close to perfect (at the right temperature) as much as they do being off by a full tolerance.

2349  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 18, 2013, 01:27:02 am
No, I have not... but if the millis() or other ISR is getting masked, an external source would also lose ticks. I don't have a precise external time base anyway so the RTC seems the way to go. Looks like the PCF8583 is the way to go, 8-pin DIP, through-hole, 10ms accuracy.

It will only be late by as much time as the current ISR takes to finish, then it should run. The next tick, being from external, will still come 1 ms after the last was -sent-. And it looks like Serial is the real bugger in this case.

I have Arduino-compatible Teensy's. Their Serial goes straight to USB, there's an IDE patch for them and they are cheap but I do recommend to get the pins unless you are very good soldering heavy pins very close to surface mount parts. Not me.
2350  Using Arduino / Programming Questions / Re: Problems with loading and reading an array on: April 18, 2013, 01:18:59 am
You might be on to something there.

Once I sort out this glitching issue I will definitely start looking at cleaning up the code with that array trick.  It does make sense for some places... maybe just toss in some if the array variable = a number then that meant the button was pressed so do whatever needed for that.

I could see this shortening up some code a bit with some cleverness.


Now, what the hell is going on with the population of this Array though?? smiley-sad

You keep re-seeding randoms with an analog read to pin 0 that are a fraction of a millisecond apart. If that's an unterminated input, they don't vary that fast. If you're feeding it high-pitched noise then that might work but you say you always get 8? That would be because the seed is the same, so don't seed so often. Once per button press and be feeding the pin something like busy music through a diode.

Yes, you want to use arrays.

byte btnPin[ 4 ] = { 19, 18, 2, 3 };
byte btnState[ 4 ] = { 0,0,0,0 };

for ( byte i = 0; i < 4; i++ )
  btnState[ i ] = btnPin[ i ] );
Also read about enum for enumerate. It lets you assign numbers to names in a list that your code uses, like a list version of #define. The compiler replaces the names your code uses to make easier sense (one hopes) with the numbers. The compiler type-checks enums which I don't think it does with #defines.

enum { Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec } month;

if ( month == Dec )
  print( "HO HO HO!" );

C strings are char arrays with any text in the first chars and a char == 0 marks the text end. If the array is bigger then you can add characters until the last array character is zero. It's good to either check the limit or code so it never gets passed.
There's a whole set of C string functions but remember the string is a char array that you can read or write any character of just by indexing to it and operating.

char ch = '0'; // sets ch = 48, which is the ASCII code for 0, or NULL, OFF and LOW.
ch = '7';         // sets ch = 55
int val = ch - '0'; // sets val= 7

ch = 'X';
if (( ch >= 'A' ) && ( ch <='Z')) { print( "upper case alpha" );
Of course there -is- a function to do that but you have to remember they exist and it helps to have a bookmark  smiley-grin

And step by step you learn pointers and on to classes and maybe even templates, your growing bag of tricks will help you write more and more effective code with less effort all the time. It's worth learning.
2351  Using Arduino / Programming Questions / Re: String clarification on: April 17, 2013, 10:35:25 pm
If you read serial characters and add each to a String as it comes in, the String copies itself with the new character added and erases it's old self leaving a hole that the next copy won't fit in but the 3rd will before the cycle begins again as the next character is added, etc.
If your program defined a String before other well-behaved variables then the hole left when it copies bigger may never get used.

When I have time-intensive code that is also logging reports, do I need Strings soaking cycles and heap to jump through convenience hoops so I can be ignorant of my hardware and how my code does or does not fit? No. I want my code to be tight and fast, not dimwitted.
The thing about to String or not to String is practice and familiarity. It is usually better to stick with one way and know it well than be so-so at both, but if you've got it in you to be good at both then shine on, you diamond!
But most of us choose at least on one environment or other just one way and when it comes to being able to give or get much help, see who responds when you call for it and what they can do.
2352  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 17, 2013, 07:40:29 pm
Did you try with an ***external*** oscillating source?
2353  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 17, 2013, 07:02:28 pm
With an external clock interrupting every 1 ms sharp and incrementing the value of an unsigned long, you'd be able to use that variable instead of millis().

It might be off if another interrupt is acting but ISR's are supposed to be short for a reason.

I wonder how short serial print() is? One way to influence serial print() time is to limit serial text and send values over as packed binary, and only send raw or compressed data. Set up a Processing sketch to get those bytes in the PC, process and make the CSV file and your Arduino will have more cycles for aiming and data capture.

I promise you, if you can code Arduino, you can code Processing. It will help greatly with resource headaches.
2354  Using Arduino / Programming Questions / Re: How to generate a piano sound using SPI on: April 17, 2013, 11:58:45 am
You might table a sine wave and then vary the pitch by how fast you shove the data through the DAC.

Also look up ADSR envelope to see about volume control.

Best move, get a sound chip with MIDI and room for 'effects' like reverb, etc. MIDI w/o effects takes a lot of work to sound good.

2355  Using Arduino / Programming Questions / Re: Millis Accuracy Again on: April 17, 2013, 11:48:37 am
Arduino allows the 64-bit integer types long long and unsigned long long. You can do high-precision fixed-point with those, faster than with 32-bit float/double. Problem may be in using 8 bytes per stored value instead of 4.

You will have to make your own fixed-point atan/trig table in flash but look at it this way, lookup is incredibly faster than calculate and you will be using the methods of Charles H. Moore the astronomer in 1959. Look him up!

Pages: 1 ... 155 156 [157] 158 159 ... 352