Saturday, August 30, 2014

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

No comments:

Post a Comment