Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: analogWrite() problem on: January 16, 2013, 06:15:07 am
I think the problem has been solved. the problem was something wrong with the calibration I made to my ESCs. I recalibrated them and the problem was gone. Thanks a lot Mike for your help.
2  Using Arduino / Sensors / Re: ITG3200 gyroscope simple question on: January 14, 2013, 05:44:34 pm
Quote
If you look at the schematic at the sparkfun site ( https://www.sparkfun.com/products/9801 ) you see a solder jumper for AD0. You have to remove the connection to Vcc and make a connection to GND.

That solder jumper is the one with three pads near the Vdd pin.

Thanks a lot. it's clear now smiley
3  Using Arduino / Sensors / ITG3200 gyroscope simple question on: January 14, 2013, 02:11:44 pm
I want to change the address of the gyroscope from 0x69 to 0x68. I read in the description that it can be done by pulling the AD0 (pin 9) in the gyroscope to ground instead of Vcc using a jumper on the top of the board. Do anyone know exactly how this can be done cause I don't want to burn it?
I'm not sure if it's allowed to post links here but you can find the gyroscope in the first link (sparkfun) if you just google itg3200. This is written in the third paragraph.


Here is a photo f the gyro anyway:



Thanks in advance.

 
4  Using Arduino / Programming Questions / Re: analogWrite() problem on: January 13, 2013, 05:59:48 pm
Quote
Not sure but are you saying that with the same code you only get a problem if the ESC is connected to the arduino but no motor is connected to the ESC?

First, Thanks for being so patient.I really appreciate it.

Second, I thought of making a videos showing the problem to make it more clear

watch?v=Im_qju60XWc&feature=youtu.be  (on youtube)


5  Using Arduino / Programming Questions / Re: analogWrite() problem on: January 13, 2013, 03:35:23 pm
Quote
But does this cause problems if the motor is disconnected?

Well, Motors are powered by an external battery and connected to arduino through electronic speed controllers. The problem only occurs when those ESCs are connected, it vanishes when I disconnect them but it doesn't make a difference if motors are powered or not.
6  Using Arduino / Programming Questions / Re: analogWrite() problem on: January 13, 2013, 04:33:14 am
Quote
Well as you don't appear to be actually using the servos at all why is it included at the start of the sketch?

Yes you are right, I removed it.

Quote
There is no software reason why the two sketches should interfere with each other. Have you tried replacing the motors with an LED and resistor? It could be the interference from the motor is messing up the I2C bus.

Well, I don't have leds right now, I'll buy some 2day and try that but there is a thing that may mean something to you. When any statement that uses this itgaddress is put in the void loop, this problem occurs (for example, data = itgRead(itgAddress, GYRO_XOUT_H)<<8; //in the readX() function). I changed the itgaddress from 0x69 to 0x68 to see if the problem stills on but it went away but ofcourse all the gyro readings printed out are zeros cause it's not the right  address to write on. As I mentioned I'm using an accelerometer (the address is 0x40) too with the motors but it doesn't cause this problem so, I think it's not with the I2C bus. It's something with that address, may be it gets something from both the gyro and receiver at the same time that causes this conflict, I'm just guessing.
7  Using Arduino / Programming Questions / Re: analogWrite() problem on: January 12, 2013, 05:55:33 pm
Quote
If you don't have any servos, why are you including the Servo header file?
Because I was using servo functions before modifying them to analogWrite, can this make a problem?
8  Using Arduino / Programming Questions / Re: analogWrite() problem on: January 12, 2013, 05:53:52 pm
Quote
As opposed to just dividing by 10?

I just did that for simplicity but even changing that range problem still goes on

Quote
How do you KNOW that duration is in the range 1000 to 2000?
I got this from forums of people using the same type of this transmitter, with a value lower than 1000, receiver won't get any signals.

Quote
If the comment doesn't match the code, does it serve any useful purpose? Calling delay() with a value of 0 certainly does not.
No it didn't solve anything, I just forgot to modfy it back.

Quote
What do you Serial.print() statements tell you is happening?

They print out angular velocities around X,Y and Z. They work very fine without the analogWrite() function. I use an accelerometer to print ou angles but it doesn't cause the same problem with the analogWrite function
9  Using Arduino / Programming Questions / Re: analogWrite() problem on: January 12, 2013, 05:42:57 pm
Quote
Check what timer the servo library uses, check what timer is used to drive the PWM for pins 9 & 10 and I think you will find an overlap.
As a cure use pins for PWM that do not use the servo's timer.

I'm a noob with that timers thing but for simplicity I connected only 2 motors to pins 7,8 and only one channel from receiver is connected to pin 5. So, I think I'm not using servo's timers
10  Using Arduino / Programming Questions / analogWrite() problem on: January 12, 2013, 05:14:38 pm
I use an ITG3200 gyroscope sensor , Turnigy 9X transmitter,4 brushless motors and arduino Mega 2560. I found a code used to get readings from the gyro and it works fine. I used the analogwrite function to write the value coming from receivers to motors and it works fine too. but when these two functions are put together in the same code (i.e reading from gyro and analogwrite() function) everything stop working, the serial monitor stops monitoring the gyro readings and the motors are no longer receiving values from TX and they are stuck to the last speed they received till I disconnect. If I remove any of those functions from void loop() the other one works fine with no problems. I thought the problem might be with the itgaddress which is 0x69 (may be conflict occurs or something) cause I've been trying everything else for 3 days but in vain. Does anyone know what the problem could be or if there is a way to change the address of the gyroscope?

Here is the code I use for testing where both functions are put toghether:

Code:
#include <Wire.h>
#include <Servo.h>

//Tx definations
int throttle = 11;
int val  = 0;
unsigned long duration;


//defining the Offsets of x,y,z
#define OFFSET_X 18;
#define OFFSET_Y 242;
#define OFFSET_Z 8;
//

//This is a list of registers in the ITG-3200. Registers are parameters that determine how the sensor will behave, or they can hold data that represent the
//sensors current status.
//To learn more about the registers on the ITG-3200, download and read the datasheet.
char WHO_AM_I = 0x00;
char SMPLRT_DIV= 0x15;
char DLPF_FS = 0x16;
char GYRO_XOUT_H = 0x1D;
char GYRO_XOUT_L = 0x1E;
char GYRO_YOUT_H = 0x1F;
char GYRO_YOUT_L = 0x20;
char GYRO_ZOUT_H = 0x21;
char GYRO_ZOUT_L = 0x22;

//definitions of the equation that converts to deg/s
float Vref = 3.3;
float sensgyro = .0007238;


//This is a list of settings that can be loaded into the registers.
//DLPF, Full Scale Register Bits
//FS_SEL must be set to 3 for proper operation
//Set DLPF_CFG to 3 for 1kHz Fint and 42 Hz Low Pass Filter
char DLPF_CFG_0 = (1<<0);
char DLPF_CFG_1 = (1<<1);
char DLPF_CFG_2 = (1<<2);
char DLPF_FS_SEL_0 = (1<<3);
char DLPF_FS_SEL_1 = (1<<4);

//I2C devices each have an address. The address is defined in the datasheet for the device. The ITG-3200 breakout board can have different address depending on how
//the jumper on top of the board is configured. By default, the jumper is connected to the VDD pin. When the jumper is connected to the VDD pin the I2C address
//is 0x69.
char itgAddress = 0x69;

//In the setup section of the sketch the serial port will be configured, the i2c communication will be initialized, and the itg-3200 will be configured.
void setup()
{
  //Create a serial connection using a 9600bps baud rate.
  Serial.begin(115200);
 
  //Initialize the I2C communication. This will set the Arduino up as the 'Master' device.
  Wire.begin();
 
  //Read the WHO_AM_I register and print the result
  char id=0;
  id = itgRead(itgAddress, 0x00); 
  Serial.print("ID: ");
  Serial.println(id, HEX);
 
  //Configure the gyroscope
  //Set the gyroscope scale for the outputs to +/-2000 degrees per second
  itgWrite(itgAddress, DLPF_FS, (DLPF_FS_SEL_0|DLPF_FS_SEL_1|DLPF_CFG_0));
  //Set the sample rate to 100 hz
  itgWrite(itgAddress, SMPLRT_DIV, 9);
  pinMode(throttle, INPUT);
}

//The loop section of the sketch will read the X,Y and Z output rates from the gyroscope and output them in the Serial Terminal
void loop()
{
  //Create variables to hold the output rates.
  int xRate, yRate, zRate;

  //Read the x,y and z output rates from the gyroscope.
  xRate = readX();
  yRate = readY();
  zRate = readZ();
 
  duration = pulseIn(throttle, HIGH); //Get the value of RX received from TX
  duration = map(duration,1000,2000,100,200);
  analogWrite(9,duration); //write value from receiver on motor1 connected to pin9
  analogWrite(10,duration);
 
  //calculate the total time of the process

  //Print the output rates to the terminal, seperated by a TAB character.
  Serial.print(xRate);
  Serial.print('\t');
  Serial.print(yRate);
  Serial.print('\t');
  Serial.println(zRate);

  //Wait 10ms before reading the values again. (Remember, the output rate was set to 100hz and 1reading per 10ms = 100hz.)
  delay(0);
}

//This function will write a value to a register on the itg-3200.
//Parameters:
//  char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.
//  char registerAddress: The address of the register on the sensor that should be written to.
//  char data: The value to be written to the specified register.
void itgWrite(char address, char registerAddress, char data)
{
  //Initiate a communication sequence with the desired i2c device
  Wire.beginTransmission(address);
  //Tell the I2C address which register we are writing to
  Wire.write(registerAddress);
  //Send the value to write to the specified register
  Wire.write(data);
  //End the communication sequence
  Wire.endTransmission();
}

//This function will read the data from a specified register on the ITG-3200 and return the value.
//Parameters:
//  char address: The I2C address of the sensor. For the ITG-3200 breakout the address is 0x69.
//  char registerAddress: The address of the register on the sensor that should be read
//Return:
//  unsigned char: The value currently residing in the specified register
unsigned char itgRead(char address, char registerAddress)
{
  //This variable will hold the contents read from the i2c device.
  unsigned char data=0;
 
  //Send the register address to be read.
  Wire.beginTransmission(address);
  //Send the Register Address
  Wire.write(registerAddress);
  //End the communication sequence.
  Wire.endTransmission();
 
  //Ask the I2C device for data
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 1);
 
  //Wait for a response from the I2C device
  if(Wire.available()){
    //Save the data sent from the I2C device
    data = Wire.read();
  }
 
  //End the communication sequence.
  Wire.endTransmission();
 
  //Return the data read during the operation
  return data;
}

//This function is used to read the X-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second.
//Usage: int xRate = readX();
int readX(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_XOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_XOUT_L);
  data -= OFFSET_X;   
  float Ratex = (((data * Vref / 65535) - 0) / sensgyro);
  data = Ratex;
  return data;
}

//This function is used to read the Y-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second.
//Usage: int yRate = readY();
int readY(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_YOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_YOUT_L);   
  data -= OFFSET_Y;   
  float Ratey = (((data * Vref / 65535) - 0) / sensgyro);
  data = Ratey;
  return data;
}

//This function is used to read the Z-Axis rate of the gyroscope. The function returns the ADC value from the Gyroscope
//NOTE: This value is NOT in degrees per second.
//Usage: int zRate = readZ();
int readZ(void)
{
  int data=0;
  data = itgRead(itgAddress, GYRO_ZOUT_H)<<8;
  data |= itgRead(itgAddress, GYRO_ZOUT_L); 
  data -= OFFSET_Z;   
  float Ratez = (((data * Vref / 65535) - 0) / sensgyro);
  data = Ratez;
  return data;
}
11  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: October 24, 2012, 02:16:00 pm
yes got it smiley Thanks Lauszus a lot for ur efforts, wish u all the best
12  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: October 24, 2012, 08:53:13 am
Yup I noticed that smiley, but shouldn't I use the acc sensitivity in this function and for the Y angle as well :
double getXangle() {
 double accXval = Accx-zeroValue[0];
 double accZval = Accz-zeroValue[2];
 double angle = (atan2(accXval,accZval))*RAD_TO_DEG;
 return angle;

I mean would be like this: (4095 = sens in 2g range)

double getXangle() {
  double accXval = (Accx-zeroValue[0])/4095;
  double accZval = (Accz-zeroValue[2])/4095;
  double angle = (atan2(accXval,accZval))*RAD_TO_DEG;
  return angle;
13  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: October 24, 2012, 08:15:38 am
Man, you are great smiley , the problem was in this function:-
 R = sqrt(pow(accXval,2)+pow(accYval,2)+pow(accZval,2));
 accXangle = acos(accXval/R)*RAD_TO_DEG-90;
 accYangle = acos(accYval/R)*RAD_TO_DEG-90;

I think it's not accurate or something as I was applying it in my old code and instead of (accXval/R), it was (Rxest/R) where Rxest is calculated using both acc and gyro readings. However, after I changed it with the one u sent me in the previous post, it worked so fine. Thank you so much.
14  Using Arduino / Sensors / Re: Guide to gyro and accelerometer with Arduino including Kalman filtering on: October 23, 2012, 09:25:38 am
Hallo Lauszus, Thanks so much for this great blog. I need ur help with something. I'm using itg 3200 and bma 180, I applied your code and it works fine but when rotating around roll for exaple with 90 degrees, the output reading is 70 and the same for pitch although before that, i was applying a comp filter (explained by starlino) and it was giving an output of 90 when rotating with 90 degrees. Do you have any idea what might be causing that?
Pages: [1]