Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 5945|回復: 6
打印 上一主題 下一主題

Arduino MEGA和G145陀螺儀連接問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2010-8-26 20:07:46 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
本帖最後由 chem0103 於 2010-8-27 11:53 編輯

大家好,小弟最近開始接觸Arduino.

目前是使用Arduino MAEG和G145陀螺儀
(規格書= RoBoard_RM-G145.pdf (577.37 KB) G145
下載次數: 2
19 小時前

)
現在測試遇到的問題是,跑出來的數值都是0.00

在猜想是不是地址選擇錯誤了,我是參考G144程式碼去修改的.

想請問MEGA的地址部分要去哪邊參照呢?或是程式碼本身有錯誤.

要麻煩大家提供意見了,謝謝.

現在硬體接線部分
SDA_21
SCL_20
Vcc_5V
GND_GND,使用USB供電,沒有外接電源.

程式碼部分如下,

複製代碼
  1. #include <Wire.h>

  2. byte Data[2]={0,0};
  3. float Pitch;

  4. void setup()
  5. {
  6. Wire.begin();
  7. Serial.begin(9600);
  8. }
  9. void loop()
  10. {
  11. Wire.beginTransmission(83);/*開始傳輸到I2C從設備與給定的地址*/
  12. Wire.send(0x21);/*發送數據到0x21*/
  13. Wire.endTransmission();/*結束傳輸*/
  14. Wire.requestFrom(83, 2);/*接收時須向模組告知我現在要接收兩個byte的資料
  15. */
  16. while(Wire.available()) /*等待模組回覆資料*/
  17. {
  18. Data[0]=Wire.receive();
  19. Data[1]=Wire.receive();

  20. }
  21. Pitch=(Data[1] <<8|Data[0]);

  22. Serial.println(Pitch);/*顯示資料*/

  23. delay(100);
  24. }
複製代碼

2#
發表於 2010-8-27 01:19:11 | 只看該作者
??
G145和144的位址根本不一樣啊
送出的控制碼也不相同耶

話說回來
你是?? 怎麼會說跟我拿的G-145?
3#
 樓主| 發表於 2010-8-27 11:52:14 | 只看該作者
本帖最後由 chem0103 於 2010-8-27 12:31 編輯

不好意思,我是有在六月跟您購買一些零件的台中楊同學。
mail:chem0103@hotmail.com
4#
發表於 2010-8-27 19:38:55 | 只看該作者
這是官網的C語言版本  http://www.roboard.com/G145.html
仔細看看她使用i2c0master_WriteN指令送的東西喔
你送的東西差很多哩
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <roboard.h>

//you need to change this function for Linux and DOS
void wait_ms(unsigned long ms) {
    unsigned long nowtime = GetTickCount();
    while ((GetTickCount() - nowtime) <= ms);
}

char *out_title[] ={"X-OUT","X45-OUT","Y-OUT","Y45-OUT","Z-OUT","Z45-OUT","IDG_Temp","ISZ_Temp"};

int main(void) {
        unsigned int i,d1,d2;
        unsigned char i2c_address,high,low;

        i2c_address = 0x21;

    // if you use RB-110, modify the parameter "RB_100" to "RB_110"
        roboio_SetRBVer(RB_100); // use RB-100

    if (i2c_Initialize(I2CIRQ_DISABLE) == false)
    {
                printf("FALSE!!  %s\n", roboio_GetErrMsg());
                return -1;
        }

        i2c0_SetSpeed(I2CMODE_FAST, 400000L);

        i2c0master_StartN(i2c_address,I2C_WRITE,2); //AS pin is high
        i2c0master_WriteN(0x03); //cycle time register
        i2c0master_WriteN(0x01); //convert time
        do
        {
                printf("read 3-axis values of Gyro and chip temperature\n\n");
                for(i = 0;i < 8;i++)
                {
                        high = (0xf0 & (0x01 << i)) >> 4;//CH5 ~ CH8
                        low = (0x0f & (0x01 << i)) << 4;//CH1 ~ CH4

                        i2c0master_StartN(i2c_address,I2C_WRITE,3);//write 3 bytes
                        i2c0master_WriteN(0x02);//configuration register
                        i2c0master_WriteN(high);
                        i2c0master_WriteN(low + 0x0c);//0x0c : FLTR = 1,ALERT/EN = 1
                        wait_ms(10);

                        i2c0master_StartN(i2c_address,I2C_WRITE,1);
                        i2c0master_SetRestartN(I2C_READ,2);
                        i2c0master_WriteN(0x00);//Read data form Conversion Result Register
                        //Data : 12bits
                        d1 = i2c0master_ReadN();
                        d2 = i2c0master_ReadN();
                        printf("%s : %d\n",out_title[((d1 & 0x70) >> 4)],(d1 & 0x0f)*256+d2);
                }
                printf("\n");
        }while(_getch() != 27);

    i2c_Close();
    return 0;
}
5#
發表於 2010-8-27 19:49:16 | 只看該作者
對了
接線的部分也要確認
是否真的有確實接正確喔
可否有照片看看呢
因為我老是遇到接錯的
6#
 樓主| 發表於 2010-8-28 14:36:23 | 只看該作者
本帖最後由 chem0103 於 2010-9-2 16:06 編輯

1

相片0173.jpg (642.34 KB, 下載次數: 226)

相片0173.jpg

相片0176.jpg (550.69 KB, 下載次數: 233)

相片0176.jpg
7#
 樓主| 發表於 2010-8-28 14:52:11 | 只看該作者
本帖最後由 chem0103 於 2010-8-31 21:49 編輯

  1. #include <Wire.h>

  2. void setup()
  3. {
  4. Wire.begin(); // join i2c bus (address optional for master)
  5. Serial.begin(9600); // start serial for output
  6. }

  7. void loop()
  8. {
  9. Wire.beginTransmission(0x21);
  10. Wire.send(0x03);
  11. Wire.send(0x01);
  12. Wire.endTransmission();
  13. delay(100);
  14. Wire.beginTransmission(0x21);
  15. Wire.send(0xf0);
  16. Wire.send(0x0f);
  17. Wire.endTransmission();
  18. delay(100);
  19. Wire.beginTransmission(0x21);
  20. Wire.send(0x02);
  21. Wire.send(0x0c);
  22. Wire.endTransmission();
  23. delay(100);
  24. // // request 6 bytes from slave device #2
  25. Wire.beginTransmission(0x21);
  26. Wire.send(0x00);
  27. Wire.endTransmission();
  28. delay(100);
  29. Wire.requestFrom(0x21, 6);

  30. while(Wire.available()) // slave may send less than requested
  31. {
  32. char c1 = Wire.receive(); // receive a byte as character
  33. char c2 = Wire.receive(); // receive a byte as character
  34. char c3 = Wire.receive(); // receive a byte as character
  35. char c4 = Wire.receive(); // receive a byte as character
  36. char c5 = Wire.receive(); // receive a byte as character
  37. char c6 = Wire.receive(); // receive a byte as character
  38. int p = 001;//作為資料的間隔
  39. int x = 002;
  40. int y = 003;
  41. Serial.println(c1, BIN);
  42. Serial.println(p);
  43. Serial.println(c2, BIN);
  44. Serial.println(x);
  45. Serial.println(c3, BIN);
  46. Serial.println(c4, BIN);
  47. Serial.println(y);
  48. Serial.println(c5, BIN);
  49. Serial.println(c6, BIN); // print the character
  50. }

  51. delay(500);
  52. }
複製代碼

這是一些C的小問題..
如果有空,可以請您幫忙講解一下嗎?
g145 IN C.docx (17.06 KB, 下載次數: 982)

官網給的是AD7793/7794 Datasheet.

但是G145 Users Manual內寫的是AD7798,

我在網路上找,有兩種 Datasheet.

這兩天我再看看兩種Datasheet的差異.
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-4-29 16:16 , Processed in 0.228676 second(s), 9 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表