Show Posts
Pages: 1 ... 129 130 [131] 132 133 ... 301
1951  Using Arduino / Sensors / Re: Measure nightsky with TSL237 on: March 05, 2013, 12:53:49 pm
I wouldn't use a library. I'd save micros() in an unsigned long, count 10,000 pulses and save the micros() right then.
Annnnnd I think you can get micros() in an interrupt though it's stopped. If not then you'll pick up a couple micros setting a flag in the interrupt, leaving the interrupt and catching the flag in loop(). With a tight loop() you'll have micros() very quickly.

Errors --- you can measure Arduino inaccuracy and compensate. Deal with that after you get the rest working. It amounts to changing time microseconds

frequency = pulses / time

If the time is a 62845 microseconds then multiply pulses by 1 million then divide by 62845 to get Hz = cycles(pulses) per second.

10000 pulses / 62845 usecs = 10000 pulses / ( 62845 seconds / 1000000 ) = 10000 pulses x 1000000 / 62845 seconds (doing it with integers and the least loss requires 64-bit long long int) = 159121 Hz.
 
When you do math for science, keep the units (pulses, seconds, ergs) in the math because at the end if your units don't make sense then your math didn't either. (this is where you remember your science teachers saying the same thing)

1952  Using Arduino / Sensors / Re: DS18B20 multiple sensors on: March 05, 2013, 07:50:45 am
The microcontroller must assure that sufficient power is available by enabling what Dallas calls a "strong pullup". 

I dunno about PIC but with AVR I can make a pin pullup by setting it INPUT HIGH. If I'm not using that same pin to read data for a while, I can switch it to OUTPUT and give the line 5V. If I want to, I can switch the same pin to INPUT again. With the ability to switch modes in less than a usec, why do I need an extra pin? I can throw an extra resistor, even 1k on the pin and it won't affect the current from low-tolerance pullup in the AVR (20k-50k, does PIC have built-in pullup resistors?) much but limit the OUTPUT HIGH current lots.
   
1953  Using Arduino / Programming Questions / Re: Why does this program only work when I use a Serial.* statement in it? on: March 05, 2013, 07:38:14 am

The example code is not the best it could be.

int ledpin = 13;  //  there are less than 256 pins, use a byte instead, save a byte in RAM
This I get.
int pinArray[ 8 ]; // because a habit is a habit
This?  Not so much unless you mean it as an example of what NOT to do?

Exactly. It is the same mistake multiplied 8 times in 1 line most often out of the habit of typing i-n-t.

 
1954  Using Arduino / Sensors / Re: Measure nightsky with TSL237 on: March 05, 2013, 07:12:01 am
You can count the time length of a number of pulses, the more you count the more the per-pulse average will ... average out.

You can count how many pulses in a measure of time and lose a fraction of a pulse. The longer the time the less the lost fraction means.

pulses/time or time/pulses, both are ratios is all. Get one, you have the other.

 
1955  Using Arduino / Programming Questions / Re: Delays and unsigned long on: March 04, 2013, 04:37:14 am
Why not a stepper?
1956  Using Arduino / Sensors / Re: DS18B20 multiple sensors on: March 04, 2013, 04:24:40 am
The dallas 1-wire bus is made up of either 2 or 3 wires with the sensors attached along the bus.  One bus wire is ground and one is the data line.  The third (optional) wire is to carry a full 5V to the devices.  Since the data bus uses a pullup resistor, power can be sourced from the bus by the device.  If you ground the normally 5V supply pin on the device, it will draw power from the data line.

Since the data line on the bus has a pullup on it, only a limited amount of current can be supplied to the device.  This is fine until the device needs to execute a CONVERT command to sample the temp and measure it.  This requires more current than can be drawn thru the data line.  So back at the head end of the bus (where the microcontroller is) after issuing a CONVERT command enables full power to the data line by bypassing the pullup resistor.  The device can then draw as much current as it needs.  After the CONVERT command is finished, the microcontroller disables the pullup bypass so that communications can take place on the data line.  This saves running the 5V power wire to each device.

I don't know what you mean about many wires, all devices can reside on one bus.  Please just download the document, it explains it all much better.

I see that no extra pin is needed. The data pin goes OUTPUT HIGH during the conversion only.

If the device has a conductive chassis you would only need 1 wire.
 
1957  Using Arduino / Programming Questions / Re: Possible Serial Overflow? on: March 04, 2013, 04:14:28 am
Learn the BlinkWithoutDelay sketch, then you will know how to handle tasks-in-time and generally still have time for more.

You don't need blocking code.
>> Blocking code kills your code's ability to do more than one thing at the same time.
>> Blocking code kills your code's ability to respond to change quickly.

How that one little, needs no wiring sketch works is the key to not needing blocking code.

From there, learn about state machines.

1958  Using Arduino / Sensors / Re: DS18B20 multiple sensors on: March 04, 2013, 03:40:56 am
I would rather the wire than a pin and a wire or many pins and many wires. Using the pin for extra power only when the device works will need a wire regardless and might need many of both.

Why would you need a pin to supply power if you're not running off a pullup?

Is the point of parasite power to reduce power consumption for battery operation?

1959  Using Arduino / Project Guidance / Re: Home cockpit and Arduino: some questions about feasibility. on: March 04, 2013, 03:31:00 am
On the other hand, a bit OT, what simulator do you fly with?

I don't fly much at all anymore. Last was IL-2, a spin to look at 4.11.1. I like IL-2 and it's the most modern flight sim my PC can run. But my good videocard died so now I run with limited-range vision.

Last time I was up to being really into it, 8 to 12+ hours a day online was RB3D in 1998 in beta testing and after till life caught up with me. I got pretty hot then. Not the best but better than not bad. I had a partner and we'd practice loose-deuce from server to server. It was fun.

1960  Using Arduino / Project Guidance / Re: Home cockpit and Arduino: some questions about feasibility. on: March 04, 2013, 03:00:58 am
Quote
Have anybody made yoke and rudder pedals at arduino, shop yoke pay lot and can do itself if have code whit arduino ?
i need yoke,choke,trimm,pedals,and maybe propeller angle ?

The easy way to make a home controller is making it an HID combo: mouse/stick/keyboard. Maybe the Leonardo can do that. The Teensy 2.0 and Teensy++ 2.0 certainly can as it's built right into the Teensyduino IDE addon. If you're not a solder wiz make sure to get the with pins option on those, they plug right into a breadboard. The Leonardo uses the same chip as the Teensy, there's a features comparison on the Teensy site. Plain Teensy 2.0 has 12 10-bit analog pins and USB-speed serial, for like $20 with pins.

You can get higher precision ADC chips and run them with controllers if 10 bits is not enough. But even with 10 bits you want short shielded wires from sensor to chip to get the best results.

For homemade sticks, the best axial measure is a bar magnet across the end of a shaft and a linear Hall sensor right above the turn axis. The Hall output will tell the cosine of the alignment of the magnet times the input voltage. Stick position can be read any time.

There are people making floor-mount joysticks out of car U-joints. Some on a frame with seat, pedals and PC-mounts. Some weld steel, some use PVC tube, one in Greece includes a gimbal mounted motor-powered limited-tilt-couch for the user and PC.

1961  Using Arduino / Programming Questions / Re: Why does this program only work when I use a Serial.* statement in it? on: March 04, 2013, 01:58:09 am
I don't see it in much of the example code. 

The example code is not the best it could be.

int ledpin = 13;  //  there are less than 256 pins, use a byte instead, save a byte in RAM
int pinArray[ 8 ]; // because a habit is a habit
1962  Using Arduino / Sensors / Re: DS18B20 multiple sensors on: March 04, 2013, 01:48:30 am
Time to look at the datasheet, it tells all.  The only difference is that you have to supply extra power when a temp conversion (or EEPROM write) is in progress.  The datasheet shows how to do it, it's simple; it takes an extra i/o pin though.  You just enable the pin after issuing the conversion command.  That in turn bypasses the pull-up resistor on the data line (Q) so that the device has plenty of power to do the temp conversion or write to its EEPROM.  Look at the datasheet, they have a nice write-up on how it all works.

Is that for parasite mode only?


Yes it is.

Then a common power line could save an I/O pin ... is that per device?

1963  Using Arduino / Sensors / Re: DS18B20 multiple sensors on: March 03, 2013, 06:55:13 am
@GoForSmoke, i don't realy understand how do you meen, do you maybe have any shematic picture or something like that?  smiley-red

Using SPI bus shift registers, it would connect like in the Daisy chain SPI configuration here:
Daisy chain SPI configuration

The 3 SPI slaves would be 3 8-bit parallel to serial shift registers. A sensor would hook to each input pin which is not shown in the wikipedia diagram. The registers read the digital state from the sensor and on command, copies those as bits. Then the bits are shifted out of the chips and read by the master in as fast as 1.5 microseconds.

The register has its own power line, some people power leds off them on external power.

1964  Using Arduino / Sensors / Re: DS18B20 multiple sensors on: March 03, 2013, 06:34:10 am
Time to look at the datasheet, it tells all.  The only difference is that you have to supply extra power when a temp conversion (or EEPROM write) is in progress.  The datasheet shows how to do it, it's simple; it takes an extra i/o pin though.  You just enable the pin after issuing the conversion command.  That in turn bypasses the pull-up resistor on the data line (Q) so that the device has plenty of power to do the temp conversion or write to its EEPROM.  Look at the datasheet, they have a nice write-up on how it all works.

Is that for parasite mode only?

1965  Using Arduino / Sensors / Re: Measure nightsky with TSL237 on: March 03, 2013, 06:01:37 am
Ok, i start to understand now, for the long, it can hold 32 bit of numbers, witch is 2 billions something, i think that will do, so for now, i will count Hz.

i also found this formula that seems more logical for me smiley

From candela/m2  to magnitudes/arcsec2:
 B=-2.5Log(C/108000)   or   12.58-2.5Log(C)


Yes. But the variable has to be able to handle the math you will use when scaling and squaring, be able to count much bigger than the numbers used, and smaller.

If I am dealing with kilometers, my work unit might be in millimeters, mm fractions are lost.
To help keep accuracy, instead of 1 float factor like 333.333333 I keep two integers 1000 and 3 and use those as 'x 1000 / 3' in the bigger equation.
When the bigger equation is written out don't be afraid to rearrange the operations (without breaking the algebra!) to push the intermediate value high before dividing.
X = A * (1000 / 3) * (22 / 7) would re-arrange to X = A * 22000 / 21. Note that with FP using factors you get the first.

Once you have your equation, then is the time to see how many digits you need. If A above is big then I need enough for 7000 x the biggest 'A' can be with enough to the right for display decimals.

Using mm I can show 1.234 km or 1.2 km and know I had 2 places round-safe in the math.

You deal with some squares and factors with lots of places? Some of those will be simple as a ratio of integers, some won't. Pi to 6 places is 3141592 / 1000000, to use that in an integer equation adds 7 digits to the digits needed to hold the number being multiplied by Pi to 6 places. There's a price for precision and scale, in digits and bytes. 

Pages: 1 ... 129 130 [131] 132 133 ... 301