homecloud computingcloud data Processingclound of networks
cloud of things

RaspberryPi C Programming - An Introduction

Duration: 5 Days

Course Background

The goals of this course are to introduce students to the world of programming using C as their first, serious, programming language. There have been many discussions over the years regarding the use of C as the first programming language to teach. Admittedly C has several tricky features, especially pointers and dynamic memory management. These are very powerful, but can be tricky to use well in practice. It is possible to write good structured code in C, and the Linux Kernel serves as excellent testimony for this assertion. It is also possible to teach C as a first programming language, as FTT's instructors have been doing for many years now. C syntax has had an influence on many programming languages e.g. C#, C++, Java, and Objective C. It is also used in implementing code for many small microcontroller based embedded systems such as those using Microchip, or AtmelAVR microcontrollers. Arduino programming is also C with a few C++ features added in.
This course will cover C programming not only on Linux systems (PC running Linux, or RaspberryPi running Linux) - but will also, to demonstrate the portability of C, include an introduction to C programming of a small embedded system using an 8 bit Microchip controller, that can communicate with a RaspberryPi, or a PC running Linux over a serial (RS232) link.

An important purpose of RPI103 is to "teach the teachers". To this end, as well as regular programming labs the course will include labs in which students are required to develop "teaching materials and their associated labs". This is why this course follows the intensive "Boot Camp" format. The "develop labs and teaching materials" sections will take place in the early evening "breakout" sessions. These will be group sessions involving groups of 3 to 4 students. This course will be a "dual mode" course. Code will be developed on the PC and will be compiled and tested on the PC, but also cross-compiled for an ARM processor target and downloaded and run on the RaspberryPi. The course will teach both command line compiling and the use of make and Makefiles as well as programming using the Eclipse IDE (Integrated Development Environment). The basics of debugging and Unit testing techniques will also be introduced.

Each attendee will be given a RaspberryPi and a Microchip evaluation board to take with them after the course. If there is sufficient demand FTT will set up a forum for teachers , engineers and experimenters to discuss and follow up on various issues and topics raised on this course.

Course Benefits

You'll learn how to write C programs to process text and data, read and write files. You will also be introduced to arrays and pointers and how they are related. In addition, you will learn about techniques for devising data structures and the algorithms to manipulate them.

Course Prerequisites and Target Audience

Attendees should have a basic understanding of Linux, e.g. as might be acquired by attending the Introduction to the RaspberryPi course. You are expected to have a basic knowledge of how to use Linux, both from the desktop and from the command line. You are not expected to be programmers, though a little prior exposure to e.g. Javascript or VBA would not go amiss. As always, a positive attitude to open source software would be most helpful, as would an enthusiasm for exploring and playing around with new technologies.

Course Outline

  • First steps
    • How C became
    • Building C programs from the command line vs. Building C programs using the IDE (Integrated Development Environment)
    • Introduction to the Eclipse CDT IDE
    • The basic anatomy of a C program
  • Data types, operators and expressions (the basics)
    • Base data types and their sizes
    • Constants and declarations
    • Variable names
    • Arithemetic operators
    • Relational and logical operators
    • Increment and decrement operators
    • Assignment operators
    • Expressions
    • Operator precedence
    • Casting and type conversion
  • Program flow control
    • if/else
    • switch
    • while , do-while and for-loops
    • statements and blocks
  • Functions
    • Functions and function prototypes
    • Returning values from functions
    • External variables and scope rules
    • Static variables
    • Call by value and recursion
  • Pointers and arrays
    • Pointers and addresses
    • Pointers as arguments to functions
    • Arrays
    • The relationship of pointers and arrays
    • Pointer arithmetic
    • How C deals with multi-dimensional arrays
    • Arrays of pointers: their uses and initialisation
    • Strings and string functions
  • Structures
    • Fundamentals of structures
    • Passing structures as arguments to functions
    • Returning structures as return values from functions
    • Arrays of structures
    • Pointers to structures
    • Using pointers to structures to pass values to a function and return values from a function
    • typedef and its uses in developing well structured and maintainable code
  • An introduction to data structures and algorithms
    • Aorting arrays of records
    • Allocating and freeing memory (malloc and free)
    • An overview of linked lists and queues
    • An overview of indexing (table lookup, binary trees, hashing)
  • Input-output
    • Standard input and standard output
    • Formatted output: printf
    • Formatted input: scanf
    • The dangers of scanf
    • File access and file I/O
    • An overview of input-output in a windowing environment
  • Further topics
    • The MACRO pre-processor and how to use it wisely
    • Unions
    • Bit fields
    • Date and Time functions in the C Standard Library
    • Diagnostics- the assert macro
  • Introduction to embedded systems C programming using the PIC16 MPLABX and Microchip's XC8 compiler
    • Overview of the MPLAB IDE and the HiTech C compiler
    • Compiling, simulating and downloading C programs
    • Making things happen - flashing LEDs, detecting button presses
    • Introduction to interrupts and timers
    • Introduction to ADC (Analog to Data Converstion)
    • Introduction to RS232 - and getting a PIC16 to communicate with a RaspberryPi over RS232