Show Posts
Pages: [1] 2
1  Using Arduino / Networking, Protocols, and Devices / Re: I2C serial read on: February 13, 2013, 12:43:54 pm
Trying and searching and reading stuff about I2C i concluded to that all i need to do is just to send a tringging pulse in the clock and then just read the data.

so my code goes like this;

int pin4= A4;


void setup()
{
     pinMode(pin4, OUTPUT);
     Serial.begin(9600);
}

void loop()
{
 int sensorValue=analogRead(A5);
digitalWrite(pin4, HIGH);
delay(1);
digitalWrite(pin4, LOW);
Serial.println(sensorValue);
delay(1);
}

Is that correct? will it work?


2  Using Arduino / Networking, Protocols, and Devices / Re: I2C serial read on: February 13, 2013, 11:08:46 am
Has to be that hard? noone can help me?
3  Using Arduino / Networking, Protocols, and Devices / Re: I2C serial read on: February 13, 2013, 10:27:59 am
Ok, Here is the simple code you refering too. Well a part of if because it exceeds the 9500 characters


#include <Wire.h>
#define GRAVITY 256  
#define ToRad(x) ((x)*0.01745329252)
#define ToDeg(x) ((x)*57.2957795131)

// L3G4200D gyro: 2000 dps full scale
// 70 mdps/digit; 1 dps = 0.07
#define Gyro_Gain_X 0.07
#define Gyro_Gain_Y 0.07
#define Gyro_Gain_Z 0.07
#define Gyro_Scaled_X(x) ((x)*ToRad(Gyro_Gain_X))
#define Gyro_Scaled_Y(x) ((x)*ToRad(Gyro_Gain_Y))  
#define Gyro_Scaled_Z(x) ((x)*ToRad(Gyro_Gain_Z))
#define M_X_MIN -421
#define M_Y_MIN -639
#define M_Z_MIN -238
#define M_X_MAX 424
#define M_Y_MAX 295
#define M_Z_MAX 472
#define Kp_ROLLPITCH 0.02
#define Ki_ROLLPITCH 0.00002
#define Kp_YAW 1.2
#define Ki_YAW 0.00002
#define OUTPUTMODE 1
#define PRINT_ANALOGS 0
#define PRINT_EULER 1  
#define STATUS_LED 13
float G_Dt=0.02;    // Integration time (DCM algorithm)  We will run the integration loop at 50Hz if possible
long timer=0;   //general purpuse timer
long timer_old;
long timer24=0; //Second timer used to print values
int AN[6]; //array that stores the gyro and accelerometer data
int AN_OFFSET[6]={0,0,0,0,0,0}; //Array that stores the Offset of the sensors

.................

  AN[0] = gyro.g.x;
  AN[1] = gyro.g.y;
  AN[2] = gyro.g.z;
  gyro_x = SENSOR_SIGN[0] * (AN[0] - AN_OFFSET[0]);
  gyro_y = SENSOR_SIGN[1] * (AN[1] - AN_OFFSET[1]);
  gyro_z = SENSOR_SIGN[2] * (AN[2] - AN_OFFSET[2]);
}

void Accel_Init()
{
  compass.init();
  if (compass.getDeviceType() == LSM303DLHC_DEVICE)
  {
    compass.writeAccReg(LSM303_CTRL_REG1_A, 0x47); // normal power mode, all axes enabled, 50 Hz
    compass.writeAccReg(LSM303_CTRL_REG4_A, 0x08); // high resolution output mode
    compass.writeAccReg(LSM303_CTRL_REG4_A, 0x20); // 8 g full scale: FS = 10 on DLHC
  }
  else
  {
    compass.writeAccReg(LSM303_CTRL_REG1_A, 0x27); // normal power mode, all axes enabled, 50 Hz
    compass.writeAccReg(LSM303_CTRL_REG4_A, 0x30); // 8 g full scale: FS = 11 on DLH, DLM
  }
}

// Reads x,y and z accelerometer registers
void Read_Accel()
{
  compass.readAcc();
  
  AN[3] = compass.a.x;
  AN[4] = compass.a.y;
  AN[5] = compass.a.z;
  accel_x = SENSOR_SIGN[3] * (AN[3] - AN_OFFSET[3]);
  accel_y = SENSOR_SIGN[4] * (AN[4] - AN_OFFSET[4]);
  accel_z = SENSOR_SIGN[5] * (AN[5] - AN_OFFSET[5]);
}

void Compass_Init()
{
  compass.writeMagReg(LSM303_MR_REG_M, 0x00); // continuous conversion mode
  // 15 Hz default
}

void Read_Compass()
{
  compass.readMag();
  
  magnetom_x = SENSOR_SIGN[6] * compass.m.x;
  magnetom_y = SENSOR_SIGN[7] * compass.m.y;
  magnetom_z = SENSOR_SIGN[8] * compass.m.z;
}
void printdata(void)
{    
      Serial.print("!");

      #if PRINT_EULER == 1
      Serial.print("ANG:");
      Serial.print(ToDeg(roll));
      Serial.print(",");
      Serial.print(ToDeg(pitch));
      Serial.print(",");
      Serial.print(ToDeg(yaw));
      #endif      
      #if PRINT_ANALOGS==1
      Serial.print(",AN:");
      Serial.print(AN[0]);  //(int)read_adc(0)
      Serial.print(",");
      Serial.print(AN[1]);
      Serial.print(",");
      Serial.print(AN[2]);  
      Serial.print(",");
      Serial.print(AN[3]);
      Serial.print (",");
      Serial.print(AN[4]);
      Serial.print (",");
      Serial.print(AN[5]);
      Serial.print(",");
      Serial.print(c_magnetom_x);
      Serial.print (",");
      Serial.print(c_magnetom_y);
      Serial.print (",");
      Serial.print(c_magnetom_z);
      #endif
      /*#if PRINT_DCM == 1
      Serial.print (",DCM:");
      Serial.print(convert_to_dec(DCM_Matrix[0][0]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[0][1]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[0][2]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[1][0]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[1][1]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[1][2]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[2][0]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[2][1]));
      Serial.print (",");
      Serial.print(convert_to_dec(DCM_Matrix[2][2]));
      #endif*/
      Serial.println();    
      
}

long convert_to_dec(float x)
{
  return x*10000000;
}

It may be simple to you but for me is greek...

So can you please help me with a simpler code? or that code is the simplest to implement a reading from I2C?
4  Using Arduino / Networking, Protocols, and Devices / Re: I2C serial read on: February 13, 2013, 09:29:13 am
Ok, firstly thank you for pointing out that im stupid smiley

You didn't help at all tho..

I'v tried that code that MiniMu-9 gives, is awesome and does a very good work. But i can't figure out how exactly works.
Thats why i asked from someone who knows to help me with the code.
I can understand that dealing with someone newbee isn't that exiting or not challenging at all but this could really solve me a problem that's delaying my thesis.

All i want is get the data from the sensor. Lets say i will name it sensordata and then do a Serial.Println(sensordada);
Can you please write me a code that implements that task?

Thank you alot and sorry for bothering you.

Minas
5  Using Arduino / Networking, Protocols, and Devices / Re: I2C serial read on: February 13, 2013, 08:00:00 am
At first thank you for you replay,

Excuse me, the editing i did somehow didn't worked and you saw that incomplete post.

The sensor is MiniMu-9 a 3-axis accelerometer/magetometer/compass
http://www.pololu.com/catalog/product/1268

It has SCL and SDA pins which i connect respectively to 5 and 4 analog pins of my arduino Duemilanove.

In order to define what means simple code for me, i can tell you that the best code i'v composed until now is just a void loop that reads a pontesiometer from an analog input or just light a led with a delay.

My task is to get the data that sensor gives me and serially pass it to Matlab. In the latter i will do the data fusion and filtering via Kalman filter in order to implement an AHRS.

Best regards,

Minas
6  Using Arduino / Networking, Protocols, and Devices / I2C serial read on: February 13, 2013, 07:12:00 am
Hello,

The task i'm try to accomplish is to get data from Arduino and pass it through serial connection to Matlab in order to proccess it.
However, i'm a begginer and, a simple code just to read the data from a sensor which only uses I2C, looks like something really hard to me.
I found a good library for AHRS (which is all about) for Arduino, but unfortunately is too complicated for me to understand it.
The code i want to write must be simple.
Just some commands to trigger the clock and to read the data so at the end i can get e.g. Serial.println(sensordata);
Can you please help me out here?


Thank you in advance.

With respect,

Minas
7  Using Arduino / Networking, Protocols, and Devices / Re: I2C - how does that work? on: February 12, 2013, 07:40:34 am
Hello,

On my quest to find the right way to write a code for I2C i found your post.

I'm a begginer and i just want to write a simple code just to read the data from a sensor which only uses I2C
so at the end i can get e.g.

Serial.println(sensordata);

I see that you guys have a complete comprehension on that topic that's why i post here instead of opening a new post that might have already been opened.

Thank you in advance.

With respect,

Minas
8  Using Arduino / Sensors / Re: Pololu MinIMU-9 v2 on: January 24, 2013, 08:44:04 pm
Thank you alot for your help. Turned out that i was abit dizzy... i was exctracting the whole folder with readme etc and not the certain one that included the files. smiley-red

Thank you again.
9  Using Arduino / Sensors / Re: Pololu MinIMU-9 v2 on: January 24, 2013, 06:50:56 pm
Which is the correct way to install a library?

I just download the zip file from the site and then extracting it in the library folder.

Is there another way or am i doing it wrong?
10  Using Arduino / Sensors / Pololu MinIMU-9 v2 on: January 24, 2013, 01:43:49 pm
Hello,
I just got this sensor and tried to run the code found in the site. The L3G one.

But when im compiling it on arduion interface i get these errors;

"Serial:4: error: 'L3G' does not name a type
Serial.ino: In function 'void setup()':
Serial:10: error: 'gyro' was not declared in this scope
Serial:16: error: 'gyro' was not declared in this scope
Serial.ino: In function 'void loop()':
Serial:20: error: 'gyro' was not declared in this scope
"

I have dowloaded the file from site and extracted it to libraries forlder on my arduino folder
I just running it from file->examples->L3G->serial

The code is the following.
I'm kinda newbee in programming so please enlighten me.


#include <Wire.h>
#include <L3G.h>

L3G gyro;

void setup() {
  Serial.begin(9600);
  Wire.begin();

  if (!gyro.init())
  {
    Serial.println("Failed to autodetect gyro type!");
    while (1);
  }

  gyro.enableDefault();
}

void loop() {
  gyro.read();

  Serial.print("G ");
  Serial.print("X: ");
  Serial.print((int)gyro.g.x);
  Serial.print(" Y: ");
  Serial.print((int)gyro.g.y);
  Serial.print(" Z: ");
  Serial.println((int)gyro.g.z);

  delay(100);
}

Thank you in advance
Minas
11  Using Arduino / Sensors / Re: Sensor board MinIMU-9 Gyro, Accelerometer, and Compass on: January 24, 2013, 01:02:04 pm
Hi,

If everything works sound in your board and in your connections with the sensor and the sensor it self ain't broken then, i suggest the problem is caused by other things.

You see, the flactuation on these values could be due to white noise, perhaps some magnetic fields interfierence or anything could cause it. You have to consinder the square error in the measurements as well.

The best way to deal with this, is kalman filter.

I think will be a good code example in arduino forums for the kalman filter implementation.

Hope this helps.

Minas
12  Using Arduino / Sensors / Re: Ultrasonic Sensor single pin TR on: February 01, 2012, 12:00:09 pm
Thank you alot Peter.

I will try to build a code with this new perspective.

If i manage to get it work i will post it
13  Using Arduino / Sensors / Re: Ultrasonic Sensor single pin TR on: January 25, 2012, 11:36:17 am
Any other suggestions guys?

I'v managed to run the sensor in a bx-24 microcontroller..
and i can't run it on arduino?? this is a shame! please help!

the logic is like this

give 10us High as a trigger pulse
make an interrupt and measure the pulseWidth.

Take pulseWidth and print its value..

Where is the black hole here...i can't see it..
14  Using Arduino / Sensors / Re: DYP-ME007TX Ultrasonic Sensor NEED HELP!!! on: January 24, 2012, 03:44:59 am
Nothing has changed..

As a return for the duration im getting a constant high "1" and as a return of in or cm im getting "0"

It's either im doing something wrong in the hardware part like cables etc or the sensor is broken..
But i must plug only 3 cables VCC GND and OUT and have tried em on a new breadboard in different spots with different cables and the sensor was brand new never used before.

Thank you alot for your help. Always electronics will have their ways to frustrate us i reckon..
15  Using Arduino / Sensors / Re: DYP-ME007TX Ultrasonic Sensor on: January 23, 2012, 03:33:21 pm
http://www.alibaba.com/product-gs/456951035/ultrasonic_sensor.html

This is the link with the data sheet.

I have tried everything.. i really don't know what else to try.

And im getting a constant High "1" i'v even attached a led on the output pin and it just stays lit. Only a fast blink due to the 100ms delay.
Pages: [1] 2