'blink fade'에 해당되는 글 1건

  1. 2018.05.16 Hardware | ATtiny85 를 사용해 보자 - 2

Hardware | ATtiny85 를 사용해 보자 - 2

|

1. 준비물


ATtiny85 에 구동 program 를 업로드 하기 전에, 구성품 준비가 필요합니다.

관련해서는 다음에 링크된 이전글을 참고해 주세요.


* Hardware | ATtiny85 를 사용해 보자 - 1

http://chocoball.tistory.com/entry/Hardware-ATtiny85-1



참고로 ATtiny85 의 datasheet 는 다음과 같습니다.

Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet.pdf





2. 참조 사이트


ATtiny85 에 프로그램 업로드를 위해서는 몇가지 방법이 있지만,

저는 다음 사이트를 기준으로 참고하였습니다.


* Breathing life into the DigiSpark clone with ATtiny MCU

https://makbit.com/web/firmware/breathing-life-into-digispark-clone-with-attiny-mcu/




3. Arduino - ArduinoISP


자, 이제 준비가 완료 되었으니 이제 시작을 해 볼까요?


ATtiny85 에 프로그램을 심으려면,

바로 PC 와 USB를 통해 연결하면 안되고 "PC -- USB -- Arduino -- ATtiny85" 식으로 연결하여 프로그래밍 할 수 있습니다.


중간에 위치한 Arduino 를 브릿지 형식으로 사용하는 것입니다. 이름하야  In-circuit Serial Programmer (ISP) 라는군요.

이를 위해, Arduino 가 ISP 로 동작할 수 있도록 Arduino 에 ISP 프로그램을 업로드 해줍니다.


File > Examples > 11.ArduinoISP > ArduinoISP 



이걸로 Arduino 쪽의 준비는 끝났습니다.




4. Arduino IDE - Perferences


다음으로 IDE의 Preferences 메뉴로 이동하여 ATtiny85 보드를 Arduino 에서 인식시킬 수 있도록 관련된 library 를 인스톨 합니다.

이를 위하여, 다음 URL 중 하나를 Preferences 의 Boards Manager URLs 에 다음 중 하나를 선택하여 입력해 줍니다.


* ATtinyCore

- http://drazzy.com/package_drazzy.com_index.json

* Digispark

- http://digistump.com/package_digistump_index.json


File > Preferences > Additional Boards Manager URLs



보통은 Digispark 용을 사용해도 되나,

Spence Konde 라는 사람이 만든 ATTinyCore 는 좀더 정밀하게 설정할 수 있고, 문제 없이 동작한다고 합니다.


* Spence Konde

https://github.com/SpenceKonde/ATTinyCore


저는 Spence Konde 를 선택했습니다.




5. Arduino IDE - Board Manager


다음으로 ATtinyCore 라이브러리를 Board Manager 를 통해 설치합니다.


Tools > Board > Board Manager > search "ATtinyCore"



위의 과정까지 거치면, 아래처럼 Board 에서 ATtiny85 를 선택할 수 있습니다.





6. Arduino IDE - Programmer


이제 마지막으로 운용할 Programmer 를 선택합니다.

이미 우리는 Arduino 를 ISP 로 사용할 것을 알기에, "Arduino as ISP" 를 선택하면 됩니다.


ATtinyCore 라이브러리가 설치되어 있으므로, "Arduino as ISP (ATtinyCore)" 를 선택해도 됩니다만,

왠지 default 로 제공되는 것을 사용하고 싶어서 "Arduino as ISP" 를 선택했습니다.


어느쪽을 선택해도 문제없을것 같아요.



이제 Arduino IDE 에서의 준비는 끝났습니다.




7. Layout


ATtiny85 의 Pin 배열은 다음과 같습니다.



위의 그림을 참조하여 Arduino 와 ATtiny85 를 다음과 같이 연결합니다.


  ATtiny85  | Arduino Nano
---------------------------
    VCC     |     5V
    GND     |     GND
    Reset   |     D10
    Pin 0   |     D11
    Pin 1   |     D12
    Pin 2   |     D13
---------------------------


추가로 Arduino 의 GND/RESET 에 10uF 캐패시터를 연결해 줍니다.

이유는 Arduino 가 ATtiny85 에 업로드 할 때, auto reset 을 방지하기 위함이라 합니다.



실제 모양은 다음과 같아요.

그간 고생해서 얻은 "DIP to SOIC converter" 가 빛을 발하는 순간입니다.



이제 물리적인 구성은 완료 되었습니다.




8. sketch


소스는 아래 link 를 참조하였습니다.

깜빡이 간격이 좀 짧은것 같아 increment / decrement 를 5에서 1로 변경했습니다.


* Attiny85 blink fade for loop 3 LED

https://codebender.cc/sketch:354605


해당 소스는 단순히 LED 를 깜빡이게 하는것 외에도,

PWM (Pulse With Modulation) 기법을 이용하여 LED 점등을 fade 효과를 낸 것입니다.


/*
This code will allow you to mix fading and blinking on 3 LEDs
Jill Dawson
*/

int Pin0 = 0;	// LED connected to pwm pin 0, which can blink or fade
int Pin1 = 1;	// LED connected to pwm pin 1, which can blink or fade
int Pin2 = 2;	// LED connected to digital pin 2, which can only blink

void setup() {
	// nothing happens in setup
	// declares pins as outputs
	
	pinMode (0, OUTPUT);
	pinMode (1, OUTPUT);
	pinMode (2, OUTPUT);
} 

//Loop repeats
void loop() {
	// fades pin 0 in from min to max in increments of 5 points
	for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) {
		// sets the value (range from 0 to 255):
		analogWrite(Pin0, fadeValue);
		// wait for 30 milliseconds to see the dimming effect
		delay(30);
	}
	
	// fades pin 0 out from max to min in increments of 5 points
	for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1) {
		// sets the value (range from 0 to 255):
		analogWrite(Pin0, fadeValue);
		// wait for 30 milliseconds to see the dimming effect
		delay(30);
	}
	
	// blinks LED 1 three times
	{
		digitalWrite (1, HIGH);	//turns pin 1 on
		delay (1000);			//waits for 1 second
		digitalWrite (1, LOW);	//turns pin 1 off
		delay (1000);			//waits for 1 second
		digitalWrite (1, HIGH);	//turns pin 1 on
		delay (1000);			//waits for 1 second
		digitalWrite (1, LOW);	//turns pin 1 off
		delay (1000);			//waits for 1 second
		digitalWrite (1, HIGH);	//turns pin 1 on
		delay (1000);			//waits for 1 second
		digitalWrite (1, LOW);	//turns pin 1 off
	}
	
	// blinks LED 2 three times
	{
		digitalWrite (2, HIGH);	//turns pin 2 on
		delay (1000);			//wait for 1 second
		digitalWrite (2, LOW);	//turns pin 2 off
		delay (1000);			//waits for 1 second
		digitalWrite (2, HIGH);	//turns pin 2 on
		delay (1000);			//wait for 1 second
		digitalWrite (2, LOW);	//turns pin 2 off
		delay (1000);			//waits for 1 second
		digitalWrite (2, HIGH);	//turns pin 2 on
		delay (1000);			//wait for 1 second
		digitalWrite (2, LOW);	//turns pin 2 off
		delay (1000);			//waits for 1 second
	}
	
	// fades pin 1 out from max to min in increments of 5 points
	for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=1) {
		// sets the value (range from 0 to 255):
		analogWrite(Pin1, fadeValue);
		// wait for 30 milliseconds to see the dimming effect
		delay(30);
	}
	
	// fades out from max to min in increments of 5 points:
	for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=1) {
		// sets the value (range from 0 to 255):
		analogWrite(Pin1, fadeValue);
		// wait for 30 milliseconds to see the dimming effect
		delay(30);
	}
}


Arduino IDE 에서 업로드 합니다.



AVR Part 항목을 보면 ATtiny85 로 정확히 인식합니다.



ATtiny85 에 FLUSH 가 성공하면 위와 같이 문제없이 완료가 됩니다.




9. 결과


짜잔~!





FIN


이제 ATtiny85 에 프로그램을 업로드 하여 standalone 으로 동작하는 것까지 확인할 수 있었습니다.


"ATtiny85 + DIP to SOIC adapter + USB board" 를 USB 에 직접 연결하여,

Arduino ISP 없이도 Digispark 처럼 프로그램을 업로드 할 수 있는게 목표므로, 다음 글에서 구성해 보도록 하겠습니다.


And
prev | 1 | next