IOT-GATE-RPi: Raspbian

From Compulab Mediawiki
Revision as of 12:53, 21 April 2020 by imported>Igor.vaisbein (Controller–area network (CAN))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Overview

IOT-GATE-RPi comes with a Raspbian Linux image. Raspbian Linux is a free operating system based on Debian optimized for the Raspberry Pi hardware. It is the official supported operating system for Raspberry Pi. Raspbian Linux image includes more than 35,000 software packages. Among them:

  • Core system
  • Debian package management system
  • X11 Windowing System
  • LXDE desktop manager
  • SSH server and client
  • Python, Scratch, Sonic Pi, Java and Mathematica

Additional images can be used with IOT-GATE-RPi. All optional images can be found in Raspberry Pi downloads. The IOT-GATE-RPi: Raspbian: Manual Installation page provides a brief introduction on how to install the Rasbian image.

Using Raspbian Linux on IOT-GATE-RPi

Connection and Logging In

To login into the Linux system, use a keyboard and display or a serial console, connect through the network (ssh).

Use the following username and password to login:

raspberrypi login: pi
Password: raspberry

Networking

For most home networks, no further configuration is required in order to be able to connect to the Internet. For this to work, the router should be configured for DHCP (Dynamic Host Configuration Protocol).

To configure networking, edit /etc/network/interfaces and /etc/dhcpcd.conf. For more information about Debian Linux network configuration read:

The majority of network setup can be done via the interfaces configuration file at /etc/network/interfaces.

Admolition note.png auto line is required for interfaces that have to be brought up at boot time.
  • Using DHCP to automatically configure the interface
auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
  • Configuring the interface manually
auto eth0
    iface eth0 inet static
        address 192.168.1.170
        netmask 255.255.0.0
        gateway 192.0.0.1

RTC

Accessing and setting the RTC

To access the RTC time and date run:

root@cm-debian:~# hwclock
Sat Jan 1 00:00:00 2000 -10.011159 seconds

To set the date and write it into the RTC do the following:

root@cm-debian:~# date -s "31 JUL 2015 10:00:00"
Fri Jul 31 10:00:00 UTC 2015
root@cm-debian:~# hwclock -w
root@cm-debian:~# hwclock
Fri Jul 31 10:00:13 2015  -1.066224 seconds

Wifi

IOT-GATE-RPi features 802.11b/g/n wireless connectivity solution.

WiFi Initialization

  • WiFi requires no user interaction for being configured. The drivers get loaded automatically.

Make sure that the WiFi drivers are loaded:

root@cl-rootfs:~# lsmod
rt2800usb                 18824  0
rt800lib                  80070  1
rt2x00usb                 12798  1
rt2x00lib                 48694  3

The WiFi driver can be loaded manually using modprobe.

  • iwconfig command from wireless-tools package can be used to retrieve detailed information about the WiFi interfaces:
root@cl-rootfs:~# iwconfig wlan0
wlan0     IEEE 802.11abgn  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=0 dBm   
          Retry short limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:on
  • Activate the interface:
root@cl-rootfs:~# ifconfig wlan0 up
  • Sample WiFi scanning:
root@cl-rootfs:~# iwlist wlan0 scan

The output will show the list of Access Points and Ad-Hoc cells in range. For more information about connecting to wireless networks and tuning WiFi interfaces refer to wpa_supplicant and wireless-tools man pages.

wpa_supplicant

  • Configuration sample

Please open a wpa_supplicant configuration file bellow and put a network name and a password into the "ssid" and "psk" fields respectively.

root@cl-rootfs:~# cat /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant

network={
	ssid="wireless_network_name"
	key_mgmt=WPA-PSK
	psk="wireless_network_password"
}
  • Sample run
root@cl-rootfs:~# ifconfig wlan0 up
root@cl-rootfs:~# wpa_supplicant -B -Dwext -c /etc/wpa_supplicant.conf -i wlan0
root@cl-rootfs:~# dhclient wlan0

4G/3G Cellular Modem

IOT-GATE-RPi is equipped with an on-board micro-SIM card socket and support cellular communication using 4G/3G cellular modem with USB interface in mini-PCIe form-factor.

The following 3G cellular modules have been tested:

In order to use 4G/3G cellular modem the several software packages have to be installed.

Admolition note.png iot-gate-rpi_raspbian_2018-01-24.zip contains the package rpi3-modem which takes care of all needed package installations.

When using the image burned to the eMMC provided by us, there is no need to install additional packages because rpi3-modem is allready installed. In both cases continue to the Loading kernel modules section.

Installing Debian packages

root@cm-debian:~# apt-get install libpcap0.8 libuniconf4.6 libwvstreams4.6-base libwvstreams4.6-extras ppp wvdial

Loading kernel modules

Device driver modules require no user interaction and get loaded automatically. If for some reason device driver modules are not loaded automatically, please load them manually:

  • USB Driver for GSM modems and Qualcomm MSM Interface (QMI) WWAN driver are required for SIMcom modules:
root@cl-som-imx7-sid:~# modprobe option
root@cl-som-imx7-sid:~# modprobe qmi_wwan
  • USB Abstract Control Model driver is required for Telit HE910-D:
root@cl-som-imx7-sid:~# modprobe cdc-acm

Point-to-Point protocol (PPP) drivers must be loaded manually prior to dialing:

root@cl-som-imx7-sid:~# modprobe ppp_generic
root@cl-som-imx7-sid:~# modprobe ppp_async
root@cl-som-imx7-sid:~# modprobe ppp_synctty
root@cl-som-imx7-sid:~# modprobe bsd_comp
root@cl-som-imx7-sid:~# modprobe ppp_deflate

WvDial

WvDial is a Point-to-Point Protocol dialer that automatically detects modem, and can log into almost any Internet Service Provider without a complicated configuration. First, edit the wldial configuration file. Please use the a correct ISP APN instead of YOUR_ISP_APN stub:

root@cl-som-imx7-sid:~# cat /etc/wvdial.conf
[Dialer cellular]

# Your modem device. Usually /dev/ttyUSB0 or /dev/ttyACM0
#Modem = /dev/ttyACM0
Modem = /dev/ttyUSB3

# Port speeds that're worth testing:
# 921600
# 460800
# 115200
#  57600
Baud = 115200

# If your SIM card has a PIN, comment this line, uncomment the next one, and
# change the PIN shown to your PIN.
Init = ATZ
# Init = ATZ+CPIN="0000"

# If you know your ISP's APN, specify it instead of YOUR_ISP_APN below.
# If you don't, you may be able to find out on the 'net, or from tech
# support.
#
# There's also an APN table at https://wiki.ubuntu.com/NetworkManager/Hardware/3G .
#
# If you can't find it, you might be able to dial out without setting an APN
# (especially from a mobile phone). Just comment this line and uncomment
# the next one.
Init2 = AT+CGDCONT=1,"IP","YOUR_ISP_APN"
#Init2 = AT+CGDCONT=1,"IP"

# Most services/devices dial with *99# . A few seem to require *99***1#
Phone = *99#

# These often suffice, but your ISP might require different details. They're
# often dummy details used for all users on the ISP, frequently the ISP's
# name, but some ISP's do require you to use a real username and password.
Username = dummy
Password = dummy

The following command can be used for dialing:

root@cm-debian:~# wvdial cellular &

GPIO access

Linux provides simple and convenient GPIO access via sysfs interface. A GPIO should be exported using /sys/class/gpio/export. After the GPIO is exported it is possible to change its direction and value using /sys/class/gpio/gpioX/direction and /sys/class/gpio/gpioX/value attributes.

Example

The following example demonstrates how to configure GPIO 140 as output and set value to high:

root@cl-rootfs:~# echo 140 > /sys/class/gpio/export
root@cl-rootfs:~# echo out > /sys/class/gpio/gpio140/direction
root@cl-rootfs:~# echo 1 > /sys/class/gpio/gpio140/value
Admolition note.png The above example assumes that the pinmux configuration of the corresponding pin is set to GPIO mode and the GPIO 140 is not requested in the Linux kernel.

Controller–area network (CAN)

IOT-GATE-RPi fitted with FCSD HAT board features MCP2515 stand-alone Controller Area Network interface.

Loading CAN modules

If the MCP2515 driver and/or Raw CAN protocol compiled as module(s), they must be loaded prior to enabling CAN interface.

  • The MCP2515 driver gets loaded automatically. Make sure it is loaded:
root@cl-rootfs:~# lsmod | grep mcp
mcp251x                20480  0
can_dev                24576  1 mcp251x
The MCP2515 driver can be loaded manually:
root@cl-rootfs:~# modprobe mcp251x
  • Load Raw CAN protocol module:
root@cl-rootfs:~# modprobe can-raw
CAN interface configuration

It is recommended configure the CAN interface, with the iproute2 utilities.

  • To make sure the right ip utility is used, run:
root@cl-rootfs:~# ip -V
ip utility, iproute2-ss151103
  • Configure the CAN interface bit-rate to 125 Kbits/sec (values of up to 1Mbit/sec are supported):
root@cl-rootfs:~# ip link set can0 type can bitrate 125000
  • Enable the CAN interface:
root@cl-rootfs:~# ip link set can0 up
Software installation
  • Use the following command to install can-utils:
root@cl-rootfs:~# apt-get install --no-install-recommends can-utils
Send/Receive packets

Use cansend and candump utilities to send and receive packets via CAN interface.

  • Send standard CAN frame (on the first device):
root@cl-rootfs:~# cansend can0 111#1122334455667788
  • Send extended CAN frame (on the first device):
root@cl-rootfs:~# cansend can0 11111111#1122334455667788
  • CAN frames (extended mode) generator, random payload, interval between two successive flames 50 msec:
root@cl-rootfs:~# cangen -g 50 -e -D r -v can0
can: raw protocol (rev 20170425)
...
  can0  03FF0983#D7.61.FF.03.C1.F7.C1.34
  can0  19C34D32#F7.5A.C2.73.AD.0E.3F.0B
  can0  0675E391#2B.2D.D3.49
  can0  13091C55#99.32.EC.77.27.81.49.0B
  can0  098D67CF#22.50.AB.48.AD.7F.F4.26
  can0  05263FEC#1B.4C.02.45.6E
  can0  12B30E20#
  can0  1F193DF9#C5
  can0  1EB0B18F#3E.3F.DA.57.C2.FE.73.58
  can0  1E5C64D9#6F.0D.B3.63.6A
  can0  1E1DE3F9#96.48.AC.79.4E.00.27.71
  can0  0E1A11B7#75.81.70.7C.86.79.A7.77
  can0  05F8FD8B#33.F9.9B.1E.77.3D.1F
  can0  1E155FCD#E6.BA.F8.58.ED.6D.C8.10
  can0  1D91DF9E#5D.29.82.7B.97.1D.AB.5C
  can0  11FB3CDA#14.65.C3
  can0  091352C0#2C.ED
...
  • Dump all received data frames as well as error frames (on the second device):
root@cl-rootfs:~# candump any,0:0,#FFFFFFFF
  can0  111   [8]  11 22 33 44 55 66 77 88
  can0  11111111   [8]  11 22 33 44 55 66 77 88
...
  can0  03FF0983   [8]  D7 61 FF 03 C1 F7 C1 34
  can0  19C34D32   [8]  F7 5A C2 73 AD 0E 3F 0B
  can0  0675E391   [4]  2B 2D D3 49
  can0  13091C55   [8]  99 32 EC 77 27 81 49 0B
  can0  098D67CF   [8]  22 50 AB 48 AD 7F F4 26
  can0  05263FEC   [5]  1B 4C 02 45 6E
  can0  12B30E20   [0] 
  can0  1F193DF9   [1]  C5
  can0  1EB0B18F   [8]  3E 3F DA 57 C2 FE 73 58
  can0  1E5C64D9   [5]  6F 0D B3 63 6A
  can0  1E1DE3F9   [8]  96 48 AC 79 4E 00 27 71
  can0  0E1A11B7   [8]  75 81 70 7C 86 79 A7 77
  can0  05F8FD8B   [7]  33 F9 9B 1E 77 3D 1F
  can0  1E155FCD   [8]  E6 BA F8 58 ED 6D C8 10
  can0  1D91DF9E   [8]  5D 29 82 7B 97 1D AB 5C
  can0  11FB3CDA   [3]  14 65 C3
  can0  091352C0   [2]  2C ED
...

RS-485 (Modbus)

IOT-GATE-RPi can support RS-485 half-duplex serial communications using the EB-RPI-FCSD add-on board.

To use this interface on /dev/ttyAMA0, the login shell over serial must be disabled first:

  • Open a terminal and type: $ sudo raspi-config
  • Select option 5 "Interfacing options", select option P6 "Serial".
  • On "Would you like a login shell to be accessible over serial" select no.
  • On "Would you like the serial port hardware to be enabled" select yes.
  • Select exit and reboot IOT-GATE-RPi.

Libmodbus

  • To create a Modbus RTU context: modbus_new_rtu("/dev/ttyAMA0", 115200, 'N', 8, 1)
  • The Raspberry Pi fork of libmodbus does not support IOT-GATE-RPi because it was built for GPIO pin based switching instead of automatic rx-tx switching.

See also