embeded/arduino(genuino)2016. 4. 6. 23:41



 

예전에 가지고 있던 녀석으로 구워볼려고 했더니..

프로그래머 이녀석은... 굽는 용도가 아닌가? 안되지 왜?

(어쩌면 보드를 정해줘서 그런걸지도..)


아무튼 STK500 개발보드로 하니 USBISP로 구워진다

[링크 : http://www.us-technology.co.kr/product/product_main.asp?mode=5&smode=5]



근데.. 메시지가 머이리 길어?

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500 -PCOM6 -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDA:m -Ulfuse:w:0xFF:m


avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2009 Joerg Wunsch


         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"


         Using Port                    : COM6

         Using Programmer              : stk500

         AVR Part                      : ATmega328P

         Chip Erase delay              : 9000 us

         PAGEL                         : PD7

         BS2                           : PC2

         RESET disposition             : dedicated

         RETRY pulse                   : SCK

         serial program mode           : yes

         parallel program mode         : yes

         Timeout                       : 200

         StabDelay                     : 100

         CmdexeDelay                   : 25

         SyncLoops                     : 32

         ByteDelay                     : 0

         PollIndex                     : 3

         PollValue                     : 0x53

         Memory Detail                 :


                                  Block Poll               Page                       Polled

           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack

           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------

           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff

           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff

           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00


         Programmer Type : STK500V2

         Description     : Atmel STK500

         Programmer Model: AVRISP

         Hardware Version: 2

         Firmware Version Master : 2.10

         Vtarget         : 5.0 V

         SCK period      : 43.5 us


avrdude: AVR device initialized and ready to accept instructions


Reading | ################################################## | 100% 0.09s


avrdude: Device signature = 0x1e950f

avrdude: erasing chip

avrdude: reading input file "0x3F"

avrdude: writing lock (1 bytes):


Writing | ################################################## | 100% 0.04s


avrdude: 1 bytes of lock written

avrdude: verifying lock memory against 0x3F:

avrdude: load data lock data from input file 0x3F:

avrdude: input file 0x3F contains 1 bytes

avrdude: reading on-chip lock data:


Reading | ################################################## | 100% 0.03s


avrdude: verifying ...

avrdude: 1 bytes of lock verified

avrdude: reading input file "0x05"

avrdude: writing efuse (1 bytes):


Writing | ################################################## | 100% 0.03s


avrdude: 1 bytes of efuse written

avrdude: verifying efuse memory against 0x05:

avrdude: load data efuse data from input file 0x05:

avrdude: input file 0x05 contains 1 bytes

avrdude: reading on-chip efuse data:


Reading | ################################################## | 100% 0.03s


avrdude: verifying ...

avrdude: 1 bytes of efuse verified

avrdude: reading input file "0xDA"

avrdude: writing hfuse (1 bytes):


Writing | ################################################## | 100% 0.03s


avrdude: 1 bytes of hfuse written

avrdude: verifying hfuse memory against 0xDA:

avrdude: load data hfuse data from input file 0xDA:

avrdude: input file 0xDA contains 1 bytes

avrdude: reading on-chip hfuse data:


Reading | ################################################## | 100% 0.03s


avrdude: verifying ...

avrdude: 1 bytes of hfuse verified

avrdude: reading input file "0xFF"

avrdude: writing lfuse (1 bytes):


Writing | ################################################## | 100% 0.03s


avrdude: 1 bytes of lfuse written

avrdude: verifying lfuse memory against 0xFF:

avrdude: load data lfuse data from input file 0xFF:

avrdude: input file 0xFF contains 1 bytes

avrdude: reading on-chip lfuse data:


Reading | ################################################## | 100% 0.02s


avrdude: verifying ...

avrdude: 1 bytes of lfuse verified


avrdude done.  Thank you.


C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -cstk500 -PCOM6 -Uflash:w:C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:i -Ulock:w:0x0F:m 


avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2009 Joerg Wunsch


         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"


         Using Port                    : COM6

         Using Programmer              : stk500

         AVR Part                      : ATmega328P

         Chip Erase delay              : 9000 us

         PAGEL                         : PD7

         BS2                           : PC2

         RESET disposition             : dedicated

         RETRY pulse                   : SCK

         serial program mode           : yes

         parallel program mode         : yes

         Timeout                       : 200

         StabDelay                     : 100

         CmdexeDelay                   : 25

         SyncLoops                     : 32

         ByteDelay                     : 0

         PollIndex                     : 3

         PollValue                     : 0x53

         Memory Detail                 :


                                  Block Poll               Page                       Polled

           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack

           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------

           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff

           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff

           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00

           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00

           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00


         Programmer Type : STK500V2

         Description     : Atmel STK500

         Programmer Model: AVRISP

         Hardware Version: 2

         Firmware Version Master : 2.10

         Vtarget         : 5.0 V

         SCK period      : 43.5 us


avrdude: AVR device initialized and ready to accept instructions


Reading | ################################################## | 100% 0.09s


avrdude: Device signature = 0x1e950f

avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.

avrdude: erasing chip

avrdude: reading input file "C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex"

avrdude: writing flash (32670 bytes):


Writing | ################################################## | 100% 0.00s


avrdude: 32670 bytes of flash written

avrdude: verifying flash memory against C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:

avrdude: load data flash data from input file C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex:

avrdude: input file C:\Program Files (x86)\Arduino\hardware\arduino\avr/bootloaders/atmega/ATmegaBOOT_168_atmega328.hex contains 32670 bytes

avrdude: reading on-chip flash data:


Reading | ################################################## | 100% 0.00s


avrdude: verifying ...

avrdude: 32670 bytes of flash verified

avrdude: reading input file "0x0F"

avrdude: writing lock (1 bytes):


Writing | ################################################## | 100% 0.09s


avrdude: 1 bytes of lock written

avrdude: verifying lock memory against 0x0F:

avrdude: load data lock data from input file 0x0F:

avrdude: input file 0x0F contains 1 bytes

avrdude: reading on-chip lock data:


Reading | ################################################## | 100% 0.04s


avrdude: verifying ...

avrdude: 1 bytes of lock verified


avrdude done.  Thank you. 


Posted by 구차니
embeded/arduino(genuino)2016. 4. 6. 22:59

헐.. 설정이 문제가 아니었나 -ㅁ-?!?!


시리얼 포트를 통해서는 이런 메시지가(115k)

 NON GENUINE DEVICE FOUND! NON GENUINE DEVICE FOUND! 


구을려고 하면 아래와 같은 메시지가 나온다.

avrdude: Version 6.0.1, compiled on Apr 15 2015 at 19:59:58

         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/

         Copyright (c) 2007-2009 Joerg Wunsch


         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"


         Using Port                    : COM6

         Using Programmer              : arduino

         Overriding Baud Rate          : 57600

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x43

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x45

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x20

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x46

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x4f

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x55

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x4e

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x44

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x21

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20 


얘는 내가 쓰던 usbisp 인데.. 이렇게 나오고..


안구워지는 녀석은.. 이렇게


구워지는 놈은 이렇게... 어?


윈도우 드라이버가 의심되서 봐도 머.. 둘다 상관없네




[링크 : http://www.instructables.com/id/A-solution-to-avrdude-stk500getsync-not-in-syn/]

[링크 : https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader]

[링크 : http://electropit.com/index.php/2015/09/06/arduino-nano-v3-0-clones/]

[링크 : http://internetofhomethings.com/homethings/?tag=not-genuine-device-found]

[링크 : http://www.ftdichip.com/Support/Utilities.htm#FT_PROG]



일단.. 위에 내용을 덮어 쓰고 하니까.

새로운 포트로 잡히고 나서 구워진다.. 머지?


16진수 값으로도 가장 마지막 비트가 먼가 이상한게 씌어져 있을때는 안되었고(무슨값인진..)

0000 으로 되어 있으니 되는걸 봐서는..

의심가는 건.. hardware specific 하위의 RS232와 IO 컨트롤 관련 셋팅..



Posted by 구차니
embeded/arduino(genuino)2016. 4. 6. 20:01

라즈베리는 3.3v 일테고

아두이노는 5v 일텐데.. 그냥 연결해도 되려나?

라즈베리 날려먹긴 싫은데.. 레벨 시프터 사야하나 ㅠㅠ


[링크 : https://www.eleparts.co.kr/EPX8MXNR] 6천원... ㅠㅠ


일단은...

아래는 3.3V 짜리를 5V인 아두이노에서 쓰는거지만...

[링크 : http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter]

2016/04/01 - [embeded/arduino(genuino)] - 아두이노 level shift / MPU-6050


The Raspberry Pi is running at 3.3 Volts while the Arduino is running at 5 Volts. There are tutorials suggest using a level converter for the I2C communication. This is NOT needed if the Raspberry Pi is running as “master” and the Arduino is running as “slave”.


The reason it works is because the Arduino does not have any pull-ups resistors installed, but the P1 header on the Raspberry Pi has 1k8 ohms resistors to the 3.3 volts power rail. Data is transmitted by pulling the lines to 0v, for a “high” logic signal. For “low” logic signal, it’s pulled up to the supply rail voltage level. Because there is no pull-up resistors in the Arduino and because 3.3 volts is within the “low” logic level range for the Arduino everything works as it should.

[링크 : http://blog.oscarliang.net/raspberry-pi-arduino-connected-i2c/]

    [링크 : http://dsscircuits.com/articles/effects-of-varying-i2c-pull-up-resistors]

[링크 : http://blog.retep.org/2014/02/15/connecting-an-arduino-to-a-raspberry-pi-using-i2c/]




걍.. 과감하게(?) atmega 녀석들이 대부분 2.8V~5.5V 니까 3.3V로 주면 안되려나?


Operating Voltage:

1.8 - 5.5V


TWI(I2C)쪽 입력 전압은 Vcc + 0.5 니까.. 3.3V 주면은.. 어떻게 안되려나?

그나저나.. 0.3V~0.7V 로 무지 좁네..



[링크 : http://www.atmel.com/...atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet_complete.pdf]

Posted by 구차니
embeded/arduino(genuino)2016. 4. 1. 16:40

음.. 우리나라가 미친듯 비싸게 파는걸려나..


The MPU-6050 is not expensive, especially given the fact that it combines both an accelerometer and a gyro.

[링크 : http://playground.arduino.cc/Main/MPU-6050]



어라.. 3.3V 짜리인 i2c 장비를 레벨 쉬프트 하지 않고 쓸수가 있나보네?


[링크 : http://playground.arduino.cc/Main/I2CBi-directionalLevelShifter]

Posted by 구차니
embeded/arduino(genuino)2016. 3. 31. 20:25

temperature = (ADCW - 324.31) / 1.22


[링크 : http://playground.arduino.cc/Main/InternalTemperatureSensor]





[링크 : http://www.atmel.com/images/...328p_datasheet_complete.pdf]

Posted by 구차니
embeded/arduino(genuino)2016. 3. 31. 19:03

엥? winavr에서도 안되었던가??

급 멘붕 ㄷㄷ


char *dtostrf(double val, signed char width, unsigned char prec, char *s)


Use this method to convert it to a C-Style string and then use sprintf, eg:


char str_temp[6];


/* 4 is mininum width, 2 is precision; float value is copied onto str_temp*/

dtostrf(temp, 4, 2, str_temp);

sprintf(temperature,"%s F", str_temp);

[링크 : http://stackoverflow.com/questions/27651012/arduino-sprintf-float-not-formatting]

[링크 : http://forum.arduino.cc/index.php?topic=175478.0]


[링크 : http://whiteat.com/bPDS_AVR/28406]

Posted by 구차니
embeded/arduino(genuino)2016. 3. 31. 10:30

필터는 나중에 적용하고..

걍.. atan()만 쓰면 끝나나?



double x_angle = -atan((double)ay/(double)az)*180.0 / 3.1416;

[링크 : http://hs36.tistory.com/19]


[링크 : http://pinkwink.kr/73]

[링크 : http://mechaworld.tistory.com/11]



+


2016/04/06 - [이론 관련] - 가속도계로 각도계산하기


Posted by 구차니
embeded/arduino(genuino)2016. 3. 31. 09:51

음.. 이제 좀 마음에 들게 되긴했는데..

각도를 어떻게 받고. 어떤 각도를 계산해야 하려나..


#include <avr/io.h>
#include <Wire.h>

#define I2C_ID  0x53 // ADXL-345

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();

  // adxl345 initialize
  // power setting
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x2d));
    Wire.write(byte(0x18));
  Wire.endTransmission();

  // range setting
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x31));
    Wire.write(byte(0x09));
  Wire.endTransmission();
}

void loop() {
  // put your main code here, to run repeatedly:
  char str[30];
  char data[6];
  unsigned char idx = 0;
  short acc_x;
  short acc_y;
  short acc_z;

  // data request
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x32));
  Wire.endTransmission();
  Wire.requestFrom(0x53, 6);

  idx = 0;
  while (Wire.available())
    data[idx++] = Wire.read();

  acc_x = (data[1] << 8) | data[0];
  acc_y = (data[3] << 8) | data[2];
  acc_z = (data[5] << 8) | data[4];

  sprintf(str,"x:%6d y:%6d z:%6d",acc_x, acc_y, acc_z);
  Serial.println(str);

  delay(100);
}



FULL_RES 끄고(10bit output / 0~1023) +-16g로 출력

#include <avr/io.h>
#include <math.h>
#include <Wire.h>

#define I2C_ID  0x53 // ADXL-345

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();

  // adxl345 initialize
  // power setting
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x2d));
    Wire.write(byte(0x18));
  Wire.endTransmission();

  // range setting
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x31));
    Wire.write(byte(0x03));
  Wire.endTransmission();
}

void loop() {
  // put your main code here, to run repeatedly:
  char str[30];
  char data[6];
  unsigned char idx = 0;
  short acc_x;
  short acc_y;
  short acc_z;
  double deg_x;
  double deg_y;

  // data request
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x32));
  Wire.endTransmission();
  Wire.requestFrom(0x53, 6);

  idx = 0;
  while (Wire.available())
    data[idx++] = Wire.read();

  acc_x = (data[1] << 8) | data[0];
  acc_y = (data[3] << 8) | data[2];
  acc_z = (data[5] << 8) | data[4];

  if(acc_z == 0)
  {
    deg_x = 0.0;
    deg_y = 0.0;
  }
  else
  {
    deg_x = atan((double)acc_x / (double)acc_z) * 57.2957;
    deg_y = atan((double)acc_y / (double)acc_z) * 57.2957;
  }
  
  sprintf(str,"x:%6d y:%6d z:%6d",acc_x, acc_y, acc_z);
  Serial.println(str);
  
  sprintf(str,"x:%d y:%d",(short)deg_x, (short)deg_y);
  Serial.println(str);

  delay(100);
}



#include <avr/io.h>
#include <math.h>
#include <Wire.h>

#define I2C_ID  0x53 // ADXL-345

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  Wire.begin();

  // adxl345 initialize
  // power setting
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x2d));
    Wire.write(byte(0x18));
  Wire.endTransmission();

  // range setting
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x31));
    Wire.write(byte(0x02));
  Wire.endTransmission();
}

void loop() {
  // put your main code here, to run repeatedly:
  char str[30];
  char str_x[15];
  char str_y[15];
  char data[6];
  unsigned char idx = 0;
  short acc_x;
  short acc_y;
  short acc_z;
  double deg_x;
  double deg_y;

  // data request
  Wire.beginTransmission(I2C_ID);
    Wire.write(byte(0x32));
  Wire.endTransmission();
  Wire.requestFrom(0x53, 6);

  idx = 0;
  while (Wire.available())
    data[idx++] = Wire.read();

  acc_x = (data[1] << 8) | data[0];
  acc_y = (data[3] << 8) | data[2];
  acc_z = (data[5] << 8) | data[4];

  if(acc_z == 0)
  {
    deg_x = 0.0;
    deg_y = 0.0;
  }
  else
  {
    deg_x = atan((double)acc_x / (double)acc_z) * 57.2957;
    deg_y = atan((double)acc_y / (double)acc_z) * 57.2957;
  }
  
  sprintf(str,"x:%6d y:%6d z:%6d",acc_x, acc_y, acc_z);
  Serial.println(str);

  dtostrf(deg_x, 4,2, str_x);
  dtostrf(deg_y, 4,2, str_y);
  sprintf(str,"x:%s y:%s",str_x, str_y);
  Serial.println(str);

  delay(100);
}


Posted by 구차니
embeded/arduino(genuino)2016. 3. 30. 19:38

이걸 한번... 아두이노 용으로 변환해서 해봐야지..

일단 0x53이고

파워업 리셋시 센서 작동하지 않으므로


Rate는 0x0A(1010b)로 설정되어 100Hz 표준 i2c 속도의 출력 속도에 맞춰 지는건가?


0x2d 레지스터에 0x18을 넣어

AUTO_SLEEP 과 Measure를 설정해 값을 측정하도록 한다.

AUTO_SLEEP은 좀더 봐야 할 듯


0x31에서는 측정할 가속도의 범위를 설정하는데

기본값은 0x00으로 Range +-2g를 측정하게 된다.

+

2016.03.31

FULL_RES=1의 경우 무조건 4mg=1 로 계산되고 Range에 영향을 받아 출력되는 범위가 달라진다.

예를 들어 +2g로 Range 설정시 256으로 출력되며 1g(4mg*256=1024mg=1g) 흔들어서나오는 값이

+-512를 넘지 못한다(512*4=2048=2g)


FULL_RES=0의 경우 Range를 0x03으로 하면 8g이고 32값이 나오게 된다(1g에 대한 값)

즉, 최대 범위에 대해서 0~1023으로 scaling된 값이 나오게 된다.

+


그리고는 0x32~0x37까지 6바이트에 대해서 x,y,z 축에 대한 값을 받아 온다.

DATAX0이 LSB쪽

DATAX1이 MSB쪽이다.


#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <iostream>

int main(int argc, char **argv)
{
   printf("**** ADXL435 example program ****\n");
   
   int fd;                                          // File descrition
   char *fileName = "/dev/i2c-1";                        // Name of the port we will be using
   int  address = 0x53;                              // Address of the SRF02 shifted right one bit
   char buf[6];                              // Buffer for data being read/ written on the i2c bus
   short x,y,z;

   if ((fd = open(fileName, O_RDWR)) < 0) {               // Open port for reading and writing
      printf("Failed to open i2c port\n");
      exit(1);
   }
   
   if (ioctl(fd, I2C_SLAVE, address) < 0) {               // Set the port options and set the address of the device we wish to speak to
      printf("Unable to get bus access to talk to slave\n");
      exit(1);
   }

   buf[0] = 0x2d;                                       // Commands for performing a ranging
   buf[1] = 0x18;
   
   if ((write(fd, buf, 2)) != 2) {                        // Write commands to the i2c port
      printf("Error writing to i2c slave\n");
      exit(1);
   }

   buf[0] = 0x31;                                       // Commands for performing a ranging
   buf[1] = 0x09;
   
   if ((write(fd, buf, 2)) != 2) {                        // Write commands to the i2c port
      printf("Error writing to i2c slave\n");
      exit(1);
   }

                                       // This sleep waits for the ping to come back
while(true){   

   buf[0] = 0x32;                                       // This is the register we wish to read from
   if ((write(fd, buf, 1)) != 1) {                        // Send the register to read from
      printf("Error writing to i2c slave\n");
      exit(1);
   }
   

usleep(1000);
  memset(&buf,0,sizeof(buf));

   if (read(fd, buf, 6) != 6) {                        // Read back data into buf[]
      printf("Unable to read from slave\n");
      exit(1);
   }
   else { x=y=z=0;
//               memset(&buf,0,sizeof(buf));

      x = ((short)buf[1]<<8) | (short) buf[0]; 
       y = ((short)buf[3]<<8) | (short) buf[2];
       z = ((short)buf[5]<<8) | (short) buf[4];
       std::cout<<"x:"<<x<<"\ty:"<<y<<"\tz:"<<z<<std::endl;
   }
}
   return 0;

} 


2015/08/24 - [개소리 왈왈/라즈베리 파이(rpi)] - 라즈베리 파이 i2c ADXL345 3축 가속도 센서


값이 바뀌긴 한데 수치만으로는 헷갈리네..


#include <avr/io.h> #include <Wire.h> #define I2C_ID  0x53 // ADXL-345 void setup() {  // put your setup code here, to run once:  Wire.begin();  Serial.begin(9600); } void loop() {  // put your main code here, to run repeatedly:  char str[30];  char data[6];  unsigned char idx = 0;  short acc_x;  short acc_y;  short acc_z;  // power setting  Wire.beginTransmission(I2C_ID);    Wire.write(byte(0x2d));    Wire.write(byte(0x18));  Wire.endTransmission();  // range setting  Wire.beginTransmission(I2C_ID);    Wire.write(byte(0x31));    Wire.write(byte(0x09));  Wire.endTransmission();  // data request  Wire.beginTransmission(I2C_ID);    Wire.write(byte(0x32));  Wire.endTransmission();  Wire.requestFrom(0x53, 6);  idx = 0;  while (Wire.available())    data[idx++] = Wire.read();  acc_x = (data[1] << 8) | data[0];  acc_y = (data[3] << 8) | data[2];  acc_z = (data[5] << 8) | data[4];  sprintf(str,"x:%6d y:%6d z:%6d",acc_x, acc_y, acc_z);  Serial.println(str);  delay(100); }


#include <avr/io.h> #include <Wire.h> #define I2C_ID  0x53 // ADXL-345 void setup() {  // put your setup code here, to run once:  Wire.begin();  Serial.begin(115200); } void loop() {  // put your main code here, to run repeatedly:  char str[30];  char data[6];  unsigned char idx = 0;  short acc_x;  short acc_y;  short acc_z;  sprintf(str,"%c%c",0x2d,0x18);  // power setting  Wire.beginTransmission(I2C_ID);    Wire.write(str);  Wire.endTransmission();  sprintf(str,"%c%c",0x31,0x09);  // range setting  Wire.beginTransmission(I2C_ID);    Wire.write(str);  Wire.endTransmission();  sprintf(str,"%c",0x32);         // data request  Wire.beginTransmission(I2C_ID);    Wire.write(str);  Wire.endTransmission();  Wire.requestFrom(0x53, 6);  idx = 0;  while (Wire.available())    data[idx++] = Wire.read();  acc_x = (data[1] << 8) | data[0];  acc_y = (data[3] << 8) | data[2];  acc_z = (data[5] << 8) | data[4];  sprintf(str,"x:%6d y:%6d z:%6d",acc_x, acc_y, acc_z);  Serial.println(str);  delay(100); }


먼가 값은 나온다.


A4 -> SDA

A5 -> SCL

5V -> VCC

GND -> GND

이렇게 4줄 연결 하고 끝


이제 이걸.. 수학 공식을 이용해서 각도로 계산을 어떻게 한다냐...

'embeded > arduino(genuino)' 카테고리의 다른 글

가속도계 각도 계산..  (2) 2016.03.31
아두이노 nano + ADXL345  (0) 2016.03.31
아두이노 나노 pinout / atmega328p  (0) 2016.03.30
아두이노 avr 헤더사용하기 / PUD  (0) 2016.03.30
아두이노 / avr bootloader  (0) 2016.03.30
Posted by 구차니
embeded/arduino(genuino)2016. 3. 30. 16:58

얘네는 디지털 핀 쪽

Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.

        These pins are connected to the corresponding pins of the FTDI USB-to-TTL Serial chip.

External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low value,

                      a rising or falling edge, or a change in value. See the attachInterrupt() function for details.

PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication, which,

      although provided by the underlying hardware, is not currently included in the Arduino language.

LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on,

           when the pin is LOW, it's off.


얘는 아날로그 핀 쪽

I2C: A4 (SDA) and A5 (SCL). Support I2C (TWI) communication using the Wire library

      (documentation on the Wiring website).

[링크 : https://www.arduino.cc/en/Main/ArduinoBoardNano]





[링크 : https://www.arduino.cc/en/uploads/Main/ArduinoNanoManual23.pdf]


일단.. I2C는 1채널뿐이군

SPI: 2

TWI (I2C): 1

UART: 1

ADC Channels: 8

ADC Resolution (bits): 10

ADC Speed (ksps): 15

Temp. Sensor: Yes

SRAM (kBytes): 2

EEPROM (Bytes): 1024

Self Program Memory: Yes

Timers: 3


[링크 : http://www.atmel.com/devices/atmega328p.aspx]

'embeded > arduino(genuino)' 카테고리의 다른 글

아두이노 nano + ADXL345  (0) 2016.03.31
ADXL345 소스 분석 및 아두이노 용으로 변환  (0) 2016.03.30
아두이노 avr 헤더사용하기 / PUD  (0) 2016.03.30
아두이노 / avr bootloader  (0) 2016.03.30
arduino i2c 예제  (0) 2016.03.30
Posted by 구차니