Posts

Which language on the Raspberry Pi?

Image
What language should you use on the Raspberry Pi? There is quite a choice, including Python, Scratch, Java, C, Julia, and that's not counting the web stuff like Javascript, Html and Php.
There is no definitive answer - it depends on what you want to do. If you are teaching a child the basics of programming then Scratch might be a good choice. If you are an older learner then you might go for Python or Java with Greenfoot.
If you are interested in programming the Raspberry Pi hardware then there are libraries for pretty much any language that will let you do that. 
If you want a graphical user interface then you may want to give C a miss. But not necessarily because you can tack on a GUI in almost any language these days.
So where does that leave us?
Here is a list of some of the programming languages available for the Raspberry Pi with my brief personal notes and an example program for each one (except Scratch).

Advertisement

Scratch This is a graphical language designed to tea…

Just Enough Python

Image
Just Enough Python This is a series of tutorials to get you going with Python on your Raspberry Pi (or other Linux system) . It is NOT a comprehensive guide to Python but  teaches you enough to be able to give you a flavour of the language and to produce useful programs.



Just Enough Python 0 - getting set up If you are using a Raspberry Pi to follow this tutorial and you have the latest version of Raspbian, then you already have everything you need. If you are using something else, read this first.  (Go there now)
Just Enough Python with Geany 1 Python is a great language to learn, as well as being a real professional's language. It is include in Raspbian the Pi's operation system. Here we see how to use the powerful but light-weight editor, Geany, to create and run a Python program. (Go to Just Enough Python with Geany 1)

Just Enough Python 2 Now we know how to use Geany, we are going to write a simple program that takes and input from the keyboard, changes it a little, and wri…

Introduction to Python by Andrew Ng

Image
A free ebook or a very reasonably priced paperback that provides a very broad coverage of the Python language.

Andrew Ng is a well known figure in the world of AI and since Python is a major language in that world, you'd imagine that Ng is quite an authority on Python.

This books demonstrates that this is, indeed, the case. It is an extremely comprehensive book covering just about every aspect of Python that you might want to know about. It is a conventional book that starts with how to install the software and then moves on to the language itself. It covers data and variables, moves through operators, control statements, libraries, functions, OOP, and databases, giving a detailed coverage of each topic.You'd be hard-pressed to find anything missing.

While it is well explained, the examples are fairly trivial which, in a book of less than 300 pages, is not really very surprising, particularly given the amount of ground the author covers.


Advertisement

Ng is clearly an expert …

K&R - the C Programming Language

Image
Having looked at Simon Long's book about C programming, I thought I should give a mention to the one that has been long regarded as the C Bible, and the one that Simon suggests as further reading: the C Programming Language by Brian W. Kernighan and Dennis Ritchie.

Kernighan and Ritchie not only wrote the book, they wrote the language, too (well, Ritchie did) . They then went on to revise the language and produce a new edition of the book. So if your grandfather offers to lend you a copy of K&R's first edition, just politely say, "no, thanks", it’s the second edition that you need.

The K&R book is quite short - less than 300 pages - and in two main parts, the first part is a tutorial which covers the main aspects of the language and the second is a series of chapters going into the different parts of the language in much more depth.

The tutorial gives plenty of examples albeit fairly short ones and you can get a pretty good idea of the language just from the…

Learn to code with C

Image
C is the world's most popular language, according to Simon Long, and he is going to show you how to use it. 

The book comes from the publishers of Magpi, a magazine which is aimed at Raspberry Pi owners both beginners and enthusiasts.  It's a short book (less than 100 pages) that leads you through a language that has the reputation of being difficult to learn.

While it is aimed at Raspberry Pi users, it can be used by any would-be C programmer. Long uses the Rasbian operating system but, from the point of view of this book, it could be almost any Linux distribution And the language details are, of course, the same no matter what operating system you use.

Advertisement


We start off with the ubiquitous "Hello World!" program and this is entirely appropriate because the original book of the C language by Kernighan and Ritchie was where this program first appeared.

Long moves along at a good pace with short chapters on all the main features of C. We quickly go through v…

A little bit of Java

Java is a comprehensive, general purpose language. It has a ton of libraries available for it, some come built in when you get it, others you can download. One of the most important libraries, Swing, let's you build vsophisticated user interfaces.

So Java can be used to build desktop applications but it is also widely used on the web, too. The are several frameworks for building web applications. It is also the language for building Android applications.

All in all, it's a useful language to learn. 
Java is fully object-oriented (although I won't be demonstrating that, here) and inherits much of its syntax from C and C++.
Here's an example. It’s the same guessing game that I've used in my other "A little bit of..."  posts. It gives you a flavour of the language and illustrates some basic programming constructs.

import java.util.Scanner;
import java.util.Random;
public class guess {
// Start here
public static void main (String args[]) {
Random r = new Random()…

WARP how it works

Image
Weather According to Raspberry Pi (WARP)(Please note that this tutorial is based on a previous on about Flask and edited specifically for the WARP project. If you think you have read it before, then move on to the next one.)

In a previous post I described the WARP mini-project and gave you the files to make it work on your own Raspberry Pi. This post describes how it works by using the Flask framework.

Most web applications are written in PHP, Java, Ruby or one of Microsoft's languages like C# and use a web server such as Apache or IIS. Flask let's you do the same thing with Python.
To begin with we are going to write a simple Python/Flask program to combine the best of these two worlds and publish data read by your Raspberry Pi onto your network, where you can view it on your laptop or phone. 
The final program will read weather data from a SenseHAT (or SenseHAT emulator) and display it on a web page. However, we won't be going that far in this tutorial because our main a…