Developing for Raspberry PI

New to Debian (Or Linux in general)? Ask your questions here!

Developing for Raspberry PI

Postby sumit4palz » 2012-01-12 08:22

Hello Friends,

To introduce myself :
I just entered the world of debian today and i am really excited to part of the community. I am completely a noob into a linux world, my entire programming experience is on windows and C#.

To give an overview here is what i want to achieve.

I am in a process of creating a device powered by Raspberry PI, it will be a LCD screen connected to Raspberry PI. My objective is to show custom text and graphics which are retrieved from web. Consider this as device which will display RSS feeds with graphics.

To be specific these are my questions:

1. Since the device will be only meant to run a specific program, do i need to boot full operating system to run my program? Is there a way to tell Debian to run only my program, instead of booting full OS?

2. Since i will be doing graphics, animation what is IDE/SDK pack you guys recommend? Currently i have Python Geany installed on my system.

I look forward for help in this regards.

Thanks,
Sumit
sumit4palz
 
Posts: 4
Joined: 2012-01-12 08:04

Re: Developing for Raspberry PI

Postby vbrummond » 2012-01-12 09:21

Hello and welcome to the community! 8)

1. Since the device will be only meant to run a specific program, do i need to boot full operating system to run my program? Is there a way to tell Debian to run only my program, instead of booting full OS?

Well considering the Debian base system (just the kernel and core utilities) uses around 8-20mb of ram I would think you need not do any special modifications. Debian is a very modular system where you are not forced to use a graphical environment. If that is what you mean anyway.

2. Since i will be doing graphics, animation what is IDE/SDK pack you guys recommend? Currently i have Python Geany installed on my system.

Not sure. I only program simple GUI applications using python and gtk+. I just use a normal text editor to code it.

Hope you find your answers.
Always on Debian Testing
vbrummond
 
Posts: 4468
Joined: 2010-03-02 01:42

Re: Developing for Raspberry PI

Postby saulgoode » 2012-01-12 10:06

sumit4palz wrote:1. Since the device will be only meant to run a specific program, do i need to boot full operating system to run my program?

Technically speaking, no.

sumit4palz wrote:Is there a way to tell Debian to run only my program, instead of booting full OS?

You can have the Linux kernel execute a single program (instead of 'init') by passing the name of the program to the kernel command line. For example, at the boot prompt the following would execute just the bash terminal after the kernel finishes setting up the filesystems:
Code: Select all
linux init=/bin/bash

Of course, this would be a very limited capability because it is the 'init' process which does the bulk of setting up your system (device drivers, networking, terminals, services/daemons). Your program would most likely need much of this added functionality and so at a minimum, you should look in your startup scripts for the appropriate place to "intercept" the normal boot process.

For a text-based startup (and my guess would be that the Pi device by default boots to text mode), 'sulogin' is typically the last thing the setup does before things are handed over to the user (who is supplied a login prompt on the terminal). If you have configured your startup to boot directly into graphical mode then control is typically handed over to one of the display managers (KDM, GDM, XDM, etc).

Since you are doing graphics, you will want to have the X Window System running. This means that you need to edit your startup scripts so that -- instead of 'sulogin' or the display manager running -- your program gets passed as a client to 'xinit', preferably not running as root. This startup command should look something like:
Code: Select all
/bin/su sumit4palz -c xinit /full/path/to/yourprogram

Control will be passed to your program, which should never exit (once your program terminates, X is shutdown and, depending on your /etc/inittab settings, then restarted). This all presumes that your program is the ONLY program you want to have running (or if any other program is to be executed, your program provides a way of doing so).
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan
User avatar
saulgoode
 
Posts: 1545
Joined: 2007-10-22 11:34

Re: Developing for Raspberry PI

Postby sumit4palz » 2012-01-12 10:18

Thanks for the answers guys.

@Saulgood : Excellent answer! You are right i only want to run only one program.

@vbrummond : I will give GTK+ a try. If you can recommend some good tutorials and existing sample codes for : Python, GTK+ and sample codes for Python and GTK+ than it will help.
sumit4palz
 
Posts: 4
Joined: 2012-01-12 08:04

Re: Developing for Raspberry PI

Postby vbrummond » 2012-01-12 11:37

Here is a link to pygtk web site. Here also is a simple web browser I wrote. (Save a browser.py file in your text editor). You also need python-webkit installed. You can run it with python /path/to/browser.py

http://pygtk.org/

Code: Select all
#!/usr/bin/env python

# Sam's Web Browser, a nice simple web browser that is most appropriately useless, like it's creator.
 
# Known bugs: Trying to open a new browser window is possible from the GUI, but does not work. You have to type "http://" before everything or it will not work. This is probably easy to fix but I am just lazy.

# Enjoy. Scores 100/100 on the Acid 3 test.

# Requires gtk and webkit.
import gtk
import webkit

# Create main window and it's properties.
window = gtk.Window()
window.set_title("Sam's Browser")
window.resize(720, 480)
window.connect("delete-event", gtk.main_quit)

# Create the widgets.
address = gtk.Entry()

progress = gtk.ProgressBar()
progress.set_text("Page is loading, please wait..")

go = gtk.Button("Go")

about_button = gtk.Button("About")

search = gtk.Button("Search")

browser = webkit.WebView()

scroll = gtk.ScrolledWindow()
scroll.add(browser)

# About Dialog
about_dialog = gtk.AboutDialog()
about_dialog.set_comments("Simplicity and elegance.")
about_dialog.set_program_name("Sam's Browser")
about_dialog.set_version("0.2")
about_dialog.set_license("GPL v2 or greater.")
about_dialog.set_website("http://www.debian.org/")
about_dialog.set_authors(["Samuel Orr"])
about_dialog.set_logo(None)

# Load a default page. This can be changed.
DEFAULT_URL = 'http://www.duckduckgo.com/'
url = DEFAULT_URL
browser.open(url)

# Define the horizontal widgets.
toolbar = gtk.HBox()
toolbar.pack_start(about_button, False)
toolbar.pack_start(address)
toolbar.pack_start(go, False)
toolbar.pack_start(search, False)

# Define the vertical widgets.
display = gtk.VBox()
display.pack_start(toolbar, False)
display.pack_start(scroll)
display.pack_start(progress, False)

# Function to define the load page button.
def goclicked(btn):
    browser.open(address.get_text())
go.connect("clicked", goclicked)

# Function to load a page on key press.
def loadpagekey(key):
    browser.open(address.get_text())
address.connect("activate", loadpagekey)

# Funtion to define the progress bar.
def load_progress_changed(webview, amount):
    progress.set_fraction(amount / 100.0)
browser.connect("load-progress-changed", load_progress_changed)

# Function to show the progress bar during page load.
def load_started(webview, frame):
    progress.set_visible(True)
browser.connect("load-started", load_started)

# Function to hide the progress bar when load is finished.
def load_finished(webview, frame):
    progress.set_visible(False)
    address.set_text(frame.get_uri())
browser.connect("load_finished", load_finished)

# Function to define the about button.
def about_button_clicked(btn):
    about_dialog.run()
    about_dialog.hide()
about_button.connect("clicked", about_button_clicked)

# Function to define the search button.
def search_button(btn):
    browser.open("http://www.duckduckgo.com/")
search.connect("clicked", search_button)


# Show the widgets
window.add(display)
window.show_all()

# Start the program
gtk.main()
Last edited by vbrummond on 2012-01-12 11:46, edited 2 times in total.
Always on Debian Testing
vbrummond
 
Posts: 4468
Joined: 2010-03-02 01:42

Re: Developing for Raspberry PI

Postby sumit4palz » 2012-01-12 11:46

Thanks once again.

Currently i am struggling with installing PyGTK and getting following error:

root@debian:/home/sumit# apt-get install python-gtk python-glade2
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package python-gtk is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-gtk' has no installation candidate
root@debian:/home/sumit#

I have tried variants of this command like : python-glade2 but not successfull. Still searching if there are others facing the same issue.
sumit4palz
 
Posts: 4
Joined: 2012-01-12 08:04

Re: Developing for Raspberry PI

Postby vbrummond » 2012-01-12 11:47

Seems like you need to update your sources. Try apt-get update Then run the command again.

Edit: Oops, its python-gtk2 you want.
Always on Debian Testing
vbrummond
 
Posts: 4468
Joined: 2010-03-02 01:42

Re: Developing for Raspberry PI

Postby nadir » 2012-01-12 14:35

I did never get anywhere with anything (and hence not with python too), but i got this in my python bookmarks:
http://www.micahcarrick.com/gtk-glade-t ... art-1.html
this one too, which is from the link vbrummond gave above:
http://www.pygtk.org/pygtk2tutorial/index.html

the web-browser from above is cool (got to test it on my stoneage machines, as it seems really fast).
"I am not fine with it, so there is nothing for me to do but stand aside." M.D.
User avatar
nadir
 
Posts: 5964
Joined: 2009-10-05 22:06
Location: away

Re: Developing for Raspberry PI

Postby vbrummond » 2012-01-13 00:37

nadir wrote:the web-browser from above is cool (got to test it on my stoneage machines, as it seems really fast).


Thank you! :) It is kind of 'useless' but it was fun to make. I wanted to learn to program a GUI and not just script kiddie stuff.
Always on Debian Testing
vbrummond
 
Posts: 4468
Joined: 2010-03-02 01:42


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 4 guests

fashionable