RaspberryPi:Programming

From UCT EE Wiki
Revision as of 15:44, 6 February 2020 by CRNKEE002 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

Options for programming environments include:

  1. PyCharm for Python
  2. CLion for C and C++
  3. Visual Studio Code for just about anything, so long as you can find a plug in
  4. Using one of the many standard Text Editors

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>