2 questions (email through the arduino and code)

Hi there,
I have 2 questions:

  1. Can I send an email (or SMS or any other message) through the arduino?
  2. Will somebody please tell me more about the attached code?
    Thanks
}

//http://pansenti.wordpress.com/2013/03/26/pansentis-invensense-mpu-9150-software-for-arduino-is-now-on-github/
//Thank you to pansenti for setup code.
void MPU9150_setupCompass(){
  MPU9150_I2C_ADDRESS = 0x0C;      //change Adress to Compass

  MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode
  MPU9150_writeSensor(0x0A, 0x0F); //SelfTest
  MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode

  MPU9150_I2C_ADDRESS = 0x68;      //change Adress to MPU

  MPU9150_writeSensor(0x24, 0x40); //Wait for Data at Slave0
  MPU9150_writeSensor(0x25, 0x8C); //Set i2c address at slave0 at 0x0C
  MPU9150_writeSensor(0x26, 0x02); //Set where reading at slave 0 starts
  MPU9150_writeSensor(0x27, 0x88); //set offset at start reading and enable
  MPU9150_writeSensor(0x28, 0x0C); //set i2c address at slv1 at 0x0C
  MPU9150_writeSensor(0x29, 0x0A); //Set where reading at slave 1 starts
  MPU9150_writeSensor(0x2A, 0x81); //Enable at set length to 1
  MPU9150_writeSensor(0x64, 0x01); //overvride register
  MPU9150_writeSensor(0x67, 0x03); //set delay rate
  MPU9150_writeSensor(0x01, 0x80);

  MPU9150_writeSensor(0x34, 0x04); //set i2c slv4 delay
  MPU9150_writeSensor(0x64, 0x00); //override register
  MPU9150_writeSensor(0x6A, 0x00); //clear usr setting
  MPU9150_writeSensor(0x64, 0x01); //override register
  MPU9150_writeSensor(0x6A, 0x20); //enable master i2c mode
  MPU9150_writeSensor(0x34, 0x13); //disable slv4
}

////////////////////////////////////////////////////////////
///////// I2C functions to get easier all values ///////////
////////////////////////////////////////////////////////////

int MPU9150_readSensor(int addrL, int addrH){
  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addrL);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  byte L = Wire.read();

  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addrH);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  byte H = Wire.read();

  return (H<<8)+L;
}

int MPU9150_readSensor(int addr){
  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addr);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  return Wire.read();
}

int MPU9150_writeSensor(int addr,int data){
  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addr);
  Wire.write(data);
  Wire.endTransmission(true);

  return 1;
}

If your Arduino has a network interface then it can send an email. Exactly how you send it would depend on the mail protocols that your email provider supported (SMTP or ESMTP are the most likely ones), and some authentication mechanisms would be difficult/infeasible for an Arduino to implement, but if you have an email provider that doesn't enforce an encrypted connection and with an auth protocol that you can find implemented (or implement yourself) then sending emails is conceptually easy.

There are various ways to send an SMS, If your Arduino has a GSM modem attached (and it has service) then you can use an extended AT command set to send and receive SMSs. Various GSM service providers also support sending and receiving SMS via email.

The code snippet you included appears to be dealing with an MPU9150 and is incomplete. I can't tell you where it comes from, what it is supposed to do or what it actually does, or whether there are any problems with it. Perhaps you already know that.

I know what the program is doing a loop, the rest is the sensor's settings, I do not understand.

If arduino connected to the computer, and the computer has internet so arduino connected to the Internet?

#include <Wire.h>

#define MPU9150_SELF_TEST_X 0x0D // R/W
#define MPU9150_SELF_TEST_Y 0x0E // R/W
#define MPU9150_SELF_TEST_X 0x0F // R/W
#define MPU9150_SELF_TEST_A 0x10 // R/W
#define MPU9150_SMPLRT_DIV 0x19 // R/W
#define MPU9150_CONFIG 0x1A // R/W
#define MPU9150_GYRO_CONFIG 0x1B // R/W
#define MPU9150_ACCEL_CONFIG 0x1C // R/W
#define MPU9150_FF_THR 0x1D // R/W
#define MPU9150_FF_DUR 0x1E // R/W
#define MPU9150_MOT_THR 0x1F // R/W
#define MPU9150_MOT_DUR 0x20 // R/W
#define MPU9150_ZRMOT_THR 0x21 // R/W
#define MPU9150_ZRMOT_DUR 0x22 // R/W
#define MPU9150_FIFO_EN 0x23 // R/W
#define MPU9150_I2C_MST_CTRL 0x24 // R/W
#define MPU9150_I2C_SLV0_ADDR 0x25 // R/W
#define MPU9150_I2C_SLV0_REG 0x26 // R/W
#define MPU9150_I2C_SLV0_CTRL 0x27 // R/W
#define MPU9150_I2C_SLV1_ADDR 0x28 // R/W
#define MPU9150_I2C_SLV1_REG 0x29 // R/W
#define MPU9150_I2C_SLV1_CTRL 0x2A // R/W
#define MPU9150_I2C_SLV2_ADDR 0x2B // R/W
#define MPU9150_I2C_SLV2_REG 0x2C // R/W
#define MPU9150_I2C_SLV2_CTRL 0x2D // R/W
#define MPU9150_I2C_SLV3_ADDR 0x2E // R/W
#define MPU9150_I2C_SLV3_REG 0x2F // R/W
#define MPU9150_I2C_SLV3_CTRL 0x30 // R/W
#define MPU9150_I2C_SLV4_ADDR 0x31 // R/W
#define MPU9150_I2C_SLV4_REG 0x32 // R/W
#define MPU9150_I2C_SLV4_DO 0x33 // R/W
#define MPU9150_I2C_SLV4_CTRL 0x34 // R/W
#define MPU9150_I2C_SLV4_DI 0x35 // R
#define MPU9150_I2C_MST_STATUS 0x36 // R
#define MPU9150_INT_PIN_CFG 0x37 // R/W
#define MPU9150_INT_ENABLE 0x38 // R/W
#define MPU9150_INT_STATUS 0x3A // R
#define MPU9150_ACCEL_XOUT_H 0x3B // R
#define MPU9150_ACCEL_XOUT_L 0x3C // R
#define MPU9150_ACCEL_YOUT_H 0x3D // R
#define MPU9150_ACCEL_YOUT_L 0x3E // R
#define MPU9150_ACCEL_ZOUT_H 0x3F // R
#define MPU9150_ACCEL_ZOUT_L 0x40 // R
#define MPU9150_TEMP_OUT_H 0x41 // R
#define MPU9150_TEMP_OUT_L 0x42 // R
#define MPU9150_GYRO_XOUT_H 0x43 // R
#define MPU9150_GYRO_XOUT_L 0x44 // R
#define MPU9150_GYRO_YOUT_H 0x45 // R
#define MPU9150_GYRO_YOUT_L 0x46 // R
#define MPU9150_GYRO_ZOUT_H 0x47 // R
#define MPU9150_GYRO_ZOUT_L 0x48 // R
#define MPU9150_EXT_SENS_DATA_00 0x49 // R
#define MPU9150_EXT_SENS_DATA_01 0x4A // R
#define MPU9150_EXT_SENS_DATA_02 0x4B // R
#define MPU9150_EXT_SENS_DATA_03 0x4C // R
#define MPU9150_EXT_SENS_DATA_04 0x4D // R
#define MPU9150_EXT_SENS_DATA_05 0x4E // R
#define MPU9150_EXT_SENS_DATA_06 0x4F // R
#define MPU9150_EXT_SENS_DATA_07 0x50 // R
#define MPU9150_EXT_SENS_DATA_08 0x51 // R
#define MPU9150_EXT_SENS_DATA_09 0x52 // R
#define MPU9150_EXT_SENS_DATA_10 0x53 // R
#define MPU9150_EXT_SENS_DATA_11 0x54 // R
#define MPU9150_EXT_SENS_DATA_12 0x55 // R
#define MPU9150_EXT_SENS_DATA_13 0x56 // R
#define MPU9150_EXT_SENS_DATA_14 0x57 // R
#define MPU9150_EXT_SENS_DATA_15 0x58 // R
#define MPU9150_EXT_SENS_DATA_16 0x59 // R
#define MPU9150_EXT_SENS_DATA_17 0x5A // R
#define MPU9150_EXT_SENS_DATA_18 0x5B // R
#define MPU9150_EXT_SENS_DATA_19 0x5C // R
#define MPU9150_EXT_SENS_DATA_20 0x5D // R
#define MPU9150_EXT_SENS_DATA_21 0x5E // R
#define MPU9150_EXT_SENS_DATA_22 0x5F // R
#define MPU9150_EXT_SENS_DATA_23 0x60 // R
#define MPU9150_MOT_DETECT_STATUS 0x61 // R
#define MPU9150_I2C_SLV0_DO 0x63 // R/W
#define MPU9150_I2C_SLV1_DO 0x64 // R/W
#define MPU9150_I2C_SLV2_DO 0x65 // R/W
#define MPU9150_I2C_SLV3_DO 0x66 // R/W
#define MPU9150_I2C_MST_DELAY_CTRL 0x67 // R/W
#define MPU9150_SIGNAL_PATH_RESET 0x68 // R/W
#define MPU9150_MOT_DETECT_CTRL 0x69 // R/W
#define MPU9150_USER_CTRL 0x6A // R/W
#define MPU9150_PWR_MGMT_1 0x6B // R/W
#define MPU9150_PWR_MGMT_2 0x6C // R/W
#define MPU9150_FIFO_COUNTH 0x72 // R/W
#define MPU9150_FIFO_COUNTL 0x73 // R/W
#define MPU9150_FIFO_R_W 0x74 // R/W
#define MPU9150_WHO_AM_I 0x75 // R

#define MPU9150_CMPS_XOUT_L 0x4A // R
#define MPU9150_CMPS_XOUT_H 0x4B // R
#define MPU9150_CMPS_YOUT_L 0x4C // R
#define MPU9150_CMPS_YOUT_H 0x4D // R
#define MPU9150_CMPS_ZOUT_L 0x4E // R
#define MPU9150_CMPS_ZOUT_H 0x4F // R

int MPU9150_I2C_ADDRESS = 0x68;

int cmps[3];
int accl[3];
int gyro[3];
int temp;
int i=0;
int ledPin = 13;
int ledPin1 = 8;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
Wire.begin();

MPU9150_writeSensor(MPU9150_PWR_MGMT_1, 0);

MPU9150_setupCompass();
}

void loop()
{

int gyro_x=MPU9150_readSensor(MPU9150_GYRO_XOUT_L,MPU9150_GYRO_XOUT_H);
int gyro_y=MPU9150_readSensor(MPU9150_GYRO_YOUT_L,MPU9150_GYRO_YOUT_H);
int gyro_z=MPU9150_readSensor(MPU9150_GYRO_ZOUT_L,MPU9150_GYRO_ZOUT_H);
int accel_x=MPU9150_readSensor(MPU9150_ACCEL_XOUT_L,MPU9150_ACCEL_XOUT_H);
int accel_y=MPU9150_readSensor(MPU9150_ACCEL_YOUT_L,MPU9150_ACCEL_YOUT_H);
int accel_z=MPU9150_readSensor(MPU9150_ACCEL_ZOUT_L,MPU9150_ACCEL_ZOUT_H);

if (((gyro_x>15000)||(gyro_x<-22000))&&((gyro_y>4200)||(gyro_y<-500))&&((gyro_z>1000)||(gyro_z<-13000))&&((accel_x>6000)||(accel_x<-6000))&&((accel_y>4000)||(accel_y<-27000))&&((accel_z>7000)||(accel_z<-200)))
{
Serial.print("HOMO NAFAL ");
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
i=i+1;
delay(10000);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin1, HIGH);

}
if (i==0)
{
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin1, HIGH);
Serial.print(gyro_x);
Serial.print(" ");
Serial.print(gyro_y);
Serial.print(" ");
Serial.print(gyro_z);
Serial.print(" ");
Serial.print(accel_x);
Serial.print(" ");
Serial.print(accel_y);
Serial.print(" ");
Serial.print(accel_z);
Serial.println();
delay(100);
}

}

//http://pansenti.wordpress.com/2013/03/26/pansentis-invensense-mpu-9150-software-for-arduino-is-now-on-github/
//Thank you to pansenti for setup code.
void MPU9150_setupCompass(){
MPU9150_I2C_ADDRESS = 0x0C; //change Adress to Compass

MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode
MPU9150_writeSensor(0x0A, 0x0F); //SelfTest
MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode

MPU9150_I2C_ADDRESS = 0x68; //change Adress to MPU

MPU9150_writeSensor(0x24, 0x40); //Wait for Data at Slave0
MPU9150_writeSensor(0x25, 0x8C); //Set i2c address at slave0 at 0x0C
MPU9150_writeSensor(0x26, 0x02); //Set where reading at slave 0 starts
MPU9150_writeSensor(0x27, 0x88); //set offset at start reading and enable
MPU9150_writeSensor(0x28, 0x0C); //set i2c address at slv1 at 0x0C
MPU9150_writeSensor(0x29, 0x0A); //Set where reading at slave 1 starts
MPU9150_writeSensor(0x2A, 0x81); //Enable at set length to 1
MPU9150_writeSensor(0x64, 0x01); //overvride register
MPU9150_writeSensor(0x67, 0x03); //set delay rate
MPU9150_writeSensor(0x01, 0x80);

MPU9150_writeSensor(0x34, 0x04); //set i2c slv4 delay
MPU9150_writeSensor(0x64, 0x00); //override register
MPU9150_writeSensor(0x6A, 0x00); //clear usr setting
MPU9150_writeSensor(0x64, 0x01); //override register
MPU9150_writeSensor(0x6A, 0x20); //enable master i2c mode
MPU9150_writeSensor(0x34, 0x13); //disable slv4
}

////////////////////////////////////////////////////////////
///////// I2C functions to get easier all values ///////////
////////////////////////////////////////////////////////////

int MPU9150_readSensor(int addrL, int addrH){
Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addrL);
Wire.endTransmission(false);

Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
byte L = Wire.read();

Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addrH);
Wire.endTransmission(false);

Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
byte H = Wire.read();

return (H<<8)+L;
}

int MPU9150_readSensor(int addr){
Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addr);
Wire.endTransmission(false);

Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
return Wire.read();
}

int MPU9150_writeSensor(int addr,int data){
Wire.beginTransmission(MPU9150_I2C_ADDRESS);
Wire.write(addr);
Wire.write(data);
Wire.endTransmission(true);

return 1;
}

If arduino connected to the computer, and the computer has internet so arduino connected to the Internet?

No.

The Arduino connection to the PC is USB or Serial (USB is also virtual serial.). But you have no TCP stack in the Arduino environment. You may be aware that some USB devices can use a PC client to establish Internet and pass the results to the device, but Arduino by-itself (Without WiFi router, WiFi shield, or Ethernet shield) does not do this magic.

Ray

APSron:
If arduino connected to the computer, and the computer has internet so arduino connected to the Internet?

If your Arduino does not have a network interface then it is not connected to the internet. A network interface could be an Ethernet adapter, WiFi adapter, GSM modem etc.

If the only connection you have is a serial link to a PC and the PC has a network interface with internet access then you could send the email/text via the PC. It would need you to find/write an application to run on the PC and run that each time you wanted to send an email/text/whatever. There are various clients available to do that sort of thing, and it would be up to you to find one that is compatible with your PC and does what you want. You would also need an application on the PC to read the serial input from the Arduino and invoke the email/SMS sending. If you're working on Windows you could use Gobetwino for that. On other platforms you would need to write your own equivalent.

Can I do the following:
connect Bluetooth to arduino so that the arduino is connected with the cell phone, and using what arduino cell phone message send SMS?

And I steel need help with the code

This assumes you are in an app with a "send MMS/Text" button:
http://community.skype.com/t5/Android/quot-Enter-quot-key-doesn-t-send-message-via-Bluetooth-Keyboard/td-p/1886367

The trick on how to open the texting application from a Bluetooth keyboard appears to be more handset centric unless you write a client application for the handset yourself. Once you know how to do what you want from a Bluetooth keyboard, the Arduino piece should be reachable.

I do not wish to burst your Arduino bubble, but generally forum members do not write significant portions of an application. If we know of a working example, we will point you there and it is your responsibility to come up to speed on the overall project. If you get stuck with something, we will attempt to assist IF you are willing to post all of your existing code. But, you must shoulder the bulk of all work.

Ray

i have that code (Arduino Playground - MPU-9150)
can u explain me that code?
Divide the code into several parts and explain what each part means

// MPU-9150 Accelerometer + Gyro + Compass + Temperature


#include <Wire.h>

// Register names according to the datasheet.
// According to the InvenSense document
// "MPU-9150 Register Map and Descriptions Revision 4.0",

#define MPU9150_SELF_TEST_X        0x0D   // R/W
#define MPU9150_SELF_TEST_Y        0x0E   // R/W
#define MPU9150_SELF_TEST_X        0x0F   // R/W
#define MPU9150_SELF_TEST_A        0x10   // R/W
#define MPU9150_SMPLRT_DIV         0x19   // R/W
#define MPU9150_CONFIG             0x1A   // R/W
#define MPU9150_GYRO_CONFIG        0x1B   // R/W
#define MPU9150_ACCEL_CONFIG       0x1C   // R/W
#define MPU9150_FF_THR             0x1D   // R/W
#define MPU9150_FF_DUR             0x1E   // R/W
#define MPU9150_MOT_THR            0x1F   // R/W
#define MPU9150_MOT_DUR            0x20   // R/W
#define MPU9150_ZRMOT_THR          0x21   // R/W
#define MPU9150_ZRMOT_DUR          0x22   // R/W
#define MPU9150_FIFO_EN            0x23   // R/W
#define MPU9150_I2C_MST_CTRL       0x24   // R/W
#define MPU9150_I2C_SLV0_ADDR      0x25   // R/W
#define MPU9150_I2C_SLV0_REG       0x26   // R/W
#define MPU9150_I2C_SLV0_CTRL      0x27   // R/W
#define MPU9150_I2C_SLV1_ADDR      0x28   // R/W
#define MPU9150_I2C_SLV1_REG       0x29   // R/W
#define MPU9150_I2C_SLV1_CTRL      0x2A   // R/W
#define MPU9150_I2C_SLV2_ADDR      0x2B   // R/W
#define MPU9150_I2C_SLV2_REG       0x2C   // R/W
#define MPU9150_I2C_SLV2_CTRL      0x2D   // R/W
#define MPU9150_I2C_SLV3_ADDR      0x2E   // R/W
#define MPU9150_I2C_SLV3_REG       0x2F   // R/W
#define MPU9150_I2C_SLV3_CTRL      0x30   // R/W
#define MPU9150_I2C_SLV4_ADDR      0x31   // R/W
#define MPU9150_I2C_SLV4_REG       0x32   // R/W
#define MPU9150_I2C_SLV4_DO        0x33   // R/W
#define MPU9150_I2C_SLV4_CTRL      0x34   // R/W
#define MPU9150_I2C_SLV4_DI        0x35   // R  
#define MPU9150_I2C_MST_STATUS     0x36   // R
#define MPU9150_INT_PIN_CFG        0x37   // R/W
#define MPU9150_INT_ENABLE         0x38   // R/W
#define MPU9150_INT_STATUS         0x3A   // R  
#define MPU9150_ACCEL_XOUT_H       0x3B   // R  
#define MPU9150_ACCEL_XOUT_L       0x3C   // R  
#define MPU9150_ACCEL_YOUT_H       0x3D   // R  
#define MPU9150_ACCEL_YOUT_L       0x3E   // R  
#define MPU9150_ACCEL_ZOUT_H       0x3F   // R  
#define MPU9150_ACCEL_ZOUT_L       0x40   // R  
#define MPU9150_TEMP_OUT_H         0x41   // R  
#define MPU9150_TEMP_OUT_L         0x42   // R  
#define MPU9150_GYRO_XOUT_H        0x43   // R  
#define MPU9150_GYRO_XOUT_L        0x44   // R  
#define MPU9150_GYRO_YOUT_H        0x45   // R  
#define MPU9150_GYRO_YOUT_L        0x46   // R  
#define MPU9150_GYRO_ZOUT_H        0x47   // R  
#define MPU9150_GYRO_ZOUT_L        0x48   // R  
#define MPU9150_EXT_SENS_DATA_00   0x49   // R  
#define MPU9150_EXT_SENS_DATA_01   0x4A   // R  
#define MPU9150_EXT_SENS_DATA_02   0x4B   // R  
#define MPU9150_EXT_SENS_DATA_03   0x4C   // R  
#define MPU9150_EXT_SENS_DATA_04   0x4D   // R  
#define MPU9150_EXT_SENS_DATA_05   0x4E   // R  
#define MPU9150_EXT_SENS_DATA_06   0x4F   // R  
#define MPU9150_EXT_SENS_DATA_07   0x50   // R  
#define MPU9150_EXT_SENS_DATA_08   0x51   // R  
#define MPU9150_EXT_SENS_DATA_09   0x52   // R  
#define MPU9150_EXT_SENS_DATA_10   0x53   // R  
#define MPU9150_EXT_SENS_DATA_11   0x54   // R  
#define MPU9150_EXT_SENS_DATA_12   0x55   // R  
#define MPU9150_EXT_SENS_DATA_13   0x56   // R  
#define MPU9150_EXT_SENS_DATA_14   0x57   // R  
#define MPU9150_EXT_SENS_DATA_15   0x58   // R  
#define MPU9150_EXT_SENS_DATA_16   0x59   // R  
#define MPU9150_EXT_SENS_DATA_17   0x5A   // R  
#define MPU9150_EXT_SENS_DATA_18   0x5B   // R  
#define MPU9150_EXT_SENS_DATA_19   0x5C   // R  
#define MPU9150_EXT_SENS_DATA_20   0x5D   // R  
#define MPU9150_EXT_SENS_DATA_21   0x5E   // R  
#define MPU9150_EXT_SENS_DATA_22   0x5F   // R  
#define MPU9150_EXT_SENS_DATA_23   0x60   // R  
#define MPU9150_MOT_DETECT_STATUS  0x61   // R  
#define MPU9150_I2C_SLV0_DO        0x63   // R/W
#define MPU9150_I2C_SLV1_DO        0x64   // R/W
#define MPU9150_I2C_SLV2_DO        0x65   // R/W
#define MPU9150_I2C_SLV3_DO        0x66   // R/W
#define MPU9150_I2C_MST_DELAY_CTRL 0x67   // R/W
#define MPU9150_SIGNAL_PATH_RESET  0x68   // R/W
#define MPU9150_MOT_DETECT_CTRL    0x69   // R/W
#define MPU9150_USER_CTRL          0x6A   // R/W
#define MPU9150_PWR_MGMT_1         0x6B   // R/W
#define MPU9150_PWR_MGMT_2         0x6C   // R/W
#define MPU9150_FIFO_COUNTH        0x72   // R/W
#define MPU9150_FIFO_COUNTL        0x73   // R/W
#define MPU9150_FIFO_R_W           0x74   // R/W
#define MPU9150_WHO_AM_I           0x75   // R

//MPU9150 Compass
#define MPU9150_CMPS_XOUT_L        0x4A   // R
#define MPU9150_CMPS_XOUT_H        0x4B   // R
#define MPU9150_CMPS_YOUT_L        0x4C   // R
#define MPU9150_CMPS_YOUT_H        0x4D   // R
#define MPU9150_CMPS_ZOUT_L        0x4E   // R
#define MPU9150_CMPS_ZOUT_H        0x4F   // R


// I2C address 0x69 could be 0x68 depends on your wiring. 
int MPU9150_I2C_ADDRESS = 0x69;


//Variables where our values can be stored
int cmps[3];
int accl[3];
int gyro[3];
int temp;

void setup()
{      
  // Initialize the Serial Bus for printing data.
  Serial.begin(9600);

  // Initialize the 'Wire' class for the I2C-bus.
  Wire.begin();

  // Clear the 'sleep' bit to start the sensor.
  MPU9150_writeSensor(MPU9150_PWR_MGMT_1, 0);

  MPU9150_setupCompass();
}


void loop()
{
  // Print all sensor values which the sensor provides
  // Formated all values as x, y, and z in order for
  // Compass, Gyro, Acceleration. The First value is
  // the temperature.

  double dT = ( (double) MPU9150_readSensor(MPU9150_TEMP_OUT_L,MPU9150_TEMP_OUT_H) + 12412.0) / 340.0;
  Serial.print(dT);
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_CMPS_XOUT_L,MPU9150_CMPS_XOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_CMPS_YOUT_L,MPU9150_CMPS_YOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_CMPS_ZOUT_L,MPU9150_CMPS_ZOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_GYRO_XOUT_L,MPU9150_GYRO_XOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_GYRO_YOUT_L,MPU9150_GYRO_YOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_GYRO_ZOUT_L,MPU9150_GYRO_ZOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_ACCEL_XOUT_L,MPU9150_ACCEL_XOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_ACCEL_YOUT_L,MPU9150_ACCEL_YOUT_H));
  Serial.print("  ");
  Serial.print(MPU9150_readSensor(MPU9150_ACCEL_ZOUT_L,MPU9150_ACCEL_ZOUT_H));
  Serial.println();
  delay(100);
}

//http://pansenti.wordpress.com/2013/03/26/pansentis-invensense-mpu-9150-software-for-arduino-is-now-on-github/
//Thank you to pansenti for setup code.
void MPU9150_setupCompass(){
  MPU9150_I2C_ADDRESS = 0x0C;      //change Adress to Compass

  MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode
  MPU9150_writeSensor(0x0A, 0x0F); //SelfTest
  MPU9150_writeSensor(0x0A, 0x00); //PowerDownMode

  MPU9150_I2C_ADDRESS = 0x69;      //change Adress to MPU

  MPU9150_writeSensor(0x24, 0x40); //Wait for Data at Slave0
  MPU9150_writeSensor(0x25, 0x8C); //Set i2c address at slave0 at 0x0C
  MPU9150_writeSensor(0x26, 0x02); //Set where reading at slave 0 starts
  MPU9150_writeSensor(0x27, 0x88); //set offset at start reading and enable
  MPU9150_writeSensor(0x28, 0x0C); //set i2c address at slv1 at 0x0C
  MPU9150_writeSensor(0x29, 0x0A); //Set where reading at slave 1 starts
  MPU9150_writeSensor(0x2A, 0x81); //Enable at set length to 1
  MPU9150_writeSensor(0x64, 0x01); //overvride register
  MPU9150_writeSensor(0x67, 0x03); //set delay rate
  MPU9150_writeSensor(0x01, 0x80);

  MPU9150_writeSensor(0x34, 0x04); //set i2c slv4 delay
  MPU9150_writeSensor(0x64, 0x00); //override register
  MPU9150_writeSensor(0x6A, 0x00); //clear usr setting
  MPU9150_writeSensor(0x64, 0x01); //override register
  MPU9150_writeSensor(0x6A, 0x20); //enable master i2c mode
  MPU9150_writeSensor(0x34, 0x13); //disable slv4
}

////////////////////////////////////////////////////////////
///////// I2C functions to get easier all values ///////////
////////////////////////////////////////////////////////////

int MPU9150_readSensor(int addrL, int addrH){
  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addrL);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  byte L = Wire.read();

  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addrH);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  byte H = Wire.read();

  return (H<<8)+L;
}

int MPU9150_readSensor(int addr){
  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addr);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  return Wire.read();
}

int MPU9150_writeSensor(int addr,int data){
  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addr);
  Wire.write(data);
  Wire.endTransmission(true);

  return 1;
}

Divide the code into several parts and explain what each part means

Much of the code already has comments: that is the double-shashes, //
Lines such as

  Serial.print(MPU9150_readSensor(MPU9150_CMPS_XOUT_L,MPU9150_CMPS_XOUT_H));

Are executing a function, int MPU9150_readSensor(int addrL, int addrH){ which returns an integer value, hence the int prefix. It is your job to learn what a function is and how it works. Arduino comes with many example sketches to assist you in learning and the Internet is rich on tutorials.

IMO, such broad, nonspecific requests to explain entire sketches is a poor use of forum members time. It simply not how forums are suppose to work. However, your request sounded earnest, so I wanted to take a little time and respond in good faith. There are lots of toys out in Arduino land, mist comes with example sketches which can be loaded and "just work." Sometimes, a little Googling is necessary to find sample sketches. The best way to learn is to work with these sketches and when you see something like

///////////////////////////////////////////////////////
///////// I2C functions to get easier all values ///////////
////////////////////////////////////////////////////////////

Know that it is your responsibility to locate, read, and understand what is happening. Only after you do your homework will something like

int MPU9150_readSensor(int addrL, int addrH){
  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addrL);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  byte L = Wire.read();

  Wire.beginTransmission(MPU9150_I2C_ADDRESS);
  Wire.write(addrH);
  Wire.endTransmission(false);

  Wire.requestFrom(MPU9150_I2C_ADDRESS, 1, true);
  byte H = Wire.read();

  return (H<<8)+L;
}

Make sense.

Ray

APSron:
Can I do the following:
connect Bluetooth to arduino so that the arduino is connected with the cell phone, and using what arduino cell phone message send SMS?

And I steel need help with the code

Yes. Take a look at BTInterface Android app. If you buy a bluetooth module, such as HC05 or HV06, then you could send commands over serial that have BTInterface send SMS for you via the paired smartphone. You can also have SMS coming in, with a keyword, that passes the commands to Arduino over bluetooth and allow you to control from a remote location via SMS.

You can also do other things, like give your Arduino a voice via the phone text to speech engine, and also configure and control an on screen interface to use with your sketch.

http://ww.btinterface.com
http://www.btinterface.com/BTInterface/forum/ - for help and examples

Hello,
I want to send a Word file by e-mail,
Which will be listed:
"Man fell,
Its location is:
Google Maps = ,
"
The LAT-and-LONG I'll change with the coordination that the GPS will give, is it possible?
My code is:

int serInLen = 25;
char serInString[25];
int pId =0;
int result;

void setup() 
{ 
  Serial.begin(9600); 
  Serial.println("#S|SPXL|[]#");        // start EXCEL
  pId= atoi(serInString);               // convert result to integer 
  sendPotValues();                       // send some data to Excell
} 
 
void loop() 
{ 
   //analogValue= random(0,1023);
   //logData(analogValue);
   //delay(5000); 
} 

void sendPotValues() 
{
   char buffer[5];
   int potValue1;
   int potValue2;
   
     //Read the two pot values - could be any sensor value or whatever
     potValue1=analogRead(1);
     potValue2=analogRead(2);
  
    //Send the values as though it was typed into Excell, using the SENDK command
    // This is the total line that is send: #S,SENDK,[pId; potValue1 {TAB} potValue2 {DOWN} {LEFT} ]#
     Serial.print("#S|SENDK|[");
     Serial.print(itoa((pId), buffer, 10));
     Serial.print("&");
     Serial.print(itoa((potValue1), buffer, 10));
     Serial.print(" {TAB} ");
     Serial.print(itoa((potValue2), buffer, 10));
     Serial.print(" {DOWN} ");
     Serial.print(" {LEFT} ");
     Serial.println("]#");
     // wait up to 1000 ms for answer from Gobetwino, answer will be in serInString, answer is 0 if all is OK
     //Deal with answer here - omitted in this example
     delay(2000);
  
  // Now we have sent the 2 pot values 15 times, so save and close the XL sheet.
 Serial.print("#S|SENDK|[");
 Serial.print(itoa((pId), buffer, 10));
 Serial.print("& ");
 Serial.print("^{s}%{F4}");  //=   ALT f   ALT g  = save and exit in danish Excell
 Serial.println("]#");
 // Wait 2 seconds for the save to finish
 delay(2000);
 // wait up to 1000 ms for answer from Gobetwino, answer will be in serInString, answer is 0 if all is OK
 // Next e-mail the XL sheet to someone
 Serial.println("#S|MXL|[]#");
 // wait up to 1000 ms for answer from Gobetwino, answer will be in serInString, answer is 0 if all is OK
}

.. is it possible?

@APSron:
I spend hours a week in the forums trying to assist with pointing Ops in the correct direction to "help themselves". Many, many other members do the same. We generally avoid a simple "Yes or No" and try and provide the appropriate Yes or No along with further information often as links for additional study by the Op. Sometimes with posted code and full explanations, we may actually provide specific, corrective instructions or code.

Our efforts, however, simply fall short when confronted by questions such as yours. "Yes" is not satisfying you and subsequent responses such as "an u explain me that code?" clearly states that your current knowledge is not satisfactory to understand a response.

I think you are looking for a "turn key" product that is complete that simply requires you to complete a few menu choices, or change a line in code, and then to have a working system. This then becomes a purchasing question and not a project inquiry since your present level of understanding will not permit you to assemble and code your own solution.

Ray

I have one question, how can I do a few sentences?
Can I get code example?
Because when I tried to change the code above for some reason it continued to print the data and not the sentences

Good evening,
I currently have two codes that each works alone, but because I'm trying to combine them are not working ...
I want the end to be registered
Father / Mother fell

  • Web link.
 #include <SoftwareSerial.h>

SoftwareSerial gpsSerial(10, 11); // RX, TX (TX not used)
const int sentenceSize = 80;

char sentence[sentenceSize];

void setup()
{
  Serial.begin(9600);
  gpsSerial.begin(9600);
}

void loop()
{
  static int i = 0;
  if (gpsSerial.available())
  {
    char ch = gpsSerial.read();
    if (ch != '\n' && i < sentenceSize)
    {
      sentence[i] = ch;
      i++;
    }
    else
    {
     sentence[i] = '\0';
     i = 0;
     displayGPS();
    }
  }
}

void displayGPS()
{
  char field[20];
  getField(field, 0);
  if (strcmp(field, "$GPRMC") == 0)
  {
    int a;
   double  num,num1;
    char cr;
    Serial.print("Lat: ");
   getField(field, 3);  // number
    num = atof(field);
    num=num-3200;
    num=32+num/60;
    Serial.print(num);
    getField(field, 4); // N/S
    Serial.print(field);
    Serial.print(" Long: ");
    getField(field, 5);  // number
    num1 = atof(field);
    num1=num1-3400;
    num1=34+num1/60;
    Serial.print(num1);
    getField(field, 6);  // E/W
    Serial.println("https://maps.google.com/?ll=") ;   Serial.println(num,10);    Serial.println(","); Serial.println(num1,10);   
  }
}
void getField(char* buffer, int index)
{
  int sentencePos = 0;
  int fieldPos = 0;
  int commaCount = 0;
  while (sentencePos < sentenceSize)
  {
    if (sentence[sentencePos] == ',')
    {
      commaCount ++;
      sentencePos ++;
    }
    if (commaCount == index)
    {
      buffer[fieldPos] = sentence[sentencePos];
      fieldPos ++;
    }
    sentencePos ++;
  }
  buffer[fieldPos] = '\0';
}

and

the last code:

APSron:
i have that code (Arduino Playground - HomePage)
can u explain me that code?
Divide the code into several parts and explain what each part means

// MPU-9150 Accelerometer + Gyro + Compass + Temperature

// MPU-9150 Accelerometer + Gyro + Compass + Temperature

#include <Wire.h>

// Register names according to the datasheet.
// According to the InvenSense document
// "MPU-9150 Register Map and Descriptions Revision 4.0",

#define MPU9150_SELF_TEST_X        0x0D  // R/W
#define MPU9150_SELF_TEST_Y        0x0E  // R/W
#define MPU9150_SELF_TEST_X        0x0F  // R/W

Just wanted to point out the error ... in the three lines above, the last should be

#define MPU9150_SELF_TEST_Z        0x0F  // R/W