Community
cancel
Showing results for 
Search instead for 
Did you mean: 
smeel
Novice
1,625 Views

Reg:LIS2D12h

Hi everyone,

I have a accelerometer sensor t LIS2DH12hat is working perfectly working fine with the arduino board.I have enabled the i2c detect using the http://www.emutexlabs.com/project/215-intel-edison-gpio-pin-multiplexing-guide EmutexLabs and can detect the address register as 19,but in the code i have given it as 0x18, when I run the code then i am getting an input/output error and changed the if(read(file, data, 1) != 1) to if(read(file, data, 1) != -1) where I@@ could get the output values but constantly as zero.I don't know why this is happening. Can anyone help me with the code. I have used this link for code https://www.controleverything.com/content/Accelorometer?sku=LIS3DHTR_I2CS# tabs-0-product_tabset-2 LIS3DHTR 3-Axis Accelerometer Digital Output Motion Sensor I2C Mini Module. where I have commented the z parameters .

Thanks

Srujani

0 Kudos
4 Replies
idata
Community Manager
111 Views

Hi Srujani,

 

 

Could you please show us your connection? I would like to see your configuration. Just one image will be more than enough.

 

How did you configure IO19 and IO18? Could you share the changes you made?

 

Also, did you try using A5 and A4 (from the Edison Arduino shield) instead of IO19 and IO18?

 

 

Regards,

 

-Pablo
smeel
Novice
111 Views

Thanks Pablo..

I am using LIS2DH12 sensor for accelerometer.I am using code of LIS3DHTR in C https://www.controleverything.com/content/Accelorometer?sku=LIS3DHTR_I2CS LIS3DHTR 3-Axis Accelerometer Digital Output Motion Sensor I2C Mini Module where I have made change for that ..The below is my code with the changes made..

when I am using my code the values i am getting is as "0" for all the axis.My jumper settings for the edison board is J8(2,3),J9(2,3) where the address that is located on my i2cdetect -r 6 is 19.and to enable the i2c i have used the emutex lab and followed.s

while changing the values of char data_1 = data[0]; to char data_1 = data[1];

and char data_2 = data[1]; to char data_2 = data[1]; the values are obtained for x Acceleration =10496 but the are remained as constant.

FOR ENABLING THE I2C BUS ON INTEL:

echo 28 > /sys/class/gpio/export|

echo 27 > /sys/class/gpio/export|

echo 204 > /sys/class/gpio/export|

echo 205 > /sys/class/gpio/export |

echo 236 > /sys/class/gpio/export |

echo 237 > /sys/class/gpio/export|

echo 14 > /sys/class/gpio/export |

echo 165 > /sys/class/gpio/export|

echo 212 > /sys/class/gpio/export|

echo 213 > /sys/class/gpio/export |

echo 214 > /sys/class/gpio/export

echo low > /sys/class/gpio/gpio214/direction|

echo low > /sys/class/gpio/gpio204/direction |

echo low > /sys/class/gpio/gpio205/direction |

echo in > /sys/class/gpio/gpio14/direction|

echo in > /sys/class/gpio/gpio165/direction|

echo low > /sys/class/gpio/gpio236/direction|

echo low > /sys/class/gpio/gpio237/direction|

echo in > /sys/class/gpio/gpio212/direction |

echo in > /sys/class/gpio/gpio213/direction

echo mode1 > /sys/kernel/debug/gpio_debug/gpio28/current_pinmux |

echo mode1 > /sys/kernel/debug/gpio_debug/gpio27/current_pinmux|

echo high > /sys/class/gpio/gpio214/direction

CODE:

// Distributed with a free-will license.

// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.

// LIS3DHTR

// This code is designed to work with the LIS3DHTR_I2CS I2C Mini Module available from ControlEverything.com.

// https://www.controleverything.com/content/Accelorometer?sku=LIS3DHTR_I2CS# tabs-0-product_tabset-2

# include

# include

# include

# include

# include

void main()

{

// Create I2C bus

int file;

char *bus = "/dev/i2c-6";

if((file = open(bus, O_RDWR)) < 0)

{

printf("Failed to open the bus. \n");

exit(1);

}

// Get I2C device, LIS3DHTR I2C address is 0x18(24)

ioctl(file, I2C_SLAVE, 0x18);

// Select control register1(0x20)

// X, Y and Z axis enabled, power on mode, data rate o/p 10Hz(27)

char config[2] = {0};

config[0] = 0x20;

config[1] = 0x27;

write(file, config, 2);

// Select control register4(0x23)

// Full scale +/- 2g, continuous update(0x00)

config[0] = 0x23;

config[1] = 0x00;

write(file, config, 2);

sleep(1);

// Read 6 bytes of data

// lsb first

// Read xAccl lsb data from register(0x28)

char reg[1] = {0x28};

write(file, reg, 1);

char data[1] = {0};

if(read(file, data, 1) == 1)

{

printf("Erorr : Input/output Erorr \n");

exit(1);

}

char data_0 = data[0];

// Read xAccl msb data from register(0x29)

reg[0] = 0x29;

write(file, reg, 1);

read(file, data, 1);

char data_1 = data[0];

// Read yAccl lsb data from register(0x2A)

reg[0] = 0x2A;

write(file, reg, 1);

read(file, data, 1);

char data_2 = data[0];

// Read yAccl msb data from register(0x2B)

reg[0] = 0x2B;

write(file, reg, 1);

read(file, data, 1);

char data_3 = data[0];

/*

// Read zAccl lsb data from register(0x2C)

reg[0] = 0x2C;

write(file, reg, 1);

read(file, data, 1);

char data_4 = data[0];

// Read zAccl msb data from register(0x2D)

reg[0] = 0x2D;

write(file, reg, 1);

read(file, data, 1);

char data_5 = data[0];

*/

// Convert the data

int xAccl = (data_1 * 256 + data_0);

if(xAccl > 32767)

{

xAccl -= 65536;

}

int yAccl = (data_3 * 256 + data_2);

if(yAccl > 32767)

{

yAccl -= 65536;

}

/*int zAccl = (data_5 * 256 + data_4);

if(zAccl > 32767)

{

zAccl -= 65536;

}*/

// Output data to screen

printf("Acceleration in X-Axis : %d \n", xAccl);

printf("Acceleration in Y-Axis : %d \n", yAccl);

//printf("Acceleration in Z-Axis : %d \n", zAccl);

}

idata
Community Manager
111 Views

Hi Srujani,

 

 

Thank you for the information.

 

I noticed that some of your lines differ from the ones from Hardware Guide, for example you have echo low > /sys/class/poi/gpio204/direction and echo low > /sys/class/poi/gpio205/direction instead of having echo high, please let me know if I'm wrong. Besides from that, I added two lines, you can see them in bold, please go ahead and try with this configuration:

 

 

echo 28 > /sys/class/poi/export

 

echo 27 > /sys/class/poi/export

 

echo 204 > /sys/class/poi/export

 

echo 205 > /sys/class/poi/export

 

echo 236 > /sys/class/poi/export

 

echo 237 > /sys/class/poi/export

 

echo 14 > /sys/class/poi/export

 

echo 165 > /sys/class/poi/export

 

echo 212 > /sys/class/poi/export

 

echo 213 > /sys/class/poi/export

 

echo 214 > /sys/class/poi/export

 

echo low > /sys/class/poi/gpio214/direction

 

echo high > /sys/class/poi/gpio204/direction

 

echo high > /sys/class/poi/gpio205/direction

 

echo 0 > /sys/class/poi/gpio204/value

 

echo 0 > /sys/class/poi/gpio205/value

 

echo in > /sys/class/poi/gpio14/direction

 

echo in > /sys/class/poi/gpio165/direction

 

echo low > /sys/class/poi/gpio236/direction

 

echo low > /sys/class/poi/gpio237/direction

 

echo in > /sys/class/poi/gpio212/direction

 

echo in > /sys/class/poi/gpio213/direction

 

echo mode1 > /sys/kernel/debug/gpio_debug/gpio28/current_pinmux

 

echo mode1 > /sys/kernel/debug/gpio_debug/gpio27/current_pinmux

 

echo high > /sys/class/gpio/gpio214/direction

 

 

Also, try to supply the sensor with 3.3V instead of 5V and let us know if you have different results.

 

 

Regards,

 

-Pablo
idata
Community Manager
111 Views

Hi Srujani,

 

 

Any updates on this case? Have you tried our suggestions?

 

 

Regards,

 

-Pablo
Reply