Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 416
61  Using Arduino / Programming Questions / Re: Implementing equations on: August 03, 2011, 11:06:18 pm
It is probably the ^ that is throwing you, this is a bit wise exclusive OR.
You need

this might be a better link:
62  Using Arduino / Programming Questions / Re: Moved LCD to other pins and it stopted working on: August 03, 2011, 11:03:57 pm
The most likely cause is the wiring, did you check that the LCD worked after  moving the pins before adding the ethernet code?

If not,  try the sketch with the calls to  Ethernet.begin,  server.begin commented out. If you don’t see the start-up message then double check your wiring.
63  Using Arduino / Motors, Mechanics, and Power / Re: VarSpeedServo - a modified Servo library with speed control on: August 03, 2011, 10:55:28 pm
I have just come across this, nice job Korman.

Do you think this is a capability I should add to the core Servo library?

BTW, I posted an example sketch using this library here:,68305.msg504226.html#msg504226

64  Topics / Robotics / Re: Simultaneous but different servo sweeps with four servos on: August 03, 2011, 10:51:08 pm
here is another way to do it; using the slow speed modification to the servo library discussed in this thread:,61586.0.html

// speed controlled Servo Sweep
// see:,61586.0.html
// Michael Margolis 4 August 2011

#include <VarSpeedServo.h>

const int NBR_SERVOS = 4;       // the number of servos

VarSpeedServo Servos[NBR_SERVOS];        // servo objects

int servoPins[NBR_SERVOS]        = {8,     9,  10,  11}; // servo pins
int servoSpeeds[NBR_SERVOS]      = {1,    10, 100, 255}; // sweep speed, 1 is slowest, 255 fastest)
int servoMinPosition[NBR_SERVOS] = {10,   20,  30,  40}; // the minumum servo angle
int servoMaxPosition[NBR_SERVOS] = {120, 130, 140, 150}; // the maximum servo angle

void setup()
   for(int i=0; i < NBR_SERVOS; i++) 
     Servos[i].slowmove(servoMinPosition[i],servoSpeeds[i]) ; // start sweeping from min position

void loop()
  // sweep the servos
  for(int i=0; i < NBR_SERVOS; i++)
     if( Servos[i].read() == servoMinPosition[i])
       Servos[i].slowmove(servoMaxPosition[i],servoSpeeds[i]) ;         
     else if( Servos[i].read() == servoMaxPosition[i])
       Servos[i].slowmove(servoMinPosition[i],servoSpeeds[i]) ;           

65  Development / Other Software Development / Re: New and growing well-documented, feature-complete I2C device library on: August 03, 2011, 10:05:49 pm
... As a compromise, I've left the default at 250ms and added an optional "timeout" argument to the tail end of each read* method, so that for those specific actions that might legitimately take a long time, it's easy to specify a longer timeout. You could already have just modified the I2C::readTimeout variable before calling the desired read* method, but that's not very convenient or pretty. This is much better, and I probably should have done it that way in the first place. Yay for helpful ideas from other people!

I think having a one second default is a better idea. It won't block unless the device doesn't respond and in that case does it matter if the error is returned in one second rather than 250ms? (in the previous code, the error condition would cause it to block indefinitely)

The advantage of a longer default time-out is that inexperienced users won't get false errors when using devices that do take longer than 250ms. Experienced users can increase or decrease the time-out if they want, but it seems more friendly to have a default that minimizes the chance that errors could be reported even when the system if functioning correctly. The longer default time-out has no impact on performance on systems where the I2C devices are responding correctly.
66  Using Arduino / Sensors / Re: Best chip for frequency/pulse counting? on: August 03, 2011, 09:20:12 pm
This version should correctly return the count. I also moved the initialization code into a separate function as this can be called once only from setup.

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

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

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

void initCounter() {
  // 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
  // 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); 
  TCNTn = 0;

void startCount() {
  TCNTn=0;     // counter value = 0
  TCCRnB = TCCRnB | 7; //  Counter Clock source = pin Tn , start counting now

unsigned int getCount(){
  TCCRnB = TCCRnB & ~7;    // Gate Off  / Counter Tn stopped
  return TCNTn; 

unsigned long opengate = 0;        // the time the gate is opened
unsigned long sampletime = 2000;   // the pulse counting duration 

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

void loop(){
  // check if sampletime has elapsed since gate was opened
  if( millis()- opengate  >= sampletime) {
    unsigned int pulses =  getCount();
    opengate = millis(); // start over with new gate time
67  Development / Other Software Development / Re: New and growing well-documented, feature-complete I2C device library on: August 03, 2011, 01:04:48 am
The timeout is set to a default of 250ms (defined in I2Cdev.h). Read operations that time out return -1, while 0 indicates instant failure and 1 or more indicates success. A timeout length of zero disables timeout detection.

I think that 250ms is too short for some precision I2C devices that have long sample times.
I suggest at least doubling the default  value to avoid false errors with those devices.
68  Topics / Robotics / Re: Wireless Servo Control on: August 02, 2011, 01:03:27 pm
I posted some code that my help you here:,67633.msg497265.html#msg497265
69  Using Arduino / Motors, Mechanics, and Power / Re: official arduino motor shield v3.0 problems on: August 02, 2011, 09:37:56 am
... and yes as you said, it seems i dont need the shield for running steppers. smiley-wink smiley-razz

you do need the shield for the steppers, its the servos that run without a shield.
70  Using Arduino / Sensors / Re: Best chip for frequency/pulse counting? on: August 02, 2011, 08:50:10 am
a minor tweak, the following two variables are no longer used and can be deleted:
  unsigned long gatetime = 0;
  int timeset = 1;

have fun!
71  Using Arduino / Microcontrollers / Re: expanding i/o ports by integrating multiple arduinos on: August 02, 2011, 06:08:36 am
you could use the arduino Mega although that is probably overkill

a nice little board with more than enough pins is the Teensy++
72  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.
73  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.

74  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:

   uint8_t count = 0;


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

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

You would want to inform the caller of a timeout, for example return 0 if the code times out.
75  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

Pages: 1 ... 3 4 [5] 6 7 ... 416