embeded/raspberry pi2015. 7. 13. 23:14

3.3-5V 이나 5V추천

탐지거리 3cm-4m

[링크 : http://www.seeedstudio.com/depot/Grove-Ultrasonic-Ranger-p-960.html]


다른 소스들의 예제와 다르게 이녀석...

Trigger / Echo가 아닌 Signal 하나 뿐이다


그래서 Trigger로 output 모드 설정후 전송하고 재빠르게

Echo로 input 모드로 설정후 받아 시간을 재도록 수정해야 한다.


포트는 만만한(?) GPIO18번 PWM 포트(wiring pi 기준 1번)으로 설정

흰색 - 5V

검정 - GND

보라 - GPIO18 ->A0




$ cat ultrasonic_1.py

#!/usr/bin/python

#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|

#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

#

# ultrasonic_1.py

# Measure distance using an ultrasonic module

#

# Author : Matt Hawkins

# Date   : 09/01/2013

# -----------------------


# Import required Python libraries

import time

import RPi.GPIO as GPIO


# Use BCM GPIO references

# instead of physical pin numbers

GPIO.setmode(GPIO.BCM)


# Define GPIO to use on Pi

GPIO_TRIGGER = 18

GPIO_ECHO    = 18


print "Ultrasonic Measurement"


# Set pins as output and input

GPIO.setup(GPIO_TRIGGER,GPIO.OUT)  # Trigger


# Set trigger to False (Low)

GPIO.output(GPIO_TRIGGER, False)


# Allow module to settle

time.sleep(0.5)


# Send 10us pulse to trigger

GPIO.output(GPIO_TRIGGER, True)

time.sleep(0.00001)

GPIO.output(GPIO_TRIGGER, False)

start = time.time()


GPIO.setup(GPIO_ECHO,GPIO.IN)      # Echo

while GPIO.input(GPIO_ECHO)==0:

  start = time.time()


while GPIO.input(GPIO_ECHO)==1:

  stop = time.time()


# Calculate pulse length

elapsed = stop-start


# Distance pulse travelled in that time is time

# multiplied by the speed of sound (cm/s)

distance = elapsed * 34300


# That was the distance there and back so halve the value

distance = distance / 2


print "Distance : %.1f" % distance


# Reset GPIO settings

GPIO.cleanup() 


자가 없어서 대충 한뼘(21cm)로 해봤는데 얼추 맞는 기분

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 154.8

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 3.0

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 9.1

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 26.3 


대충 소스 받아서 수정

[링크 : http://www.raspberrypi-spy.co.uk/2012/12/ultrasonic-distance-measurement-using-python-part-1/]

Posted by 구차니
embeded/raspberry pi2015. 7. 7. 06:54

그냥 쏘고 받고

그 시간 간격재고 끝인가? 굳이.. 몇개의 파형을 안보내는 되는 걸려나..


[링크 : http://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi]

[링크 : http://www.raspberrypi-spy.co.uk/2012/12/ultrasonic-distance-measurement-using-python-part-1/]

Posted by 구차니
embeded/raspberry pi2015. 7. 6. 23:40

귀찮아서 여전히 USB to RS232로 하면서 뻔뻔한 제목 ㅋㅋ

땜질 안되어 있는 녀석이라 핀 몇개만 일단 박고 대충 결선하고 테스트!


핀이 하나도 없네?!?!


으쌰으쌰 대충 땜질하자


귀찮으니.. 3.3V를 내줄수 있는 USB to 232를 애용합시다? ㅋㅋ

일단 당연하지만 RX와 TX는 서로 엇갈리게 연결해준다.


232의 RXBT의 TX

232의 TXBT의 RX


전원도 대충~ GND와 3.3V 연결


3.3V 입력

TTL 레벨에 38400 으로 연결하고

명령어를 치면되는데.. \r\n 이라 그냥 입력이 불가능해서

Putty로는 테스트 불가 -_ㅠ


1. Set work mode

\r\n+STWMOD=1\r\n Set work mode Master




[링크 : http://www.seeedstudio.com/wiki/Serial_port_bluetooth_module_(Master/Slave)]

[링크 : http://www.seeedstudio.com/wiki/images/e/e8/BTSoftware_Instruction.pdf]

    [링크 : http://www.seeedstudio.com/wiki/Bluetooth_Shield]


Posted by 구차니
embeded/raspberry pi2015. 7. 6. 18:47

결국은 비표준 통신이라.

GPIO로 쌩 고생을 시켜야하나...


/*

 *  dht11.c:

 * Simple test program to test the wiringPi functions

 * DHT11 test

 */


#include <wiringPi.h>


#include <stdio.h>

#include <stdlib.h>

#include <stdint.h>

#define MAXTIMINGS 85

#define DHTPIN 7

int dht11_dat[5] = { 0, 0, 0, 0, 0 };


void read_dht11_dat()

{

uint8_t laststate = HIGH;

uint8_t counter = 0;

uint8_t j = 0, i;

float f; /* fahrenheit */


dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0;


/* pull pin down for 18 milliseconds */

pinMode( DHTPIN, OUTPUT );

digitalWrite( DHTPIN, LOW );

delay( 18 );

/* then pull it up for 40 microseconds */

digitalWrite( DHTPIN, HIGH );

delayMicroseconds( 40 );

/* prepare to read the pin */

pinMode( DHTPIN, INPUT );


/* detect change and read data */

for ( i = 0; i < MAXTIMINGS; i++ )

{

counter = 0;

while ( digitalRead( DHTPIN ) == laststate )

{

counter++;

delayMicroseconds( 1 );

if ( counter == 255 )

{

break;

}

}

laststate = digitalRead( DHTPIN );


if ( counter == 255 )

break;


/* ignore first 3 transitions */

if ( (i >= 4) && (i % 2 == 0) )

{

/* shove each bit into the storage bytes */

dht11_dat[j / 8] <<= 1;

if ( counter > 16 )

dht11_dat[j / 8] |= 1;

j++;

}

}


/*

 * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte

 * print it out if data is good

 */

if ( (j >= 40) &&

     (dht11_dat[4] == ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF) ) )

{

f = dht11_dat[2] * 9. / 5. + 32;

printf( "Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F)\n",

dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f );

}else  {

printf( "Data not good, skip\n" );

}

}


int main( void )

{

printf( "Raspberry Pi wiringPi DHT11 Temperature test program\n" );


if ( wiringPiSetup() == -1 )

exit( 1 );


while ( 1 )

{

read_dht11_dat();

delay( 1000 ); /* wait 1sec to refresh */

}


return(0);

}


[링크 : http://www.uugear.com/portfolio/dht11-humidity-temperature-sensor-module/] 


+

2015.07.14

입김불고 얼음대고 온도 변화주기

$ gcc dht11.c -lwiringPi

$ sudo ./a.out

Raspberry Pi wiringPi DHT11 Temperature test program

Humidity = 63.0 % Temperature = 26.0 *C (78.8 *F)

Data not good, skip

...

Humidity = 85.0 % Temperature = 30.0 *C (86.0 *F)

...

Humidity = 80.0 % Temperature = 25.0 *C (77.0 *F)
Humidity = 73.0 % Temperature = 24.0 *C (75.2 *F)
Humidity = 73.0 % Temperature = 23.0 *C (73.4 *F)
Humidity = 71.0 % Temperature = 22.0 *C (71.6 *F)


소스상 GPIO 4 / 7번 핀을 사용하므로 적절하게 연결!


전체구성은 대충 이런 느낌적인 느낌으로



Posted by 구차니
embeded/raspberry pi2015. 7. 5. 18:16

라즈베리에서 하긴 귀차나서 ㅋㅋㅋ

일단 PC에서 테스트



데이터 시트 상으로는.. 이런 순서로 데이터가 되어잇고

38400bps 로 전송한다고 하는데.. jpeg라고는 하지만..

하나 받으려면 꽤 걸리겠네 ㄷㄷ

[링크 : http://www.linksprite.com/upload/file/1291522825.pdf]


프로그램은.. 다른 사이트에서 찾아서 테스트

기본값대로 테스트 했고, USB 시리얼 포트만 COM2로 이동 시켜서 수행

속도를 올리기 위해서는 baudrate를 올리는 것도 방법 일 듯 하다.


320x240

38400  14초

115200 5초

드럽게 오래걸리네.. 그런데 640x480이랑 차이가 없는거 보면.. 프로그램 문제일수도..

(그냥 640x480으로 받는게 아닐까 싶다.


배선은..

가지고 있는 녀석들이 순서가 안 맞아 케이블을 꼬아서

RX -TX - Vcc - GND로 연결되는걸

RX -TX - GND - Vcc 로 바꾸어주고


시리얼이니 당연히(!) RX-TX꼬아서 USB to Serial에 연결해 주었다.


USB 시리얼 부터

TXD - 주황 - D2 - RXD

RXD - 노랑 - D3 - TXD

GND - 갈색 - GND - GND

Vcc - 빨강 - Vcc - Vcc(5V)


[링크 : http://store.cutedigi.com/infrared-jpeg-color-camera-serial-uart-rs232-level/]

[링크 : https://s3.amazonaws.com/linksprite/camera/JPEG_camera_uartinterface_TTL/LSY201evaluationsoftware.exe]

Posted by 구차니
embeded/raspberry pi2015. 7. 4. 12:48

테스트 회로에는 이렇게 되어 있어서..

6V 입력에 220옴으로.. LED를 output에 연결하라고 되어 있긴한데..

막상 출력을 재보니..

5V 입력에 1.8V 출력


불밝기가 엄청 약하다...

GPIO 에서 3.3V 톨러런스니까.. 1.8를 1로 인식하겠지?




최대 탐지거리는 6미터 라는데. 최소로 하면 한 50cm 정도 되는듯(실험치)

그리고 시간은.. 최소 5초 정도.. 중간으로만 놔도 언제 꺼지나 세다가 포기하는 수준이라..

일단은 최소로 해놓고 쓰면 될 것으로 보인다.


Sensitivity range: up to 20 feet (6 meters) 110° x 70° detection range

Power supply: 3V-9V input voltage, but 5V is ideal.


If the Rtime potentiometer is turned all the way down counter-clockwise (to 0 ohms) then

Tx = 24576 x (10K) x 0.01uF = 2.5 seconds (approx)

If the Rtime potentiometer is turned all the way up clockwise to 1 Megaohm then

Tx = 24576 x (1010K) x 0.01uF = 250 seconds (approx)


[링크 : https://learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf] 



귀찮으니.. GPIO1번에 연결하고 읽어오기


pi@raspberrypi ~ $  gpio readall

 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+

 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |

 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |

 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |

 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |

 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |

 |  17 |   0 | GPIO. 0 |  OUT | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |

 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |

 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |

 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |

 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |

 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |

 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |

 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 |  28 |  17 | GPIO.17 |   IN | 0 | 51 || 52 | 0 | IN   | GPIO.18 | 18  | 29  |

 |  30 |  19 | GPIO.19 |   IN | 0 | 53 || 54 | 0 | IN   | GPIO.20 | 20  | 31  |

 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+

 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |

 +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+


pi@raspberrypi ~ $ gpio read 1

0

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

1

pi@raspberrypi ~ $ gpio read 1

0

pi@raspberrypi ~ $ gpio read 1

0

pi@raspberrypi ~ $ gpio read 1

0 


5초 정도

Posted by 구차니
embeded/raspberry pi2015. 7. 2. 22:42

일단.. 귀차니즘으로.. 5V USB 파워를 그냥 서보에 연결해서 사용

180도에 0.9~1.1초에 가깝게 걸리는 듯(약간 부족하게 움직이다 돌아오는거 봐서는)

전압이 낮아서인가.. 전류가 부족한건가..

스펙상으로는 4.8V에 60도 0.2초 정도였으니 3배면 0.6초이고

그러면 거의 인지 가능할 만큼 그거보다 빨리 움직여서 멈춰있는 시간이 있어야 할텐데 -_-


아무튼.. 동영상에서 찾은 것에 비해서도 꽤 늦은 느낌..


$ gpio pwm 1 30; sleep 1; gpio pwm 1 110; sleep 1;gpio pwm 1 30; sleep 1; gpio pwm 1 110; sleep 1 



Posted by 구차니
embeded/raspberry pi2015. 7. 2. 22:31

wiiring pi 설치방법


$ sudo apt-get install git-core

$ mkdir ~/src

$ cd ~/src

$ git clone git://git.drogon.net/wiringPi

$ cd wiringPi

$ git pull origin

$ ./build 


[링크 : http://wiringpi.com/download-and-install/]

Posted by 구차니
embeded/arduino(genuino)2015. 6. 29. 17:08

헐.. 다 합치면 한 30만 넘을듯 ㄷㄷㄷㄷ


RFID

[링크 : http://www.seeedstudio.com/depot/Grove-125KHz-RFID-Reader-p-1008.html] 5V / TTL 9600bps

    [링크 : http://www.seeedstudio.com/wiki/Grove_-_125KHz_RFID_Reader]


Ultrasonic Ranger

[링크 : http://www.seeedstudio.com/depot/Grove-Ultrasonic-Ranger-p-960.html] 5V (3.3에도 작동은 함)



    [링크 : http://www.seeedstudio.com/wiki/Ultra_Sonic_range_measurement_module]


Joystick

[링크 : http://www.seeedstudio.com/depot/Grove-Thumb-Joystick-p-935.html] 5V


Chainable LED


1. The ic will latch a bit of data when the rising edge of the clock coming, And the data should changed after the falling edge of the clock;

2. The flag bits is two “1”;

3. The verify dta B7’is equal to ~B7,and B6’1S ~B6,B7 and B6 are the gray data of blue

4. the serial data is MSB first ,and the sortorder is blue ,green, red 


[링크 : http://www.seeedstudio.com/wiki/images/b/be/P9813_datasheet.pdf]

    [링크 : http://www.seeedstudio.com/depot/Grove-Chainable-RGB-LED-p-850.html] 5V 20mA


Relay

[링크 : http://www.seeedstudio.com/depot/Grove-Relay-p-769.html]


Humidity - Temperature Sensor

[링크 : http://www.seeedstudio.com/depot/Grove-TempHumi-Sensor-p-745.html] 3.3~5V


Serial Camera

[링크 : http://www.linksprite.com/upload/file/1291522825.pdf]

[링크 : http://store.cutedigi.com/infrared-jpeg-color-camera-serial-uart-rs232-level/] 5V / TTL 38400bps

    [링크 : http://learn.linksprite.com/.../use-linksprite-jpeg-camera-to-take-picture-and-store-to-a-sd-card/]


PIR Sensor

[링크 : https://cdn.openimpulse.com/.../DYP-ME003_PIR_Sensor_Module_Datasheet.pdf] 5V / output 3.3 high/low

    [링크 : http://www.vetco.net/catalog/product_info.php?products_id=12843]

    [링크 : https://learn.adafruit.com/downloads/pdf/pir-passive-infrared-proximity-motion-sensor.pdf]




bluetooth shield

[링크 : http://www.seeedstudio.com/wiki/Bluetooth_Shield] 3.3V / TTL 38400bps


Mega Shield

[링크 : http://www.seeedstudio.com/depot/Grove-Mega-Shield-p-934.html]

    [링크 : http://www.seeedstudio.com/wiki/Grove_-_Mega_Shield]


Wifi shield

[링크 : https://www.arduino.cc/en/Main/ArduinoWiFiShield]




android board

[링크 : http://www.seeedstudio.com/depot/Seeeduino-ADK-Main-Board-p-846.html]

    [링크 : http://www.seeedstudio.com/wiki/Seeeduino_ADK_Main_Board]




GND / Vcc / Data / Data 식으로 주로 사용하는 듯?


[링크 : http://www.seeedstudio.com/depot/grove-base-shield-p-754.html?cPath=132_134]

Posted by 구차니
embeded/raspberry pi2015. 6. 29. 15:26


KEY_OK 보다는..

KEY_ENTER로 해줘야 하려나?


ir receiver 해서 설정시

KEY_OK로 하면 메뉴에서 들어갈수 없다 -_-


[링크 : http://kodi.wiki/view/Keymap]

[링크 : http://kodi.wiki/view/Keyboards]

Posted by 구차니