레이블이 automates gpio sensors인 게시물을 표시합니다. 모든 게시물 표시
레이블이 automates gpio sensors인 게시물을 표시합니다. 모든 게시물 표시

2015. 2. 15.

[Casual hacking] GPIO app project 2 : how to build Air Button using ultrasonic sensor

[Casual hacking] GPIO app project 2 : how to build Air Button using ultrasonic sensor 



This is the second project using the GPIO app.
Please note the following to build an Air Button using an ultrasonic sensor.

First of all, ultrasonic sensor adopts serial communication called UART.
If you would like to check out the specification of the sensor, you can do so by clicking the link below.
(Please note the data sheet or details from the product page of your purchased goods)

Product information from ultrasonic sensor: HG-C40U


From here on, please follow the instructions below.


1. Get your breadboard ready




Like in the picture, only TxD, RxD, GND, and 5V are connected.
An LED has also been pinned to be notified whether the settings are working properly.



2. Configure UART from the GPIO app
Please configure your settings as shown in the guideline of UI of GPIO app.
  • Baud rate : 38,400 bps
  • Data bit : 8 bit
  • Stop bit : 1 bit
  • Buffer size : 100
    • The buffer size means the number of letters that can be delivered at one transfer.
  • Register all values &  Set !
  • As a result, 'Read data’ of ultrasonic sensor is retrieved.
  • /x32/x37/x03/x02/x5e/x31/x37/x32/x38/x03/x02/x5e.. so on. Data like /x03/x02 repeats and meaningful data follows from the third.
  • (note that this is limited to HG-C40U specification and data may differ depends on your ultrasonic models.)


I will also pin a LED to provide me a feedback of whether the ultrasonic sensor has been properly placed.


3. Test the ultrasonic sensor


To test whether the ultrasonic sensor has been placed properly, I will use the rules below.

Like in the clip below, tests can be made with the two automation rules.



Lets go over with how to configure the first Rule.

“If the distance reading on ultrasonic is less than 10cm, turn on the LED."


- Check out the configuring process of the first Rule in .gif!



<How to configure a sensor app>
1. select GPIO app
2. select UART serial
3. UART Read
4. (check the green checkbox)
5. select and register filter : click '+ Advanced'
 Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!le(100)}}
This works by parsing /x03/x02 and making use of the second data in list(=[1]). This is the value retrieved from ultrasonic sensor.
(This may be a bit difficult step to some of us.. in short, le(less than and equal to) 100mm. Try testing by changing the numbers yourself!)

If you’d like to understand more about how to register code in filter values and build the rule for yourself, please try out the link(blog) below.

<How to configure an actuator app>
1. select GPIO app 
2. select Write Digital
3. select GPIO pin$
4. (check the green checkbox), Set '1’(turn on the LED)



Lets check out how to setup the second Rule.

“If the distance reading on ultrasonic is more than 10cm, turn off the LED."

- Check out the configuring process of the second Rule in .gif!



<How to configure a sensor app>
1. select GPIO app
2. select UART serial  
3. UART Read  
4. (check the green checkbox)
5. select and register filter : click '+ Advanced'
  Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!ge(100)}}
(ge(greater than and equal to) 100mm.)

<How to configure an actuator app>
1. select GPIO app
2. select Write Digital
3. select GPIO pin$
4. (check the green checkbox), Set '0’(turn off the LED)


4. Build an Air button!



Lets make use of the rules we created above for testing and create an air button.
Using the button and the Volumio app, I can 'Play music', 'Stop music', 'Volume up', 'Volume down.'

I’ve marked the heights for the buttons using a ruler and some Post-it.
… and this’s what my desk looks like :)

# Marking buttons





Heights for Air Button

         ~ 10cm : volume up
11cm ~ 20cm : volume down
21cm ~ 30cm : play music
31cm ~ 40cm : stop music

# Create automation rules



Please note the gif above for creating the first rule.

This’s been the guideline of creating an Air Button using ultrasonic wave.

Try building a button of different purpose.

Control digital devices and appliances using an Air Button next to yo ur bed.
“I wish I could turn on and off the bedside lights with Air Button."
“Turn on the monitors and notebook cooler with Air Button on my desk!"
More IoT experience to come using the GPIO app! :)

[Casual hacking] GPIO 앱 프로젝트 2 : 초음파 센서 에어 버튼(Air button) 만들기!

 [Casual hacking] GPIO app PROJECT 2 : 초음파 센서 Air button 만들기! 


GPIO 앱을 이용한 두 번째 프로젝트!
초음파 센서를 이용한 에어 버튼(Air button) 만들기 입니다.

우선 초음파 센서는 UART라는 시리얼 통신을 이용하죠.
우선 사용한 초음파 센서 사양은 아래의 링크를 통해 확인 가능합니다!
(구입하신 전자제품 쇼핑몰에 대부분 데이타 시트 및 상세 정보 등이 있으니 참고하세요)

초음파센서 제품 가이드 : HG-C40U

자 그럼 기본적인 초음파 센서를 숙지했다고 가정하고 설명을 시작해볼게요~


1. 브레드보드 셋팅하기



그림처럼 TxD, RxD, GND, 5V 만을 설정해주었습니다.
또한 제대로 셋팅했는지 알기 위해 LED를 설치해놨습니다.


2. GPIO 앱에서 UART 설정하기

제품 가이드에 나와있던 것처럼 GPIO 앱 UI에서도 똑같이 설정해주면 됩니다!


  • Baud rate : 38,400 bps
  • Data bit : 8 bit
  • Stop bit : 1 bit
  • Buffer size : 100
    • 버퍼 사이즈는 한 번에 받을 글자 사이즈를 의미해요.
  • 값들을 모두 입력해주고  Set !
  • 그러면 'Read data'에 초음파 센서로부터 데이터가 넘어오게 됩니다.
  • /x32/x37/x03/x02/x5e/x31/x37/x32/x38/x03/x02/x5e.... 같은 데이터가 반복되게 됩니다. 여기서 /x03/x02/ 가 반복되고 유용한 초음파 거리 값은 그 바로 뒤 2번째에 나옵니다.
    나중에 이 데이터를 이용해서 버튼을 만들 수 있어요!
  • (단, 저희가 가지고 있는 HG-C40U 사양에 해당하는 내용이니, 여러분의 초음파 센서와 데이터가 다를 수 있습니다!)



자 그리고 초음파 센서가 제대로 설정됐는지 확인하기 위해 LED 핀도 설정을 함께 해줄게요!


3. 초음파 센서 테스트하기

아래의 두 가지 룰로 초음파 센서가 제대로 셋팅됐는지 확인해 보겠습니다!

이 두 가지 자동화 규칙으로 아래의 영상처럼 테스트를 해볼 수 있습니다.



우선 첫 번째 Rule 설정과정부터 확인해볼게요!

"초음파 거리가 10cm 이하가 되면, LED 가 켜져라"

- 첫 번째 룰 설정 .gif 로 보기!


<센서(sensor) 앱 설정 스텝>
1. GPIO app 선택  
2. UART serial 선택  
3. UART Read  
4. (녹색박스 체크)
5. 필터 선택 및 입력 : '+ Advanced' 클릭
 Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!le(100)}}
(필터에 입력하는 값이 어렵죠..
/x03/x02 를 파싱해서 리스트의 2번째(=[1]) 데이터를 사용하는 겁니다. 위에서 말했듯이 그 값이 초음파 센서가 감지한 거리이기 때문이죠!
그리고 그 데이터를 숫자로 바꾼 후 le(less and equal) 100mm 이하거나 같다는 의미입니다. 직접 숫자를 바꿔서 테스트 해보세요!)


필터 값에 입력하는 코드를 자세히 알고, 직접 만들어보고 싶다면 아래의 링크를 참고해주세요!
'AMBLANG(엠비언시 언어) 자세히 알기'

<액츄에이터(actuator) 앱 설정 스텝>
1. GPIO app 선택  
2. Write Digital 선택  
3. GPIO pin$ 선택  
4. (녹색박스 체크), Set '1'(LED를 켜라)


이제 두 번째 Rule 설정과정을 볼게요.

"초음파 거리가 10cm 이상이 되면, LED가 꺼져라"

- 두 번째 룰 설정 .gif로 보기!


<센서(sensor) 앱 설정 스텝>
1. GPIO app 선택  
2. UART serial 선택  
3. UART Read  
4. (녹색박스 체크)
5. 필터 선택 및 입력 : '+ Advanced' 클릭
  Test True : {{{{{{data!split("\x03\x02^")}}[1]!to_int}}!ge(100)}}
(ge(greater and equal) 100mm 라는 의미입니다. 100mm보다 크거나 같거나가 되겠네요...)

<액츄에이터(actuator) 앱 설정 스텝>
1. GPIO app 선택  
2. Write Digital 선택  
3. GPIO pin$ 선택  
4. (녹색박스 체크), Set '0'(LED를 꺼라)


4. Air button 만들기!


자 이제 위의 테스트를 응용해서 에어 버튼(air button)을 만들어볼까요?
버튼의 용도는 Volumio 앱을 이용해서 'Play music', 'Stop music', 'Volume up', 'Volume down' 만들어보겠습니다!

자 우선 자로 에어 버튼을 만들기 위해 버튼의 위치를 만들어 볼게요!
... 제 책상에서 테스트 해봤어요 :)

# 버튼 설치




에어 버튼(air button) 위치

         ~ 10cm : volume up
11cm ~ 20cm : volume down
21cm ~ 30cm : play music
31cm ~ 40cm : stop music

# 자동화 룰 설정


첫 번째 룰 설정 방법만 gif 를 참고해보세요!


자 이렇게 해서 초음파(Ultrasonic wave)를 이용한 에어 버튼(air button)을 만들어봤습니다.

여러분은 다른 버튼을 만들어보세요!

초음파 거리를 이용해서 리모콘이 있던 제품, 리모콘이 없던 제품 또한 제어가 가능합니다!
"침대 옆에 에어 버튼(air button)을 만들어 전등을 껐다 켰다 하고 싶다"
"출근하고 에어 버튼(air button)을 누르면 모니터와 노트북 쿨러가 켜져라!"
GPIO  앱 프로젝트를 이용한 사물인터넷 체험은 계속됩니다! :)

2015. 1. 29.

[Casual hacking] GPIO app PROJECT 1 : Traffic lights

[Casual hacking] GPIO app PROJECT 1 : Traffic lights

What is GPIO app PROJECT?
GPIO app PROJECT is automation projects created with GPIO ports of Raspberry Pi and apps for PROTA. The result is simple. Programming is building a logical formulation that executes specific operation using computer language. The combination of the two elements, GPIO and PROTA apps, give users a chance to build for themselves logical, working products, that we believe is an user-defined programming, that they can experience in just a couple of steps.
(Users can simply program in a couple of steps using GPIO by choosing sensors on the top and actuators on the bottom.)

Projects may vary depends on the combination of the apps. To start off, you’ll be able to grasp the basic idea of the GPIO app by following the instructions below.


PROJECT 1 : Traffic lights


Have a look at the above two rules. By simply selecting and defining conditions that users desire, a formulation of traffic lights can be built in just three steps.

If you still have a hard time grasping the idea of Ambiency, please check out the link below.


[Quick & Dirty guide] Make an image file of Ambiency rule!

1. How to setup pins on the breadboard, LED, and webcam
Wire LED to GPIO pins 17 and 27.




2. Set up the GPIO app
Set the values of the above pins on the UI.
The saved values on this app becomes the source values when creating automation rules on Ambiency. Please click Remember & Save button to save.


3. Create automation rules!
Create two rules like the following by choosing the source values you've created in the above steps on the GPIO app.
  • 1st Rule
  • Sensor app - Webcam app
    Trigger - "Motion detected : Edge rising"
  • Actuator app - GPIO app
    Action - "Write value : GPIO $pin : Write=1" & "Write value : GPIO %pin : Write=0"
  • If motion detected is interrupted on Webcam -> write value 1 in the output of $pin on GPIO(app) to turn on a LED -> write value 0 in the output of %pin to turn off a LED.
  • As a result, the rule turns on the green and turns off the red traffic lights on motion detection for pedestrian signals.
  • 2nd Rule
  • Sensor app - Webcam app
    Trigger - "No motion : Edge falling"
  • Actuator app - GPIO app
    Action - "Write value : on GPIO $pin : Write=0" & "Write value : on GPIO %pin : Write=1"
  • If No motion on Webcam -> write value 0 in the output of $pin on GPIO to turn off a LED -> write value 1 in the output of %pin on GPIO to turn on a LED.
  • As a result, the rule turns off the green and turns on the red traffic lights on no motion for pedestrian signals.

4. Test and find out in History!


In this session, you’ve just created a working traffic lights by creating rules with GPIO. As shown in the first picture, there’re many combinations of rules that can be created with GPIO and other apps.

Please check out other projects you can try out in the coming sessions.

Thank you.

2015. 1. 27.

[Casual hacking] GPIO app PROJECT 1 : 신호등(Traffic lights)




[Casual hacking] GPIO app PROJECT 1 : 신호등(Traffic lights)


GPIO app PROJECT란?
GPIO app PROJECT 는 라즈베리파이를 이용한 창작물(프로젝트 결과)들을 PROTA Pi의 GPIO앱으로 구현함과 동시에~ smart hub PROTA Pi의 다른 앱들과 조합하여 자동화 룰을 만들어 보는 것입니다!
(GPIO app이 '센서(Sensor)'와 '액츄에이터(Actuator)'로 선택되어 다른 앱들과 연동이 가능합니다!)

한 가지의 프로젝트가 조합되는 앱이 무엇이냐에 따라 아주 다르게 사용될 수 있는거죠!!
아직 와닿지 않으실 수 있으니,
오늘은 아주 간단한 첫 번째 프로젝트를 소개하면서 GPIO 앱에 익숙해지는 시간을 갖겠습니다!



PROJECT 1 : Traffic lights



위에 두 개의 Rule이 있습니다.
기존에는 Programming 을 해야만 가능했던 신호등 만들기를
위의 세 개의 Rule로 만들 수 있습니다.

아직 엠비언시(ambiency) 룰 만들기를 모르신다면 아래의 링크를 확인하세요!

[Quick & Dirty guide] Automation solution, Ambiency tutorial. Why not make your own rule?

[Quick & Dirty guide] 엠비언시 룰(Ambiency rule) 이미지 만들기!


1. 보드 pin, LED, 웹캠(webcam) 셋팅하기
LED에는 GPIO17, GPIO27을 셋팅해줍니다.






2. GPIO 앱 셋팅하기
해당 pin을 GPIO 앱 UI에서 찾아서 하나씩 값을 설정해줍니다!
여기서의 설정이 엠비언시(ambiency) 앱에서 자동화 룰을 만들 때 소스(source)가 되니,
꼭 Remember & Save 를 해주셔야 됩니다!




3. 자동화 Rule 만들기!
이제 GPIO 앱에서 설정해준 소스들을 자동화 룰로 설정만 해주면 됩니다!
  • 1st Rule : 

    • Sensor app - Webcam app
      Trigger - "Motion detected
       : Edge rising"
    • Actuator app - GPIO app
      Action - "Write digital : GPIO $pin : Write=1" & "Write digital : GPIO %pin : Write=0"
    • Webcam 앱의 motion detected의 interrupted가 발생하면 -> GPIO 앱의 $pin에 output에 1을 입력하여 LED 불이 켜지고 -> %pin에 output에 0을 입력하여 LED 불이 꺼지게 한다.
    • Webcam에 물체를 감지하면 보행 신호를 켜게 하는 것입니다.

  • 2nd Rule 


    • Sensor app - Webcam app
      Trigger - "No motion : Edge falling"
    • Actuator app - GPIO app
      Action - "Write digital : GPIO $pin : Write=0" & "Write digital : GPIO %pin : Write=1"
    • Webcam 앱이 No motion이면 -> GPIO 앱의 $pin에 output에 0을 입력하여 LED 불이 꺼지게 하고 -> %pin에 output에 1을 입력하여 LED 불이 켜지게 한다.
    • Webcam에 물체가 감지되지 않으면 주행 신호를 켜게 하는 것입니다.

4. 테스트 그리고 History 확인!



'PROJECT 1 : Traffic lights' 에서는 GPIO앱과 GPIO앱 만의 자동화 규칙을 만들어 봤는데요,
위 이미지에서도 보셨듯이 GPIO앱과 연동할 수 있는 앱들은 정말 많습니다.

앞으로 유용한 PROJECT 시리즈를 소개해드릴 수 있도록 하겠습니다!

감사합니다 :)

2015. 1. 13.

[Casual hacking] Introduce GPIO app for Raspberry Pi

 [Casual hacking] GPIO app for Raspberry Pi 

What is GPIO?
GPIO stands for General Purpose Input/Output. By integrating with software, electrical input and output of a device can be controlled.

This blog post is about GPIO Raspberry Pi, one of the most popular board out there.

If you are one of its users, you’ll be able to see that it’s quite different from how you managed and built it before.




(Above is what the GPIO app looks like)


(This is what inside the app looks like when you first launch it.)


(Python code to test input & output)

This’s what it looked like before when trying code to control pins.

To list functions in the GPIO UI you’ve seen above, they are as follows:
GPIO / SPI, UART, I2C / Pull up & down / PWM

1) GPIO pins
- Input, Output


Select the specific GPIO pins that you wish.
When selected it provide you options like the following.


Selecting Input will let you Read.
You can find out if the current GPIO state is 0 or 1 with this option.


Selecting Output will send data of 0 and 1 to the specific device.
For instance, when trying to control the LED using Raspberry Pi, you can control its power using True(=1), False(=1) using python. Writing 1 in blank will turn on the LED and 0 in blank will turn off the LED.

2) PWM - GPIO18 pin
- 1 ~ 1023 write


Inputting 1023 like in the above will increase the voltage to its highest level.

What’s unique about using a GPIO app is that you can select input or output values with a few clicks.

However, this’s the real reason why it was created.


GPIO can be integrated with other apps. They can easily integrated for automation.
In the next blog post, you can find out more about how to integrate the values from GPIO with other apps and how to setup PI, UART, I2C, and Interrupt(rising, falling).

2015. 1. 10.

[Casual hacking] Introduce GPIO app for Raspberry Pi

 [Casual hacking] GPIO app for Raspberry Pi 


GPIO 란?
Genenral Purpose Input/Output. 쉽게 말해 다용도 입출력 포트를 말합니다.
GPIO를 소프트웨어와 연동해서 전기 입력 및 출력 신호를 이용하여 소프트웨어에서 구현하려고 했던 디바이스 컨트롤을 행하죠.

이번에 다루는 GPIO는 세계적인 열풍을 불러 일으킨 라즈베리파이(Raspberry Pi) GPIO 입니다!

기존 라즈베리파이 유저분들이라면 신세계를 맞이할 것 같네요^^



 (위에 GPIO 앱이 보이시나요?)

(GPIO app을 접속하면 처음 보시게 되는 Shell 화면입니다.)


(Input & Output test를 위한 python code)

기존에는 위와 같은 코딩을 통해서 pin들을 컨트롤해왔었죠?!

이제 위 이미지에서 봤던 GPIO 앱 UI를 순서대로 하나씩 설명해 드리겠습니다!^^
GPIO / SPI,UART,I2C / Pull up & down / PWM

1) GPIO pins 
    - Input, Output

해당 GPIO pin 들을 마우스로 선택해줍니다.
선택하면 아래의 옵션이 보이게 되죠.
input option은 Read 를 할 수 있습니다.
현재 해당 GPIO 의 상태가 0인지 1인지를 판단할 수 있죠!



 Output option은 1과 0을 입력하여 해당 device에 data값을 보내줍니다.
예를 들자면,
기존 Raspberry Pi를 이용하여 LED 를 컨트롤 하려고 하면, python 의 경우 True(=1), False(=1)로 LED 의 전원을 제어할 수 있었죠!
blank에 1을 Write하면 LED 가 켜지고, 0을 Write하면 LED 가 

2) PWM - GPIO18 pin
    - 1 ~ 1023 write

위의 이미지에서는 PWM값을 1023으로 입력하여 전압 폭을 늘리는 시도를 하고 있네요!

GPIO 앱을 사용하면 기존의 번거로운 코딩없이 입출력을 클릭 몇번으로 사용할 수 있는 것이 큰 매력이라고 할 수 있습니다.

하지만 GPIO 앱이 개발된 가장 큰 이유는 바로!

PROTA에 설치되어 있는 다른 앱들과의 자동화를 실현할 수 있다는 점입니다!!
실제로 GPIO 값을 다른 앱들과 연동하여 자동화 하는 case는 SPI, UART, I2C, Interrupt(rising, falling) 값을 설정하는 법과 함께 다음 포스팅에서 소개해드리겠습니다!^^