Saturday, August 30, 2014

Work Process-การทดลองใช้ Linear Hall Effect Sensor-KY024

ระบบปฏิบัติการที่ใช้


  • Ubuntu 12.10

อุปกรณ์ฮาร์ดแวร์มีดังนี้

  • บอร์ด Raspberry Pi 512 MB model B
  • SD card ขนาด 8+ GB
  • Wireless USB Adapter
  • micro USB Cable  + 5V. AC/DC Adapter
  • Linear Hall Effect Sensor-KY024
  • magnetic 



ขั้นตอนการดำเนินงาน

1.) เตรียมบอร์ด raspberry pi ให้พร้อมสำหรับการใช้งาน ผ่าน SSH โดยการเชื่อมต่อด้วย Wi-Fi

2.) เชื่อมต่อ pin ของ Linear Hall Effect Sensor-KY024 เข้ากับบอร์ด raspberry pi โดยต่อเข้ากับ GPIO Pin ดังนี้
     VIN     ต่อเข้ากับ    5V  Voltage pin
     GND     ต่อเข้ากับ    ground
     D0      ต่อเข้ากับ    GPIO 24

3.) ทดสอบการใช้งานด้วยการนำเซนเซอร์เข้าใกล้กับแม่เหล็ก

       - ก่อนนำเซนเซอร์เข้าใกล้กับแม่เหล็กจะเห็นได้ว่า หลอด LED ติดแค่ดวงเดียว


      - เมื่อนำเซนเซอร์เข้าใกล้กับแม่เหล็ก หลอด LED จะติดทั้ง 2 ดวง



4.) ทดสอบในส่วนของ Analog pin โดยการนำ Oscilloscope เข้ามาวัดแรงดันเอาต์พุตของเซนเซอร์ โดยแบ่งเป็นสองช่วงคือ ช่วงที่เซนเซอร์อยู่ห่างจากแม่เหล็ก LED ดับ 1 ดวง และช่วงที่เซนเซอร์อยู่ติดกับแม่เหล็ก LED ติดสองดวง

     - ช่วงแรก คือ ช่วงที่เซนเซอร์อยู่ห่างจากแม่เหล็ก วัดค่าแรงดันได้ที่ 2.20 V โดยเอาต์พุตของแรงดันที่ได้มีลักษณะเป็น linear




เซนเซอร์อยู่ห่างกับแม่เหล็ก วัดแรงดันได้ 2.20 V

- ช่วงที่สอง คือ ช่วงที่นำเซนเซอร์เข้ามาใกล้(ติด) กับแม่เหล็ก จะเห็นได้ว่าแรงดันเอาต์พุตที่ได้มีค่าลดลงจาก 2.20 V เป็น 1.64 V และยังมีลักษณะเป็น linear 



     
เซนเซอร์อยู่ใกล้(ติด) กับแม่เหล็ก วัดแรงดันได้ 1.64 V

     - จากการทดลองวัดแรงดันเอาต์พุตพบว่าค่าแรงดันที่ได้ขึ้นอยู่กับระยะห่างระหว่างเซนเซอร์กับแม่เหล็ก เมื่อแม่เหล็กเข้าใกล้กับเซนเซอร์แรงดันที่ได้จะต่ำลง แต่เมื่อแม่เหล็กออกห่างจากเซนเซอร์แรงดันที่ได้จะเพิ่มขึ้น

5.) ทดสอบการทำงานของเซนเซอร์โดยการเขียนโปรแกรมให้แสดงสถานะเมื่อเข้าใกล้แม่เหล็ก โดยเมื่อมีแม่เหล็กเข้ามาใกล้กับเซนเซอร์ จะได้เอาต์พุตเป็น Switch state active, rising edge detected - LED ON
แต่เมื่อ นำแม่เหล็กออกห่างจากเซนเซอร์จะได้เอาต์พุตเป็น switch state off,falling edge detected - LED OFF





ที่มา :










Work Process-การทดลองใช้ Barometric Pressure Sensor

ระบบปฏิบัติการที่ใช้

  • Ubuntu 12.10 

 

อุปกรณ์ฮาร์ดแวร์มีดังนี้

  • บอร์ด Raspberry Pi 512 MB model B
  • SD card ขนาด 8+ GB
  • Wireless USB Adapter
  • micro USB Cable  + 5V. AC/DC Adapter
  • Barometric Pressure Sensor(BMP180)


ขั้นตอนการดำเนินงาน

1.) เตรียมบอร์ด Raspberry Pi ให้พร้อมสำหรับการใช้งานผ่าน Wi-Fi และ log in เข้าสู่ระบบด้วยโปรแกรม Putty

2.) เชื่อมต่อ pin ของ  Barometric Pressure Sensor-BMP180 เข้ากับบอร์ด Raspberry Pi  โดยต่อเข้ากับ GPIO Pin ดังนี้
     VIN   ต่อเข้ากับ 3.3V Voltage pin
     GND   ต่อเข้ากับ ground
     SCL   ต่อเข้ากับ I2C Clock
     SDA   ต่อเข้ากับ I2C Data
   
อ้างอิ่ง ref: http://2014.makerland.org/event/tutorials/raspberrypi/



3.) ตั้งค่าการใช้งาน I2C บนบอร์ด Raspberry Pi (เนื่องจาก Barometric Pressure Sensor-BMP180 มีการสื่อสารด้วย I2C bus) โดยมีขั้นตอนดังนี้
  • ให้แก้ไขไฟล์ /etc/modules โดยคำสั่งต่อไปนี้
     sudo nano /etc/modules

  • เพิ่มบรรทัดดังต่อไปนี้ลงไปในส่วนล่างสุดของไฟล์       
     i2c-bcm2835
     i2c-dev
    
  • ติดตั้งเครื่องมือ i2c บน raspberry pi
     sudo apt-get install python-smbus
     sudo apt-get install i2c-tools

  • เปิดไฟล์ /etc/modprobe.d/raspi-blacklist.conf ด้วยคำสั่ง

     sudo nano /etc/modprobe.d/raspi-blacklist.conf

  • แก้ไขบรรทัดดังต่อไปนี้ด้วยการเพิ่ม # ไปข้างหน้า เพื่อเอา blacklist ออก  

     blacklist spi-bcm2708
     blacklist i2c-bcm2708

  • ทำการ reboot Raspberry Pi

     sudo reboot

  • log in เข้าไปยัง Raspberry pi และใช้คำสั่งดังต่อไปนี้เพื่อตรวจสอบ i2c address

     sudo i2cdetect -y 1



     จะเห็นได้ว่า i2c address ที่ปรากฏขึ้น คือ 77 เมื่อนำไปตรวจสอบกับ datasheet ของ BMP180 แล้วจะพบว่า i2c address นั้นตรงกัน



4.) ทดสอบการทำงานของ BMP180 โดยใช้ Adafruit BMP085 Python Library(สามารถใช้ได้กับ BMP180) ซึ่งสามารถ Download ได้จาก https://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code
หรือ Download ด้วยคำสั่ง
     git clone https://github.con/adafruit/Adafruit-Raspberry-Pi-Python-Code.git

  • เข้าไปภายใน directory Adafruit-Raspberry-Pi-Python-Code  

    cd Adafruit-Raspberry-Pi-Python-Code


  • เนื่องจากบอร์ด Raspberry Pi ที่ใช้ เป็น version 2 (512 MB) จึงต้องแก้ไขไฟล์ Adafruit_I2C.py จาก

     def __int__(self,address,bus=smbus.SMBus(0),debug = Faulse):
   เป็น

     def __int__(self,address,bus=smbus.SMBus(1),debug = Faulse):
     

  • ทดสอบการทำงาน ด้วยคำสั่ง

     sudo python example/simple.py 


ผลการทำงาน


ทดสอบการนำค่าจาก Barometric Pressure Sensor(BMP180) มา Plot Graph

ผลการทำงาน



ปัญหาที่เกิด

    - ในการนำค่าที่ได้จาก barometric pressure sensor มา plot graph มีการแสดงเอาต์พุตหรือจุดที่พล็อต ค่อนข้างช้ามาก
    - เกิดปัญหา raspberry pi มีอุณหภูมิที่ค่อนข้างสูงกว่าปกติ


ที่มา :

https://learn.adafruit.com/using-the-bmp085-with-raspberry-pi/using-the-adafruit-bmp085-python-library

https://learn.adafruit.com/adafruits-raspberry-pi-lesson-4-gpio-setup/configuring-i2c

http://elinux.org/RPi_Low-level_peripherals

Saturday, August 16, 2014

แหล่งข้อมูลและความรู้ที่เกี่ยวข้องในการทำ

Raspberry Pi Hall Effect switchแหล่งข้อมูลและความรู้ที่เกี่ยวข้องในการทำ

Android กับการใช้งาน AsyncTask เบื้องต้น :
http://devahoy.com/2014/05/android-asynctask-tutorial/

Link : การใช้งาน GPS Module กับ Raspberry Pi
Link : Low-pass filter Wikipedia
Link : SensorEvent : TYPE.ACCELEROMETER

บทความ

RestFul vs SOAP อันไหนดี
- Google App Engine
เครื่องวัดสนามแม่เหล็ก
Hall Effect Sensor( Magnetic Sensor) คืออะไร

Raspberry Pi

- Model B IO PIN
GPIO Electrical Specifications

Sensor

   
 Hall Effect Sensor  

   - Tutorial: How to use the hall effect sensor with Arduino
   - Using Hall Effect Switches and Sensors 
   - Raspberry Pi Hall Effect switch
   - Low Cost Hall Effect Sensor
   - A Strange Attraction. Various Hall Effect Sensors 
   - How do I measure the RPM of a wheel?
   - Reading Fan RPM
   - Hall effect and GPIO
   - Raspberry Pi Hall Effect switch

Other Devices 

- Interfacing an SPI ADC (MCP3008) chip to the Raspberry Pi using C++ (spidev)

Cloud Service

Google Cloud SQL
- Google App Engine
- Google Cloud Storage
Rackspace
- Cloud data
- xively
- APEX Fusion
- Cloud Platform


DIY

- Home automation with Remoht.us
- RPi Android HTML5 Realtime Servo Control
- Start Using HTML5 WebSockets Today
- Google Cloud Platforrm
- Raspberry Pi Temperature Logger With Xively
- *First test with EVRYTHNG cloud, Raspberry PI and Python
Live Web Bicycle Dashboard using ControlMyPi
***********Live Web Bicycle Dashboard - the code
Raspberry Pi + TMP36 Temperature Sensor
Movable Parts
Rest of You: Bike Forces
ReadingRPM

Books

- Beginning Sensor Networks with Arduino and Raspberry Pi