Difference between revisions of "RaspberryPi:Programming"

From UCT EE Wiki
Jump to navigation Jump to search
(Created page with "= Overview = The Raspberry Pi can run a Linux based operating system, and can therefore use almost any programming language. For the sake of interfacing with the GPIOs, Python...")
 
Line 9: Line 9:
  
 
= Cross Compilation =
 
= Cross Compilation =
 +
For more information on cross compilation, please see [[Toolchains, Compilers And Makefiles]].
 +
 +
== Requirements ==
 +
 +
On Windows, download and install the cross compilation framework: [http://gnutoolchains.com/raspberry/  http://gnutoolchains.com/raspberry/] When installing, make sure you select “Add to Path”.
 +
 +
On a Linux/Ubuntu-based system, run
 +
 +
<pre>$ sudo apt-get install libc6-armel-cross libc6-dev-armel-cross
 +
$ sudo apt-get install binutils-arm-linux-gnueabi libncurses5-dev lib32z1
 +
$ sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi</pre>
 +
=== Using cross compilation ===
 +
 +
Cross compilation is as simple as setting a different compiler in your make file or compilation script. For example, instead of
 +
 +
<pre>$ g++  &lt;file&gt;.cpp -o &lt;compiled_file_name&gt;</pre>
 +
You would run
 +
 +
<pre>$ arm-linux-gnueabihf-g++ &lt;file&gt;.cpp -o &lt;compiled_file_name&gt;</pre>
 +
== Moving the files to the Pi ==
 +
 +
To move the compiled files to the Pi, SCP (See [[Network Protocols]]) is quick and painless solution. Once the compiled file has been copied across, add the execution flag and run the file by running the following commands on the Raspberry Pi:
 +
 +
<pre>$ chmod +x &lt;compiled_file_name&gt;
 +
$ ./&lt;compiled_file_name&gt;</pre>

Revision as of 08:28, 6 February 2020

Overview

The Raspberry Pi can run a Linux based operating system, and can therefore use almost any programming language. For the sake of interfacing with the GPIOs, Python and C/C++ are usually considered the simplest, and you will find the most resources.

For programming in Python, please visit RaspberryPi:ProgrammingInPython.

For programming in C or C++, please visit RaspberryPi:ProgrammingInC.

Programming Environments

Cross Compilation

For more information on cross compilation, please see Toolchains, Compilers And Makefiles.

Requirements

On Windows, download and install the cross compilation framework: http://gnutoolchains.com/raspberry/ When installing, make sure you select “Add to Path”.

On a Linux/Ubuntu-based system, run

$ sudo apt-get install libc6-armel-cross libc6-dev-armel-cross 
$ sudo apt-get install binutils-arm-linux-gnueabi libncurses5-dev lib32z1
$ sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

Using cross compilation

Cross compilation is as simple as setting a different compiler in your make file or compilation script. For example, instead of

$ g++  <file>.cpp -o <compiled_file_name>

You would run

$ arm-linux-gnueabihf-g++ <file>.cpp -o <compiled_file_name>

Moving the files to the Pi

To move the compiled files to the Pi, SCP (See Network Protocols) is quick and painless solution. Once the compiled file has been copied across, add the execution flag and run the file by running the following commands on the Raspberry Pi:

$ chmod +x <compiled_file_name>
$ ./<compiled_file_name>