Difference between revisions of "RPi Peripherals"

From eLinux.org
Jump to: navigation, search
(Wireless: TP-Link TL-WN722N USB wireless adapter (Debian 6))
(added GPIO pin reference (cf rpdom) and a reference to the serial port page)
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
[[Category:RaspberryPi]]
 
=Setup examples for various peripherals=
 
=Setup examples for various peripherals=
 +
=== GPIO wiring ===
 +
{|
 +
!Pin
 +
!Function(s)
 +
|-
 +
|1
 +
| 3.3 volt power
 +
|-
 +
|2
 +
| 5 volt power
 +
|-
 +
|3
 +
| GPIO 2 used as SDA
 +
|-
 +
|4
 +
| 5 volt power
 +
|-
 +
|5
 +
| GPIO 3 used as SCL
 +
|-
 +
|6
 +
| 0 volt Ground
 +
|-
 +
|7
 +
| GPIO 4
 +
|-
 +
|8
 +
| GPIO 14 used as UART serial data transmit (TxD)
 +
|-
 +
|9
 +
| 0 volt Ground
 +
|-
 +
|10
 +
| GPIO 15 used as UART serial data receive (RxD)
 +
|-
 +
|11
 +
| GPIO 17
 +
|-
 +
|12
 +
| GPIO 18
 +
|-
 +
|13
 +
| GPIO 27
 +
|-
 +
|14
 +
| 0 volt ground
 +
|-
 +
|15
 +
| GPIO 22
 +
|-
 +
|16
 +
| GPIO 23
 +
|-
 +
|17
 +
| 3.3 volt power
 +
|-
 +
|18
 +
| GPIO 24
 +
|-
 +
|19
 +
| GPIO 10 used as SPI0 MOSI
 +
|-
 +
|20
 +
| 0 volt Ground
 +
|-
 +
|21
 +
| GPIO 9 used as SPI0 MISO
 +
|-
 +
|22
 +
| GPIO 25
 +
|-
 +
|23
 +
| GPIO 11 used as SPI0 SCLK
 +
|-
 +
|24
 +
| GPIO 8 used as SPI0 CE0
 +
|-
 +
|25
 +
| 0 volt Ground
 +
|-
 +
|26
 +
| GPIO 7 used as SPI0 CE1
 +
|}
 +
On earlier model Bs some of the pins were different as follows
 +
{|
 +
|-
 +
|3
 +
| GPIO 0 used as SDA
 +
|-
 +
|5
 +
| GPIO 1 used as SCL
 +
|13
 +
| GPIO 21
 +
|}
 +
You can confirm you have a Revision 2 board by the presence of a hole at the west of the USB connector.
 +
===Serial Port===
 +
Uses GIO pins 8 and 10 as TxD and RxD respectively which can then be accessed through serial port software such as Putty or the Java RXTX package.  See [[RPi_Serial_Connection]] for details.
  
 
===Wireless: TP-Link TL-WN722N USB wireless adapter (Debian 6)===
 
===Wireless: TP-Link TL-WN722N USB wireless adapter (Debian 6)===
 
'''IMPORTANT NOTE: Although I thought I'd got this particular TP-Link adapter working, it's not actually connecting to the network (Damn! Working on it), but I'm leaving this info here as it will be useful to others, but do check the [http://elinux.org/RPi_VerifiedPeripherals hardware compatibility list] to ensure your dongle is supported.''' [[User:Linker3000|Linker3000]]
 
  
 
See also:
 
See also:
Line 64: Line 160:
  
 
<pre>
 
<pre>
  root@raspberrypi:~# iwconfig
+
  root@raspberrypi:~# sudo iwconfig
 
   lo        no wireless extensions.
 
   lo        no wireless extensions.
  
Line 87: Line 183:
  
 
* Create the wpa.conf file - eg: sudo vi /etc/wpa.conf:
 
* Create the wpa.conf file - eg: sudo vi /etc/wpa.conf:
 +
 +
'''Note: The ssid is case sensitive - if your WLAN's SSID is MYLAN, using "mylan" will not work - you won't connect!'''
  
 
<pre>
 
<pre>
Line 105: Line 203:
 
</pre>
 
</pre>
  
If you are now connected, well done! If not, check your editing and also have a look at the output of dmesg to see if you have any error messages.
+
* Double-check whether you are connected - below the WLAN interface has been given an IP address - looks good!
 +
 
 +
<pre>
 +
root@raspberrypi:~# ifconfig
 +
eth0      Link encap:Ethernet  HWaddr b8:27:eb:76:7e:2e
 +
          inet addr:192.168.202.75  Bcast:192.168.202.255  Mask:255.255.255.0
 +
          UP BROADCAST RUNNING MULTICAST  MTU:1488  Metric:1
 +
          RX packets:1060 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:1000
 +
          RX bytes:95749 (93.5 KiB)  TX bytes:48493 (47.3 KiB)
 +
 
 +
lo        Link encap:Local Loopback
 +
          inet addr:127.0.0.1  Mask:255.0.0.0
 +
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
 +
          RX packets:8 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:0
 +
          RX bytes:560 (560.0 B)  TX bytes:560 (560.0 B)
 +
 
 +
wlan0    Link encap:Ethernet  HWaddr b0:48:7a:91:5c:f4
 +
          inet addr:192.168.222.161  Bcast:192.168.222.255  Mask:255.255.255.0
 +
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 +
          RX packets:31 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:1000
 +
          RX bytes:2260 (2.2 KiB)  TX bytes:1542 (1.5 KiB)
 +
</pre>
 +
 
 +
If you are now connected, well done! If not, check your editing and also have a look at the output of ''dmesg'' to see if you have any error messages. You can also view the system log for messages - for example: ''sudo cat /var/log/messages | more''
 +
 
 +
You are connected, you can ping and be pinged, hovewer to add network connectivity you may want to specify define default gateway:
 +
<pre>sudo route add default gw 192.168.1.254 wlan0</pre>
 +
 
 +
==Notes==
 +
 
 +
'''USB interrupt/dma system debug messages'''
 +
 
 +
Firing up the TP-Link USB WLAN interface generates a lot of debug messages in the system log like this:
 +
 
 +
DEBUG:handle_hc_chhltd_intr_dma:: XactErr without NYET/NAK/ACK
 +
 
 +
Things may calm down a bit if the following file is created in /etc/modprobe.d (eg: sudo vi /etc/modprobe.d/smscnonturbo.conf) and then the RPi rebooted:
 +
 
 +
'''smscnonturbo.conf:'''
 +
<pre>
 +
options smsc95xx turbo_mode=N
 +
</pre>
 +
 
 +
This fix may slow down wired LAN performance but help with wireless and reduce the frequency of the debug messages - YMMV. If you want to undo this fix, just delete the file (sudo rm /etc/modprobe.d/smscnonturbo.conf) and reboot.
 +
 
  
 
'''Firmware requirements'''
 
'''Firmware requirements'''
Line 118: Line 266:
  
 
Armed with this information, try a web search for 'debian 6' and the name of the driver or driver file and/or head over to http://linuxwireless.org. Also check the links at the top of this page.
 
Armed with this information, try a web search for 'debian 6' and the name of the driver or driver file and/or head over to http://linuxwireless.org. Also check the links at the top of this page.
 +
 +
'''Power requirements'''
 +
 +
If you experience erratic network, keyboard, mouse or Raspberry Pi operation when using a USB wifi dongle, check that whatever is powering your RPi and/or USB hub can deliver sufficient current for everything that's connected together. The first setup tried with the TP-Link adapter had it, a keyboard, mouse and the RPi all connected to a Trust 7-port powered USB hub with a 5V 2A power supply, but in this configuration the mouse stopped working. In this case, the fix was to power the RPi from a separate 5V 1A phone power adapter.
 +
 +
'''wpasupplicant deamon failed to start'''
 +
 +
a) If you get this error when you attempt to
 +
<pre>
 +
sudo ifup wlan0
 +
</pre>
 +
Then there may be a syntax error in your
 +
<pre>
 +
/etc/wpa.conf
 +
</pre>
 +
For example, ensure that your SSID and Password have double quotes round them, and that the curly brackets are closed.
 +
 +
b) Another possible solution could be changing:
 +
<pre>
 +
iface wlan0 inet dhcp
 +
</pre>
 +
to
 +
<pre>
 +
iface wlan0 inet manual
 +
</pre>
 +
in /etc/network/interfaces.  Then sudo ifup wlan0 then sudo ifdown wlan0 then changing manual to dhcp. Works me, as described http://unix.stackexchange.com/a/7717.

Revision as of 23:18, 18 March 2013

Setup examples for various peripherals

GPIO wiring

Pin Function(s)
1 3.3 volt power
2 5 volt power
3 GPIO 2 used as SDA
4 5 volt power
5 GPIO 3 used as SCL
6 0 volt Ground
7 GPIO 4
8 GPIO 14 used as UART serial data transmit (TxD)
9 0 volt Ground
10 GPIO 15 used as UART serial data receive (RxD)
11 GPIO 17
12 GPIO 18
13 GPIO 27
14 0 volt ground
15 GPIO 22
16 GPIO 23
17 3.3 volt power
18 GPIO 24
19 GPIO 10 used as SPI0 MOSI
20 0 volt Ground
21 GPIO 9 used as SPI0 MISO
22 GPIO 25
23 GPIO 11 used as SPI0 SCLK
24 GPIO 8 used as SPI0 CE0
25 0 volt Ground
26 GPIO 7 used as SPI0 CE1

On earlier model Bs some of the pins were different as follows

3 GPIO 0 used as SDA
5 GPIO 1 used as SCL 13 GPIO 21

You can confirm you have a Revision 2 board by the presence of a hole at the west of the USB connector.

Serial Port

Uses GIO pins 8 and 10 as TxD and RxD respectively which can then be accessed through serial port software such as Putty or the Java RXTX package. See RPi_Serial_Connection for details.

Wireless: TP-Link TL-WN722N USB wireless adapter (Debian 6)

See also:

http://www.element14.com/community/docs/DOC-44703/l/raspberry-pi-wifi-adapter-testing

http://omer.me/2012/04/setting-up-wireless-networks-under-debian-on-raspberry-pi/

This will serve as a general guide for USB wireless devices but may need modifying for your specific one.

  • Edit /etc/apt/sources.list to add the non-free archive and backports (eg: sudo vi /etc/apt/sources.list):
 deb http://ftp.us.debian.org/debian/ squeeze main non-free
 deb http://security.debian.org/ squeeze/updates main non-free
 deb http://ftp.us.debian.org/debian/ squeeze-updates main non-free
 deb http://backports.debian.org/debian-backports squeeze-backports main non-free
  • Update the package cache:
 sudo apt-get update
  • Download the wifi utils:
 sudo apt-get install wireless-tools usbutils 
  • Download the required firmware and put it in the correct location - you may not need to do this for your adapter or you may need different firmware - see below.
 sudo apt-get install firmware-atheros
 sudo wget http://linuxwireless.org/download/htc_fw/1.3/htc_9271.fw
 sudo cp htc_9271.fw /lib/firmware
  • Add adapter definition to network config - eg: sudo vi /etc/network/interfaces - add the wlan0 section:
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.

auto lo

iface lo inet loopback
iface eth0 inet dhcp

# The wireless interface
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa.conf
  • Plug in adapter
  • Confirm adapter is present:
 root@raspberrypi:~# sudo iwconfig
  lo        no wireless extensions.

  eth0      no wireless extensions.

  wlan0     IEEE 802.11bgn  ESSID:off/any
            Mode:Managed  Access Point: Not-Associated   Tx-Power=20 dBm
            Retry  long limit:7   RTS thr:off   Fragment thr:off
            Encryption key:off
            Power Management:off
  • Scan your network to see what wireless access points can be seen. You may need to do this to identify your network's SSID (name), but it also confirms that the wifi dongle is doing something. The first command just lists the SSIDs found, the second tells you probably more than you ever want to know:
  sudo iwlist wlan0 scan | grep ESSID

or

  sudo iwlist wlan0 scan
  • Create the wpa.conf file - eg: sudo vi /etc/wpa.conf:

Note: The ssid is case sensitive - if your WLAN's SSID is MYLAN, using "mylan" will not work - you won't connect!

network={
ssid="NETWORK-SSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="YOUR-WLAN-PASSWORD"
}
  • Start the adapter
  sudo ifup wlan0
  • Double-check whether you are connected - below the WLAN interface has been given an IP address - looks good!
 root@raspberrypi:~# ifconfig
 eth0      Link encap:Ethernet  HWaddr b8:27:eb:76:7e:2e
           inet addr:192.168.202.75  Bcast:192.168.202.255  Mask:255.255.255.0
           UP BROADCAST RUNNING MULTICAST  MTU:1488  Metric:1
           RX packets:1060 errors:0 dropped:0 overruns:0 frame:0
           TX packets:146 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000
           RX bytes:95749 (93.5 KiB)  TX bytes:48493 (47.3 KiB)

 lo        Link encap:Local Loopback
           inet addr:127.0.0.1  Mask:255.0.0.0
           UP LOOPBACK RUNNING  MTU:16436  Metric:1
           RX packets:8 errors:0 dropped:0 overruns:0 frame:0
           TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:0
           RX bytes:560 (560.0 B)  TX bytes:560 (560.0 B)

 wlan0     Link encap:Ethernet  HWaddr b0:48:7a:91:5c:f4
           inet addr:192.168.222.161  Bcast:192.168.222.255  Mask:255.255.255.0
           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
           RX packets:31 errors:0 dropped:0 overruns:0 frame:0
           TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:1000
           RX bytes:2260 (2.2 KiB)  TX bytes:1542 (1.5 KiB)

If you are now connected, well done! If not, check your editing and also have a look at the output of dmesg to see if you have any error messages. You can also view the system log for messages - for example: sudo cat /var/log/messages | more

You are connected, you can ping and be pinged, hovewer to add network connectivity you may want to specify define default gateway:

sudo route add default gw 192.168.1.254 wlan0

Notes

USB interrupt/dma system debug messages

Firing up the TP-Link USB WLAN interface generates a lot of debug messages in the system log like this:

DEBUG:handle_hc_chhltd_intr_dma:: XactErr without NYET/NAK/ACK

Things may calm down a bit if the following file is created in /etc/modprobe.d (eg: sudo vi /etc/modprobe.d/smscnonturbo.conf) and then the RPi rebooted:

smscnonturbo.conf:

 options smsc95xx turbo_mode=N

This fix may slow down wired LAN performance but help with wireless and reduce the frequency of the debug messages - YMMV. If you want to undo this fix, just delete the file (sudo rm /etc/modprobe.d/smscnonturbo.conf) and reboot.


Firmware requirements

If no wlanx device is shown, you might need to download firmware for your USB wifi device (or track down other compatible drivers if they are available). To confirm this, check the dmesg output when you plug in your adapter - typing dmesg at the command prompt may be sufficient - and look for information related to your adapter - the example dmesg output below shows what is seen in the event of the TP-Link firmware not being present - notice that the name of the required firmware file is given (htc_9271.fw), the driver name (ath9k_htc) and an error -22 message:

  usb 1-1.2.4.2: ath9k_htc: Firmware - htc_9271.fw not found
  ath9k_htc: probe of 1-1.2.4.2:1.0 failed with error -22
  usbcore: registered new interface driver ath9k_htc

Armed with this information, try a web search for 'debian 6' and the name of the driver or driver file and/or head over to http://linuxwireless.org. Also check the links at the top of this page.

Power requirements

If you experience erratic network, keyboard, mouse or Raspberry Pi operation when using a USB wifi dongle, check that whatever is powering your RPi and/or USB hub can deliver sufficient current for everything that's connected together. The first setup tried with the TP-Link adapter had it, a keyboard, mouse and the RPi all connected to a Trust 7-port powered USB hub with a 5V 2A power supply, but in this configuration the mouse stopped working. In this case, the fix was to power the RPi from a separate 5V 1A phone power adapter.

wpasupplicant deamon failed to start

a) If you get this error when you attempt to

sudo ifup wlan0

Then there may be a syntax error in your

/etc/wpa.conf

For example, ensure that your SSID and Password have double quotes round them, and that the curly brackets are closed.

b) Another possible solution could be changing:

iface wlan0 inet dhcp

to

iface wlan0 inet manual

in /etc/network/interfaces. Then sudo ifup wlan0 then sudo ifdown wlan0 then changing manual to dhcp. Works me, as described http://unix.stackexchange.com/a/7717.