Show Posts
Pages: [1]
1  Using Arduino / Motors, Mechanics, and Power / Re: 9-18V (up to 4A) DC motors + arduino on: March 28, 2013, 11:58:52 am
my bad...the stepper driver was just sitting on the breadboard, i used the one i provided link for....

as up now i was trying this code and wiring

(probably there is something wrong with the wiring, i was just trying to get voltage variation on the multimeter but no luck. if i set latchpin to 8, multimeter is at 0, if i use any other pin it  gets the power supply voltage

Code:
/************************************************************************************************************************************
 * ShiftPWM non-blocking RGB fades example, (c) Elco Jacobs, updated August 2012.
 *
 ************************************************************************************************************************************/

// You can choose the latch pin yourself.
const int ShiftPWM_latchPin=8;


// If your LED's turn on if the pin is low, set this to true, otherwise set it to false.
const bool ShiftPWM_invertOutputs = false;

const bool ShiftPWM_balanceLoad = false;

#include <ShiftPWM.h>   // include ShiftPWM.h after setting the pins!

unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 6;
int numOutputs = numRegisters*8;
int numRGBLeds = numRegisters*8/3;
int fadingMode = 0; //start with all LED's off.

unsigned long startTime = 0; // start time for the chosen fading mode

void setup()   {               
  Serial.begin(9600);

  // Sets the number of 8-bit registers that are used.
  ShiftPWM.SetAmountOfRegisters(numRegisters);

  // SetPinGrouping allows flexibility in LED setup.
  // If your LED's are connected like this: RRRRGGGGBBBBRRRRGGGGBBBB, use SetPinGrouping(4).
  ShiftPWM.SetPinGrouping(1); //This is the default, but I added here to demonstrate how to use the funtion
 
  ShiftPWM.Start(pwmFrequency,maxBrightness);
  printInstructions();
}



void loop()
{   
  if(Serial.available()){
    if(Serial.peek() == 'l'){
      // Print information about the interrupt frequency, duration and load on your program
      ShiftPWM.PrintInterruptLoad();
      Serial.flush();
    }
    else{
      fadingMode = Serial.parseInt(); // read a number from the serial port to set the mode
      Serial.print("Mode set to ");
      Serial.print(fadingMode);
      Serial.print(": ");
      startTime = millis();
      switch(fadingMode){
      case 0:
        Serial.println("All LED's off");
        break;
      case 1:
        Serial.println("Fade in and out one by one");
        break;
      case 2:
        Serial.println("Fade in and out all LED's");
        break;               
      default:
        Serial.println("Unknown mode!");
        break;
      }
    }
  }
  unsigned char brightness;
  switch(fadingMode){
  case 0:
    // Turn all LED's off.
    ShiftPWM.SetAll(0);
    break;
  case 1:
    oneByOne();
    break;
  case 2:
    inOutAll();
    break;
 
  default:
    Serial.println("Unknown Mode!");
    delay(1000);
    break;
  }
}

void oneByOne(void){ // Fade in and fade out all outputs one at a time
  unsigned char brightness;
  unsigned long fadeTime = 500;
  unsigned long loopTime = numOutputs*fadeTime*2;
  unsigned long time = millis()-startTime;
  unsigned long timer = time%loopTime;
  unsigned long currentStep = timer%(fadeTime*2);

  int activeLED = timer/(fadeTime*2);

  if(currentStep <= fadeTime ){
    brightness = currentStep*maxBrightness/fadeTime; ///fading in
  }
  else{
    brightness = maxBrightness-(currentStep-fadeTime)*maxBrightness/fadeTime; ///fading out;
  }
  ShiftPWM.SetAll(0);
  ShiftPWM.SetOne(activeLED, brightness);
}

void inOutTwoLeds(void){ // Fade in and out 2 outputs at a time
  unsigned long fadeTime = 500;
  unsigned long loopTime = numOutputs*fadeTime;
  unsigned long time = millis()-startTime;
  unsigned long timer = time%loopTime;
  unsigned long currentStep = timer%fadeTime;

  int activeLED = timer/fadeTime;
  unsigned char brightness = currentStep*maxBrightness/fadeTime;

  ShiftPWM.SetAll(0);
  ShiftPWM.SetOne((activeLED+1)%numOutputs,brightness);
  ShiftPWM.SetOne(activeLED,maxBrightness-brightness);
}

void inOutAll(void){  // Fade in all outputs
  unsigned char brightness;
  unsigned long fadeTime = 2000;
  unsigned long time = millis()-startTime;
  unsigned long currentStep = time%(fadeTime*2);

  if(currentStep <= fadeTime ){
    brightness = currentStep*maxBrightness/fadeTime; ///fading in
  }
  else{
    brightness = maxBrightness-(currentStep-fadeTime)*maxBrightness/fadeTime; ///fading out;
  }
  ShiftPWM.SetAll(brightness);
}

void alternatingColors(void){ // Alternate LED's in 6 different colors
  unsigned long holdTime = 2000;
  unsigned long time = millis()-startTime;
  unsigned long shift = (time/holdTime)%6;
  for(int led=0; led<numRGBLeds; led++){
    switch((led+shift)%6){
    case 0:
      ShiftPWM.SetRGB(led,255,0,0);    // red
      break;
    case 1:
      ShiftPWM.SetRGB(led,0,255,0);    // green
      break;
    case 2:
      ShiftPWM.SetRGB(led,0,0,255);    // blue
      break;
    case 3:
      ShiftPWM.SetRGB(led,255,128,0);  // orange
      break;
    case 4:
      ShiftPWM.SetRGB(led,0,255,255);  // turqoise
      break;
    case 5:
      ShiftPWM.SetRGB(led,255,0,255);  // purple
      break;
    }
  }
}

void hueShiftAll(){  // Hue shift all LED's
  unsigned long cycleTime = 10000;
  unsigned long time = millis()-startTime;
  unsigned long hue = (360*time/cycleTime)%360;
  ShiftPWM.SetAllHSV(hue, 255, 255);
}

void randomColors(){  // Update random LED to random color. Funky!
  unsigned long updateDelay = 100;
  static unsigned long previousUpdateTime;
  if(millis()-previousUpdateTime > updateDelay){
    previousUpdateTime = millis();
    ShiftPWM.SetHSV(random(numRGBLeds),random(360),255,255);
  }
}

void fakeVuMeter(void){ // immitate a VU meter
  static int peak = 0;
  static int prevPeak = 0;
  static int currentLevel = 0;
  static unsigned long fadeStartTime = startTime;

  unsigned char brightness;
  unsigned long fadeTime = (currentLevel*2);// go slower near the top

  unsigned long time = millis()-fadeStartTime;
  unsigned long currentStep = time%(fadeTime);

  if(currentLevel==peak){
    // get a new peak value
    prevPeak = peak;
    while(abs(peak-prevPeak)<5){
      peak =  random(numRGBLeds); // pick a new peak value that differs at least 5 from previous peak
    }
  }

  if(millis()-fadeStartTime > fadeTime){
    fadeStartTime = millis();
    if(currentLevel<peak){ //fading in
      currentLevel++;
    }
    else{ //fading out
      currentLevel--;
    }
  }
  // animate to new top
  for(int led=0;led<numRGBLeds;led++){
    if(led<currentLevel){
      int hue = (numRGBLeds-1-led)*120/numRGBLeds; // From green to red
      ShiftPWM.SetHSV(led,hue,255,255);
    }
    else if(led==currentLevel){
      int hue = (numRGBLeds-1-led)*120/numRGBLeds; // From green to red
      int value;
      if(currentLevel<peak){ //fading in       
        value = time*255/fadeTime;
      }
      else{ //fading out
        value = 255-time*255/fadeTime;
      }
      ShiftPWM.SetHSV(led,hue,255,value);       
    }
    else{
      ShiftPWM.SetRGB(led,0,0,0);
    }
  }
}

void rgbLedRainbow(unsigned long cycleTime, int rainbowWidth){
  // Displays a rainbow spread over a few LED's (numRGBLeds), which shifts in hue.
  // The rainbow can be wider then the real number of LED's.
  unsigned long time = millis()-startTime;
  unsigned long colorShift = (360*time/cycleTime)%360; // this color shift is like the hue slider in Photoshop.

  for(int led=0;led<numRGBLeds;led++){ // loop over all LED's
    int hue = ((led)*360/(rainbowWidth-1)+colorShift)%360; // Set hue from 0 to 360 from first to last led and shift the hue
    ShiftPWM.SetHSV(led, hue, 255, 255); // write the HSV values, with saturation and value at maximum
  }
}

void printInstructions(void){
  Serial.println("---- ShiftPWM Non-blocking fades demo ----");
  Serial.println("");
 
  Serial.println("Type 'l' to see the load of the ShiftPWM interrupt (the % of CPU time the AVR is busy with ShiftPWM)");
  Serial.println("");
  Serial.println("Type any of these numbers to set the demo to this mode:");
  Serial.println("  0. All LED's off");
  Serial.println("  1. Fade in and out one by one");
  Serial.println("  2. Fade in and out all LED's");
 
  Serial.println("");
  Serial.println("Type 'm' to see this info again"); 
  Serial.println("");
  Serial.println("----");
}

with this wiring...



2  Using Arduino / Motors, Mechanics, and Power / Re: 9-18V (up to 4A) DC motors + arduino on: March 28, 2013, 10:41:13 am
thanks again for the fast response

the indicated shield should suffice:
5A at up to 30V

My motors are indeed 9-18v, 24000rpm, 4.2A draw at maximum efficiency (guess it will never go that high with just propellers)


As for the code...I definitely couldn't get the shield to work with DC's so I tested with a stepper, since the documentation and example code provided uses a stepper...hope that clarifies it

Lastly...i only need it to spin in one direction!
3  Using Arduino / Motors, Mechanics, and Power / Re: 9-18V (up to 4A) DC motors + arduino on: March 28, 2013, 09:17:18 am
The sample code provided compiles fine, but not even following the datasheet wiring diagram for steppers produced any output which may or may not indicate a faulty shield

This was the code for steppers:
Code:
#include <ShiftStepper.h>

#define DATPIN    13 
#define SCLPIN    12
#define LATPIN    7
#define MRPIN     8 
#define INDPIN     2

// Set up the step sequence for a random motor...
static const uint8_t stepSequence[4] = {0x2, 0x4, 0x1, 0x8};
// Set up channel combinations for the motors...
static const uint8_t motChans0[__channelsPerMotor__] = {0,2,3,1};
static const uint8_t motChans1[__channelsPerMotor__] = {4,5,6,7};
static const uint8_t motChans2[__channelsPerMotor__] = {11,9,10,8};
static const uint8_t motChans3[__channelsPerMotor__] = {15,14,13,12};

// Declare some required globals

shiftChain *myChain = 0; // initializes so everyone can see it, but doesn't call the constructor
shiftStepMotor motor0(__channelsPerMotor__, stepSequence, motChans0);
shiftStepMotor motor1(__channelsPerMotor__, stepSequence, motChans1);
shiftStepMotor motor2(__channelsPerMotor__, stepSequence, motChans2);
shiftStepMotor motor3(__channelsPerMotor__, stepSequence, motChans3);
shiftDevice *motors[4] = {&motor0, &motor1, &motor2, &motor3};
shiftSixteen board0(4, motors);
shiftBoard *boards[1] = {&board0};
shiftChain storeChain(1, boards, DATPIN, SCLPIN, LATPIN, MRPIN, INDPIN);

/* ISR functions to shift it all out */

ISR (TIMER2_OVF_vect)
{
  myChain->doTick();
}

void setup (void)
{
  myChain = &storeChain;
  Serial.begin(57600);
  Serial.println("I live!");
  myChain->startTimer(__preScaler32__, 0, 2);
  Serial.println("Timer started");
  ((shiftStepMotor*)myChain->getBoard(0)->getDev(0))->doSteps(-1,1);  // set motor for continuous rotation
  ((shiftStepMotor*)myChain->getBoard(0)->getDev(1))->doSteps(-1,-1); // set motor for continuous rotation
  ((shiftStepMotor*)myChain->getBoard(0)->getDev(2))->doSteps(-1,1);  // set motor for continuous rotation
  ((shiftStepMotor*)myChain->getBoard(0)->getDev(3))->doSteps(-1,-1); // set motor for continuous rotation
}

void loop (void) {
  char in = 0;        // input character
  static int16_t speedSetting = 1;  // speed
  if (Serial.available() > 0) {
    in = Serial.read();
    switch (in) {
      case '+':
        speedSetting++;
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(0))->setSpeed(speedSetting);
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(1))->setSpeed(-speedSetting);
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(2))->setSpeed(speedSetting);
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(3))->setSpeed(-speedSetting);
        Serial.print("Speed setting: ");
        Serial.print(speedSetting, DEC);
        Serial.print(" Forward speed: ");
        Serial.print(((shiftStepMotor*)myChain->getBoard(0)->getDev(0))->getSpeed(), DEC);
        Serial.print(" Reverse speed: ");
        Serial.println(((shiftStepMotor*)myChain->getBoard(0)->getDev(1))->getSpeed(), DEC);
        break;
      case '-':
        speedSetting--;
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(0))->setSpeed(speedSetting);
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(1))->setSpeed(-speedSetting);
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(2))->setSpeed(speedSetting);
        ((shiftStepMotor*)myChain->getBoard(0)->getDev(3))->setSpeed(-speedSetting);
        Serial.print("Speed setting: ");
        Serial.print(speedSetting, DEC);
        Serial.print(" Forward speed: ");
        Serial.print(((shiftStepMotor*)myChain->getBoard(0)->getDev(0))->getSpeed(), DEC);
        Serial.print(" Reverse speed: ");
        Serial.println(((shiftStepMotor*)myChain->getBoard(0)->getDev(1))->getSpeed(), DEC);
        break;
    }
  }
  delay(10);
}

as per controlling the dc motors via arduino i was just suggested either using a dual chip h-bridge (which I am not sure i could get one that would allow the peak to go up to 4A or close to that value) or a transistor.

I have never worked with transistors but can anyone recommend one that would work for me? I did a bit of research and came across this one
http://www.fairchildsemi.com/ds/TI/TIP120.pdf

but might as well ask! thanks
4  Using Arduino / Motors, Mechanics, and Power / 9-18V (up to 4A) DC motors + arduino on: March 28, 2013, 08:45:22 am
Hi everyone

I am trying to help a couple students with a project that involves controlling some DC motors with propellers attached.

Initially we were going to use this
https://www.sparkfun.com/products/11352

But no luck in getting it to work.

Now, I do have a lab power supply and the effect we can get with pushbuttons would suffice. Would I be able to use a sensors instead to turn motors on an off? Putting it in another words...is there a way i can wire this up such that via software i can control if power is driven to the motors or not?

Thanks in advance.

5  Using Arduino / Sensors / Re: Arduino Duemilanove + Mega Sensor Shield V4 + PIR Body Sensor Movement on: October 04, 2011, 03:29:42 pm
yup it works, i guess it was just too sensitive!

thank you all for the help  smiley-cool
6  Using Arduino / Sensors / Re: Arduino Duemilanove + Mega Sensor Shield V4 + PIR Body Sensor Movement on: October 04, 2011, 12:40:44 pm
Thank you for letting me know ...it kind of makes sense that it wasn't working but this image made me believe this shield was for my arduino:



However, I'm trying to connect directly to the arduino but the outcome is the same....am I doing something wrong? i wanted to turn the led on/off by getting my hand in front of the sensor but do i need a separate code for that? is there any way to know if it's reading well?

HereĀ“s my setup:



Thank you so much
7  Using Arduino / Sensors / Re: Arduino Duemilanove + Mega Sensor Shield V4 + PIR Body Sensor Movement on: October 04, 2011, 04:50:30 am
that would be here: http://www.ebay.com/itm/Arduino-Mega-Sensor-Shield-V4-digital-analog-module-/190581394447?pt=LH_DefaultDomain_0&hash=item2c5f894c0f

I will try to connect it directly to the duemilanove...to check if it's working, serial monitor should do it?

Thank you for your help!
8  Using Arduino / Sensors / Arduino Duemilanove + Mega Sensor Shield V4 + PIR Body Sensor Movement on: October 04, 2011, 04:03:58 am
Hi everyone,

I'm fairly new to arduino and I ran it some problems...I was trying to make an LED turn on and off but I'm not successful, I couldn't find any documentation on this shield and I don't know how to check if the sensor is working properly....can anyone help me!? Do I need a separate code to check the status of the sensors or I just need to open the serial monitor? I couldn't find if any of the sensors I tried were working...

Here are the pics of my setup:













Thank you for any help you can give me!

Btw, this is the code I tried:

Code:
int ledPin = 13;
int switchPin = 2;
int value = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}
void loop() {
value = digitalRead(switchPin);
if (HIGH == value) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
Pages: [1]