วันพุธที่ 20 พฤษภาคม พ.ศ. 2558

เริ่มต้นใช้งาน I2C กับบอร์ด Raspberry Pi

ตามนี้เลยครับ NYR ทดสอบแล้วใช้งานได้ครับ :)





This page details how to setup I2C support on the Raspbian “wheezy” image from http://www.raspberrypi.org/downloads


Step 1: Download the latest Raspbian “wheezy” image and burn to your SD Card following the instructions onhttp://elinux.org/RPi_Easy_SD_Card_Setup
If you are using Raspian Linux 3.18 or later you need to go into the raspberry pi config utility and enable I2C.
sudo raspi-config
Select 8 Advanced Options and then  A7 I2C - Enable/Disable automatic loading. A prompt will appear asking Would you like the ARM I2C interface to be enabled?, select Yes, exit the utility and reboot your raspberry pi.
sudo reboot
Step 2: Next you need to update your Raspberry Pi to ensure all the latest packages are installed:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
Step 3 a:  Once you have logged into your Raspberry Pi from the command line, run the following command to install SMBus and Python Dev:
sudo apt-get install python-smbus
sudo apt-get install python-dev
sudo apt-get install python3-dev
Step 3 b:  For Python 3 you need to compile the SMBus module from source and replace one of the source files with the instructions below:
Install dependency
sudo apt-get install libi2c-dev
Download i2c-tools source
wget http://ftp.de.debian.org/debian/pool/main/i/i2c-tools/i2c-tools_3.1.0.orig.tar.bz2
tar xf i2c-tools_3.1.0.orig.tar.bz2
cd i2c-tools-3.1.0/py-smbus
Backup smbusmodule.c file
mv smbusmodule.c smbusmodule.c.orig
Download patched Python 3 source
wget https://raw.githubusercontent.com/abelectronicsuk/ABElectronics_Python3_Libraries/master/smbusmodule.c
Now install the new modified smbus module
sudo bash
python3 setup.py build
python3 setup.py install
Step 4:  From the command line, run the following command to install i2c-tools:
sudo apt-get install i2c-tools
For previous releases before Raspian Linux 3.18 you need to complete the following steps:
Step 5: Enable I2C and SPI protocols. I2C and SPI protocols are turned off in the wheezy distro by default, so you will need to enable them by editing the file /etc/modprobe.d/raspi-blacklist.conf :
sudo nano /etc/modprobe.d/raspi-blacklist.conf
In the file you will see two lines, you need to disable the blacklisting of these by adding a # character before each line:
#blacklist spi-bcm2708
#blacklist i2c-bcm2708
Save your changes and exit the nano editor.
Step 6:
For recent versions of the Raspberry Pi (3.18 kernel or later) you will need to update the /boot/config.txt file.  Open the file with nano using the command:
sudo nano /boot/config.txt
Add the following text to the bottom of the file:
dtparam=i2c1=on
dtparam=i2c_arm=on
Save your changes and exit the nano editor.
All versions:
Step 7: Set the Raspberry Pi to start I2C automatically at boot by editing /etc/modules :
sudo nano /etc/modules
Use your cursor keys to move to the last line and add a new line and then add:
i2c-dev
Save your changes and exit the nano editor.
Step 8: To avoid having to run the I2C tools at root add the ‘pi’ user to the I2C group:
sudo adduser pi i2c
Step 9: Next reboot the Raspberry Pi:
sudo reboot
When your Raspberry Pi has rebooted you will now have I2C and SMBus Python 2 or 3 support.

Credit : abelectronics.co.uk

วิธีเช็คว่าใช้งานได้หรือเปล่าก็ให้ทำการจ่ายไฟเลี้ยง Arduino ต่อสายให้เรียบร้อยแล้วคีย์คำสั่ง

If you’ve got a Model A, B Rev 2 or B+ Pi then type the following command :
sudo i2cdetect -y 1
If you’ve got an original Model B Rev 1 Pi then type the following command :
sudo i2cdetect -y 0

ไม่มีความคิดเห็น:

แสดงความคิดเห็น