Show Posts
Pages: 1 ... 8 9 [10] 11 12 ... 20
136  Using Arduino / Networking, Protocols, and Devices / Android Bluetooth joystick on: June 21, 2013, 02:17:30 am
Hi,

I developped an Android application that turns a smartphone into a virtual Bluetooth joystick.
The applications in the robotic field are endless: Home Automation, R/C cars, robotic arms and of course  balancing robots smiley-wink



By default, the device transmits data every 200ms
Data format: [STX  X  Y  ETX]  
example: [0X02  0X2A  0X30  0X03]

The application is available (for free smiley-cool) here
From you smartphone, access Google Store and search for "Joystick bluetooth Commander"

This demo Arduino sketch will parse data on the serial monitor, and control the pin13 LED
Code:
// AndroLED V5
// Arduino test sketch for Joystick BT commander
// LED control for buttons + joystick echo to serial monitor

// V5.0 removed SoftwareSerial

#define    DEBUG        false
#define    ledPin       13            // LED pin
#define    STX          0x02
#define    ETX          0x03

int i=0;
byte cmd[5] = {0, 0, 0, 0,0};

void setup()  {
  Serial.begin(9600);    //  ++ should match your specific BT board baud rate ++
  pinMode(ledPin, OUTPUT);
  Serial.println("Bluetooth Commander simulation");
}

void loop() {
  if(Serial.available())  {            // received from smartphone
    delay(5);
    cmd[0] =  Serial.read();  
    if(DEBUG)  Serial.println(cmd[0]);   // to serial monitor
    if(cmd[0] == STX)  {  
      i=1;      
      while(Serial.available() && ((cmd[i]=Serial.read()) != ETX)) {
        if(i>3)  break;
        if(DEBUG)    {Serial.print(i); Serial.print(": "); Serial.println(cmd[i]);}
        i++;
      }
    }
    if(i==2)    setLED(cmd[1]);
    if(i==3)    setJoystick();  
  }
  delay(5);
}

void setLED(int LEDstatus)  {
  switch (LEDstatus) {
    case '1':
      Serial.println("Button: ON");
      digitalWrite(ledPin, HIGH);
      break;
    case '2':
      Serial.println("Button: OFF");
      digitalWrite(ledPin, LOW);
      break;
  }
}

void setJoystick()    {
  Serial.print("Joystick data:  ");
  Serial.print(cmd[1]);  
  Serial.print(", ");  
  Serial.println(cmd[2]);
}




The Hardware setup is rather straightforward, should you need additional info, just let me know

Enjoy

Edit:
Updated Arduino sketch,
 set Baud rate to default 9600
 removed softserial
For sketch upload, don't forget to disconnect board TX from Arduino D0

Edit2:
** Joystick Bluetooth Commander Version 2.3 is now compatible with Android V3.X and V4.X (Honeycomb, Ice Cream Sandwich, Jelly Bean) **

Edit3:
added   Serial.println("Bluetooth Commander simulation") in setup() for communication testing purpose

Edit4:
Joystick Bluetooth Commander Version 2.4

Four toggle buttons with visual feedback

Change Log and Arduino sketch modification: please refer to reply #51

Edit5:
Joystick Bluetooth Commander Version 2.5


Change Log: refer to reply #70

Edit6:
 Joystick Bluetooth Commander Version 3.0

** major Upgrade **
Joystick Bluetooth Commander is now a full blown two way Bluetooth communication application
Arduino sends back a button status Byte and a user defined data Byte to be displayed on the phone/tablet screen (Bot battery level is a nice candidate)

Communication protocol has changed
Joystick data is now transmitted as an integer = 2 Bytes (Most Significant Byte + Less Significant Byte)
<STX  MSB-X  LSB-X  MSB-Y  LSB-Y  ETX>
Your V2.5 Arduino sketch needs to be modified for V3.0


See full change Log at reply #74
Updated demo Arduino sketch at reply #90

Edit7:
Fixed link to Balancing robot for dummies

Edit8:
New Arduino demo sketch (V10.1)
Improve decoding algorithm, see reply #98

Edit9:
Joystick Bluetooth Commander Version 3.1
Maintenance release, see reply #100

Edit10:
New Arduino demo sketch (V10.3)                     << for Artouste   smiley-wink
Bug fix, see reply #129

Edit11:
Joystick BT Plus  has been released with 6 buttons and 4 data bytes



The actual number of buttons and data fields is adjustable within the Option menu
Fields and buttons labels are fully customizable
See reply #165

Edit11:
Detailed info re Communication Protocol (send and receive)
See reply #154 & #156

Edit12:
Joystick BT Plus (6 buttons, 3 datafields)
and
Total RC Commander (video from IP camera)
are now available see reply #177
137  Using Arduino / Microcontrollers / Re: Question for Nick Gammon on: March 05, 2013, 01:33:53 pm
The chip is running 8Mhz from the internal clock

Based on your comments, I changed board for the LilyPad Arduino w/ ATmega328 (8MHz)
and all is well  smiley 

Thanks for your help
138  Using Arduino / Microcontrollers / Question for Nick Gammon on: March 05, 2013, 12:02:34 pm
Hi Nick,

I made a 328P-PU Arduino compatible minimal board based on your super tutorial
http://www.gammon.com.au/forum/?id=11637

I uploaded:
 - "board detector" sketch
 - bootloader programming sketch (8 MHz without a crystal)
Everything went well and I finally loaded up the basic Blink example

...
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(2000);               // wait for 2 seconds
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(2000);               // wait for 2 seconds
...

The LED turn ON for 4 seconds and OFF for 4 seconds
What am I doing wrong ??
Is it related to the 8 MHz clock ??

Thanks for your assistance
139  Using Arduino / Sensors / Re: MPU6050 SparkFun Breakout to Arduino Uno - No Communication on: July 30, 2012, 01:25:06 pm
Thanks,

Rechecked voltage: 3.32V   
go figure  smiley-roll-blue   I should add some water in my Bordeaux...

I will put additional resistors on SDA and SCL, on the Arduino side
I guess the original 10K's are OK when more sensors are added to the I2C Bus
140  Using Arduino / Sensors / Re: MPU6050 SparkFun Breakout to Arduino Uno - No Communication on: July 29, 2012, 02:23:45 pm
Answering partially my own questions
Not familiar with SMD  smiley-roll
The black components with 3 digits are actually resistors (http://www.hobby-hour.com/electronics/3-digit-smd-resistors.php)
331: 330 ohms
103: 10K
472: 4.7K

So, two 10K pull up resistors
Google is definitly your best friend  smiley-wink  smiley-wink

btw, this board can be had for 15 bucks shipped (Google ...)
141  Using Arduino / Sensors / Re: MPU6050 SparkFun Breakout to Arduino Uno - No Communication on: July 27, 2012, 12:04:45 pm
Hi Krodal,

Thanks for your very informative playground article
I bought a GY-52 breakout board which seems rather similar to yours (same manufacturer):



I connected as follow:
VCC - 5V
GND - GND
SCL - A5
SDA - A4

and loaded your code http://arduino.cc/playground/Main/MPU-6050
Amazingly enough, it worked first time

Now, I try to understand why it works  smiley-razz  smiley-razz
No additional pull up resistors on SDA/SCL
ADO seem to be pulled down (0X68)

Would you mind checking your onboard regulator output, mine is 4.3V with 5V or 3.3V supply
according to datasheet, seems a bit high
Please check the above photo for possible pullup resistors

My final project is a new/better Balancing Robot http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1284738418

Thanks again for this great job
142  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 16, 2011, 07:10:19 am
I am better at photo than video  smiley-wink
143  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 16, 2011, 01:33:28 am
..........   continued


       [size=14] ** Balancing robot for dummies **[/size]


[size=14]Part seven: Xbee wireless control, KasBot V 3.0[/size]



[size=14]2) Robot side:[/size]

On the bot side, the Xbee module is set as per post #107

The datastream is decoded within getMotion()
Code:
void getMotion() {
  if(!Serial.available())      return;
  delay(5);                  
  int controlByte = Serial.read();              // get control byte
  if(!Serial.available())      return;
  int dataByte_1 = Serial.read();               // get data byte 1
  if(!Serial.available())      return;
  int dataByte_2 = Serial.read();               // get data byte 2
  Serial.flush();                                
 
  if(controlByte == 'd')   {                    // Nunchuk joystick data
    setPoint = -(dataByte_1 - 20)/2;          // get forward/backward motion byte
    if(abs(setPoint) > 2)  {
      count = 0;
      last_count = 0;
    }
    turn = (dataByte_2 - 20);                   // get right/left motion byte
  }  else    bip(bipPin, 10, 1);                  // wrong header
}

setPoint is used to bias updatePid() and slithly move the bot from vertical, thus initiating the move

Code:
void loop() {
// ********************* Get Xbee data *******************************
  getMotion();

// ********************* Sensor aquisition & filtering ***************
.....

// *********************** Angle Control and motor drive *************
  drive = updatePid(setPoint, actAngle);                                // PID algorithm

  if(abs(actAngle) < 100)    {
    Drive_Motor(drive);
  }  else {  
    Drive_Motor(0);                                                    // stop motors if situation is hopeless
    setZeroIntegal();                                                  // reset PID Integral accumulaor
  }
// ********************* print Debug info ****************************
.....

// *********************** loop timing control ***********************
.....

}


turn becomes a new parameter in Drive_Motor(), to allow right and left motor to run at their own speed
Code:
int Drive_Motor(int torque)  {
  if (torque + turn >= 0)  {                                          // drive motors forward
    digitalWrite(InA_R, LOW);                        
    digitalWrite(InB_R, HIGH);
    torque_R = torque + turn;
    if (torque - turn >= 0)  {                                        // drive motors forward
      digitalWrite(InA_L, LOW);                    
      digitalWrite(InB_L, HIGH);
      torque_L = torque - turn;
    }  else  {
      digitalWrite(InA_L, HIGH);                      
      digitalWrite(InB_L, LOW);
      torque_L = abs(torque - turn);
    }
  }  else {                                                           // drive motors backward
    digitalWrite(InA_R, HIGH);                      
    digitalWrite(InB_R, LOW);
    torque_R = abs(torque + turn);
     if (torque - turn >= 0)  {                                       // drive motors forward
      digitalWrite(InA_L, LOW);                    
      digitalWrite(InB_L, HIGH);
      torque_L = torque - turn;
    }  else  {
      digitalWrite(InA_L, HIGH);                      
      digitalWrite(InB_L, LOW);
      torque_L = abs(torque - turn);
    }
 }
  torque_R = map(torque_R,0,255,K_map,255);
  torque_L = map(torque_L,0,255,K_map,255);
  torque_R = constrain(torque_R, 0, 255);
  torque_L = constrain(torque_L * motor_Offset, 0, 255);
  analogWrite(PWM_R,torque_R);
  analogWrite(PWM_L,torque_L * motor_Offset);                      // motors are not built equal...
}


OK guys, this is probably my last significant contribution to this thread  :-/
I suddently realize that I have a real life and... some other projects to explore  :smiley :smiley

I am sure this thread will keep on, with new bright ideas coming on
What about non linear control ??
What about one wheeled bot as shown by Big Oil ??

"...Two wheeled balancing robots are an area of research that may well provide the future locomotion for everyday robots..."

I really enjoyed all these discussions we had on this common project
Thanks again to everybody for reading and contributing   smiley smiley smiley

144  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 15, 2011, 06:12:19 am
       [size=14] ** Balancing robot for dummies **[/size]


[size=14]Part seven: Xbee wireless control, KasBot V 3.0[/size]

The objective is to obtain basic motion control (Forward/Backward, Stop Right/Left)
Xbee modules act as a serial line replacement, a USB cable without the cable smiley
See post #82 for more info


[size=14]1) controller side:[/size]

Shopping list at post #77
Transmitter with Nunchuck joystick controller is shown on post #107
The additional micro joystick and the 3 LED's will be used for advanced features wich are beyong the scope of this basic KasControl V1.0

Nunchuk_kas.h does take care of the I2C communication with the joystick
Code:
// Nunchuck_kas.h        joystick functions ----------------------------------------------------------------

#include "Wprogram.h"
#include <Wire.h>

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

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 a zero.  
  Wire.endTransmission();                                  // stop transmitting
}

void nunchuck_send_request()  {                             // Send a request for data to nunchuck
  Wire.beginTransmission(0x52);                                  // transmit to device 0x52
  Wire.send(0x00);                                        // sends one byte
  Wire.endTransmission();                                  // stop transmitting
}
 
char nunchuk_decode_byte (char x)  {                         // Encode data to format that most wiimote drivers
  x = (x ^ 0x17) + 0x17;                                     // except only needed if you use one of the regular
  return x;                                                  // wiimote drivers
}

int nunchuck_get_data()  {                                   // Receive data back from the nunchuck
  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 (cnt >= 5)     return 1;                               // If we recieved the 6 bytes, then go print them
  return 0;                                                 // failure
}                                                           // returns 1 on success read, returns 0 on failure

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

int nunchuck_joyy()  {                                     // returns value of y-axis joystick
  return nunchuck_buf[1];
}
This is a strip down version of the code that can be found in the Arduino Playground section.
We only use the joystick data, (we have enough accelerometers in this project  smiley-wink)
More info on wiring and code here

The main code uses a communication protocol based on 3 Bytes:
   controlByte = 'd'      (just says "hey, I am coming with new joystick data !!")
   dataByte_1 = value of y-axis joystick
   dataByte_2 = value of x-axis joystick

To reduce traffic, data is only sent when joystick is moved
Code:
// ** Kas Control V10     Balancing bot RC with nunchuk **  

// Yellow: Clock SCL (AI5)  Red: 3.3V  Green: Data SDA(AI4)  Write: Ground
// serial data format:   <controlByte> <dataByte_1> <dataByte_2> <CR>
// V1.0 basic control

#include <Wire.h>
#include "Nunchuck_kas.h"

int refreshTime = 100;                                    // time in millisecs between Nunchuck poolings
long lastPulse = 0;
char controlByte = 0;
char dataByte_1 = 0;                                      // joystick data
char dataByte_2 = 0;

void setup()  {
  Serial.begin(19200);
  nunchuck_init();                                         // send the initilization handshake
  delay(100);
  nunchuck_joyx();
  nunchuck_joyy();
}

void loop()  {
  if (millis() - lastPulse >= refreshTime) {                // x ms have passed
    checkNunchuck();
    lastPulse = millis();                                   // save the time of last pulse
  }
}

void checkNunchuck()  {
  static int Byte1_ant, Byte2_ant;
  nunchuck_get_data();
  controlByte = 'd';
  dataByte_1 = map(nunchuck_joyy(), 27, 218, 0, 40);        // nunchuck joystick North/South                    
  dataByte_2 = map(nunchuck_joyx(), 27, 218, 0, 40);        // nunchuck joystick East/West
  dataByte_1 = constrain(dataByte_1, 0, 40);                                
  dataByte_2 = constrain(dataByte_2, 0, 40);
  if((dataByte_1!=Byte1_ant)||(dataByte_2!=Byte2_ant))  {
    updateBot();
    Byte1_ant = dataByte_1;
    Byte2_ant = dataByte_2;
  }
}

void updateBot()    {                                       // send data stream
    Serial.print(controlByte);        
    Serial.print(dataByte_1);    
    Serial.print(dataByte_2);
    Serial.print("\n");
}

...........

145  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 15, 2011, 05:47:26 am
Hi prof_jazz, welcome  smiley
please let us have a photo of your new pet

Quote
I used 6V HITEC HS-325HB hacked to run continuosly, but this motors are not enough for he job they have to do
I also waste one year following this track  smiley-wink

Quote
(1) in the setup, with the function calibrateSensors(); you have to put the robot (each time you switch it on) exactly in the static equilibrium position in order to evaluate zero values (exept for z).
is this a little bit boring and could produce errors (if it is not perfectly perpendicular)?
If during the calibrateSensors() i'll give a tilt, the Robot will work to keep the tilt!
No No...
If you tilt the bot forward before calibrateSensors(), it will move forward and find a vertical equilibrium
This will happen only with encoder(s) implementation, look here

Quote
(2) what do You use to recharge the 12V batteries?
I ordered the battery charger shown here



146  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 14, 2011, 10:29:07 am
08:16 14/01/2011
@Osmaneram
Nice bot  smiley
I played with a MPC3208 ADC which is the 8 input version
As far as I remember, those are 12 bit ADC's with 4096 units (not 8096)  :o
Please clarify

Your IMU board may have a different noise pattern that may require specific Kalman filter tuning.
The ADC should not inpact Kalman tuning (it didn't on my setup)



@Ro-Bot-X
I am also tempted to go digital for several reasons
 - analogic is noisy by nature
 - additional features
 - this is the future...

I2C frequency is in the 100KHz range, don't be affraid
Please try it and let us know the outcome, we all need guinea pigs  smiley-wink smiley-wink
 

147  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 14, 2011, 06:33:01 am
Quote
I got my hands on a free L298N H-Bridge: http://www.st.com/stonline/books/pdf/docs/1773.pdf
Unfortunately it only can handle spikes of 3 A (repetitive 2.5 A). Did you ever get an idea of what currents are used? I plan on making the bot relatively small...
I would take the motor stall current as the H-bridge amp requirement

Quote
Also, have you ever run into speed problems from the microcontroller? Is 16 MHz fast enough?
16 MHz is fast enough

Quote
My understanding was that the sensors act as the feedback to tell the motors direction and speed, so a motor encoder is not necessary. I see you made the same statement in your initial post.
You will get "basic" balance w/o encoders, but the bot will drift forward/backward




Quote
I have now gotten my BlueSmirf and the other parts I was missing to be able to complete my bot.
...
I will post some images and a video on the interface and robot in the end of the week hopefully..
Congratulation Patrik
I will also post my XBee version this week end smiley-wink smiley-wink



148  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 11, 2011, 05:01:20 am
Hi BrianBot,
Welcome and good luck for your project  smiley

Looking at your shopping list, I have the following comments:
motor controller shield:
This device will definitly not cope with the amperes needed to feed your motors  :-?
Look here (initial post)

motors & wheels:
The wheels are wide and soft, which is good for balancing
Wheel diameter could be higher
You need encoders (at least one). How will you afix them ??

Quote
My instructor seems to think there will be problems with different torques of each motor.
How much validity is in that?
This is addressed with the second encoder

Feel free to document you project here
This thread is now very visible from Google, this is convenient for discussion with non Arduino jerks
149  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 10, 2011, 05:05:01 am
Quote
hello.
I'm looking for the kasBot v2.0 code, involving quadrature encoders. Couldn't find it on the "official" site.
Can you help me?

Andreas
Norway
Hi Andreas,
Sorry for that, I will send it today to Patrik for posting in his blog
http://www.x-firm.com/?page_id=145
150  Forum 2005-2010 (read only) / Exhibition / Re: Balancing robot for dummies on: January 09, 2011, 03:55:41 am
Quote
What do you think about it so far?
Possible options for speeding the transmital process:
 - reduce number of parameters to be tansmitted
 - transmit parameter only when value have changed
 - if you have 50 data to transmit, split the information and try sending 10 values per cycle.
    all info will be passed within 5 cycles = 500ms, which is acceptable
 - Combine these options
Pages: 1 ... 8 9 [10] 11 12 ... 20