1. 程式人生 > >樹莓派 零 Zero W 串列埠SSH登入和無線配置

樹莓派 零 Zero W 串列埠SSH登入和無線配置

新的raspberry pi,刷了RetroPi,但是無法識別usb hub下的鍵盤,直接插鍵盤就可以,但是用hub就不行,試了很多方法無果。


於是先嚐試ssh登入到系統。但是沒有網絡卡所以網線無法直連,而板載wifi沒初始化配置過,所以也連線不了,只有通過硬體串列埠來。

參照網上方法,GPIO40pin排針,左上角,前兩個為5v。從第三個開始,順延三個pin,分別接到usb-ttl串列埠工具(CH340,CP2102,FT232)的GND,TXD,RXD腳。

因為我板子已經供電,所以只接三根線到usb棒到膝上型電腦即可通訊。另外還需要拔下micro sd卡,用讀卡器修改config.txt檔案,在最後加一句enable_uart=1,並且配置相關視訊尺寸設定。


retropie啟動後,需要蠻久的,才能看到登入pi資訊,不管,先開啟putty慢慢等。COM10,115200波特率。


SSH登入進入後raspi-config指令可以進系統設定介面。但裡面並沒有網絡卡設定,所以懷疑Retropi 4.3映象的raspbian韌體很舊,並不支援zero W的無線wifi和藍芽外設。

於是只能手動配置。


ifconfig先檢視wlan0,找到wlan0存在,但是沒有資料收發。說明這就是wifi板載。

nano/etc/network/interfaces


修改內容,加入這三句話:

auto wlan0 allow-hotplug wlan0
iface wlan0 inet dhcp

儲存退出,再去修改密碼配置檔案:

nano/etc/wpa_supplicant/wpa_supplicant.conf


然後內容 ,改家裡網路ssid和密碼配置:

“裡面的內容需要你自己對照著修改,如果WiFi是WEP加密的或者沒密碼的,就按照如下形式表示: 
network={ 
ssid=”你的WiFi的SSID” 
key_mgmt=NONE 
priority=4 

如果WiFi是WPA/WPA2加密的,就按照如下形式表示:

network={
    ssid="你的WiFi的SSID"
    key_mgmt=WPA-PSK
    psk="你的密碼"
    priority=5
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

其中ssid表示WiFi的SSID號,key_mgmt表示加密型別,key_mgmt=NONE表示沒有密碼或者WEP,key_mgmt=WPA-PSK表示WPA/WPA2加密,psk表示密碼,沒有密碼就不用寫,priority表示優先順序,大的優先連線,一般這兩種就夠了。”

最後reboot重啟,就成功了,wifi OK,可以連網,有資料。




嘗試升級系統後,依然識別不了鍵盤。

用lsusb和dmesg發現,識別並掛載了usb hub,四口,但是讀寫通訊有問題,列舉失敗。



分析上述錯誤資訊,感覺像是插入鍵盤後發生的。於是重啟系統,不帶鍵盤啟動,先用dmesg查日誌發現沒有上述紅色的錯誤資訊。

然後再熱插接入usb鍵盤到hub,再dmesg就發現出現了上述紅色資訊。說明該鍵盤跟hub某種程度上不相容。證實了想法。


但是換了一個滑鼠後,還是一樣的錯誤資訊。

於是上網搜了搜,發現有高手遇到類似的問題:

http://blog.163.com/[email protected]/blog/static/1320681162010101804218436/

今天除錯USB HOST ,當插入U盤的時候發現了以下的錯誤

device descriptor read/64, error -71

原始碼中的-71(/include/asm-generic/erro.h)代表的是協議的錯誤,百思不得其解

晚上睡覺的時候,想到,協議的錯誤應該就是時序的錯誤,時序的錯誤就代表了硬體走線應該是有問題,

把到USB埠的線做的很短,發現問題解決了。

https://community.nxp.com/thread/294381

In my case, it was a non-required resistors on the data lines, which were attenuating signal and causing USB to work/fail intermittently.

Once they were removed, all was well.

--Rohith


My problem occurred because one of the power rails was not connected properly on our own hardware.  Once that was fixed, devices enumerated  correctly.  In our case, no devices worked at all.  As Make suggested, it seems that your problem is not the same as ours.

看樣子。跟供電和硬體的關係很大。hub的下口5v上並10uF電容也沒有用。後來用u盤測試,發現插U盤是可以成功識別的。看來真是相容性問題。


問題依然待解決。。。。。

hub


http://www.guyrutenberg.com/2008/06/26/usb-1-4-device-descriptor-read64-error-71/


usb 1-4: device descriptor read/64, error -71


When I try to connect my Sansa Clip MP3 player to the linux box I see the following error indmesg:

usb 1-4: device descriptor read/64, error -71

and the device recognition fails. The player’s battery gets reloaded but I can’t mount it and transfer songs.

The solution that worked for me was runnig as root

echo Y > /sys/module/usbcore/parameters/old_scheme_first

The general idea behind the solution is that there are two way to enumerate USB devices according to the standard. The method that is currently used by default in the usbcore module is similar to the one found in Windows. Apparently There are devices, and the Sansa Clip is among them, that require the other method to function properly. See Linux USB FAQ for more info.




http://blog.csdn.net/huangxiaohu_coder/article/details/13267525


裝置名:中興MF190

    Linux Kernel版本:3.4

    錯誤名:usb 1-1: device descriptor read/64, error -110
                    usb 1-1: device not accepting address 33, error -110
                    usb 1-1: device not accepting address 34, error -110

    症狀:我的3G USB dongle在平臺上第一次插拔(不管是開機插拔還是熱插拔)都能正常執行,不過當我拔掉後,再插上,便會出現以上所示的錯誤,我用lsusb命令也看不到有任何的新裝置被識別出來,之後我插上USB滑鼠也是同樣的被識別不出來

    解決方式:1.這裡的error-110,實際上式連線超時的錯誤,至於為什麼會出現這個錯誤,還不明所以,後來搜尋到資料說USB2.0的驅動有些問題,會導致這樣的問題,和USB相關的模組是ehci_hcd模組,你可以通過lsmod命令檢視你當前的kernel是否載入ehci_hcd模組,若載入了你可以使用modeprobe -r ehci_hcd把該模組解除安裝掉,之後你再試試看裝置能否被發現;如果還是不行,你找到系統的開機指令碼在開機的時候不載入ehci_hcd模組,我便是這樣在在開機的時候不載入ehci_hcd的模組,以後熱插拔便恢復了正常。

    不過這樣之後對USB的傳輸速度應該有一定的影響,這裡只是暫時使用此方法解決,後續若有新發現,繼續更新,若有同學有新的線索,懇請交流哦。



---

我這兩天一直在分析原因,感覺應該是走線的問題,D+D-的查分資料問題眼圖波型。原來的四口hub裸板,能識別到usb hub,但是hub下級的鍵盤和按鈕板都識別不了,插上U盤勉強可以識別,但是用lsusb和dmesg檢視詳細資訊發現依然有識別錯誤的條目。說明類似接觸不良似好非好的狀態。


又懷疑是5V供電的問題,懷疑是充電器Adapter的5V干擾,但是換了乾淨的線性直流電源DC 5V供電,問題依舊,所以排除電源因素。

嘗試在hub輸出的口加電容,10uF貼片到100uF電解,都試過了,無果。

今天嘗試了一個全新的usb hub後,終於可以確認問題所在,hub到pi zero的USB OTG走線我用的一段5cm排線,所以也出現了偶爾能識別偶爾不能識別的問題。一旦我理下線的擺放,在lsusb下確認hub都識別成功後,我在hub下級再隨便掛接什麼鍵盤U盤都沒問題了,說明hub下級訊號OK,OTG口給的5V供電也完全也OK不存在不足,可以確認就是遮蔽線不能用排線隨便亂替代的問題了。


所以根本不是什麼沒有驅動程式的鍋。linux的Rasbian的系統很完善好嗎,usb HID裝置都能自動列舉識別出來的,根本不要裝驅動。

--------------


又試了下,安裝一個按鈕來關機。關機按鈕,一個按鈕串100歐保護電阻然後直接掛接到gpio7和GND,正好是40pin header的25,26腳,相鄰兩個,測試關機成功了。

這樣再也不擔心關機時直接熱拔電源損害快閃記憶體卡的問題了:

http://shumeipai.nxez.com/2014/09/01/add-raspberry-pi-sent-to-reboot-off-button.html

#!/usr/bin/env python
# coding=utf-8
# author:ksc
 
import RPi.GPIO as GPIO
import time
import os,sys
import signal
 
GPIO.setmode(GPIO.BCM)
 
#define GPIO pin
pin_btn=7
 
GPIO.setup(pin_btn, GPIO.IN, pull_up_down=GPIO.PUD_UP)
 
press_time=0
count_down=10
 
def cleanup():
    '''釋放資源,不然下次執行是可能會收到警告
    '''
    print('clean up')
    GPIO.cleanup()
 
def handleSIGTERM(signum, frame):
    #cleanup()
    sys.exit()#raise an exception of type SystemExit
 
def onPress(channel):
    global press_time,count_down
    print('pressed')
    press_time+=1
    if press_time >3:
        press_time=1
    if press_time==1:
        print('system will restart in %s'%(count_down))
    elif press_time==2:
        print('system will halt in %s'%(count_down))
    elif press_time==3:
        print 'cancel '
        count_down=10
 
GPIO.add_event_detect(pin_btn, GPIO.FALLING, callback= onPress,bouncetime=500)
 
#signal.signal(signal.SIGTERM, handleSIGTERM)
try:
    while True:
        if press_time==1:
            if count_down==0:
                print "start restart"
                os.system("shutdown -r -t 5 now")
                sys.exit()
        if press_time==2 and count_down==0:
            print "start shutdown"
            os.system("halt")
            sys.exit()
 
        if press_time==1 or press_time==2:
            count_down-=1
            print "%s second"%(count_down)
        time.sleep(1)
except KeyboardInterrupt:
    print('User press Ctrl+c ,exit;')
finally:
    cleanup()


然後執行這個python指令碼,
#建立程式,把程式碼貼上進去儲存 [email protected]:~ # nano reboot.py #修改可執行 [email protected]:~ # chmod 775 reboot.py #測試下 [email protected]:~ # ./reboot.py

然後設定為開機自動執行:

編輯這個檔案

[email protected]:/etc# nano rc.local

在exit 0上一行輸入:

python /home/pi/reboot.py

儲存退出。


新建啟動指令碼為/etc/init.d/buttonboot檔案

#!/bin/bash
# /etc/init.d/buttonboot

### BEGIN INIT INFO
# Provides: embbnux
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ledblink initscript
# Description: This service is used to manage a led
### END INIT INFO

case "$1" in
    start)
        echo "Starting button boot"
        /home/pi/reboot.py &
        ;;
    stop)
        echo "Stopping button boot"
        #killall reboot.py
        kill $(ps aux | grep -m 1 'python /home/pi/reboot.py' | awk '{ print $2 }')
        ;;
    *)
        echo "Usage: service button boot start|stop"
        exit 1
        ;;
esac
exit 0

設定python指令碼開機啟動

chmod +x buttonboot

最後設定開機啟動就好了

update-rc.d buttonboot defaults

系統啟動後,按兩次按鈕,等大約2秒,就可以安全關機啦。


以後隨時可用service 命令來啟動或者停止:

sudo service buttonboot start#啟動

sudo service buttonboot stop#停止


重啟測試即可。