<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>http://wiki.ee.uct.ac.za/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CRNKEE002</id>
	<title>UCT EE Wiki - User contributions [en-gb]</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.ee.uct.ac.za/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=CRNKEE002"/>
	<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/Special:Contributions/CRNKEE002"/>
	<updated>2026-04-08T08:58:37Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=Main_Page&amp;diff=474</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=Main_Page&amp;diff=474"/>
		<updated>2021-02-16T11:38:04Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: Reverted edits by Swinberg (talk) to last revision by 102.140.112.36&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Management]]&lt;br /&gt;
&amp;lt;strong&amp;gt;Welcome to the Department of Electrical Engineering Wiki&amp;lt;/strong&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Department's Website is located at [https://ee.uct.ac.za ee.uct.ac.za]&lt;br /&gt;
&lt;br /&gt;
This wiki is intended to give information on tools, software and hardware that make studying and research in the department easier. It is &amp;lt;strong&amp;gt;not&amp;lt;/strong&amp;gt; a place to host course specific content. For that, please see [http://ocw.ee.uct.ac.za/ EE Department OpenCourseWare site].&lt;br /&gt;
&lt;br /&gt;
If you have any queries, complaints, compliments, criticisms or suggestions, please send them to ucteewiki[at]gmail.com&lt;br /&gt;
&lt;br /&gt;
= Using the wiki =&lt;br /&gt;
[[File:UsingWikimedia.jpg|right|100px|]]&lt;br /&gt;
Most of the time, as a user seeking information, you basically want to go to the search box at the top of the page and type in keywords related to the issue you want to find out about. According to 'wiki editing philosophy' (See [[Project:Editing]]) we are attempting to keep things marked with keyworkds and put in suitable namespaces to keep the information well index and easily searchable. If you have additional ideas on how we can improve the indexing and creation of contact, or ideas generally to improve our knowledge management practices, we would be most grateful to hear your ideas (please email them to ucteewiki[at]gmail.com).&lt;br /&gt;
&lt;br /&gt;
= Main Categories =&lt;br /&gt;
[[File:CategoriesSearch.jpeg|right|100px|]]&lt;br /&gt;
The Categories are the top-level categories that pages in this wiki are arranged into. Each of the categories listed below essentially link to pages that have further links to the actual content that you may want to browser for answers to your questions, see: {{Special:Prefixindex/Category:}}&lt;br /&gt;
&lt;br /&gt;
= A Hitchhiker's Guide to this Wiki =&lt;br /&gt;
* To view all pages on the Wiki, see [[All Pages]]&lt;br /&gt;
* If you'd like to learn how to create pages on this Wiki and what the philosophies of data organisation are, please see [[Project:Editing]]&lt;br /&gt;
* Guide on formatting: [https://meta.wikimedia.org/wiki/Help:Wikitext_examples Wikitext formatting examples]&lt;br /&gt;
&lt;br /&gt;
= Other Useful Links =&lt;br /&gt;
* [http://hive.ee.uct.ac.za/ Hive, a single access point for all things EE]&lt;br /&gt;
* [http://ocw.ee.uct.ac.za/ EE Department OpenCourseWare site]&lt;br /&gt;
* [https://github.com/UCT-EE-OCW The UCT OCW GitHub]&lt;br /&gt;
* [http://wiki.ee.uct.ac.za/Templates_for_Articles,_Dissertations_and_Reports]&lt;br /&gt;
* [https://docs.google.com/document/d/1tp_YYqvUUViPUb_ZTzGNi4BVfWNqkrOlXcdM63DAwWY/edit Justin's Useful Linker (White Lab Links)]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=471</id>
		<title>VHDL</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=471"/>
		<updated>2021-01-28T11:00:10Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* VHDL Operators */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]][[Category:Software]]&lt;br /&gt;
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. &lt;br /&gt;
The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. [[File:VHDL Notes 2016 updated SamuelGinsberg.pdf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Structure and Behaviour =&lt;br /&gt;
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-StructureandBehaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-StructureandBehaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Structure&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Structure&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
The structure of a system describes that system in terms of &amp;quot;what is connected to what&amp;quot;. The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Behaviour ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Behaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Behaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entities ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Entities&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Entities&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
As we have mentioned an entity is a &amp;quot;box&amp;quot; with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity hadder is&lt;br /&gt;
    port&lt;br /&gt;
        (inA, inB  : in  std_logic;&lt;br /&gt;
         sum,carry : out std_logic); --note the semicolon&lt;br /&gt;
end hadder;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architectures ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Architectures&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Architectures&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.&lt;br /&gt;
&lt;br /&gt;
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
Here is an example of structural description:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
architecture structure of hadder is&lt;br /&gt;
--We now need to describe the interface to the components that we are&lt;br /&gt;
--using. These components are described in the ALTERA MAXPLUS2 library.&lt;br /&gt;
component a_7408 --AND gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
component a_7486 --XOR gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
--Signals are like wires used to connect components&lt;br /&gt;
signal inputA,inputB : std_logic;&lt;br /&gt;
begin&lt;br /&gt;
 --see equivalent diagram in notes to understand this.&lt;br /&gt;
 inputA&amp;lt;=inA;&lt;br /&gt;
 inputB&amp;lt;=inB;&lt;br /&gt;
 myAND: a_7408 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;carry);&lt;br /&gt;
 myXOR: a_7486 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;sum);&lt;br /&gt;
end structure;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal &amp;quot;wires&amp;quot; which connect components together. The signals are inputA and inputB.&lt;br /&gt;
&lt;br /&gt;
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Processes =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Processes&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Processes&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
We sometimes want a set of VHDL statements to execute sequentially, one after the other. This allows us to build up a set of instructions that are 'executed' one after the other. The execution of this list is triggered by some event happening, very often on a port of the entity.&lt;br /&gt;
&lt;br /&gt;
As an example consider this simple flip flop design:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
LIBRARY ieee;&lt;br /&gt;
USE ieee.std_logic_1164.all;&lt;br /&gt;
ENTITY test_proc1 IS&lt;br /&gt;
 PORT&lt;br /&gt;
 (D_input : IN STD_LOGIC;&lt;br /&gt;
 clk_input : IN STD_LOGIC;&lt;br /&gt;
 Q_output : OUT STD_LOGIC);&lt;br /&gt;
END test_proc1;&lt;br /&gt;
ARCHITECTURE a OF test_proc1 IS&lt;br /&gt;
BEGIN&lt;br /&gt;
 PROCESS (clk_input) --trigger this when clk_input changes&lt;br /&gt;
 BEGIN&lt;br /&gt;
 if (clk_input='1') then&lt;br /&gt;
 Q_output &amp;lt;= D_input;&lt;br /&gt;
 end if;&lt;br /&gt;
 END &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we are describing the behavior of a D type flip flop. The flip flop's D input is transferred to the Q output and held there on the rising edge of the clock signal.&lt;br /&gt;
We declare an entity as before.&lt;br /&gt;
&lt;br /&gt;
The architecture begins with the keyword 'Process' followed by a list of port names, in this case clk_input. This list is called a 'sensitivity list'. Whenever one (or more) of the items in the sensitivity list changes the code that is contained in the process is executed. In this example when clk_input changes, the code within the process is executed. This code examines the state of the clk_input bit and if it is high the Q output is updated to be equal to the D input. We achieve the rising edge triggered action by looking for a change in clk_input and then examining to see if the change was a rising or a falling edge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Variables&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Variables&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
It is possible to have variables in an architecture. Variables are used to store data within a process. Signals differ from variables in that variables cannot trigger events, nor can a change in a variable trigger a process. &lt;br /&gt;
&lt;br /&gt;
Furthermore, signal values within a process change only when the process is completed, whereas variables are evaluated immediately.&lt;br /&gt;
&lt;br /&gt;
Variables are modified with the variable assignment operator which is :=, thus assigning one variable to another is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
one_variable := another_variable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Syntax =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Syntax&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Syntax&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
== Comments ==&lt;br /&gt;
Comments are preceded by &amp;quot;--&amp;quot; (two dashes) and extend to the end of the line. Multiline comments are not available, but some code editors provide a multiline comment feature.&lt;br /&gt;
&lt;br /&gt;
== Identifiers ==&lt;br /&gt;
Identifiers are names of signals, variables, components etc. etc. The names must all begin with a letter. After the initial letter they may have any combination of letters, numbers and underscores. VHDL is not case sensitive.&lt;br /&gt;
&lt;br /&gt;
== Numbers ==&lt;br /&gt;
VHDL has support for a very wide range of number representations.&lt;br /&gt;
&lt;br /&gt;
Numbers may be in any base between 2 and 16. The hash (#) separator is used to separate the base from the rest of the number, by surrounding the number. e.g. 2#10101010# =10101010 base 2. Note that the base is an integer expressed in base 10.&lt;br /&gt;
&lt;br /&gt;
Real literals may have decimal points. These numbers are real numbers with a fixed fractional part. The VHDL standard supports floating point numbers although some VHDL compilers do not. Floating point operations are extremely expensive to implement because of the inefficiency incurred in synthesizing the floating point operations. e.g. 3.1415 is a fixed point real number.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember that VHDL only looks like a programming language. Bear in mind that when you use a floating point number the required operation has to be constructed out of gates when the design is put onto a chip. Numbers may have exponents. The exponents are expressed in decimal and may only be integers. Exponents may be positive or negative. The exponent is signified by an 'E'. The exponent is raised to the base. For example, a number expressed in base 2 will be multiplied by 2 to the power of the exponent.&lt;br /&gt;
&lt;br /&gt;
Example: 2#1010#E1=1010*2^1=10100=20 decimal.&lt;br /&gt;
&lt;br /&gt;
Here is an example of VHDL using integer types:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
  port (clock : In std_logic;&lt;br /&gt;
    sel : In std_logic;&lt;br /&gt;
    output: Out integer range 0 to 255);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
  begin&lt;br /&gt;
  process (clock)&lt;br /&gt;
  begin&lt;br /&gt;
     if clock='1' then&lt;br /&gt;
       if sel='1' then&lt;br /&gt;
         output&amp;lt;=16#55#;&lt;br /&gt;
       else&lt;br /&gt;
         output&amp;lt;=2#1010_1010#;&lt;br /&gt;
       end if;&lt;br /&gt;
     end if;&lt;br /&gt;
  end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Integer types are used for representing numbers with no fractional part. VHDL guarantees that integers will be represented by at least 32 bits. Integers are signed. We can limit the range of integers by using the range keyword. This is useful for limiting the size of the representation and for making your code more compiler independent. In general limit your range to the size that you need. When we limit the range of a type we obtain a &amp;lt;i&amp;gt;Subtype&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When limiting the range of an integer only the size of the representation is limited, not the actual range of the number. As an example if we said &amp;lt;code&amp;gt;dout: OUT integer range 0 to 2&amp;lt;/code&amp;gt; in the example above we would still have had a 2 bit counter. The code that could be represented on those 2 bits would still include “11”, even though it is outside of our defined range. Some simulation packages would flag a warning if this occurs, but many would not.&lt;br /&gt;
&lt;br /&gt;
When using an integer as a port, the port will have as many physical lines as are needed to represent the integer using standard binary coding. Thus, in the example above, 'dout' will be represented by two physical port lines.&lt;br /&gt;
&lt;br /&gt;
== Characters and Strings == &lt;br /&gt;
Characters are enclosed in single quotation marks and are equivalent to their ASCII number. e.g. '0'=48&lt;br /&gt;
&lt;br /&gt;
Strings are enclosed in double quotation marks. Example &amp;quot;Samuel&amp;quot; To include a double quotation mark inside quotation marks use it twice &amp;quot;Fred said&amp;quot;&amp;quot;hello&amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Strings may be formed in other number bases. These bases are binary, octal and hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 sel : In Std_logic;&lt;br /&gt;
 output: Out std_logic_vector (7 downto 0));&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if sel='1' then&lt;br /&gt;
     output&amp;lt;=&amp;quot;01010101&amp;quot;; --binary string. Use a string to fill vector&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=X&amp;quot;FF&amp;quot;; --Hexadecimal string&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enumerated Types ==&lt;br /&gt;
VHDL provides enumerated types for convenience. We have already come across one of these, std_logic, in which the logic states are represented as an enumerated type having nine different states which represent different electrical possibilities available on logic signals.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 output: Out integer range 0 to 1);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
type colour is (green, blue);&lt;br /&gt;
 --declare types in architecture declarative section&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
variable status: colour;&lt;br /&gt;
 --declare variables in process declarative section&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if status =green then&lt;br /&gt;
     output&amp;lt;=1;&lt;br /&gt;
     status:=blue;&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=0;&lt;br /&gt;
     status:=green;&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Arrays ==&lt;br /&gt;
These have the same meaning that you are used to. Arrays may have any number of dimensions and may be formed from any supported type, or previously defined type.&lt;br /&gt;
&lt;br /&gt;
There are predefined types, such as strings and bit vectors.&lt;br /&gt;
&lt;br /&gt;
The definition for the string type is given as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type string is array (positive range &amp;lt;&amp;gt;) of character;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The definition for bit vectors is as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type bit_vector is array (natural range &amp;lt;&amp;gt;) of bit;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;&amp;lt;&amp;gt;&amp;quot; angle brackets are called a box. They are placeholders which indicate that the range will be filled in when the types are used.&lt;br /&gt;
&lt;br /&gt;
Bit vectors are essentially an array of bits used for binary numbers. Here is an example of the usage of a bit&lt;br /&gt;
vector:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
din: in bit_vector (2 downto 0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this case the box will be filled in with the range 2 downto 0.&lt;br /&gt;
&lt;br /&gt;
Arrays may be indexed to access individual elements. If we wish to access the first bit in din then we can say:&lt;br /&gt;
&amp;lt;code&amp;gt;if din(2)='1' then....&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in the case of bit vectors when we specify the range we are specifying an array index. As a result, we are not specifying the numerical range, but rather the actual number of bits in the array.&lt;br /&gt;
&lt;br /&gt;
If we use the “downto” keyword then the most significant bit will occupy the highest numbered array position. The opposite will apply if we use the “to” keyword.&lt;br /&gt;
&lt;br /&gt;
We will not use bit vectors much, rather we will use 'standard logic vectors' which are more widely supported. The reason for this is that most of the libraries that are available for our VHDL system are defined in terms of standard logic vectors, rather than bit vectors. The behavior of std_logic_vectors is however very similar to the bit vector, except that, as noted above, std_logic has more possible states.&lt;br /&gt;
&lt;br /&gt;
See above for examples of std_logic_vector usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Operators =&lt;br /&gt;
Like any language VHDL has a set of operators. These operators may be divided into three types: Logical, arithmetic and comparison.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Operators&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Operators&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Logical Operators ==&lt;br /&gt;
Logical operators are used to derive logical results from bits and bit_vectors. When used with bit_vectors the operators act in a bitwise manner. When used with bit_vectors, those vectors must be of the same length.&lt;br /&gt;
The logical operators are as follows:&lt;br /&gt;
* NOT&lt;br /&gt;
* AND&lt;br /&gt;
* OR&lt;br /&gt;
* NAND&lt;br /&gt;
* NOR&lt;br /&gt;
* XOR&lt;br /&gt;
These should require no further explanation.&lt;br /&gt;
In addition there is a concatenation operator. This is the ampersand &amp;quot;&amp;amp;&amp;quot;. This concatenates two bit vectors.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
signal a: bit_vector (1 to 3);&lt;br /&gt;
signal b: bit_vector (1 to 5);&lt;br /&gt;
signal c: bit_vector (1 to 8);&lt;br /&gt;
c &amp;lt;= a &amp;amp; b; --legal concatenation operation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arithmetic Operators ==&lt;br /&gt;
These operators perform basic arithmetic operations on numbers. Normally these operations are only intended for use on integers. Some VHDL suites come with libraries which contain arithmetic functions for use with bit_vectors and std_logic vectors.&lt;br /&gt;
&lt;br /&gt;
The operators are:&lt;br /&gt;
* addition (+)&lt;br /&gt;
* subtraction (-)&lt;br /&gt;
* multiplication (*)&lt;br /&gt;
* division (/)&lt;br /&gt;
&lt;br /&gt;
The only caution that applies here is that some packages only support multiplication and division by integer powers of two. This in effect reduces multiplication and division to the status of arithmetic shift operations.&lt;br /&gt;
&lt;br /&gt;
== Comparison Operators ==&lt;br /&gt;
These operators are used to compare two scalar or bit_vector arguments and they return 'true ' or 'false'. If bit_vectors are compared then the vectors must be of the same length.&lt;br /&gt;
{|&lt;br /&gt;
| &amp;lt;&lt;br /&gt;
| smaller than&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= &lt;br /&gt;
| smaller than or equal&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt; &lt;br /&gt;
| greater than&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= &lt;br /&gt;
| greater than or equal&lt;br /&gt;
|-&lt;br /&gt;
| = &lt;br /&gt;
| equal&lt;br /&gt;
|-&lt;br /&gt;
| /= &lt;br /&gt;
|not equal&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Attributes of Objects =&lt;br /&gt;
Attributes are properties of VHDL types that can be very useful. We use attributes to extract further information about a VHDL object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-AoO&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-AoO&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All attributes are accessed by using the apostrophe ' operator, sometimes pronounced “tick”. In theory attributes are classified by what sort of thing they return, but in authoritative sources (compare Ashenden 2008 to Perry 2002) they are dealt with in quite different ways. For purposes of this course we will be quite loose in our handling of attributes, aiming for utility rather than formal correctness.&lt;br /&gt;
&lt;br /&gt;
== Attributes of Signals ==&lt;br /&gt;
These attributes either derive information about signals or define new signals based on other signals. We have seen one of these already, the 'event attribute. This attribute creates a signal that is true when its base signal has changed in the last cycle. Examples have been shown above. There is also a 'last_value attribute which returns the value of a signal prior to its last transition.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are many more of these attributes, however many of them are for simulation purposes only and cannot be directly synthesized to hardware. These would typically be used for generating testbenches.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Attributes of Scalar Types ==&lt;br /&gt;
&lt;br /&gt;
'pos – str'pos (&amp;quot;fred&amp;quot;) gives the position of fred in the string str.   &lt;br /&gt;
&lt;br /&gt;
'val – Var'val(x) gives the value at position x of variable var.    &lt;br /&gt;
&lt;br /&gt;
'leftof – value in a variable to the left of a specified position.    &lt;br /&gt;
&lt;br /&gt;
'rightof – value in a variable to the right of a specified position.    &lt;br /&gt;
&lt;br /&gt;
'pred – value of a preceding position. Depends on range direction.    &lt;br /&gt;
&lt;br /&gt;
'succ – value of a succeeding position. Depends on range direction.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that not all of these attributes apply to all types. Most of the above are useful with enumerated types. If an array is declared with a range of indices from 10 to 30 then Array'left will return 10.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
Suppose we have the following declarations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
lsb_output: OUT std_logic --declare a bit-wide port&lt;br /&gt;
signal count_signal_name : STD_LOGIC_VECTOR (3 downto 0); --declare a 4 bit wide signal&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the following line extracts the least significant bit from the signal and assigns it to the port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
lsb_output &amp;lt;= count_signal_name (count_signal_name'right);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This is useful for making procedures which handle arrays independently of the array width.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= More on Processes = &lt;br /&gt;
= Changing Execution Flow in VHDL = &lt;br /&gt;
= Dividing Big Jobs into Little Jobs = &lt;br /&gt;
= Packages = &lt;br /&gt;
= Conversion Functions =&lt;br /&gt;
= Megafunctions =&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=470</id>
		<title>VHDL</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=470"/>
		<updated>2021-01-28T10:59:53Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Attributes of Objects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]][[Category:Software]]&lt;br /&gt;
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. &lt;br /&gt;
The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. [[File:VHDL Notes 2016 updated SamuelGinsberg.pdf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Structure and Behaviour =&lt;br /&gt;
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-StructureandBehaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-StructureandBehaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Structure&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Structure&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
The structure of a system describes that system in terms of &amp;quot;what is connected to what&amp;quot;. The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Behaviour ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Behaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Behaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entities ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Entities&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Entities&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
As we have mentioned an entity is a &amp;quot;box&amp;quot; with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity hadder is&lt;br /&gt;
    port&lt;br /&gt;
        (inA, inB  : in  std_logic;&lt;br /&gt;
         sum,carry : out std_logic); --note the semicolon&lt;br /&gt;
end hadder;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architectures ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Architectures&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Architectures&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.&lt;br /&gt;
&lt;br /&gt;
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
Here is an example of structural description:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
architecture structure of hadder is&lt;br /&gt;
--We now need to describe the interface to the components that we are&lt;br /&gt;
--using. These components are described in the ALTERA MAXPLUS2 library.&lt;br /&gt;
component a_7408 --AND gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
component a_7486 --XOR gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
--Signals are like wires used to connect components&lt;br /&gt;
signal inputA,inputB : std_logic;&lt;br /&gt;
begin&lt;br /&gt;
 --see equivalent diagram in notes to understand this.&lt;br /&gt;
 inputA&amp;lt;=inA;&lt;br /&gt;
 inputB&amp;lt;=inB;&lt;br /&gt;
 myAND: a_7408 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;carry);&lt;br /&gt;
 myXOR: a_7486 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;sum);&lt;br /&gt;
end structure;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal &amp;quot;wires&amp;quot; which connect components together. The signals are inputA and inputB.&lt;br /&gt;
&lt;br /&gt;
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Processes =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Processes&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Processes&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
We sometimes want a set of VHDL statements to execute sequentially, one after the other. This allows us to build up a set of instructions that are 'executed' one after the other. The execution of this list is triggered by some event happening, very often on a port of the entity.&lt;br /&gt;
&lt;br /&gt;
As an example consider this simple flip flop design:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
LIBRARY ieee;&lt;br /&gt;
USE ieee.std_logic_1164.all;&lt;br /&gt;
ENTITY test_proc1 IS&lt;br /&gt;
 PORT&lt;br /&gt;
 (D_input : IN STD_LOGIC;&lt;br /&gt;
 clk_input : IN STD_LOGIC;&lt;br /&gt;
 Q_output : OUT STD_LOGIC);&lt;br /&gt;
END test_proc1;&lt;br /&gt;
ARCHITECTURE a OF test_proc1 IS&lt;br /&gt;
BEGIN&lt;br /&gt;
 PROCESS (clk_input) --trigger this when clk_input changes&lt;br /&gt;
 BEGIN&lt;br /&gt;
 if (clk_input='1') then&lt;br /&gt;
 Q_output &amp;lt;= D_input;&lt;br /&gt;
 end if;&lt;br /&gt;
 END &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we are describing the behavior of a D type flip flop. The flip flop's D input is transferred to the Q output and held there on the rising edge of the clock signal.&lt;br /&gt;
We declare an entity as before.&lt;br /&gt;
&lt;br /&gt;
The architecture begins with the keyword 'Process' followed by a list of port names, in this case clk_input. This list is called a 'sensitivity list'. Whenever one (or more) of the items in the sensitivity list changes the code that is contained in the process is executed. In this example when clk_input changes, the code within the process is executed. This code examines the state of the clk_input bit and if it is high the Q output is updated to be equal to the D input. We achieve the rising edge triggered action by looking for a change in clk_input and then examining to see if the change was a rising or a falling edge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Variables&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Variables&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
It is possible to have variables in an architecture. Variables are used to store data within a process. Signals differ from variables in that variables cannot trigger events, nor can a change in a variable trigger a process. &lt;br /&gt;
&lt;br /&gt;
Furthermore, signal values within a process change only when the process is completed, whereas variables are evaluated immediately.&lt;br /&gt;
&lt;br /&gt;
Variables are modified with the variable assignment operator which is :=, thus assigning one variable to another is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
one_variable := another_variable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Syntax =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Syntax&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Syntax&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
== Comments ==&lt;br /&gt;
Comments are preceded by &amp;quot;--&amp;quot; (two dashes) and extend to the end of the line. Multiline comments are not available, but some code editors provide a multiline comment feature.&lt;br /&gt;
&lt;br /&gt;
== Identifiers ==&lt;br /&gt;
Identifiers are names of signals, variables, components etc. etc. The names must all begin with a letter. After the initial letter they may have any combination of letters, numbers and underscores. VHDL is not case sensitive.&lt;br /&gt;
&lt;br /&gt;
== Numbers ==&lt;br /&gt;
VHDL has support for a very wide range of number representations.&lt;br /&gt;
&lt;br /&gt;
Numbers may be in any base between 2 and 16. The hash (#) separator is used to separate the base from the rest of the number, by surrounding the number. e.g. 2#10101010# =10101010 base 2. Note that the base is an integer expressed in base 10.&lt;br /&gt;
&lt;br /&gt;
Real literals may have decimal points. These numbers are real numbers with a fixed fractional part. The VHDL standard supports floating point numbers although some VHDL compilers do not. Floating point operations are extremely expensive to implement because of the inefficiency incurred in synthesizing the floating point operations. e.g. 3.1415 is a fixed point real number.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember that VHDL only looks like a programming language. Bear in mind that when you use a floating point number the required operation has to be constructed out of gates when the design is put onto a chip. Numbers may have exponents. The exponents are expressed in decimal and may only be integers. Exponents may be positive or negative. The exponent is signified by an 'E'. The exponent is raised to the base. For example, a number expressed in base 2 will be multiplied by 2 to the power of the exponent.&lt;br /&gt;
&lt;br /&gt;
Example: 2#1010#E1=1010*2^1=10100=20 decimal.&lt;br /&gt;
&lt;br /&gt;
Here is an example of VHDL using integer types:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
  port (clock : In std_logic;&lt;br /&gt;
    sel : In std_logic;&lt;br /&gt;
    output: Out integer range 0 to 255);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
  begin&lt;br /&gt;
  process (clock)&lt;br /&gt;
  begin&lt;br /&gt;
     if clock='1' then&lt;br /&gt;
       if sel='1' then&lt;br /&gt;
         output&amp;lt;=16#55#;&lt;br /&gt;
       else&lt;br /&gt;
         output&amp;lt;=2#1010_1010#;&lt;br /&gt;
       end if;&lt;br /&gt;
     end if;&lt;br /&gt;
  end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Integer types are used for representing numbers with no fractional part. VHDL guarantees that integers will be represented by at least 32 bits. Integers are signed. We can limit the range of integers by using the range keyword. This is useful for limiting the size of the representation and for making your code more compiler independent. In general limit your range to the size that you need. When we limit the range of a type we obtain a &amp;lt;i&amp;gt;Subtype&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When limiting the range of an integer only the size of the representation is limited, not the actual range of the number. As an example if we said &amp;lt;code&amp;gt;dout: OUT integer range 0 to 2&amp;lt;/code&amp;gt; in the example above we would still have had a 2 bit counter. The code that could be represented on those 2 bits would still include “11”, even though it is outside of our defined range. Some simulation packages would flag a warning if this occurs, but many would not.&lt;br /&gt;
&lt;br /&gt;
When using an integer as a port, the port will have as many physical lines as are needed to represent the integer using standard binary coding. Thus, in the example above, 'dout' will be represented by two physical port lines.&lt;br /&gt;
&lt;br /&gt;
== Characters and Strings == &lt;br /&gt;
Characters are enclosed in single quotation marks and are equivalent to their ASCII number. e.g. '0'=48&lt;br /&gt;
&lt;br /&gt;
Strings are enclosed in double quotation marks. Example &amp;quot;Samuel&amp;quot; To include a double quotation mark inside quotation marks use it twice &amp;quot;Fred said&amp;quot;&amp;quot;hello&amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Strings may be formed in other number bases. These bases are binary, octal and hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 sel : In Std_logic;&lt;br /&gt;
 output: Out std_logic_vector (7 downto 0));&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if sel='1' then&lt;br /&gt;
     output&amp;lt;=&amp;quot;01010101&amp;quot;; --binary string. Use a string to fill vector&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=X&amp;quot;FF&amp;quot;; --Hexadecimal string&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enumerated Types ==&lt;br /&gt;
VHDL provides enumerated types for convenience. We have already come across one of these, std_logic, in which the logic states are represented as an enumerated type having nine different states which represent different electrical possibilities available on logic signals.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 output: Out integer range 0 to 1);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
type colour is (green, blue);&lt;br /&gt;
 --declare types in architecture declarative section&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
variable status: colour;&lt;br /&gt;
 --declare variables in process declarative section&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if status =green then&lt;br /&gt;
     output&amp;lt;=1;&lt;br /&gt;
     status:=blue;&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=0;&lt;br /&gt;
     status:=green;&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Arrays ==&lt;br /&gt;
These have the same meaning that you are used to. Arrays may have any number of dimensions and may be formed from any supported type, or previously defined type.&lt;br /&gt;
&lt;br /&gt;
There are predefined types, such as strings and bit vectors.&lt;br /&gt;
&lt;br /&gt;
The definition for the string type is given as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type string is array (positive range &amp;lt;&amp;gt;) of character;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The definition for bit vectors is as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type bit_vector is array (natural range &amp;lt;&amp;gt;) of bit;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;&amp;lt;&amp;gt;&amp;quot; angle brackets are called a box. They are placeholders which indicate that the range will be filled in when the types are used.&lt;br /&gt;
&lt;br /&gt;
Bit vectors are essentially an array of bits used for binary numbers. Here is an example of the usage of a bit&lt;br /&gt;
vector:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
din: in bit_vector (2 downto 0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this case the box will be filled in with the range 2 downto 0.&lt;br /&gt;
&lt;br /&gt;
Arrays may be indexed to access individual elements. If we wish to access the first bit in din then we can say:&lt;br /&gt;
&amp;lt;code&amp;gt;if din(2)='1' then....&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in the case of bit vectors when we specify the range we are specifying an array index. As a result, we are not specifying the numerical range, but rather the actual number of bits in the array.&lt;br /&gt;
&lt;br /&gt;
If we use the “downto” keyword then the most significant bit will occupy the highest numbered array position. The opposite will apply if we use the “to” keyword.&lt;br /&gt;
&lt;br /&gt;
We will not use bit vectors much, rather we will use 'standard logic vectors' which are more widely supported. The reason for this is that most of the libraries that are available for our VHDL system are defined in terms of standard logic vectors, rather than bit vectors. The behavior of std_logic_vectors is however very similar to the bit vector, except that, as noted above, std_logic has more possible states.&lt;br /&gt;
&lt;br /&gt;
See above for examples of std_logic_vector usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Operators =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Operators&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Operators&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like any language VHDL has a set of operators. These operators may be divided into three types: Logical, arithmetic and comparison.&lt;br /&gt;
&lt;br /&gt;
== Logical Operators ==&lt;br /&gt;
Logical operators are used to derive logical results from bits and bit_vectors. When used with bit_vectors the operators act in a bitwise manner. When used with bit_vectors, those vectors must be of the same length.&lt;br /&gt;
The logical operators are as follows:&lt;br /&gt;
* NOT&lt;br /&gt;
* AND&lt;br /&gt;
* OR&lt;br /&gt;
* NAND&lt;br /&gt;
* NOR&lt;br /&gt;
* XOR&lt;br /&gt;
These should require no further explanation.&lt;br /&gt;
In addition there is a concatenation operator. This is the ampersand &amp;quot;&amp;amp;&amp;quot;. This concatenates two bit vectors.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
signal a: bit_vector (1 to 3);&lt;br /&gt;
signal b: bit_vector (1 to 5);&lt;br /&gt;
signal c: bit_vector (1 to 8);&lt;br /&gt;
c &amp;lt;= a &amp;amp; b; --legal concatenation operation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arithmetic Operators ==&lt;br /&gt;
These operators perform basic arithmetic operations on numbers. Normally these operations are only intended for use on integers. Some VHDL suites come with libraries which contain arithmetic functions for use with bit_vectors and std_logic vectors.&lt;br /&gt;
&lt;br /&gt;
The operators are:&lt;br /&gt;
* addition (+)&lt;br /&gt;
* subtraction (-)&lt;br /&gt;
* multiplication (*)&lt;br /&gt;
* division (/)&lt;br /&gt;
&lt;br /&gt;
The only caution that applies here is that some packages only support multiplication and division by integer powers of two. This in effect reduces multiplication and division to the status of arithmetic shift operations.&lt;br /&gt;
&lt;br /&gt;
== Comparison Operators ==&lt;br /&gt;
These operators are used to compare two scalar or bit_vector arguments and they return 'true ' or 'false'. If bit_vectors are compared then the vectors must be of the same length.&lt;br /&gt;
{|&lt;br /&gt;
| &amp;lt;&lt;br /&gt;
| smaller than&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= &lt;br /&gt;
| smaller than or equal&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt; &lt;br /&gt;
| greater than&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= &lt;br /&gt;
| greater than or equal&lt;br /&gt;
|-&lt;br /&gt;
| = &lt;br /&gt;
| equal&lt;br /&gt;
|-&lt;br /&gt;
| /= &lt;br /&gt;
|not equal&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Attributes of Objects =&lt;br /&gt;
Attributes are properties of VHDL types that can be very useful. We use attributes to extract further information about a VHDL object.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-AoO&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-AoO&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All attributes are accessed by using the apostrophe ' operator, sometimes pronounced “tick”. In theory attributes are classified by what sort of thing they return, but in authoritative sources (compare Ashenden 2008 to Perry 2002) they are dealt with in quite different ways. For purposes of this course we will be quite loose in our handling of attributes, aiming for utility rather than formal correctness.&lt;br /&gt;
&lt;br /&gt;
== Attributes of Signals ==&lt;br /&gt;
These attributes either derive information about signals or define new signals based on other signals. We have seen one of these already, the 'event attribute. This attribute creates a signal that is true when its base signal has changed in the last cycle. Examples have been shown above. There is also a 'last_value attribute which returns the value of a signal prior to its last transition.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
There are many more of these attributes, however many of them are for simulation purposes only and cannot be directly synthesized to hardware. These would typically be used for generating testbenches.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Attributes of Scalar Types ==&lt;br /&gt;
&lt;br /&gt;
'pos – str'pos (&amp;quot;fred&amp;quot;) gives the position of fred in the string str.   &lt;br /&gt;
&lt;br /&gt;
'val – Var'val(x) gives the value at position x of variable var.    &lt;br /&gt;
&lt;br /&gt;
'leftof – value in a variable to the left of a specified position.    &lt;br /&gt;
&lt;br /&gt;
'rightof – value in a variable to the right of a specified position.    &lt;br /&gt;
&lt;br /&gt;
'pred – value of a preceding position. Depends on range direction.    &lt;br /&gt;
&lt;br /&gt;
'succ – value of a succeeding position. Depends on range direction.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Note that not all of these attributes apply to all types. Most of the above are useful with enumerated types. If an array is declared with a range of indices from 10 to 30 then Array'left will return 10.&lt;br /&gt;
&lt;br /&gt;
Example:&lt;br /&gt;
Suppose we have the following declarations:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
lsb_output: OUT std_logic --declare a bit-wide port&lt;br /&gt;
signal count_signal_name : STD_LOGIC_VECTOR (3 downto 0); --declare a 4 bit wide signal&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the following line extracts the least significant bit from the signal and assigns it to the port:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
lsb_output &amp;lt;= count_signal_name (count_signal_name'right);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
This is useful for making procedures which handle arrays independently of the array width.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= More on Processes = &lt;br /&gt;
= Changing Execution Flow in VHDL = &lt;br /&gt;
= Dividing Big Jobs into Little Jobs = &lt;br /&gt;
= Packages = &lt;br /&gt;
= Conversion Functions =&lt;br /&gt;
= Megafunctions =&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=469</id>
		<title>VHDL</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=469"/>
		<updated>2021-01-28T10:53:40Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]][[Category:Software]]&lt;br /&gt;
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. &lt;br /&gt;
The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. [[File:VHDL Notes 2016 updated SamuelGinsberg.pdf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Structure and Behaviour =&lt;br /&gt;
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-StructureandBehaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-StructureandBehaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Structure&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Structure&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
The structure of a system describes that system in terms of &amp;quot;what is connected to what&amp;quot;. The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Behaviour ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Behaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Behaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entities ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Entities&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Entities&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
As we have mentioned an entity is a &amp;quot;box&amp;quot; with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity hadder is&lt;br /&gt;
    port&lt;br /&gt;
        (inA, inB  : in  std_logic;&lt;br /&gt;
         sum,carry : out std_logic); --note the semicolon&lt;br /&gt;
end hadder;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architectures ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Architectures&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Architectures&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.&lt;br /&gt;
&lt;br /&gt;
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
Here is an example of structural description:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
architecture structure of hadder is&lt;br /&gt;
--We now need to describe the interface to the components that we are&lt;br /&gt;
--using. These components are described in the ALTERA MAXPLUS2 library.&lt;br /&gt;
component a_7408 --AND gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
component a_7486 --XOR gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
--Signals are like wires used to connect components&lt;br /&gt;
signal inputA,inputB : std_logic;&lt;br /&gt;
begin&lt;br /&gt;
 --see equivalent diagram in notes to understand this.&lt;br /&gt;
 inputA&amp;lt;=inA;&lt;br /&gt;
 inputB&amp;lt;=inB;&lt;br /&gt;
 myAND: a_7408 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;carry);&lt;br /&gt;
 myXOR: a_7486 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;sum);&lt;br /&gt;
end structure;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal &amp;quot;wires&amp;quot; which connect components together. The signals are inputA and inputB.&lt;br /&gt;
&lt;br /&gt;
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Processes =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Processes&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Processes&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
We sometimes want a set of VHDL statements to execute sequentially, one after the other. This allows us to build up a set of instructions that are 'executed' one after the other. The execution of this list is triggered by some event happening, very often on a port of the entity.&lt;br /&gt;
&lt;br /&gt;
As an example consider this simple flip flop design:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
LIBRARY ieee;&lt;br /&gt;
USE ieee.std_logic_1164.all;&lt;br /&gt;
ENTITY test_proc1 IS&lt;br /&gt;
 PORT&lt;br /&gt;
 (D_input : IN STD_LOGIC;&lt;br /&gt;
 clk_input : IN STD_LOGIC;&lt;br /&gt;
 Q_output : OUT STD_LOGIC);&lt;br /&gt;
END test_proc1;&lt;br /&gt;
ARCHITECTURE a OF test_proc1 IS&lt;br /&gt;
BEGIN&lt;br /&gt;
 PROCESS (clk_input) --trigger this when clk_input changes&lt;br /&gt;
 BEGIN&lt;br /&gt;
 if (clk_input='1') then&lt;br /&gt;
 Q_output &amp;lt;= D_input;&lt;br /&gt;
 end if;&lt;br /&gt;
 END &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we are describing the behavior of a D type flip flop. The flip flop's D input is transferred to the Q output and held there on the rising edge of the clock signal.&lt;br /&gt;
We declare an entity as before.&lt;br /&gt;
&lt;br /&gt;
The architecture begins with the keyword 'Process' followed by a list of port names, in this case clk_input. This list is called a 'sensitivity list'. Whenever one (or more) of the items in the sensitivity list changes the code that is contained in the process is executed. In this example when clk_input changes, the code within the process is executed. This code examines the state of the clk_input bit and if it is high the Q output is updated to be equal to the D input. We achieve the rising edge triggered action by looking for a change in clk_input and then examining to see if the change was a rising or a falling edge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Variables&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Variables&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
It is possible to have variables in an architecture. Variables are used to store data within a process. Signals differ from variables in that variables cannot trigger events, nor can a change in a variable trigger a process. &lt;br /&gt;
&lt;br /&gt;
Furthermore, signal values within a process change only when the process is completed, whereas variables are evaluated immediately.&lt;br /&gt;
&lt;br /&gt;
Variables are modified with the variable assignment operator which is :=, thus assigning one variable to another is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
one_variable := another_variable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Syntax =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Syntax&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Syntax&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
== Comments ==&lt;br /&gt;
Comments are preceded by &amp;quot;--&amp;quot; (two dashes) and extend to the end of the line. Multiline comments are not available, but some code editors provide a multiline comment feature.&lt;br /&gt;
&lt;br /&gt;
== Identifiers ==&lt;br /&gt;
Identifiers are names of signals, variables, components etc. etc. The names must all begin with a letter. After the initial letter they may have any combination of letters, numbers and underscores. VHDL is not case sensitive.&lt;br /&gt;
&lt;br /&gt;
== Numbers ==&lt;br /&gt;
VHDL has support for a very wide range of number representations.&lt;br /&gt;
&lt;br /&gt;
Numbers may be in any base between 2 and 16. The hash (#) separator is used to separate the base from the rest of the number, by surrounding the number. e.g. 2#10101010# =10101010 base 2. Note that the base is an integer expressed in base 10.&lt;br /&gt;
&lt;br /&gt;
Real literals may have decimal points. These numbers are real numbers with a fixed fractional part. The VHDL standard supports floating point numbers although some VHDL compilers do not. Floating point operations are extremely expensive to implement because of the inefficiency incurred in synthesizing the floating point operations. e.g. 3.1415 is a fixed point real number.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember that VHDL only looks like a programming language. Bear in mind that when you use a floating point number the required operation has to be constructed out of gates when the design is put onto a chip. Numbers may have exponents. The exponents are expressed in decimal and may only be integers. Exponents may be positive or negative. The exponent is signified by an 'E'. The exponent is raised to the base. For example, a number expressed in base 2 will be multiplied by 2 to the power of the exponent.&lt;br /&gt;
&lt;br /&gt;
Example: 2#1010#E1=1010*2^1=10100=20 decimal.&lt;br /&gt;
&lt;br /&gt;
Here is an example of VHDL using integer types:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
  port (clock : In std_logic;&lt;br /&gt;
    sel : In std_logic;&lt;br /&gt;
    output: Out integer range 0 to 255);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
  begin&lt;br /&gt;
  process (clock)&lt;br /&gt;
  begin&lt;br /&gt;
     if clock='1' then&lt;br /&gt;
       if sel='1' then&lt;br /&gt;
         output&amp;lt;=16#55#;&lt;br /&gt;
       else&lt;br /&gt;
         output&amp;lt;=2#1010_1010#;&lt;br /&gt;
       end if;&lt;br /&gt;
     end if;&lt;br /&gt;
  end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Integer types are used for representing numbers with no fractional part. VHDL guarantees that integers will be represented by at least 32 bits. Integers are signed. We can limit the range of integers by using the range keyword. This is useful for limiting the size of the representation and for making your code more compiler independent. In general limit your range to the size that you need. When we limit the range of a type we obtain a &amp;lt;i&amp;gt;Subtype&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When limiting the range of an integer only the size of the representation is limited, not the actual range of the number. As an example if we said &amp;lt;code&amp;gt;dout: OUT integer range 0 to 2&amp;lt;/code&amp;gt; in the example above we would still have had a 2 bit counter. The code that could be represented on those 2 bits would still include “11”, even though it is outside of our defined range. Some simulation packages would flag a warning if this occurs, but many would not.&lt;br /&gt;
&lt;br /&gt;
When using an integer as a port, the port will have as many physical lines as are needed to represent the integer using standard binary coding. Thus, in the example above, 'dout' will be represented by two physical port lines.&lt;br /&gt;
&lt;br /&gt;
== Characters and Strings == &lt;br /&gt;
Characters are enclosed in single quotation marks and are equivalent to their ASCII number. e.g. '0'=48&lt;br /&gt;
&lt;br /&gt;
Strings are enclosed in double quotation marks. Example &amp;quot;Samuel&amp;quot; To include a double quotation mark inside quotation marks use it twice &amp;quot;Fred said&amp;quot;&amp;quot;hello&amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Strings may be formed in other number bases. These bases are binary, octal and hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 sel : In Std_logic;&lt;br /&gt;
 output: Out std_logic_vector (7 downto 0));&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if sel='1' then&lt;br /&gt;
     output&amp;lt;=&amp;quot;01010101&amp;quot;; --binary string. Use a string to fill vector&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=X&amp;quot;FF&amp;quot;; --Hexadecimal string&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enumerated Types ==&lt;br /&gt;
VHDL provides enumerated types for convenience. We have already come across one of these, std_logic, in which the logic states are represented as an enumerated type having nine different states which represent different electrical possibilities available on logic signals.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 output: Out integer range 0 to 1);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
type colour is (green, blue);&lt;br /&gt;
 --declare types in architecture declarative section&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
variable status: colour;&lt;br /&gt;
 --declare variables in process declarative section&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if status =green then&lt;br /&gt;
     output&amp;lt;=1;&lt;br /&gt;
     status:=blue;&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=0;&lt;br /&gt;
     status:=green;&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Arrays ==&lt;br /&gt;
These have the same meaning that you are used to. Arrays may have any number of dimensions and may be formed from any supported type, or previously defined type.&lt;br /&gt;
&lt;br /&gt;
There are predefined types, such as strings and bit vectors.&lt;br /&gt;
&lt;br /&gt;
The definition for the string type is given as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type string is array (positive range &amp;lt;&amp;gt;) of character;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The definition for bit vectors is as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type bit_vector is array (natural range &amp;lt;&amp;gt;) of bit;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;&amp;lt;&amp;gt;&amp;quot; angle brackets are called a box. They are placeholders which indicate that the range will be filled in when the types are used.&lt;br /&gt;
&lt;br /&gt;
Bit vectors are essentially an array of bits used for binary numbers. Here is an example of the usage of a bit&lt;br /&gt;
vector:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
din: in bit_vector (2 downto 0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this case the box will be filled in with the range 2 downto 0.&lt;br /&gt;
&lt;br /&gt;
Arrays may be indexed to access individual elements. If we wish to access the first bit in din then we can say:&lt;br /&gt;
&amp;lt;code&amp;gt;if din(2)='1' then....&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in the case of bit vectors when we specify the range we are specifying an array index. As a result, we are not specifying the numerical range, but rather the actual number of bits in the array.&lt;br /&gt;
&lt;br /&gt;
If we use the “downto” keyword then the most significant bit will occupy the highest numbered array position. The opposite will apply if we use the “to” keyword.&lt;br /&gt;
&lt;br /&gt;
We will not use bit vectors much, rather we will use 'standard logic vectors' which are more widely supported. The reason for this is that most of the libraries that are available for our VHDL system are defined in terms of standard logic vectors, rather than bit vectors. The behavior of std_logic_vectors is however very similar to the bit vector, except that, as noted above, std_logic has more possible states.&lt;br /&gt;
&lt;br /&gt;
See above for examples of std_logic_vector usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Operators =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Operators&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Operators&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Like any language VHDL has a set of operators. These operators may be divided into three types: Logical, arithmetic and comparison.&lt;br /&gt;
&lt;br /&gt;
== Logical Operators ==&lt;br /&gt;
Logical operators are used to derive logical results from bits and bit_vectors. When used with bit_vectors the operators act in a bitwise manner. When used with bit_vectors, those vectors must be of the same length.&lt;br /&gt;
The logical operators are as follows:&lt;br /&gt;
* NOT&lt;br /&gt;
* AND&lt;br /&gt;
* OR&lt;br /&gt;
* NAND&lt;br /&gt;
* NOR&lt;br /&gt;
* XOR&lt;br /&gt;
These should require no further explanation.&lt;br /&gt;
In addition there is a concatenation operator. This is the ampersand &amp;quot;&amp;amp;&amp;quot;. This concatenates two bit vectors.&lt;br /&gt;
Example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
signal a: bit_vector (1 to 3);&lt;br /&gt;
signal b: bit_vector (1 to 5);&lt;br /&gt;
signal c: bit_vector (1 to 8);&lt;br /&gt;
c &amp;lt;= a &amp;amp; b; --legal concatenation operation.&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Arithmetic Operators ==&lt;br /&gt;
These operators perform basic arithmetic operations on numbers. Normally these operations are only intended for use on integers. Some VHDL suites come with libraries which contain arithmetic functions for use with bit_vectors and std_logic vectors.&lt;br /&gt;
&lt;br /&gt;
The operators are:&lt;br /&gt;
* addition (+)&lt;br /&gt;
* subtraction (-)&lt;br /&gt;
* multiplication (*)&lt;br /&gt;
* division (/)&lt;br /&gt;
&lt;br /&gt;
The only caution that applies here is that some packages only support multiplication and division by integer powers of two. This in effect reduces multiplication and division to the status of arithmetic shift operations.&lt;br /&gt;
&lt;br /&gt;
== Comparison Operators ==&lt;br /&gt;
These operators are used to compare two scalar or bit_vector arguments and they return 'true ' or 'false'. If bit_vectors are compared then the vectors must be of the same length.&lt;br /&gt;
{|&lt;br /&gt;
| &amp;lt;&lt;br /&gt;
| smaller than&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;= &lt;br /&gt;
| smaller than or equal&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt; &lt;br /&gt;
| greater than&lt;br /&gt;
|-&lt;br /&gt;
| &amp;gt;= &lt;br /&gt;
| greater than or equal&lt;br /&gt;
|-&lt;br /&gt;
| = &lt;br /&gt;
| equal&lt;br /&gt;
|-&lt;br /&gt;
| /= &lt;br /&gt;
|not equal&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Attributes of Objects = &lt;br /&gt;
= More on Processes = &lt;br /&gt;
= Changing Execution Flow in VHDL = &lt;br /&gt;
= Dividing Big Jobs into Little Jobs = &lt;br /&gt;
= Packages = &lt;br /&gt;
= Conversion Functions =&lt;br /&gt;
= Megafunctions =&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=467</id>
		<title>VHDL</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=467"/>
		<updated>2021-01-27T14:51:16Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* VHDL Syntax */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]][[Category:Software]]&lt;br /&gt;
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. [[File:VHDL Notes 2016 updated SamuelGinsberg.pdf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Structure and Behaviour =&lt;br /&gt;
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-StructureandBehaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-StructureandBehaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Structure&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Structure&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
The structure of a system describes that system in terms of &amp;quot;what is connected to what&amp;quot;. The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Behaviour ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Behaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Behaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entities ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Entities&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Entities&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
As we have mentioned an entity is a &amp;quot;box&amp;quot; with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity hadder is&lt;br /&gt;
    port&lt;br /&gt;
        (inA, inB  : in  std_logic;&lt;br /&gt;
         sum,carry : out std_logic); --note the semicolon&lt;br /&gt;
end hadder;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architectures ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Architectures&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Architectures&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.&lt;br /&gt;
&lt;br /&gt;
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
Here is an example of structural description:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
architecture structure of hadder is&lt;br /&gt;
--We now need to describe the interface to the components that we are&lt;br /&gt;
--using. These components are described in the ALTERA MAXPLUS2 library.&lt;br /&gt;
component a_7408 --AND gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
component a_7486 --XOR gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
--Signals are like wires used to connect components&lt;br /&gt;
signal inputA,inputB : std_logic;&lt;br /&gt;
begin&lt;br /&gt;
 --see equivalent diagram in notes to understand this.&lt;br /&gt;
 inputA&amp;lt;=inA;&lt;br /&gt;
 inputB&amp;lt;=inB;&lt;br /&gt;
 myAND: a_7408 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;carry);&lt;br /&gt;
 myXOR: a_7486 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;sum);&lt;br /&gt;
end structure;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal &amp;quot;wires&amp;quot; which connect components together. The signals are inputA and inputB.&lt;br /&gt;
&lt;br /&gt;
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Processes =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Processes&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Processes&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
We sometimes want a set of VHDL statements to execute sequentially, one after the other. This allows us to build up a set of instructions that are 'executed' one after the other. The execution of this list is triggered by some event happening, very often on a port of the entity.&lt;br /&gt;
&lt;br /&gt;
As an example consider this simple flip flop design:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
LIBRARY ieee;&lt;br /&gt;
USE ieee.std_logic_1164.all;&lt;br /&gt;
ENTITY test_proc1 IS&lt;br /&gt;
 PORT&lt;br /&gt;
 (D_input : IN STD_LOGIC;&lt;br /&gt;
 clk_input : IN STD_LOGIC;&lt;br /&gt;
 Q_output : OUT STD_LOGIC);&lt;br /&gt;
END test_proc1;&lt;br /&gt;
ARCHITECTURE a OF test_proc1 IS&lt;br /&gt;
BEGIN&lt;br /&gt;
 PROCESS (clk_input) --trigger this when clk_input changes&lt;br /&gt;
 BEGIN&lt;br /&gt;
 if (clk_input='1') then&lt;br /&gt;
 Q_output &amp;lt;= D_input;&lt;br /&gt;
 end if;&lt;br /&gt;
 END &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we are describing the behavior of a D type flip flop. The flip flop's D input is transferred to the Q output and held there on the rising edge of the clock signal.&lt;br /&gt;
We declare an entity as before.&lt;br /&gt;
&lt;br /&gt;
The architecture begins with the keyword 'Process' followed by a list of port names, in this case clk_input. This list is called a 'sensitivity list'. Whenever one (or more) of the items in the sensitivity list changes the code that is contained in the process is executed. In this example when clk_input changes, the code within the process is executed. This code examines the state of the clk_input bit and if it is high the Q output is updated to be equal to the D input. We achieve the rising edge triggered action by looking for a change in clk_input and then examining to see if the change was a rising or a falling edge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Variables&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Variables&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
It is possible to have variables in an architecture. Variables are used to store data within a process. Signals differ from variables in that variables cannot trigger events, nor can a change in a variable trigger a process. &lt;br /&gt;
&lt;br /&gt;
Furthermore, signal values within a process change only when the process is completed, whereas variables are evaluated immediately.&lt;br /&gt;
&lt;br /&gt;
Variables are modified with the variable assignment operator which is :=, thus assigning one variable to another is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
one_variable := another_variable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Syntax =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Syntax&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Syntax&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
== Comments ==&lt;br /&gt;
Comments are preceded by &amp;quot;--&amp;quot; (two dashes) and extend to the end of the line. Multiline comments are not available, but some code editors provide a multiline comment feature.&lt;br /&gt;
&lt;br /&gt;
== Identifiers ==&lt;br /&gt;
Identifiers are names of signals, variables, components etc. etc. The names must all begin with a letter. After the initial letter they may have any combination of letters, numbers and underscores. VHDL is not case sensitive.&lt;br /&gt;
&lt;br /&gt;
== Numbers ==&lt;br /&gt;
VHDL has support for a very wide range of number representations.&lt;br /&gt;
&lt;br /&gt;
Numbers may be in any base between 2 and 16. The hash (#) separator is used to separate the base from the rest of the number, by surrounding the number. e.g. 2#10101010# =10101010 base 2. Note that the base is an integer expressed in base 10.&lt;br /&gt;
&lt;br /&gt;
Real literals may have decimal points. These numbers are real numbers with a fixed fractional part. The VHDL standard supports floating point numbers although some VHDL compilers do not. Floating point operations are extremely expensive to implement because of the inefficiency incurred in synthesizing the floating point operations. e.g. 3.1415 is a fixed point real number.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Remember that VHDL only looks like a programming language. Bear in mind that when you use a floating point number the required operation has to be constructed out of gates when the design is put onto a chip. Numbers may have exponents. The exponents are expressed in decimal and may only be integers. Exponents may be positive or negative. The exponent is signified by an 'E'. The exponent is raised to the base. For example, a number expressed in base 2 will be multiplied by 2 to the power of the exponent.&lt;br /&gt;
&lt;br /&gt;
Example: 2#1010#E1=1010*2^1=10100=20 decimal.&lt;br /&gt;
&lt;br /&gt;
Here is an example of VHDL using integer types:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
  port (clock : In std_logic;&lt;br /&gt;
    sel : In std_logic;&lt;br /&gt;
    output: Out integer range 0 to 255);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
  begin&lt;br /&gt;
  process (clock)&lt;br /&gt;
  begin&lt;br /&gt;
     if clock='1' then&lt;br /&gt;
       if sel='1' then&lt;br /&gt;
         output&amp;lt;=16#55#;&lt;br /&gt;
       else&lt;br /&gt;
         output&amp;lt;=2#1010_1010#;&lt;br /&gt;
       end if;&lt;br /&gt;
     end if;&lt;br /&gt;
  end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Integer types are used for representing numbers with no fractional part. VHDL guarantees that integers will be represented by at least 32 bits. Integers are signed. We can limit the range of integers by using the range keyword. This is useful for limiting the size of the representation and for making your code more compiler independent. In general limit your range to the size that you need. When we limit the range of a type we obtain a &amp;lt;i&amp;gt;Subtype&amp;lt;/i&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
When limiting the range of an integer only the size of the representation is limited, not the actual range of the number. As an example if we said &amp;lt;code&amp;gt;dout: OUT integer range 0 to 2&amp;lt;/code&amp;gt; in the example above we would still have had a 2 bit counter. The code that could be represented on those 2 bits would still include “11”, even though it is outside of our defined range. Some simulation packages would flag a warning if this occurs, but many would not.&lt;br /&gt;
&lt;br /&gt;
When using an integer as a port, the port will have as many physical lines as are needed to represent the integer using standard binary coding. Thus, in the example above, 'dout' will be represented by two physical port lines.&lt;br /&gt;
&lt;br /&gt;
== Characters and Strings == &lt;br /&gt;
Characters are enclosed in single quotation marks and are equivalent to their ASCII number. e.g. '0'=48&lt;br /&gt;
&lt;br /&gt;
Strings are enclosed in double quotation marks. Example &amp;quot;Samuel&amp;quot; To include a double quotation mark inside quotation marks use it twice &amp;quot;Fred said&amp;quot;&amp;quot;hello&amp;quot;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
Strings may be formed in other number bases. These bases are binary, octal and hex.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 sel : In Std_logic;&lt;br /&gt;
 output: Out std_logic_vector (7 downto 0));&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if sel='1' then&lt;br /&gt;
     output&amp;lt;=&amp;quot;01010101&amp;quot;; --binary string. Use a string to fill vector&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=X&amp;quot;FF&amp;quot;; --Hexadecimal string&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Enumerated Types ==&lt;br /&gt;
VHDL provides enumerated types for convenience. We have already come across one of these, std_logic, in which the logic states are represented as an enumerated type having nine different states which represent different electrical possibilities available on logic signals.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity Code_Example is&lt;br /&gt;
port (clock : In std_logic;&lt;br /&gt;
 output: Out integer range 0 to 1);&lt;br /&gt;
end Code_Example;&lt;br /&gt;
architecture archy of Code_Example is&lt;br /&gt;
type colour is (green, blue);&lt;br /&gt;
 --declare types in architecture declarative section&lt;br /&gt;
begin&lt;br /&gt;
process (clock)&lt;br /&gt;
variable status: colour;&lt;br /&gt;
 --declare variables in process declarative section&lt;br /&gt;
begin&lt;br /&gt;
 if clock='1' then&lt;br /&gt;
   if status =green then&lt;br /&gt;
     output&amp;lt;=1;&lt;br /&gt;
     status:=blue;&lt;br /&gt;
   else&lt;br /&gt;
     output&amp;lt;=0;&lt;br /&gt;
     status:=green;&lt;br /&gt;
   end if;&lt;br /&gt;
 end if;&lt;br /&gt;
end process;&lt;br /&gt;
end archy;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Arrays ==&lt;br /&gt;
These have the same meaning that you are used to. Arrays may have any number of dimensions and may be formed from any supported type, or previously defined type.&lt;br /&gt;
&lt;br /&gt;
There are predefined types, such as strings and bit vectors.&lt;br /&gt;
&lt;br /&gt;
The definition for the string type is given as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type string is array (positive range &amp;lt;&amp;gt;) of character;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The definition for bit vectors is as follows:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
type bit_vector is array (natural range &amp;lt;&amp;gt;) of bit;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;&amp;lt;&amp;gt;&amp;quot; angle brackets are called a box. They are placeholders which indicate that the range will be filled in when the types are used.&lt;br /&gt;
&lt;br /&gt;
Bit vectors are essentially an array of bits used for binary numbers. Here is an example of the usage of a bit&lt;br /&gt;
vector:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot;&amp;gt;&lt;br /&gt;
din: in bit_vector (2 downto 0);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
In this case the box will be filled in with the range 2 downto 0.&lt;br /&gt;
&lt;br /&gt;
Arrays may be indexed to access individual elements. If we wish to access the first bit in din then we can say:&lt;br /&gt;
&amp;lt;code&amp;gt;if din(2)='1' then....&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that in the case of bit vectors when we specify the range we are specifying an array index. As a result, we are not specifying the numerical range, but rather the actual number of bits in the array.&lt;br /&gt;
&lt;br /&gt;
If we use the “downto” keyword then the most significant bit will occupy the highest numbered array position. The opposite will apply if we use the “to” keyword.&lt;br /&gt;
&lt;br /&gt;
We will not use bit vectors much, rather we will use 'standard logic vectors' which are more widely supported. The reason for this is that most of the libraries that are available for our VHDL system are defined in terms of standard logic vectors, rather than bit vectors. The behavior of std_logic_vectors is however very similar to the bit vector, except that, as noted above, std_logic has more possible states.&lt;br /&gt;
&lt;br /&gt;
See above for examples of std_logic_vector usage.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Operators = &lt;br /&gt;
= Attributes of Objects = &lt;br /&gt;
= More on Processes = &lt;br /&gt;
= Changing Execution Flow in VHDL = &lt;br /&gt;
= Dividing Big Jobs into Little Jobs = &lt;br /&gt;
= Packages = &lt;br /&gt;
= Conversion Functions =&lt;br /&gt;
= Megafunctions =&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=466</id>
		<title>VHDL</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=466"/>
		<updated>2021-01-27T14:39:15Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]][[Category:Software]]&lt;br /&gt;
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. [[File:VHDL Notes 2016 updated SamuelGinsberg.pdf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Structure and Behaviour =&lt;br /&gt;
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-StructureandBehaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-StructureandBehaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Structure&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Structure&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
The structure of a system describes that system in terms of &amp;quot;what is connected to what&amp;quot;. The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Behaviour ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Behaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Behaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entities ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Entities&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Entities&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
As we have mentioned an entity is a &amp;quot;box&amp;quot; with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity hadder is&lt;br /&gt;
    port&lt;br /&gt;
        (inA, inB  : in  std_logic;&lt;br /&gt;
         sum,carry : out std_logic); --note the semicolon&lt;br /&gt;
end hadder;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architectures ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Architectures&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Architectures&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.&lt;br /&gt;
&lt;br /&gt;
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
Here is an example of structural description:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
architecture structure of hadder is&lt;br /&gt;
--We now need to describe the interface to the components that we are&lt;br /&gt;
--using. These components are described in the ALTERA MAXPLUS2 library.&lt;br /&gt;
component a_7408 --AND gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
component a_7486 --XOR gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
--Signals are like wires used to connect components&lt;br /&gt;
signal inputA,inputB : std_logic;&lt;br /&gt;
begin&lt;br /&gt;
 --see equivalent diagram in notes to understand this.&lt;br /&gt;
 inputA&amp;lt;=inA;&lt;br /&gt;
 inputB&amp;lt;=inB;&lt;br /&gt;
 myAND: a_7408 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;carry);&lt;br /&gt;
 myXOR: a_7486 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;sum);&lt;br /&gt;
end structure;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal &amp;quot;wires&amp;quot; which connect components together. The signals are inputA and inputB.&lt;br /&gt;
&lt;br /&gt;
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Processes =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Processes&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Processes&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
We sometimes want a set of VHDL statements to execute sequentially, one after the other. This allows us to build up a set of instructions that are 'executed' one after the other. The execution of this list is triggered by some event happening, very often on a port of the entity.&lt;br /&gt;
&lt;br /&gt;
As an example consider this simple flip flop design:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
LIBRARY ieee;&lt;br /&gt;
USE ieee.std_logic_1164.all;&lt;br /&gt;
ENTITY test_proc1 IS&lt;br /&gt;
 PORT&lt;br /&gt;
 (D_input : IN STD_LOGIC;&lt;br /&gt;
 clk_input : IN STD_LOGIC;&lt;br /&gt;
 Q_output : OUT STD_LOGIC);&lt;br /&gt;
END test_proc1;&lt;br /&gt;
ARCHITECTURE a OF test_proc1 IS&lt;br /&gt;
BEGIN&lt;br /&gt;
 PROCESS (clk_input) --trigger this when clk_input changes&lt;br /&gt;
 BEGIN&lt;br /&gt;
 if (clk_input='1') then&lt;br /&gt;
 Q_output &amp;lt;= D_input;&lt;br /&gt;
 end if;&lt;br /&gt;
 END &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we are describing the behavior of a D type flip flop. The flip flop's D input is transferred to the Q output and held there on the rising edge of the clock signal.&lt;br /&gt;
We declare an entity as before.&lt;br /&gt;
&lt;br /&gt;
The architecture begins with the keyword 'Process' followed by a list of port names, in this case clk_input. This list is called a 'sensitivity list'. Whenever one (or more) of the items in the sensitivity list changes the code that is contained in the process is executed. In this example when clk_input changes, the code within the process is executed. This code examines the state of the clk_input bit and if it is high the Q output is updated to be equal to the D input. We achieve the rising edge triggered action by looking for a change in clk_input and then examining to see if the change was a rising or a falling edge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Variables&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Variables&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
It is possible to have variables in an architecture. Variables are used to store data within a process. Signals differ from variables in that variables cannot trigger events, nor can a change in a variable trigger a process. &lt;br /&gt;
&lt;br /&gt;
Furthermore, signal values within a process change only when the process is completed, whereas variables are evaluated immediately.&lt;br /&gt;
&lt;br /&gt;
Variables are modified with the variable assignment operator which is :=, thus assigning one variable to another is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
one_variable := another_variable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Syntax = &lt;br /&gt;
= VHDL Operators = &lt;br /&gt;
= Attributes of Objects = &lt;br /&gt;
= More on Processes = &lt;br /&gt;
= Changing Execution Flow in VHDL = &lt;br /&gt;
= Dividing Big Jobs into Little Jobs = &lt;br /&gt;
= Packages = &lt;br /&gt;
= Conversion Functions =&lt;br /&gt;
= Megafunctions =&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=465</id>
		<title>VHDL</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=465"/>
		<updated>2021-01-27T14:39:00Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]][[Category:Software]]&lt;br /&gt;
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. [[File:VHDL Notes 2016 updated SamuelGinsberg.pdf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Structure and Behaviour =&lt;br /&gt;
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-StructureandBehaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-StructureandBehaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Structure&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Structure&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
The structure of a system describes that system in terms of &amp;quot;what is connected to what&amp;quot;. The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Behaviour ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Behaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Behaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entities ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Entities&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Entities&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
As we have mentioned an entity is a &amp;quot;box&amp;quot; with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity hadder is&lt;br /&gt;
    port&lt;br /&gt;
        (inA, inB  : in  std_logic;&lt;br /&gt;
         sum,carry : out std_logic); --note the semicolon&lt;br /&gt;
end hadder;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architectures ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Architectures&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Architectures&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.&lt;br /&gt;
&lt;br /&gt;
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
Here is an example of structural description:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
architecture structure of hadder is&lt;br /&gt;
--We now need to describe the interface to the components that we are&lt;br /&gt;
--using. These components are described in the ALTERA MAXPLUS2 library.&lt;br /&gt;
component a_7408 --AND gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
component a_7486 --XOR gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
--Signals are like wires used to connect components&lt;br /&gt;
signal inputA,inputB : std_logic;&lt;br /&gt;
begin&lt;br /&gt;
 --see equivalent diagram in notes to understand this.&lt;br /&gt;
 inputA&amp;lt;=inA;&lt;br /&gt;
 inputB&amp;lt;=inB;&lt;br /&gt;
 myAND: a_7408 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;carry);&lt;br /&gt;
 myXOR: a_7486 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;sum);&lt;br /&gt;
end structure;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal &amp;quot;wires&amp;quot; which connect components together. The signals are inputA and inputB.&lt;br /&gt;
&lt;br /&gt;
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Processes =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Processes&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Processes&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
We sometimes want a set of VHDL statements to execute sequentially, one after the other. This allows us to build up a set of instructions that are 'executed' one after the other. The execution of this list is triggered by some event happening, very often on a port of the entity.&lt;br /&gt;
&lt;br /&gt;
As an example consider this simple flip flop design:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
LIBRARY ieee;&lt;br /&gt;
USE ieee.std_logic_1164.all;&lt;br /&gt;
ENTITY test_proc1 IS&lt;br /&gt;
 PORT&lt;br /&gt;
 (D_input : IN STD_LOGIC;&lt;br /&gt;
 clk_input : IN STD_LOGIC;&lt;br /&gt;
 Q_output : OUT STD_LOGIC);&lt;br /&gt;
END test_proc1;&lt;br /&gt;
ARCHITECTURE a OF test_proc1 IS&lt;br /&gt;
BEGIN&lt;br /&gt;
 PROCESS (clk_input) --trigger this when clk_input changes&lt;br /&gt;
 BEGIN&lt;br /&gt;
 if (clk_input='1') then&lt;br /&gt;
 Q_output &amp;lt;= D_input;&lt;br /&gt;
 end if;&lt;br /&gt;
 END &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we are describing the behavior of a D type flip flop. The flip flop's D input is transferred to the Q output and held there on the rising edge of the clock signal.&lt;br /&gt;
We declare an entity as before.&lt;br /&gt;
&lt;br /&gt;
The architecture begins with the keyword 'Process' followed by a list of port names, in this case clk_input. This list is called a 'sensitivity list'. Whenever one (or more) of the items in the sensitivity list changes the code that is contained in the process is executed. In this example when clk_input changes, the code within the process is executed. This code examines the state of the clk_input bit and if it is high the Q output is updated to be equal to the D input. We achieve the rising edge triggered action by looking for a change in clk_input and then examining to see if the change was a rising or a falling edge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Variables&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Variables&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
It is possible to have variables in an architecture. Variables are used to store data within a process. Signals differ from variables in that variables cannot trigger events, nor can a change in a variable trigger a process. &lt;br /&gt;
&lt;br /&gt;
Furthermore, signal values within a process change only when the process is completed, whereas variables are evaluated immediately.&lt;br /&gt;
&lt;br /&gt;
Variables are modified with the variable assignment operator which is :=, thus assigning one variable to another is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
one_variable := another_variable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Syntax = &lt;br /&gt;
= VHDL Operators = &lt;br /&gt;
= Attributes of Objects = &lt;br /&gt;
= More on Processes = &lt;br /&gt;
= Changing Execution Flow in VHDL = &lt;br /&gt;
= Dividing Big Jobs into Little Jobs = &lt;br /&gt;
= Packages = &lt;br /&gt;
= Conversion Functions =&lt;br /&gt;
= Megafunctions =&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=464</id>
		<title>VHDL</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=VHDL&amp;diff=464"/>
		<updated>2021-01-27T14:37:32Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]][[Category:Software]]&lt;br /&gt;
VHDL stands for VHSIC-HDL, which in turn stands for Very High Speed Integrated Circuit Hardware Description Language. It is one way in which hardware can be described. The guide below was adapted by notes originally written by Samuel Ginsberg, which can be downloaded as a PDF here. [[File:VHDL Notes 2016 updated SamuelGinsberg.pdf]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Structure and Behaviour =&lt;br /&gt;
There are two fundamentally different ways of specifying logic. The first method is to specify the structure of the logic and the other method is to specify the behaviour of the system.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-StructureandBehaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-StructureandBehaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Structure&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Structure&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
The structure of a system describes that system in terms of &amp;quot;what is connected to what&amp;quot;. The system is thus broken down into smaller units which are connected together to form a whole. The whole unit is called an entity. Inputs and outputs to/from the entity are called ports.&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
In this illustration the overall entity is called Z. The input ports are called A, B and C. The output ports are called D and E. The interconnections inside the entity Z are called signals. You will observe that X and Y are themselves entities. The entities X and Y would in turn have to be specified in terms of either their behaviour or their structure. This nested definition system implies that by using structural descriptions very big and complex blocks may be built up out of a number of simple blocks. This is fundamental to problem solving of almost any type.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Behaviour ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Behaviour&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Behaviour&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
You will see that structural descriptions are extremely useful for building systems from smaller components. Ultimately we need to specify what each component actually does. In this case structural descriptions are of limited use. We need some way of describing the behaviour of the entities that we use. At the very minimum we need to specify the behaviour of the entities at the bottom of the hierarchical structure. VHDL thus provides a means of specifying the behaviour of entities by means of a behavioural description. Behavioural descriptions resemble a programming language. We will discuss syntax as we need it to implement the concepts that follow. Please bear in mind as we go that, despite the similarities, a VHDL description is a hardware description, and that the analogy to a programming language is actually fairly weak.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Entities ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Entities&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Entities&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
As we have mentioned an entity is a &amp;quot;box&amp;quot; with inputs and outputs called ports. We need to give the ports names and associate them with an entity. Here is an example of this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
entity hadder is&lt;br /&gt;
    port&lt;br /&gt;
        (inA, inB  : in  std_logic;&lt;br /&gt;
         sum,carry : out std_logic); --note the semicolon&lt;br /&gt;
end hadder;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This entity declaration states that we are creating an entity called hadder. This entity has two inputs called inA and inB and two outputs called sum and carry. Further we have declared that the ports are all 'std_logic' values. A std_logic value is basically a binary bit, which can take on the value 0 and 1. Std_logic bits can also take on a few other states, such as high impedance and undefined, in order to closely model the behaviour of real logic bits. The entity is shown graphically here:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Architectures ==&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Architectures&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Architectures&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once we have declared the entity we need to describe how it works. We use an architecture to do this. We could use either a structural description or a behavioural one.&lt;br /&gt;
&lt;br /&gt;
Suppose for the sake of the illustration that the above entity implements a half adder. Our adder's circuit diagram is as follows:&lt;br /&gt;
&lt;br /&gt;
TODO: IMAGE&lt;br /&gt;
&lt;br /&gt;
Here is an example of structural description:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
architecture structure of hadder is&lt;br /&gt;
--We now need to describe the interface to the components that we are&lt;br /&gt;
--using. These components are described in the ALTERA MAXPLUS2 library.&lt;br /&gt;
component a_7408 --AND gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
component a_7486 --XOR gate&lt;br /&gt;
 port (a_2: in STD_LOGIC;&lt;br /&gt;
 a_3: in STD_LOGIC;&lt;br /&gt;
 a_1: out STD_LOGIC);&lt;br /&gt;
end component;&lt;br /&gt;
--Signals are like wires used to connect components&lt;br /&gt;
signal inputA,inputB : std_logic;&lt;br /&gt;
begin&lt;br /&gt;
 --see equivalent diagram in notes to understand this.&lt;br /&gt;
 inputA&amp;lt;=inA;&lt;br /&gt;
 inputB&amp;lt;=inB;&lt;br /&gt;
 myAND: a_7408 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;carry);&lt;br /&gt;
 myXOR: a_7486 port map (a_2=&amp;gt;inputA,a_3=&amp;gt;inputB,a_1=&amp;gt;sum);&lt;br /&gt;
end structure;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first thing that we do is state which components are contained in our box. These are an AND gate and an XOR gate. We also define the ports of these components. Note that the components were created previously and we are only using them here. We then define two signals. These signals are the internal &amp;quot;wires&amp;quot; which connect components together. The signals are inputA and inputB.&lt;br /&gt;
&lt;br /&gt;
After we have defined all of the types of things that go into our description we need to instantiate them. We do that in the next section of code. We make an instance of the AND gate called myAND and an instance of the XOR gate called myXOR. When we instantiate the components we list how the inputs are connected to the signals. This effectively creates a netlist. A netlist is a list of how components connect together. The first two statements connect the internal signals inputA and inputB to the input ports, as shown in the circuit diagram.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Processes =&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Processes&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Processes&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
We sometimes want a set of VHDL statements to execute sequentially, one after the other. This allows us to build up a set of instructions that are 'executed' one after the other. The execution of this list is triggered by some event happening, very often on a port of the entity.&lt;br /&gt;
&lt;br /&gt;
As an example consider this simple flip flop design:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
LIBRARY ieee;&lt;br /&gt;
USE ieee.std_logic_1164.all;&lt;br /&gt;
ENTITY test_proc1 IS&lt;br /&gt;
 PORT&lt;br /&gt;
 (D_input : IN STD_LOGIC;&lt;br /&gt;
 clk_input : IN STD_LOGIC;&lt;br /&gt;
 Q_output : OUT STD_LOGIC);&lt;br /&gt;
END test_proc1;&lt;br /&gt;
ARCHITECTURE a OF test_proc1 IS&lt;br /&gt;
BEGIN&lt;br /&gt;
 PROCESS (clk_input) --trigger this when clk_input changes&lt;br /&gt;
 BEGIN&lt;br /&gt;
 if (clk_input='1') then&lt;br /&gt;
 Q_output &amp;lt;= D_input;&lt;br /&gt;
 end if;&lt;br /&gt;
 END &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example we are describing the behavior of a D type flip flop. The flip flop's D input is transferred to the Q output and held there on the rising edge of the clock signal.&lt;br /&gt;
We declare an entity as before.&lt;br /&gt;
&lt;br /&gt;
The architecture begins with the keyword 'Process' followed by a list of port names, in this case clk_input. This list is called a 'sensitivity list'. Whenever one (or more) of the items in the sensitivity list changes the code that is contained in the process is executed. In this example when clk_input changes, the code within the process is executed. This code examines the state of the clk_input bit and if it is high the Q output is updated to be equal to the D input. We achieve the rising edge triggered action by looking for a change in clk_input and then examining to see if the change was a rising or a falling edge.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Variables =&lt;br /&gt;
It is possible to have variables in an architecture. Variables are used to store data within a process. Signals differ from variables in that variables cannot trigger events, nor can a change in a variable trigger a process. &lt;br /&gt;
&lt;br /&gt;
Furthermore, signal values within a process change only when the process is completed, whereas variables are evaluated immediately.&lt;br /&gt;
&lt;br /&gt;
Variables are modified with the variable assignment operator which is :=, thus assigning one variable to another is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;vhdl&amp;quot; line='line'&amp;gt;&lt;br /&gt;
one_variable := another_variable;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= VHDL Syntax = &lt;br /&gt;
= VHDL Operators = &lt;br /&gt;
= Attributes of Objects = &lt;br /&gt;
= More on Processes = &lt;br /&gt;
= Changing Execution Flow in VHDL = &lt;br /&gt;
= Dividing Big Jobs into Little Jobs = &lt;br /&gt;
= Packages = &lt;br /&gt;
= Conversion Functions =&lt;br /&gt;
= Megafunctions =&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=453</id>
		<title>RaspberryPi:ProgrammingInPython</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=453"/>
		<updated>2020-10-28T06:03:38Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Using Threads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Most of the content in the guide comes from the documentation, available online [https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ here].&lt;br /&gt;
&lt;br /&gt;
Python, while not as powerful as C or C++, is quickly becoming a common choice for embedded systems developers due to its ease of use and rapid development times. See [https://spectrum.ieee.org/at-work/innovation/the-2018-top-programming-languages this IEEE article]. For information on programming in C or C++, go to [[RaspberryPi:ProgrammingInC]].&lt;br /&gt;
&lt;br /&gt;
This chapter serves as a short guide for programming in Python on the RPi. You will also find some templates for techniques such as debouncing, or making use of the Raspberry Pi’s multicore architecture by implementing threading.&lt;br /&gt;
&lt;br /&gt;
= The RPI.GPIO Library =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library is the common Python library used on the Raspberry Pi. Documentation for the library can be found here:&amp;lt;br /&amp;gt;&lt;br /&gt;
https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/&lt;br /&gt;
&lt;br /&gt;
It is included in the environment variables by default, so to use it, you can simply just import it into your Python script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import RPi.GPIO as GPIO&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You need to specify which board mode you’re using. For more information on board modes, see Section [[RaspberryPi:Overview#GPIO_Pins]]. Board modes are specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setmode(GPIO.BCM)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You also need to perform “cleanup” on GPIOs when your application exists. By performing cleanup and resetting all pins to their default modes, you can prevent possible damage to your Raspberry Pi. The cleanup function is called as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If your program is meant to run indefinitely, and only close upon an exception, you can wrap it in a try catch, as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    # Make sure the GPIO is stopped correctly&lt;br /&gt;
    try:&lt;br /&gt;
        while True:&lt;br /&gt;
            main()&lt;br /&gt;
    except KeyboardInterrupt:&lt;br /&gt;
        print(&amp;quot;Exiting gracefully&amp;quot;)&lt;br /&gt;
        GPIO.cleanup()&lt;br /&gt;
    except e:&lt;br /&gt;
        print(&amp;quot;Some other error occurred: {}&amp;quot;.format(e.message)})&lt;br /&gt;
        GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Basic IO =&lt;br /&gt;
&lt;br /&gt;
Read the documentation, available [https://sourceforge.net/p/raspberry-gpio-python/wiki/Outputs/ here].&lt;br /&gt;
&lt;br /&gt;
== Digital Logic ==&lt;br /&gt;
&lt;br /&gt;
Digital output on the Raspberry Pi is accomplished by writing values to channels. A channel is a pin, which is numbered in the way you’ve configured. Basic configuration of a pin for output is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(&amp;lt;channel&amp;gt;, &amp;lt;Logic&amp;gt;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your logic (high, 3.3V, or low, 0V), can be specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 3.3V (high) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.HIGH)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 1)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, True)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 0V (low) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.LOW)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 0)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, False)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Channels can also be specified in lists, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;LEDs = (11,12)&lt;br /&gt;
GPIO.output(LEDs, GPIO.HIGH) # Will turn all channels HIGH&lt;br /&gt;
GPIO.output(LEDs, (GPIO.HIGH, GPIO.LOW)) # Will the first channel HIGH, and the second LOW&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you can also read the state of the pin/channel that is set as an output by using the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function. For example, if you wanted to toggle pin 12, you could do something as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(12, not GPIO.input(12))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Analog ==&lt;br /&gt;
&lt;br /&gt;
The Raspberry Pi does not have any analog input pins. You will need to use something like the [https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf MCP3008] to read analog voltages.&lt;br /&gt;
&lt;br /&gt;
== Inputs ==&lt;br /&gt;
&lt;br /&gt;
=== Digital Read ===&lt;br /&gt;
&lt;br /&gt;
To read the value of a digital pin, you can use the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if GPIO.input(12):&lt;br /&gt;
    print(&amp;quot;Pin 12 HIGH&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;quot;Pin 12 LOW&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Pull Up/Pull Down Resistors ===&lt;br /&gt;
&lt;br /&gt;
Using pull up and pull down resistors is essential when working with digital logic. Thankfully, the Raspberry Pi has internal pull up and pull down resistors. To make use of these, initialize the pin/channel as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_UP)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Interrupts ===&lt;br /&gt;
&lt;br /&gt;
Very often it is useful to set up an interrupt, for example to trigger an event when a button is pressed. Callback functions are executed on a different thread. If you have multiple callbacks, know that they will be executed sequentially as only one thread exists for interrupts. Interrupts can be implemented as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# The bounce time is given in milliseconds.&lt;br /&gt;
# If your pin is set to use pull down resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and 3.3V&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.RISING, callback=callback_method(), bouncetime=200)&lt;br /&gt;
# If your pin is set to use pull up resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and GND&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.FALLING, callback=callback_method(), bouncetime=200)  &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Other functions ===&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO Library offers other functions for interrupts the first is the &amp;lt;code&amp;gt;wait_for_edge()&amp;lt;/code&amp;gt; function, which is designed to block execution until an edge is detected. You can detect edges of &amp;lt;code&amp;gt;GPIO.RISING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GPIO.FALLING&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;GPIO.BOTH&amp;lt;/code&amp;gt;. The timeout is given in milliseconds:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# wait for up to 5 seconds for a rising edge&lt;br /&gt;
edge = GPIO.wait_for_edge(&amp;lt;channel&amp;gt;, GPIO_RISING, timeout=5000)&lt;br /&gt;
if edge is None:&lt;br /&gt;
    print('Timeout occurred')&lt;br /&gt;
else:&lt;br /&gt;
    print('Edge detected on pin &amp;lt;CHANNEL&amp;gt;')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another function is the &amp;lt;code&amp;gt;event_detected()&amp;lt;/code&amp;gt; function. From the docs: “The event_detected() function is designed to be used in a loop with other things, but unlike polling it is not going to miss the change in state of an input while the CPU is busy working on other things. This could be useful when using something like Pygame or PyQt where there is a main loop listening and responding to GUI events in a timely basis.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.add_event_detect(channel, GPIO.RISING)  # add rising edge detection on a channel&lt;br /&gt;
if GPIO.event_detected(channel):&lt;br /&gt;
    print('Button pressed')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Communication Protocols =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library has no native support for communication protocols. Very often, specific Python libraries are provided on a per-device use case. However, this can become tedious and cause your code to become bloated. See the sections below for relevant libraries for using I2C and SPI directly.&lt;br /&gt;
&lt;br /&gt;
== I2C ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable I2C in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To use I2C in Python, you can use the &amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; library. To do this, we need to install and configure smbus. This is usually done by default, but instructions are included for posterity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get install i2c-tools&lt;br /&gt;
$ sudo apt-get install python-smbus&lt;br /&gt;
$ sudo adduser &amp;amp;lt;username&amp;amp;gt; i2c&lt;br /&gt;
$ sudo reboot&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you connect a device, you can run &amp;lt;code&amp;gt;$gpio i2cdetect&amp;lt;/code&amp;gt; to determine if a device is detected on the I2C bus. In the example below, there is an electronic compass (GY-271) connected to the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:I2cdetect.png|frame|none|alt=|An i2cdetect example]]&lt;br /&gt;
&lt;br /&gt;
To initialize an I2C device, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import smbus&lt;br /&gt;
i2cdevice = smbus.SMBus(1) # 1 indicates /dev/i2c-1&lt;br /&gt;
address = 0x1e #whatever the device is for your i2c device&amp;lt;/pre&amp;gt;&lt;br /&gt;
To read a byte from the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;result = i2cdevice.read_byte_data(address, &amp;amp;lt;register&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
To write a byte to the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;i2cdevice.write_byte_data(address, &amp;amp;lt;register&amp;amp;gt;, &amp;amp;lt;value&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Methods Available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; has multiple methods. The documentation for these is quite minimal, but brief descriptions are available [http://wiki.erazor-zone.de/wiki:linux:python:smbus:doc here].&lt;br /&gt;
&lt;br /&gt;
Note: If you're working with EEPROM (specifically 24C32), you may need to read the answer to the questions given [https://www.raspberrypi.org/forums/viewtopic.php?p=1401819&amp;amp;sid=582cace49dad59d93f4e0369047dd89d#p1401819 here].&lt;br /&gt;
&lt;br /&gt;
== SPI ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable SPI in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can use SPI in Python by using the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library. Documentation is available [https://pypi.org/project/spidev/ here]. Basic usage is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import spidev&lt;br /&gt;
&lt;br /&gt;
#Bus is 0 or 1, depending on which SPI bus you've connected to&lt;br /&gt;
bus = 0&lt;br /&gt;
#Device is the chip select pin. Set to 0 or 1, depending on the connections&lt;br /&gt;
device = 1&lt;br /&gt;
&lt;br /&gt;
spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.open(bus, device) #Open connection to a specific bus and device (CS pin)&lt;br /&gt;
&lt;br /&gt;
# Set settings (SPI speed and mode)&lt;br /&gt;
spi.max_speed_hz = 500000&lt;br /&gt;
spi.mode = 0&lt;br /&gt;
&lt;br /&gt;
to_send = [0x01, 0x02, 0x03] #define what to send&lt;br /&gt;
spi.xfer(to_send)&lt;br /&gt;
&lt;br /&gt;
# Close the SPI connection&lt;br /&gt;
close()&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Settings ===&lt;br /&gt;
&lt;br /&gt;
The following settings are configurable in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library, and can be set as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.&amp;amp;lt;setting&amp;amp;gt; = &amp;amp;lt;value&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
List of settings:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;bits_per_word&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;cs_high&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;loop&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_LOOP” flag to enable loopback mode&lt;br /&gt;
* &amp;lt;code&amp;gt;no_cs&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_NO_CS” flag to disable use of the chip select (although the driver may still own the CS pin)&lt;br /&gt;
* &amp;lt;code&amp;gt;lsbfirst&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_speed_hz&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;mode&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SPI mode as two bit pattern of clock polarity and phase [CPOL/CPHA], min: 0b00 = 0, max: 0b11 = 3&lt;br /&gt;
* &amp;lt;code&amp;gt;threewire&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SI/SO signals shared&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are available in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;open(bus, device)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Connects to the specified SPI device, opening &amp;lt;code&amp;gt;/dev/spidev&amp;amp;lt;bus&amp;amp;gt;.&amp;amp;lt;device&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;readbytes(n)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Read n bytes from SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;writebytes(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Writes a list of values to SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt;writebytes2(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to ‘writebytes‘ but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations. Also, writebytes2 understands [https://docs.python.org/3/c-api/buffer.html buffer protocol] so it can accept numpy byte arrays for example without need to convert them with &amp;lt;code&amp;gt;tolist()&amp;lt;/code&amp;gt; first. This offers much better performance where you need to transfer frames to SPI-connected displays for instance.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer2(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be held active between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer3(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to xfer2 but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Disconnects from the SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Threads =&lt;br /&gt;
&lt;br /&gt;
[https://realpython.com/intro-to-python-threading/ This guide] serves as the basis for the text below. This manual does not teach everything there is to know about threading in Python, but will give you the basics to be able to utilize threads for simple tasks that may be of use to you in the practicals. It’s strongly recommended you read through that text if you have not yet been exposed to threading concepts.&lt;br /&gt;
&lt;br /&gt;
This text does not cover issues and precautions when working with threads, such as mutex’s and locks, data races, producer/consumer concerns and the likes. However, these are knowledge areas of critical importance, and it is strongly suggested that the reader tries to make an effort to understand these concerns before writing threaded code.&lt;br /&gt;
&lt;br /&gt;
== The Threading Library ==&lt;br /&gt;
&lt;br /&gt;
The Python library &amp;lt;code&amp;gt;threading&amp;lt;/code&amp;gt; library offers all the functionality one would expect. Import it in to your code in the standard way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are 4 basic things you need to do when creating a thread:&lt;br /&gt;
&lt;br /&gt;
# Initialize it&lt;br /&gt;
# Start it&lt;br /&gt;
# Let is execute&lt;br /&gt;
# “Shut it down” by joining&lt;br /&gt;
&lt;br /&gt;
== Basic Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
For example, if you want to create a separate thread to fetch a sensor value five times, you could do it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line='line'&amp;gt;import threading&lt;br /&gt;
import time&lt;br /&gt;
import RPi.GPIO as GPIO&lt;br /&gt;
&lt;br /&gt;
def setup():&lt;br /&gt;
    #Contains all code for initialisation of RPi.GPIO&lt;br /&gt;
&lt;br /&gt;
def fetch_sensor_vals(sensor_pin):&lt;br /&gt;
    for i in range(5):&lt;br /&gt;
        GPIO.input(sensor_pin)&lt;br /&gt;
        time.sleep(2)&lt;br /&gt;
    &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    setup()&lt;br /&gt;
    # Create a thread to call the function and pass &amp;quot;12&amp;quot; in as sensor pin&lt;br /&gt;
    x = threading.Thread(target=fetch_sensor_vals, args=(12,)) &lt;br /&gt;
    print(&amp;quot;Starting thread&amp;quot;)&lt;br /&gt;
    x.start()&lt;br /&gt;
    print(&amp;quot;Waiting for the thread to finish&amp;quot;)&lt;br /&gt;
    x.join()&lt;br /&gt;
    print(&amp;quot;Reading finished&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Timed Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
Often in embedded systems we want a specific task to run every X time units. There is an option in the Python threading library. It works as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line='line'&amp;gt;import threading&lt;br /&gt;
import datetime&lt;br /&gt;
&lt;br /&gt;
def print_time_thread():&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    This function prints the time to the screen every five seconds&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    thread = threading.Timer(5.0, print_time_thread)&lt;br /&gt;
    thread.daemon = True  # Daemon threads exit when the program does&lt;br /&gt;
    thread.start()&lt;br /&gt;
    print(datetime.datetime.now())&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    print_time_thread() # call it once to start the thread&lt;br /&gt;
    &lt;br /&gt;
    # Tell our program to run indefinitely&lt;br /&gt;
    while True:&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see that in this code example, we have also set the &amp;lt;code&amp;gt;daemon&amp;lt;/code&amp;gt; flag of the thread to be be &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. A daemon thread will shut down immediately when the program exits. In essence, the daemon thread will run indefinitely in the background until your application exits, and you do not need to worry about calling &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;It’s important to note that calling t.join() will wait for a thread to finish executing, even if it is a daemon.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=449</id>
		<title>RaspberryPi:ProgrammingInPython</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=449"/>
		<updated>2020-09-22T12:00:42Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Timed Thread Usage */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Most of the content in the guide comes from the documentation, available online [https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ here].&lt;br /&gt;
&lt;br /&gt;
Python, while not as powerful as C or C++, is quickly becoming a common choice for embedded systems developers due to its ease of use and rapid development times. See [https://spectrum.ieee.org/at-work/innovation/the-2018-top-programming-languages this IEEE article]. For information on programming in C or C++, go to [[RaspberryPi:ProgrammingInC]].&lt;br /&gt;
&lt;br /&gt;
This chapter serves as a short guide for programming in Python on the RPi. You will also find some templates for techniques such as debouncing, or making use of the Raspberry Pi’s multicore architecture by implementing threading.&lt;br /&gt;
&lt;br /&gt;
= The RPI.GPIO Library =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library is the common Python library used on the Raspberry Pi. Documentation for the library can be found here:&amp;lt;br /&amp;gt;&lt;br /&gt;
https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/&lt;br /&gt;
&lt;br /&gt;
It is included in the environment variables by default, so to use it, you can simply just import it into your Python script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;include RPi.GPIO as GPIO&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You need to specify which board mode you’re using. For more information on board modes, see Section [[RaspberryPi:Overview#GPIO_Pins]]. Board modes are specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setmode(GPIO.BCM)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You also need to perform “cleanup” on GPIOs when your application exists. By performing cleanup and resetting all pins to their default modes, you can prevent possible damage to your Raspberry Pi. The cleanup function is called as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If your program is meant to run indefinitely, and only close upon an exception, you can wrap it in a try catch, as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    # Make sure the GPIO is stopped correctly&lt;br /&gt;
    try:&lt;br /&gt;
        while True:&lt;br /&gt;
            main()&lt;br /&gt;
    except KeyboardInterrupt:&lt;br /&gt;
        print(&amp;quot;Exiting gracefully&amp;quot;)&lt;br /&gt;
        GPIO.cleanup()&lt;br /&gt;
    except e:&lt;br /&gt;
        print(&amp;quot;Some other error occurred: {}&amp;quot;.format(e.message)})&lt;br /&gt;
        GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Basic IO =&lt;br /&gt;
&lt;br /&gt;
Read the documentation, available [https://sourceforge.net/p/raspberry-gpio-python/wiki/Outputs/ here].&lt;br /&gt;
&lt;br /&gt;
== Digital Logic ==&lt;br /&gt;
&lt;br /&gt;
Digital output on the Raspberry Pi is accomplished by writing values to channels. A channel is a pin, which is numbered in the way you’ve configured. Basic configuration of a pin for output is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(&amp;lt;channel&amp;gt;, &amp;lt;Logic&amp;gt;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your logic (high, 3.3V, or low, 0V), can be specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 3.3V (high) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.HIGH)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 1)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, True)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 0V (low) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.LOW)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 0)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, False)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Channels can also be specified in lists, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;LEDs = (11,12)&lt;br /&gt;
GPIO.output(LEDs, GPIO.HIGH) # Will turn all channels HIGH&lt;br /&gt;
GPIO.output(LEDs, (GPIO.HIGH, GPIO.LOW)) # Will the first channel HIGH, and the second LOW&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you can also read the state of the pin/channel that is set as an output by using the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function. For example, if you wanted to toggle pin 12, you could do something as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(12, not GPIO.input(12))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Analog ==&lt;br /&gt;
&lt;br /&gt;
The Raspberry Pi does not have any analog input pins. You will need to use something like the [https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf MCP3008] to read analog voltages.&lt;br /&gt;
&lt;br /&gt;
== Inputs ==&lt;br /&gt;
&lt;br /&gt;
=== Digital Read ===&lt;br /&gt;
&lt;br /&gt;
To read the value of a digital pin, you can use the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if GPIO.input(12):&lt;br /&gt;
    print(&amp;quot;Pin 12 HIGH&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;quot;Pin 12 LOW&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Pull Up/Pull Down Resistors ===&lt;br /&gt;
&lt;br /&gt;
Using pull up and pull down resistors is essential when working with digital logic. Thankfully, the Raspberry Pi has internal pull up and pull down resistors. To make use of these, initialize the pin/channel as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_UP)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Interrupts ===&lt;br /&gt;
&lt;br /&gt;
Very often it is useful to set up an interrupt, for example to trigger an event when a button is pressed. Callback functions are executed on a different thread. If you have multiple callbacks, know that they will be executed sequentially as only one thread exists for interrupts. Interrupts can be implemented as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# The bounce time is given in milliseconds.&lt;br /&gt;
# If your pin is set to use pull down resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and 3.3V&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.RISING, callback=callback_method(), bouncetime=200)&lt;br /&gt;
# If your pin is set to use pull up resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and GND&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.FALLING, callback=callback_method(), bouncetime=200)  &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Other functions ===&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO Library offers other functions for interrupts the first is the &amp;lt;code&amp;gt;wait_for_edge()&amp;lt;/code&amp;gt; function, which is designed to block execution until an edge is detected. You can detect edges of &amp;lt;code&amp;gt;GPIO.RISING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GPIO.FALLING&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;GPIO.BOTH&amp;lt;/code&amp;gt;. The timeout is given in milliseconds:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# wait for up to 5 seconds for a rising edge&lt;br /&gt;
edge = GPIO.wait_for_edge(&amp;lt;channel&amp;gt;, GPIO_RISING, timeout=5000)&lt;br /&gt;
if edge is None:&lt;br /&gt;
    print('Timeout occurred')&lt;br /&gt;
else:&lt;br /&gt;
    print('Edge detected on pin &amp;lt;CHANNEL&amp;gt;')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another function is the &amp;lt;code&amp;gt;event_detected()&amp;lt;/code&amp;gt; function. From the docs: “The event_detected() function is designed to be used in a loop with other things, but unlike polling it is not going to miss the change in state of an input while the CPU is busy working on other things. This could be useful when using something like Pygame or PyQt where there is a main loop listening and responding to GUI events in a timely basis.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.add_event_detect(channel, GPIO.RISING)  # add rising edge detection on a channel&lt;br /&gt;
if GPIO.event_detected(channel):&lt;br /&gt;
    print('Button pressed')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Communication Protocols =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library has no native support for communication protocols. Very often, specific Python libraries are provided on a per-device use case. However, this can become tedious and cause your code to become bloated. See the sections below for relevant libraries for using I2C and SPI directly.&lt;br /&gt;
&lt;br /&gt;
== I2C ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable I2C in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To use I2C in Python, you can use the &amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; library. To do this, we need to install and configure smbus. This is usually done by default, but instructions are included for posterity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get install i2c-tools&lt;br /&gt;
$ sudo apt-get install python-smbus&lt;br /&gt;
$ sudo adduser &amp;amp;lt;username&amp;amp;gt; i2c&lt;br /&gt;
$ sudo reboot&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you connect a device, you can run &amp;lt;code&amp;gt;$gpio i2cdetect&amp;lt;/code&amp;gt; to determine if a device is detected on the I2C bus. In the example below, there is an electronic compass (GY-271) connected to the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:I2cdetect.png|frame|none|alt=|An i2cdetect example]]&lt;br /&gt;
&lt;br /&gt;
To initialize an I2C device, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import smbus&lt;br /&gt;
i2cdevice = smbus.SMBus(1) # 1 indicates /dev/i2c-1&lt;br /&gt;
address = 0x1e #whatever the device is for your i2c device&amp;lt;/pre&amp;gt;&lt;br /&gt;
To read a byte from the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;result = i2cdevice.read_byte_data(address, &amp;amp;lt;register&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
To write a byte to the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;i2cdevice.write_byte_data(address, &amp;amp;lt;register&amp;amp;gt;, &amp;amp;lt;value&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Methods Available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; has multiple methods. The documentation for these is quite minimal, but brief descriptions are available [http://wiki.erazor-zone.de/wiki:linux:python:smbus:doc here].&lt;br /&gt;
&lt;br /&gt;
Note: If you're working with EEPROM (specifically 24C32), you may need to read the answer to the questions given [https://www.raspberrypi.org/forums/viewtopic.php?p=1401819&amp;amp;sid=582cace49dad59d93f4e0369047dd89d#p1401819 here].&lt;br /&gt;
&lt;br /&gt;
== SPI ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable SPI in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can use SPI in Python by using the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library. Documentation is available [https://pypi.org/project/spidev/ here]. Basic usage is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import spidev&lt;br /&gt;
&lt;br /&gt;
#Bus is 0 or 1, depending on which SPI bus you've connected to&lt;br /&gt;
bus = 0&lt;br /&gt;
#Device is the chip select pin. Set to 0 or 1, depending on the connections&lt;br /&gt;
device = 1&lt;br /&gt;
&lt;br /&gt;
spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.open(bus, device) #Open connection to a specific bus and device (CS pin)&lt;br /&gt;
&lt;br /&gt;
# Set settings (SPI speed and mode)&lt;br /&gt;
spi.max_speed_hz = 500000&lt;br /&gt;
spi.mode = 0&lt;br /&gt;
&lt;br /&gt;
to_send = [0x01, 0x02, 0x03] #define what to send&lt;br /&gt;
spi.xfer(to_send)&lt;br /&gt;
&lt;br /&gt;
# Close the SPI connection&lt;br /&gt;
close()&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Settings ===&lt;br /&gt;
&lt;br /&gt;
The following settings are configurable in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library, and can be set as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.&amp;amp;lt;setting&amp;amp;gt; = &amp;amp;lt;value&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
List of settings:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;bits_per_word&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;cs_high&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;loop&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_LOOP” flag to enable loopback mode&lt;br /&gt;
* &amp;lt;code&amp;gt;no_cs&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_NO_CS” flag to disable use of the chip select (although the driver may still own the CS pin)&lt;br /&gt;
* &amp;lt;code&amp;gt;lsbfirst&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_speed_hz&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;mode&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SPI mode as two bit pattern of clock polarity and phase [CPOL/CPHA], min: 0b00 = 0, max: 0b11 = 3&lt;br /&gt;
* &amp;lt;code&amp;gt;threewire&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SI/SO signals shared&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are available in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;open(bus, device)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Connects to the specified SPI device, opening &amp;lt;code&amp;gt;/dev/spidev&amp;amp;lt;bus&amp;amp;gt;.&amp;amp;lt;device&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;readbytes(n)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Read n bytes from SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;writebytes(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Writes a list of values to SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt;writebytes2(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to ‘writebytes‘ but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations. Also, writebytes2 understands [https://docs.python.org/3/c-api/buffer.html buffer protocol] so it can accept numpy byte arrays for example without need to convert them with &amp;lt;code&amp;gt;tolist()&amp;lt;/code&amp;gt; first. This offers much better performance where you need to transfer frames to SPI-connected displays for instance.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer2(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be held active between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer3(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to xfer2 but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Disconnects from the SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Threads =&lt;br /&gt;
&lt;br /&gt;
[https://realpython.com/intro-to-python-threading/ This guide] serves as the basis for the text below. This manual does not teach everything there is to know about threading in Python, but will give you the basics to be able to utilize threads for simple tasks that may be of use to you in the practicals. It’s strongly recommended you read through that text if you have not yet been exposed to threading concepts.&lt;br /&gt;
&lt;br /&gt;
This text does not cover issues and precautions when working with threads, such as mutex’s and locks, data races, producer/consumer concerns and the likes. However, these are knowledge areas of critical importance, and it is strongly suggested that the reader tries to make an effort to understand these concerns before writing threaded code.&lt;br /&gt;
&lt;br /&gt;
== The Threading Library ==&lt;br /&gt;
&lt;br /&gt;
The Python library &amp;lt;code&amp;gt;threading&amp;lt;/code&amp;gt; library offers all the functionality one would expect. Import it in to your code in the standard way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are 4 basic things you need to do when creating a thread:&lt;br /&gt;
&lt;br /&gt;
# Initialize it&lt;br /&gt;
# Start it&lt;br /&gt;
# Let is execute&lt;br /&gt;
# “Shut it down” by joining&lt;br /&gt;
&lt;br /&gt;
== Basic Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
For example, if you want to create a separate thread to fetch a sensor value five times, you could do it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&lt;br /&gt;
import time&lt;br /&gt;
import RPi.GPIO as GPIO&lt;br /&gt;
&lt;br /&gt;
def setup():&lt;br /&gt;
    #Contains all code for initialisation of RPi.GPIO&lt;br /&gt;
&lt;br /&gt;
def fetch_sensor_vals(sensor_pin):&lt;br /&gt;
    for i in range(5):&lt;br /&gt;
        GPIO.input(sensor_pin)&lt;br /&gt;
        time.sleep(2)&lt;br /&gt;
    &lt;br /&gt;
if __name__ == &amp;amp;quot;__main__&amp;amp;quot;:&lt;br /&gt;
    setup()&lt;br /&gt;
    # Create a thread to call the function and pass &amp;amp;quot;12&amp;amp;quot; in as sensor pin&lt;br /&gt;
    x = threading.Thread(target=fetch_sensor_vals, args=(12,)) &lt;br /&gt;
    print(&amp;amp;quot;Starting thread&amp;amp;quot;)&lt;br /&gt;
    x.start()&lt;br /&gt;
    print(&amp;amp;quot;Waiting for the thread to finish&amp;amp;quot;)&lt;br /&gt;
    x.join()&lt;br /&gt;
    print(&amp;amp;quot;Reading finished&amp;amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Timed Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
Often in embedded systems we want a specific task to run every X time units. There is an option in the Python threading library. It works as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot; line='line'&amp;gt;import threading&lt;br /&gt;
import datetime&lt;br /&gt;
&lt;br /&gt;
def print_time_thread():&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    This function prints the time to the screen every five seconds&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    thread = threading.Timer(5.0, print_time_thread)&lt;br /&gt;
    thread.daemon = True  # Daemon threads exit when the program does&lt;br /&gt;
    thread.start()&lt;br /&gt;
    print(datetime.datetime.now())&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    print_time_thread() # call it once to start the thread&lt;br /&gt;
    &lt;br /&gt;
    # Tell our program to run indefinitely&lt;br /&gt;
    while True:&lt;br /&gt;
        pass&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You will see that in this code example, we have also set the &amp;lt;code&amp;gt;daemon&amp;lt;/code&amp;gt; flag of the thread to be be &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. A daemon thread will shut down immediately when the program exits. In essence, the daemon thread will run indefinitely in the background until your application exits, and you do not need to worry about calling &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;It’s important to note that calling t.join() will wait for a thread to finish executing, even if it is a daemon.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=448</id>
		<title>RaspberryPi:DebuggingConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=448"/>
		<updated>2020-09-15T07:51:41Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Ubuntu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Debugging Connections =&lt;br /&gt;
&lt;br /&gt;
This section is a work in progress. As more common issues are reported by students, this section will be expanded. It's important to note that most connectivity problems come down to an incorrectly configured file, where you may have missed a space, or misspelled something.&lt;br /&gt;
&lt;br /&gt;
= Note for Windows Users =&lt;br /&gt;
&lt;br /&gt;
If you are having trouble accessing the internet from your Pi using the Ethernet Passthrough technique, it’s likely the Windows bridge needs a reset. Change the IPv4 address of your Ethernet port to “Obtain an IP address automatically”, then on your WiFi connection, disable sharing, click okay, and then re-enable sharing. Go back to the IP configuration of your Ethernet post, and double check the IP to see if it’s been assigned 192.168.137.1. If not, you will need to change it using the “Advanced settings” button.&lt;br /&gt;
&lt;br /&gt;
= Ping = &lt;br /&gt;
''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. &lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall. &lt;br /&gt;
&lt;br /&gt;
= WiFi =&lt;br /&gt;
&lt;br /&gt;
See if you can see wireless networks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ iwlist wlan0 scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you cannot connect via WiFi, enter into a shell on the Pi and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ journalctl -u wpa_supplicant | grep wlan0&lt;br /&gt;
$ journalctl -u dhcpcd.service | grep wlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will output the log files and notify you of any incorrect configurations in wpa_supplicant.&lt;br /&gt;
&lt;br /&gt;
The following command will force the interface to be up (if it can be):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo ifconfig wlan0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
If all else fails, reboot and try again. Some services can be restarted without restarting the Pi, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test wpa_supplicant config by killing the process, and running it in debug mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo killall wpa_supplicant&lt;br /&gt;
sudo /sbin/wpa_supplicant -d -c/etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211,wext -iwlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;quot;Failure resolving URLs&amp;quot; or &amp;quot;unknown host&amp;quot; =&lt;br /&gt;
&lt;br /&gt;
If you try to ping a website from the Pi and it fails, but pinging a IP such as 8.8.8.8 works as expected, it is likely an issue with DNS configuration. Open the resolv.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/resolv.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit it to read the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;nameserver 8.8.8.8&lt;br /&gt;
nameserver 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
8.8.8.8 is the IP of Google’s DNS server. A DNS (Domain Name Service) server is responsible for converting human-readable addressed (for example google.co.za) to something the network architecture can understand (172.217.170.67, in this example).&lt;br /&gt;
&lt;br /&gt;
If you still get this error, try running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo route add default gw 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where the IP supplied is the IP of the computer or router you are connected to.&lt;br /&gt;
&lt;br /&gt;
= SSH'ing Into the Pi 0/0W =&lt;br /&gt;
This section assumes you've correctly modified the SD card contents using the correct editor, and are using the correct USB port on the Pi.&lt;br /&gt;
== Windows ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open up device manager by pressing the Windows key and X and selecting &amp;quot;Device Manager&amp;quot; from the drop down&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If you have no other USB to Ethernet Gadgets plugged in, and you see this, it means your Pi is connected correctly and you need to double check you've installed Bonjour and are connecting to the correct hostname. &lt;br /&gt;
[[File:RNDISWithCorrectDrivers.png|none|left]]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If the device manager is constantly &amp;quot;flashing&amp;quot; after giving the Pi enough time to boot, it means there isn't enough power delivery to the Pi. This is only really a problem on older systems. To resolve this issue, add an additional connection from the &amp;quot;power&amp;quot; USB port to something that can provide additional current, like a cellphone charger, or even just another USB port.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If under &amp;quot;Universal Serial Bus controllers&amp;quot; you see something like &amp;quot;Unknown USB Device (Device Descriptor Failed)&amp;quot;, it means the driver is not installed. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RNDISDriverNotInstalled.png|none|left]]&lt;br /&gt;
To install the driver, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on the &amp;quot;Unknown USB Device&amp;quot; and uninstall the driver.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unplug the Pi from your computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Download the RNDIS drivers here: [[Media:Mod-duo-rndis.zip|Windows 10 RNDIS Drivers]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Extract the contents&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on &amp;quot;RNDIS.inf&amp;quot; and select &amp;quot;install&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Plug in the Raspberry Pi again, it should be picked up as a USB Ethernet Device under &amp;quot;Network Adapters&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ubuntu ==&lt;br /&gt;
Some Ubuntu systems are unable to perform the IP lookup based on the hostname. &lt;br /&gt;
Follow the instructions [https://askubuntu.com/questions/992388/ubuntu-avahi-daemon-cannot-find-raspberrypi-local/1010785#1010785 here] to connect.&lt;br /&gt;
&lt;br /&gt;
The instructions above were converted into a script. Before running the script, you need to set IPv6 of the Pi's ethernet connection to link-local only, and get the name of the interface using &amp;lt;code&amp;gt;ifconfig&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The script is as follows:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
set -e&lt;br /&gt;
echo &amp;quot;Ensure you've set IPv6 to link local only&amp;quot;&lt;br /&gt;
echo &amp;quot;Ensure you know the interface on which the Pi is located&amp;quot;&lt;br /&gt;
echo &amp;quot;Use the ifconfig command to get the interface. Often 'usb0'&amp;quot;&lt;br /&gt;
echo &amp;quot;Trying to resolve raspberrypi.local&amp;quot;&lt;br /&gt;
resolved=`avahi-resolve-host-name raspberrypi.local`&lt;br /&gt;
piIP=`echo $resolved | cut -c 19-128`&lt;br /&gt;
echo &amp;quot;Please enter in the USB interface&amp;quot;&lt;br /&gt;
read interface&lt;br /&gt;
echo &amp;quot;Attempting to SSH into pi@$piIP%$interface&amp;quot;&lt;br /&gt;
ssh pi@$piIP%$interface&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Once you've connected, it's suggest you connect to a wifi network to be able to SSH in using &amp;quot;pi@raspberrypi.local&amp;quot;, or set a static IP on the USB port and use the same subnet on the network created on the PC when you plug in the Pi.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=447</id>
		<title>RaspberryPi:DebuggingConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=447"/>
		<updated>2020-09-14T10:01:06Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Ubuntu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Debugging Connections =&lt;br /&gt;
&lt;br /&gt;
This section is a work in progress. As more common issues are reported by students, this section will be expanded. It's important to note that most connectivity problems come down to an incorrectly configured file, where you may have missed a space, or misspelled something.&lt;br /&gt;
&lt;br /&gt;
= Note for Windows Users =&lt;br /&gt;
&lt;br /&gt;
If you are having trouble accessing the internet from your Pi using the Ethernet Passthrough technique, it’s likely the Windows bridge needs a reset. Change the IPv4 address of your Ethernet port to “Obtain an IP address automatically”, then on your WiFi connection, disable sharing, click okay, and then re-enable sharing. Go back to the IP configuration of your Ethernet post, and double check the IP to see if it’s been assigned 192.168.137.1. If not, you will need to change it using the “Advanced settings” button.&lt;br /&gt;
&lt;br /&gt;
= Ping = &lt;br /&gt;
''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. &lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall. &lt;br /&gt;
&lt;br /&gt;
= WiFi =&lt;br /&gt;
&lt;br /&gt;
See if you can see wireless networks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ iwlist wlan0 scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you cannot connect via WiFi, enter into a shell on the Pi and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ journalctl -u wpa_supplicant | grep wlan0&lt;br /&gt;
$ journalctl -u dhcpcd.service | grep wlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will output the log files and notify you of any incorrect configurations in wpa_supplicant.&lt;br /&gt;
&lt;br /&gt;
The following command will force the interface to be up (if it can be):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo ifconfig wlan0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
If all else fails, reboot and try again. Some services can be restarted without restarting the Pi, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test wpa_supplicant config by killing the process, and running it in debug mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo killall wpa_supplicant&lt;br /&gt;
sudo /sbin/wpa_supplicant -d -c/etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211,wext -iwlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;quot;Failure resolving URLs&amp;quot; or &amp;quot;unknown host&amp;quot; =&lt;br /&gt;
&lt;br /&gt;
If you try to ping a website from the Pi and it fails, but pinging a IP such as 8.8.8.8 works as expected, it is likely an issue with DNS configuration. Open the resolv.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/resolv.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit it to read the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;nameserver 8.8.8.8&lt;br /&gt;
nameserver 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
8.8.8.8 is the IP of Google’s DNS server. A DNS (Domain Name Service) server is responsible for converting human-readable addressed (for example google.co.za) to something the network architecture can understand (172.217.170.67, in this example).&lt;br /&gt;
&lt;br /&gt;
If you still get this error, try running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo route add default gw 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where the IP supplied is the IP of the computer or router you are connected to.&lt;br /&gt;
&lt;br /&gt;
= SSH'ing Into the Pi 0/0W =&lt;br /&gt;
This section assumes you've correctly modified the SD card contents using the correct editor, and are using the correct USB port on the Pi.&lt;br /&gt;
== Windows ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open up device manager by pressing the Windows key and X and selecting &amp;quot;Device Manager&amp;quot; from the drop down&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If you have no other USB to Ethernet Gadgets plugged in, and you see this, it means your Pi is connected correctly and you need to double check you've installed Bonjour and are connecting to the correct hostname. &lt;br /&gt;
[[File:RNDISWithCorrectDrivers.png|none|left]]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If the device manager is constantly &amp;quot;flashing&amp;quot; after giving the Pi enough time to boot, it means there isn't enough power delivery to the Pi. This is only really a problem on older systems. To resolve this issue, add an additional connection from the &amp;quot;power&amp;quot; USB port to something that can provide additional current, like a cellphone charger, or even just another USB port.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If under &amp;quot;Universal Serial Bus controllers&amp;quot; you see something like &amp;quot;Unknown USB Device (Device Descriptor Failed)&amp;quot;, it means the driver is not installed. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RNDISDriverNotInstalled.png|none|left]]&lt;br /&gt;
To install the driver, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on the &amp;quot;Unknown USB Device&amp;quot; and uninstall the driver.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unplug the Pi from your computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Download the RNDIS drivers here: [[Media:Mod-duo-rndis.zip|Windows 10 RNDIS Drivers]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Extract the contents&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on &amp;quot;RNDIS.inf&amp;quot; and select &amp;quot;install&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Plug in the Raspberry Pi again, it should be picked up as a USB Ethernet Device under &amp;quot;Network Adapters&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ubuntu ==&lt;br /&gt;
Some Ubuntu systems are unable to perform the IP lookup based on the hostname. &lt;br /&gt;
Follow the instructions [https://askubuntu.com/questions/992388/ubuntu-avahi-daemon-cannot-find-raspberrypi-local/1010785#1010785 here] to connect.&lt;br /&gt;
&lt;br /&gt;
Once you've connected, it's suggest you connect to a wifi network to be able to SSH in using &amp;quot;pi@raspberrypi.local&amp;quot;, or set a static IP on the USB port and use the same subnet on the network created on the PC when you plug in the Pi.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=446</id>
		<title>RaspberryPi:DebuggingConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=446"/>
		<updated>2020-09-14T10:00:51Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Ubuntu */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Debugging Connections =&lt;br /&gt;
&lt;br /&gt;
This section is a work in progress. As more common issues are reported by students, this section will be expanded. It's important to note that most connectivity problems come down to an incorrectly configured file, where you may have missed a space, or misspelled something.&lt;br /&gt;
&lt;br /&gt;
= Note for Windows Users =&lt;br /&gt;
&lt;br /&gt;
If you are having trouble accessing the internet from your Pi using the Ethernet Passthrough technique, it’s likely the Windows bridge needs a reset. Change the IPv4 address of your Ethernet port to “Obtain an IP address automatically”, then on your WiFi connection, disable sharing, click okay, and then re-enable sharing. Go back to the IP configuration of your Ethernet post, and double check the IP to see if it’s been assigned 192.168.137.1. If not, you will need to change it using the “Advanced settings” button.&lt;br /&gt;
&lt;br /&gt;
= Ping = &lt;br /&gt;
''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. &lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall. &lt;br /&gt;
&lt;br /&gt;
= WiFi =&lt;br /&gt;
&lt;br /&gt;
See if you can see wireless networks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ iwlist wlan0 scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you cannot connect via WiFi, enter into a shell on the Pi and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ journalctl -u wpa_supplicant | grep wlan0&lt;br /&gt;
$ journalctl -u dhcpcd.service | grep wlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will output the log files and notify you of any incorrect configurations in wpa_supplicant.&lt;br /&gt;
&lt;br /&gt;
The following command will force the interface to be up (if it can be):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo ifconfig wlan0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
If all else fails, reboot and try again. Some services can be restarted without restarting the Pi, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test wpa_supplicant config by killing the process, and running it in debug mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo killall wpa_supplicant&lt;br /&gt;
sudo /sbin/wpa_supplicant -d -c/etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211,wext -iwlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;quot;Failure resolving URLs&amp;quot; or &amp;quot;unknown host&amp;quot; =&lt;br /&gt;
&lt;br /&gt;
If you try to ping a website from the Pi and it fails, but pinging a IP such as 8.8.8.8 works as expected, it is likely an issue with DNS configuration. Open the resolv.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/resolv.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit it to read the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;nameserver 8.8.8.8&lt;br /&gt;
nameserver 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
8.8.8.8 is the IP of Google’s DNS server. A DNS (Domain Name Service) server is responsible for converting human-readable addressed (for example google.co.za) to something the network architecture can understand (172.217.170.67, in this example).&lt;br /&gt;
&lt;br /&gt;
If you still get this error, try running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo route add default gw 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where the IP supplied is the IP of the computer or router you are connected to.&lt;br /&gt;
&lt;br /&gt;
= SSH'ing Into the Pi 0/0W =&lt;br /&gt;
This section assumes you've correctly modified the SD card contents using the correct editor, and are using the correct USB port on the Pi.&lt;br /&gt;
== Windows ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open up device manager by pressing the Windows key and X and selecting &amp;quot;Device Manager&amp;quot; from the drop down&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If you have no other USB to Ethernet Gadgets plugged in, and you see this, it means your Pi is connected correctly and you need to double check you've installed Bonjour and are connecting to the correct hostname. &lt;br /&gt;
[[File:RNDISWithCorrectDrivers.png|none|left]]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If the device manager is constantly &amp;quot;flashing&amp;quot; after giving the Pi enough time to boot, it means there isn't enough power delivery to the Pi. This is only really a problem on older systems. To resolve this issue, add an additional connection from the &amp;quot;power&amp;quot; USB port to something that can provide additional current, like a cellphone charger, or even just another USB port.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If under &amp;quot;Universal Serial Bus controllers&amp;quot; you see something like &amp;quot;Unknown USB Device (Device Descriptor Failed)&amp;quot;, it means the driver is not installed. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RNDISDriverNotInstalled.png|none|left]]&lt;br /&gt;
To install the driver, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on the &amp;quot;Unknown USB Device&amp;quot; and uninstall the driver.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unplug the Pi from your computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Download the RNDIS drivers here: [[Media:Mod-duo-rndis.zip|Windows 10 RNDIS Drivers]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Extract the contents&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on &amp;quot;RNDIS.inf&amp;quot; and select &amp;quot;install&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Plug in the Raspberry Pi again, it should be picked up as a USB Ethernet Device under &amp;quot;Network Adapters&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ubuntu ==&lt;br /&gt;
Some Ubuntu systems are unable to perform the IP lookup based on the hostname. &lt;br /&gt;
Follow the instructions [https://askubuntu.com/questions/992388/ubuntu-avahi-daemon-cannot-find-raspberrypi-local/1010785#1010785 here] to connect.&lt;br /&gt;
&lt;br /&gt;
Once you've connected, it's suggest you connect to a wifi network to be able to SSH in using &amp;quot;raspberrypi.local&amp;quot;, or set a static IP on the USB port and use the same subnet on the network created on the PC when you plug in the Pi.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=445</id>
		<title>RaspberryPi:ProgrammingInPython</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=445"/>
		<updated>2020-09-11T09:34:06Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* I2C */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Most of the content in the guide comes from the documentation, available online [https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ here].&lt;br /&gt;
&lt;br /&gt;
Python, while not as powerful as C or C++, is quickly becoming a common choice for embedded systems developers due to its ease of use and rapid development times. See [https://spectrum.ieee.org/at-work/innovation/the-2018-top-programming-languages this IEEE article]. For information on programming in C or C++, go to [[RaspberryPi:ProgrammingInC]].&lt;br /&gt;
&lt;br /&gt;
This chapter serves as a short guide for programming in Python on the RPi. You will also find some templates for techniques such as debouncing, or making use of the Raspberry Pi’s multicore architecture by implementing threading.&lt;br /&gt;
&lt;br /&gt;
= The RPI.GPIO Library =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library is the common Python library used on the Raspberry Pi. Documentation for the library can be found here:&amp;lt;br /&amp;gt;&lt;br /&gt;
https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/&lt;br /&gt;
&lt;br /&gt;
It is included in the environment variables by default, so to use it, you can simply just import it into your Python script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;include RPi.GPIO as GPIO&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You need to specify which board mode you’re using. For more information on board modes, see Section [[RaspberryPi:Overview#GPIO_Pins]]. Board modes are specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setmode(GPIO.BCM)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You also need to perform “cleanup” on GPIOs when your application exists. By performing cleanup and resetting all pins to their default modes, you can prevent possible damage to your Raspberry Pi. The cleanup function is called as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If your program is meant to run indefinitely, and only close upon an exception, you can wrap it in a try catch, as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    # Make sure the GPIO is stopped correctly&lt;br /&gt;
    try:&lt;br /&gt;
        while True:&lt;br /&gt;
            main()&lt;br /&gt;
    except KeyboardInterrupt:&lt;br /&gt;
        print(&amp;quot;Exiting gracefully&amp;quot;)&lt;br /&gt;
        GPIO.cleanup()&lt;br /&gt;
    except e:&lt;br /&gt;
        print(&amp;quot;Some other error occurred: {}&amp;quot;.format(e.message)})&lt;br /&gt;
        GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Basic IO =&lt;br /&gt;
&lt;br /&gt;
Read the documentation, available [https://sourceforge.net/p/raspberry-gpio-python/wiki/Outputs/ here].&lt;br /&gt;
&lt;br /&gt;
== Digital Logic ==&lt;br /&gt;
&lt;br /&gt;
Digital output on the Raspberry Pi is accomplished by writing values to channels. A channel is a pin, which is numbered in the way you’ve configured. Basic configuration of a pin for output is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(&amp;lt;channel&amp;gt;, &amp;lt;Logic&amp;gt;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your logic (high, 3.3V, or low, 0V), can be specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 3.3V (high) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.HIGH)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 1)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, True)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 0V (low) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.LOW)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 0)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, False)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Channels can also be specified in lists, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;LEDs = (11,12)&lt;br /&gt;
GPIO.output(LEDs, GPIO.HIGH) # Will turn all channels HIGH&lt;br /&gt;
GPIO.output(LEDs, (GPIO.HIGH, GPIO.LOW)) # Will the first channel HIGH, and the second LOW&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you can also read the state of the pin/channel that is set as an output by using the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function. For example, if you wanted to toggle pin 12, you could do something as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(12, not GPIO.input(12))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Analog ==&lt;br /&gt;
&lt;br /&gt;
The Raspberry Pi does not have any analog input pins. You will need to use something like the [https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf MCP3008] to read analog voltages.&lt;br /&gt;
&lt;br /&gt;
== Inputs ==&lt;br /&gt;
&lt;br /&gt;
=== Digital Read ===&lt;br /&gt;
&lt;br /&gt;
To read the value of a digital pin, you can use the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if GPIO.input(12):&lt;br /&gt;
    print(&amp;quot;Pin 12 HIGH&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;quot;Pin 12 LOW&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Pull Up/Pull Down Resistors ===&lt;br /&gt;
&lt;br /&gt;
Using pull up and pull down resistors is essential when working with digital logic. Thankfully, the Raspberry Pi has internal pull up and pull down resistors. To make use of these, initialize the pin/channel as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_UP)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Interrupts ===&lt;br /&gt;
&lt;br /&gt;
Very often it is useful to set up an interrupt, for example to trigger an event when a button is pressed. Callback functions are executed on a different thread. If you have multiple callbacks, know that they will be executed sequentially as only one thread exists for interrupts. Interrupts can be implemented as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# The bounce time is given in milliseconds.&lt;br /&gt;
# If your pin is set to use pull down resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and 3.3V&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.RISING, callback=callback_method(), bouncetime=200)&lt;br /&gt;
# If your pin is set to use pull up resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and GND&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.FALLING, callback=callback_method(), bouncetime=200)  &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Other functions ===&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO Library offers other functions for interrupts the first is the &amp;lt;code&amp;gt;wait_for_edge()&amp;lt;/code&amp;gt; function, which is designed to block execution until an edge is detected. You can detect edges of &amp;lt;code&amp;gt;GPIO.RISING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GPIO.FALLING&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;GPIO.BOTH&amp;lt;/code&amp;gt;. The timeout is given in milliseconds:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# wait for up to 5 seconds for a rising edge&lt;br /&gt;
edge = GPIO.wait_for_edge(&amp;lt;channel&amp;gt;, GPIO_RISING, timeout=5000)&lt;br /&gt;
if edge is None:&lt;br /&gt;
    print('Timeout occurred')&lt;br /&gt;
else:&lt;br /&gt;
    print('Edge detected on pin &amp;lt;CHANNEL&amp;gt;')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another function is the &amp;lt;code&amp;gt;event_detected()&amp;lt;/code&amp;gt; function. From the docs: “The event_detected() function is designed to be used in a loop with other things, but unlike polling it is not going to miss the change in state of an input while the CPU is busy working on other things. This could be useful when using something like Pygame or PyQt where there is a main loop listening and responding to GUI events in a timely basis.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.add_event_detect(channel, GPIO.RISING)  # add rising edge detection on a channel&lt;br /&gt;
if GPIO.event_detected(channel):&lt;br /&gt;
    print('Button pressed')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Communication Protocols =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library has no native support for communication protocols. Very often, specific Python libraries are provided on a per-device use case. However, this can become tedious and cause your code to become bloated. See the sections below for relevant libraries for using I2C and SPI directly.&lt;br /&gt;
&lt;br /&gt;
== I2C ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable I2C in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To use I2C in Python, you can use the &amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; library. To do this, we need to install and configure smbus. This is usually done by default, but instructions are included for posterity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get install i2c-tools&lt;br /&gt;
$ sudo apt-get install python-smbus&lt;br /&gt;
$ sudo adduser &amp;amp;lt;username&amp;amp;gt; i2c&lt;br /&gt;
$ sudo reboot&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you connect a device, you can run &amp;lt;code&amp;gt;$gpio i2cdetect&amp;lt;/code&amp;gt; to determine if a device is detected on the I2C bus. In the example below, there is an electronic compass (GY-271) connected to the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:I2cdetect.png|frame|none|alt=|An i2cdetect example]]&lt;br /&gt;
&lt;br /&gt;
To initialize an I2C device, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import smbus&lt;br /&gt;
i2cdevice = smbus.SMBus(1) # 1 indicates /dev/i2c-1&lt;br /&gt;
address = 0x1e #whatever the device is for your i2c device&amp;lt;/pre&amp;gt;&lt;br /&gt;
To read a byte from the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;result = i2cdevice.read_byte_data(address, &amp;amp;lt;register&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
To write a byte to the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;i2cdevice.write_byte_data(address, &amp;amp;lt;register&amp;amp;gt;, &amp;amp;lt;value&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Methods Available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; has multiple methods. The documentation for these is quite minimal, but brief descriptions are available [http://wiki.erazor-zone.de/wiki:linux:python:smbus:doc here].&lt;br /&gt;
&lt;br /&gt;
Note: If you're working with EEPROM (specifically 24C32), you may need to read the answer to the questions given [https://www.raspberrypi.org/forums/viewtopic.php?p=1401819&amp;amp;sid=582cace49dad59d93f4e0369047dd89d#p1401819 here].&lt;br /&gt;
&lt;br /&gt;
== SPI ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable SPI in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can use SPI in Python by using the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library. Documentation is available [https://pypi.org/project/spidev/ here]. Basic usage is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import spidev&lt;br /&gt;
&lt;br /&gt;
#Bus is 0 or 1, depending on which SPI bus you've connected to&lt;br /&gt;
bus = 0&lt;br /&gt;
#Device is the chip select pin. Set to 0 or 1, depending on the connections&lt;br /&gt;
device = 1&lt;br /&gt;
&lt;br /&gt;
spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.open(bus, device) #Open connection to a specific bus and device (CS pin)&lt;br /&gt;
&lt;br /&gt;
# Set settings (SPI speed and mode)&lt;br /&gt;
spi.max_speed_hz = 500000&lt;br /&gt;
spi.mode = 0&lt;br /&gt;
&lt;br /&gt;
to_send = [0x01, 0x02, 0x03] #define what to send&lt;br /&gt;
spi.xfer(to_send)&lt;br /&gt;
&lt;br /&gt;
# Close the SPI connection&lt;br /&gt;
close()&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Settings ===&lt;br /&gt;
&lt;br /&gt;
The following settings are configurable in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library, and can be set as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.&amp;amp;lt;setting&amp;amp;gt; = &amp;amp;lt;value&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
List of settings:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;bits_per_word&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;cs_high&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;loop&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_LOOP” flag to enable loopback mode&lt;br /&gt;
* &amp;lt;code&amp;gt;no_cs&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_NO_CS” flag to disable use of the chip select (although the driver may still own the CS pin)&lt;br /&gt;
* &amp;lt;code&amp;gt;lsbfirst&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_speed_hz&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;mode&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SPI mode as two bit pattern of clock polarity and phase [CPOL/CPHA], min: 0b00 = 0, max: 0b11 = 3&lt;br /&gt;
* &amp;lt;code&amp;gt;threewire&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SI/SO signals shared&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are available in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;open(bus, device)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Connects to the specified SPI device, opening &amp;lt;code&amp;gt;/dev/spidev&amp;amp;lt;bus&amp;amp;gt;.&amp;amp;lt;device&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;readbytes(n)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Read n bytes from SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;writebytes(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Writes a list of values to SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt;writebytes2(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to ‘writebytes‘ but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations. Also, writebytes2 understands [https://docs.python.org/3/c-api/buffer.html buffer protocol] so it can accept numpy byte arrays for example without need to convert them with &amp;lt;code&amp;gt;tolist()&amp;lt;/code&amp;gt; first. This offers much better performance where you need to transfer frames to SPI-connected displays for instance.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer2(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be held active between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer3(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to xfer2 but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Disconnects from the SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Threads =&lt;br /&gt;
&lt;br /&gt;
[https://realpython.com/intro-to-python-threading/ This guide] serves as the basis for the text below. This manual does not teach everything there is to know about threading in Python, but will give you the basics to be able to utilize threads for simple tasks that may be of use to you in the practicals. It’s strongly recommended you read through that text if you have not yet been exposed to threading concepts.&lt;br /&gt;
&lt;br /&gt;
This text does not cover issues and precautions when working with threads, such as mutex’s and locks, data races, producer/consumer concerns and the likes. However, these are knowledge areas of critical importance, and it is strongly suggested that the reader tries to make an effort to understand these concerns before writing threaded code.&lt;br /&gt;
&lt;br /&gt;
== The Threading Library ==&lt;br /&gt;
&lt;br /&gt;
The Python library &amp;lt;code&amp;gt;threading&amp;lt;/code&amp;gt; library offers all the functionality one would expect. Import it in to your code in the standard way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are 4 basic things you need to do when creating a thread:&lt;br /&gt;
&lt;br /&gt;
# Initialize it&lt;br /&gt;
# Start it&lt;br /&gt;
# Let is execute&lt;br /&gt;
# “Shut it down” by joining&lt;br /&gt;
&lt;br /&gt;
== Basic Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
For example, if you want to create a separate thread to fetch a sensor value five times, you could do it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&lt;br /&gt;
import time&lt;br /&gt;
import RPi.GPIO as GPIO&lt;br /&gt;
&lt;br /&gt;
def setup():&lt;br /&gt;
    #Contains all code for initialisation of RPi.GPIO&lt;br /&gt;
&lt;br /&gt;
def fetch_sensor_vals(sensor_pin):&lt;br /&gt;
    for i in range(5):&lt;br /&gt;
        GPIO.input(sensor_pin)&lt;br /&gt;
        time.sleep(2)&lt;br /&gt;
    &lt;br /&gt;
if __name__ == &amp;amp;quot;__main__&amp;amp;quot;:&lt;br /&gt;
    setup()&lt;br /&gt;
    # Create a thread to call the function and pass &amp;amp;quot;12&amp;amp;quot; in as sensor pin&lt;br /&gt;
    x = threading.Thread(target=fetch_sensor_vals, args=(12,)) &lt;br /&gt;
    print(&amp;amp;quot;Starting thread&amp;amp;quot;)&lt;br /&gt;
    x.start()&lt;br /&gt;
    print(&amp;amp;quot;Waiting for the thread to finish&amp;amp;quot;)&lt;br /&gt;
    x.join()&lt;br /&gt;
    print(&amp;amp;quot;Reading finished&amp;amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Timed Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
Often in embedded systems we want a specific task to run every X time units. There is an option in the Python threading library. It works as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&lt;br /&gt;
import datetime&lt;br /&gt;
&lt;br /&gt;
&amp;amp;quot;&amp;amp;quot;&amp;amp;quot;&lt;br /&gt;
This function prints the time to the screen every five seconds&lt;br /&gt;
&amp;amp;quot;&amp;amp;quot;&amp;amp;quot;&lt;br /&gt;
def print_time():&lt;br /&gt;
    YOUR = threading.Timer(5.0, print_time)&lt;br /&gt;
    YOUR.daemon = True&lt;br /&gt;
    YOUR.start()&lt;br /&gt;
    print(datetime.datetime.now())&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;amp;quot;__main__&amp;amp;quot;:&lt;br /&gt;
    print_time() # call it once to start the thread&lt;br /&gt;
    &lt;br /&gt;
    # Tell our program to run indefinitely&lt;br /&gt;
    while True:&lt;br /&gt;
        pass&amp;lt;/pre&amp;gt;&lt;br /&gt;
You will see that in this code example, we have also set the &amp;lt;code&amp;gt;daemon&amp;lt;/code&amp;gt; flag of the thread to be be &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. A daemon thread will shut down immediately when the program exits. In essence, the daemon thread will run indefinitely in the background until your application exits, and you do not need to worry about calling &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;It’s important to note that calling t.join() will wait for a thread to finish executing, even if it is a daemon.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=444</id>
		<title>RaspberryPi:DebuggingConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=444"/>
		<updated>2020-09-10T13:37:44Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* SSH'ing Into the Pi 0/0W */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Debugging Connections =&lt;br /&gt;
&lt;br /&gt;
This section is a work in progress. As more common issues are reported by students, this section will be expanded. It's important to note that most connectivity problems come down to an incorrectly configured file, where you may have missed a space, or misspelled something.&lt;br /&gt;
&lt;br /&gt;
= Note for Windows Users =&lt;br /&gt;
&lt;br /&gt;
If you are having trouble accessing the internet from your Pi using the Ethernet Passthrough technique, it’s likely the Windows bridge needs a reset. Change the IPv4 address of your Ethernet port to “Obtain an IP address automatically”, then on your WiFi connection, disable sharing, click okay, and then re-enable sharing. Go back to the IP configuration of your Ethernet post, and double check the IP to see if it’s been assigned 192.168.137.1. If not, you will need to change it using the “Advanced settings” button.&lt;br /&gt;
&lt;br /&gt;
= Ping = &lt;br /&gt;
''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. &lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall. &lt;br /&gt;
&lt;br /&gt;
= WiFi =&lt;br /&gt;
&lt;br /&gt;
See if you can see wireless networks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ iwlist wlan0 scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you cannot connect via WiFi, enter into a shell on the Pi and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ journalctl -u wpa_supplicant | grep wlan0&lt;br /&gt;
$ journalctl -u dhcpcd.service | grep wlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will output the log files and notify you of any incorrect configurations in wpa_supplicant.&lt;br /&gt;
&lt;br /&gt;
The following command will force the interface to be up (if it can be):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo ifconfig wlan0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
If all else fails, reboot and try again. Some services can be restarted without restarting the Pi, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test wpa_supplicant config by killing the process, and running it in debug mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo killall wpa_supplicant&lt;br /&gt;
sudo /sbin/wpa_supplicant -d -c/etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211,wext -iwlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;quot;Failure resolving URLs&amp;quot; or &amp;quot;unknown host&amp;quot; =&lt;br /&gt;
&lt;br /&gt;
If you try to ping a website from the Pi and it fails, but pinging a IP such as 8.8.8.8 works as expected, it is likely an issue with DNS configuration. Open the resolv.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/resolv.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit it to read the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;nameserver 8.8.8.8&lt;br /&gt;
nameserver 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
8.8.8.8 is the IP of Google’s DNS server. A DNS (Domain Name Service) server is responsible for converting human-readable addressed (for example google.co.za) to something the network architecture can understand (172.217.170.67, in this example).&lt;br /&gt;
&lt;br /&gt;
If you still get this error, try running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo route add default gw 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where the IP supplied is the IP of the computer or router you are connected to.&lt;br /&gt;
&lt;br /&gt;
= SSH'ing Into the Pi 0/0W =&lt;br /&gt;
This section assumes you've correctly modified the SD card contents using the correct editor, and are using the correct USB port on the Pi.&lt;br /&gt;
== Windows ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open up device manager by pressing the Windows key and X and selecting &amp;quot;Device Manager&amp;quot; from the drop down&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If you have no other USB to Ethernet Gadgets plugged in, and you see this, it means your Pi is connected correctly and you need to double check you've installed Bonjour and are connecting to the correct hostname. &lt;br /&gt;
[[File:RNDISWithCorrectDrivers.png|none|left]]&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If the device manager is constantly &amp;quot;flashing&amp;quot; after giving the Pi enough time to boot, it means there isn't enough power delivery to the Pi. This is only really a problem on older systems. To resolve this issue, add an additional connection from the &amp;quot;power&amp;quot; USB port to something that can provide additional current, like a cellphone charger, or even just another USB port.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If under &amp;quot;Universal Serial Bus controllers&amp;quot; you see something like &amp;quot;Unknown USB Device (Device Descriptor Failed)&amp;quot;, it means the driver is not installed. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RNDISDriverNotInstalled.png|none|left]]&lt;br /&gt;
To install the driver, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on the &amp;quot;Unknown USB Device&amp;quot; and uninstall the driver.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unplug the Pi from your computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Download the RNDIS drivers here: [[Media:Mod-duo-rndis.zip|Windows 10 RNDIS Drivers]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Extract the contents&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on &amp;quot;RNDIS.inf&amp;quot; and select &amp;quot;install&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Plug in the Raspberry Pi again, it should be picked up as a USB Ethernet Device under &amp;quot;Network Adapters&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ubuntu ==&lt;br /&gt;
Some Ubuntu systems are unable to perform the IP lookup based on the hostname. &lt;br /&gt;
Follow the instructions [https://askubuntu.com/questions/992388/ubuntu-avahi-daemon-cannot-find-raspberrypi-local/1010785#1010785 here] to connect.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=File:RNDISWithCorrectDrivers.png&amp;diff=443</id>
		<title>File:RNDISWithCorrectDrivers.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=File:RNDISWithCorrectDrivers.png&amp;diff=443"/>
		<updated>2020-09-10T13:32:24Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The Raspberry Pi 0/0W correctly picked up by Windows.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=442</id>
		<title>RaspberryPi:ProgrammingInPython</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=442"/>
		<updated>2020-09-10T10:07:02Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Basic IO */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Most of the content in the guide comes from the documentation, available online [https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ here].&lt;br /&gt;
&lt;br /&gt;
Python, while not as powerful as C or C++, is quickly becoming a common choice for embedded systems developers due to its ease of use and rapid development times. See [https://spectrum.ieee.org/at-work/innovation/the-2018-top-programming-languages this IEEE article]. For information on programming in C or C++, go to [[RaspberryPi:ProgrammingInC]].&lt;br /&gt;
&lt;br /&gt;
This chapter serves as a short guide for programming in Python on the RPi. You will also find some templates for techniques such as debouncing, or making use of the Raspberry Pi’s multicore architecture by implementing threading.&lt;br /&gt;
&lt;br /&gt;
= The RPI.GPIO Library =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library is the common Python library used on the Raspberry Pi. Documentation for the library can be found here:&amp;lt;br /&amp;gt;&lt;br /&gt;
https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/&lt;br /&gt;
&lt;br /&gt;
It is included in the environment variables by default, so to use it, you can simply just import it into your Python script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;include RPi.GPIO as GPIO&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You need to specify which board mode you’re using. For more information on board modes, see Section [[RaspberryPi:Overview#GPIO_Pins]]. Board modes are specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setmode(GPIO.BCM)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You also need to perform “cleanup” on GPIOs when your application exists. By performing cleanup and resetting all pins to their default modes, you can prevent possible damage to your Raspberry Pi. The cleanup function is called as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If your program is meant to run indefinitely, and only close upon an exception, you can wrap it in a try catch, as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    # Make sure the GPIO is stopped correctly&lt;br /&gt;
    try:&lt;br /&gt;
        while True:&lt;br /&gt;
            main()&lt;br /&gt;
    except KeyboardInterrupt:&lt;br /&gt;
        print(&amp;quot;Exiting gracefully&amp;quot;)&lt;br /&gt;
        GPIO.cleanup()&lt;br /&gt;
    except e:&lt;br /&gt;
        print(&amp;quot;Some other error occurred: {}&amp;quot;.format(e.message)})&lt;br /&gt;
        GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Basic IO =&lt;br /&gt;
&lt;br /&gt;
Read the documentation, available [https://sourceforge.net/p/raspberry-gpio-python/wiki/Outputs/ here].&lt;br /&gt;
&lt;br /&gt;
== Digital Logic ==&lt;br /&gt;
&lt;br /&gt;
Digital output on the Raspberry Pi is accomplished by writing values to channels. A channel is a pin, which is numbered in the way you’ve configured. Basic configuration of a pin for output is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(&amp;lt;channel&amp;gt;, &amp;lt;Logic&amp;gt;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Your logic (high, 3.3V, or low, 0V), can be specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 3.3V (high) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.HIGH)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 1)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, True)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 0V (low) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, GPIO.LOW)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, 0)&lt;br /&gt;
GPIO.output(&amp;lt;channel&amp;gt;, False)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Channels can also be specified in lists, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;LEDs = (11,12)&lt;br /&gt;
GPIO.output(LEDs, GPIO.HIGH) # Will turn all channels HIGH&lt;br /&gt;
GPIO.output(LEDs, (GPIO.HIGH, GPIO.LOW)) # Will the first channel HIGH, and the second LOW&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that you can also read the state of the pin/channel that is set as an output by using the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function. For example, if you wanted to toggle pin 12, you could do something as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.output(12, not GPIO.input(12))&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Analog ==&lt;br /&gt;
&lt;br /&gt;
The Raspberry Pi does not have any analog input pins. You will need to use something like the [https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf MCP3008] to read analog voltages.&lt;br /&gt;
&lt;br /&gt;
== Inputs ==&lt;br /&gt;
&lt;br /&gt;
=== Digital Read ===&lt;br /&gt;
&lt;br /&gt;
To read the value of a digital pin, you can use the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if GPIO.input(12):&lt;br /&gt;
    print(&amp;quot;Pin 12 HIGH&amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;quot;Pin 12 LOW&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Pull Up/Pull Down Resistors ===&lt;br /&gt;
&lt;br /&gt;
Using pull up and pull down resistors is essential when working with digital logic. Thankfully, the Raspberry Pi has internal pull up and pull down resistors. To make use of these, initialize the pin/channel as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_UP)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setup(&amp;lt;channel&amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Interrupts ===&lt;br /&gt;
&lt;br /&gt;
Very often it is useful to set up an interrupt, for example to trigger an event when a button is pressed. Callback functions are executed on a different thread. If you have multiple callbacks, know that they will be executed sequentially as only one thread exists for interrupts. Interrupts can be implemented as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# The bounce time is given in milliseconds.&lt;br /&gt;
# If your pin is set to use pull down resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and 3.3V&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.RISING, callback=callback_method(), bouncetime=200)&lt;br /&gt;
# If your pin is set to use pull up resistors&lt;br /&gt;
# Connect a button between &amp;lt;channel&amp;gt; and GND&lt;br /&gt;
GPIO.add_event_detect(&amp;lt;channel&amp;gt;, GPIO.FALLING, callback=callback_method(), bouncetime=200)  &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
=== Other functions ===&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO Library offers other functions for interrupts the first is the &amp;lt;code&amp;gt;wait_for_edge()&amp;lt;/code&amp;gt; function, which is designed to block execution until an edge is detected. You can detect edges of &amp;lt;code&amp;gt;GPIO.RISING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GPIO.FALLING&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;GPIO.BOTH&amp;lt;/code&amp;gt;. The timeout is given in milliseconds:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;# wait for up to 5 seconds for a rising edge&lt;br /&gt;
edge = GPIO.wait_for_edge(&amp;lt;channel&amp;gt;, GPIO_RISING, timeout=5000)&lt;br /&gt;
if edge is None:&lt;br /&gt;
    print('Timeout occurred')&lt;br /&gt;
else:&lt;br /&gt;
    print('Edge detected on pin &amp;lt;CHANNEL&amp;gt;')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Another function is the &amp;lt;code&amp;gt;event_detected()&amp;lt;/code&amp;gt; function. From the docs: “The event_detected() function is designed to be used in a loop with other things, but unlike polling it is not going to miss the change in state of an input while the CPU is busy working on other things. This could be useful when using something like Pygame or PyQt where there is a main loop listening and responding to GUI events in a timely basis.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.add_event_detect(channel, GPIO.RISING)  # add rising edge detection on a channel&lt;br /&gt;
if GPIO.event_detected(channel):&lt;br /&gt;
    print('Button pressed')&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Communication Protocols =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library has no native support for communication protocols. Very often, specific Python libraries are provided on a per-device use case. However, this can become tedious and cause your code to become bloated. See the sections below for relevant libraries for using I2C and SPI directly.&lt;br /&gt;
&lt;br /&gt;
== I2C ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable I2C in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To use I2C in Python, you can use the &amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; library. To do this, we need to install and configure smbus. This is usually done by default, but instructions are included for posterity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get install i2c-tools&lt;br /&gt;
$ sudo apt-get install python-smbus&lt;br /&gt;
$ sudo adduser &amp;amp;lt;username&amp;amp;gt; i2c&lt;br /&gt;
$ sudo reboot&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you connect a device, you can run &amp;lt;code&amp;gt;$gpio i2cdetect&amp;lt;/code&amp;gt; to determine if a device is detected on the I2C bus. In the example below, there is an electronic compass (GY-271) connected to the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:I2cdetect.png|frame|none|alt=|An i2cdetect example]]&lt;br /&gt;
&lt;br /&gt;
To initialize an I2C device, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import smbus&lt;br /&gt;
i2cdevice = smbus.SMBus(1) # 1 indicates /dev/i2c-1&lt;br /&gt;
address = 0x1e #whatever the device is for your i2c device&amp;lt;/pre&amp;gt;&lt;br /&gt;
To read a byte from the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;result = i2cdevice.read_byte_data(address, &amp;amp;lt;register&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
To write a byte to the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;i2cdevice.write_byte_data(address, &amp;amp;lt;register&amp;amp;gt;, &amp;amp;lt;value&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Methods Available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; has multiple methods. The documentation for these is quite minimal, but brief descriptions are available [http://wiki.erazor-zone.de/wiki:linux:python:smbus:doc here].&lt;br /&gt;
&lt;br /&gt;
== SPI ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable SPI in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can use SPI in Python by using the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library. Documentation is available [https://pypi.org/project/spidev/ here]. Basic usage is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import spidev&lt;br /&gt;
&lt;br /&gt;
#Bus is 0 or 1, depending on which SPI bus you've connected to&lt;br /&gt;
bus = 0&lt;br /&gt;
#Device is the chip select pin. Set to 0 or 1, depending on the connections&lt;br /&gt;
device = 1&lt;br /&gt;
&lt;br /&gt;
spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.open(bus, device) #Open connection to a specific bus and device (CS pin)&lt;br /&gt;
&lt;br /&gt;
# Set settings (SPI speed and mode)&lt;br /&gt;
spi.max_speed_hz = 500000&lt;br /&gt;
spi.mode = 0&lt;br /&gt;
&lt;br /&gt;
to_send = [0x01, 0x02, 0x03] #define what to send&lt;br /&gt;
spi.xfer(to_send)&lt;br /&gt;
&lt;br /&gt;
# Close the SPI connection&lt;br /&gt;
close()&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Settings ===&lt;br /&gt;
&lt;br /&gt;
The following settings are configurable in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library, and can be set as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.&amp;amp;lt;setting&amp;amp;gt; = &amp;amp;lt;value&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
List of settings:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;bits_per_word&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;cs_high&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;loop&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_LOOP” flag to enable loopback mode&lt;br /&gt;
* &amp;lt;code&amp;gt;no_cs&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_NO_CS” flag to disable use of the chip select (although the driver may still own the CS pin)&lt;br /&gt;
* &amp;lt;code&amp;gt;lsbfirst&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_speed_hz&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;mode&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SPI mode as two bit pattern of clock polarity and phase [CPOL/CPHA], min: 0b00 = 0, max: 0b11 = 3&lt;br /&gt;
* &amp;lt;code&amp;gt;threewire&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SI/SO signals shared&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are available in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;open(bus, device)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Connects to the specified SPI device, opening &amp;lt;code&amp;gt;/dev/spidev&amp;amp;lt;bus&amp;amp;gt;.&amp;amp;lt;device&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;readbytes(n)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Read n bytes from SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;writebytes(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Writes a list of values to SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt;writebytes2(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to ‘writebytes‘ but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations. Also, writebytes2 understands [https://docs.python.org/3/c-api/buffer.html buffer protocol] so it can accept numpy byte arrays for example without need to convert them with &amp;lt;code&amp;gt;tolist()&amp;lt;/code&amp;gt; first. This offers much better performance where you need to transfer frames to SPI-connected displays for instance.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer2(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be held active between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer3(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to xfer2 but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Disconnects from the SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Threads =&lt;br /&gt;
&lt;br /&gt;
[https://realpython.com/intro-to-python-threading/ This guide] serves as the basis for the text below. This manual does not teach everything there is to know about threading in Python, but will give you the basics to be able to utilize threads for simple tasks that may be of use to you in the practicals. It’s strongly recommended you read through that text if you have not yet been exposed to threading concepts.&lt;br /&gt;
&lt;br /&gt;
This text does not cover issues and precautions when working with threads, such as mutex’s and locks, data races, producer/consumer concerns and the likes. However, these are knowledge areas of critical importance, and it is strongly suggested that the reader tries to make an effort to understand these concerns before writing threaded code.&lt;br /&gt;
&lt;br /&gt;
== The Threading Library ==&lt;br /&gt;
&lt;br /&gt;
The Python library &amp;lt;code&amp;gt;threading&amp;lt;/code&amp;gt; library offers all the functionality one would expect. Import it in to your code in the standard way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are 4 basic things you need to do when creating a thread:&lt;br /&gt;
&lt;br /&gt;
# Initialize it&lt;br /&gt;
# Start it&lt;br /&gt;
# Let is execute&lt;br /&gt;
# “Shut it down” by joining&lt;br /&gt;
&lt;br /&gt;
== Basic Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
For example, if you want to create a separate thread to fetch a sensor value five times, you could do it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&lt;br /&gt;
import time&lt;br /&gt;
import RPi.GPIO as GPIO&lt;br /&gt;
&lt;br /&gt;
def setup():&lt;br /&gt;
    #Contains all code for initialisation of RPi.GPIO&lt;br /&gt;
&lt;br /&gt;
def fetch_sensor_vals(sensor_pin):&lt;br /&gt;
    for i in range(5):&lt;br /&gt;
        GPIO.input(sensor_pin)&lt;br /&gt;
        time.sleep(2)&lt;br /&gt;
    &lt;br /&gt;
if __name__ == &amp;amp;quot;__main__&amp;amp;quot;:&lt;br /&gt;
    setup()&lt;br /&gt;
    # Create a thread to call the function and pass &amp;amp;quot;12&amp;amp;quot; in as sensor pin&lt;br /&gt;
    x = threading.Thread(target=fetch_sensor_vals, args=(12,)) &lt;br /&gt;
    print(&amp;amp;quot;Starting thread&amp;amp;quot;)&lt;br /&gt;
    x.start()&lt;br /&gt;
    print(&amp;amp;quot;Waiting for the thread to finish&amp;amp;quot;)&lt;br /&gt;
    x.join()&lt;br /&gt;
    print(&amp;amp;quot;Reading finished&amp;amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Timed Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
Often in embedded systems we want a specific task to run every X time units. There is an option in the Python threading library. It works as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&lt;br /&gt;
import datetime&lt;br /&gt;
&lt;br /&gt;
&amp;amp;quot;&amp;amp;quot;&amp;amp;quot;&lt;br /&gt;
This function prints the time to the screen every five seconds&lt;br /&gt;
&amp;amp;quot;&amp;amp;quot;&amp;amp;quot;&lt;br /&gt;
def print_time():&lt;br /&gt;
    YOUR = threading.Timer(5.0, print_time)&lt;br /&gt;
    YOUR.daemon = True&lt;br /&gt;
    YOUR.start()&lt;br /&gt;
    print(datetime.datetime.now())&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;amp;quot;__main__&amp;amp;quot;:&lt;br /&gt;
    print_time() # call it once to start the thread&lt;br /&gt;
    &lt;br /&gt;
    # Tell our program to run indefinitely&lt;br /&gt;
    while True:&lt;br /&gt;
        pass&amp;lt;/pre&amp;gt;&lt;br /&gt;
You will see that in this code example, we have also set the &amp;lt;code&amp;gt;daemon&amp;lt;/code&amp;gt; flag of the thread to be be &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. A daemon thread will shut down immediately when the program exits. In essence, the daemon thread will run indefinitely in the background until your application exits, and you do not need to worry about calling &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;It’s important to note that calling t.join() will wait for a thread to finish executing, even if it is a daemon.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=441</id>
		<title>RaspberryPi:ProgrammingInPython</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:ProgrammingInPython&amp;diff=441"/>
		<updated>2020-09-10T09:59:29Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* The RPI.GPIO Library */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Most of the content in the guide comes from the documentation, available online [https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/ here].&lt;br /&gt;
&lt;br /&gt;
Python, while not as powerful as C or C++, is quickly becoming a common choice for embedded systems developers due to its ease of use and rapid development times. See [https://spectrum.ieee.org/at-work/innovation/the-2018-top-programming-languages this IEEE article]. For information on programming in C or C++, go to [[RaspberryPi:ProgrammingInC]].&lt;br /&gt;
&lt;br /&gt;
This chapter serves as a short guide for programming in Python on the RPi. You will also find some templates for techniques such as debouncing, or making use of the Raspberry Pi’s multicore architecture by implementing threading.&lt;br /&gt;
&lt;br /&gt;
= The RPI.GPIO Library =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library is the common Python library used on the Raspberry Pi. Documentation for the library can be found here:&amp;lt;br /&amp;gt;&lt;br /&gt;
https://sourceforge.net/p/raspberry-gpio-python/wiki/Home/&lt;br /&gt;
&lt;br /&gt;
It is included in the environment variables by default, so to use it, you can simply just import it into your Python script:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;include RPi.GPIO as GPIO&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You need to specify which board mode you’re using. For more information on board modes, see Section [[RaspberryPi:Overview#GPIO_Pins]]. Board modes are specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setmode(GPIO.BCM)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
You also need to perform “cleanup” on GPIOs when your application exists. By performing cleanup and resetting all pins to their default modes, you can prevent possible damage to your Raspberry Pi. The cleanup function is called as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If your program is meant to run indefinitely, and only close upon an exception, you can wrap it in a try catch, as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    # Make sure the GPIO is stopped correctly&lt;br /&gt;
    try:&lt;br /&gt;
        while True:&lt;br /&gt;
            main()&lt;br /&gt;
    except KeyboardInterrupt:&lt;br /&gt;
        print(&amp;quot;Exiting gracefully&amp;quot;)&lt;br /&gt;
        GPIO.cleanup()&lt;br /&gt;
    except e:&lt;br /&gt;
        print(&amp;quot;Some other error occurred: {}&amp;quot;.format(e.message)})&lt;br /&gt;
        GPIO.cleanup()&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Basic IO =&lt;br /&gt;
&lt;br /&gt;
Read the documentation, available [https://sourceforge.net/p/raspberry-gpio-python/wiki/Outputs/ here].&lt;br /&gt;
&lt;br /&gt;
== Digital Logic ==&lt;br /&gt;
&lt;br /&gt;
Digital output on the Raspberry Pi is accomplished by writing values to channels. A channel is a pin, which is numbered in the way you’ve configured. Basic configuration of a pin for output is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;GPIO.output(&amp;amp;lt;channel&amp;amp;gt;, &amp;amp;lt;Logic&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Your logic (high, 3.3V, or low, 0V), can be specified as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 3.3V (high) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GPIO.output(&amp;amp;lt;channel&amp;amp;gt;, GPIO.HIGH)&lt;br /&gt;
GPIO.output(&amp;amp;lt;channel&amp;amp;gt;, 1)&lt;br /&gt;
GPIO.output(&amp;amp;lt;channel&amp;amp;gt;, True)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;For 0V (low) output:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
GPIO.output(&amp;amp;lt;channel&amp;amp;gt;, GPIO.LOW)&lt;br /&gt;
GPIO.output(&amp;amp;lt;channel&amp;amp;gt;, 0)&lt;br /&gt;
GPIO.output(&amp;amp;lt;channel&amp;amp;gt;, False)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Channels can also be specified in lists, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;LEDs = (11,12)&lt;br /&gt;
GPIO.output(LEDs, GPIO.HIGH) # Will turn all channels HIGH&lt;br /&gt;
GPIO.output(LEDs, (GPIO.HIGH, GPIO.LOW)) # Will the first channel HIGH, and the second LOW&amp;lt;/pre&amp;gt;&lt;br /&gt;
Note that you can also read the state of the pin/channel that is set as an output by using the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function. For example, if you wanted to toggle pin 12, you could do something as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;GPIO.output(12, not GPIO.input(12))&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Analog ==&lt;br /&gt;
&lt;br /&gt;
The Raspberry Pi does not have any analog input pins. You will need to use something like the [https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf MCP3008] to read analog voltages.&lt;br /&gt;
&lt;br /&gt;
== Inputs ==&lt;br /&gt;
&lt;br /&gt;
=== Digital Read ===&lt;br /&gt;
&lt;br /&gt;
To read the value of a digital pin, you can use the &amp;lt;code&amp;gt;input()&amp;lt;/code&amp;gt; function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;if GPIO.input(12):&lt;br /&gt;
    print(&amp;amp;quot;Pin 12 HIGH&amp;amp;quot;)&lt;br /&gt;
else:&lt;br /&gt;
    print(&amp;amp;quot;Pin 12 LOW&amp;amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Pull Up/Pull Down Resistors ===&lt;br /&gt;
&lt;br /&gt;
Using pull up and pull down resistors is essential when working with digital logic. Thankfully, the Raspberry Pi has internal pull up and pull down resistors. To make use of these, initialize the pin/channel as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;GPIO.setup(&amp;amp;lt;channel&amp;amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_UP)&lt;br /&gt;
# or&lt;br /&gt;
GPIO.setup(&amp;amp;lt;channel&amp;amp;gt;, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Interrupts ===&lt;br /&gt;
&lt;br /&gt;
Very often it is useful to set up an interrupt, for example to trigger an event when a button is pressed. Callback functions are executed on a different thread. If you have multiple callbacks, know that they will be executed sequentially as only one thread exists for interrupts. Interrupts can be implemented as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# The bounce time is given in milliseconds.&lt;br /&gt;
# If your pin is set to use pull down resistors&lt;br /&gt;
# Connect a button between &amp;amp;lt;channel&amp;amp;gt; and 3.3V&lt;br /&gt;
GPIO.add_event_detect(&amp;amp;lt;channel&amp;amp;gt;, GPIO.RISING, callback=callback_method(), bouncetime=200)&lt;br /&gt;
# If your pin is set to use pull up resistors&lt;br /&gt;
# Connect a button between &amp;amp;lt;channel&amp;amp;gt; and GND&lt;br /&gt;
GPIO.add_event_detect(&amp;amp;lt;channel&amp;amp;gt;, GPIO.FALLING, callback=callback_method(), bouncetime=200)  &amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Other functions ===&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO Library offers other functions for interrupts the first is the &amp;lt;code&amp;gt;wait_for_edge()&amp;lt;/code&amp;gt; function, which is designed to block execution until an edge is detected. You can detect edges of &amp;lt;code&amp;gt;GPIO.RISING&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;GPIO.FALLING&amp;lt;/code&amp;gt;, or &amp;lt;code&amp;gt;GPIO.BOTH&amp;lt;/code&amp;gt;. The timeout is given in milliseconds:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# wait for up to 5 seconds for a rising edge&lt;br /&gt;
edge = GPIO.wait_for_edge(&amp;amp;lt;channel&amp;amp;gt;, GPIO_RISING, timeout=5000)&lt;br /&gt;
if edge is None:&lt;br /&gt;
    print('Timeout occurred')&lt;br /&gt;
else:&lt;br /&gt;
    print('Edge detected on pin ', TO)&amp;lt;/pre&amp;gt;&lt;br /&gt;
Another function is the &amp;lt;code&amp;gt;event_detected()&amp;lt;/code&amp;gt; function. From the docs: “The event_detected() function is designed to be used in a loop with other things, but unlike polling it is not going to miss the change in state of an input while the CPU is busy working on other things. This could be useful when using something like Pygame or PyQt where there is a main loop listening and responding to GUI events in a timely basis.”&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;GPIO.add_event_detect(channel, GPIO.RISING)  # add rising edge detection on a channel&lt;br /&gt;
do_something()&lt;br /&gt;
if GPIO.event_detected(channel):&lt;br /&gt;
    print('Button pressed')&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Communication Protocols =&lt;br /&gt;
&lt;br /&gt;
The RPi.GPIO library has no native support for communication protocols. Very often, specific Python libraries are provided on a per-device use case. However, this can become tedious and cause your code to become bloated. See the sections below for relevant libraries for using I2C and SPI directly.&lt;br /&gt;
&lt;br /&gt;
== I2C ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable I2C in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
To use I2C in Python, you can use the &amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; library. To do this, we need to install and configure smbus. This is usually done by default, but instructions are included for posterity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get install i2c-tools&lt;br /&gt;
$ sudo apt-get install python-smbus&lt;br /&gt;
$ sudo adduser &amp;amp;lt;username&amp;amp;gt; i2c&lt;br /&gt;
$ sudo reboot&amp;lt;/pre&amp;gt;&lt;br /&gt;
Once you connect a device, you can run &amp;lt;code&amp;gt;$gpio i2cdetect&amp;lt;/code&amp;gt; to determine if a device is detected on the I2C bus. In the example below, there is an electronic compass (GY-271) connected to the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:I2cdetect.png|frame|none|alt=|An i2cdetect example]]&lt;br /&gt;
&lt;br /&gt;
To initialize an I2C device, do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import smbus&lt;br /&gt;
i2cdevice = smbus.SMBus(1) # 1 indicates /dev/i2c-1&lt;br /&gt;
address = 0x1e #whatever the device is for your i2c device&amp;lt;/pre&amp;gt;&lt;br /&gt;
To read a byte from the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;result = i2cdevice.read_byte_data(address, &amp;amp;lt;register&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
To write a byte to the I2C device:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;i2cdevice.write_byte_data(address, &amp;amp;lt;register&amp;amp;gt;, &amp;amp;lt;value&amp;amp;gt;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Methods Available ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;smbus&amp;lt;/code&amp;gt; has multiple methods. The documentation for these is quite minimal, but brief descriptions are available [http://wiki.erazor-zone.de/wiki:linux:python:smbus:doc here].&lt;br /&gt;
&lt;br /&gt;
== SPI ==&lt;br /&gt;
&lt;br /&gt;
Ensure you enable SPI in &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You can use SPI in Python by using the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library. Documentation is available [https://pypi.org/project/spidev/ here]. Basic usage is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import spidev&lt;br /&gt;
&lt;br /&gt;
#Bus is 0 or 1, depending on which SPI bus you've connected to&lt;br /&gt;
bus = 0&lt;br /&gt;
#Device is the chip select pin. Set to 0 or 1, depending on the connections&lt;br /&gt;
device = 1&lt;br /&gt;
&lt;br /&gt;
spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.open(bus, device) #Open connection to a specific bus and device (CS pin)&lt;br /&gt;
&lt;br /&gt;
# Set settings (SPI speed and mode)&lt;br /&gt;
spi.max_speed_hz = 500000&lt;br /&gt;
spi.mode = 0&lt;br /&gt;
&lt;br /&gt;
to_send = [0x01, 0x02, 0x03] #define what to send&lt;br /&gt;
spi.xfer(to_send)&lt;br /&gt;
&lt;br /&gt;
# Close the SPI connection&lt;br /&gt;
close()&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== Settings ===&lt;br /&gt;
&lt;br /&gt;
The following settings are configurable in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library, and can be set as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;spi = spidev.SpiDev() #Enable SPI&lt;br /&gt;
spi.&amp;amp;lt;setting&amp;amp;gt; = &amp;amp;lt;value&amp;amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;
List of settings:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;bits_per_word&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;cs_high&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;loop&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_LOOP” flag to enable loopback mode&lt;br /&gt;
* &amp;lt;code&amp;gt;no_cs&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Set the “SPI_NO_CS” flag to disable use of the chip select (although the driver may still own the CS pin)&lt;br /&gt;
* &amp;lt;code&amp;gt;lsbfirst&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;max_speed_hz&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;mode&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SPI mode as two bit pattern of clock polarity and phase [CPOL/CPHA], min: 0b00 = 0, max: 0b11 = 3&lt;br /&gt;
* &amp;lt;code&amp;gt;threewire&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
SI/SO signals shared&lt;br /&gt;
&lt;br /&gt;
=== Methods ===&lt;br /&gt;
&lt;br /&gt;
The following methods are available in the &amp;lt;code&amp;gt;spidev&amp;lt;/code&amp;gt; library&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;open(bus, device)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Connects to the specified SPI device, opening &amp;lt;code&amp;gt;/dev/spidev&amp;amp;lt;bus&amp;amp;gt;.&amp;amp;lt;device&amp;amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;readbytes(n)&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Read n bytes from SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;writebytes(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Writes a list of values to SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; &amp;lt;code&amp;gt;writebytes2(list of values)&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to ‘writebytes‘ but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations. Also, writebytes2 understands [https://docs.python.org/3/c-api/buffer.html buffer protocol] so it can accept numpy byte arrays for example without need to convert them with &amp;lt;code&amp;gt;tolist()&amp;lt;/code&amp;gt; first. This offers much better performance where you need to transfer frames to SPI-connected displays for instance.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be released and reactivated between blocks. Delay specifies the delay in usec between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer2(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Performs an SPI transaction. Chip-select should be held active between blocks.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;xfer3(list of values[, speed_hz, delay_usec, bits_per_word])&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Similar to xfer2 but accepts arbitrary large lists. If list size exceeds buffer size (which is read from &amp;lt;code&amp;gt;/sys/module/spidev/parameters/bufsiz&amp;lt;/code&amp;gt;), data will be split into smaller chunks and sent in multiple operations.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Disconnects from the SPI device.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Using Threads =&lt;br /&gt;
&lt;br /&gt;
[https://realpython.com/intro-to-python-threading/ This guide] serves as the basis for the text below. This manual does not teach everything there is to know about threading in Python, but will give you the basics to be able to utilize threads for simple tasks that may be of use to you in the practicals. It’s strongly recommended you read through that text if you have not yet been exposed to threading concepts.&lt;br /&gt;
&lt;br /&gt;
This text does not cover issues and precautions when working with threads, such as mutex’s and locks, data races, producer/consumer concerns and the likes. However, these are knowledge areas of critical importance, and it is strongly suggested that the reader tries to make an effort to understand these concerns before writing threaded code.&lt;br /&gt;
&lt;br /&gt;
== The Threading Library ==&lt;br /&gt;
&lt;br /&gt;
The Python library &amp;lt;code&amp;gt;threading&amp;lt;/code&amp;gt; library offers all the functionality one would expect. Import it in to your code in the standard way:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&amp;lt;/pre&amp;gt;&lt;br /&gt;
There are 4 basic things you need to do when creating a thread:&lt;br /&gt;
&lt;br /&gt;
# Initialize it&lt;br /&gt;
# Start it&lt;br /&gt;
# Let is execute&lt;br /&gt;
# “Shut it down” by joining&lt;br /&gt;
&lt;br /&gt;
== Basic Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
For example, if you want to create a separate thread to fetch a sensor value five times, you could do it as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&lt;br /&gt;
import time&lt;br /&gt;
import RPi.GPIO as GPIO&lt;br /&gt;
&lt;br /&gt;
def setup():&lt;br /&gt;
    #Contains all code for initialisation of RPi.GPIO&lt;br /&gt;
&lt;br /&gt;
def fetch_sensor_vals(sensor_pin):&lt;br /&gt;
    for i in range(5):&lt;br /&gt;
        GPIO.input(sensor_pin)&lt;br /&gt;
        time.sleep(2)&lt;br /&gt;
    &lt;br /&gt;
if __name__ == &amp;amp;quot;__main__&amp;amp;quot;:&lt;br /&gt;
    setup()&lt;br /&gt;
    # Create a thread to call the function and pass &amp;amp;quot;12&amp;amp;quot; in as sensor pin&lt;br /&gt;
    x = threading.Thread(target=fetch_sensor_vals, args=(12,)) &lt;br /&gt;
    print(&amp;amp;quot;Starting thread&amp;amp;quot;)&lt;br /&gt;
    x.start()&lt;br /&gt;
    print(&amp;amp;quot;Waiting for the thread to finish&amp;amp;quot;)&lt;br /&gt;
    x.join()&lt;br /&gt;
    print(&amp;amp;quot;Reading finished&amp;amp;quot;)&amp;lt;/pre&amp;gt;&lt;br /&gt;
== Timed Thread Usage ==&lt;br /&gt;
&lt;br /&gt;
Often in embedded systems we want a specific task to run every X time units. There is an option in the Python threading library. It works as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;import threading&lt;br /&gt;
import datetime&lt;br /&gt;
&lt;br /&gt;
&amp;amp;quot;&amp;amp;quot;&amp;amp;quot;&lt;br /&gt;
This function prints the time to the screen every five seconds&lt;br /&gt;
&amp;amp;quot;&amp;amp;quot;&amp;amp;quot;&lt;br /&gt;
def print_time():&lt;br /&gt;
    YOUR = threading.Timer(5.0, print_time)&lt;br /&gt;
    YOUR.daemon = True&lt;br /&gt;
    YOUR.start()&lt;br /&gt;
    print(datetime.datetime.now())&lt;br /&gt;
    &lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;amp;quot;__main__&amp;amp;quot;:&lt;br /&gt;
    print_time() # call it once to start the thread&lt;br /&gt;
    &lt;br /&gt;
    # Tell our program to run indefinitely&lt;br /&gt;
    while True:&lt;br /&gt;
        pass&amp;lt;/pre&amp;gt;&lt;br /&gt;
You will see that in this code example, we have also set the &amp;lt;code&amp;gt;daemon&amp;lt;/code&amp;gt; flag of the thread to be be &amp;lt;code&amp;gt;True&amp;lt;/code&amp;gt;. A daemon thread will shut down immediately when the program exits. In essence, the daemon thread will run indefinitely in the background until your application exits, and you do not need to worry about calling &amp;lt;code&amp;gt;join()&amp;lt;/code&amp;gt;.&amp;lt;ref&amp;gt;It’s important to note that calling t.join() will wait for a thread to finish executing, even if it is a daemon.&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=440</id>
		<title>RaspberryPi:DebuggingConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=440"/>
		<updated>2020-09-10T09:06:04Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Windows */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Debugging Connections =&lt;br /&gt;
&lt;br /&gt;
This section is a work in progress. As more common issues are reported by students, this section will be expanded. It's important to note that most connectivity problems come down to an incorrectly configured file, where you may have missed a space, or misspelled something.&lt;br /&gt;
&lt;br /&gt;
= Note for Windows Users =&lt;br /&gt;
&lt;br /&gt;
If you are having trouble accessing the internet from your Pi using the Ethernet Passthrough technique, it’s likely the Windows bridge needs a reset. Change the IPv4 address of your Ethernet port to “Obtain an IP address automatically”, then on your WiFi connection, disable sharing, click okay, and then re-enable sharing. Go back to the IP configuration of your Ethernet post, and double check the IP to see if it’s been assigned 192.168.137.1. If not, you will need to change it using the “Advanced settings” button.&lt;br /&gt;
&lt;br /&gt;
= Ping = &lt;br /&gt;
''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. &lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall. &lt;br /&gt;
&lt;br /&gt;
= WiFi =&lt;br /&gt;
&lt;br /&gt;
See if you can see wireless networks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ iwlist wlan0 scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you cannot connect via WiFi, enter into a shell on the Pi and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ journalctl -u wpa_supplicant | grep wlan0&lt;br /&gt;
$ journalctl -u dhcpcd.service | grep wlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will output the log files and notify you of any incorrect configurations in wpa_supplicant.&lt;br /&gt;
&lt;br /&gt;
The following command will force the interface to be up (if it can be):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo ifconfig wlan0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
If all else fails, reboot and try again. Some services can be restarted without restarting the Pi, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test wpa_supplicant config by killing the process, and running it in debug mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo killall wpa_supplicant&lt;br /&gt;
sudo /sbin/wpa_supplicant -d -c/etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211,wext -iwlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;quot;Failure resolving URLs&amp;quot; or &amp;quot;unknown host&amp;quot; =&lt;br /&gt;
&lt;br /&gt;
If you try to ping a website from the Pi and it fails, but pinging a IP such as 8.8.8.8 works as expected, it is likely an issue with DNS configuration. Open the resolv.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/resolv.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit it to read the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;nameserver 8.8.8.8&lt;br /&gt;
nameserver 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
8.8.8.8 is the IP of Google’s DNS server. A DNS (Domain Name Service) server is responsible for converting human-readable addressed (for example google.co.za) to something the network architecture can understand (172.217.170.67, in this example).&lt;br /&gt;
&lt;br /&gt;
If you still get this error, try running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo route add default gw 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where the IP supplied is the IP of the computer or router you are connected to.&lt;br /&gt;
&lt;br /&gt;
= SSH'ing Into the Pi 0/0W =&lt;br /&gt;
This section assumes you've correctly modified the SD card contents using the correct editor, and are using the correct USB port on the Pi.&lt;br /&gt;
== Windows ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open up device manager by pressing the Windows key and X and selecting &amp;quot;Device Manager&amp;quot; from the drop down&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If you have no other USB to Ethernet Gadgets plugged in, and you see this, it means your Pi is connected correctly and you need to double check you've installed Bonjour and are connecting to the correct hostname. PICTURE&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If under &amp;quot;Universal Serial Bus controllers&amp;quot; you see something like &amp;quot;Unknown USB Device (Device Descriptor Failed)&amp;quot;, it means the driver is not installed. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RNDISDriverNotInstalled.png|none|left]]&lt;br /&gt;
To install the driver, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on the &amp;quot;Unknown USB Device&amp;quot; and uninstall the driver.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unplug the Pi from your computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Download the RNDIS drivers here: [[Media:Mod-duo-rndis.zip|Windows 10 RNDIS Drivers]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Extract the contents&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on &amp;quot;RNDIS.inf&amp;quot; and select &amp;quot;install&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Plug in the Raspberry Pi again, it should be picked up as a USB Ethernet Device under &amp;quot;Network Adapters&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Ubuntu ==&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=439</id>
		<title>RaspberryPi:DebuggingConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:DebuggingConnectivity&amp;diff=439"/>
		<updated>2020-09-10T09:03:03Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Debugging Connections =&lt;br /&gt;
&lt;br /&gt;
This section is a work in progress. As more common issues are reported by students, this section will be expanded. It's important to note that most connectivity problems come down to an incorrectly configured file, where you may have missed a space, or misspelled something.&lt;br /&gt;
&lt;br /&gt;
= Note for Windows Users =&lt;br /&gt;
&lt;br /&gt;
If you are having trouble accessing the internet from your Pi using the Ethernet Passthrough technique, it’s likely the Windows bridge needs a reset. Change the IPv4 address of your Ethernet port to “Obtain an IP address automatically”, then on your WiFi connection, disable sharing, click okay, and then re-enable sharing. Go back to the IP configuration of your Ethernet post, and double check the IP to see if it’s been assigned 192.168.137.1. If not, you will need to change it using the “Advanced settings” button.&lt;br /&gt;
&lt;br /&gt;
= Ping = &lt;br /&gt;
''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. &lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall. &lt;br /&gt;
&lt;br /&gt;
= WiFi =&lt;br /&gt;
&lt;br /&gt;
See if you can see wireless networks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ iwlist wlan0 scan&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you cannot connect via WiFi, enter into a shell on the Pi and run:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ journalctl -u wpa_supplicant | grep wlan0&lt;br /&gt;
$ journalctl -u dhcpcd.service | grep wlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will output the log files and notify you of any incorrect configurations in wpa_supplicant.&lt;br /&gt;
&lt;br /&gt;
The following command will force the interface to be up (if it can be):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo ifconfig wlan0 up&amp;lt;/pre&amp;gt;&lt;br /&gt;
If all else fails, reboot and try again. Some services can be restarted without restarting the Pi, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&lt;br /&gt;
Test wpa_supplicant config by killing the process, and running it in debug mode:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo killall wpa_supplicant&lt;br /&gt;
sudo /sbin/wpa_supplicant -d -c/etc/wpa_supplicant/wpa_supplicant.conf -Dnl80211,wext -iwlan0&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= &amp;quot;Failure resolving URLs&amp;quot; or &amp;quot;unknown host&amp;quot; =&lt;br /&gt;
&lt;br /&gt;
If you try to ping a website from the Pi and it fails, but pinging a IP such as 8.8.8.8 works as expected, it is likely an issue with DNS configuration. Open the resolv.conf file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/resolv.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit it to read the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;nameserver 8.8.8.8&lt;br /&gt;
nameserver 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
8.8.8.8 is the IP of Google’s DNS server. A DNS (Domain Name Service) server is responsible for converting human-readable addressed (for example google.co.za) to something the network architecture can understand (172.217.170.67, in this example).&lt;br /&gt;
&lt;br /&gt;
If you still get this error, try running the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo route add default gw 192.168.137.1&amp;lt;/pre&amp;gt;&lt;br /&gt;
Where the IP supplied is the IP of the computer or router you are connected to.&lt;br /&gt;
&lt;br /&gt;
= SSH'ing Into the Pi 0/0W =&lt;br /&gt;
This section assumes you've correctly modified the SD card contents using the correct editor, and are using the correct USB port on the Pi.&lt;br /&gt;
== Windows ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open up device manager by pressing the Windows key and X and selecting &amp;quot;Device Manager&amp;quot; from the drop down&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If you have no other USB to Ethernet Gadgets plugged in, and you see this, it means your Pi is connected correctly and you need to double check you've installed Bonjour and are connecting to the correct hostname. PICTURE&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; If you see this, it means the driver is not installed. &amp;lt;br&amp;gt;&lt;br /&gt;
[[File:RNDISDriverNotInstalled.png|none|left]]&lt;br /&gt;
To install the driver, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on the &amp;quot;Unknown USB Device&amp;quot; and uninstall the driver.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Unplug the Pi from your computer&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Download the RNDIS drivers here: [[Media:Mod-duo-rndis.zip|Windows 10 RNDIS Drivers]] &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Extract the contents&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click on &amp;quot;RNDIS.inf&amp;quot; and select &amp;quot;install&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Plug in the Raspberry Pi again, it should be picked up as a USB Ethernet Device under &amp;quot;Network Adapters&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
== Ubuntu ==&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=File:Mod-duo-rndis.zip&amp;diff=438</id>
		<title>File:Mod-duo-rndis.zip</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=File:Mod-duo-rndis.zip&amp;diff=438"/>
		<updated>2020-09-10T08:54:18Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: RNDIS Drivers for Windows 10, useful for getting the Pi 0W to work.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Summary ==&lt;br /&gt;
RNDIS Drivers for Windows 10, useful for getting the Pi 0W to work.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=File:RNDISDriverNotInstalled.png&amp;diff=437</id>
		<title>File:RNDISDriverNotInstalled.png</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=File:RNDISDriverNotInstalled.png&amp;diff=437"/>
		<updated>2020-09-10T08:47:22Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;An image of device manager when Windows fails to install the RNDIS driver for use with the RaspberryPi&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=Visual_Studio_Code&amp;diff=435</id>
		<title>Visual Studio Code</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=Visual_Studio_Code&amp;diff=435"/>
		<updated>2020-09-09T08:31:39Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Useful plugins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Software]]&lt;br /&gt;
[[Category:IDEs]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Visual Studio Code is a lightweight code editor with plugins for many different languages and frameworks.&lt;br /&gt;
&lt;br /&gt;
= Installation = &lt;br /&gt;
See [https://code.visualstudio.com/docs/setup/setup-overview this link] for details on installation and configuration.&lt;br /&gt;
&lt;br /&gt;
= Useful plugins =&lt;br /&gt;
== LaTeX Workshop ==&lt;br /&gt;
On Windows:&lt;br /&gt;
# Install the James Yu Tex workshop plugin&lt;br /&gt;
# Install Miktex-basic&lt;br /&gt;
# Install Perl&lt;br /&gt;
&lt;br /&gt;
== Remote Development for the Raspberry Pi ==&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=Visual_Studio_Code&amp;diff=434</id>
		<title>Visual Studio Code</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=Visual_Studio_Code&amp;diff=434"/>
		<updated>2020-09-09T08:30:54Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Useful plugins */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Software]]&lt;br /&gt;
[[Category:IDEs]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Visual Studio Code is a lightweight code editor with plugins for many different languages and frameworks.&lt;br /&gt;
&lt;br /&gt;
= Installation = &lt;br /&gt;
See [https://code.visualstudio.com/docs/setup/setup-overview this link] for details on installation and configuration.&lt;br /&gt;
&lt;br /&gt;
= Useful plugins =&lt;br /&gt;
== LaTeX Workshop ==&lt;br /&gt;
On Windows:&lt;br /&gt;
# Install the James Yu Tex workshop plugin&lt;br /&gt;
# Install Miktex-basic&lt;br /&gt;
# Install Perl&lt;br /&gt;
&lt;br /&gt;
== Remote development for the Raspberry Pi ==&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=433</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=433"/>
		<updated>2020-09-04T12:13:49Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Internet Access over USB */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
There are two sorts of Ethernet Connectivity we will consider. The first is just connecting the Pi to a known Ethernet network. It is simple as it requires no configuration, but it means you will need to use other methods to ensure the network allows SSH traffic and to ensure you can determine the IP of the Pi.&lt;br /&gt;
&lt;br /&gt;
The second is using Ethernet passthrough from your computer to the Raspberry Pi. This leaves the WiFi free to host your own access point, and you can host services such as a Node-Red server or media center on the Pi.&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi to a router will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi.&lt;br /&gt;
&lt;br /&gt;
== TTL over USB ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The Pi uses 3.3V logic levels. Using a 5V logic module will permanently damage the pins.&lt;br /&gt;
&lt;br /&gt;
This option allows you to use a USB to UART converter such as a FT232R or CP2102. Begin by removing the SD card, and insert it into a computer. Make the following changes on the boot partition:&lt;br /&gt;
&lt;br /&gt;
cmdline.txt: add the following (on the same line)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;console=serial0,115200 &amp;lt;/pre&amp;gt;&lt;br /&gt;
config.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uart_enable=1&lt;br /&gt;
dtoverlay=pi3-disable-bt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using USB connectivity on the Pi 0/0W ==&lt;br /&gt;
In order to use this method on Windows you require [https://support.apple.com/kb/DL999?locale=en_US Apple Bonjour Print Services] as well as [https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html PuTTY].&lt;br /&gt;
&lt;br /&gt;
With the SD card plugged into your computer, open up the boot partition and make the following changes:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to enable SSH as described at [[RaspberryPi:Networking#Enabling_SSH]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;At the bottom of config.txt, add the following line &lt;br /&gt;
&amp;lt;pre&amp;gt;dtoverlay=dwc2&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the '''same line''' in cmdline.txt, append the following: &lt;br /&gt;
&amp;lt;pre&amp;gt; modules-load=dwc2,g_ether&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open up a terminal window (or PuTTY if you're on Windows).&lt;br /&gt;
After about 90 or so seconds, you should be able to SSH in (assuming you enabled SSH on the Pi) by connecting to &amp;lt;code&amp;gt;raspberrypi.local&amp;lt;/code&amp;gt;.&lt;br /&gt;
You may (if you're using PuTTY) get a message about keys and hashes and hosts - just click &amp;quot;yes&amp;quot;.&lt;br /&gt;
You can then log in with the username &amp;quot;pi&amp;quot; and the password &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Internet Access over USB ===&lt;br /&gt;
If you don't have WiFi connectivity, you can send an internet connection from your computer over USB.&lt;br /&gt;
&lt;br /&gt;
In order to provide the Pi with internet access, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Share your computer's  connection with the Pi as you have done in the &amp;quot;WiFi to Ethernet Passthrough&amp;quot; section above. You will be sharing your regular connection with an Ethernet connection, as that is how the Pi 0 has been set up. In the test I ran &amp;lt;li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; On the Pi, you need to configure DHCPCD to have usb0 use a static IP of 192.168.137.x. The rest of this wiki has been written with x=15&lt;br /&gt;
&amp;lt;li&amp;gt; SSH in using &amp;quot;raspberrypi.local&amp;quot; as the address to connect to &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Run &amp;lt;code&amp;gt; sudo nano /etc/dhcpcd.conf&amp;lt;/code&amp;gt;, scroll to the bottom, and add the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface usb0&lt;br /&gt;
static ip_address=192.168.137.15&lt;br /&gt;
static router = 192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Save and close the file &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Run the command &amp;lt;code&amp;gt; sudo route add default gw 192.168.137.1 &amp;lt;/code&amp;gt; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Reboot the Pi &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; SSH in again. You should be able to ssh in using &amp;quot;192.168.137.15&amp;quot; now, as well as &amp;quot;raspberrypi.local&amp;quot; &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To test connectivity, try pinging google.com. You should get a valid response back. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=432</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=432"/>
		<updated>2020-09-04T12:06:43Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Internet Access over USB */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
There are two sorts of Ethernet Connectivity we will consider. The first is just connecting the Pi to a known Ethernet network. It is simple as it requires no configuration, but it means you will need to use other methods to ensure the network allows SSH traffic and to ensure you can determine the IP of the Pi.&lt;br /&gt;
&lt;br /&gt;
The second is using Ethernet passthrough from your computer to the Raspberry Pi. This leaves the WiFi free to host your own access point, and you can host services such as a Node-Red server or media center on the Pi.&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi to a router will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi.&lt;br /&gt;
&lt;br /&gt;
== TTL over USB ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The Pi uses 3.3V logic levels. Using a 5V logic module will permanently damage the pins.&lt;br /&gt;
&lt;br /&gt;
This option allows you to use a USB to UART converter such as a FT232R or CP2102. Begin by removing the SD card, and insert it into a computer. Make the following changes on the boot partition:&lt;br /&gt;
&lt;br /&gt;
cmdline.txt: add the following (on the same line)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;console=serial0,115200 &amp;lt;/pre&amp;gt;&lt;br /&gt;
config.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uart_enable=1&lt;br /&gt;
dtoverlay=pi3-disable-bt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using USB connectivity on the Pi 0/0W ==&lt;br /&gt;
In order to use this method on Windows you require [https://support.apple.com/kb/DL999?locale=en_US Apple Bonjour Print Services] as well as [https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html PuTTY].&lt;br /&gt;
&lt;br /&gt;
With the SD card plugged into your computer, open up the boot partition and make the following changes:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to enable SSH as described at [[RaspberryPi:Networking#Enabling_SSH]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;At the bottom of config.txt, add the following line &lt;br /&gt;
&amp;lt;pre&amp;gt;dtoverlay=dwc2&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the '''same line''' in cmdline.txt, append the following: &lt;br /&gt;
&amp;lt;pre&amp;gt; modules-load=dwc2,g_ether&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open up a terminal window (or PuTTY if you're on Windows).&lt;br /&gt;
After about 90 or so seconds, you should be able to SSH in (assuming you enabled SSH on the Pi) by connecting to &amp;lt;code&amp;gt;raspberrypi.local&amp;lt;/code&amp;gt;.&lt;br /&gt;
You may (if you're using PuTTY) get a message about keys and hashes and hosts - just click &amp;quot;yes&amp;quot;.&lt;br /&gt;
You can then log in with the username &amp;quot;pi&amp;quot; and the password &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Internet Access over USB ===&lt;br /&gt;
If you don't have WiFi connectivity, you can send an internet connection from your computer over USB.&lt;br /&gt;
&lt;br /&gt;
In order to provide the Pi with internet access, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Share your computer's  connection with the Pi as you have done in the &amp;quot;WiFi to Ethernet Passthrough&amp;quot; section above. You will be sharing your regular connection with an Ethernet connection, as that is how the Pi 0 has been set up. In the test I ran &amp;lt;li&amp;gt;&lt;br /&gt;
# On the Pi, you need to configure DHCPCD to have usb0 use a static IP of 192.168.137.x. The rest of this wiki has been written with x=15&lt;br /&gt;
# SSH in using &amp;quot;raspberrypi.local&amp;quot; as the address to connect to &lt;br /&gt;
# Run &amp;lt;code&amp;gt; sudo nano /etc/dhcpcd.conf&amp;lt;/code&amp;gt;, scroll to the bottom, and add the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface usb0&lt;br /&gt;
static ip_address=192.168.137.15&lt;br /&gt;
static router = 192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Save and close the file&lt;br /&gt;
# Run the command &amp;lt;code&amp;gt; sudo route add default gw 192.168.137.1 &amp;lt;/code&amp;gt;&lt;br /&gt;
# Reboot the Pi&lt;br /&gt;
# SSH in again. You should be able to ssh in using &amp;quot;192.168.137.15&amp;quot; now, as well as &amp;quot;raspberrypi.local&amp;quot;&lt;br /&gt;
# To test connectivity, try pinging google.com. You should get a valid response back.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=431</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=431"/>
		<updated>2020-09-04T12:05:46Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Using USB connectivity on the Pi 0/0W */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
There are two sorts of Ethernet Connectivity we will consider. The first is just connecting the Pi to a known Ethernet network. It is simple as it requires no configuration, but it means you will need to use other methods to ensure the network allows SSH traffic and to ensure you can determine the IP of the Pi.&lt;br /&gt;
&lt;br /&gt;
The second is using Ethernet passthrough from your computer to the Raspberry Pi. This leaves the WiFi free to host your own access point, and you can host services such as a Node-Red server or media center on the Pi.&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi to a router will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi.&lt;br /&gt;
&lt;br /&gt;
== TTL over USB ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The Pi uses 3.3V logic levels. Using a 5V logic module will permanently damage the pins.&lt;br /&gt;
&lt;br /&gt;
This option allows you to use a USB to UART converter such as a FT232R or CP2102. Begin by removing the SD card, and insert it into a computer. Make the following changes on the boot partition:&lt;br /&gt;
&lt;br /&gt;
cmdline.txt: add the following (on the same line)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;console=serial0,115200 &amp;lt;/pre&amp;gt;&lt;br /&gt;
config.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uart_enable=1&lt;br /&gt;
dtoverlay=pi3-disable-bt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using USB connectivity on the Pi 0/0W ==&lt;br /&gt;
In order to use this method on Windows you require [https://support.apple.com/kb/DL999?locale=en_US Apple Bonjour Print Services] as well as [https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html PuTTY].&lt;br /&gt;
&lt;br /&gt;
With the SD card plugged into your computer, open up the boot partition and make the following changes:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to enable SSH as described at [[RaspberryPi:Networking#Enabling_SSH]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;At the bottom of config.txt, add the following line &lt;br /&gt;
&amp;lt;pre&amp;gt;dtoverlay=dwc2&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the '''same line''' in cmdline.txt, append the following: &lt;br /&gt;
&amp;lt;pre&amp;gt; modules-load=dwc2,g_ether&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open up a terminal window (or PuTTY if you're on Windows).&lt;br /&gt;
After about 90 or so seconds, you should be able to SSH in (assuming you enabled SSH on the Pi) by connecting to &amp;lt;code&amp;gt;raspberrypi.local&amp;lt;/code&amp;gt;.&lt;br /&gt;
You may (if you're using PuTTY) get a message about keys and hashes and hosts - just click &amp;quot;yes&amp;quot;.&lt;br /&gt;
You can then log in with the username &amp;quot;pi&amp;quot; and the password &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Internet Access over USB ===&lt;br /&gt;
In order to provide the Pi with internet access, you need to do the following:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Share your computer's  connection with the Pi as you have done in the &amp;quot;WiFi to Ethernet Passthrough&amp;quot; section above. You will be sharing your regular connection with an Ethernet connection, as that is how the Pi 0 has been set up. In the test I ran &amp;lt;li&amp;gt;&lt;br /&gt;
# On the Pi, you need to configure DHCPCD to have usb0 use a static IP of 192.168.137.x. The rest of this wiki has been written with x=15&lt;br /&gt;
# SSH in using &amp;quot;raspberrypi.local&amp;quot; as the address to connect to &lt;br /&gt;
# Run &amp;lt;code&amp;gt; sudo nano /etc/dhcpcd.conf&amp;lt;/code&amp;gt;, scroll to the bottom, and add the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
interface usb0&lt;br /&gt;
static ip_address=192.168.137.15&lt;br /&gt;
static router = 192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
# Save and close the file&lt;br /&gt;
# Run the command &amp;lt;code&amp;gt; sudo route add default gw 192.168.137.1 &amp;lt;/code&amp;gt;&lt;br /&gt;
# Reboot the Pi&lt;br /&gt;
# SSH in again. You should be able to ssh in using &amp;quot;192.168.137.15&amp;quot; now, as well as &amp;quot;raspberrypi.local&amp;quot;&lt;br /&gt;
# To test connectivity, try pinging google.com. You should get a valid response back.&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=430</id>
		<title>RaspberryPi:Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=430"/>
		<updated>2020-09-04T11:10:53Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
In order to use the Pi you need to install an operating system on it and set up networking. You will then configure the networking settings on your Pi to allow you to access the Pi using SSH. &lt;br /&gt;
&lt;br /&gt;
This process will follow headless installation, as we are going to assume most students do not have access to spare screens, keyboards and mouses for the Pi. Headless mode on the Raspberry Pi refers to using it without direct user input and output (essentially no screen, mouse or keyboard connected directly to it).&lt;br /&gt;
&lt;br /&gt;
The instructions below may seem complicated, but configuring any Raspberry Pi consists of the same basic steps:&lt;br /&gt;
&lt;br /&gt;
# Flash the SD Card&lt;br /&gt;
# Edit the configs to get headless access&lt;br /&gt;
# Complete first boot&lt;br /&gt;
# Enable configs for other connectivity&lt;br /&gt;
&lt;br /&gt;
= Prerequisites =&lt;br /&gt;
== Software Requirements ==&lt;br /&gt;
'''Note''': Recently, the Pi Foundation released an imager tool which can be run from multiple operating systems and also has support for a selection of operating systems which can be installed on the Raspberry Pi. you can downlaod this tool from [https://www.raspberrypi.org/downloads/ here]. It will automatically download the selected operating system for your Raspberry Pi too, or allow you to select one you have already downloaded and have stored on local storage.&lt;br /&gt;
&lt;br /&gt;
If you'd prefer not to use the Pi Foundation imager, you'll need the following tools:&lt;br /&gt;
* An operating system image. It's recommended you use [https://www.raspberrypi.org/downloads/raspberry-pi-os/ Raspberry Pi OS]. You can read more about operating systems for the Pi on [http://wiki.ee.uct.ac.za/RaspberryPi:Overview#OperatingSystems this page]&lt;br /&gt;
* Something to allow you to SSH in to your Pi. On Windows you can use [http://wiki.ee.uct.ac.za/PuTTY PuTTY] or [http://wiki.ee.uct.ac.za/Windows_Subsystem_for_Linux WSL]&lt;br /&gt;
* On Windows, you will need an [https://www.sdcard.org/downloads/formatter\_4/eula\_windows/index.html SD Card Formatter]&lt;br /&gt;
* On Windows, you will require software to burn the image. [https://www.balena.io/etcher/ Balena Etcher] is recommended.&lt;br /&gt;
&lt;br /&gt;
== Hardware Requirements ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|- style=&amp;quot;font-weight:bold;&amp;quot;&lt;br /&gt;
! All Pi's&lt;br /&gt;
! Pi 0/0W&lt;br /&gt;
! Other&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card&lt;br /&gt;
| Micro USB cable&lt;br /&gt;
| Ethernet Cable&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card Reader&lt;br /&gt;
| &lt;br /&gt;
| 3A or greater power micro USB power supply&lt;br /&gt;
|-&lt;br /&gt;
| Computer with USB port&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
Using a Raspberry Pi for the first time can be intimidating, but over time (and countless flashing of software) you will realise it's quite easy! In general, it consists of the following steps:&lt;br /&gt;
# Install the operating system&lt;br /&gt;
# Adjust configuration for the first boot&lt;br /&gt;
# Upon first boot, validate settings and update any other configurations&lt;br /&gt;
&lt;br /&gt;
== Using the Pi Imager ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Plug your SD card in to your machine.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select your image, select the correct SD card, and select &amp;quot;Write&amp;quot;. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The tool will process the image and write it to the SD card.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
== Using seperate tools ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Preparing the SD Card &amp;lt;/br&amp;gt;&lt;br /&gt;
Plug your SD card in to your machine and format it. On Windows, this can be done using the SD Card Formatter linked in the Software Requirements section. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Burn the image to the SD card &amp;lt;/br&amp;gt;&lt;br /&gt;
Open Etcher. Select the downloaded zip image, and the SD card, and format. At the end of format, it may read that it failed, but don’t worry. &amp;lt;strong&amp;gt;Ignore the Windows popups about needing to format the SD card.&amp;lt;/strong&amp;gt; Upon completion, Windows will try to mount partitions on the SD card that it can’t read. Just press “Cancel” and then “OK” to the dialog boxes that pop up. The boot partition is the only partition we will be dealing with. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Enabling Connectivity =&lt;br /&gt;
The form of connectivity you use depends on the Raspberry Pi you are using. However, there are some steps which are applicable to all Raspberry Pis.&lt;br /&gt;
Before starting, disconnect and reconnect the SD card to ensure it is mounted correctly.&lt;br /&gt;
== SSH ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open the partition called &amp;quot;boot&amp;quot;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a file '''without a file extension''' called &amp;quot;ssh&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To show file extensions on Windows, click &amp;quot;View&amp;quot; and then &amp;quot;File name extensions&amp;quot;. &lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information on the general use of SSH can be found in [[Network Protocols]].&lt;br /&gt;
&lt;br /&gt;
== Configure Networking ==&lt;br /&gt;
Which network connectivity you decide to enable is up to your use case and the the Raspberry Pi model you're using. However, we'll cover the basics for general WiFi, Ethernet over USB for the Pi Zero, and Ethernet on other Pi models. To learn more about connectivity on the Pi, read through [[RaspberryPi:Networking]].&lt;br /&gt;
=== General Wifi Connectivity ===&lt;br /&gt;
You can enable WiFi connectivity before first boot by adding a wpa_supplicant file to the boot partition.&lt;br /&gt;
Simply open the boot partition and create a file called &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt;. The contents would be the same as described at [[RaspberryPi:Networking]]&lt;br /&gt;
&lt;br /&gt;
If you've already got access to the Pi, you can run &amp;lt;code&amp;gt;sudo raspi-config&amp;lt;/code&amp;gt; to configure wifi through command prompts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For details on connecting the Pi to Eduroam, visit [[RaspberryPi:AdvancedConnectivity]]&lt;br /&gt;
&lt;br /&gt;
=== Static IP for Pi with Ethernet ===&lt;br /&gt;
When using an Ethernet connection, it can be beneficial to assign a static IP to the Ethernet port on the Pi. This however requires knowledge of subnets and IP addresses. For information on this, see [[RaspberryPi:AdvancedConnectivity#Static_IPs]]&lt;br /&gt;
&lt;br /&gt;
=== SSH over USB for Pi 0/0W ===&lt;br /&gt;
When using a Pi 0 or 0W, using the on-board USB as a connection for SSH is very useful. It means just a single port is required for all access to the Pi, so long as you're not doing anything that requires too much current. To see details on setting up Ethernet over USB on the Raspberry Pi, visit [[RaspberryPi:Networking#Using_USB_connectivity_on_the_Pi_0.2F0W]].&lt;br /&gt;
&lt;br /&gt;
= First Boot = &lt;br /&gt;
&amp;lt;li&amp;gt;Boot&amp;lt;br&amp;gt;&lt;br /&gt;
Insert the SD Card into the Pi, and power it on.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Ensure Connectivity &amp;lt;br&amp;gt;&lt;br /&gt;
Try and ping the Pi's static IP, or view COM Port connections if you are using the Pi Zero Serial option. For example, &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see a response similar to&lt;br /&gt;
&amp;lt;pre&amp;gt; $ 64 bytes from 192.168.137.15: icmp_seq=1 ttl=64 time=0.557 ms&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt; $ Reply from 192.168.137.15 bytes=32 time=0.5ms TTL=52&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; SSH In to your Pi &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ ssh pi@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You will be asked to add the machine to known hosts. Select yes. The default password for Raspbian is simply &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Change your password&amp;lt;br&amp;gt;&lt;br /&gt;
To change your password, you can simply run &amp;lt;pre&amp;gt;$ passwd &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Enable Services &amp;lt;br&amp;gt;&lt;br /&gt;
It's a good idea to enable useful services on the Pi.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On your Pi, run &amp;lt;pre&amp;gt; $ sudo raspi-config&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to &amp;quot;Interfacing Options&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If not enabled, enable SSH, VNC, SPI, I2C and Serial&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save and exit raspi-config by using the left and right arrow keys to jump to the bottom buttons. Your Pi will reboot.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Expand the Filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
The Rasberry Pi Installation may not make use of the full SD card. In order to give yourself as much file space as you have access to, you need to expand the filesystem.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;SSH into the Pi&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run &amp;lt;pre&amp;gt; $ sudo raspi-config &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to “Advanced Options&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select &amp;quot;Expand Filesystem&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will be shown a message saying that the root partition has been resized. Select “Ok”, then “Finish” then “Yes” to reboot your Pi.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= More detailed Information =&lt;br /&gt;
If you need more detailed information on how to configure the SD card when using a different operating system (such as Mac), visit the [https://www.raspberrypi.org/documentation/installation/installing-images/README.md Raspberry Pi Website]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=429</id>
		<title>RaspberryPi:Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=429"/>
		<updated>2020-09-04T11:00:58Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Hardware Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
In order to use the Pi you need to install an operating system on it and set up networking. You will then configure the networking settings on your Pi to allow you to access the Pi using SSH. &lt;br /&gt;
&lt;br /&gt;
This process will follow headless installation, as we are going to assume most students do not have access to spare screens, keyboards and mouses for the Pi. Headless mode on the Raspberry Pi refers to using it without direct user input and output (essentially no screen, mouse or keyboard connected directly to it). &lt;br /&gt;
&lt;br /&gt;
= Prerequisites =&lt;br /&gt;
== Software Requirements ==&lt;br /&gt;
'''Note''': Recently, the Pi Foundation released an imager tool which can be run from multiple operating systems and also has support for a selection of operating systems which can be installed on the Raspberry Pi. you can downlaod this tool from [https://www.raspberrypi.org/downloads/ here]. It will automatically download the selected operating system for your Raspberry Pi too, or allow you to select one you have already downloaded and have stored on local storage.&lt;br /&gt;
&lt;br /&gt;
If you'd prefer not to use the Pi Foundation imager, you'll need the following tools:&lt;br /&gt;
* An operating system image. It's recommended you use [https://www.raspberrypi.org/downloads/raspberry-pi-os/ Raspberry Pi OS]. You can read more about operating systems for the Pi on [http://wiki.ee.uct.ac.za/RaspberryPi:Overview#OperatingSystems this page]&lt;br /&gt;
* Something to allow you to SSH in to your Pi. On Windows you can use [http://wiki.ee.uct.ac.za/PuTTY PuTTY] or [http://wiki.ee.uct.ac.za/Windows_Subsystem_for_Linux WSL]&lt;br /&gt;
* On Windows, you will need an [https://www.sdcard.org/downloads/formatter\_4/eula\_windows/index.html SD Card Formatter]&lt;br /&gt;
* On Windows, you will require software to burn the image. [https://www.balena.io/etcher/ Balena Etcher] is recommended.&lt;br /&gt;
&lt;br /&gt;
== Hardware Requirements ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|- style=&amp;quot;font-weight:bold;&amp;quot;&lt;br /&gt;
! All Pi's&lt;br /&gt;
! Pi 0/0W&lt;br /&gt;
! Other&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card&lt;br /&gt;
| Micro USB cable&lt;br /&gt;
| Ethernet Cable&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card Reader&lt;br /&gt;
| &lt;br /&gt;
| 3A or greater power micro USB power supply&lt;br /&gt;
|-&lt;br /&gt;
| Computer with USB port&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
Using a Raspberry Pi for the first time can be intimidating, but over time (and countless flashing of software) you will realise it's quite easy! In general, it consists of the following steps:&lt;br /&gt;
# Install the operating system&lt;br /&gt;
# Adjust configuration for the first boot&lt;br /&gt;
# Upon first boot, validate settings and update any other configurations&lt;br /&gt;
&lt;br /&gt;
== Using the Pi Imager ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Plug your SD card in to your machine.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select your image, select the correct SD card, and select &amp;quot;Write&amp;quot;. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The tool will process the image and write it to the SD card.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
== Using seperate tools ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Preparing the SD Card &amp;lt;/br&amp;gt;&lt;br /&gt;
Plug your SD card in to your machine and format it. On Windows, this can be done using the SD Card Formatter linked in the Software Requirements section. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Burn the image to the SD card &amp;lt;/br&amp;gt;&lt;br /&gt;
Open Etcher. Select the downloaded zip image, and the SD card, and format. At the end of format, it may read that it failed, but don’t worry. &amp;lt;strong&amp;gt;Ignore the Windows popups about needing to format the SD card.&amp;lt;/strong&amp;gt; Upon completion, Windows will try to mount partitions on the SD card that it can’t read. Just press “Cancel” and then “OK” to the dialog boxes that pop up. The boot partition is the only partition we will be dealing with. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Enabling Connectivity =&lt;br /&gt;
The form of connectivity you use depends on the Raspberry Pi you are using. However, there are some steps which are applicable to all Raspberry Pis.&lt;br /&gt;
Before starting, disconnect and reconnect the SD card to ensure it is mounted correctly.&lt;br /&gt;
== SSH ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open the partition called &amp;quot;boot&amp;quot;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a file '''without a file extension''' called &amp;quot;ssh&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To show file extensions on Windows, click &amp;quot;View&amp;quot; and then &amp;quot;File name extensions&amp;quot;. &lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information on the general use of SSH can be found in [[Network Protocols]].&lt;br /&gt;
&lt;br /&gt;
== Configure Networking ==&lt;br /&gt;
Which network connectivity you decide to enable is up to your use case and the the Raspberry Pi model you're using. However, we'll cover the basics for general WiFi, Ethernet over USB for the Pi Zero, and Ethernet on other Pi models. To learn more about connectivity on the Pi, read through [[RaspberryPi:Networking]].&lt;br /&gt;
=== General Wifi Connectivity ===&lt;br /&gt;
You can enable WiFi connectivity before first boot by adding a wpa_supplicant file to the boot partition.&lt;br /&gt;
Simply open the boot partition and create a file called &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt;. The contents would be the same as described at [[RaspberryPi:Networking]]&lt;br /&gt;
&lt;br /&gt;
If you've already got access to the Pi, you can run &amp;lt;code&amp;gt;sudo raspi-config&amp;lt;/code&amp;gt; to configure wifi through command prompts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For details on connecting the Pi to Eduroam, visit [[RaspberryPi:AdvancedConnectivity]]&lt;br /&gt;
&lt;br /&gt;
=== Static IP for Pi with Ethernet ===&lt;br /&gt;
When using an Ethernet connection, it can be beneficial to assign a static IP to the Ethernet port on the Pi. This however requires knowledge of subnets and IP addresses. For information on this, see [[RaspberryPi:AdvancedConnectivity#Static_IPs]]&lt;br /&gt;
&lt;br /&gt;
=== SSH over USB for Pi 0/0W ===&lt;br /&gt;
When using a Pi 0 or 0W, using the on-board USB as a connection for SSH is very useful. It means just a single port is required for all access to the Pi, so long as you're not doing anything that requires too much current. To see details on setting up Ethernet over USB on the Raspberry Pi, visit [[RaspberryPi:Networking#Using_USB_connectivity_on_the_Pi_0.2F0W]].&lt;br /&gt;
&lt;br /&gt;
= First Boot = &lt;br /&gt;
&amp;lt;li&amp;gt;Boot&amp;lt;br&amp;gt;&lt;br /&gt;
Insert the SD Card into the Pi, and power it on.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Ensure Connectivity &amp;lt;br&amp;gt;&lt;br /&gt;
Try and ping the Pi's static IP, or view COM Port connections if you are using the Pi Zero Serial option. For example, &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see a response similar to&lt;br /&gt;
&amp;lt;pre&amp;gt; $ 64 bytes from 192.168.137.15: icmp_seq=1 ttl=64 time=0.557 ms&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt; $ Reply from 192.168.137.15 bytes=32 time=0.5ms TTL=52&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; SSH In to your Pi &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ ssh pi@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You will be asked to add the machine to known hosts. Select yes. The default password for Raspbian is simply &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Change your password&amp;lt;br&amp;gt;&lt;br /&gt;
To change your password, you can simply run &amp;lt;pre&amp;gt;$ passwd &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Enable Services &amp;lt;br&amp;gt;&lt;br /&gt;
It's a good idea to enable useful services on the Pi.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On your Pi, run &amp;lt;pre&amp;gt; $ sudo raspi-config&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to &amp;quot;Interfacing Options&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If not enabled, enable SSH, VNC, SPI, I2C and Serial&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save and exit raspi-config by using the left and right arrow keys to jump to the bottom buttons. Your Pi will reboot.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Expand the Filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
The Rasberry Pi Installation may not make use of the full SD card. In order to give yourself as much file space as you have access to, you need to expand the filesystem.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;SSH into the Pi&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run &amp;lt;pre&amp;gt; $ sudo raspi-config &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to “Advanced Options&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select &amp;quot;Expand Filesystem&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will be shown a message saying that the root partition has been resized. Select “Ok”, then “Finish” then “Yes” to reboot your Pi.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= More detailed Information =&lt;br /&gt;
If you need more detailed information on how to configure the SD card when using a different operating system (such as Mac), visit the [https://www.raspberrypi.org/documentation/installation/installing-images/README.md Raspberry Pi Website]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=Unix_Shell_(Terminal)&amp;diff=428</id>
		<title>Unix Shell (Terminal)</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=Unix_Shell_(Terminal)&amp;diff=428"/>
		<updated>2020-09-04T10:55:18Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Useful Commands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Software]]&lt;br /&gt;
= Overview =&lt;br /&gt;
Being able to use the Unix Shell and terminal commands is an invaluable skill, and a requirement for this course. Follow [https://swcarpentry.github.io/shell-novice/ this software carpentry link] for more learning resources.&lt;br /&gt;
&lt;br /&gt;
= Useful Commands =&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|- style=&amp;quot;font-weight:bold;&amp;quot;&lt;br /&gt;
! Command&lt;br /&gt;
! Description&lt;br /&gt;
|-&lt;br /&gt;
| ls&lt;br /&gt;
| List current files and folders in directory&lt;br /&gt;
|-&lt;br /&gt;
| ls -al&lt;br /&gt;
| List details about everything&lt;br /&gt;
|-&lt;br /&gt;
| pwd&lt;br /&gt;
| Print current (working) directory&lt;br /&gt;
|-&lt;br /&gt;
| cd &amp;lt;directory&amp;gt;&lt;br /&gt;
| Move into the specified directory&lt;br /&gt;
|-&lt;br /&gt;
| cd ..&lt;br /&gt;
| Move up one directory&lt;br /&gt;
|-&lt;br /&gt;
| ifconfig&lt;br /&gt;
| Shows details on current network interfaces (requires package net-tools to be installed)&lt;br /&gt;
|-&lt;br /&gt;
| touch &amp;lt;file&amp;gt;&lt;br /&gt;
| Creates a file. For example &amp;quot;touch.txt&amp;quot; will create a file in the directory you are in.&lt;br /&gt;
|-&lt;br /&gt;
| nano &amp;lt;file&amp;gt;&lt;br /&gt;
| Opens the specified file in nano, a text editor&lt;br /&gt;
|-&lt;br /&gt;
| mkdir &amp;lt;directory&amp;gt;&lt;br /&gt;
| Creates a directory&lt;br /&gt;
|-&lt;br /&gt;
| sudo &amp;lt;command&amp;gt;&lt;br /&gt;
| Executes &amp;lt;command&amp;gt; with super user privilages&lt;br /&gt;
|-&lt;br /&gt;
| man &amp;lt;command&amp;gt;&lt;br /&gt;
| Opens the user manual relating to the specified command&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:CMDOutput.png|frame|none|An example output of running some commands in the shell on a Raspberry Pi 3b+]]&lt;br /&gt;
&lt;br /&gt;
= Aliases = &lt;br /&gt;
Sometimes you may want to run long or complex commands. In this scenario, it can be useful to create an alias. This allows you to rename a command (or chain of commands) to an easier to type or remember command. An alias is a sort of shortcut, and it can be temporary or permanent. &lt;br /&gt;
&lt;br /&gt;
For example, the command &amp;lt;code&amp;gt;vcgencmd measure_temp&amp;lt;/code&amp;gt; on a Raspberry Pi will return the core temperature. However, this can be a tricky command to remember. So, let's create an alias.&lt;br /&gt;
For a temporary alias, you can just enter in &amp;lt;code&amp;gt;alias temp=&amp;quot;vcgencmd measure_temp&amp;quot;&amp;lt;/code&amp;gt; on the command line. This will allow you to type &amp;quot;temp&amp;quot; and get the temperature. However, this alias will expire when you end your session (log out). To create a permanent alias, the following is required.&lt;br /&gt;
&lt;br /&gt;
# Open .bash_profile: &amp;lt;code&amp;gt;nano ~/.bash_profile&amp;lt;/code&amp;gt;&lt;br /&gt;
# Add a line for the alias: &amp;lt;code&amp;gt;alias temp=&amp;quot;vcgencmd measure_temp&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
# Save and close the file&lt;br /&gt;
# Reload .bash_profile: &amp;lt;code&amp;gt;source ~/.bash_profile&amp;lt;/code&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=427</id>
		<title>RaspberryPi:Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=427"/>
		<updated>2020-09-01T08:51:15Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* General Wifi Connectivity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
In order to use the Pi you need to install an operating system on it and set up networking. You will then configure the networking settings on your Pi to allow you to access the Pi using SSH. &lt;br /&gt;
&lt;br /&gt;
This process will follow headless installation, as we are going to assume most students do not have access to spare screens, keyboards and mouses for the Pi. Headless mode on the Raspberry Pi refers to using it without direct user input and output (essentially no screen, mouse or keyboard connected directly to it). &lt;br /&gt;
&lt;br /&gt;
= Prerequisites =&lt;br /&gt;
== Software Requirements ==&lt;br /&gt;
'''Note''': Recently, the Pi Foundation released an imager tool which can be run from multiple operating systems and also has support for a selection of operating systems which can be installed on the Raspberry Pi. you can downlaod this tool from [https://www.raspberrypi.org/downloads/ here]. It will automatically download the selected operating system for your Raspberry Pi too, or allow you to select one you have already downloaded and have stored on local storage.&lt;br /&gt;
&lt;br /&gt;
If you'd prefer not to use the Pi Foundation imager, you'll need the following tools:&lt;br /&gt;
* An operating system image. It's recommended you use [https://www.raspberrypi.org/downloads/raspberry-pi-os/ Raspberry Pi OS]. You can read more about operating systems for the Pi on [http://wiki.ee.uct.ac.za/RaspberryPi:Overview#OperatingSystems this page]&lt;br /&gt;
* Something to allow you to SSH in to your Pi. On Windows you can use [http://wiki.ee.uct.ac.za/PuTTY PuTTY] or [http://wiki.ee.uct.ac.za/Windows_Subsystem_for_Linux WSL]&lt;br /&gt;
* On Windows, you will need an [https://www.sdcard.org/downloads/formatter\_4/eula\_windows/index.html SD Card Formatter]&lt;br /&gt;
* On Windows, you will require software to burn the image. [https://www.balena.io/etcher/ Balena Etcher] is recommended.&lt;br /&gt;
&lt;br /&gt;
== Hardware Requirements ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|- style=&amp;quot;font-weight:bold;&amp;quot;&lt;br /&gt;
! All Pi's&lt;br /&gt;
! Pi 0/0W&lt;br /&gt;
! Other (greater current requirements)&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card&lt;br /&gt;
| Micro USB cable&lt;br /&gt;
| Ethernet Cable&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card Reader&lt;br /&gt;
| &lt;br /&gt;
| 3A or greater power micro USB power supply&lt;br /&gt;
|-&lt;br /&gt;
| Computer with USB port&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
Using a Raspberry Pi for the first time can be intimidating, but over time (and countless flashing of software) you will realise it's quite easy! In general, it consists of the following steps:&lt;br /&gt;
# Install the operating system&lt;br /&gt;
# Adjust configuration for the first boot&lt;br /&gt;
# Upon first boot, validate settings and update any other configurations&lt;br /&gt;
&lt;br /&gt;
== Using the Pi Imager ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Plug your SD card in to your machine.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select your image, select the correct SD card, and select &amp;quot;Write&amp;quot;. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The tool will process the image and write it to the SD card.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
== Using seperate tools ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Preparing the SD Card &amp;lt;/br&amp;gt;&lt;br /&gt;
Plug your SD card in to your machine and format it. On Windows, this can be done using the SD Card Formatter linked in the Software Requirements section. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Burn the image to the SD card &amp;lt;/br&amp;gt;&lt;br /&gt;
Open Etcher. Select the downloaded zip image, and the SD card, and format. At the end of format, it may read that it failed, but don’t worry. &amp;lt;strong&amp;gt;Ignore the Windows popups about needing to format the SD card.&amp;lt;/strong&amp;gt; Upon completion, Windows will try to mount partitions on the SD card that it can’t read. Just press “Cancel” and then “OK” to the dialog boxes that pop up. The boot partition is the only partition we will be dealing with. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Enabling Connectivity =&lt;br /&gt;
The form of connectivity you use depends on the Raspberry Pi you are using. However, there are some steps which are applicable to all Raspberry Pis.&lt;br /&gt;
Before starting, disconnect and reconnect the SD card to ensure it is mounted correctly.&lt;br /&gt;
== SSH ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open the partition called &amp;quot;boot&amp;quot;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a file '''without a file extension''' called &amp;quot;ssh&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To show file extensions on Windows, click &amp;quot;View&amp;quot; and then &amp;quot;File name extensions&amp;quot;. &lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information on the general use of SSH can be found in [[Network Protocols]].&lt;br /&gt;
&lt;br /&gt;
== Configure Networking ==&lt;br /&gt;
Which network connectivity you decide to enable is up to your use case and the the Raspberry Pi model you're using. However, we'll cover the basics for general WiFi, Ethernet over USB for the Pi Zero, and Ethernet on other Pi models. To learn more about connectivity on the Pi, read through [[RaspberryPi:Networking]].&lt;br /&gt;
=== General Wifi Connectivity ===&lt;br /&gt;
You can enable WiFi connectivity before first boot by adding a wpa_supplicant file to the boot partition.&lt;br /&gt;
Simply open the boot partition and create a file called &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt;. The contents would be the same as described at [[RaspberryPi:Networking]]&lt;br /&gt;
&lt;br /&gt;
If you've already got access to the Pi, you can run &amp;lt;code&amp;gt;sudo raspi-config&amp;lt;/code&amp;gt; to configure wifi through command prompts.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For details on connecting the Pi to Eduroam, visit [[RaspberryPi:AdvancedConnectivity]]&lt;br /&gt;
&lt;br /&gt;
=== Static IP for Pi with Ethernet ===&lt;br /&gt;
When using an Ethernet connection, it can be beneficial to assign a static IP to the Ethernet port on the Pi. This however requires knowledge of subnets and IP addresses. For information on this, see [[RaspberryPi:AdvancedConnectivity#Static_IPs]]&lt;br /&gt;
&lt;br /&gt;
=== SSH over USB for Pi 0/0W ===&lt;br /&gt;
When using a Pi 0 or 0W, using the on-board USB as a connection for SSH is very useful. It means just a single port is required for all access to the Pi, so long as you're not doing anything that requires too much current. To see details on setting up Ethernet over USB on the Raspberry Pi, visit [[RaspberryPi:Networking#Using_USB_connectivity_on_the_Pi_0.2F0W]].&lt;br /&gt;
&lt;br /&gt;
= First Boot = &lt;br /&gt;
&amp;lt;li&amp;gt;Boot&amp;lt;br&amp;gt;&lt;br /&gt;
Insert the SD Card into the Pi, and power it on.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Ensure Connectivity &amp;lt;br&amp;gt;&lt;br /&gt;
Try and ping the Pi's static IP, or view COM Port connections if you are using the Pi Zero Serial option. For example, &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see a response similar to&lt;br /&gt;
&amp;lt;pre&amp;gt; $ 64 bytes from 192.168.137.15: icmp_seq=1 ttl=64 time=0.557 ms&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt; $ Reply from 192.168.137.15 bytes=32 time=0.5ms TTL=52&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; SSH In to your Pi &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ ssh pi@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You will be asked to add the machine to known hosts. Select yes. The default password for Raspbian is simply &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Change your password&amp;lt;br&amp;gt;&lt;br /&gt;
To change your password, you can simply run &amp;lt;pre&amp;gt;$ passwd &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Enable Services &amp;lt;br&amp;gt;&lt;br /&gt;
It's a good idea to enable useful services on the Pi.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On your Pi, run &amp;lt;pre&amp;gt; $ sudo raspi-config&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to &amp;quot;Interfacing Options&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If not enabled, enable SSH, VNC, SPI, I2C and Serial&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save and exit raspi-config by using the left and right arrow keys to jump to the bottom buttons. Your Pi will reboot.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Expand the Filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
The Rasberry Pi Installation may not make use of the full SD card. In order to give yourself as much file space as you have access to, you need to expand the filesystem.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;SSH into the Pi&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run &amp;lt;pre&amp;gt; $ sudo raspi-config &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to “Advanced Options&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select &amp;quot;Expand Filesystem&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will be shown a message saying that the root partition has been resized. Select “Ok”, then “Finish” then “Yes” to reboot your Pi.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= More detailed Information =&lt;br /&gt;
If you need more detailed information on how to configure the SD card when using a different operating system (such as Mac), visit the [https://www.raspberrypi.org/documentation/installation/installing-images/README.md Raspberry Pi Website]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=HDL_Simulation&amp;diff=426</id>
		<title>HDL Simulation</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=HDL_Simulation&amp;diff=426"/>
		<updated>2020-08-28T07:11:05Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* iVerilog */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: FPGAs]]&lt;br /&gt;
[[Category: Software]]&lt;br /&gt;
&lt;br /&gt;
When creating HDL designs, simulation can be used to verify your logic (behavioral simulation) or ensure you meet timing constraints (timing simulation). This page covers some useful information on writing testbenches, as well simulators that are used in the department (and in some cases, instructions on how to use them). While there are of course many simulators, the ones below are used by academics, staff and researchers in the department.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Testbenches =&lt;br /&gt;
Testbenches in HDL are modules that instantiate other modules.&lt;br /&gt;
&lt;br /&gt;
= Testbenches in Verilog = &lt;br /&gt;
Testbenches in Verilog are simply modules that instantiate the DUT, control the inputs, and monitor the outputs accordingly. They usually contain a single DUT, an initial block to set starting conditions, and an always block to run the testbench. The general approach for a DUT is to use registers for inputs and wires for outputs. Of course there is much more to testbenches than that, but that is the short of it.&lt;br /&gt;
&lt;br /&gt;
For example, take a module called ModuleToTest that is meant to display switch values on LEDs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
`timescale 1ns / 1ps  // Set time and precision&lt;br /&gt;
&lt;br /&gt;
module testbench();&lt;br /&gt;
&lt;br /&gt;
// Define our inputs and outputs&lt;br /&gt;
reg clk;&lt;br /&gt;
reg [3:0] switches;&lt;br /&gt;
wire [7:0] leds;&lt;br /&gt;
&lt;br /&gt;
// Instantiate the device under test&lt;br /&gt;
ModuleToTest DUT(clk, switches, leds);&lt;br /&gt;
&lt;br /&gt;
// Set initial conditions&lt;br /&gt;
initial &lt;br /&gt;
begin&lt;br /&gt;
    clk &amp;lt;= 1;&lt;br /&gt;
    switches &amp;lt;= 0;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
//toggle the clock&lt;br /&gt;
always begin&lt;br /&gt;
    #5 clk = ~clk;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
endmodule&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Verilog Testbench Directives ==&lt;br /&gt;
Verilog directives allow you to do things which are not usually possible in hardware, only through simulation. This includes printing data to a screen, loading data from a text file, or stopping the simulation.&lt;br /&gt;
&lt;br /&gt;
For a quick reference list of commands, see [http://www.techsystemsembedded.com/verilog_testbench.php this link].&lt;br /&gt;
&lt;br /&gt;
= Available Simulators =&lt;br /&gt;
The following is a collection of some HDL simulators used in the department.&lt;br /&gt;
== iVerilog ==&lt;br /&gt;
See [http://www.referencedesigner.com/tutorials/verilog/verilog_02.php this link] for a tutorial on iVerilog.&lt;br /&gt;
&lt;br /&gt;
== EDAPlayground ==&lt;br /&gt;
&lt;br /&gt;
== Vivado ==&lt;br /&gt;
The Vivado Simulator comes as a part of the Vivado IDE. For details on the Vivado IDE, see [[Xilinx Vivado]]. For details specific to Vivado, you can find a video on simulation [https://www.youtube.com/watch?v=Cb5LRi5scMw here]. &lt;br /&gt;
&lt;br /&gt;
Once you begin writing your modules you need to check that they’re working. You can do this through simulation.&lt;br /&gt;
&lt;br /&gt;
Once you’ve synthesized your project, you should be able to click “Run simulation”.&lt;br /&gt;
&lt;br /&gt;
This will only run a simulation of your top module. It is far more useful to create a testbench.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click &amp;quot;Simulation Sources&amp;quot; and Select &amp;quot;Add new&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
In the dialog box, ensure Simulation sources is selected.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Create it in a new simulation set, and use the checkbox to set it as active&amp;lt;br&amp;gt;&lt;br /&gt;
You can toggle which simulation source is active by setting it in the same way you'd set your top level module under design sources - just right click on the simulation source and select &amp;quot;Make active&amp;quot;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Create a file for your testbench&amp;lt;br&amp;gt;&lt;br /&gt;
It's a good idea to name it the same as the module you're testing, followed by a &amp;quot;_tb&amp;quot; to distinguish it. For example, if you're creating a test bench for a clock, you might call the file &amp;quot;clock_tb&amp;quot;. This file will appear under &amp;quot;non module sources&amp;quot; in the simulation set until you add some code to it.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Add basic TB code to the modele&amp;lt;br&amp;gt;&lt;br /&gt;
A super simple testbench consists of a generated clock and an instantiation of the module you're testing. Add the simple clock generation code, save the file, and set it as top in the simulation source. See the example above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;You should now be able to instantiate modules and run behavioral simulations to ensure your design works. You can connect the modules in such a way to minic switches by setting register values and using delay constructs.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=425</id>
		<title>RaspberryPi:Installation</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Installation&amp;diff=425"/>
		<updated>2020-08-24T23:52:44Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* SSH over USB for Pi 0/0W */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
In order to use the Pi you need to install an operating system on it and set up networking. You will then configure the networking settings on your Pi to allow you to access the Pi using SSH. &lt;br /&gt;
&lt;br /&gt;
This process will follow headless installation, as we are going to assume most students do not have access to spare screens, keyboards and mouses for the Pi. Headless mode on the Raspberry Pi refers to using it without direct user input and output (essentially no screen, mouse or keyboard connected directly to it). &lt;br /&gt;
&lt;br /&gt;
= Prerequisites =&lt;br /&gt;
== Software Requirements ==&lt;br /&gt;
'''Note''': Recently, the Pi Foundation released an imager tool which can be run from multiple operating systems and also has support for a selection of operating systems which can be installed on the Raspberry Pi. you can downlaod this tool from [https://www.raspberrypi.org/downloads/ here]. It will automatically download the selected operating system for your Raspberry Pi too, or allow you to select one you have already downloaded and have stored on local storage.&lt;br /&gt;
&lt;br /&gt;
If you'd prefer not to use the Pi Foundation imager, you'll need the following tools:&lt;br /&gt;
* An operating system image. It's recommended you use [https://www.raspberrypi.org/downloads/raspberry-pi-os/ Raspberry Pi OS]. You can read more about operating systems for the Pi on [http://wiki.ee.uct.ac.za/RaspberryPi:Overview#OperatingSystems this page]&lt;br /&gt;
* Something to allow you to SSH in to your Pi. On Windows you can use [http://wiki.ee.uct.ac.za/PuTTY PuTTY] or [http://wiki.ee.uct.ac.za/Windows_Subsystem_for_Linux WSL]&lt;br /&gt;
* On Windows, you will need an [https://www.sdcard.org/downloads/formatter\_4/eula\_windows/index.html SD Card Formatter]&lt;br /&gt;
* On Windows, you will require software to burn the image. [https://www.balena.io/etcher/ Balena Etcher] is recommended.&lt;br /&gt;
&lt;br /&gt;
== Hardware Requirements ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|- style=&amp;quot;font-weight:bold;&amp;quot;&lt;br /&gt;
! All Pi's&lt;br /&gt;
! Pi 0/0W&lt;br /&gt;
! Other (greater current requirements)&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card&lt;br /&gt;
| Micro USB cable&lt;br /&gt;
| Ethernet Cable&lt;br /&gt;
|-&lt;br /&gt;
| Micro SD Card Reader&lt;br /&gt;
| &lt;br /&gt;
| 3A or greater power micro USB power supply&lt;br /&gt;
|-&lt;br /&gt;
| Computer with USB port&lt;br /&gt;
| &lt;br /&gt;
| &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
Using a Raspberry Pi for the first time can be intimidating, but over time (and countless flashing of software) you will realise it's quite easy! In general, it consists of the following steps:&lt;br /&gt;
# Install the operating system&lt;br /&gt;
# Adjust configuration for the first boot&lt;br /&gt;
# Upon first boot, validate settings and update any other configurations&lt;br /&gt;
&lt;br /&gt;
== Using the Pi Imager ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Plug your SD card in to your machine.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select your image, select the correct SD card, and select &amp;quot;Write&amp;quot;. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;The tool will process the image and write it to the SD card.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
== Using seperate tools ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Preparing the SD Card &amp;lt;/br&amp;gt;&lt;br /&gt;
Plug your SD card in to your machine and format it. On Windows, this can be done using the SD Card Formatter linked in the Software Requirements section. &amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; Burn the image to the SD card &amp;lt;/br&amp;gt;&lt;br /&gt;
Open Etcher. Select the downloaded zip image, and the SD card, and format. At the end of format, it may read that it failed, but don’t worry. &amp;lt;strong&amp;gt;Ignore the Windows popups about needing to format the SD card.&amp;lt;/strong&amp;gt; Upon completion, Windows will try to mount partitions on the SD card that it can’t read. Just press “Cancel” and then “OK” to the dialog boxes that pop up. The boot partition is the only partition we will be dealing with. &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Enabling Connectivity =&lt;br /&gt;
The form of connectivity you use depends on the Raspberry Pi you are using. However, there are some steps which are applicable to all Raspberry Pis.&lt;br /&gt;
Before starting, disconnect and reconnect the SD card to ensure it is mounted correctly.&lt;br /&gt;
== SSH ==&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Open the partition called &amp;quot;boot&amp;quot;&lt;br /&gt;
&amp;lt;li&amp;gt; Create a file '''without a file extension''' called &amp;quot;ssh&amp;quot;.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; To show file extensions on Windows, click &amp;quot;View&amp;quot; and then &amp;quot;File name extensions&amp;quot;. &lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
More information on the general use of SSH can be found in [[Network Protocols]].&lt;br /&gt;
&lt;br /&gt;
== Configure Networking ==&lt;br /&gt;
Which network connectivity you decide to enable is up to your use case and the the Raspberry Pi model you're using. However, we'll cover the basics for general WiFi, Ethernet over USB for the Pi Zero, and Ethernet on other Pi models. To learn more about connectivity on the Pi, read through [[RaspberryPi:Networking]].&lt;br /&gt;
=== General Wifi Connectivity ===&lt;br /&gt;
You can enable WiFi connectivity before first boot by adding a wpa_supplicant file to the boot partition.&lt;br /&gt;
Simply open the boot partition and create a file called &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt;. The contents would be the same as described at&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For details on connecting the Pi to Eduroam, visit [[RaspberryPi:AdvancedConnectivity]]&lt;br /&gt;
&lt;br /&gt;
=== Static IP for Pi with Ethernet ===&lt;br /&gt;
When using an Ethernet connection, it can be beneficial to assign a static IP to the Ethernet port on the Pi. This however requires knowledge of subnets and IP addresses. For information on this, see [[RaspberryPi:AdvancedConnectivity#Static_IPs]]&lt;br /&gt;
&lt;br /&gt;
=== SSH over USB for Pi 0/0W ===&lt;br /&gt;
When using a Pi 0 or 0W, using the on-board USB as a connection for SSH is very useful. It means just a single port is required for all access to the Pi, so long as you're not doing anything that requires too much current. To see details on setting up Ethernet over USB on the Raspberry Pi, visit [[RaspberryPi:Networking#Using_USB_connectivity_on_the_Pi_0.2F0W]].&lt;br /&gt;
&lt;br /&gt;
= First Boot = &lt;br /&gt;
&amp;lt;li&amp;gt;Boot&amp;lt;br&amp;gt;&lt;br /&gt;
Insert the SD Card into the Pi, and power it on.&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Ensure Connectivity &amp;lt;br&amp;gt;&lt;br /&gt;
Try and ping the Pi's static IP, or view COM Port connections if you are using the Pi Zero Serial option. For example, &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You should see a response similar to&lt;br /&gt;
&amp;lt;pre&amp;gt; $ 64 bytes from 192.168.137.15: icmp_seq=1 ttl=64 time=0.557 ms&amp;lt;/pre&amp;gt;&lt;br /&gt;
or&lt;br /&gt;
&amp;lt;pre&amp;gt; $ Reply from 192.168.137.15 bytes=32 time=0.5ms TTL=52&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt; SSH In to your Pi &amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ ssh pi@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
You will be asked to add the machine to known hosts. Select yes. The default password for Raspbian is simply &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Change your password&amp;lt;br&amp;gt;&lt;br /&gt;
To change your password, you can simply run &amp;lt;pre&amp;gt;$ passwd &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Enable Services &amp;lt;br&amp;gt;&lt;br /&gt;
It's a good idea to enable useful services on the Pi.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On your Pi, run &amp;lt;pre&amp;gt; $ sudo raspi-config&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to &amp;quot;Interfacing Options&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;If not enabled, enable SSH, VNC, SPI, I2C and Serial&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Save and exit raspi-config by using the left and right arrow keys to jump to the bottom buttons. Your Pi will reboot.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Expand the Filesystem &amp;lt;br&amp;gt;&lt;br /&gt;
The Rasberry Pi Installation may not make use of the full SD card. In order to give yourself as much file space as you have access to, you need to expand the filesystem.&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;SSH into the Pi&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run &amp;lt;pre&amp;gt; $ sudo raspi-config &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Use the arrow keys and scroll down to “Advanced Options&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Select &amp;quot;Expand Filesystem&amp;quot;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;You will be shown a message saying that the root partition has been resized. Select “Ok”, then “Finish” then “Yes” to reboot your Pi.&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= More detailed Information =&lt;br /&gt;
If you need more detailed information on how to configure the SD card when using a different operating system (such as Mac), visit the [https://www.raspberrypi.org/documentation/installation/installing-images/README.md Raspberry Pi Website]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=424</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=424"/>
		<updated>2020-08-20T10:55:08Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Using USB connectivity on the Pi 0/0W */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
There are two sorts of Ethernet Connectivity we will consider. The first is just connecting the Pi to a known Ethernet network. It is simple as it requires no configuration, but it means you will need to use other methods to ensure the network allows SSH traffic and to ensure you can determine the IP of the Pi.&lt;br /&gt;
&lt;br /&gt;
The second is using Ethernet passthrough from your computer to the Raspberry Pi. This leaves the WiFi free to host your own access point, and you can host services such as a Node-Red server or media center on the Pi.&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi to a router will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi.&lt;br /&gt;
&lt;br /&gt;
== TTL over USB ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The Pi uses 3.3V logic levels. Using a 5V logic module will permanently damage the pins.&lt;br /&gt;
&lt;br /&gt;
This option allows you to use a USB to UART converter such as a FT232R or CP2102. Begin by removing the SD card, and insert it into a computer. Make the following changes on the boot partition:&lt;br /&gt;
&lt;br /&gt;
cmdline.txt: add the following (on the same line)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;console=serial0,115200 &amp;lt;/pre&amp;gt;&lt;br /&gt;
config.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uart_enable=1&lt;br /&gt;
dtoverlay=pi3-disable-bt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using USB connectivity on the Pi 0/0W ==&lt;br /&gt;
In order to use this method on Windows you require [https://support.apple.com/kb/DL999?locale=en_US Apple Bonjour Print Services] as well as [https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html PuTTY].&lt;br /&gt;
&lt;br /&gt;
With the SD card plugged into your computer, open up the boot partition and make the following changes:&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Be sure to enable SSH as described at [[RaspberryPi:Networking#Enabling_SSH]]&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;At the bottom of config.txt, add the following line &lt;br /&gt;
&amp;lt;pre&amp;gt;dtoverlay=dwc2&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;On the '''same line''' in cmdline.txt, append the following: &lt;br /&gt;
&amp;lt;pre&amp;gt; modules-load=dwc2,g_ether&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Open up a terminal window (or PuTTY if you're on Windows).&lt;br /&gt;
After about 90 or so seconds, you should be able to SSH in (assuming you enabled SSH on the Pi) by connecting to &amp;lt;code&amp;gt;raspberrypi.local&amp;lt;/code&amp;gt;.&lt;br /&gt;
You may (if you're using PuTTY) get a message about keys and hashes and hosts - just click &amp;quot;yes&amp;quot;.&lt;br /&gt;
You can then log in with the username &amp;quot;pi&amp;quot; and the password &amp;quot;raspberry&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=HDL_Simulation&amp;diff=423</id>
		<title>HDL Simulation</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=HDL_Simulation&amp;diff=423"/>
		<updated>2020-08-20T10:39:10Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Available Simulators */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category: FPGAs]]&lt;br /&gt;
[[Category: Software]]&lt;br /&gt;
&lt;br /&gt;
When creating HDL designs, simulation can be used to verify your logic (behavioral simulation) or ensure you meet timing constraints (timing simulation). This page covers some useful information on writing testbenches, as well simulators that are used in the department (and in some cases, instructions on how to use them). While there are of course many simulators, the ones below are used by academics, staff and researchers in the department.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Testbenches =&lt;br /&gt;
Testbenches in HDL are modules that instantiate other modules.&lt;br /&gt;
&lt;br /&gt;
= Testbenches in Verilog = &lt;br /&gt;
Testbenches in Verilog are simply modules that instantiate the DUT, control the inputs, and monitor the outputs accordingly. They usually contain a single DUT, an initial block to set starting conditions, and an always block to run the testbench. The general approach for a DUT is to use registers for inputs and wires for outputs. Of course there is much more to testbenches than that, but that is the short of it.&lt;br /&gt;
&lt;br /&gt;
For example, take a module called ModuleToTest that is meant to display switch values on LEDs:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
`timescale 1ns / 1ps  // Set time and precision&lt;br /&gt;
&lt;br /&gt;
module testbench();&lt;br /&gt;
&lt;br /&gt;
// Define our inputs and outputs&lt;br /&gt;
reg clk;&lt;br /&gt;
reg [3:0] switches;&lt;br /&gt;
wire [7:0] leds;&lt;br /&gt;
&lt;br /&gt;
// Instantiate the device under test&lt;br /&gt;
ModuleToTest DUT(clk, switches, leds);&lt;br /&gt;
&lt;br /&gt;
// Set initial conditions&lt;br /&gt;
initial &lt;br /&gt;
begin&lt;br /&gt;
    clk &amp;lt;= 1;&lt;br /&gt;
    switches &amp;lt;= 0;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
//toggle the clock&lt;br /&gt;
always begin&lt;br /&gt;
    #5 clk = ~clk;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
endmodule&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Verilog Testbench Directives ==&lt;br /&gt;
Verilog directives allow you to do things which are not usually possible in hardware, only through simulation. This includes printing data to a screen, loading data from a text file, or stopping the simulation.&lt;br /&gt;
&lt;br /&gt;
For a quick reference list of commands, see [http://www.techsystemsembedded.com/verilog_testbench.php this link].&lt;br /&gt;
&lt;br /&gt;
= Available Simulators =&lt;br /&gt;
The following is a collection of some HDL simulators used in the department.&lt;br /&gt;
== iVerilog ==&lt;br /&gt;
&lt;br /&gt;
== EDAPlayground ==&lt;br /&gt;
&lt;br /&gt;
== Vivado ==&lt;br /&gt;
The Vivado Simulator comes as a part of the Vivado IDE. For details on the Vivado IDE, see [[Xilinx Vivado]]. For details specific to Vivado, you can find a video on simulation [https://www.youtube.com/watch?v=Cb5LRi5scMw here]. &lt;br /&gt;
&lt;br /&gt;
Once you begin writing your modules you need to check that they’re working. You can do this through simulation.&lt;br /&gt;
&lt;br /&gt;
Once you’ve synthesized your project, you should be able to click “Run simulation”.&lt;br /&gt;
&lt;br /&gt;
This will only run a simulation of your top module. It is far more useful to create a testbench.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Right click &amp;quot;Simulation Sources&amp;quot; and Select &amp;quot;Add new&amp;quot; &amp;lt;br&amp;gt;&lt;br /&gt;
In the dialog box, ensure Simulation sources is selected.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Create it in a new simulation set, and use the checkbox to set it as active&amp;lt;br&amp;gt;&lt;br /&gt;
You can toggle which simulation source is active by setting it in the same way you'd set your top level module under design sources - just right click on the simulation source and select &amp;quot;Make active&amp;quot;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Create a file for your testbench&amp;lt;br&amp;gt;&lt;br /&gt;
It's a good idea to name it the same as the module you're testing, followed by a &amp;quot;_tb&amp;quot; to distinguish it. For example, if you're creating a test bench for a clock, you might call the file &amp;quot;clock_tb&amp;quot;. This file will appear under &amp;quot;non module sources&amp;quot; in the simulation set until you add some code to it.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;Add basic TB code to the modele&amp;lt;br&amp;gt;&lt;br /&gt;
A super simple testbench consists of a generated clock and an instantiation of the module you're testing. Add the simple clock generation code, save the file, and set it as top in the simulation source. See the example above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;li&amp;gt;You should now be able to instantiate modules and run behavioral simulations to ensure your design works. You can connect the modules in such a way to minic switches by setting register values and using delay constructs.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=422</id>
		<title>HDL - FAQs</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=422"/>
		<updated>2020-08-19T07:53:50Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:FPGAs]]&lt;br /&gt;
As with any skill, the only way to improve and to grasp concepts is to practice. This page details some perspectives on writing HDL. They are mostly perspective based, and the way you conceptualize creating hardware may be different. In the same way that there are often many approaches to solving problems, there are many ways to implement solutions in hardware. However, they don't all work, and some are definitely better than others. The hope is that this page helps you to be able to better grasp writing HDL and how your thinking needs to change in order to understand how to solve the problems you're given.&lt;br /&gt;
&lt;br /&gt;
= How is HDL Different from Writing Software? = &lt;br /&gt;
Hardware Descriptor Languages (HDLs - most commonly VHDL or Verilog) is fundamentally different from the programming languages you’re used to. &lt;br /&gt;
&lt;br /&gt;
With writing software, you’re describing how to solve a problem. When writing HDL, you’re describing how hardware works. Ideally your description should be the description to a solution.&lt;br /&gt;
&lt;br /&gt;
When writing HDL you need to think about HOW the code translates to hardware. I find it helpful to think of my project as a breadboard, modules as IC’s, registers as, well, registers in the module, wires as connections between modules, and inputs/outputs as pins on the IC. Output registers are just registers tied directly to an “output pin”. It isn’t a perfect analogy of course - sometimes it makes more sense to think of the current module you’re in as the primary breadboard (but in that case I just imagine I’m designing the IC).&lt;br /&gt;
&lt;br /&gt;
= Why isn't this loop working as I expect? =&lt;br /&gt;
You can’t directly translate the constructs you’re used to in software to programming constructs in hardware. A good example is for loops. You may be tempted to use a for loop as a delay, but a for loop in hardware operates rather differently to a for loop in software. Think about how you might implement a for loop as you understand it – the easiest to do is have a register, incrementally increase that register’s value, and then perform your operation once that register reaches the desired value. Nandland (a great resource for all things FPGA) has a nice discussion on for loops in HDL (https://www.nandland.com/vhdl/examples/example-for-loop.html) but for the most part there’s no need to use a for loop, or any kind of loop for that matter.&lt;br /&gt;
&lt;br /&gt;
= Why is my code taking a long time to compile? = &lt;br /&gt;
“Compile” isn’t technically correct here – it’s synthesizing, converting to a netlist, and then creating a bitstream. But we all know what each other means, so I suppose it’s okay. This is usually quite a time consuming process, which is why testbenches and simulation are such a great and easy way of testing code changes before trying to run it on the board.&lt;br /&gt;
&lt;br /&gt;
Single core performance is really the biggest factor in synthesis. There is use for multicore, but a lot of the synthesis -&amp;gt; bitstream generation is mostly sequential (I’ve been told that the Altera/Intel tools only see about a 10% improvement when moving to the multicore/multi-threaded implementation of the synthesis tools). That probably makes a difference when creating projects that take hours to synthesize, but, for practicals and most applications, high performance PCs won’t really make all that much of a difference as most modern CPUs have similar enough single-core throughput (assuming a modern architecture).&lt;br /&gt;
&lt;br /&gt;
Memory (RAM) is also a big contributing factor, but according to https://www.xilinx.com/products/design-tools/vivado/memory.html the XC7A100T (the FPGA found on the Nexys A7) uses at MOST 3GB of RAM. An implementation of a simple wall clock display only requires about 700-800mb&lt;br /&gt;
&lt;br /&gt;
[https://xkcd.com/303/ Always relevant XKCD]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=421</id>
		<title>HDL - FAQs</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=421"/>
		<updated>2020-08-19T07:53:07Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As with any skill, the only way to improve and to grasp concepts is to practice. This page details some perspectives on writing HDL. They are mostly perspective based, and the way you conceptualize creating hardware may be different. In the same way that there are often many approaches to solving problems, there are many ways to implement solutions in hardware. However, they don't all work, and some are definitely better than others. The hope is that this page helps you to be able to better grasp writing HDL and how your thinking needs to change in order to understand how to solve the problems you're given.&lt;br /&gt;
&lt;br /&gt;
= How is HDL Different from Writing Software? = &lt;br /&gt;
Hardware Descriptor Languages (HDLs - most commonly VHDL or Verilog) is fundamentally different from the programming languages you’re used to. &lt;br /&gt;
&lt;br /&gt;
With writing software, you’re describing how to solve a problem. When writing HDL, you’re describing how hardware works. Ideally your description should be the description to a solution.&lt;br /&gt;
&lt;br /&gt;
When writing HDL you need to think about HOW the code translates to hardware. I find it helpful to think of my project as a breadboard, modules as IC’s, registers as, well, registers in the module, wires as connections between modules, and inputs/outputs as pins on the IC. Output registers are just registers tied directly to an “output pin”. It isn’t a perfect analogy of course - sometimes it makes more sense to think of the current module you’re in as the primary breadboard (but in that case I just imagine I’m designing the IC).&lt;br /&gt;
&lt;br /&gt;
= Why isn't this loop working as I expect? =&lt;br /&gt;
You can’t directly translate the constructs you’re used to in software to programming constructs in hardware. A good example is for loops. You may be tempted to use a for loop as a delay, but a for loop in hardware operates rather differently to a for loop in software. Think about how you might implement a for loop as you understand it – the easiest to do is have a register, incrementally increase that register’s value, and then perform your operation once that register reaches the desired value. Nandland (a great resource for all things FPGA) has a nice discussion on for loops in HDL (https://www.nandland.com/vhdl/examples/example-for-loop.html) but for the most part there’s no need to use a for loop, or any kind of loop for that matter.&lt;br /&gt;
&lt;br /&gt;
= Why is my code taking a long time to compile? = &lt;br /&gt;
“Compile” isn’t technically correct here – it’s synthesizing, converting to a netlist, and then creating a bitstream. But we all know what each other means, so I suppose it’s okay. This is usually quite a time consuming process, which is why testbenches and simulation are such a great and easy way of testing code changes before trying to run it on the board.&lt;br /&gt;
&lt;br /&gt;
Single core performance is really the biggest factor in synthesis. There is use for multicore, but a lot of the synthesis -&amp;gt; bitstream generation is mostly sequential (I’ve been told that the Altera/Intel tools only see about a 10% improvement when moving to the multicore/multi-threaded implementation of the synthesis tools). That probably makes a difference when creating projects that take hours to synthesize, but, for practicals and most applications, high performance PCs won’t really make all that much of a difference as most modern CPUs have similar enough single-core throughput (assuming a modern architecture).&lt;br /&gt;
&lt;br /&gt;
Memory (RAM) is also a big contributing factor, but according to https://www.xilinx.com/products/design-tools/vivado/memory.html the XC7A100T (the FPGA found on the Nexys A7) uses at MOST 3GB of RAM. An implementation of a simple wall clock display only requires about 700-800mb&lt;br /&gt;
&lt;br /&gt;
[https://xkcd.com/303/ Always relevant XKCD]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=420</id>
		<title>HDL - FAQs</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=420"/>
		<updated>2020-08-19T07:52:35Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;As with any skill, the only way to improve and to grasp concepts is to practice. This page details some perspectives on writing HDL. They are mostly perspective based, and the way you conceptualize creating hardware may be different. In the same way that there are often many approaches to solving problems, there are many ways to implement solutions in hardware. However, they don't all work, and some are definitely better than others. The hope is that this page helps you to be able &lt;br /&gt;
&lt;br /&gt;
= How is HDL Different from Writing Software? = &lt;br /&gt;
Hardware Descriptor Languages (HDLs - most commonly VHDL or Verilog) is fundamentally different from the programming languages you’re used to. &lt;br /&gt;
&lt;br /&gt;
With writing software, you’re describing how to solve a problem. When writing HDL, you’re describing how hardware works. Ideally your description should be the description to a solution.&lt;br /&gt;
&lt;br /&gt;
When writing HDL you need to think about HOW the code translates to hardware. I find it helpful to think of my project as a breadboard, modules as IC’s, registers as, well, registers in the module, wires as connections between modules, and inputs/outputs as pins on the IC. Output registers are just registers tied directly to an “output pin”. It isn’t a perfect analogy of course - sometimes it makes more sense to think of the current module you’re in as the primary breadboard (but in that case I just imagine I’m designing the IC).&lt;br /&gt;
&lt;br /&gt;
= Why isn't this loop working as I expect? =&lt;br /&gt;
You can’t directly translate the constructs you’re used to in software to programming constructs in hardware. A good example is for loops. You may be tempted to use a for loop as a delay, but a for loop in hardware operates rather differently to a for loop in software. Think about how you might implement a for loop as you understand it – the easiest to do is have a register, incrementally increase that register’s value, and then perform your operation once that register reaches the desired value. Nandland (a great resource for all things FPGA) has a nice discussion on for loops in HDL (https://www.nandland.com/vhdl/examples/example-for-loop.html) but for the most part there’s no need to use a for loop, or any kind of loop for that matter.&lt;br /&gt;
&lt;br /&gt;
= Why is my code taking a long time to compile? = &lt;br /&gt;
“Compile” isn’t technically correct here – it’s synthesizing, converting to a netlist, and then creating a bitstream. But we all know what each other means, so I suppose it’s okay. This is usually quite a time consuming process, which is why testbenches and simulation are such a great and easy way of testing code changes before trying to run it on the board.&lt;br /&gt;
&lt;br /&gt;
Single core performance is really the biggest factor in synthesis. There is use for multicore, but a lot of the synthesis -&amp;gt; bitstream generation is mostly sequential (I’ve been told that the Altera/Intel tools only see about a 10% improvement when moving to the multicore/multi-threaded implementation of the synthesis tools). That probably makes a difference when creating projects that take hours to synthesize, but, for practicals and most applications, high performance PCs won’t really make all that much of a difference as most modern CPUs have similar enough single-core throughput (assuming a modern architecture).&lt;br /&gt;
&lt;br /&gt;
Memory (RAM) is also a big contributing factor, but according to https://www.xilinx.com/products/design-tools/vivado/memory.html the XC7A100T (the FPGA found on the Nexys A7) uses at MOST 3GB of RAM. An implementation of a simple wall clock display only requires about 700-800mb&lt;br /&gt;
&lt;br /&gt;
[https://xkcd.com/303/ Always relevant XKCD]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=419</id>
		<title>HDL - FAQs</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=HDL_-_FAQs&amp;diff=419"/>
		<updated>2020-08-19T07:52:05Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: Created page with &amp;quot;=HDL= As with any skill, the only way to improve and to grasp concepts is to practice. This page details some perspectives on writing HDL. They are mostly perspective based, a...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=HDL=&lt;br /&gt;
As with any skill, the only way to improve and to grasp concepts is to practice. This page details some perspectives on writing HDL. They are mostly perspective based, and the way you conceptualize creating hardware may be different. In the same way that there are often many approaches to solving problems, there are many ways to implement solutions in hardware. However, they don't all work, and some are definitely better than others. The hope is that this page helps you to be able &lt;br /&gt;
&lt;br /&gt;
= How is HDL Different from Writing Software? = &lt;br /&gt;
Hardware Descriptor Languages (HDLs - most commonly VHDL or Verilog) is fundamentally different from the programming languages you’re used to. &lt;br /&gt;
&lt;br /&gt;
With writing software, you’re describing how to solve a problem. When writing HDL, you’re describing how hardware works. Ideally your description should be the description to a solution.&lt;br /&gt;
&lt;br /&gt;
When writing HDL you need to think about HOW the code translates to hardware. I find it helpful to think of my project as a breadboard, modules as IC’s, registers as, well, registers in the module, wires as connections between modules, and inputs/outputs as pins on the IC. Output registers are just registers tied directly to an “output pin”. It isn’t a perfect analogy of course - sometimes it makes more sense to think of the current module you’re in as the primary breadboard (but in that case I just imagine I’m designing the IC).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Why isn't this loop working as I expect? =&lt;br /&gt;
You can’t directly translate the constructs you’re used to in software to programming constructs in hardware. A good example is for loops. You may be tempted to use a for loop as a delay, but a for loop in hardware operates rather differently to a for loop in software. Think about how you might implement a for loop as you understand it – the easiest to do is have a register, incrementally increase that register’s value, and then perform your operation once that register reaches the desired value. Nandland (a great resource for all things FPGA) has a nice discussion on for loops in HDL (https://www.nandland.com/vhdl/examples/example-for-loop.html) but for the most part there’s no need to use a for loop, or any kind of loop for that matter.&lt;br /&gt;
&lt;br /&gt;
= Why is my code taking a long time to compile? = &lt;br /&gt;
“Compile” isn’t technically correct here – it’s synthesizing, converting to a netlist, and then creating a bitstream. But we all know what each other means, so I suppose it’s okay. This is usually quite a time consuming process, which is why testbenches and simulation are such a great and easy way of testing code changes before trying to run it on the board.&lt;br /&gt;
&lt;br /&gt;
Single core performance is really the biggest factor in synthesis. There is use for multicore, but a lot of the synthesis -&amp;gt; bitstream generation is mostly sequential (I’ve been told that the Altera/Intel tools only see about a 10% improvement when moving to the multicore/multi-threaded implementation of the synthesis tools). That probably makes a difference when creating projects that take hours to synthesize, but, for practicals and most applications, high performance PCs won’t really make all that much of a difference as most modern CPUs have similar enough single-core throughput (assuming a modern architecture).&lt;br /&gt;
&lt;br /&gt;
Memory (RAM) is also a big contributing factor, but according to https://www.xilinx.com/products/design-tools/vivado/memory.html the XC7A100T (the FPGA found on the Nexys A7) uses at MOST 3GB of RAM. An implementation of a simple wall clock display only requires about 700-800mb&lt;br /&gt;
&lt;br /&gt;
[https://xkcd.com/303/ Always relevant XKCD]&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:AdvancedConnectivity&amp;diff=418</id>
		<title>RaspberryPi:AdvancedConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:AdvancedConnectivity&amp;diff=418"/>
		<updated>2020-08-18T12:20:59Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Providing your Pi with wireless Internet Access */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
This page covers advanced connectivity options that you can use on the Raspberry Pi. While not always required, they can simplify and streamline the way you work with the Raspberry Pi. &lt;br /&gt;
&lt;br /&gt;
For issues with connectivity, visit [[RaspberryPi:DebuggingConnectivity]]&lt;br /&gt;
&lt;br /&gt;
= Configuring the Pi to Act as an Access Point =&lt;br /&gt;
&lt;br /&gt;
If you are hosting a server on the Raspberry Pi, or perhaps want to create a WiFi network for guests to connect to, the Pi can act as an access point. This guide comes from https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md and https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/ and will work with a Pi that has an Ethernet Port (though it it possible to mimic an Ethernet port on a Pi 0W over USB. A Pi 0 doesn't have WiFi so this wouldn't serve any purpose).&lt;br /&gt;
&lt;br /&gt;
Note that this WiFi connection will not provide internet access by bridging the Ethernet port (that’s something else entirely), but it works well for hosting services on the Pi, such as a Node-Red server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-AP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-AP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into the Pi, update, and reboot to ensure updates have taken place&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get dist-upgrade&lt;br /&gt;
$ sudo reboot&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Wait for the Pi to reboot, and reconnect via SSH. Install hostapd and dnsmasq&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get install hostapd dnsmasq&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Configure a static IP in dhcpcd&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Adjust the contents so that the wireless interface is described as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
static ip_address=192.168.4.1/24&lt;br /&gt;
nohook wpa_supplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close that file, and restart the dhcp service&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Run the following commands to create save the original dnsmasq, and create a new file which will be edited:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig&lt;br /&gt;
$ sudo nano /etc/dnsmasq.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Place the following in the now open file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface=wlan0&lt;br /&gt;
listen-address=192.168.4.1&lt;br /&gt;
dhcp-range=192.168.4.2,192.168.4.180,255.255.255.0,24h&lt;br /&gt;
server=8.8.8.8&lt;br /&gt;
domain-needed&lt;br /&gt;
bogus-priv&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Restart the dnsmasq service&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo systemctl reload dnsmasq&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Configure hostapd. Open up the configuration file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo nano /etc/hostapd/hostapd.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Place the following configuration in the file. Some assumptions are made about the technical aspects of it, but these are beyond the scope of this course. Note that network name and password '''do not''' have quotes around them.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface=wlan0&lt;br /&gt;
driver=nl80211&lt;br /&gt;
ssid=TestNetwork&lt;br /&gt;
hw_mode=g&lt;br /&gt;
channel=7&lt;br /&gt;
ieee80211n=1&lt;br /&gt;
wmm_enabled=1&lt;br /&gt;
macaddr_acl=0&lt;br /&gt;
auth_algs=1&lt;br /&gt;
ignore_broadcast_ssid=0&lt;br /&gt;
wpa=2&lt;br /&gt;
wpa_passphrase=TestNetwork&lt;br /&gt;
wpa_key_mgmt=WPA-PSK&lt;br /&gt;
wpa_pairwise=TKIP&lt;br /&gt;
rsn_pairwise=CCMP&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Next, the system needs to know where to find this configuration file. Open the configuration file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/default/hostapd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Find the line with “#DAEMON_CONF” and replace it with:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DAEMON_CONF=&amp;amp;quot;/etc/hostapd/hostapd.conf&amp;amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close this file.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Now enable and start hostapd:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo systemctl unmask hostapd&lt;br /&gt;
$ sudo systemctl enable hostapd&lt;br /&gt;
$ sudo systemctl start hostapd&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add routing and masquerade by opening sysctl:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/sysctl.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And uncomment this line by removing the preceding # symbol:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;net.ipv4.ip_forward=1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a masquerade, and save the iptables rule:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE&lt;br /&gt;
$ sudo sh -c &amp;amp;quot;iptables-save &amp;amp;gt; /etc/iptables.ipv4.nat&amp;amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit /etc/rc.local and add this just above “exit 0” to install these rules on boot.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/rc.local&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Place the following just above “exit 0” to install these rules on boot&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables-restore &amp;amp;lt; /etc/iptables.ipv4.nat&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:AdvancedConnectivity&amp;diff=417</id>
		<title>RaspberryPi:AdvancedConnectivity</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:AdvancedConnectivity&amp;diff=417"/>
		<updated>2020-08-18T12:20:51Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
= Overview =&lt;br /&gt;
This page covers advanced connectivity options that you can use on the Raspberry Pi. While not always required, they can simplify and streamline the way you work with the Raspberry Pi. &lt;br /&gt;
&lt;br /&gt;
For issues with connectivity, visit [[RaspberryPi:DebuggingConnectivity]]&lt;br /&gt;
&lt;br /&gt;
= Providing your Pi with wireless Internet Access =&lt;br /&gt;
&lt;br /&gt;
There are three possible methods of this that will be presented, each with it’s own advantages and disadvantages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The third involves connecting to a wireless network. We provide examples for private networks, and Eduroam. Note that if connected using Eduroam, some services may be limited based on ICTS policy, but, for the most part, everything should accessible &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Configuring the Pi to Act as an Access Point =&lt;br /&gt;
&lt;br /&gt;
If you are hosting a server on the Raspberry Pi, or perhaps want to create a WiFi network for guests to connect to, the Pi can act as an access point. This guide comes from https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md and https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/ and will work with a Pi that has an Ethernet Port (though it it possible to mimic an Ethernet port on a Pi 0W over USB. A Pi 0 doesn't have WiFi so this wouldn't serve any purpose).&lt;br /&gt;
&lt;br /&gt;
Note that this WiFi connection will not provide internet access by bridging the Ethernet port (that’s something else entirely), but it works well for hosting services on the Pi, such as a Node-Red server.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-AP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-AP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into the Pi, update, and reboot to ensure updates have taken place&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get dist-upgrade&lt;br /&gt;
$ sudo reboot&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Wait for the Pi to reboot, and reconnect via SSH. Install hostapd and dnsmasq&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get install hostapd dnsmasq&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Configure a static IP in dhcpcd&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Adjust the contents so that the wireless interface is described as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
static ip_address=192.168.4.1/24&lt;br /&gt;
nohook wpa_supplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close that file, and restart the dhcp service&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo systemctl restart dhcpcd&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Run the following commands to create save the original dnsmasq, and create a new file which will be edited:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig&lt;br /&gt;
$ sudo nano /etc/dnsmasq.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Place the following in the now open file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface=wlan0&lt;br /&gt;
listen-address=192.168.4.1&lt;br /&gt;
dhcp-range=192.168.4.2,192.168.4.180,255.255.255.0,24h&lt;br /&gt;
server=8.8.8.8&lt;br /&gt;
domain-needed&lt;br /&gt;
bogus-priv&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Restart the dnsmasq service&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo systemctl reload dnsmasq&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Configure hostapd. Open up the configuration file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;sudo nano /etc/hostapd/hostapd.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Place the following configuration in the file. Some assumptions are made about the technical aspects of it, but these are beyond the scope of this course. Note that network name and password '''do not''' have quotes around them.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface=wlan0&lt;br /&gt;
driver=nl80211&lt;br /&gt;
ssid=TestNetwork&lt;br /&gt;
hw_mode=g&lt;br /&gt;
channel=7&lt;br /&gt;
ieee80211n=1&lt;br /&gt;
wmm_enabled=1&lt;br /&gt;
macaddr_acl=0&lt;br /&gt;
auth_algs=1&lt;br /&gt;
ignore_broadcast_ssid=0&lt;br /&gt;
wpa=2&lt;br /&gt;
wpa_passphrase=TestNetwork&lt;br /&gt;
wpa_key_mgmt=WPA-PSK&lt;br /&gt;
wpa_pairwise=TKIP&lt;br /&gt;
rsn_pairwise=CCMP&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Next, the system needs to know where to find this configuration file. Open the configuration file:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/default/hostapd&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Find the line with “#DAEMON_CONF” and replace it with:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;DAEMON_CONF=&amp;amp;quot;/etc/hostapd/hostapd.conf&amp;amp;quot;&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close this file.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Now enable and start hostapd:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo systemctl unmask hostapd&lt;br /&gt;
$ sudo systemctl enable hostapd&lt;br /&gt;
$ sudo systemctl start hostapd&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add routing and masquerade by opening sysctl:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/sysctl.conf&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And uncomment this line by removing the preceding # symbol:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;net.ipv4.ip_forward=1&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Save and close the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Add a masquerade, and save the iptables rule:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE&lt;br /&gt;
$ sudo sh -c &amp;amp;quot;iptables-save &amp;amp;gt; /etc/iptables.ipv4.nat&amp;amp;quot;&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit /etc/rc.local and add this just above “exit 0” to install these rules on boot.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/rc.local&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Place the following just above “exit 0” to install these rules on boot&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;iptables-restore &amp;amp;lt; /etc/iptables.ipv4.nat&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=416</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=416"/>
		<updated>2020-08-18T12:19:03Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Ethernet Connectivity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
There are two sorts of Ethernet Connectivity we will consider. The first is just connecting the Pi to a known Ethernet network. It is simple as it requires no configuration, but it means you will need to use other methods to ensure the network allows SSH traffic and to ensure you can determine the IP of the Pi.&lt;br /&gt;
&lt;br /&gt;
The second is using Ethernet passthrough from your computer to the Raspberry Pi. This leaves the WiFi free to host your own access point, and you can host services such as a Node-Red server or media center on the Pi.&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi to a router will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi.&lt;br /&gt;
&lt;br /&gt;
== TTL over USB ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The Pi uses 3.3V logic levels. Using a 5V logic module will permanently damage the pins.&lt;br /&gt;
&lt;br /&gt;
This option allows you to use a USB to UART converter such as a FT232R or CP2102. Begin by removing the SD card, and insert it into a computer. Make the following changes on the boot partition:&lt;br /&gt;
&lt;br /&gt;
cmdline.txt: add the following (on the same line)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;console=serial0,115200 &amp;lt;/pre&amp;gt;&lt;br /&gt;
config.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uart_enable=1&lt;br /&gt;
dtoverlay=pi3-disable-bt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using USB connectivity on the Pi 0/0W ==&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=415</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=415"/>
		<updated>2020-08-18T12:11:52Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Using USB connectivity on the Pi 0/ 0W */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi.&lt;br /&gt;
&lt;br /&gt;
== TTL over USB ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The Pi uses 3.3V logic levels. Using a 5V logic module will permanently damage the pins.&lt;br /&gt;
&lt;br /&gt;
This option allows you to use a USB to UART converter such as a FT232R or CP2102. Begin by removing the SD card, and insert it into a computer. Make the following changes on the boot partition:&lt;br /&gt;
&lt;br /&gt;
cmdline.txt: add the following (on the same line)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;console=serial0,115200 &amp;lt;/pre&amp;gt;&lt;br /&gt;
config.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uart_enable=1&lt;br /&gt;
dtoverlay=pi3-disable-bt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using USB connectivity on the Pi 0/0W ==&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=414</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=414"/>
		<updated>2020-08-18T12:11:21Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Other Connectivity Methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi.&lt;br /&gt;
&lt;br /&gt;
== TTL over USB ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The Pi uses 3.3V logic levels. Using a 5V logic module will permanently damage the pins.&lt;br /&gt;
&lt;br /&gt;
This option allows you to use a USB to UART converter such as a FT232R or CP2102. Begin by removing the SD card, and insert it into a computer. Make the following changes on the boot partition:&lt;br /&gt;
&lt;br /&gt;
cmdline.txt: add the following (on the same line)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;console=serial0,115200 &amp;lt;/pre&amp;gt;&lt;br /&gt;
config.txt&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;uart_enable=1&lt;br /&gt;
dtoverlay=pi3-disable-bt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Using USB connectivity on the Pi 0/ 0W ==&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=413</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=413"/>
		<updated>2020-08-18T12:10:45Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Other Connectivity Methods = &lt;br /&gt;
There are ways other than WiFi and Ethernet as a means of connecting headlessly (without a keyboard and screen directly attached) to the Pi. &lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=412</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=412"/>
		<updated>2020-08-18T12:06:52Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Setting a static IP on the Pi */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
Before setting the static IP, ensure you have the correct subdomain, and that you don't assign an IP that another device on the network is using. If you're assinging it a static IP and you have, for example, a router acting as a DHCP server, ensure the IP you assign is outside of DHCP range.&lt;br /&gt;
&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=411</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=411"/>
		<updated>2020-08-18T12:05:39Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Setting a static IP on your Desktop */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too. If you're setting a static IP on a Pi that's already connected directly to the network through a router or similar network switch, you can ignore setting a static IP on the computer.&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=GNU_Debugger_(GDB)&amp;diff=410</id>
		<title>GNU Debugger (GDB)</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=GNU_Debugger_(GDB)&amp;diff=410"/>
		<updated>2020-08-18T12:04:45Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Installation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Software]]&lt;br /&gt;
The GNU Project Debugger (GDB)&lt;br /&gt;
&lt;br /&gt;
= Installation =&lt;br /&gt;
== Windows ==&lt;br /&gt;
On Windows, gdb is a part of MinGW. See [[MinGW]] for more information.&lt;br /&gt;
== Ubuntu ==&lt;br /&gt;
GDB comes installed by default on most Unix-like systems, but if it's not installed, you can run the following:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;Bash&amp;quot;&amp;gt;&lt;br /&gt;
sudo apt install gdb&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Usage =&lt;br /&gt;
This section defines simple usage of GDB. It is by no means comprehensive, but it should be sufficient for a fair amount of debugging scenarios.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Compile &amp;lt;br&amp;gt;&lt;br /&gt;
You would compile your file as per usual, but attach the g flag:&lt;br /&gt;
&amp;lt;pre&amp;gt;$ cc -g main.c&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Launch&lt;br /&gt;
To launch gdb, run the following, where &amp;quot;a.out&amp;quot; is the output of the compile command above&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt; Configure Debug&lt;br /&gt;
See below for useful debugging commands such as adding breakpoints, stepping through functions or printing the values of variables&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Run&lt;br /&gt;
Run the program with your added breakpoints by typing the &amp;quot;run&amp;quot; command.&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;Finish&lt;br /&gt;
To close gdb, you can enter &amp;quot;q&amp;quot;&lt;br /&gt;
&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ol&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= GDB Commands = &lt;br /&gt;
Some useful gdb commands include:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|General&lt;br /&gt;
|-&lt;br /&gt;
|help&lt;br /&gt;
|Shows details about commands&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Controlling Execution flow&lt;br /&gt;
|-&lt;br /&gt;
|break &amp;lt;line_number&amp;gt;&lt;br /&gt;
|Adds a breakpoint at the given line number. Other options include&amp;lt;br&amp;gt;&lt;br /&gt;
break &amp;lt;file_name:line_number&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
break &amp;lt;file_name:function_name&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|run&lt;br /&gt;
|Executes the program in gdb&lt;br /&gt;
|-&lt;br /&gt;
|next&lt;br /&gt;
|Debugger will execute the next line as single instruction. This includes whole functions&amp;lt;br&amp;gt;&lt;br /&gt;
Can be abbreviated to n.&lt;br /&gt;
|-&lt;br /&gt;
|step&lt;br /&gt;
|Runs a single line of code. Will enter into a called function, unlike next.&lt;br /&gt;
Can be abbreviated to s.&lt;br /&gt;
|-&lt;br /&gt;
|continue&lt;br /&gt;
|Continues execution until the next breakpoint.    &lt;br /&gt;
Can be abbreviated to c.&lt;br /&gt;
|-&lt;br /&gt;
|finish&lt;br /&gt;
|If you're in a function which returns at some point, you can use the finish command to execute the program until the end of the function.&lt;br /&gt;
It's equivalent to setting a breakpoint at the return line of a function, and then letting the program run.&lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Gathering information&lt;br /&gt;
|-&lt;br /&gt;
|print &amp;lt;variable&amp;gt;&lt;br /&gt;
|prints the value of a specified variable.&lt;br /&gt;
Can be abbreviated to p.&lt;br /&gt;
|-&lt;br /&gt;
|info variables&lt;br /&gt;
|Will give information on all variables, including some that you haven't defined&lt;br /&gt;
|-&lt;br /&gt;
|info locals&lt;br /&gt;
|Will give information on variables in the current scope&lt;br /&gt;
|-&lt;br /&gt;
|info args&lt;br /&gt;
|Will return information on the arguments passed &lt;br /&gt;
|-&lt;br /&gt;
!colspan=&amp;quot;2&amp;quot;|Dealing with Pointers&lt;br /&gt;
|-&lt;br /&gt;
|print *&amp;lt;pointer&amp;gt;&lt;br /&gt;
|Prints what the pointer is pointing to&lt;br /&gt;
|-&lt;br /&gt;
|print &amp;amp;&amp;lt;variable&amp;gt;&lt;br /&gt;
|Displays the address of the variable&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== gdb for openOCD ==&lt;br /&gt;
See the [[openOCD]] page for more details on using it. Here are some additional gdb commands that might be useful when debugging on hardware:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; &lt;br /&gt;
|monitor &amp;lt;command&amp;gt;&lt;br /&gt;
|[asses &amp;lt;command&amp;gt; directly to openOCD. Allows openOCD commands to be passed through gdb&lt;br /&gt;
|-&lt;br /&gt;
|info registers&lt;br /&gt;
|prints the names and values of the CPU registers&lt;br /&gt;
|-&lt;br /&gt;
|info registers rX&lt;br /&gt;
|Prints the value of the specifed register rX, where X is a number of a register (0-15 in ARM). &lt;br /&gt;
|-&lt;br /&gt;
|set $rX=val&lt;br /&gt;
|sets register X (O-15 in ARM) to the value val&lt;br /&gt;
|-&lt;br /&gt;
|x/format address&lt;br /&gt;
|Reads the contents of address and displays it according to format. &lt;br /&gt;
See [http://sourceware.org/gdb/current/onlinedocs/gdb/Memory.html this link] for more.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=409</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=409"/>
		<updated>2020-08-18T12:02:55Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Static IPs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
If you're connecting your Pi through your desktop, you'll need to assign a static IP to the desktop, too.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
	<entry>
		<id>http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=408</id>
		<title>RaspberryPi:Networking</title>
		<link rel="alternate" type="text/html" href="http://wiki.ee.uct.ac.za/index.php?title=RaspberryPi:Networking&amp;diff=408"/>
		<updated>2020-08-18T12:01:25Z</updated>

		<summary type="html">&lt;p&gt;CRNKEE002: /* Ethernet Connectivity */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:RaspberryPi]]&lt;br /&gt;
There are many ways to interface with the Pi. This page will cover types of network connectivity. For more comprehensive, advanced networking details, see [[RaspberryPi:AdvancedConnectivity]].&lt;br /&gt;
&lt;br /&gt;
= A Brief Overview of Networks =&lt;br /&gt;
&lt;br /&gt;
It is useful to have a basic idea of how networks, IP addresses, and subnets work. For this, it it suggested you read [https://support.microsoft.com/en-za/help/164015/understanding-tcp-ip-addressing-and-subnetting-basics this article] from Microsoft.&lt;br /&gt;
&lt;br /&gt;
= Wireless Connectivity =&lt;br /&gt;
WiFi connectivity is a useful way of connecting the Pi to the internet as it enables more portability. You can adjust WiFi Connections either before boot, by creating a &amp;lt;code&amp;gt;wpa_cupplicant.conf&amp;lt;/code&amp;gt; file on the boot partition, or while the pi is running, either by editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly, or using &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt;. Note that the raspi-config method will not work for Eduroam.&lt;br /&gt;
&lt;br /&gt;
== Simple Wifi Connections ==&lt;br /&gt;
If the Pi is up and running and you have access to it, you can run &amp;lt;code&amp;gt;$ sudo raspi-config&amp;lt;/code&amp;gt; and enable WiFi using that menu, or editing &amp;lt;code&amp;gt;/etc/wpa/wpa_supplicant.conf&amp;lt;/code&amp;gt; directly using an editor such as nano. However if you don't have access, you can create a  a &amp;lt;code&amp;gt;wpa_supplicant.conf&amp;lt;/code&amp;gt; file on the SD card, on the boot partition while it is plugged into another system.&lt;br /&gt;
&lt;br /&gt;
If editing the wpa_supplicant configuration file, the contents should look something like the following:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
update_config=1&lt;br /&gt;
country=ZA&lt;br /&gt;
&lt;br /&gt;
network={&lt;br /&gt;
 ssid=&amp;quot;&amp;lt;Name of your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
 psk=&amp;quot;&amp;lt;Password for your WiFi network&amp;gt;&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Connecting to Eduroam ==&lt;br /&gt;
Connecting to Eduroam requires a fair amount of configuration which depends on your operating system. Generally though, edits to wpa_supplicant.conf and dhcpcd.conf are sufficient. Note that there are new releases of Raspberry Pi OS, and it is unknown if the edits for Buster are still required.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-Eduroam&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-Eduroam&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
=== Raspbian Buster ===&lt;br /&gt;
'''Note:''' There have been updates to the Buster code base, and roll back of wpasupplicant might not be required. However this is currently unable to be tested due to the lockdown. If someone has the chance to test, please update this page accordingly.&lt;br /&gt;
These instructions come from [https://www.raspberrypi.org/forums/viewtopic.php?p=1501822#p1501822 here].&amp;lt;br /&amp;gt;&lt;br /&gt;
Unfortunately, when you use bleeding edge technology, you may end up cutting yourself. Raspbian Buster updates &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to a version that doesn’t have support for the authentication method used by Eduroam. So we need to roll back &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; to an older version. Ensure your Pi has internet access through a method such as Ethernet passthrough, and run the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get remove wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
Edit /etc/apt/sources.list :&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And change&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ stretch main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&lt;br /&gt;
$ sudo apt-get install wpasupplicant&amp;lt;/pre&amp;gt;&lt;br /&gt;
This will install the correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt;. Check that '''version 2.4''' is installed by running&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ wpa_supplicant -v&amp;lt;/pre&amp;gt;&lt;br /&gt;
Now, change the sources file back.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/apt/sources.list&amp;lt;/pre&amp;gt;&lt;br /&gt;
And edit the contents to contain&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;deb http://raspbian.raspberrypi.org/raspbian/ buster main contrib non-free rpi&amp;lt;/pre&amp;gt;&lt;br /&gt;
Finally, run&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo apt-get update&amp;lt;/pre&amp;gt;&lt;br /&gt;
To update sources The correct version of &amp;lt;code&amp;gt;wpa_supplicant&amp;lt;/code&amp;gt; should now be installed, and you can configure your Pi for WiFi as you would if you were using Raspbian Stretch as explained in below.&lt;br /&gt;
&lt;br /&gt;
=== Raspbian Stretch ===&lt;br /&gt;
&lt;br /&gt;
This section provides the instructions on how to configure the Pi to use Eduroam. It is possible to do using the GUI through VNC, but we will not cover that here.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;SSH into your Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Generate a hash for your password. Take note of it as it is needed in a later step&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ echo -n your_uct_password_here | iconv -t utf16le | openssl md4&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Edit it so it looks as follows:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev&lt;br /&gt;
    update_config=1&lt;br /&gt;
    country=ZA&lt;br /&gt;
&lt;br /&gt;
    network={&lt;br /&gt;
    ssid=&amp;amp;quot;eduroam&amp;amp;quot;&lt;br /&gt;
    key_mgmt=WPA-EAP&lt;br /&gt;
    identity=&amp;amp;quot;studentnumber@wf.uct.ac.za&amp;amp;quot;&lt;br /&gt;
    password=hash:generated_hash_from_earlier&lt;br /&gt;
    }&lt;br /&gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Save the file&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open &amp;lt;code&amp;gt;/etc/dhcpcd.conf&amp;lt;/code&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; $ sudo nano /etc/dhcpcd.conf&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Make sure the following lines are in the document:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;interface wlan0&lt;br /&gt;
metric 200&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Reboot your Pi&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;WiFi Generally takes a little longer to initialize than Ethernet, so give it time. You can see if it’s ready by running&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ifconfig &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;And seeing if an IPv4 address (“inet”) has been given.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Test your configuration by pinging from the WiFi interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping google.com -I wlan0&amp;lt;/pre&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ethernet Connectivity =&lt;br /&gt;
Ethernet is the physical connection made using a CAT 5 or 6 cable - though there are ways that Ethernet can be mimicked over USB (see Details on the Pi 0 and 0W for more information).&lt;br /&gt;
&lt;br /&gt;
If you're on a private network, connecting your Pi will usually just assign it an IP address and internet connectivity automatically works. If you're on a linux-based system, like Ubuntu, you can use the hostname of the Pi to connect. By default this is &amp;quot;raspberrypi&amp;quot;, so you could SSH in using &amp;quot;SSH pi@raspberrypi&amp;quot;. However, in most cases, you'll want to know the IP address and assign a static IP address.&lt;br /&gt;
&lt;br /&gt;
== Static IPs ==&lt;br /&gt;
Setting a static IP makes it easy to access the Pi and ensures that the IP address of the Pi is always known. In this course, we assign the Pi an IP address of 192.168.137.15. The reason for this is that when using Ethernet Passthrough on Windows, Windows asserts a domain of 192.168.137.x, with the host PC being assigned 192.168.137.1. Keep in mind that all devices will need to be on the same subnet though, so if you're assigning a static IP to be used on your own Ethernet network, you need to know what the subnet of that network is.&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on your Desktop ==&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-WindowsIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-WindowsIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Windows 10, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Right click on your network option in Windows taskbar&lt;br /&gt;
* Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
* Select “Change Adapted Options”&lt;br /&gt;
* Right click on the Ethernet Connection and select “Properties”&lt;br /&gt;
* Select “Internet Protocol Version 4 (TCP/IPv4) and click ”Properties&amp;amp;quot;&lt;br /&gt;
* Select “Use the following IP address:” and enter in the following options:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You have successfully changed the IP of the Ethernet card on your computer. It is suggested that you now ensure connectivity by attempting to ping the Pi.&lt;br /&gt;
&lt;br /&gt;
[[File:windowsIPConfig.png|thumb|none|alt=|The IPv4 configuration screen in Windows 10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-UbuntuIP&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-UbuntuIP&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
To change the IP of your Ethernet port on Ubuntu, complete the following steps:&lt;br /&gt;
&lt;br /&gt;
* Click the network interface icon on the status bar and select Wired Settings&lt;br /&gt;
* Click the gear button of the interface you’d like to change&lt;br /&gt;
* Select the IPv4 Tab, and change the IPv4 method to Manual&lt;br /&gt;
* Under “Addresses” enter in the following:&amp;lt;br /&amp;gt;&lt;br /&gt;
- IP Address: 192.168.137.1&amp;lt;br /&amp;gt;&lt;br /&gt;
- Subnet Mask: 255.255.255.0&lt;br /&gt;
* You can leave Gateway and DNS blank&lt;br /&gt;
&lt;br /&gt;
[[File:Ubuntustaticip.png|thumb|none|alt=|The IPv4 configuration screen in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Setting a static IP on the Pi ==&lt;br /&gt;
To set a static IP on the Pi, you have multiple options. You can do it before first boot by addling a line to cmdline.txt on the boot partition of the SD card, or once the Pi is running by editing dhcpcd.&lt;br /&gt;
=== From the boot partition ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticBoot&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticBoot&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;ol&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Insert the SD card into your computer and navigate to the BOOT partition&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Open “cmdline.txt” and append the following to the line (don’t create a new line)&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt; ip=192.168.137.15 &amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;This tells the Raspberry Pi to configure the Ethernet port to use the IP address 192.168.137.15&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;Enable SSH as per Section [sec:SSH].&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;li&amp;gt;&amp;lt;p&amp;gt;You need to configure your PC to use the same subnet as the Pi. To do so, see the information below in the section on Assigning a static IP to the Pi.&amp;lt;/p&amp;gt;&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== In dhcpcd (while the Pi is running)===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PiStaticDHCPCD&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PiStaticDHCPCD&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
Once you’ve successfully SSH’d into your Pi, it’s a good idea to configure the networking options in the config files directly. You will need to set a static IP on the computer first if you are SSH'ing through an Ethernet connection.&lt;br /&gt;
&lt;br /&gt;
Use a text editor such as nano to open /etc/dhcpcd.conf as sudo user, and edit it to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;# Static IP profile for eth0&lt;br /&gt;
profile static_eth0&lt;br /&gt;
static ip_address=192.168.137.15/24&lt;br /&gt;
static routers=192.168.137.1&lt;br /&gt;
static domain_name_servers=192.168.137.1 8.8.8.8&lt;br /&gt;
&lt;br /&gt;
# Ethernet interface configuration &lt;br /&gt;
interface eth0&lt;br /&gt;
fallback static_eth0&lt;br /&gt;
&lt;br /&gt;
# Wireless configuration&lt;br /&gt;
interface wlan0&lt;br /&gt;
metric 200&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== WiFi to Ethernet Passthrough ==&lt;br /&gt;
In a situation when you can't or don't want to connect to a WiFi network, but are connected to a computer through an Ethernet port There may be a situation in which you want your Pi to work as an access point rather than using the WiFi interface to provide the Pi with internet access. In this situation, you need to get internet access through the Ethernet port. Before starting, you need to ensure the computer you're using has a static IP assigned. When enabling network sharing on Windows, it automatically assigns 192.168.137.1. Once that's done, complete the following to enable network sharing:&lt;br /&gt;
&lt;br /&gt;
=== Windows ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughWindows&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughWindows&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged&lt;br /&gt;
# Right click on your network option in Windows taskbar&lt;br /&gt;
# Select “Open Network &amp;amp;amp; Internet Settings”, on the lower right hand side of the screen.&lt;br /&gt;
# Select “Change Adapted Options”&lt;br /&gt;
# Right click on your WiFi network and select “Properties”&lt;br /&gt;
# Click the “Sharing” tab, and enable the first checkbox &amp;lt;ref&amp;gt;This setting is what forces us to have to use the subnet 192.168.137.x.&amp;lt;/ref&amp;gt;&lt;br /&gt;
# Select the Ethernet connection that your Pi will be using in the drop down box (Usually just “Ethernet”, but may be different if there are multiple Ethernet posts on your system)&lt;br /&gt;
&lt;br /&gt;
[[File:Windowspassthrough.png|thumb|none|alt=|Using WiFi to Ethernet passthrough in Windows]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
=== Ubuntu ===&lt;br /&gt;
&amp;lt;span class=&amp;quot;mw-customtoggle-PassthroughUbuntu&amp;quot; style=&amp;quot;font-size:small; display:inline-block; &amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-customtoggletext&amp;quot; data-expandtext=&amp;quot;Illuminate&amp;quot; data-collapsetext=&amp;quot;Deluminate&amp;quot;&amp;gt;[Show/hide]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;div  id=&amp;quot;mw-customcollapsible-PassthroughUbuntu&amp;quot; class=&amp;quot;mw-collapsible mw-collapsed&amp;quot;&amp;gt;&lt;br /&gt;
# Ensure the Pi is unplugged and turned off.&lt;br /&gt;
# Open a terminal and run &amp;lt;code&amp;gt;nm-connection-editor&amp;lt;/code&amp;gt;&lt;br /&gt;
# Select the wired connection you’d like to share your WiFi to&lt;br /&gt;
# Select the IPv4 settings tab&lt;br /&gt;
# Under Method, select “Shared to other computers”&lt;br /&gt;
# under the IP addresses, click “Add” and enter in an address of 192.168.137.1, and a netmask of 24&lt;br /&gt;
# Select “Save”, and close the windows&lt;br /&gt;
# Plug in the Pi, start an SSH session and see if you can ping google.co.za&lt;br /&gt;
&lt;br /&gt;
[[File:Nm-connection-editor.png|thumb|none|alt=|nm-connection-editor in Ubuntu 18.10]]&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Ensuring Connectivity =&lt;br /&gt;
&lt;br /&gt;
Sometimes you may want to debug your connection to the Pi. A fast way to do this is via the ''ping'' command. ''Ping'' sends a packet to a particular host (in this case the Pi), and measures the time taken for a response from that host.&lt;br /&gt;
&lt;br /&gt;
To use the ping command, open a command prompt window or terminal and type the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ping 192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If that host is unreachable (the Pi hasn’t booted yet or is incorrectly configured), a message will show that the host is unreachable. If everything was correctly configured, you should get&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;Reply from 192.168.137.15: bytes=32 time&amp;amp;lt;1ns TTL=64&amp;lt;/pre&amp;gt;&lt;br /&gt;
This means your Pi and computer are both correctly configured. See section [sec:SSH] for configuring your Pi for SSH access.&lt;br /&gt;
&lt;br /&gt;
'''NB:''' Don’t be surprised if you can’t ping a Windows machine from your Pi. Windows blocks the specific type of packet required for a ping in the firewall.&lt;br /&gt;
&lt;br /&gt;
= Networking Protocols=&lt;br /&gt;
For a more detailed overview on useful networking protocols,  see [[Network Protocols]]&lt;br /&gt;
== SSH ==&lt;br /&gt;
&lt;br /&gt;
=== Enabling SSH ===&lt;br /&gt;
&lt;br /&gt;
If you have not connected to your Pi and configured it for SSH, you need to do so. SSH is disabled by default on new installations of Raspbian.&lt;br /&gt;
&lt;br /&gt;
To enable SSH, add it as an enabled service in the &amp;lt;code&amp;gt;raspi-config&amp;lt;/code&amp;gt; menu. If you do not have access to the Pi as yet, do the following:&lt;br /&gt;
&lt;br /&gt;
# Insert the SD card into a computer&lt;br /&gt;
# Navigate to the BOOT partition&lt;br /&gt;
# Create a file called “ssh”. &amp;lt;strong&amp;gt;Note there is no file extension!&amp;lt;/strong&amp;gt;&lt;br /&gt;
# Your Pi will enable SSH upon next boot&lt;br /&gt;
&lt;br /&gt;
=== Using SSH ===&lt;br /&gt;
&lt;br /&gt;
To use SSH on your Pi, you need to connect to the computer to a network. See Section [sec:NetworkingOnThePi] on various ways that can be done (it is suggested to use Ethernet upon first connection).&lt;br /&gt;
&lt;br /&gt;
Once your Pi is connected to the computer and you have ensured connection (see Section [sec:Connectivity-EnsuringConnectivity]), use can log in to your Pi via SSH. If you are on a Linux-based system, such as Ubuntu or Mac, you should be able to run the following. Note that the default username is “pi” and the default password is “raspberry”.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;$ ssh &amp;amp;lt;username&amp;amp;gt;@192.168.137.15&amp;lt;/pre&amp;gt;&lt;br /&gt;
If you are on Windows, you may need to use PuTTY. Some instances of windows have SSH in the command line, and you can run the command shown above. But if not, you will need to do the following:&lt;br /&gt;
&lt;br /&gt;
# Open PuTTY&lt;br /&gt;
# In the “Hostname” field, enter in “192.168.137.15”&lt;br /&gt;
# Click “Open”. A terminal window will be opened. If it is the first time you’re SSH’ing into your Pi on this particular computer, you will be asked about the server fingerprint. Click “Yes” to continue.&lt;br /&gt;
# You will be asked for a username and password. The default username is “pi” and the password is “raspberry”.&lt;br /&gt;
# You should now successfully connected to your Raspberry Pi via SSH&lt;br /&gt;
&lt;br /&gt;
== VNC ==&lt;br /&gt;
To learn about how to install VNC, see&lt;br /&gt;
# Ensure the VNC service is enabled on the Pi&lt;br /&gt;
&lt;br /&gt;
#Connect to the Pi through VNC.&lt;br /&gt;
# Set your preferred resolution for Raspbian&lt;br /&gt;
## In the desktop menu, go to Preferences - Raspberry Pi Configuration and click the “Set Resolution” button.&lt;br /&gt;
## Select a more appropriate resolution (1280*720 suggested)&lt;br /&gt;
## Select “Okay” and then “Okay”. You will be asked to reboot your Pi, do so.&lt;br /&gt;
# Set the VNC resolution&lt;br /&gt;
## Through editing /boot/config.txt, uncomment the following lines relating to framebuffer_width and framebuffer_height&lt;br /&gt;
## On the desktop on VNC, use the settings. Do this if you have already connected to VNC. This is a little more difficult as it required you to play with windows in order to see the buttons you need.&lt;/div&gt;</summary>
		<author><name>CRNKEE002</name></author>
		
	</entry>
</feed>