Submitted by The Fan Club on
Setting up a USB 3G/4G modem on a Raspberry Pi is not a simple task. There are many guides available using the now defunct sakis3g script, but getting my modem to work required a bit more understanding.
The main problem is that most USB modems act as two devices - a USB storage device and a USB modem. When plugged in to the Raspberry PI the device is usually in USB storage mode. There is a program called usb_modeswitch that we can use to do the switching
The other missing part is a way to connect to the cellular network with the USB modem from the Raspberry. For this we will use the classic ppp and wvdial programs.
Requirements
- Raspberry PI computer
- Raspbian OS installed
- USB 3G Modem
- 5V 1A power supply for the Raspberry PI
1. Install required software
- Connect your Raspberry PI to the internet via LAN or Wifi
- Open a terminal window and enter:
sudo apt-get update
sudo apt-get install ppp usb-modeswitch wvdial
2. Get the USB switching codes
- We need to get the codes of the USB device in USB storage mode and USB modem mode.
- Connect your USB modem and reboot the Raspberry PI without LAN or Wifi connection
- Once rebooted open a terminal window and enter:
lsusb
- The output will look similar to the screenshot below. Your modem should be listed as one of the USB devices. Note the numbers underlined. These are the device vendor and product codes.
- Make a note of these numbers. In this case it is 19d2:2000
- This value will later be used in the DefaultProduct value
- Then we need to soft reboot the Rapberry PI with the modem connected.
- Open a terminal window and enter:
sudo reboot
- Once rebooted open a terminal window and enter:
lsusb
- The output will look similar to the screenshot below. Your modem should be listed and if you are lucky the second set of numbers would have changed. This is usb_modeswitch doing it's job and switching the device to USB modem mode.
- Make a note of the new numbers. In this case it is 19d2:2002
- This value will be used later in the TargetProduct value
3. Create custom usb_modeswitch config file
- We need to create a custom config file for usb_modeswitch on the Raspberry PI because on a cold boot the device is not always active yet when usb_modeswitch runs on startup and the device is left in USB storage mode.
- We will extract some more information for our usb_modeswitch config file so that we can do the switching manually.
- Open a terminal window and enter the following replacing the codes 19d2 and 2000 with the codes you noted in step 2. Also note the added backslash.
cd /tmp
tar -xzvf /usr/share/usb_modeswitch/configPack.tar.gz 19d2\:2000
- Now open the extracted file with a text editor like leafpad replacing the codes noted in step 2.
leafpad 19d2:2000
- The content of the file should look something similar to the screenshot below.
- The parts we are interested in are shown in blue.
- Now open the /etc/usb_modeswitch.conf file and add the information obtained above to the file.
- Open a terminal window and enter:
sudo leafpad /etc/usb_modeswitch.conf
- Then add the following replacing the codes and MessageContent values with those of your device and save.
DefaultVendor=0x19d2
DefaultProduct=0x2000
TargetVendor=0x19d2
TargetProduct=0x2002
MessageContent="5553424312345678000000000000061e000000000000000000000000000000"
MessageContent2="5553424312345679000000000000061b000000020000000000000000000000"
MessageContent3="55534243123456702000000080000c85010101180101010101000000000000"
4. Create the wvdial config file
- The next step is to create a config file for wvdial so you can connect to your service provider.
- Open a terminal window and enter:
sudo leafpad /etc/wvdial.conf
- Replace the content of the file with the following.
[Dialer 3gconnect] Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0 Init3 = AT+CGDCONT=1,"IP","internet" Stupid Mode = 1 Modem Type = Analog Modem ISDN = 0 Phone = *99# Modem = /dev/gsmmodem Username = { } Password = { } Baud = 460800
- Replace internet with your service provider's APN
- Replace the Phone number if you need to dial a different code to connect.
- Replace Username and Password if needed. To leave the username and password as blank use { }
5. Connect to the internet
- To connect we need to make sure the device is in modem mode.
- Open a terminal and enter:
sudo usb_modeswitch -c /etc/usb_modeswitch.conf
- Then connect to the internet with:
wvdial 3gconnect
Comments
Hi. Is there any way to
Submitted by bogdan (not verified) on
If your service provider
Submitted by The Fan Club on
Hi, can this method be
Submitted by Khingcat (not verified) on
EVDO is just another 3G
Submitted by The Fan Club on
I'm planning to use Wifi or
Submitted by hendfu (not verified) on
Yes it is. Almost anything is
Submitted by The Fan Club on
E: Unable to locate package
Submitted by aliks bright (not verified) on
Corrected the instructions -
Submitted by The Fan Club on
Thanks for the tutorial - it
Submitted by Jono (not verified) on
The permissions on /usr/sbin
Submitted by The Fan Club on
unable to locate wvidal
Submitted by kyle (not verified) on
unable to locate wvidal
Submitted by The Fan Club on
Use to send sms instead?
Submitted by Andrew (not verified) on
SMS
Submitted by The Fan Club on
Re SMS
Submitted by Andrew (not verified) on
SMS
Submitted by The Fan Club on
Step #2
Submitted by Octopus (not verified) on
Step #2
Submitted by The Fan Club on
Huawei E303c supported on Raspberrry Pi?
Submitted by Jonty (not verified) on
Sierra Wireless Modem
Submitted by Sashmo (not verified) on
Thank
Submitted by cesar (not verified) on