Raspberry Pi project - 라즈베리파이로 핑퐁게임하기 - 1401582 신동윤 1401574 박지환.

Slides:



Advertisements
Similar presentations
Raspberry Pi The singing jelly baby.
Advertisements

ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
Lab7: Introduction to Arduino
ARDUINO FRAMEWORK.
What is Arduino?  Arduino is a ATMEL 168 micro-controller kit designed specially for small projects  User friendly IDE(Integrated Development Environment)
Embedded Sumo 1T4 – 1T5 UTRA.
Panasonic EVE-KC2F2024B 24 pulses per revolution 6mm diameter flattened output shaft output type: quadrature (incremental) minimum life: 15,000 rotations.
Introduction to Arduino Programming January MER-421:Mechatronic System Design.
Arduino Interrupts Paul MacDougal September 8, 2014.
1 Arduino Board: Arduino UNO Arduino Programing Environment: Arduino 0022
Embedded Programming and Robotics Lesson 19 Raspberry Pi Programming in C 1.
Embedded Programming and Robotics
Parallax 4x20 LCD (part number 27979) with Arduino Duemilanove
ARDUINO PROGRAMMING Working with the Arduino microcontroller.
Arduino Part 2 Topics: Serial Communication Programming Constructs: functions, loops and conditionals Digital Input.
Basic Circuits – Lab 2 Arduino and Sensors
FUN WITH COOL KIT. Kit Purpose Have fun assembling and programming a simple robot – Includes chassis, wheels, motors, motor driver, IR sensor and arduino.
DPNM Lab., POSTECH 1/25 CS490K - Internet of Things (IoT) Jonghwan Hyun DPNM Lab. Department of Computer Science and Engineering, POSTECH
RASPBERRY PI IMPLEMENTING BINARY COUNTING Marlon Myers Computer Hardware Systems: EMT 2370 Instructor: Prof. Carranza.
Practical Electronics & Programming
ProtoSnap Introduction to Arduino Casey Haskell, Pete Lewis, David Stillman, Jim Lindblom, Pete Dokter, Lindsay Levkoff, Trevor Zylstra.
Arduino. What is it? A open-source software suite and single-board microcontroller. Allows easy and affordable prototyping of microcontroller applications.
Intro to Arduino Programming. Draw your circuits before you build them From Arduino 330 Ohm From Arduino 330 Ohm From Arduino 330 Ohm.
Khaled A. Al-Utaibi  The Push Button  Interfacing Push Buttons to Arduino  Programming Digital Inputs  Working with “Bouncy”
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Arduino Programming Language Chin-Shiuh Shieh ( 謝欽旭 ) Department.
Introduction to Sensor Technology Week Five Adam Taylor
Embedded Programming and Robotics
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 1 Getting Started to Arduino.
Code The Arduino Environment.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
Autumn, 2014C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Arduino Development Environment Chin-Shiuh Shieh ( 謝欽旭 ) Department.
Braille Printer An-Najah National University Faculty of Engineering Braille Printer Prepared by : Rbee waheeb Supervisor: Dr. Nidal Farahat May
ARDUINO 1. Basics  Comments  /* * Blink * * The basic Arduino example. Turns on an LED on for one second, * then off for one second, and so on... We.
Welcome to Week 4 at the Summer Computer Club Raspberry Pi (contd)
Microcontrollers, Microcomputers, and Microprocessors
Arduino libraries Datatekniker Udvidet hardware/software.
Arduino Mega Arduino Mega 2560 Arduino Mega 2560.
INTERNET OF EVERYTHING SDU 2016 Week 4. Simple Digital and Analog Inputs  The Arduino’s ability to sense digital and analog inputs allows it to respond.
Microcontroller basics Embedded systems for mortals.
Autumn, 2012C.-S. Shieh, EC, KUAS, Taiwan1 智慧電子應用設計導論 (1/3) Arduino Development Environment Chin-Shiuh Shieh ( 謝欽旭 ) Department.
Arduino + Bluetooth TYWu. Connection Arduino + Bluetooth Module.
ARDUINO 실습 과제 보 고서. PWM 은 아날로그 출력이라는 함수를 사용하게 되는데 이 출력에는 3, 5, 6, 9, 10, 11 번의 핀만 사용 가능. ( 숫자 옆 에 ~ 표시 )
Arduino “Getting Started” Instructor : Dr Matthew Miss Khin Yi Kyaw
Arduino Programming. THE ARDUINO IS A MICROCONTROLLER – A LOW COST, LOW PERFORMANCE COMPUTER.
Embedded Software Design Week III Processor Basics Raspberry Pi -> Blinking LEDs & pushing buttons.
Introducing the Arduino Uno Presented by Dave Mawdsley, DACS Member, Linux SIG Member (wiring, programming and running a cute traffic light simulation)
Harpeth Hall Jan 2016 Introduction to Arduino Prepared for Harpeth Hall Winterim January 2016.
Application of Programming: Scratch & Arduino
Sparkfun Electronics ATtiny85 Arduino Quick Reference Sheet
1 Button 2 Buttons Light Emitting Diodes LED and Buttons
Microcontroller basics
Callback TYWu.
WORKSHOP LED CONTROL.
RASPBERRY PI WORKSHOP.
INC 161 , CPE 100 Computer Programming
Lecture 2-2: Arduino Programming
Arduino.
Session 3 DIY Moderate Project
Lighting LEDs with a RASPBERRY PI
Roller Coaster Design Project
مقدمة في الاردنيو د فضل الاكوع.
Internet-of-Things (IoT)
1 Code
Topics: Programming Constructs: loops & conditionals Digital Input
Raspberry Pi 2/3 GPIO - LED, Button
TicTacToe 過三關 使用者可按 XO X char gb[3][3]; gb[0][1] gb[0][0] gb[0][2]
Arduino程式範例.
Introduction to Arduino IDE and Software
Presentation transcript:

Raspberry Pi project - 라즈베리파이로 핑퐁게임하기 신동윤 박지환

프로젝트 소개 Game pi 라즈베리파이를 이용하여 게임즐기기

프로젝트 부품 라즈베리파이케이블 스위치 breadboard 아두이노 8*8 도트 매트릭스

프로젝트 내용 조작 버튼 python Serial 통신 RaspberryPi GPIO Port 도트 메트릭스 python Arduino Serial Port USB 를 통한

제작과정  라즈베리파이와 버튼 모듈 연결선과 브레드보드를 연결  버튼 작동에 관한 파이썬 소스 작동 후 터미널로 테스트  아두이노와 쉬프트 레지스터가 달린 8X8 도트 메트릭스를 연결  도트메트릭스의 각 LED 램프의 좌표값을 확인하면서 테스트한 후 도트메트릭스 소스들을 참조하여 아두이노 핑퐁게임 소스작성  라즈베리파이에 우노를 설치 후 USB 연결로 파이와 아두이노를 연결  아두이노와 라즈베리파이의 시리얼 통신 소스코드를 참고하여 핑퐁게임에 라즈베리파이의 버튼들 을 대응시킴  시리얼 통신으로 인한 오류와 반응속도가 많이 느린 문제등을 해결하기 위해 소스코드를 수정하며 테스트  테스트 이후 게임시작버튼과 종료버튼 그리고 도트메트릭스를 통한 그림그리기 등 추가 희망사항 등을 테스트하며 프로젝트 완성

Flow Chart

흐름도

라즈베리파이 아두이노 연동  라즈베리파이에 아두이노 설치 sudo apt-get install Arduino  시리얼 포트의 액세스 권한얻기 sudo usermod –a -G tty pi sudo usermod –a –G dialout pi  아두이노 실행 후 Tools ->Serial Port 에서 시리얼포트 선택 Tools -> Board 에서 보드선택

핑퐁게임 #include #define PIN_RedPlayer_Left 0 //1P q 버튼 #define PIN_RedPlayer_Right 1 #define PIN_BluePlayer_Right 3 // 2P 버튼 #define PIN_BluePlayer_Left 2 #define ROW_DATA // 열 주소값 ((row[0]<<7)|(row[1]<<6)|(row[2]<<5)|(row[3]<<4) |(row[4]<<3)|(row[5]<<2)|(row[6]<<1)|(row[7]<<0)) #define COL_DATA // 행 주소값 ((col[0]<<7)|(col[1]<<6)|(col[2]<<5)|(col[3]<<4)|(c ol[4]<<3)|(col[5]<<2)|(col[6]<<1)|(col[7]<<0)) int SER = 9; // 핀이 연결된 포트넘버 int RCK = 10; int SRCK = 11; unsigned int left = 0; unsigned int right = 0; unsigned int BlueButton_R = 0; unsigned int BlueButton_L = 0; unsigned int RedButton_R = 0; unsigned int RedButton_L = 0; int BlueScore = 0; int RedScore = 0; int angle = 0; int radians;

핑퐁게임 // 열과 행의 배열생성 int row[8] = {0, 0, 0, 0, 0, 0, 0, 0 }; int col[8] = { 0, 0, 0, 0, 0, 0, 0, 0}; byte screen[8] = {0, 0, 0, 0, 0, 0, 0, 0}; volatile byte screenRow = 0; volatile byte screenCol = 0; int _angle; int _px; int _py; int _w = 7; int _h = 7; int _wall[] = {3, 3}; int _count = 0; int _speed = 3; int _countPoints = 0; void setup() { Timer1.initialize(100); // 핀에 신호를 내보낸다 pinMode(RCK, OUTPUT); pinMode(SRCK, OUTPUT); pinMode(SER, OUTPUT); Timer1.attachInterrupt(doubleBuffer); // 신호를 가져온다 // attachInterrupt(0, restartGame, LOW); Serial.begin(115200); // 시리얼의 시작과 속도를 정의 }

핑퐁게임 void doubleBuffer() { row[screenRow] = 0; col[screenCol] = 1; screenCol++; if (screenCol >= 8) { screenCol = 0; screenRow++; if (screenRow >= 8){screenRow = 0;} } if ((screen[screenRow] >> screenCol) & B1 == B1) { row[screenRow] = 1; col[screenCol] = 0; digitalWrite(RCK, LOW); shiftOut(COL_DATA); shiftOut(ROW_DATA); digitalWrite(RCK, HIGH); } else { row[screenRow] = 0; col[screenCol] = 1; } void allOFF() { for (int i = 0; i < 8; i++) screen[i] = 0;} void on(byte row, byte column) { screen[column - 1] |= (B1 << (row - 1));} void off(byte row, byte column) { screen[column - 1] &= ~(B1 << (row - 1)); }

핑퐁게임 //1P 버튼을 읽어온다. void BlueButton(char b) { BlueButton_R = analogRead(PIN_BluePlayer_Right); BlueButton_L = analogRead(PIN_BluePlayer_Left); if (b=='1' ) { if (right > 5) {right = 6;} else { right ++; } delay(40); } else if (b=='2') { if (right < 1) { right = 0;} else { right --; } delay(40);} else { } //2P 버튼을 읽어온다. void RedButton(char b) { RedButton_R = analogRead(PIN_RedPlayer_Right); RedButton_L = analogRead(PIN_RedPlayer_Left); if (b=='5' ) { if (left > 5) { left = 6;} else { left ++;} delay(40); } else if (b=='6') { if (left < 1) { left = 0;} else { left --;} delay(40); } else { }

핑퐁게임 char i='Stop'; void calcWall() { if(i=='5'||i=='6') RedButton(i); if(i=='1'||i=='2') BlueButton(i); clearWall(); on(1, left + 1); on(1, left + 2); on(8, right + 1); on(8, right + 2); _wall[0] = left; _wall[1] = right; show(); } void clearWall() { for (int i = 0; i < 8; i++) screen[i] &= B ; } void clearGame() { for (int i = 0; i < 8; i++) screen[i] &= B ;} int count = 0; void loop() { delay(80); i=Serial.read(); Serial.println(i); if(i=='S'){ count=1; face(); // 웃는얼굴 테스트 reset(); // 리셋 } if(count==1){ calcWall(); enterFrameHandler(); } if(i=='T'){ clearD(); count=0; }

핑퐁게임 void show() { clearGame(); on(_px + 1, _py + 1); } //Collision check void checkCollision() { if (_px == _w - 1) { if (_angle == 315 || _angle == 0 || _angle == 45) { if (_py == _wall[1] || _py == _wall[1] + 1) { if (_angle == 0 && _py == _wall[1]) retorted(225); else if (_angle == 0 && _py == _wall[1] + 1) retorted(135); else if (_angle == 45 && _py == _wall[1]) retorted(135); else if (_angle == 45 && _py == _wall[1] + 1) retorted(180); else if (_angle == 315 && _py == _wall[1]) retorted(180); else if (_angle == 315 && _py == _wall[1] + 1) retorted(225); }

핑퐁게임 else if (_px == 1) { if (_angle == 225 || _angle == 180 || _angle == 135) { if (_py == _wall[0] || _py == _wall[0] + 1) { if (_angle == 180 && _py == _wall[0]) retorted(315); else if (_angle == 180 && _py == _wall[0] + 1) retorted(45); else if (_angle == 135 && _py == _wall[0]) retorted(45); else if (_angle == 135 && _py == _wall[0] + 1) retorted(0); else if (_angle == 225 && _py == _wall[0]) retorted(0); else if (_angle == 225 && _py == _wall[0] + 1) retorted(315); } if (_px == _w) { RedScore++; reset(); } else if (_px == 0) { BlueScore++; reset(); } else if (_py == _h) { if (_angle == 45) _angle = 315; else if (_angle == 135) _angle = 225; } else if (_py == 0) {

핑퐁게임 if (_angle == 225) _angle = 135; else if (_angle == 315) _angle = 45; } //Calculate the Angle increment void calcAngleIncrement() { if (_angle == 0 || _angle == 360) { _px += 1; } else if (_angle == 45) { _px += 1; _py += 1; } else if (_angle == 135) { _px -= 1; _py += 1; } else if (_angle == 180) { _px -= 1; } else if (_angle == 225) { _px -= 1; _py -= 1; } else if (_angle == 315) { _px += 1; _py -= 1; }

핑퐁게임 void shiftOut(byte myDataOut) { boolean pinState; // 쉬프트 레지스터를 읽어오고 데이터를 보낸다 digitalWrite(RCK, LOW); // 각각의 비트에 해당하는 데이터를 보낸다 for (int i = 0; i <= 7; i++) { digitalWrite(SRCK, LOW); if ( myDataOut & (1 << i) ) { pinState = HIGH; } else { pinState = LOW; } digitalWrite(SER, pinState); digitalWrite(SRCK, HIGH); digitalWrite(SER, LOW); } // 쉬프트를 멈춘다 digitalWrite(SRCK, LOW); } void clearD(){ for(int i=1;i<9;i++){ for(int j=1;j<9;j++){ off(i,j); }

조작버튼 제작 import serial import RPi.GPIO as GPIO import time //GPIO 모듈 준비 GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) Up=21 Down=20 Start=4 A=19 B=26 GPIO.setup(21,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(20,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(4,GPIO.IN,pull_up_down=GPIO.PUD_UP) // 각 버튼에 GPIO 대응 GPIO.setup(19,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(26,GPIO.IN,pull_up_down=GPIO.PUD_UP) // 시리얼 통신을 위해 포트 지정 port= " /dev/ttyACM0“ serial=serial.Serial(port,115200) // 포트속도 결정 serialA.flushOutput() // 시리얼 통신 serialA.open() serialA.isOpen() x='0‘ count = 0 while count is not 2: // 정지신호가 올때까지

조작버튼 제작 S=GPIO.input(Start) if S is 0: if count is 0: x='S‘ serialA.write(x) x='0‘ time.sleep(5) count=1 elif count is 1: x='T‘ serialA.write(x) break if count is 1: U=GPIO.input(Up) D=GPIO.input(Down) A_B=GPIO.input(A) B_B=GPIO.input(B) if U is 0: x='1‘ if D is 0: x='2‘ if A_B is 0: x='5‘ if B_B is 0: x='6‘ serialA.write(x) time.sleep(0.5) GPIO.cleanup()