Friday, February 27, 2015

Waveshare SpotPear 3.2 inch TFT touchscreen for Raspberry Pi

A word of caution: setting up Waveshare touchscreen for Pi is not very straightforward. I spent a long on it. Get a better touchscreen if you can. 

Waveshare touchscreen may be shipped with a CD with a special factory image. With the factory image, all you need is to boot up with a microSD with the image. However, due to some issues that I could not fix, the factory image does not support EW-7811Un WiFi dongle. I tried for quite a while, such as rebuilding the kernel as some websites suggest, but I could not make it work.
Then I had to try to configure the touchscreen based on common Raspbian (Debian Wheezy, 2015-02-16). I followed the steps by Notro to install FBTFT drivers as loadable modules:

1. Modify /usr/share/X11/xorg.conf.d/99-fbturbo.conf: change fb0 (HDMI output) to fb1 (SPI output), so that the line will look like:

 Option          "fbdev" "/dev/fb1"

2. Make changes in /boot/config.txt so that it has the following:

# uncomment to force a console size. By default it will be display's size minus
# overscan.
framebuffer_width=800
framebuffer_height=600

dtparam=spi=on

3. Enable SPI using raspi-config.

4. Install Notro's kernel module:
sudo REPO_URI=https://github.com/notro/rpi-firmware rpi-update
Reboot.


5. To load the kernel module automatically at boot time, I modified /etc/modules and the following is what it is now: 

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.

snd-bcm2835
i2c-bcm2708
i2c-dev
fbtft_device name=waveshare32b debug=3 rotate=90 width=320 height=240
ads7846_device model=7846 cs=1 gpio_pendown=17  keep_vref_on=1 swap_xy=1 pressure_max=255 x_plate_ohms=60 x_min=200 x_max=3900 y_min=200 y_max=3900

w1-gpio
w1-therm

Alternatively, the module can be loaded if you type:
sudo modprobe fbtft_device name=waveshare32b
This seems not loading the touch, but the display should work fine now.
I did not change /boot/cmdline.txt.

6. To test:
Typing dmesg | grep tft should show that SPI devices registered.

   6-1: Add in /etc/rc.local before exit 0 if you wish to start GUI automatically on the touchscreen upon startup:
     su -l pi -c startx  
   6-2: Type the following to start xwindows:
          FRAMEBUFFER=/dev/fb1 startx
   6-3: Type the following to start the console on the touchscreen:
con2fbmap 1 1



See also the following websites for excellent tutorials:

Wednesday, December 17, 2014

Raspberry pi running SSH, lxsession, and Motion


This screenshot shows RPi with SSH enabled, and connected via a Ubuntu laptop in a headless way. The RPi is running Motion with an old wedcam.

To connect to RPi using the laptop, do
sudo ssh -X pi@192...
And then use lxsession to open x window.

The screenshot shows the Pi window is merged with the Ubuntu window. The left bar is for Ubuntu. The bottom bar lists all the programs running in both Pi and Ubuntu. The bottom right shows the Pi's CPU usage, time, etc.

Note that Motion cannot be viewed in Chromium. I had to use Firefox to view it. The default port for it (unless the conf file is modified) is 8081. To start/stop/restart the service, do
sudo service motion start
sudo service motion stop
sudo service motion restart

Wednesday, October 22, 2014

Raspberry Pi B+ boot up and connect to laptop

Just received B+ and could not wait to power it up!

1. Put into the case

I also ordered a Vilros clear case for the B+ model from Amazon. I thought this should be a fairly easy process, but it turned out to take more than 25 min! I think the case is simply too tight, at least for the case and Pi I received. I tried various ways and realized that unless I pressed it really hard, it just would not fit. But I was afraid to break my Pi!

After trying some more time I was able to click the Pi into the case. What I did was to seat the HDMI side on the bottom case, and press really hard on the GPIO side, all the way down through the two slide-shaped bumps. Of course I could not press on the GPIO pins, so I had to press a little below the pins. It was uncomfortable, and excessive force had to be used. And I guess there is no way I can get the Pi out of the case in future unless I break the case.


2. Boot up

I ordered a micro SD card Kingston Digital 16 GB Class 4 microSDHC Flash Card with SD Adapter (SDC4/16GBET). I followed the procedure on this link to install the Raspbian Wheezy 2014-09-09 on the SD card using a Ubuntu laptop. After that, if I inserted the micro SD card into the laptop, it showed two devices, one "boot" with files such as bootcode.bin, cmdline.txt, *.elf, etc., and the other "3 GB Volume" which should be expandable using the Pi.

The micro SD card was then inserted to the Pi. Even if it "clicked", I could still pull it out. It seems there is nothing really locking it into the slot. But it does make good contact.

Then I connected the Pi to USB mouse, USB keyboard, Edimax nano-size USB WiFi adapter, and a DVI monitor using a HDMI-DVI cable. It booted up!

The setting up of WiFi was super easy in the desktop. I tested IDLE, Pi Store, Mathematica, Wolfram Language, web browser, installing vim, etc. It was very smooth.

I enabled ssh during the booting up. Then I could try the "headless" way, removing the connections of keyboard, mouse, and the monitor!

3. Connect to laptop

After enabling ssh on the Pi, I wrote down the IP address of the Pi, something like 192.168.0.???. I bundled the MAC and IP in the router so that I will always use the same IP address to access the Pi.

I removed the keyboard, mouse, and monitor from the Pi. In my Ubuntu laptop, I opened Xterm and typed:
sudo ssh -X pi@192.168.0.15
Then entered the password, and the connection was made. In the above, the "-X" is for allowing x windows.

To start the desktop, type
lxsession &

The Pi's window would then merge into the Ubuntu's desktop. All the software worked fine on the merged desktop, except that I found I could not get Scratch to open in this headless way.

To terminate the lxsession, type the following in the terminal running ssh:
lxsession-logout

Thursday, January 16, 2014

Ubuntu backup deja-dup

http://www.howtogeek.com/108869/how-to-back-up-ubuntu-the-easy-way-with-dj-dup/ 

Can recover the whole system, a selected file (right click Revert to Previous Version ...), and a deleted file (right click Restore Missing Files ...)

However some users complained about its unreliability
https://apps.ubuntu.com/cat/applications/deja-dup/

Sunday, January 12, 2014

Tools/procedures for generating high-quality PDF/EPS files with LaTex math

Without using pricey licensed softwares, you can generate high-quality PDF/EPS files with LaTex math expressions, as shown in the following. Other procedures may work as well, but the following have been tested and may save some time.

1. Drawing tools and procedures

To make your own figures with LaTex math, you may use LibreOffice Draw. To enable LaTex, in Tools --- Extension Manager..., add TexMaths (http://roland65.free.fr/texmaths).

You may also use Inkscape. For math expressions, use Extensions --- Render --- LaTex formula ...

Both LibreOffice Draw and Inkscape are free.

On the other hand, if you have MS Office, you may use Powerpoint to draw, with TexPoint ($30~$45) or IguanaTex (free) for math expressions.

After drawing, export or save as a PDF file and embed all fonts. Converting to other file formats may be not preserve all formats/information.


2. PDF tools and procedures

This PDF file should have all fonts embedded. To check, use:
pdffonts a.pdf

to make sure all fonts are embedded correctly.

To generate an EPS file with a bounding box or a PDF file with only the drawing area kept, do:
pdfcrop a.pdf b.pdf

This removes the white space around the drawing area in a.pdf and generates an output file b.pdf.

If EPS format is desirable, perform:
pdftops -eps b.pdf

This is generate b.eps with the bounding box.

If Adobe Acrobat Professional is available, you may also crop the pdf using it, and save as another PDF file or save as an EPS file.

3. Include the drawing file in LaTex document

The b.pdf file or b.eps file can be included in a LaTex document using e.g.:

\begin{figure}[h]
\begin{center}
\subfigure[]{\scalebox{.6}{\includegraphics{b1}}}
\subfigure[]{\scalebox{.6}{\includegraphics{b2}}}
\end{center}
\end{figure}


If no file extension is specified, PDFLaTex will look for b1.pdf, b2.pdf, etc., and LaTex will look for b1.eps, b2.eps, etc.


If LaTex --> dvi2ps --> ps2pdf procedure is to be followed, make sure the option
-Ppdf 
is used for dvips, and the options
-dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress 
are used for ps2pdf.

If PDFLaTex or the like is to be used used, set the following option:
updmap --setoption pdftexDownloadBase14 true 


The produced PDF file should have all fonts embedded and high-quality figures. You may use pdffonts to verify.


Wednesday, August 28, 2013

Immanuel Kant

Two things fill the mind with ever new and increasing admiration and awe, the more often and steadily reflection is occupied with them: the starry heaven above me and the moral law within me. Neither of them need I seek and merely suspect as if shrouded in obscurity or rapture beyond my own horizon; I see them before me and connect them immediately with my existence

All natural capacities of a creature are destined to evolve completely to their natural end.

Rules for Happiness: something to do, someone to love, something to hope for.

Have the courage to use your own reason- That is the motto of enlightenment.

Enlightenment is man’s emergence from his self-imposed immaturity. Immaturity is the inability to use one’s understanding without guidance from another. This immaturity is self-imposed when its cause lies not in lack of understanding, but in lack of resolve and courage to use it without guidance from another. Sapere Aude (Dare to think/know/be wise)!

Live your life as though your every act were to become a universal law.

We are not rich by what we possess but by what we can do without

All our knowledge begins with the senses, proceeds then to the understanding, and ends with reason. There is nothing higher than reason.

To Be is To Do.

Saturday, August 17, 2013

Friedrich Nietzsche quotes

Man's maturity: to have regained the seriousness that he had as a child at play.

That which does not kill us makes us stronger.

The individual has always had to struggle to keep from being overwhelmed by the tribe. If you try it, you will be lonely often, and sometimes frightened. But no price is too high to pay for the privilege of owning yourself.

He who has a why to live can bear almost any how.

All things are subject to interpretation whichever interpretation prevails at a given time is a function of power and not truth.

Without music, life would be a mistake.

To live is to suffer, to survive is to find some meaning in the suffering.

You have your way. I have my way. As for the right way, the correct way, and the only way, it does not exist.

And we should consider every day lost on which we have not danced at least once. And we should call every truth false which was not accompanied by at least one laugh.

All truly great thoughts are conceived by walking.