Loading...
  Show Posts
Pages: 1 [2] 3 4 ... 116
16  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 10:46:30 am
Give this a try.
I can't test this, so if it does not work, play around with it and get it to work by learning from your mistakes.

Code:
#include <SoftwareSerial.h>
#define rxPin 5
#define txPin 6
// Sukuriamas naujas servo objektas
SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
int qualifier;
int dataByte;


void setup() 
{
  // Apra6omi tx, rx išėjimai:
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  //SoftwareSerial aprašymas
  Serial.begin(9600);
  mySerial.begin(9600);   // BT modulis
//====================================================
  //Setup Channel A
  pinMode(12, OUTPUT); //Initiates Motor Channel A pin
  pinMode(9, OUTPUT); //Initiates Brake Channel A pin

  //Setup Channel B
  pinMode(13, OUTPUT); //Initiates Motor Channel A pin
  pinMode(8, OUTPUT);  //Initiates Brake Channel A pin
 
}
void loop() // Vykdymas be pristabdymų
{
  if (Serial.available()) // from USB
    mySerial.write(Serial.read());
  if(mySerial.available()>1) // from Bluetooth
  {
    qualifier=mySerial.read();
    dataByte=mySerial.read();
 
    mySerial.print("qualifier = ");
    mySerial.println(qualifier);
    mySerial.print("dataByte = ");
    mySerial.println(dataByte);
 
    if ( qualifier == 68)
    {
      if (dataByte == 1)
      {
        forward();
      }
      if (dataByte == 2)
      {
        left();
      }
      if (dataByte == 3)
      {
        right();
      }
      if (dataByte == 4)
      {
        backward();
      }
      if (dataByte == 5)
      {
        stop();
      }
    }
  }
}
 
void stop(){
  digitalWrite(9, HIGH);  //Engage the Brake for Channel A
  digitalWrite(9, HIGH);  //Engage the Brake for Channel B
}
 
void forward(){
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed

  //Motor B backward @ half speed
  digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);    //Spins the motor on Channel B at half speed
 
}
 
void backward(){
  digitalWrite(12, LOW); //Establishes backward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed

  //Motor B backward @ half speed
  digitalWrite(13, LOW);  //Establishes backward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);    //Spins the motor on Channel B at half speed
 
}
 
void left(){
  digitalWrite(12, HIGH); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed

  //Motor B backward @ half speed
  digitalWrite(13, LOW);  //Establishes backward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);    //Spins the motor on Channel B at half speed
}
 
void right(){
  digitalWrite(12, LOW); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed

  //Motor B backward @ half speed
  digitalWrite(13, HIGH);  //Establishes backward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);    //Spins the motor on Channel B at half speed
}
17  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 10:15:14 am
Wow, your code is set to use SERVOS, not DC MOTORS, so why are you using the servo library??? (hard face palm)
18  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 10:01:33 am
ok, so what is that simple program? Post it.
19  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 09:44:15 am
Its in your link you provided, but upon looking at the actual picture of the board, it looks like you can use pins 2 and 3 for your servos.
20  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 09:36:06 am
Check your data sheet for what pins you can use. I get an Error when I try to check it, maybe you will have better luck than me.
21  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 09:15:49 am
You need to change
Quote
leftServo.attach(21);   
rightServo.attach(22);             
to whatever pins you have wired from the UNO to the motor controller.

Example: if you are using pins 5 and 6, then you need to change 21 => 5, and 22 => 6.
22  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 09:09:03 am
Pretty much. Thank holmes4 for pointing that out.
23  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 09:01:14 am
You have an UNO R3 so you only have 14 digital pins and 6 analog pins, so why are your servo set for pins 21 and 22?
24  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 08:49:45 am
You didn't mention you were using a motor shield, that's why I ask how everything was powered.

Also what is "a simple command engine management"
25  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 08:27:54 am
Quote
I use the battery is 9V. It is powered by two motors and bt module. Maybe I need more power?


9 Volt batteries are horrible for an Arduino project. Also please tell me you are not putting 9V directly into the BT module and servos, the Arduino is fine, it can handle 9V, but not the BT and servos.
26  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 08:07:10 am
First: For right now, get rid of everything, but if (mySerial.available())
    Serial.write(mySerial.read());
and see what do you get from the phone. You wont be able to do anything correctly, if you don't know what your getting.

Second:
Quote
if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
  if(mySerial.available()>1)
  {
This does NOT connect the BT module to the phone. This just checks to see if there is any data available to be read.
===================================================================================================

Quote
I fix some problem, BT connect to the smartphone. When i press "forward" i have receive data:
qualifier = 68
dataByte = 1
But robot dont go forward.

Ok great, now you have something to show. So now my question is how are the servos powered?
27  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 07:51:35 am
Quote
if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
  if(mySerial.available()>1)
  {

All you need is this,
Code:
if (Serial.available()) // from USB
    mySerial.write(Serial.read());
  if(mySerial.available()>1) // from Bluetooth
  {
28  Using Arduino / Programming Questions / Re: Size of array on: June 13, 2013, 07:48:48 am
"up + 1" will give you what you are looking for without any other functions needed.
29  Using Arduino / Programming Questions / Re: Need very fast help!!!!! on: June 13, 2013, 07:47:23 am
Quote
But not responding to commands
I understand that, that's why I asked what are you sending from the android and what are you receiving? I'm assuming you have an android phone, am I correct, or is it an IPhone?
30  Using Arduino / Project Guidance / Re: Keypad not working on standalone Arduino on: June 13, 2013, 07:27:48 am
Quote
When I built a standalone version of the same on a PCB, its not working any more.

What did you build, a keypad or an Arduino mega?
Pages: 1 [2] 3 4 ... 116