Show Posts
Pages: 1 2 3 [4] 5 6 ... 416
46  Using Arduino / Motors, Mechanics, and Power / Re: Wish list for Servo library enhancements on: August 06, 2011, 06:06:05 am
Quick look in the lib:

Servo::write
1) negative values make no sense , replace  by unsigned int types ?
2) I don't like it that the param value in write() can have two distinct meanings.

Servo::attach
1) negative value make no sense , replace by unsigned int?
2) test MIN_PULSE_WIDTH <= min <= max <= MAX_PULSE_WIDTH?

Servo::read
1) strange values if ( this->servoIndex == INVALID_SERVO ); readMicroseconds returns value 0 << SERVO_MIN.

Servo::readMicroseconds
1) return type of function differs from internal var pulsewidth; which is stricly speaking not needed
2) using -1 for invalid values..

Rob, thanks for your input.  I do agree that the argument types for Arduino libraries such as this appear less than ideal.  The current Servo library was  a drop in replacement for the one used prior to version 0017 and the argument and return types were deliberately kept the same.
ints are used throughout Arduino code to express values that cannot be negative, for example see analogRead and digitalRead.  If you can convince the Arduino team to change the rest of the API I will be more than happy to update the core Servo library accordingly.

Your point about the dual nature of write is well taken. It was included for backwards compatibility with an earlier library but  in hindsight I should have removed this capability from the initial release of this library when it went into the Arduino core. If its not too late I will see if I can make this change for the 1.0 release.

There may be a way to address all your points without changing the core, see later post regarding a superServo library.

Michael
47  Using Arduino / Motors, Mechanics, and Power / Re: Wish list for Servo library enhancements on: August 05, 2011, 07:58:48 am
Trim and Reversing are features in most RC transmitters.
I added those features to the servo library (a few versions old) for my own use.

Yes, they are standard features on an RC transmitter, but I wonder if the ease of adding a map function to get this capability into a sketch is one reason why more people don't request this feature. How many bytes of RAM did you use for the trim functions.

One way of implementing trim without using and RAM is to modify the min and max values that can be set in the attach method. The resolution of these values is currently 4 microseconds, I wonder if that would be fine enough for trim settings?
48  Using Arduino / Motors, Mechanics, and Power / Re: VarSpeedServo - a modified Servo library with speed control on: August 04, 2011, 04:17:38 pm
(My sweep code has an advantage that I can do something synchronized with two servos. In an built in function one would need to change the sweep rate for each "ratio".)

What do you mean by the ratio? Perhaps you can say more about the functionality.

I don't want to hijack this thread so I have created a new thread here: http://arduino.cc/forum/index.php/topic,68474.0.html
49  Using Arduino / Motors, Mechanics, and Power / Wish list for Servo library enhancements on: August 04, 2011, 04:14:43 pm
A couple of recent threads have discussed servo enhancements such as setting the rate of servo movement or automatically sweeping at user provided speeds.
I would be interested to hear if these or other features would be a popular addition to the Servo library. No promises that suggestions will be quickly implemented but if a number if people want enhancements that fit within the spirit of the current library then it could be considered for a future release.

see: http://arduino.cc/forum/index.php/topic,61586.0.html
and: http://arduino.cc/forum/index.php/topic,68305.msg504226.html
50  Using Arduino / Networking, Protocols, and Devices / Re: I2C buffer limit on: August 04, 2011, 11:57:44 am
The second one is in twi.h   

the buffers are defined in twi.c
51  Using Arduino / Programming Questions / Re: Stalker V2 Help!! Set the time? RFID Logger on: August 04, 2011, 11:50:34 am
sure, try this:
Code:
#include <RTC.h>
#include <Time.h>
#include <Wire.h>
 
void setup() {
 
  Serial.begin(9600);
  if (RTC.begin()) {
     Serial.println("Valid RTC device initialised");
     setSyncProvider(RTCget);  // register the get function
  }
  else {
    Serial.println("Problem initialising RTC"); 
  }

 
 
}
 
void loop() {
}
52  Using Arduino / Motors, Mechanics, and Power / Re: Help with 19 servos and Mega on: August 04, 2011, 10:17:15 am
Chris,

You can use any of the outputs, including any of the unused PWM or analog input pins.
53  Using Arduino / Microcontrollers / Re: Boards file for 3.3v 12mhz atmega328p? on: August 04, 2011, 09:56:00 am
Thanks for the replies so far smiley Bummer though, thought it would be easier. For now I am just running it at 5v at 16mhz to maintain my speed. I don't know how to rewrite the bootloader if I want to give this a go some other time, do you guys know any write ups or places to begin if I want to get going at it?

Unless you are looking forward to tinkering with non-standard bootloaders and software that is not properly handling CPU speed, you may be better of sticking with 8MHz and looking to make your application efficient enough to run at that speed. What is it that you want to do that 8MHz can’t cope  with?
54  Using Arduino / Sensors / Re: Simultaneous pulse counter inputs on: August 04, 2011, 07:56:02 am
You can use a combination of hardware (Interrupts) and software counting for your project.
Arduino provides two versatile interrupt handlers but you can detect pin pulses on more pins with the right software
Have a look at the library here: http://www.arduino.cc/playground/Main/PinChangeInt

i have not used it but the examples seem to provide a good basis for detecting and counting pulses on three pins

Have fun
55  Using Arduino / Motors, Mechanics, and Power / Re: VarSpeedServo - a modified Servo library with speed control on: August 04, 2011, 07:46:48 am
I am interested to know if adding variable speed sweep would be good enough for most applications?  Most of the additional RAM needed in VarSpeedServo is for the target position, but this is not needed if the sweep is between the min and max positions set in the attach method because only the speed and current direction need to be stored and these can be held in a single byte if the max speed is limited to 127.

Would something like that be useful or will most people want the capability to control speed when moving the servo to any given?
56  Using Arduino / Motors, Mechanics, and Power / Re: Help with 19 servos and Mega on: August 04, 2011, 07:33:31 am
Quote
Usually a servo library is used that provides for the PPM control signals that standard hobby servos use.

I agree, i understand PWM and servo’s. But I was wondering why vinceherman doesn’t use the PWM but the digital out for driving his servos.

Quote
You don't use PWM output.  That is for driving DC motors and LEDs.
Just grab the digital pins and attach the servos.

It would be nice to see some more code to achieve that.

Chris

The Arduino servo library uses hardware timers to control servo pulses to enable many more servos to be controlled than if the hardware PWM capability was used. The source code for the Servo library is in the Libraries > Servo directory of the arduino distribution.
57  Using Arduino / Motors, Mechanics, and Power / Re: VarSpeedServo - a modified Servo library with speed control on: August 04, 2011, 07:28:53 am
Hi Mem,

it's nice to know, that you like it. Whether to add it to the main Servo-library should be considered carefully. From my point of view, you're welcome to add the code or any modification from it. However, please consider a few things first:
  • The speed control adds more memory to the servo structure. It's just a few bytes, but in large setup with many servos, you should check if this causes problems
  • The speed parameter doesn't relate to any real time measure. It's just a number and you can set some speeds but others not. For many applications, like moving something at a pleasant speed to look at, this is good enough. If some specific speeds are necessary, the model I used might not offer enough granularity.
  • I didn't really check if the interaction of the position update and attach/detach works in a reasonable manner. What happens if one detaches the servo while on a slow move and then reattaches it?
  • The method-name slowMove is clumsy and not really in line with the rest of the rest of the methods
  • Some proper documentation and samples are also necessary.

In short, it was mostly a quick hack to get landing gears on model aircraft extend and retract at a more more realistic pace. Going by the general feedback, it seems to be of use for some applications. If you think part of my work is useful to be added to the main library, feel free to go ahead.

Korman

Hi Korman,

I agree with all your points. But this thread and the other one I linked below got me thinking about possibly adding a sweep function with user setable speed that I may be able to do using just one more byte of RAM per servo. I would be interested to hear if this is something that would be generally useful and will start a new thread to discuss this if enough people are interested.
58  Using Arduino / Programming Questions / Re: Stalker V2 Help!! Set the time? RFID Logger on: August 03, 2011, 11:41:45 pm
The Stalker 2 RTC is not compatible with the DS1307 so the RTC1307 code in the Time download wont work.

Here is an updated version that autodetects the RTC type.
Save the files as RTC.cpp and RTC.h. Its used in the sketch like the old library but the name is now RTC

Code:
/*
 * RTC.cpp - library for DS1307 and RX8025 RTC chips
 
  Copyright (c) Michael Margolis 2009, 2010
  This library is intended to be used with Arduino Time.h library functions

  The library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
   30 Dec 2009 - Initial release for DS1307
   20 Nov 2010 - renamed to RTC and Added support for DX8025
 */

#include <WProgram.h>
#include <Wire.h>
#include "RTC.h"

//#include <HardwareSerial.h>  //only needed for diagnostics

const uint8_t DS1307_ADDRESS = 0x68; 
const uint8_t RX8025_ADDRESS = 0x32;

const uint8_t RX8025_CTL1   = 0xE0;
const uint8_t RX8025_CTL2   = 0xf0;

const uint8_t RX8025_24HR_MODE    = 0x20;      // set bit 5 for 24 hr mode

const uint8_t RX8025_NO_INTR      = 0x0;       // interupts off, INTA hi-Z
const uint8_t RX8025_INTR_PER_SEC = 0x4;       // INTA occurs once per second
const uint8_t RX8025_INTR_PER_MIN = 0x5;       // INTA occurs once per minute
const uint8_t RX8025_INTR_PER_HR  = 0x6;       // INTA occurs once per hour
const uint8_t RX8025_INTR_PER_MON = 0x7;       // INTA occurs once per month

// PUBLIC FUNCTIONS   

time_t RTCget()  // static function that can be used as a callback
{
  RTC.get();
}

rtcClass::rtcClass()
{

}
 
// returns true if selection is valid or autodetect succeeds in finding a device
bool rtcClass::begin(RTCDevice_t selection)
{
   device =  rtcUnknown; // default to indicate that no device is selected
   Wire.begin();
   if( selection == rtcUnknown)
   {
      // discover RTC device
      if(isAddressValid( RX8025_ADDRESS))
        selection = rtcRX8025;   
      else if(isAddressValid( DS1307_ADDRESS))
        selection = rtcDS1307;             
   }
   
   if(selection == rtcDS1307)
   {
       address = DS1307_ADDRESS;
       device = rtcDS1307;
   }
   else if(selection == rtcRX8025)
   {
     address = RX8025_ADDRESS;       
     device = rtcRX8025;
     writeRegister(RX8025_CTL1,RX8025_24HR_MODE); // RX8025 defaults to 12 hr mode so change to 24hrs   
     writeRegister(RX8025_CTL2,0);                // reset power on reset flag in control register 2     
   }
   //Serial.print("device = "); Serial.println(device, DEC);
   //Serial.print("address = 0x"); Serial.println(address, HEX);
   return (device != rtcUnknown); // returns true if a valid device selected
   
}   

time_t rtcClass::get()   // Aquire data from RTC and convert to time_t
{
  tmElements_t tm;
  read(tm);
  return(makeTime(tm));
}

void  rtcClass::set(time_t t)  // set RTC to given time
{
  tmElements_t tm;
  breakTime(t, tm);
  tm.Second |= 0x80;  // stop the clock
  write(tm);
  tm.Second &= 0x7f;  // start the clock
  write(tm);
}

// Aquire data from the RTC chip in BCD format
void rtcClass::read( tmElements_t &tm)
{
  Wire.beginTransmission(address);
  Wire.send(0x00);
  Wire.endTransmission();

  // request the data fields   (secs, min, hr, dow, date, mth, yr)
  if( device == rtcRX8025)
  {
     Wire.requestFrom((int)address, 8);
     Wire.receive();  // RX8025 gets an extra byte that is ignored
  }
  else     
    Wire.requestFrom((int)address, tmNbrFields);
 
  tm.Second = bcd2dec(Wire.receive() & 0x7f);   
  tm.Minute = bcd2dec(Wire.receive() & 0x7f);  // mask added for RX8025
  tm.Hour   = bcd2dec(Wire.receive() & 0x3f);  // mask assumes 24hr clock
  tm.Wday   = bcd2dec(Wire.receive() & 0x07);  // mask added for RX8025
  tm.Day    = bcd2dec(Wire.receive() & 0x3f);  // mask added for RX8025
  tm.Month  = bcd2dec(Wire.receive() & 0x1f);  // mask added for RX8025
  tm.Year = y2kYearToTm((bcd2dec(Wire.receive())));
}

void rtcClass::write(tmElements_t &tm)
{
  Wire.beginTransmission((int)address);
  Wire.send(0x00); // reset register pointer
 
  Wire.send(dec2bcd(tm.Second)) ;   
  Wire.send(dec2bcd(tm.Minute));
  Wire.send(dec2bcd(tm.Hour));      // sets 24 hour format
  Wire.send(dec2bcd(tm.Wday));   
  Wire.send(dec2bcd(tm.Day));
  Wire.send(dec2bcd(tm.Month));
  Wire.send(dec2bcd(tmYearToY2k(tm.Year)));   

  Wire.endTransmission(); 
}

// this method sets the RX8025 periodic interrupt to the given period
// the INTA pin is set low at the selected interval if the interrupt is enabled
void rtcClass::setPeriodicInterrupt( RTCIntrInterval_t interval)
{
  if( device != rtcRX8025)
     return; // only allow this method if using RX8025
  switch(interval) {
     case rtcIntrDisable    : writeRegister(RX8025_CTL1, RX8025_24HR_MODE | RX8025_NO_INTR); break;
     case rtcIntrEachSecond : writeRegister(RX8025_CTL1, RX8025_24HR_MODE | RX8025_INTR_PER_SEC ); break;
     case rtcIntrEachMinute : writeRegister(RX8025_CTL1, RX8025_24HR_MODE | RX8025_INTR_PER_MIN ); break;
     case rtcIntrEachHour   : writeRegister(RX8025_CTL1, RX8025_24HR_MODE | RX8025_INTR_PER_HR ); break;
     case rtcIntrEachMonth  : writeRegister(RX8025_CTL1, RX8025_24HR_MODE | RX8025_INTR_PER_MON ); break;
   }
}

// this method sets the INTA pin high impedence ready for next interrupt
// call this after every interrupt
void rtcClass::resetPeriodicInterrupt( )
{
  if( device == rtcRX8025)
     writeRegister(RX8025_CTL2, 0); // clear the control2 register
}

// PRIVATE FUNCTIONS

/// returns true if there is an i2c device at the given address
bool rtcClass::isAddressValid(uint8_t address)
{
   Wire.beginTransmission(address);
   Wire.send(0x00);
   Wire.endTransmission();
   Wire.requestFrom((int)address,1);
   delay(10);
   if (Wire.available() > 0 )
   {
      Wire.receive();
      //Serial.print("check for addr "); Serial.print(address,HEX), Serial.println(" returned true");
      return true;
   }
   //Serial.print("check for addr "); Serial.print(address,HEX), Serial.println(" returned false");   
   return false;       
}       

// sets the given register to the given value
void rtcClass::writeRegister( uint8_t reg, uint8_t value)
{
  Wire.beginTransmission((int)address);
  Wire.send(reg);
  Wire.send(value);
  Wire.endTransmission(); 
}

// Convert Decimal to Binary Coded Decimal (BCD)
uint8_t rtcClass::dec2bcd(uint8_t num)
{
  return ((num/10 * 16) + (num % 10));
}

// Convert Binary Coded Decimal (BCD) to Decimal
uint8_t rtcClass::bcd2dec(uint8_t num)
{
  return ((num/16 * 10) + (num % 16));
}

rtcClass RTC = rtcClass(); // create an instance for the user

Code:
/*
 * RTC.h - library for DS1307 RTC
 * This library is intended to be uses with Arduino Time.h library functions
 */

#ifndef rtcClass_h
#define rtcClass_h
#include <Time.h>    // download from http://www.arduino.cc/playground/Code/Time

// the list of supported RTC devices
enum RTCDevice_t {rtcUnknown, rtcDS1307, rtcRX8025};

// the list of interrupt intervals supported by the RX8025
enum RTCIntrInterval_t {rtcIntrDisable, rtcIntrEachSecond, rtcIntrEachMinute,rtcIntrEachHour,rtcIntrEachMonth} ; 
 
extern time_t RTCget(); //  function that can be used as a sync provider callback 
 
// library interface description

class rtcClass
{
  // user-accessible "public" interface
  public:
    rtcClass();
bool begin(RTCDevice_t device = rtcUnknown);
     //getExternalTime get;   // pointer to the get time method
time_t get();
void set(time_t t);
void read(tmElements_t &tm);
void write(tmElements_t &tm);
void setPeriodicInterrupt( RTCIntrInterval_t interval); // RX8025 only, set the periodic interrupt
void resetPeriodicInterrupt();                         // call after each interrupt to reset the pin.       
     RTCDevice_t device;  // the active device
  private:
     uint8_t address;     
bool isAddressValid(uint8_t address);
uint8_t dec2bcd(uint8_t num);
     uint8_t bcd2dec(uint8_t num);
void writeRegister( uint8_t register, uint8_t value);
};

extern rtcClass RTC;

#endif
 

59  Using Arduino / Microcontrollers / Re: can arduino uno pass the limits of its voltage (more than 9v) on: August 03, 2011, 11:17:13 pm
It depends on how much current is drawn from the 5v regulated output. And this depends on what you have connected to the pins and connected to the 5V line.  The regulator (the chip right next to the barrel connector) will get hot if you draw too much current. If that chip feels very hot when you touch it with your finger then try using a lower voltage power supply.
60  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
file:///Applications/Arduino.app/Contents/Resources/Java/reference/Pow.html

this might be a better link: http://www.arduino.cc/en/Reference/Pow
Pages: 1 2 3 [4] 5 6 ... 416