개발자/Arduino

nano 33 IoT 보드에 0.96 ssd1306 i2c OLED 연결하기

지구빵집 2020. 9. 29. 17:10
반응형

 

 

방금전에 아두이노 우노 보드에서 0.96 ssd1306 i2c OLED를 테스트 하였다. 그대로 nano 33 IoT보드에서 테스트를 진행한다. 연결은 아래와 같다. nano 33 IoT 보드의 Pin map을 참고하여 정확히 연결한다.

 

Nano 33 IoT 보드 Pin

ssd1306 Oled

3.3V

VCC

GND

GND

A5

SCL

A4

SDA

제대로 연결했다면 아래 이미지와 같이 한 쪽 방향에 다 연결된다. Oled의 핀 배치는 VCC와 GND 위치가 다를 수 있으므로 주의해서 연결한다.

 

Nano 33 IoT 보드와 Oled 연결

 

정확히 다른 예제와 마찬가지로 Oled를 I2C 로 잘 연결했다면 우선 아래와 같은 i2c 스캐너 프로그램을 실행시켜 연결한 i2c 주소를 알아낸다. 다른 라이브러리가 필요 없는 아래 코드를 i2c_scanner.ino로 저장하고 컴파일하고 업로드를 수행한다.아래 코드와 문서 출처는 여기를 참고하기 바란다. 

 

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
// 
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include <Wire.h>


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) 
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4) 
    {
      Serial.print("Unknown error at address 0x");
      if (address<16) 
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}

 

위 코드를 컴파일 업로드 하는 과정에 이상이 없다면 스케치 IDE 환경의 상태창에는 아래와 같은 메시지가 보일 것이다.

 

스케치는 프로그램 저장 공간 13408 바이트(5%)를 사용. 최대 262144 바이트.
전역 변수는 4076 바이트의 동적 메모리를 사용.
Atmel SMART device 0x10010005 found
Device       : ATSAMD21G18A
Chip ID      : 10010005
Version      : v2.0 [Arduino:XYZ] Apr 19 2019 14:38:48
Address      : 8192
Pages        : 3968
Page Size    : 64 bytes
Total Size   : 248KB
Planes       : 1
Lock Regions : 16
Locked       : none
Security     : false
Boot Flash   : true
BOD          : true
BOR          : true
Arduino      : FAST_CHIP_ERASE
Arduino      : FAST_MULTI_PAGE_WRITE
Arduino      : CAN_CHECKSUM_MEMORY_BUFFER
Erase flash
done in 0.828 seconds

Write 13408 bytes to flash (210 pages)

[=========                     ] 30% (64/210 pages)
[==================            ] 60% (128/210 pages)
[===========================   ] 91% (192/210 pages)
[==============================] 100% (210/210 pages)
done in 0.076 seconds

Verify 13408 bytes of flash with checksum.
Verify successful
done in 0.019 seconds
CPU reset.

 

그리고 씨리얼 모니터를 열어보면 아래 이미지와 같은 결과를 얻는다.

 

보드에 3개의 i2c 보드가 보인다. oled 주소는 0x3C

 

Nano 33 IoT 보드의 i2c 주소가 보인다. 보드에 3개의 i2c 보드가 보이는데 우리가 필요한 것은 oeld 디바이스의 i2c 주소인 0x3C가 중요하다. 

 

파일을 열어 테스트한다. 불러온 예제를 다음과 같이 불러온다. 파일 -> Examples -> Adafruit SSD1306 -> ssd1306_128864_i2c 처럼 말이다. 잘했다. 파일을 열어서 정확히 59라인 소스를 보면 I2C Oled 주소를 3C로 바꿔준다. 참고로 공급 전원 3.3v에서도 매우 동작을 잘한다. ^^ 아래 결과 화면을 첨부한다. 이제 진짜로 놀러간다. 다 했다. ^^

 

nano 33 IoT 보드에서 ssd1306 Oled 동작 이미지

 

 

 

 

반응형