raspberry pi

How to set your Raspberry Pi Screen Resolution

Previously my monitor could not support HD display and it looks awful. So I decided to turn on the safe mode for HDMI. It’s a headache because the font size is big and everything on the page is big. Recently I was using the monitor in the lab and I finally thought of changing the setting. So here’s what I did.

1. Get the list of what’s supported by your monitor:

tvservice -d edid
edidparser edid

2. There are a few modes in the resulting list. Choose one that you want. (For me, i chose DMT (35) 1280x1024p)

3. Edit the config file:

sudo nano /boot/config.txt

Comment out safemode.
#hdmi_safe=1

Find the section about HDMI, uncomment it and set the right group and mode from step 2. If your mode description contains “DMT”, the group should be 2, and if it contains “CEA”, it should be 1, so for me that was:


# Set monitor mode to DMT
hdmi_group=2
# Set monitor resolution to 1280x1024p 60Hz
hdmi_mode=35

Exit the editor with CTRL+X, followed by Y.

4. Reboot:

sudo shutdown -r now

Tadaa!

Raspberry Pi desktop screenshot

Raspberry Pi desktop screenshot


2014-03-20-121606_1280x1024_scrot

Changing Password for phpmyadmin on Raspberry Pi

I happen to forget my password to phpmyadmin because it was months ago since i installed it with my Apache2 web server. I did a quick search on the net and found a forum post discussing about recovering password for phpmyadmin on XAMPP. I haven’t try this on Raspberry Pi because I managed to recover my root password. (username is root!) However this may be useful for future reference:

You may want to edit this file: “\xampp\phpMyAdmin\config.inc.php” for XAMPP on desktop or “/etc/phpmyadmin/confid.inc.php”

change this line (for XAMPP):

$cfg[‘Servers’][$i][‘password’] = ‘WhateverPassword’;

to whatever your password is. If you don’t remember your password, then run this command in the Shell:

mysqladmin.exe -u root password WhateverPassword

where ‘WhateverPassword’ is your new password.

However I couldn’t find the line for Raspberry Pi. Instead, this may be helpful:
/* Uncomment the following to enable logging in to passwordless accounts, after taking note of the associated security risks. */
// $cfg['Servers'][$i]['AllowNoPassword'] = TRUE;

How to do Raspberry Pi Backup

It is really important to do back up to your SD card because anymore addition or configuration will cause your previous configuration state to disappear and you have to redo everything!

I am in the state where I am partly successful with my experiment but unhappy about the framework used. So it’s time to do a back up and modify the files in the card for my new experiment.

I thought I have written a post regarding this but it seems like I have not. So, just for my future reference, here are the steps to do the back up. It’s pretty simple.

  1. If you are using Window, download Win32 Disc Imager (win32diskimager-v0.9-binary) here.
  2. Unzip the file and open the “Win32DiskImager” application.
  3. To write a back up file to your laptop/ PC, select the location where you want the backup file to be by clicking the “open file” icon. WARNING: it is going to be the size of your SD card, e.g 8Gb for my case.
  4. Type in a name for your backup file. Check that everything is correct.
  5. Click Read.

It takes a while to complete. Once it is done, it will prompt you and “Done” will be written at the bottom left.

 

Capture

To write a backup file to your SD card, do the same thing. Select the back up file and right device, click Write. This will overwrite the SD card with the backup image.

Raspberry Pi with Comfort

Today I went back to my Industrial Attachment Company to continue working on the Raspberry Pi web server. Previously I was using the serial port and now I have successfully convert the program to use socket with Ethernet port. Now it can communicate with Comfort Home Automation system!

My boss is very kind to help me set up a port in the company router so that I can access the web app from anywhere. Yay, tomorrow I can demo it to my Prof. 🙂

It’s so tiring today. I didn’t do much tonight, basically just wasted my whole night away.

Good night world.

Raspberry Pi Quick Tips: Copy and Paste

When following some tutorials to test something on Raspberry Pi, there are some codes available online and they are a whole bunch of characters to type! There is a risk that you might type wrongly! So how to copy and paste those codes into Raspberry Pi terminal?

Here’s how I do it. I usually browse those tutorials using my laptop so I can just CTRL+C to copy those codes.

Then I start PuTTY to start SSH with Raspberry Pi. Unfortunately I can’t CTRL+V into the terminal. The right way to do it is to right click on the terminal. The codes are pasted right away. 😉

Also, notice that CTRL+C in the terminal will kill a process but if you select some texts and press CTRL+C, the texts will get copied and the process will get killed as well.

Some people say Shift+CTRL+C/V works but not for my case. 😦

Quick tips to kill an application on Raspberry Pi

When you are running and testing a web server (e.g cherrypy) on Raspberry Pi, and there is an error in your codes. You did not shutdown the server nor kill the application properly. You fixed the error and reload it. Tadaa! You get an error saying that the port is not freed and you do not know what to do! Solutions on the internet say “find the app Process ID (PID)”… but how exactly should you find it out of no where??

Or you are testing your new raspberry Pi camera. Opps it hangs and it is on forever. You cannot turn it off, you cannot use it for another test. How to kill it??

Try this:

pgrep the-app-name
E.g. pgrep python

This will return you the PID number (4 digits) of that app (e.g 4908)
Then type:
kill 4908

Raspberry Pi is now good to go for another test. 😉

Yes it works!

I had stop doing the integration of Raspberry Pi with Comfort system since I completed my Industrial Attachment last June. It is until recently that my FYP requires me to demonstrate the extendability of Raspberry Pi to other home automation system that I come back to the office and retouch the project I left over.

I used the UART of Raspberry Pi to perform serial communication with Comfort system. My boss had been telling me that it would be better if we could use the Ethernet connection instead. I wasn’t very clear of how it should work because the boards and the serial connection have been haunting me for months. I did not even know what keywords to search for in Google.

Yesterday, when I came back to the office again, greet by the friendly smile of my ex-colleagues, sat on the same chair, facing the same laptop and oh hello RaspberryPiServer we meet again. 😀

I had a fresher mind after the serial connection failed me and I find it tedious to borrow everything out from the office. I think it would be better if I can remotely access it and demonstrate that to my Profs. So I did a quick search on how to send netcat command in Python and these are some of the results that I found. Today I got a UCM Ethernet module and tested the connection using Comfigurator – works fine! Then using SSH in the terminal, i connect RPi to the UCM using netcat.

nc 10.0.0.70 1001 //nc followed by the IP address and port number

It is able to connect to UCM so I tried to log in by typing CTRL+V+C LI1234 CTRL+V+M and it returns LU01 which states log in success as user 1.

Next, I tried the following codes which I found here.

import socket
import time

def netcat(hostname, port, content):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, port))
s.sendall(content)
time.sleep(0.5)
s.shutdown(socket.SHUT_WR)

while 1:
data = s.recv(1024)
if data == "":
break
print "Received:", repr(data)
print "Connection closed."
s.close()

netcat ('10.0.0.70', 1001, "\x03LI%s\x0D"%passcode)

UCM replies LU01 - success!

UCM replies LU01 – success!

It is able to turn on the test light as well but when I tried to use the browser button to send command, it no longer work. :/ This is what i get:

[09/Jan/2014:14:26:53] HTTP Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cpdispatch.py", line 34, in __call__
return self.callable(*self.args, **self.kwargs)
File "eth_test2.py", line 243, in start
netcat ('10.0.0.70', 1001, "\x03O!0100\x0D")
File "eth_test2.py", line 227, in netcat
s.connect((hostname, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 111] Connection refused

[09/Jan/2014:14:26:53] HTTP
Request Headers:
Content-Length: 13
PRAGMA: no-cache
REFERER: http://10.0.0.132:8080/
HOST: 10.0.0.132:8080
CONNECTION: keep-alive
CACHE-CONTROL: no-cache
Remote-Addr: 10.0.0.190
ACCEPT: */*
USER-AGENT: Mozilla/5.0 (Windows NT 5.1; rv:26.0) Gecko/20100101 Firefox/26.0
X-REQUESTED-WITH: XMLHttpRequest
ACCEPT-LANGUAGE: en-US,en;q=0.5
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
ACCEPT-ENCODING: gzip, deflate

Update: eth_test4.py is now able to control the output test lights using the browser’s button. 😀 – i separated the start and request function to have 2 separate netcat functions in them.

TCP packets in Python?

Ethernet connection + python + data transmission?

Here are some reference links that might help in solving my problems with sending ASCII commands through the Ethernet port using Python script in Raspberry Pi.

  1. Netcat implementation in Python (stackoverflow)
  2. Netcat clone in Python
  3. Scapy and its tutorial
  4. Calling netcat in python (stackoverflow)
  5. Python equivalent of netcat (stackoverflow)
  6. Socket server

SD Card Format Successfully

Out of many suggestions found over the web and by fellow Raspberry-Enthusiasts in the Official Forum here, I finally found a solution to my SD Card Write-protected problem as mentioned here.

I intended to use my camera to format the card but I didn’t try it. Also, I didn’t have an external card reader. Thankfully, my friend, Alex, lent me his external SD card right after i posted that on Facebook. 😡 So kind!

sd card plugged into sd card reader sd card plugged into sd card reader

Finally, on this blue Monday, I plugged in the SD card into the reader and plugged the reader into my laptop. I run SDFormatter, configure quick settings and click “Format”. There were no “write protected” words appear anymore. YESH! So the process went well and I transferred the extracted NOOBS files into the SD card.

 

Now lets wait for me to get a HDMI cable. 😉

Btw, I met up with my pretty professor on Friday and we discuss further on the ideas. 🙂

My direction becomes clearer:

– automated pill dispenser & reminder system

– can help to reduce the burden of caregivers / nurses

– panel installed in a ward to check patient’s profile and dispense the medicine automatically.