![]() ![]() In the loop() we will start with the Wire.beginTransmission() function which will begin the transmission to the particular sensor, the 3 Axis Accelerometer in our case. The Wire.begin() function will initiate the Wire library and also we need to initiate the serial communication because we will use the Serial Monitor to show the data from the sensor. Here first we have to define the sensor address and the two internal registers addresses that we previously found. ![]() So we will use the Arduino Wire Library which has to be include in the sketch. Now let’s make the code that will get the data for the X axis. From the datasheet of the sensor, we can see that data for the X axis is actually stored in two registers, DATAX0 with a hexadecimal address 0x32 and DATAX1 with a hexadecimal address 0x33. For example if we want to read the data for the X axis from the 3 Axis Accelerometer sensor of the GY-80 breakout board, we need to find the internal register address where the data of the X axis is stored. So here if we upload and run that sketch, we will get the addresses of the connected devices on the I2C bus.ģ Axis Accelerometer Analog Devices ADX元45 0x53 Datasheetģ Axis GyroST Microelectronics 元G4200D 0圆9 Datasheetģ Axis Magnetometer Honeywell MC5883L 0x1E Datasheetīarometer + Thermometer Bosch BMP085 0x77 DatasheetĪfter we have found the addresses of the devices we also need to find the addresses of their internal registers in order to read the data from them. We can also get or check the addresses using the Arduino I2C Scanner sketch which can be found from the Arduino official website. See Also Arduino and MPU6050 Accelerometer and Gyroscope Tutorialįor the GY-521 breakout board we have only one address and that’s a hexadecimal 0圆8. So we can get data from 8 different sensors with just two wires with the I2C bus. ExampleĪs an example I will use the GY-80 breakout board which consists 5 different sensors and the GY-521 breakout board which consists 3 different sensors. After the data is completely sent, the transfer will end with a stop condition which occurs when the SDA line goes from low to high while the SCL line is high. These addresses can be found from datasheet of the sensor.Īfter the addressing, the data transfer sequences begin either from the master or the slave depending of the selected mode at the R/W bit. So if we want to read the data of the X-axis, first we need to send the device address and then the particular internal register address for the X-axis. ![]() For example the ADX345 Accelerometer has a unique device address and addition internal registers addresses for the X, Y and Z axis. The internal registers are locations in the slave’s memory containing various information or data. Next is the internal registers addressing. The device addressing sequence stars with the most significant bit (MSB) first and ends with the least significant bit (LSB) and it’s actually composed of 7 bits because the 8 th bit is used for indicating whether the master will write to the slave (logic low) or read from it (logic high). After this the clock starts and each data bit is transferred during each clock pulse. The start condition occurs when data line drops low while the clock line is still high. Let’s take even closer look at these events. Right after the addressing sequences follows the data sequences as many until the data is completely sent and it ends with a special stop condition. After the first Acknowledge bit in most cases comes another addressing sequence but this time for the internal registers of the slave device. After each 8 bits sequence follows a bit called Acknowledge. So after a special start condition occurs comes the first 8 bits sequence which indicates the address of the slave to which the data is being sent. The data signal is transferred in sequences of 8 bits.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |