NanoPi gpio pins read

credit: wiringNP


 +-----+-----+----------+------+---+-NanoPI M1+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 |     |     |     3.3v |      |   |  1 || 2  |   |      | 5v       |     |     |
 |  12 |   8 |    SDA.0 |   IN | 0 |  3 || 4  |   |      | 5V       |     |     |
 |  11 |   9 |    SCL.0 |   IN | 0 |  5 || 6  |   |      | 0v       |     |     |
 | 203 |   7 |   GPIO.7 |   IN | 0 |  7 || 8  | 0 | IN   | TxD3     | 15  | 198 |
 |     |     |       0v |      |   |  9 || 10 | 0 | IN   | RxD3     | 16  | 199 |
 |   0 |   0 |     RxD2 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO.1   | 1   | 6   |
 |   2 |   2 |     TxD2 |   IN | 0 | 13 || 14 |   |      | 0v       |     |     |
 |   3 |   3 |     CTS2 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO.4   | 4   | 200 |
 |     |     |     3.3v |      |   | 17 || 18 | 0 | IN   | GPIO.5   | 5   | 201 |
 |  64 |  12 |     MOSI |   IN | 0 | 19 || 20 |   |      | 0v       |     |     |
 |  65 |  13 |     MISO |   IN | 0 | 21 || 22 | 0 | IN   | RTS2     | 6   | 1   |
 |  66 |  14 |     SCLK |   IN | 0 | 23 || 24 | 0 | IN   | CE0      | 10  | 67  |
 |     |     |       0v |      |   | 25 || 26 | 0 | IN   | GPIO.11  | 11  | 17  |
 |  19 |  30 |    SDA.1 |   IN | 0 | 27 || 28 | 0 | IN   | SCL.1    | 31  | 18  |
 |  20 |  21 |  GPIO.21 |   IN | 0 | 29 || 30 |   |      | 0v       |     |     |
 |  21 |  22 |  GPIO.22 |   IN | 0 | 31 || 32 | 0 | IN   | RTS1     | 26  | 7   |
 |   8 |  23 |  GPIO.23 |   IN | 1 | 33 || 34 |   |      | 0v       |     |     |
 |  16 |  24 |  GPIO.24 |   IN | 1 | 35 || 36 | 1 | IN   | CTS1     | 27  | 13  |
 |   9 |  25 |  GPIO.25 |   IN | 0 | 37 || 38 | 1 | IN   | TxD1     | 28  | 15  |
 |     |     |       0v |      |   | 39 || 40 | 1 | IN   | RxD1     | 29  | 14  |
 +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
 | BCM | wPi |   Name   | Mode | V | Physical | V | Mode | Name     | wPi | BCM |
 +-----+-----+----------+------+---+-NanoPI M1+---+------+----------+-----+-----+

 +-----+----NanoPI M1 Debug UART---+----+
 | BCM | wPi |   Name   | Mode | V | Ph |
 +-----+-----+----------+------+---+----+
 |     |     |       0v |      |   | 41 |
 |     |     |       5v |      |   | 42 |
 |   4 |  32 |   GPIO.4 |   IN | 1 | 43 |
 |   5 |  33 |   GPIO.5 |   IN | 1 | 44 |
 +-----+-----+----------+------+---+----+


example usage:

First download and compile wiringnp

make

gpio readall

gpio mode 21 out

gpio mode 22 out

gpio write 21 1

qtwebkit not installed problem

Many a time for setting your application on fresh ubuntu machine you will be frustrated with the qt unfulfilled dependencies. Once I got this with qtwebkit and I installed all possible plugins like:

 apt-get install libqt5multimedia5 libqt5webkit5-dev qtmultimedia5-dev libqtmultimediakit1 libqt5webkit5-qmlwebkitplugin libqt5declarative5 libqtwebkit-dev

Isn’t above all which can be needed for qtwebkit but now still the application gives the same error.

Finally below fixed the issue and it seemed like I never needed all above
apt-get install qtquick1-qml-plugins

I already have the core stuff

apt-get install qt5-default libqt5declarative5
 apt-get install libqt5x11extras5

 

My experience with Ubuntu core with Just X11

In ubuntu core which is very thin ubuntu you can run UI application using linuxfb which is via raw framebuffer. It will be very slow. If your screen/UI is not updated frequently and just one screen is shown most of the time. You can do away with this.

./<yourFirstApplication> -platform linuxfb
or
./<yourSecondApplication> -platform linuxfb

Above works for my Qt application. But If you want good UI support you will need X11. You don’t need to reinvent the wheel by writing your own acceleration on top of linuxfb.

apt-get install xorg

With startx you can’t run applications on same display so :0 :1 is needed for each application

You use same terminal but different display application will run but display will be screwed whatever is changing the display that will be shown

Only part of the screen which is changed is updated weird

So run applications on different terminal and different display and then manage which terminal to show at any time.

Like

startx ./yourFirstApplication — :0 vt7 &

startx ./yourSecondApplication — :1 vt8 &

startx ./yourThirdApplication — :2 vt9 &

 

Now whenever needed switch with ctl + alt + F1 for FirstApplication F2 for SecondApplication F3 for thirdApplication make sure to press two times for switch

Not working as expected : Still whatever is changing it is going there .. so expectation is eyeris-main and menu both will not be changing at the same time somehow we need to refresh the whole screen..

This is of-course not what you want. You can’t ask user to press the keys to switch between application. You want to automatically control this from your application. What to show at what time.

For me the applications were written in Qt so Qt already uses X11 to create and arrange window. I just need to make it run in single display with single instance of startx.

The solution is simple. Start one main application with startx and then run all application from that application. You can also use a lightweight program called xdotool to control which window to bring in front.

xdotool windowraise `xdotool search –class <application-name>`

 

Or you can go other way around by using some light weight desktop/window manager

 

apt-get install xdm

from xdm you can run without startx. This is all taken care of. You will also get a simple login screen with xdm.

apt-get install lightdm lightdm-gtk-greeter

There are other options also like

apt-get install nodm

or
apt-get install ubuntu-session

or

apt-get install xfce4 xfwm4 xfce4-panel xfce4-settings xfce4-session xfce4-terminal xfdesktop4 xfce4-taskmanager tango-icon-theme

A Puzzle in probability theory

Calculating probability for a never ending situation which is recurring.

Problem: A coin tossing game between two friends (of course Alice & Bob may be Eve is also there watching them play).

Find probability of Alice winning if both Alice and Bob has two weighted coins which has a and b

probability of coming heads.

Assume Alice plays first and whoever gets Head first wins.

Solution:

P(A) = Probability of Alice winning the game = Probability of Alice coin to show head on first throw + (Probability of Alice count to show Tail on first throw)(Probability of Bob coin to show tail)*Probability of Alice count to come head + .. …


H + TT H + TT TT H

P(A) = a + (1-a)(1-b) P(A)

=> P(A) = a / (a(1-b) + b)

Running application just with X11

I have ubuntu core on my system without any UI just the bare bone minimum ubuntu core. I want the system to run some qt application nothing else.

There was two ways to it either I can take the Ubuntu mate and remove useless stuff and make my process run at startup with auto-login or to use bare bone ubuntu core and then just add the things needed to run my application.

Actually I would not have needed anything else for qt application and just used –platform linuxfb flag to run the Qt app with gun on the frame buffer. I actually did that but the problem was frame buffer approach was too slow I can actually see the screen restoring from top to bottom and for my application there was some times where screen was updated quite frequently. So I needed some other windowing system library like Wayland or X11 to handle the slow Frame buffer approach.

I chose X11 first and with some hiccups I made it work woohoo!!

You just need to install xorg and then use startx. I have put this in startup script inside /etc/init.d I will cover application starting at boot up in some other post.

apt-get install  libqt5declarative5  
# for my qt application this will install qt5-default and other qt related dependencies

It was quite a great learning and good experience to make everything work. Now the ubuntu core boots with my splash and starts all three of my qt apps with Gui and works well. It is very fast and no extra processes consuming my processor or hogging the system’s RAM. No window manager no session manager no desktop manager.

You can start any application simply by

startx application_name
[\code]

Boot log of nano pi

Alternative of slack:
Mattermost

Today I met a friend of mine and he showed me this software hosted on his companies server. This is a great alternative for paid slack. We are using unpaid version of slack and some restriction like search limit no search functionality in archived history chat. Limitation on files shared are annoying. I don’t mean to say that I want all this free it is just that for us (trying not to pay for this) mattermost will be more suitable option.

Github on your own server

How to give permissions to devices

Many a time you face with this challenge that as a user you do not have permission to read write a device file in Linux without becoming sudoer.

Example: Let us say you have a USB device say a camera or any other device file let us say /dev/uinput the file for multi touch.
You want to read write these files in your program.

You can only run this program with sudo as the device files will not be accessible otherwise.

There is a workaround to make these files read/writable once and for all by doing something like:

sudo chmod 777 /dev/uinput

But You need to do above on each restart and also not a great way to handle this problem.

There is an easy way by creating rules file inside /etc/udev/rules.d.
For example:


# DVP sensor driver rule

KERNEL=="video0", SUBSYSTEM=="video4linux", ATTRS{name}=="vfe_0", GROUP="video", MODE:="766"

Markdown Cheatsheet (.md)

This is mostly for my note and remembering. Markdown is very common now, and the simple formatting language trick  is very common in other formatting also at least partially. Some sample use cases: GitHub readme, Wikipedia ..

<h3>Giving links:</h3>

Say you have a file which you want to refer with link [linkname](file.txt) will link to file.txt in current directory with link name “linkname” for file inside folder use [linkname](folder name/file.txt)

<h3>Attaching an image </h3>

![alt text](image.jpg “image title”)

For image “!” mark is very important otherwise it will just link the file and image will not show.

 

<h4>Heading</h4>

Use “#” for heading Big heading

## for smaller heading and so on

 

In both above cases you can link to outside world also and in directories also.

 

Github link for the sample example link(GitHub)