'resistor network'에 해당되는 글 2건
- 2017.12.01 Hardware | LED bar graph 를 컨트롤 해보자 - 1
- 2017.08.17 Hardware | Resistor Network 을 사용해보자
1. Arduino 와 LED bar graph
이미 LED bar graph 를 사용해 봤습니다.
아래 글들은 본 포스팅과 관련 있는 글 들입니다.
* Hardware | LED bar graph 를 이용해 보자
- http://chocoball.tistory.com/entry/Hardware-LED-bar-graph
* Hardware | Resistor Network 을 사용해보자
- http://chocoball.tistory.com/entry/Hardware-Resistor-Network-using
* Hardware | 74HC595 shift register 를 사용해 보자
- http://chocoball.tistory.com/entry/Hardware-74HC595-shift-register
우선 arduino 와 direct 연결과 shift register 1개를 이용해서 연결을 해보기로 합니다.
2. Digital Pin 으로 직접 컨트롤
LED bar graph 의 anode 쪽을 arduino 의 digital Pin 에 직접 연결하여 전원을 공급함과 동시에 LED 를 on/off 하는 방법입니다.
Source code 는 쉽지만, arduino 와 직접 연결되는 선이 많아집니다.
또한, D13 pin 까지 쓰면 더이상 연결할 수가 없습니다.
LED | Arduino Bargraph | Nano ---------------------------- anode 2 | D2 anode 3 | D3 anode 4 | D4 anode 5 | D5 anode 6 | D6 anode 7 | D7 anode 8 | D8 anode 9 | D9 anode 10 | D10 anode 11 | D11 anode 12 | D12 anode 13 | D13 GND | GND ----------------------------
참고한 사이트는 아래와 같습니다.
- http://www.4tronix.co.uk/arduino/ArduinoLearning.pdf
int timer = 50; // The higher the number, the slower the timing. int pins[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; // an array of pin numbers int num_pins = 12; // the number of pins (i.e. the length of the array) void setup() { int i; for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num pins - 1 pinMode(pins[i], OUTPUT); // set each pin as an output } void loop() { int i; for (i = 0; i < num_pins; i++) { // loop through each pin... digitalWrite(pins[i], HIGH); // turning it on, delay(timer); // pausing, digitalWrite(pins[i], LOW); // and turning it off. } for (i = num_pins - 1; i >= 0; i--) { digitalWrite(pins[i], HIGH); delay(timer); digitalWrite(pins[i], LOW); } }
Source code 는 참고한 사이트것을 그대로 사용하빈다.
단순히 digitalWrite 를 이용한 컨트롤 되겠습니다.
연결 사진 입니다.
구동 동영상 입니다.
3. Shift Register 를 이용하는 방법
Shift Register 를 이용하면 data / latch / clock 핀인 3개의 digital pin 만으로 컨트롤이 가능합니다.
여러 sensor 를 사용할 때에는 이 방법이 최선으로 보입니다.
이미 shift register 를 이용하여 확인해 봤습니다만, 이 글에서 한번 더 해봅니다.
* Hardware | 74HC595 shift register 를 사용해 보자
- http://chocoball.tistory.com/entry/Hardware-74HC595-shift-register
우선 74HC595 pin 정보 입니다.
원본 data sheet 는 다음과 같습니다.
참고한 link 는 다음과 같습니다.
- https://www.sqlskills.com/blogs/paulselec/category/shift-registers.aspx
Pin 들의 연결은 다음과 같습니다.
LED | Shift Register | Arduino Bargraph | SN74HC595N | Nano --------------------------------------- anode 1 | Q1 (pin 1) | anode 2 | Q2 (pin 2) | anode 3 | Q3 (pin 3) | anode 4 | Q4 (pin 4) | anode 5 | Q5 (pin 5) | anode 6 | Q6 (pin 6) | anode 7 | Q7 (pin 7) | | GND (pin 8) | GND | Vcc (pin 16) | 3.3V anode 0 | Q0 (pin 15) | | DS (pin 14) | D11 --> dataPin | OE (pin 13) | GND | ST_CP (pin 12) | D8 --> latchPin | SH_CP (pin 11) | D12 --> clockPin | MR (pin 10) | 3.3V ----------------------------------------
Layout 입니다.
Arduino 에서는 컨트롤 위한 선이 3개만 사용된 것을 보실 수 있을껍니다.
연결된 모습니다.
Source code 입니다.
shiftOut 이라는 명령어를 쓰면 쉽게 동작시킬 수 있으나,
참고한 사이트의 제작자는 오로지 공부를 위해 digitalWrite 명령어를 사용했습니다.
/* Driving a 74HC595 shift register 01/27/2010 */ // This pin gets sets low when I want the 595 to listen const int pinCommLatch = 8; // This pin is used by ShiftOut to toggle to say there's another bit to shift const int pinClock = 12; // This pin is used to pass the next bit const int pinData = 11; void setup() { pinMode (pinCommLatch, OUTPUT); pinMode (pinClock, OUTPUT); pinMode (pinData, OUTPUT); //Serial.begin (56600); } // setup // Using my own method with as few instructions as possible // Gotta love C/C++ for bit-twiddling! void sendSerialData2 (byte value) { // Signal to the 595 to listen for data digitalWrite (pinCommLatch, LOW); for (byte bitMask = 128; bitMask > 0; bitMask >>= 1) { digitalWrite (pinClock, LOW); digitalWrite (pinData, value & bitMask ? HIGH : LOW); digitalWrite (pinClock, HIGH); } // Signal to the 595 that I'm done sending digitalWrite (pinCommLatch, HIGH); } // sendSerialData2 void loop() { for (int counter = 1; counter < 256; counter++) { sendSerialData2 (counter); delay (75); } } // loop
구동시킨 동영상 입니다.
4. 더 간단하게 사용해 보기
위와 같은 동작을 시키는 좀더 간단한 tutorial 이 있습니다.
- https://www.arduino.cc/en/Tutorial/ShiftOut
shiftOut 이라는 명령어로 쉽게 구현되었습니다.
- https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftout/
//**************************************************************// // Name : shiftOutCode, Hello World // Author : Carlyn Maw,Tom Igoe, David A. Mellis // Date : 25 Oct, 2006 // Modified: 23 Mar 2010 // Version : 2.0 // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 //**************************************************************** //Pin connected to ST_CP of 74HC595 int latchPin = 8; //Pin connected to SH_CP of 74HC595 int clockPin = 12; ////Pin connected to DS of 74HC595 int dataPin = 11; void setup() { //set pins to output so you can control the shift register pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { // count from 0 to 255 and display the number // on the LEDs for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) { // take the latchPin low so // the LEDs don't change while you're sending in bits: digitalWrite(latchPin, LOW); // shift out the bits: shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay); //take the latch pin high so the LEDs will light up: digitalWrite(latchPin, HIGH); // pause before next value: delay(50); } }
위의 soruce 는 위의 동영상과 완벽하게 동일한 동작을 합니다.
comment out 라인만 빼면 정말 간단하게 구현되어 있다는 것을 알 수 있죠?
/* Shift Register Example Turning on the outputs of a 74HC595 using an array Hardware: * 74HC595 shift register * LEDs attached to each of the outputs of the shift register */ //Pin connected to ST_CP of 74HC595 int latchPin = 8; //Pin connected to SH_CP of 74HC595 int clockPin = 12; ////Pin connected to DS of 74HC595 int dataPin = 11; //holders for infromation you're going to pass to shifting function byte data; byte dataArray[10]; void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin, OUTPUT); Serial.begin(9600); //Binary notation as comment dataArray[0] = 0xFF; //0b11111111 dataArray[1] = 0xFE; //0b11111110 dataArray[2] = 0xFC; //0b11111100 dataArray[3] = 0xF8; //0b11111000 dataArray[4] = 0xF0; //0b11110000 dataArray[5] = 0xE0; //0b11100000 dataArray[6] = 0xC0; //0b11000000 dataArray[7] = 0x80; //0b10000000 dataArray[8] = 0x00; //0b00000000 dataArray[9] = 0xE0; //0b11100000 //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll_2Bytes(2,500); } void loop() { for (int j = 0; j < 10; j++) { //load the light sequence you want from array data = dataArray[j]; //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin, 0); //move 'em out shiftOut(dataPin, clockPin, data); //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin, 1); delay(300); } } // the heart of the program void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { // This shifts 8 bits out MSB first, //on the rising edge of the clock, //clock idles low //internal function setup int i=0; int pinState; pinMode(myClockPin, OUTPUT); pinMode(myDataPin, OUTPUT); //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin, 0); digitalWrite(myClockPin, 0); //for each bit in the byte myDataOut //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. for (i=7; i>=0; i--) { digitalWrite(myClockPin, 0); //if the value passed to myDataOut and a bitmask result // true then... so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. if ( myDataOut & (1 << i) ) { pinState= 1; } else { pinState= 0; } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin, pinState); //register shifts bits on upstroke of clock pin digitalWrite(myClockPin, 1); //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin, 0); } //stop shifting digitalWrite(myClockPin, 0); } //blinks the whole register based on the number of times you want to //blink "n" and the pause between them "d" //starts with a moment of darkness to make sure the first blink //has its full visual effect. void blinkAll_2Bytes(int n, int d) { digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, 0); shiftOut(dataPin, clockPin, 0); digitalWrite(latchPin, 1); delay(200); for (int x = 0; x < n; x++) { digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, 255); shiftOut(dataPin, clockPin, 255); digitalWrite(latchPin, 1); delay(d); digitalWrite(latchPin, 0); shiftOut(dataPin, clockPin, 0); shiftOut(dataPin, clockPin, 0); digitalWrite(latchPin, 1); delay(d); } }
위 소스는 segment 의 모양을 dataArray 를 사용하여 표현하는 soruce 입니다.
위의 소스를 구동시킨 동영상 입니다.
FIN
12 segments LED bar graph 를 한개만 써서 하는 것은 확인해 봤습니다.
1 개의 shift register 만 사용하면 8개까지만 사용이 가능하니, 12 segments 을 모두 활용하지 못했습니다.
Shift register 를 daisy chain 으로 추가 엮어 주면 가능하다고 합니다.
따로 글을 작성해 보겠습니다.
'Hardware' 카테고리의 다른 글
Hardware | DSO150 firmware update (0) | 2017.12.11 |
---|---|
Hardware | LED bar graph 를 컨트롤 해보자 - 2 (0) | 2017.12.11 |
Hardware | 74HC595 shift register 를 사용해 보자 (0) | 2017.12.01 |
Hardware | bGeigie Nano 를 이용하여 방사능을 측정해 보자 (2) | 2017.11.24 |
Hardware | bGeigie Nano 의 battery 를 업그레이드 해보자 (0) | 2017.11.22 |
1. LED bargraph
LED bargraph 를 이용하여 progress bar 를 표현할 수 있습니다.
바로 Aliexpress 에서 구매해서 놀고 있었습니다.
- http://chocoball.tistory.com/entry/Hardware-LED-bar-graph
LED bargraph 는 LED 들을 하나의 뭉치로 만든 제품이지만,
LED 의 특성상 전압/전류를 제한하기 위해 필수로 저항을 달게 되어 있습니다.
그래서 LED bargraph 에는 다리 하나하나에 저항을 달아줘야 합니다.
당연히 아래와 같이 붙여주거나 전선의 스파게티화를 볼 수 있습니다.
그러던 중, 응?!!!!!
아래와 같은 사진을 접하게 됩니다.
이리 깔끔해 질 수 있다니!!!
확인해보니, "Resistor Network" 이라는 부품이었습니다.
예전 90년대의 PC mainboard 에도 많이 보았던 부품이 이것이었구나... 라고 추억에 젖어 봅니다.
점이 있는 부분이 공통선이고, 각각의 다리가 하나의 저항 역할을 합니다.
머리를 잘 쓴 제품이네요.
Resistor network 을 일반 저항을 이용해서 만들면 다음과 같다고 하네요.
2. 주문
바로 AliExpress 에서 제품을 찾아 봅니다.
LED 에는 보통 220 Ohm 이나 330 Ohm 이 많이 쓰이는 것 같습니다.
220 / 330 짜리를 주문합니다.
330 짜리는 나중에 LED 8x8 matrix 에서도 사용해야 해서 미리 주문해 놓습니다.
위의 제품은 331J 라고 표시된 제품인데, 의미는 330 Ohm 에 5% 의 오차라는 뜻이라 합니다.
3. 스펙
잠깐 스펙에 대해서 알아보도로 하죠.
참고한 문서는 다음과 같습니다.
- L-373215.pdf
Resistor network 은 단순한 "-1 Circuit Based" 와 각각을 짝으로 맟준 "-3 Circuit Isolated" 가 있고,
"-5 Circuit Dual Terminator" 등이 있다고 합니다.
넘버링의 의미는 다음과 같습니다.
마지막 숫자는 맨 뒤에 "0" 이 몇개가 오는지와, "J" 는 5% 의 의미랍니다.
새로운 것을 또 공부하게 됩니다. 즐겁네요.
4. 도착
부품이 도착하여 여러가지 확인해 봤습니다.
50개 단위가 적당할 것 같아서 50개 묶음을 주문했더랬습니다.
낱개의 사진입니다. 쪼만쪼만한게 귀엽네요.
220 Ohm 사진도 올려 봅니다.
330 Ohm 의 실제 저항을 측정해 봤습니다.
일반 저항보다 정도가 더 좋습니다.
아마 허용 와트(W) 용량은 작겠지만, 정도는 정말 좋네요.
5. 연결해 보자
LED bargraph 에 연결해 봤습니다.
한번에 하나밖에 점등을 못시켰는데, 이제는 한꺼번에 LED 를 킬 수 있습니다!
역시 좋네요.
GND 연결선들도 복잡하여 모두 resistor network 으로 대체해 봅니다.
전류나 전압이 떨어지겠지만 LED 점등에는 문제 없을것 같아, +/- 모두 resistor network 를 연결해 봅니다.
완전 깔끔해 졌습니다. 맙소사.
FIN
74HC595 칩이 도착하면, 이제 대망의 arduino 와 연결하여 컨트롤 해볼 예정입니다.
아... 너무 즐겁습니다.
'Hardware' 카테고리의 다른 글
Hardware | Probe Clip 을 사용해 보자 (0) | 2017.08.28 |
---|---|
Hardware | Gyroscope GY-521 MPU-6050 을 사용해 보자 (0) | 2017.08.20 |
Hardware | LED bar graph 를 이용해 보자 (0) | 2017.08.13 |
Hardware | Soil Moisture Sensor 구동해 보기 (0) | 2017.08.02 |
Hardware | MB102 Breadboard Power Supply Module 를 사용해 보자 (0) | 2017.07.31 |