라즈베리파이 3.5인치 터치스크린인식

라즈베리파이에 파이스크린 적용기록

관련 url : http://onestepcloser.tistory.com/123

sudo rpi-update

sydo apt-get update
sudo apt-get upgrade
sudo reboot

——————————————–
sudo vi /boot/config.txt

dtoverlay=piscreen,speed=16000000,rotate=90

sudo reboot

——————————————

sudo apt-get install fbi
wget http://ozzmaker.com/piscreen/image-test.gif
sudo fbi -noverbose -T 1 -a -d /dev/fb1 image-test.gif

—————————————–

sudo vi /usr/share/X11/xorg.conf.d/99-fbturbo.conf

#Option “fbdev” “/dev/fb0”
Option “fbdev” “/dev/fb1”
———————————————————-

터치스크린 터치시 상하가 반전되어 찾아봄

참고 url : http://www.waveshare.com/wiki/3.5inch_RPi_LCD_(A)
sudo apt-get install -y xinput-calibrator

라즈베리파이 x윈도상태에서
do DISPLAY=:0.0 xinput_calibrator
터치스크린에 찍으라는 위치를 찍음

결과 텍스트가 나오면 완료

재부팅 없이도 바로 터치스크린이 조정됨.

Calibrating EVDEV driver for “ADS7846 Touchscreen” id=6
current calibration values (from XInput): min_x=0, max_x=4095 and min_y=0, max_y=4095

Doing dynamic recalibration:
Setting calibration data: 217, 3908, 3891, 197
–> Making the calibration permanent <–
copy the snippet below into ‘/etc/X11/xorg.conf.d/99-calibration.conf’ (/usr/share/X11/xorg.conf.d/ in some distro’s)
Section “InputClass”
Identifier “calibration”
MatchProduct “ADS7846 Touchscreen”
Option “Calibration” “217 3908 3891 197”
Option “SwapAxes” “0”
EndSection
pi@raspberrypi:~ $ pwd
~

재부팅하니 조절했던 내역이 싹 사라짐

/etc/X11에 가보니 xorg.conf.d 디렉토리 자체가 없음
/usr/share/X11/xorg.conf.d 디렉토리는 있음

요디렉토리에 99-calibration.conf 파일을 만들고 아래 내용 추가

Section “InputClass”
Identifier “calibration”
MatchProduct “ADS7846 Touchscreen”
Option “Calibration” “217 3908 3891 197”
Option “SwapAxes” “0”
EndSection

재부팅하면 터치위치가 정상적으로 적용된다.

라즈베리파이 + 아두이노 시리얼 통신

참고 URL : http://m.blog.naver.com/agapeuni/220198811728

라즈베리파이에서 아두이노 우노를 제어하기 위한 arduino 패키지 설치

Cap 2016-02-12 16-56-59-464

Cap 2016-02-12 17-00-37-647
설치완료

라즈베리파이에 원격데스크탑으로 접속하면 아두이노 개발툴이 설치된 것을 확인 할 수 있다.Cap 2016-02-12 17-02-00-186.png

실험1. 아두이노 우노에서 시리얼통신 (USB?) 으로 0부터 1023 까지 값을 0.5초 간격으로 보내는 코드아두이노 IDE를 기동하고 아래 코드를 작성 후 아두이노에 넣고 실행~
Cap 2016-02-12 17-14-15-510.png

Tool -> Serial Moniter 를 누르면 시리얼 모니터 창에서 아두이노로부터 오는 값을 확인 할 수 있다
Cap 2016-02-12 17-18-30-195

실험2.
– 실험 1 을 적용한 후 터미널 환경에서 아두이노 우노가 시리얼 통신으로 보낸 값을 읽어오는 실험
파이썬으로 코딩한다.

Cap 2016-02-12 17-38-28-408.png
Cap 2016-02-12 17-37-46-742
이렇게 코딩하고 파이썬 실행
Cap 2016-02-12 17-39-11-859.png음 에러가 나는데…내용을 보니 port 쪽에 문제가 있는 것 같다

/dev 디렉토리를 가본다
Cap 2016-02-12 17-40-10-427
나는 ttyACM0 란게 없다. 참조한 블로그의 글쓴이분과 환경이 다른가 보다
ttyAMA0 가 있으니 이걸로 바꿔서 한번 테스트~

Cap 2016-02-12 17-42-57-360.png

Cap 2016-02-12 17-45-39-513.png
음 아무런 반응이 없다.. port에 문제가 있는것 같다.
그러고 보니 아두이노IDE 우측 하단에 아두이노와 연결된 포트정보가 있다
Cap 2016-02-12 17-49-16-336
port 정보를 바꿔서 다시 실행
Cap 2016-02-12 17-50-52-582

Cap 2016-02-12 17-51-48-153.png
파이썬으로 실행한 프로그램에서 usb를 통해 들어온 값을 읽어오는게 가능해졌다.

Cap 2016-02-12 17-53-48-711.png

재미있는 것은 터미널에서 실행시킨 SerialRead1.py 가 usb포트로부터 값을 가져와 찍으면
아두이노 IDE의 시리얼모니터에서 값이 빠지는 것이 확인되었다.

한개의 포트에 한개의 프로그램만이 값을 가져갈 수 있는 것으로 예상된다.

 

 

Extend Raspberry PI GPIO PIN

1. 최근 고민하고있던 내용에 대해, 이미 누군가 라즈베리파이 포럼에 동일한 질문을 함.
https://www.raspberrypi.org/forums/viewtopic.php?f=47&t=40879

2. 솔루션
http://nathan.chantrell.net/20120519/raspberry-pi-and-the-mcp23017-i2c-io-expander/

mcp23017 칩을 이용하면 추가적인 핀사용이 가능하다고 한다.

그런데 mcp23017 을 가지고 어떻게 하면 되는거지?

라즈베리파이 JAVA FX

참고URL : https://www.youtube.com/watch?v=swW9KJRyLeA

1. 설정변경
pi@was02 /etc/alternatives $ sudo vi /boot/config.txt
[AS-IS]
# uncomment to force a console size. By default it will be display’s size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720
[TO-BE]
# uncomment to force a console size. By default it will be display’s size minus
# overscan.
framebuffer_width=1280
framebuffer_height=720

2. CPU 오버클럭
pi@was02 ~/javaSample $ sudo raspi-config
7 -> 900Mhz 선택

3. 그래픽 메모리 추가할당
pi@was02 ~/javaSample $ sudo raspi-config
8 -> 3 -> 64를 128로 변경

4. 테스트
어떻게 하지?영상에선 이런 효과가 낼수 있다고 함.

Cap 2015-07-05 20-31-22-829

Raspberry PI + PI4J + led blink test

URL : http://pi4j.com/install.html

1. 설치 (쉬운 설치)

pi@was02 ~ $ curl -s get.pi4j.com | sudo bash
====================================================
INSTALLING Pi4J GPG PUBLIC KEY
====================================================
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
100  1761  100  1761    0     0   3070      0 –:–:– –:–:– –:–:–  5792
OK
====================================================
ADDING Pi4J APT REPOSITORY
====================================================
–2015-07-05 11:06:55–  http://get.pi4j.com/pi4j.list
Resolving get.pi4j.com (get.pi4j.com)… 54.231.112.122
Connecting to get.pi4j.com (get.pi4j.com)|54.231.112.122|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 42 [application/octet-stream]
Saving to: `/etc/apt/sources.list.d/pi4j.list’

100%[=========================================================>] 42          –.-K/s   in 0s

2015-07-05 11:06:55 (394 KB/s) – `/etc/apt/sources.list.d/pi4j.list’ saved [42/42]

====================================================
UPDATING APT REPOSITORIES
====================================================
Get:1 http://repository.pi4j.com wheezy Release.gpg [514 B]
Get:2 http://repository.pi4j.com wheezy Release [1,778 B]
Get:3 http://repository.pi4j.com wheezy/rpi armhf Packages [377 B]
Ign http://repository.pi4j.com wheezy/rpi Translation-en_GB
Ign http://repository.pi4j.com wheezy/rpi Translation-en
Fetched 2,669 B in 4s (581 B/s)
Reading package lists… Done
====================================================
INSTALLING Pi4J
====================================================
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following NEW packages will be installed:
pi4j
0 upgraded, 1 newly installed, 0 to remove and 113 not upgraded.
Need to get 616 kB of archives.
After this operation, 919 kB of additional disk space will be used.
Get:1 http://repository.pi4j.com/ wheezy/rpi pi4j all 1.0 [616 kB]
Fetched 616 kB in 3s (162 kB/s)
Selecting previously unselected package pi4j.
(Reading database … 74928 files and directories currently installed.)
Unpacking pi4j (from …/apt/archives/pi4j_1.0_all.deb) …
Setting up pi4j (1.0) …
====================================================
Pi4J INSTALLATION COMPLETE
====================================================

The Pi4J JAR files are located at:
/opt/pi4j/lib 

Example Java programs are located at:
/opt/pi4j/examples

You can compile the examples using this script:
sudo /opt/pi4j/examples/build

Please see http://www.pi4j.com for more information.

pi@was02 ~ $

PI4J 라이브러리 위치 : /opt/pi4j/lb
PI4J 샘플 : /opt/pi4j/examplesPI4J 샘플 실행 : sudo /opt/pi4j/examples/build

2. 샘플빌드
pi@was02 /opt/pi4j/examples $ ./build
———————————————————
[01 of 34] … compiling : BlinkGpioExample.java
[02 of 34] … compiling : BlinkTriggerGpioExample.java
[03 of 34] … compiling : ComputeModuleGpioExample.java
[04 of 34] … compiling : ControlGpioExample.java
[05 of 34] … compiling : CylonGpioExample.java
[06 of 34] … compiling : DebounceGpioExample.java
[07 of 34] … compiling : FrequencyGpioExample.java
[08 of 34] … compiling : I2CWiiMotionPlusExample.java
[09 of 34] … compiling : ListenGpioExample.java
[10 of 34] … compiling : ListenMultipleGpioExample.java
[11 of 34] … compiling : MCP23017GpioExample.java
[12 of 34] … compiling : MCP23S17GpioExample.java
[13 of 34] … compiling : MCP4725GpioExample.java
[14 of 34] … compiling : MultipurposePinGpioExample.java
[15 of 34] … compiling : OlimexGpioExample.java
[16 of 34] … compiling : PCF8574GpioExample.java
[17 of 34] … compiling : PCA9685GpioExample.java
[18 of 34] … compiling : PCA9685GpioServoExample.java
[19 of 34] … compiling : PibrellaExample.java
[20 of 34] … compiling : PiFaceExample.java
[21 of 34] … compiling : PiFaceGpioExample.java
[22 of 34] … compiling : SerialExample.java
[23 of 34] … compiling : ShutdownGpioExample.java
[24 of 34] … compiling : SpiExample.java
[25 of 34] … compiling : StepperMotorGpioExample.java
[26 of 34] … compiling : SystemInfoExample.java
[27 of 34] … compiling : TriggerGpioExample.java
[28 of 34] … compiling : UsageGpioExample.java
[29 of 34] … compiling : WiringPiGpioExample.java
[30 of 34] … compiling : WiringPiGpioInterruptExample.java
[31 of 34] … compiling : WiringPiGpioInterruptExample2.java
[32 of 34] … compiling : WiringPiSerialExample.java
[33 of 34] … compiling : WiringPiSoftPWMExample.java
[34 of 34] … compiling : WiringPiSPIExample.java
———————————————————
sudo java -classpath .:classes:/opt/pi4j/lib/’*’ BlinkGpioExample
3. 소스코드


import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;

/**
* This example code demonstrates how to perform simple
* blinking LED logic of a GPIO pin on the Raspberry Pi
* using the Pi4J library.
*
* @author Robert Savage
*/
public class BlinkGpioExample {

public static void main(String[] args) throws InterruptedException {

System.out.println("<--Pi4J--> GPIO Blink Example ... started.");

// create gpio controller
final GpioController gpio = GpioFactory.getInstance();

// provision gpio pin #01 & #03 as an output pins and blink
final GpioPinDigitalOutput led1 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_01);
final GpioPinDigitalOutput led2 = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_03);

// provision gpio pin #02 as an input pin with its internal pull down resistor enabled
final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02, PinPullResistance.PULL_DOWN);

// create and register gpio pin listener
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
// when button is pressed, speed up the blink rate on LED #2
System.out.println("event.getState().isHigh() => " +event.getState().isHigh());
if(event.getState().isHigh()){
led2.blink(200);
}
else{
led2.blink(1000);
}
}
});

// continuously blink the led every 1/2 second for 15 seconds
led1.blink(500, 15000);

// continuously blink the led every 1 second
led2.blink(500);

System.out.println(" ... the LED will continue blinking until the program is terminated.");
System.out.println(" ... PRESS <CTRL-C> TO STOP THE PROGRAM.");

// keep program running until user aborts (CTRL-C)
for (;;) {
Thread.sleep(500);
}

// stop all GPIO activity/threads
// (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
// gpio.shutdown();   <--- implement this method call if you wish to terminate the Pi4J GPIO controller
}
}

4. 회로도

20150707_010424

5. 실행화면

raspberry pi + wiring pi + 초음파 센서

1.회로구성
Cap 2015-07-05 10-47-10-867Cap 2015-07-05 10-50-53-333

2. 코딩

pi@was02 ~/wiringPi $ mkdir ultrasonic
pi@was02 ~/wiringPi/ultrasonic $ vi ultrasonic.c

#include&lt;stdio.h&gt;
#include&lt;wiringPi.h&gt;

#define trigPin 0
#define echoPin 1

int main(void)
{
int distance = 0;
//int pulse = 0;

if(wiringPiSetup () == -1)
{
return 1;
}

pinMode (trigPin, OUTPUT);
pinMode (echoPin, INPUT);

for(;;)
{
digitalWrite (trigPin, LOW);
delay(2);

digitalWrite (trigPin, HIGH);
delay(20);

digitalWrite (trigPin, LOW);

while(digitalRead(echoPin) == LOW);
long startTime = micros();

while(digitalRead(echoPin) == HIGH);
long travelTime = micros() - startTime;

distance = travelTime / 58;

printf("Distance: %d cm\n", distance);
delay(100);
}
}

3. 컴파일

pi@was02 ~/wiringPi/ultrasonic $ gcc -Wall -o ultrasonic ultrasonic.c -lwiringPi
pi@was02 ~/wiringPi/ultrasonic $

4. 테스트

pi@was02 ~/wiringPi/ultrasonic $ sudo ./ultrasonic
Distance: 25 cm
Distance: 25 cm
Distance: 25 cm
Distance: 25 cm
Distance: 25 cm
Distance: 25 cm
Distance: 25 cm
Distance: 25 cm
Distance: 25 cm
^Cpi@was02 ~/wiringPi/ultrasonic $
Cap 2015-07-05 11-04-08-517

rasbperry pi B gpio between extention board mapping

1. GPIO 와 익스텐션 보드 간 맵핑정보

Screen-shot-2012-08-18-at-1.37.40-PM

위 그림에서 Boardcom names에 SDA, SCL, MOSI 등 각각 이름이 있는 것들은 확장보드에 해당 값이 써있어서 위치를 찾기 쉽다

Broadcom names 그림은  테스트 샘플소스에서 몇번 GPIO 핀으로 신호를 보낸다 했을때의 값이며
Phyical / Raspberry Pi Name 그림은 GPIO 핀이 확장보드를 타고 나갔을때의 매핑 정보를 표현한 것이다.

익스텐션 보드의 와 실제 소스상의 매핑결과를 정리하면 아래와 같을 것 같다
(한동안 라즈베리에서 손을 놔서 가물가물 하다…)

PI4J에서의 핀매핑 값
소스상의 GPIO  0 -> 확장보드의 P0 -> 라즈베리 GPIO 물리적 핀번호 : 11
소스상의 GPIO  1 -> 확장보드의  P1 -> 라즈베리 GPIO 물리적 핀번호 : 12
소스상의 GPIO  2 -> 확장보드의  P2 -> 라즈베리 GPIO 물리적 핀번호 : 13
소스상의 GPIO  3 -> 확장보드의  P3 -> 라즈베리 GPIO 물리적 핀번호 : 15
소스상의 GPIO  4 -> 확장보드의  P4 -> 라즈베리 GPIO 물리적 핀번호 : 16
소스상의 GPIO  5 -> 확장보드의  P5 -> 라즈베리 GPIO 물리적 핀번호 : 18 (위 그림에서는 17 번 옆)
소스상의 GPIO  6 -> 확장보드의  P6 -> 라즈베리 GPIO 물리적 핀번호 : 22
소스상의 GPIO  7 -> 확장보드의  P7 -> 라즈베리 GPIO 물리적 핀번호 : 7
wiringPi에서의 핀매핑값 (?)
GPIO 17 -> P0
GPIO 1   -> P1
GPIO 21 -> P2
GPIO 22 -> P3
GPIO 23 -> P4
GPIO 24 -> P5
GPIO 25 -> P6
GPIO 4   -> P7

2. 익스텐션 확장보드

GPIO-T-Cobbler-Extension-Board-Cable-Breadboard-for-Raspberry-PI-Breakout-Kit

3. 라즈베리파이 B GPIO

raspberry-pi-rev2-gpio-pinout

wiringPi를 이용한 led blink 테스트

1. wiringPi 설치

pi@was02 ~ $ sudo apt-get install git-core
pi@was02 ~ $
pi@was02 ~ $ git clone git://git.drogon.net/wiringPi
Cloning into ‘wiringPi’…
remote: Counting objects: 742, done.
remote: Compressing objects: 100% (676/676), done.
remote: Total 742 (delta 538), reused 94 (delta 58)
Receiving objects: 100% (742/742), 262.41 KiB | 127 KiB/s, done.
Resolving deltas: 100% (538/538), done.
pi@was02 ~ $
pi@was02 ~ $
pi@was02 ~ $ cd wiringPi
pi@was02 ~/wiringPi $ git pull origin
Already up-to-date.
pi@was02 ~/wiringPi $
pi@was02 ~/wiringPi $ ./build
wiringPi Build script
=====================

WiringPi Library
[UnInstall]
[Compile] wiringPi.c
[Compile] wiringSerial.c
[Compile] wiringShift.c
[Compile] piThread.c
[Compile] piHiPri.c
[Compile] wiringPiSPI.c
[Compile] wiringPiI2C.c
[Compile] softPwm.c
[Compile] softTone.c
[Compile] mcp23008.c
[Compile] mcp23016.c
[Compile] mcp23017.c
[Compile] mcp23s08.c
[Compile] mcp23s17.c
[Compile] sr595.c
[Compile] pcf8574.c
[Compile] pcf8591.c
[Compile] mcp3002.c
[Compile] mcp3004.c
[Compile] mcp4802.c
[Compile] mcp3422.c
[Compile] max31855.c
[Compile] max5322.c
[Compile] sn3218.c
[Compile] drcSerial.c
[Compile] wpiExtensions.c
[Link (Dynamic)]
[Install Headers]
[Install Dynamic Lib]

WiringPi Devices Library
[UnInstall]
[Compile] ds1302.c
[Compile] gertboard.c
[Compile] maxdetect.c
[Compile] piFace.c
[Compile] piNes.c
[Compile] lcd128x64.c
[Compile] lcd.c
[Compile] piGlow.c
[Link (Dynamic)]
[Install Headers]
[Install Dynamic Lib]

GPIO Utility
[Compile] gpio.c
[Compile] readall.c
[Compile] pins.c
[Link]
[Install]

All Done.

NOTE: To compile programs with wiringPi, you need to add:
-lwiringPi
to your compile line(s) To use the Gertboard, MaxDetect, etc.
code (the devLib), you need to also add:
-lwiringPiDev
to your compile line(s).

pi@was02 ~/wiringPi $

2. 설치확인  (아래와 같이 뜨면 잘 설치된 것임)
pi@was02 ~/wiringPi $ gpio -v
gpio version: 2.26
Copyright (c) 2012-2015 Gordon Henderson
This is free software with ABSOLUTELY NO WARRANTY.
For details type: gpio -warranty

Raspberry Pi Details:
Type: Model B, Revision: 2, Memory: 512MB, Maker: Egoman
pi@was02 ~/wiringPi $
pi@was02 ~/wiringPi $ gpio readall

Cap 2015-07-05 11-07-43-180

3. 테스트 샘플 수행

pi@was02 ~/wiringPi $ cd examples
pi@was02 ~/wiringPi/examples $ gcc -Wall -o blink blink.c -lwiringPi  <– 컴파일
pi@was02 ~/wiringPi/examples $ sudo ./blink              <– 프로그램 수행시작
Raspberry Pi blink                                                       <– 프로그램 수행중
^Cpi@was02 ~/wiringPi/examples $                              <– Cntl + c 로 강제종료
pi@was02 ~/wiringPi/examples $

4. 회로구성
20150705_014916

5. 동작화면