From physics to information¶
Getting inspired by the past¶
Click on the image to download the PDF
Some references
Do not try to watch them all! Simply choose a topic you like and jump over the videos. Maybe you find something interesting and suddenly want to learn more about it.
- Information Theory
- More on information Theory and Coding (for those who enjoyed the videos above)
- How computers think
- Why we use binary
- How computers work
- How computer memory works the insides
- Colossus the first electronic computer
- How they design the computers they landed astronauts to the moon
- UNIX or what an operative system does
- Looking at how things are built and work to learn how to design
- An introduction to Arduino towards future assignments
- The Secret Life of Machines
Representing information¶
Now, let’s start representing information with our very basic circuit.
A couple of questions
- How much information are we able to represent with this circuit?
- How many possibilities do we have? And what if we combine all the circuits we just built?
Digital Logic in an Analog World¶
As we saw before:
A single switch can be on or off, enabling the storage of 1 bit of information. Switches can be grouped together to store larger numbers. This is the key reason why binary is used in digital systems.
With a bank of eight switches we can store 28 = 256 possible numbers. Each of those switches is called 1 bit, and 8 of them are a byte:
This implies then, that to represent information with electricity, we have one very important limitation: information becomes discrete:
Of course, depending on the amount of bits we use we have a more precise curve:
And if we put enough of them, we can represent more complex things like this:
Logic Levels
Now that we have talked about representing information with single bit, we have to agree on how things are going to talk to one another. For this, we standardise what we consider as a 1 (high voltage) and 0 or low voltage. We call this Logic levels:
The core component: Transistor¶
Wouldn’t it be ideal if we had a tiny mini switch we could control by ourselves? The transistor is nothing else than an electronic switch.
And it basically works like this:
We will see how this transitor helps us build more complex things, by controlling how they are connected together.
Reference Tutorials
The Arduino project¶
The importance of the freedom to use, understand, modify and share your tools.
- Hardware - Programming IDE and libs - Community
Coding languajes¶
A high-level programming language is a programming language with strong abstraction from the details of the computer.
A low-level programming language is a programming language that provides little or no abstraction from a computer’s instruction set architecture.
From wikipedia
Algorithms and flow charts¶
[…] an algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation. Algorithms are always unambiguous […]
To represent algorithms we can use a for of diagram called flow chart.
A flowchart is a type of diagram that represents a workflow or process. A flowchart can also be defined as a diagrammatic representation of an algorithm, a step-by-step approach to solving a task.
The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrows. This diagrammatic representation illustrates a solution model to a given problem. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.
From wikipedia
There are a lot of different symbols you can use on your flowcharts, these is the basic set and its function:
References
- You can draw your flow charts online with draw.io
I/O Programming¶
Our code will interface with the outer world, receiving information, i.e. inputs, and actuating in some way, i.e. outputs. After receiving information from the environment, normally through some kind of sensor, we process the collected data to take decisions and actuate.
A balancing robot is a good example of this technic.
Practical coding¶
Variables¶
Think of variables as virtual drawers where you can store your stuff!
You can even label them with names, so you don’t forget whats inside. But remember to tell the computer what the content will be, so she can build the drawer big enough to fit it.
Coding control flow statements¶
We can use control flow statements to manage how our program reacts to different inputs and actuates on the outputs.
Conditionals help us take decitions, remember that your question can only be answered with true or false.
We can chain many conditions one after the other:
Loops can be used to repeat operations based on diferent parameters:
Comments¶
It is easy to forget what a piece of code was supposed to do if we read it after a couple of days, to write reminders or to explain what the code does, or simply to make a joke, we can use comments. In C language, simply starting a line with // will make the compiler ignore all the content on it.
// This line will be ignored by the computer!!
if (fail) {
// Failure is the way to learn...
print("ERROR!!!");
}
Functions¶
When our code starts growing, it can get very messy and difficult to understand. Functions are a way to organize our code by grouping instructions that we use often and then calling them. We can assign any name we want to functions, the idea is making it descriptive so we remember what the function does.
// We define a simple function to temporary light a led
void blink() {
digitalWrite(LED_PIN, HIGH);
delay(500);
digitalWrite(LED_PIN, LOW);
}
// And we can use it whenever we want!
void loop() {
if (ERROR) {
blink();
}
}
Libraries¶
Libraries are sets of tools that someone has built to make certain tasks easier, for instance, reading pins in a microcontroller, or controlling the LEDs. For using our LED strip, we will need to install one library.
References
- Using Variables in Sketches
- Arduino article on functions.
- Get to know Arduino Libraries
- You can find alot more info on the arduino learn site.
Hands on¶
Three things to remember
- Comming in or going out? pinMode()
- Pin on/off with digitalWrite()
- Read button state with digitalRead()
Reading a button¶
Digital input with DigitalRead()
int buttonPin = 2;
int value = 0;
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(115200);
}
void loop() {
value = digitalRead(buttonPin);
Serial.println(value);
}
Blinking led¶
Digital output with digitalWrite() using delay function.
void setup() {
// Set pin 12 as output
pinMode(12, OUTPUT);
}
// Loop runs forever
void loop() {
// Voltage up in pin 12
digitalWrite(12, HIGH);
// Wait 200ms with pin 12 HIGH
delay(200);
// Voltage down in pin 12
digitalWrite(12, LOW);
// Wait 200ms with pin 12 LOW
delay(200);
}
I/O¶
If you are feeling adventurous, try this
// Our variable for checking if it's pressed or not
bool pressed = false;
// the setup function runs once when you press reset or power the board
void setup() {
pinMode(12, OUTPUT);
pinMode(27, INPUT);
// Turn the LED off
digitalWrite(12, LOW);
}
// Loop runs forever
void loop() {
// Read the pin
if (digitalRead(27)) {
// pressed!
pressed = false;
} else {
// not pressed!
pressed = true;
}
if (pressed) {
// Turn it on
digitalWrite(12, HIGH);
} else {
// Turn it off
digitalWrite(12, LOW);
}
}
General resources
- Lisa’s Soft Switches Collection of soft-switches by Lisa Stark
- Lisa’s Soft Sensors Collection of soft-sensors by Lisa Stark
- hackaday.com is one of the best blogs on DIY inventions and hardware hacking
- lowtechmagazine.com many technology choices are political and economic, looking at past forgotten technologies helps us see the future
- archive.fabacademy.org 10 years of project from Fab Labs around the world. Sometimes hard to browse but inspiring!
- learn.adafruit.com a really good site for electronics and programming tutorials, especially for beginners
- instructables more and more DIY tutorials, sometimes aren’t good but there’s a lot
- REPL.it
- Instructions for the Apollo Guidance Computer