Show Posts
Pages: [1] 2 3 4
1  Using Arduino / Programming Questions / Self Modifying Code on: June 18, 2013, 10:50:57 pm
Would it be possible to program an arduino to modify its own code, after its been uploaded?
2  Using Arduino / Programming Questions / Re: 3 Servo With 6 Button Control on: February 23, 2013, 12:02:30 am
Correction (still doens't work though):

Code:
#include <Servo.h>
 
Servo myservo2;
Servo myservo5;
Servo myservo9;

#define leftPin 1
#define rightPin 0
#define lefttPin 4
#define righttPin 3
#define leftttPin 7
#define rightttPin 6
3  Using Arduino / Programming Questions / Re: 3 Servo With 6 Button Control on: February 22, 2013, 11:58:38 pm
Why do all of my servos move at the same time when i press a button?!?

Code:
#include <Servo.h>
 
Servo myservo2;
Servo myservo5;
Servo myservo9;

#define leftPin 0
#define rightPin 1
#define lefttPin 4
#define righttPin 3
#define leftttPin 7
#define rightttPin 6

int pos = 90;
int delayPeriod = 9;  // increasing this slows down the servo movement

void setup()
{
  myservo2.attach(2);  // attaches the servo on pin 2 to the servo object
  myservo2.write(pos); // center the servo
  pinMode(leftPin, HIGH);   // turn on pullup resistors
  pinMode(rightPin, HIGH);
  myservo5.attach(5);  // attaches the servo on pin 5  to the servo object
  myservo5.write(pos); // center the servo
  pinMode(lefttPin, HIGH);   // turn on pullup resistors
  pinMode(righttPin, HIGH);
  myservo9.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo9.write(pos); // center the servo
  pinMode(leftttPin, HIGH);   // turn on pullup resistors
  pinMode(rightttPin, HIGH);
}
void loop()
{
  if(digitalRead(leftPin) == LOW) 
  {                             
   // in steps of 1 degree
   if( pos > 0)
      --pos;
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);                     
  }
  if(digitalRead(rightPin) == LOW) 
  {                             
   if( pos < 180)
       ++pos;
    myservo2.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);       
  }if(digitalRead(lefttPin) == LOW) 
  {                             
   // in steps of 1 degree
   if( pos > 0)
      --pos;
    myservo5.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);                     
  }
  if(digitalRead(righttPin) == LOW) 
  {                             
   if( pos < 180)
       ++pos;
    myservo5.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);       
  }if(digitalRead(leftttPin) == LOW) 
  {                             
   // in steps of 1 degree
   if( pos > 0)
      --pos;
    myservo9.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);                     
  }
  if(digitalRead(rightttPin) == LOW) 
  {                             
   if( pos < 180)
       ++pos;
    myservo9.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);       
  }
}/code]
4  Using Arduino / Programming Questions / Re: 3 Servo With 6 Button Control on: February 22, 2013, 11:37:29 pm
This code works with one servo and 2 buttons. Can someone edit it so I can use 3 servos and 6 buttons. I don't know how to do that!
5  Using Arduino / Programming Questions / 3 Servo With 6 Button Control on: February 22, 2013, 11:06:15 pm
I have code to have two buttons control a single servo. I need to do this using 3 servos and 6 buttons! Please help! Can someone edit this and make it so i I can do this for 3 servos?!?! Please help!

Code:
#include <Servo.h>
 
Servo myservo;

#define leftPin 1
#define rightPin 2

int pos = 90;
int delayPeriod = 9;  // increasing this slows down the servo movement

 
 
void setup()
{
  myservo.attach(2);  // attaches the servo on pin 9 to the servo object
  myservo.write(pos); // center the servo
  pinMode(leftPin, HIGH);   // turn on pullup resistors
  pinMode(rightPin, HIGH);
}
 
 
void loop()
{
  if(digitalRead(leftPin) == LOW) 
  {                             
   // in steps of 1 degree
   if( pos > 0)
      --pos;
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);                     
  }
  if(digitalRead(rightPin) == LOW) 
  {                             
   if( pos < 180)
       ++pos;
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(delayPeriod);       
  }
}
6  Using Arduino / Programming Questions / Re: Urgent! Bluetooth help! on: February 18, 2013, 03:49:46 pm
Yeah, thats my alternative plan.
7  Using Arduino / Programming Questions / Re: Urgent! Bluetooth help! on: February 18, 2013, 03:16:59 pm
I search the internet but can't find a wireless device that does the job. Can you guys offer and links?
8  Using Arduino / Programming Questions / Urgent! Bluetooth help! on: February 18, 2013, 02:02:06 am
My friend has a grandmother who is currently in bad shape. He asked me for some help and I plan on doing so. He needs a device that he can give to both his grandmother and grandfather so they can communicate to each other. His grandfather can't hear her shouts. I want to make two devices which use bluetooth to communicate to one another and that are simple to operate. This is all it needs to do. On one arduino will be a single button, when pressed will send a signal to the other arduino which will immediatly flash leds and vibrate. Can someone please make the code to make this work. I can read simple code, but when it comes to programming bluetooth I have no idea what I'm doing. Please help! Thank you so much for understanding!
9  Using Arduino / Project Guidance / Re: Siri on Arduino Uno on: December 08, 2012, 03:42:40 pm
I think I got what I was looking for. Does anyone have some good links to some Arduino speech projects? Thanks everyone!
10  Using Arduino / Project Guidance / Re: Siri on Arduino Uno on: December 08, 2012, 03:37:03 pm
I'll make a database that will translate data into a question that it will then find the correct answer to. That answer will be sent back to the arduino to be transmitted out a speaker.
11  Using Arduino / Project Guidance / Re: Siri on Arduino Uno on: December 08, 2012, 03:29:18 pm
How about I get it to pick up what the person says and send that data directly to the database. The database will translate the data into words and then send back the requested info.
12  Using Arduino / Project Guidance / Re: Siri on Arduino Uno on: December 08, 2012, 03:11:31 pm
suggestions?
13  Using Arduino / Project Guidance / Re: Siri on Arduino Uno on: December 08, 2012, 03:07:00 pm
Well, the arduino will pick up what the person said, then translate that into text and then entering the text into a database of which will have premade responses. The database will be external and to connect to it a wifi sheild would be required.
14  Using Arduino / Project Guidance / Siri on Arduino Uno on: December 08, 2012, 02:23:18 pm
I want to start a project where I make my own kind of siri that I can ask questions to and get a response from. The Arduino would be connected to a wifi shield to get the results and I would use a speaker to relay the info it found. Any suggestions on where I should start. Links are VERY much appreciated! Thanks.
15  Using Arduino / Programming Questions / Nunchuck Servo Problem on: November 22, 2012, 05:01:41 pm
I copy and pasted this exat code, but I keep getting errors. I tried fixing them but there are a few I have no idea how to fix. I am not using an led. My servo is plugged into pin 9. Which pins should my data go in? 2 and 3? Thanks for the help.

Code:
/*
 * NunchuckServo
 *
 * 2007 Tod E. Kurt, http://todbot.com/blog/
 *
 * The Wii Nunchuck reading code is taken from Windmeadow Labs
 *   http://www.windmeadow.com/node/42
 */

#include <Wire.h>

int ledPin = 13;
int servoPin = 7;      // Control pin for servo motor

int pulseWidth = 0;    // Amount to pulse the servo
int refreshTime = 20;  // the time in millisecs needed in between pulses
long lastPulse;
int minPulse = 700;   // minimum pulse width
int loop_cnt=0;

void setup()
{
  Serial.begin(19200);
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
  pulseWidth = minPulse;      // Set the motor position to the minimum

  nunchuck_setpowerpins(); // use analog pins 2&3 as fake gnd & pwr
  nunchuck_init(); // send the initilization handshake
  Serial.print("NunchuckServo ready\n");
}

void loop()
{
  checkNunchuck();
  updateServo();   // update servo position

  if( nunchuck_zbutton() )      // light the LED if z button is pressed
    digitalWrite(ledPin, HIGH);
  else
    digitalWrite(ledPin,LOW);

  delay(1);        // this is hear to give a known time per loop
}


void checkNunchuck()
{
  if( loop_cnt > 100 ) {  // loop()s is every 1msec, this is every 100msec
   
    nunchuck_get_data();
    nunchuck_print_data();

    float tilt = nunchuck_accelx();    // x-axis, in this case ranges from ~70 - ~185
    tilt = (tilt - 70) * 1.5;        // convert to angle in degrees, roughly 
    pulseWidth = (tilt * 9) + minPulse; // convert angle to microseconds
   
    loop_cnt = 0;  // reset for
  }
  loop_cnt++;
 
}

// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo()
{
  // pulse the servo again if rhe refresh time (20 ms) have passed:
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(servoPin, HIGH);   // Turn the motor on
    delayMicroseconds(pulseWidth);  // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW);    // Turn the motor off
    lastPulse = millis();           // save the time of the last pulse
  }
}


//
// Nunchuck functions
//

static uint8_t nunchuck_buf[6];   // array to store nunchuck data,

// Uses port C (analog in) pins as power & ground for Nunchuck
static void nunchuck_setpowerpins()
{
#define pwrpin PORTC3
#define gndpin PORTC2
    DDRC |= _BV(pwrpin) | _BV(gndpin);
    PORTC &=~ _BV(gndpin);
    PORTC |=  _BV(pwrpin);
    delay(100);  // wait for things to stabilize       
}

// initialize the I2C system, join the I2C bus,
// and tell the nunchuck we're talking to it
void nunchuck_init()
{
  Wire.begin();                 // join i2c bus as master
  Wire.beginTransmission(0x52); // transmit to device 0x52
  Wire.send(0x40); // sends memory address
  Wire.send(0x00); // sends sent a zero. 
  Wire.endTransmission(); // stop transmitting
}

// Send a request for data to the nunchuck
// was "send_zero()"
void nunchuck_send_request()
{
  Wire.beginTransmission(0x52); // transmit to device 0x52
  Wire.send(0x00); // sends one byte
  Wire.endTransmission(); // stop transmitting
}

// Receive data back from the nunchuck,
// returns 1 on successful read. returns 0 on failure
int nunchuck_get_data()
{
  int cnt=0;
  Wire.requestFrom (0x52, 6); // request data from nunchuck
  while (Wire.available ()) {
    // receive byte as an integer
    nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.receive());
    cnt++;
  }
  nunchuck_send_request();  // send request for next data payload
  // If we recieved the 6 bytes, then go print them
  if (cnt >= 5) {
    return 1;   // success
  }
  return 0; //failure
}

// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits.  That is why I
// multiply them by 2 * 2
void nunchuck_print_data()
{
  static int i=0;
  int joy_x_axis = nunchuck_buf[0];
  int joy_y_axis = nunchuck_buf[1];
  int accel_x_axis = nunchuck_buf[2]; // * 2 * 2;
  int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
  int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;

  int z_button = 0;
  int c_button = 0;

  // byte nunchuck_buf[5] contains bits for z and c buttons
  // it also contains the least significant bits for the accelerometer data
  // so we have to check each bit of byte outbuf[5]
  if ((nunchuck_buf[5] >> 0) & 1)
    z_button = 1;
  if ((nunchuck_buf[5] >> 1) & 1)
    c_button = 1;

  if ((nunchuck_buf[5] >> 2) & 1)
    accel_x_axis += 2;
  if ((nunchuck_buf[5] >> 3) & 1)
    accel_x_axis += 1;

  if ((nunchuck_buf[5] >> 4) & 1)
    accel_y_axis += 2;
  if ((nunchuck_buf[5] >> 5) & 1)
    accel_y_axis += 1;

  if ((nunchuck_buf[5] >> 6) & 1)
    accel_z_axis += 2;
  if ((nunchuck_buf[5] >> 7) & 1)
    accel_z_axis += 1;

  Serial.print(i,DEC);
  Serial.print("\t");

  Serial.print("joy:");
  Serial.print(joy_x_axis,DEC);
  Serial.print(",");
  Serial.print(joy_y_axis, DEC);
  Serial.print("  \t");

  Serial.print("acc:");
  Serial.print(accel_x_axis, DEC);
  Serial.print(",");
  Serial.print(accel_y_axis, DEC);
  Serial.print(",");
  Serial.print(accel_z_axis, DEC);
  Serial.print("\t");

  Serial.print("but:");
  Serial.print(z_button, DEC);
  Serial.print(",");
  Serial.print(c_button, DEC);

  Serial.print("\r\n");  // newline
  i++;
}

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char nunchuk_decode_byte (char x)
{
  x = (x ^ 0x17) + 0x17;
  return x;
}

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_zbutton()
{
   return ((nunchuck_buf[5] >> 0) & 1) ? 0 : 1;  // voodoo
}

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_cbutton()
{
   return ((nunchuck_buf[5] >> 1) & 1) ? 0 : 1;  // voodoo
}

// returns value of x-axis joystick
int nunchuck_joyx()
{
  return nunchuck_buf[0];
}

// returns value of y-axis joystick
int nunchuck_joyy()
{
  return nunchuck_buf[1];
}

// returns value of x-axis accelerometer
int nunchuck_accelx()
{
  return nunchuck_buf[2];   // FIXME: this leaves out 2-bits of the data
}

// returns value of y-axis accelerometer
int nunchuck_accely()
{
  return nunchuck_buf[3];   // FIXME: this leaves out 2-bits of the data
}

// returns value of z-axis accelerometer
int nunchuck_accelz()
{
  return nunchuck_buf[4];   // FIXME: this leaves out 2-bits of the data
}


Pages: [1] 2 3 4