Show Posts
Pages: 1 2 [3] 4 5 ... 196
31  Using Arduino / Project Guidance / Re: Keypad and LCD help on: April 08, 2014, 11:58:45 am
Yes it's possible but what are those variables supposed to do? And are you looking to keep them later in the sketch or every time you turn on the arduino?
32  Using Arduino / Programming Questions / Re: Question about Scroll Display Left on: April 08, 2014, 07:42:54 am
I modified it a little bit and add comments. I don't know exactly what your trying to do, but if you want two rows to shift at the same time (or different times) in opposite directions, then this is what you need.

Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define N_CHARS  ((sizeof(MessageOut)/sizeof(MessageOut[0]))-1)
#define N_CHARS2  ((sizeof(MessageOut2)/sizeof(MessageOut2[0]))-1)

LiquidCrystal_I2C lcd(0x20,20,4);  // set the LCD address to 0x20 for a 16 chars and 2 line display

char MessageOut[21];
char MessageOut2[21];
 
int index = 19, index2 = 0;
unsigned long oldTime = 0, oldTime2 = 0;

void setup()
{
  lcd.init(); // initialize the lcd 
  lcd.backlight();
}

void loop()
{
  setHeadingRight("Hello", 0, 1000); // message, row, duration (1 second)
  setHeadingLeft("Welcome", 1, 500); // message, row, duration (half second)
}

void setHeadingRight(char * msg, byte row, unsigned long duration)
{
  strncpy(MessageOut, msg, sizeof(MessageOut));
  if(millis() - oldTime > duration) // check the difference of the current time "millis()" to the previous time "oldTime" against the duration you want.
  {
    oldTime = millis(); // update oldTime with the current time
    if(index >= 0) // make sure the index does not go under 0
    {
      index--; // decrecment index by 1
      for (int i = 0; i < N_CHARS; i++) // this part here displays the message on the display
      {
        lcd.setCursor(i,row); // set the column to show the element in the array
        if(index == N_CHARS) index = 0; // set index back to 0 if the index has reached the arrays max size.
       
        if(MessageOut[index++] != NULL) // if the element @ index is anything but NULL, show it.
          lcd.print(MessageOut[index-1]);
        else
          lcd.print(' '); // if the element @ index is NULL, display a space. 
      }
    }
    else index = 19; // if index is less than 0, then set it back to 19
  }
}

void setHeadingLeft(char * msg, byte row, unsigned long duration2)
{
  strncpy(MessageOut2, msg, sizeof(MessageOut2));
  if(millis() - oldTime2 > duration2)
  {
    oldTime2 = millis();
    if(index2 < 20) // check to see if index2 is under the array max size
    {
      index2++; // increment index
      for (int i = 0; i < N_CHARS2; i++) // same as above
      {
        lcd.setCursor(i,row);
        if(index2 == N_CHARS2) index2 = 0;
       
        if(MessageOut2[index2++] != NULL)
          lcd.print(MessageOut2[index2-1]);
        else
          lcd.print(' ');
      }
    }
    else index2 = 0; // otherwise set it back to 0
  }
}

33  Using Arduino / Project Guidance / Re: Keypad and LCD help on: April 07, 2014, 07:28:05 pm
You need to post your full code.
34  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 07, 2014, 05:00:25 pm
Check out this sketch I made for my robot.

Code:
#include <PS2X_lib.h>  //for v1.6

PS2X ps2x; // create PS2 Controller Class

int error = 0;
byte type = 0;
byte vibrate = 0;

byte speed1 =128, speed2 = 128;

byte M1L = 5;// PWM
byte M1R = 3;// PWM
byte M2L = 6;// PWM
byte M2R = 9;// PWM

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

  //**************PAY ATTENTION*************
  pinMode(M1L, OUTPUT);                                // Establishes LEDPin as an output so the LED can be seen
  pinMode(M1R, OUTPUT);
  pinMode(M2L, OUTPUT);                                // Establishes LEDPin as an output so the LED can be seen
  pinMode(M2R, OUTPUT);
  error = ps2x.config_gamepad(13,11,10,12, true, true);   //setup pins and settings:  GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error

  if(error == 0)
    Serial.println("Controller found! You may now send commands");

  else if(error == 1)
    Serial.println("No controller found, check wiring, see readme.txt to enable debug. visit www.billporter.info for troubleshooting tips");

  else if(error == 2)
    Serial.println("Controller found but not accepting commands. see readme.txt to enable debug. Visit www.billporter.info for troubleshooting tips");

  else if(error == 3)
    Serial.println("Controller refusing to enter Pressures mode, may not support it. ");

  type = ps2x.readType();
  switch(type)
  {
  case 0:
    Serial.println("Unknown Controller type");
    break;
  case 1:
    Serial.println("DualShock Controller Found");
    break;
  }
}

void loop()
{
  if(error == 1) //skip loop if no controller found
    return;
   
  else  //DualShock Controller
  {
    ps2x.read_gamepad(false, vibrate);          //read controller and set large motor to spin at 'vibrate' speed

    if(ps2x.Button(PSB_L1))//open claw manual
    {
      // rotate turret left
    }
    else if(ps2x.Button(PSB_R1))//close claw manual
    {
      // rotate turret right
    }
    else
    {
      // do nothing
    }

    // My sketch is designed to use both joysticks, Left joystick controls the left motor and right joystick does the right motor.
   // I can condense these two into just one IF / ELSE IF / ELSE statement, but here I separated them to show how one joystick controls its motor.
    if(ps2x.Analog(PSS_LY) >= 136 && ps2x.Analog(PSS_LY) <= 255)//real center value is 128, but 140 is needed because controller is HIGHLY sensitive
    {
      speed1 = map(ps2x.Analog(PSS_LY),136 , 255, 0 , 255);
      analogWrite(M1L, speed1);
      digitalWrite(M1R, LOW);
    }
    else if(ps2x.Analog(PSS_LY) >= 0 && ps2x.Analog(PSS_LY) <= 120) //Same as above
    {
      speed1 = map(ps2x.Analog(PSS_LY),0 ,120 , 255 , 0);// create a set range for values and set output values respectively
      digitalWrite(M1L, LOW);
      analogWrite(M1R, speed1);
    } 
    else {
      digitalWrite(M1L, LOW);// all off
      digitalWrite(M1R, LOW);
    }
    //--------------------Right side motor-----------------------   
    if(ps2x.Analog(PSS_RY) >= 136 && ps2x.Analog(PSS_RY) <= 255)
    {
      speed2 = map(ps2x.Analog(PSS_RY),136 , 255, 0 , 255);
      analogWrite(M2L, speed2);
      digitalWrite(M2R, LOW);
    }

    else if(ps2x.Analog(PSS_RY) >= 0 && ps2x.Analog(PSS_RY) <= 120)
    {
      speed2 = map(ps2x.Analog(PSS_RY),0 ,120 , 255 , 0);
      digitalWrite(M2L, LOW);
      analogWrite(M2R, speed2);
    }

    else
    {
      digitalWrite(M2L, LOW);
      digitalWrite(M2R, LOW);
    } 
  }
  delay(50); // not needed, but give the robot some time to finish inputted commands   
}

35  Using Arduino / Project Guidance / Re: Speed Calculator Project Help on: April 06, 2014, 07:00:11 pm
Are you reffing to something like this?

Edit: Added more comments.
Code:
#define FPS_to_MPH 0.68182 // scale factor
#define DISTANCE 35.5625 // distance between the two sensors.

const byte SensorOnePin = 2;
const byte SensorTwoPin = 3;

byte SensorOneState;
byte SensorTwoState;
float Speed = 0, MPH = 0, tmp = 0;
boolean GotSecondSensor = false;
unsigned long SensorOne_timer = 0, SensorTwo_timer = 0;

void setup()
{
  Serial.begin(115200);
  pinMode(SensorOnePin, INPUT);
  pinMode(SensorTwoPin, INPUT);
}

void loop()
{
  // This is using normal buttons to detect car passing through one gate to another,
  // this can be changed to use US sensors to replace the buttons. That part you will 
  // need to write yourself.
 
  SensorOneState = digitalRead(SensorOnePin);
  SensorTwoState = digitalRead(SensorTwoPin);

  if(SensorOneState && GotSecondSensor == false)  // car drives through first gate "sensor"
  {
    SensorOne_timer = millis(); // record time
    GotSecondSensor = true; // lockout this IF statement and unlock the next IF statement
  }
 
  if(SensorTwoState && GotSecondSensor == true)
  {
    SensorTwo_timer = millis(); //record the time the car reaches the second gate
    Speed = GetSpeed(SensorOne_timer, SensorTwo_timer, DISTANCE); // send the times and the distance into the function.
    Serial.print("MPH: ");
    Serial.println(Speed);
    GotSecondSensor = false; // unlock first IF statement and lockout this IF statement.
  }
 
}

float GetSpeed(unsigned long T1, unsigned long T2, float distance)
{
  MPH = distance * (FPS_to_MPH); // "(FPS_to_MPH)" -> conversion factor, feet per second to miles per hour
  tmp = (T2 - T1)/1000.00; // since the time we are using is in milliseconds, we need to convert milliseconds to seconds
  Serial.print("Time (seconds): ");
  Serial.println(tmp);
  return (MPH / tmp); //return the speed of the car in MPH
}
36  Using Arduino / Project Guidance / Re: which input I turn my components? on: April 06, 2014, 05:08:17 pm
Quote
1 -) what type of Arduino is right for me? I've been researching the Mega 2560, Arduino UNO REV3 and MINI models.
ps: I need to put the arduino with these components on a boat, takes up less space as possible inside the boat, then if the arduino MIni work, it will be even better.

2 -) which and how many entries I'll use in Arduino (how many analog inputs and PWM inputs are necessary for each component)

All of this is on your end, you need to do the research. Go through each component and see what each one needs to work. Count  up the number of pins each one uses and then see what board is right for your needs. You need it to be small so your options are the Nano, Micro and Minis or you can make your own arduino from scratch with Bare Bones Arduinos.

Added: since its going to go into a boat, your going to want water proof casing or some way to prevent water from entering. Look into water proof servos too.
37  Using Arduino / Programming Questions / Re: Searching for info regarding the PS2X Library on: April 06, 2014, 04:28:50 pm
Did you try the example that came with the library? If you downloaded the PSX2 library from the arduino playground then you need to go into the PSX2.h file and change WProgram.h to Arduino.h and save it. This will allow the library to compile and you can start with the example sketch it came with. The sketch shows you how to read the buttons and analog sticks.

I use the library myself, so I can help you get started.
38  Using Arduino / Project Guidance / Re: What is this?? on: April 05, 2014, 09:40:40 pm
Quote
Would a servo be considered a digital version of a stepper which is analogue?

Kinda. a servo has a potentiometer inside which is able to keep track of where it is and also allows the user to tell it to stop at a certain degree. A stepper can do the same but it requires some math to figure out how many steps it takes and then convert that to a degree. Not all steppers are the same, some take bigger / smaller steps then others.

Also a big difference is what happens when you move a stepper. If you don't have anyway to keep track of its location(angle), it's going to get lost and it wont be able to correct itself. Whereas a servo being that it already has a way tracking its location, it can return back to a certain degree if it is ever moved.

Steppers allow for torque, but are not good at keeping track of where they are, and likewise for servos.
39  Using Arduino / Programming Questions / Re: Using TFT button for dual purposes on: April 05, 2014, 03:28:05 am
Your welcome.  smiley
40  Using Arduino / Project Guidance / Re: Robotic arm from scratch on: April 05, 2014, 03:14:51 am
?
Quote
omega
The Arduino Mega or your power supply? The arduino does have a built in regulator both 5V and 3.3V but the current is tiny, only about 200 mA and 40 mA on the digital pins. Your power supply may have a regulator too, I don't know.
41  Using Arduino / Project Guidance / Re: What is this?? on: April 05, 2014, 02:58:19 am
That small board is a stepper motor, driver, but 2 regular DC motors will work too.
42  Using Arduino / Project Guidance / Re: Robotic arm from scratch on: April 05, 2014, 02:41:27 am
The servos need 6 volts to work properly so you may need a voltage regulator to bring down the voltage.
43  Using Arduino / Project Guidance / Re: Robotic arm from scratch on: April 05, 2014, 02:16:55 am
Well you would need some good torque motors, that is if you don't want to use servos. Or you could also use hydraulic pistons to move the arm.

Servos are good to start with, especially with a kit but for better stronger applications worm gears and hydraulics are the way to go.
One other thing, servos can not run off the 5 volts from the arduino, so you will need an external power supply that can output about 6 volts and decent current ~1 - 2 amps.
44  Using Arduino / Displays / Re: 16x2 LCD nearly works - but has a few strange characters. Why??? on: April 05, 2014, 02:07:06 am
It's possible your screen is getting the ASCII codes for the carriage return and new line. When you see what is printed on the serial monitor see if they are 10 & 13.
45  Using Arduino / Project Guidance / Re: Robotic arm from scratch on: April 05, 2014, 01:58:24 am
If you want your arm to be strong, then use metal worm gears. What is the arm going to be made from and how big will it be?
Pages: 1 2 [3] 4 5 ... 196