조회 수 4264 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

Raspberry Pi 의 I²C 주변 장치는 기본적으로 켜져 있지 않다. raspi-config를 사용하여 활성화할 수 있다.

아래 명령을 입력했을 때,

ls /dev/*i2c*

다음과 같이 출력되어야 한다.

/dev/i2c-1

 

Utilities

I2C 인터페이스를 작동시키는 데 도움이 되는 일련의 명령줄 유틸리티 프로그램이 있다. apt 패키지 관리자를 사용하여 얻을 수 있다.

sudo apt install -y i2c-tools

특히 i2cdetect 은 버스의 모든 주소를 조사하고 장치가 있는지 여부를 표시해준다.

다음 명령줄을 입력해본다. -y 플래그는 확인을 기다릴 필요가 없도록 한다. 1은 I2C 버스 1(예: i2c-1)에서 I2C 장치를 스캔하고 있음을 나타낸다.

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- -- 

 

I²C 통신 Example

Arduino (ATtiny85) 측 slave 예제

// Wire Slave Sender
#include <TinyWire.h>
#include <twi.h>

void setup() {
  // config TinyWire library for I2C slave functionality
  TinyWire.begin( 0x8 );
  // register a handler function in case of a request from a master
  TinyWire.onRequest( requestEvent );
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  String data = "hello makersweb.net";
  TinyWire.send(1);
  TinyWire.send(data.c_str(), data.length());
}

라이브러리: https://github.com/lucullusTheOnly/TinyWire

배선

Raspberry Pi PIN Map
GPIO 2 - I²C 핀 중 SDA(I2C1 데이터), GPIO 3 - I²C 핀 중 SCL(I2C1 클럭).

raspberrypi_pin.png

ATtiny85 PIN Map
ATtiny85 마이크로컨트롤러에서 SDA 핀은 PB0이고 SCL 핀은 PB2이다.

attiny85_pin.png

ATtiny85 (Slave) 장치와 연결하고 Raspberry Pi 에서 다시 i2cdetect 명령줄을 입력해본다.

$ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- 08 -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --     

 

Raspberry Pi 측 master 예제

#include "pi2c.h"

int main(){
    Pi2c arduino(8); //Create a new object "arduino" using address "0x08"
    char data[20] = {0,}; //Create a buffer of char (single bytes) for the data

    //Receive from the Arduino and put the contents into the "data" char array
    arduino.i2cRead(data, sizeof(data));
    //Print out what the Arduino is sending...
    std::cout << "Arduino Says: " << data << std::endl;

    //Send an 16 bit integer
    //arduino.i2cWriteArduinoInt(4356);

    return 0;
}

라이브러리: https://github.com/JohnnySheppard/Pi2c

실행

i2c_master.png

TAG •

  1. POSIX를 지원하는 오픈소스 RTOS, RTEMS

    Date2020.04.15 Category운영체제 Bymakersweb Views5333
    Read More
  2. 라즈베리파이2에서 RTOS기반 GPIO제어(LED)

    Date2020.04.21 CategorySBC Bymakersweb Views5400
    Read More
  3. No Image

    Raspberry Pi 의 프레임버퍼(Framebuffer)구성

    Date2020.05.15 CategorySBC Bymakersweb Views6283
    Read More
  4. Android 기기를 사용하여 Raspberry Pi SD 카드 작성 방법

    Date2020.08.01 CategorySBC Bymakersweb Views4863
    Read More
  5. No Image

    플랫폼 디바이스 및 디바이스 트리

    Date2021.03.20 Category드라이버 Bymakersweb Views6506
    Read More
  6. ATtiny85 개발보드(HW-260)

    Date2023.01.02 Category개발환경 Bymakersweb Views4154
    Read More
  7. 임베디드 개발자를 위한 Hex,Bin,Dec 변환기 유틸

    Date2023.02.27 Category개발환경 Bymakersweb Views6235
    Read More
  8. 로직분석기와 함께 PulseView 를 사용해서 CAN 신호 캡쳐

    Date2023.03.16 Category통신 Bymakersweb Views3970
    Read More
  9. Raspberry Pi 와 ATtiny85 간 I²C 통신

    Date2023.03.18 Category통신 Bymakersweb Views4264
    Read More
  10. No Image

    Yocto 프로젝트 3.4 릴리스(honister) 이상 버전으로 마이그레이션 시 참고 사항

    Date2023.03.21 Category개발환경 Bymakersweb Views4640
    Read More
  11. No Image

    Raspberry Pi에서 I²C 그리고 Bit-bang (비트뱅)

    Date2023.08.27 Category통신 Bymakersweb Views4412
    Read More
  12. No Image

    Rockchip VOP

    Date2024.04.22 Category드라이버 Bymakersweb Views3533
    Read More
  13. OpenAMP 간단한 소개

    Date2024.09.21 Category통신 Bymakersweb Views3584
    Read More
  14. 임베디드 리눅스 시스템에서 Flutter와 Wayland의 조합

    Date2025.08.21 Category그래픽스 Bymakersweb Views3286
    Read More
Board Pagination Prev 1 2 3 Next
/ 3