How To Use SocketCAN With CLI

The native can interface usually named as can0,can1 etc

Identifying CAN interface

ip link show

if you can see can0 then, issue below command to get more details

ip addr ls dev can0

you can also use ifconfig command

ifconfig can0

or

ifconfig -a

Configuring And Enabling The SocketCAN Interface

sudo ip link set can0 type can bitrate 500000

This configures can0 for 500KB baud rate
Bring up the interface

sudo ip link set up can0

Send/Receive Data On SocketCAN

If you want to send/receive data on the CAN interface, you need can-utils package installed in your system

sudo apt install can-utils

To send data to the CAN bus, use the cansend utility:

cansend can0 123#1122334455667788

here ID is 0x123 and the data bytes are 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88.
To see received messages on can0 interface

candump can0

Happy Hacking 🙂

Advertisements

module “QtQuick.Controls” is not installed

This error comes on runtime of a QML app, I got this error on my Yocto build and, /usr/lib/qt5/qml/QtQuick/ does not contain a directory Controls.

To fix this error

Add these to your conf file. Edit the conf file

build/conf/local.conf

then add this to your conf file

IMAGE_INSTALL_append = " qtdeclarative-qmlplugins qtquickcontrols-qmlplugins"

In some cases this, wont bring change check whether /usr/lib/qt5/qml/QtQuick/ contain a directory named Controls else the change is not affected. Then make these chnages to your conf file

PACKAGECONFIG_append_pn-qtbase = " accessibility"
PACKAGECONFIG_append_pn-qtquickcontrols = " accessibility"

IMAGE_INSTALL_append = " qtdeclarative-qmlplugins qtquickcontrols-qmlplugins"

and rebuild Yocto.

Happy Hacking 🙂

Weston Wayland Tips and Tricks

Here are some Weston Wayland Configuration tricks

To find Video Adapters Identified by Weston

$ ls /sys/class/drm
card0
card0-VGA-1
card1
card1-DVI-I-1
card1-HDMI-A-1
card1-VGA-2

To find supported modes

$ cat /sys/class/drm/card0-LVDS-1/modes 
1366x768
1366x768

Set a resolution

[output]
name=LVDS1
mode=1366x768

To set a custom resolution or with modeline

First issue this command on any system to get modeline of your custom resolution, Here i am using 1920×768@60Hz, you can get modelines for your preffered resolutions using the cvt utility

$ cvt 1920 768 60
# 1920x768 59.86 Hz (CVT) hsync: 47.77 kHz; pclk: 120.00 MHz
Modeline "1920x768_60.00"  120.00  1920 2024 2216 2512  768 771 781 798 -hsync +vsync

Then in weston.ini, the following sets the mode with a modeline,

[output]
name=VGA1
mode=120.00  1920 2024 2216 2512  768 771 781 798 -hsync +vsync

To turn off a Video adapter

[output]
name=VGA1
mode=off

To remove top panel of weston desktop

[shell]
panel-location=""

Disabling Linux serial console on Embedded Development Boards

In different boards the systemctl behaved in different manner. For most of the boards to disable linux serial debug console and use it for user purpose use this command

systemctl disable serial-getty@ttyS0.service

systemctl disable getty@ttyS0

In some boards this method didn’t workout an alternate way was to use this command

systemctl mask serial-getty@ttyAMA0.service

To get non root access to serial port add it to dialout group, some systems don’t add debug console to dialout group so edit /etc/inittab and change the permissions.

Happy Hacking 🙂

Raspberry Pi SPI Loopback Testing

This post explains how to do SPI loopback testing in RaspberryPi.
This is the pinout of RaspbeyyPi GPIO header.

Next short the MOSI and MISO pins (GPIO10 and GPIO09)

Now download SPI test code from below link

https://raw.githubusercontent.com/raspberrypi/linux/rpi-3.10.y/Documentation/spi/spidev_test.c

Compile it

gcc -o spidev_test spidev_test.c

Run the code using spi dev

./spidev_test -D /dev/spidev0.0

If you are getting the hex characters as shown in screenshot, the SPI loopback is working.

Enabling SPI on Raspberry Pi

The Serial Peripheral Interface bus (SPI) is a synchronous serial communication interface specification used for short distance communication, primarily in embedded systems. The interface was developed by Motorola.

SPI devices communicate in full duplex mode using a master-slave architecture with a single master. The master device originates the frame for reading and writing. Multiple slave devices are supported through selection with individual slave select (SS) lines.

Read more details on Wikipedia

The SPI bus specifies five logic signals:

SCLK: Serial Clock (output from master).
MOSI: Master Out Slave In (data output from master).
MISO: Master In Slave Out (data output from slave).
SDIO: Serial Data I/O (bidirectional I/O)
SS: Slave Select (often active low, output from master).

I am using RaspberryPi Model B. First i turned on the Pi, i used NOOBS Raspbian operating system (https://www.raspberrypi.org/downloads/noobs/). I don’t have a HDMI display, so i connected it to network found out the ip of the Pi and did ssh using the following command

ssh pi@ip-address

The default password for ssh is “raspberry” if you are using NOOBS debian distro.

The SPI is not enabled by default. To enable SPI issue the following command

sudo raspi-config

Then Select Interfacing Options

Select SPI

It will ask for Enable or Disable, Enable SPI

Finish the config and reboot

After reboot you can see two spidev’s by issuing the command

ls /dev/spi*

This mean SPI is enabled on your Raspberry Pi

Increase USBFS memory limit in Ubuntu

When using USB3 camera on Linux you may face this USB memory limit issue.
By default, Linux limits image capture to 2 MB. To capture images over 2 MB, extend the USBFS limit on how many buffers can be locked into the driver.

sudo sh -c 'echo 1000 > /sys/module/usbcore/parameters/usbfs_memory_mb'

To confirm that you have successfully updated the memory limit, run the following command:

cat /sys/module/usbcore/parameters/usbfs_memory_mb

To set the maximum usbfs memory limit permanently:
Open the /etc/default/grub file in any text editor. Find and replace:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

with this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash usbcore.usbfs_memory_mb=1000"

Update grub with these settings:

$ sudo update-grub

You need to reboot the system after updating grub.