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

릴레이는 단순하게 HI/LO 입력에 따라 on/off 스위치라 별거 없으니 대충~

당연히(!) 귀차니즘으로 wiring pi 기준 1번 / GPIO18번에 연결


$ gpio mode 1 output

$ gpio write 1 1


$ gpio write 1 0



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

Posted by 구차니
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 구차니

음? 전혀.. 처음든는 게임이다?





Posted by 구차니
개소리 왈왈/블로그2015. 7. 12. 21:29

글을 안써서 그런가? 플랫~ ㅋㅋㅋㅋ




'개소리 왈왈 > 블로그' 카테고리의 다른 글

네이버가.. 50% 돌파?  (2) 2015.07.31
출장 3일의 여파?  (2) 2015.07.16
댓글 알림은 있는데 댓글이 사라졌다?  (4) 2015.06.11
한RSS 역사의 뒤안길로..  (0) 2015.05.14
벌써... 일년?  (0) 2015.05.13
Posted by 구차니
Programming/C Win32 MFC2015. 7. 7. 13:45

현실적으로 불가능 -_-

다만 vsprintf 는 인자를 받으므로 인자를 이용해서 다시 문자열을 생성하는 식으로 쓸 수는 있음


[링크 : http://stackoverflow.com/questions/2060578/is-it-possible-to-write-a-varargs-function-that-sends-it-argument-list-to-anothe]


#include <stdio.h>

int printf(const char *format, ...);

int fprintf(FILE *stream, const char *format, ...);

int sprintf(char *str, const char *format, ...);

int snprintf(char *str, size_t size, const char *format, ...);


#include <stdarg.h>

int vprintf(const char *format, va_list ap);

int vfprintf(FILE *stream, const char *format, va_list ap);

int vsprintf(char *str, const char *format, va_list ap);

int vsnprintf(char *str, size_t size, const char *format, va_list ap);


[링크 : http://linux.die.net/man/3/vsprintf] 


'Programming > C Win32 MFC' 카테고리의 다른 글

Cppcheck  (0) 2015.09.30
void형 포인터 ++  (0) 2015.07.14
printf 가변인자의 비밀?  (0) 2015.06.18
gcc 컴파일러 -D 옵션  (0) 2015.05.19
setjmp, longjmp  (0) 2015.05.19
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 구차니

월급도둑 모드 ㅋㅋㅋㅋ

유닛 테스트라고 해야하나.. 결과를 두고 하는거라 은근 잼나고

생각할게 많은 녀석..


TapeEquilibrium










[링크 : https://codility.com/programmers/]

'개소리 왈왈 > 직딩의 비애' 카테고리의 다른 글

8월...  (0) 2015.08.01
아 빔프로젝터 사고 싶다.  (0) 2015.07.18
자바의 앞날은..  (0) 2015.07.03
아씨... 오실로스코프 하나 질러?  (0) 2015.06.21
카드값 폭발!  (0) 2015.06.18
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 구차니