Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 415
61  Using Arduino / Sensors / Re: Light sensor - checking when to turn On/off lights on: August 02, 2011, 06:03:19 am
one of these could possibly work using a 250 ohm  resistor. I don't have direct experience with these, perhaps someone else can suggest a better solution.
62  Using Arduino / Sensors / Re: Light sensor - checking when to turn On/off lights on: August 02, 2011, 03:04:22 am
50 meters is too long for I2C and you may find it difficult to eliminate noise on analog signal running over that length.

Does your application really need an accuracy of 1 or 2 lux?

It will be easier for people to suggest solutions if you can say more about what you are building.

63  Development / Other Software Development / Re: New and growing well-documented, feature-complete I2C device library on: August 02, 2011, 02:08:03 am
Hi jeff, that looks very useful.

one suggestion is to add a timeout property to the library so calls want hang if the I2C device does not respond. Perhaps something like this:

Code:
   uint8_t count = 0;

    Wire.beginTransmission(devAddr);
    Wire.send(regAddr);
    Wire.endTransmission();

    Wire.beginTransmission(devAddr);
    Wire.requestFrom(devAddr, length);    // request length bytes from device

    unsigned long readStart = millis();
    do
    {
      if(Wire.available() >= length ) {
        for (; Wire.available(); count++) {
        data[count] = Wire.receive();
        #ifdef I2CDEV_SERIAL_DEBUG
            Serial.print(data[count], HEX);
            Serial.print(" ");
        #endif
        }
      }
    }
    while(millis() - readStart < timeout); //wait up to timeout period reading  
    
    Wire.endTransmission();

You would want to inform the caller of a timeout, for example return 0 if the code times out.
64  Using Arduino / Sensors / Re: Light sensor - checking when to turn On/off lights on: August 02, 2011, 01:52:16 am
You may want to look at the TAOS TSL256x range, it provides an accurate digital output using I2C and you can find arduino code for this using google

http://www.taosinc.com/getfile.aspx?type=press&file=tsl2562-e40.pdf

65  Using Arduino / Sensors / Re: Best chip for frequency/pulse counting? on: August 02, 2011, 01:40:53 am
That's coming along. The sketch below has a simplified gate duration check and enables the internal pull-up resistor on the input pin. see how that goes:

Code:
// 16 bit timer defines added by mem to enable redifining the timer used

#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#if defined(__AVR_ATmega1280__)
#define TCCRnA TCCR5A
#define TCCRnB TCCR5B
#define TCNTn  TCNT5
#define TIFRn  TIFR5
#define TOVn   TOV5
#define pulseInPin 47
#else
#define TCCRnA TCCR1A
#define TCCRnB TCCR1B
#define TCNTn  TCNT1
#define TIFRn  TIFR1
#define TOVn   TOV1
#define pulseInPin 5
#endif

void startCount() {

  // hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
  TCCRnA=0;     // reset timer/countern control register A
  TCCRnB=0;     // reset timer/countern control register A
  TCNTn=0;     // counter value = 0
  // set timer/counter1 hardware as counter , counts events on pin Tn ( arduino pin 5 on 168, pin 47 on Mega )
  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCRnB ,CS10); // External clock source on Tn pin. Clock on rising edge.
  sbi (TCCRnB ,CS11);
  sbi (TCCRnB ,CS12);
  TCCRnB = TCCRnB | 7; //  Counter Clock source = pin Tn , start counting now
}

unsigned int getCount(){

  unsigned int count;
  TCCRnB = TCCRnB & ~7;    // Gate Off  / Counter Tn stopped
  count = TCNTn;
  TCCRnB = TCCRnB | 7; //  Counter Clock source = pin Tn , start counting now   
}

unsigned long opengate = 0;
unsigned long gatetime = 0;
unsigned long sampletime = 2000;
unsigned int pulses = 0;
int timeset = 1;

void setup(){
  digitalWrite(pulseInPin, HIGH); // turn on pull-ups so pin is not floating
  Serial.begin(9600);
  Serial.print("hello ");
  opengate = millis(); // open the gate ready for first count
}

void loop(){

  // check if sampletime has elapsed since gate was opened
  if( millis()- opengate  >= sampletime) {
    pulses =  getCount();
    Serial.println(" here is the count ");
    Serial.print(pulses);
    delay(2000);   
    startCount();
    opengate = millis(); // start over with new gate time
  }
}
66  Using Arduino / Microcontrollers / Re: Boards file for 3.3v 12mhz atmega328p? on: August 01, 2011, 02:51:22 pm
Perhaps you should take a look at hardware/arduino/cores/arduino/wiring.c and look particularly at the implementation of  delayMicroseconds().
[/quote]


That was supposed to be addressed a year ago : http://code.google.com/p/arduino/issues/detail?id=256

Hans-Juergen Heinrichs  created and excellent set of delay routines that were  suggested as replacement for the current Arduino implementation of delayMicrosecond.

An include file with proper implementations for _delayNanoseconds and _delayMicroseconds can be found here: http://code.google.com/p/glcd-arduino/source/browse/trunk/glcd/include/delay.h

Johnwasser, thanks for pointing that out. Lets hope that the Arduino distribution will have something like that soon.
67  Using Arduino / Microcontrollers / Re: Boards file for 3.3v 12mhz atmega328p? on: August 01, 2011, 01:27:31 pm
As far as I am aware, all of the distributed Arduino code should cope with 12MHz. The core code and libraries use the f_cpu constant tp determine speed and these have been correctly altered in boards.txt. Note that some third party libraries may cause problems if they don’t correctly use the f-cpu constant.

As johnwasser says, the bootloader will not be set up for your altered clock speed so you either need to modify the bootloader or tweak the baud rate to run faster to compensate for the slower clock.
68  Using Arduino / Sensors / Re: Best chip for frequency/pulse counting? on: August 01, 2011, 11:48:13 am
the library linked below is probably easier to use than the code posted above. It uses a similar technique for counting and has implemented use of another timer to gate the counter if that is what you want to do.  

http://interface.khm.de/index.php/lab/experiments/arduino-frequency-counter-library/
69  Using Arduino / Sensors / Re: Best chip for frequency/pulse counting? on: August 01, 2011, 11:41:24 am
the sketch is based on standard code to access the 16 bit counter inside the Arduino chip. The technical details are in the datasheet section covering the 16 bit counter unit (section 16.5 in the latest version of the ATmega328p datasheet)

The count is stored in the TCNT1 register in the Uno chip. this line access this value:
   count = TCNTn;

Note that when compiled for the Uno the compiler will substitute TCNT1 for TCNTn. It looks a little complicated because the same code can be used on bot a Uno and a Mega even though these chips use different registers for counting.
 

This is just a counter, your sketch would control the length of the sample time by adjusting the duration between calling startCount and getCount. How were you intending to control the count duration if you used an external counter?   
70  Using Arduino / Sensors / Re: Best chip for frequency/pulse counting? on: August 01, 2011, 09:45:40 am
The solution with the minimum number of wires does not require any external chip.  You can use the 16 bit hardware timer to count pulses. Arduino does not provide a simple interface to this but I have used the following code to count up to 64k pulses:

Code:
// 16 bit timer defines added by mem to enable redifining the timer used

#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#if defined(__AVR_ATmega1280__)
#define TCCRnA TCCR5A
#define TCCRnB TCCR5B
#define TCNTn  TCNT5
#define TIFRn  TIFR5
#define TOVn   TOV5
#else
#define TCCRnA TCCR1A
#define TCCRnB TCCR1B
#define TCNTn  TCNT1
#define TIFRn  TIFR1
#define TOVn   TOV1
#endif

void startCount() {

// hardware counter setup ( refer atmega168.pdf chapter 16-bit counter1)
  TCCRnA=0;    // reset timer/countern control register A
  TCCRnB=0;    // reset timer/countern control register A
  TCNTn=0;    // counter value = 0
  // set timer/counter1 hardware as counter , counts events on pin Tn ( arduino pin 5 on 168, pin 47 on Mega )
  // normal mode, wgm10 .. wgm13 = 0
  sbi (TCCRnB ,CS10); // External clock source on Tn pin. Clock on rising edge.
  sbi (TCCRnB ,CS11);
  sbi (TCCRnB ,CS12);
  TCCRnB = TCCRnB | 7; //  Counter Clock source = pin Tn , start counting now
}

unsigned int getCount(){

  unsigned int count;
   TCCRnB = TCCRnB & ~7;   // Gate Off  / Counter Tn stopped
   count = TCNTn;
   TCCRnB = TCCRnB | 7; //  Counter Clock source = pin Tn , start counting now  
}
void setup(){
}

void loop(){
}


Connect the pulse input to Uno pin 5 (make sure the peak is not greater than 5 volts).

startCount() resets the timer and starts

Note that the 16 bit timer is used by the Servo library and for PWM on pins 9 and 10 so this will only work if you don't need those capabilities
71  Using Arduino / Motors, Mechanics, and Power / Re: Servo's triggered by TTL? on: August 01, 2011, 09:30:02 am


_Franky_ , yes thats it.


>When the servo library disturbs the interrupt handlers, what happens?
While Servo is writing its data, any other interrupt handlers must wait until the write is finished. The write only takes a microsecond but without some delay the sketch is spending most of its time disabling and enabling interrupts for no benefit. The Servo values are sent to the servos every 20ms so there is no point in updating more quickly than that.

72  Using Arduino / Motors, Mechanics, and Power / Re: Servo's triggered by TTL? on: August 01, 2011, 07:29:40 am
You should add a delay in your loop function so that the servo library is not constantly disturbing the interrupt handler to write values. A delay of 15ms is customary, see the servo knob and sweep example sketches.
73  Using Arduino / Motors, Mechanics, and Power / Re: official arduino motor shield v3.0 problems on: August 01, 2011, 07:23:11 am
you don't need a shield to run a servo, any free digital pin will work.

see the servo tutorial here: http://arduino.cc/en/Tutorial/Sweep
74  Using Arduino / Microcontrollers / Re: Arduino as a Simple Power Source on: August 01, 2011, 07:09:23 am
There have been conflicting responses to the question posed in this thread about the maximum current driving capability of the Atmel chips used on Arduino boards.  Advice to operate well below the absolute maximum ratings of 40ma per pin is not in dispute where maximum reliability is important. What is disputed is whether it is safe to operate pins at or near the 40ma  absolute maximum rating.

To get a definitive answer I asked the technical support team at Atmel for their perspective. I asked if they could confirm if Atmel considered the following advice valid for hobbyists using the Arduino ATmega chips.

Quote
The absolute maximum ratings for the Arduino chip (ATmega328P) are
40ma per pin with no more than 200ma across all pins.
It is good practice to design your applications to operate well within
the absolute maximum ratings for best reliability - limiting pins to
20ma provides a large comfort margin. For hobby use where more pin
current is wanted and reduced reliability is acceptable, 30ma would
not significantly reduce the operating lifetime and a pin can cope
with 40ma as long as the 200ma total chip dissipation is not exceeded.

The datasheet says that exposure to absolute maximum rating conditions
for extended periods may affect reliability but with typical hobby use
in a domestic environment (temperatures below 40ºC), the 5 volt
Arduino should have a life expectancy of many years (decades?)
sourcing or sinking three or four pins continuously at 40ma.

The response from Atmel was:

Quote
  The content mentioned by you is correct as per the corresponding datasheet of ATmega328P.
You seem to have covered all the aspects associated with guidelines.

I also asked:
Quote
The Mean Time Between Failure for the ATmega328 is quoted at just
under 2000 years at 65ºC,  can you provide a rough idea how that
figure would change for conditions where three or four pins are
sourcing or sinking 40ma at 40 ºC  on a 5 volt chip.
Their response:
Quote
As of you have rightly noted, currently we only have Reliability report for the test done at 65 degree centigrade (which is available at http://support.atmel.com/bin/customer.exe?=&action=viewKbEntry&id=266).

This should not deviate and should hold good for the extended conditions of 4 pins sourcing/sinking 40ma at 40 ºC.

I hope this helps to clarify that running three or four pins at or near 40ma will not fry the Arduino chip.
75  Using Arduino / Sensors / Re: analogreference and resolution question (STILL NEED HELP) on: July 28, 2011, 03:16:35 am
You may want to consider as a possible alternative to a shunt, the current sensing device here: http://www.sparkfun.com/products/8883
Pages: 1 ... 3 4 [5] 6 7 ... 415