Chips Ahoy! – The path to Programmable Components

advertisement
Chips Ahoy! – The path to
Programmable Components
Brian P Smith
Welcome
•
Good morning and welcome to the Chips Ahoy! Workshop
•
I’m Brian Smith and I have been teaching electronics and computing for 34 years and
have created a number of commercial products – Kidschip, Learn & Go, eChip
•
This session is sponsored by ICSAT and Technology Supplies
•
•
In the next 2:45 hrs we will be taking a look at this update aspect of the D&T POS
It will be a ‘hands on’ session
Aims of the Session
•
To illustrate a pathway from simple electronics to programmable components
•
To introduce programmable components, such as microcontrollers and Small Board
Computers (SBCs).
•
To show how microcontrollers can be used to apply computing principles and embed
intelligence into pupil work at Key Stage 3
•
To have a practical experience of microcontrollers and SBCs
•
To identify next steps in further developing your own use of programmable components
in the classroom.
Chips Ahoy! – The path to programmable components
INTRODUCTION
Electronics in the past
•
•
•
•
•
Simple circuits with little complexity and functionality – low value
Complex circuits and functionality difficult to achieve
Didn’t match student expectations – could buy better for under £10.00
Focussed on ‘out of date’ technologies
Often done very badly, not much success for learners
Sir – it doesn’t work!
•
•
•
•
•
•
Frustrating for staff – lack of training, support, resources
Limited scope in other D&T facets
For schools seen as being very expensive, difficult to justify
Seen as hard and not very fun!
Limited use of PICs has made a small start, but education has got left behind
Now it’s time to catch up
Brian P Smith
5
Chips Ahoy! – The path to programmable components
THE NEW POS
The new requirements for 2014
•
•
•
Technical knowledge, the key requirement are:
KS2
apply their understanding of computing to program, monitor and control their
products .
•
•
KS3
understand how more advanced electrical and electronic systems can be powered and
used in their products, such as circuits with heat, light, sound and movement as inputs
and outputs
•
apply computing and use electronics to embed intelligence in products that respond
to inputs such as sensors, and control outputs such as actuators, using programmable
components such as microcontrollers. KS3
Brian P Smith
7
What does it mean in practice?
•
It translates into:
•
‘The need to teach more advanced electronics that embed intelligence into the
products they design and make’
•
This doesn’t mean more difficult, as embedded electronics has moved on in terms of
the development tools and support available
•
We need to have high aspirations in this field of D&T to meet the challenges of the 21st
Century Designing & Making leading into world class manufacturing and engineering.
Brian P Smith
8
Access all areas
•
•
Learners are still expected to design and make their own products containing PCBs
using these devices / modules
The products can be created in all facets of D&T:
– Product Design
– Graphic Products
– Textiles – eTextiles
– Food – packaging & tracking
– Electronic Products
– Systems & Control
Brian P Smith
9
Embedded electronics
•
•
•
Embedded electronics is the term used to describe those processor based systems
added to everyday products to improve their functionality
Embedded systems are dedicated to specific tasks, design engineers can optimize
it to reduce the size and cost of the product and increase the reliability and
performance.
Embedded systems are mass-produced, benefiting from economies of scale.
Brian P Smith
10
Embedded Systems
•
The design and making of embedded systems makes full use of computing:
–
–
•
Physically, embedded systems include such devices as:
–
–
–
–
–
–
•
CADCAM
Programming
Robots
MP3 players
Cookers
Fridges
Smartphones
Smart TV’s
Embedded electronics enable the design and making of products with intelligence
and high value matching the needs and demands of the learner.
Brian P Smith
11
What's out there?
1. Simple circuits with little complexity &functionality – low value
2. Complex circuits and functionality difficult to achieve
3. Simple PIC based systems:
– PICAXE
– Genie
– Require PCBs / Programmed using flowcharts or BASIC, most are free
4.
Next generation PIC systems:
• PIC Clicker and Click boards
• Matrix ECIO boards
• Requires PCBs / Programmed using flowcharts,
BASIC and C, most are free [Computing link]
What's out there?
5. Adding capacity and intelligence with Small Board Computers (SBC’s):
– Raspberry Pi / BeagleBone / Vex Robotics
– Arduino – Uno, LilyPad, TinyDuino etc
– Programmed in ModKit, Python, C, most are free [Computing link]
– Wide range of modules, shields / PCBs required for your additional electronics
– Massive resource base on the web for help and support
Microcontrollers
What is a Microcontroller?
•
A microcontroller is programmable component widely used in schools and in industry
•
It is a small computer on a chip – a microprocessor specifically designed for control
based work
•
Can be programmed to perform different tasks – therefore ideal for a range of different
projects
•
The PIC made by Microchip and is a very common microcontroller along with the AVR
made by Amtel
What can microcontrollers do?
•
Produce timed sequences with output devices
•
Play sounds, tunes and music
•
Respond to sensors
•
Wait for sensors to change
•
Produce ‘random’ effects
•
Count
•
Respond to analogue sensors
•
Do several things at the same time
Starting point
Before deciding upon the type of hardware you would like to work with it is important to
look at the various options available many of which are free or free to teachers on
application.
What do you need to do?
Decide on the type of format that you like to work with
Direct control (basic input and output commands)
Flow Charts
Line based code
Software Platform
No Computer……
MAC
Windows
MAC & Windows
Several can be obtained in schools for free
Chips Ahoy! – The path to programmable components
GETTING STARTED
Where to start
•
Simple PIC based systems:
–
–
–
–
•
•
PICAXE
Genie
Programmed using flowcharts or BASIC, most are free
Require PCBs
How to build them in to products – Projects that work
What knowledge and skills will I need?
Brian P Smith
22
Moving up a gear
•
Next generation PIC systems:
–
–
–
–
•
•
PIC Clicker and Click boards
Matrix ECIO boards
Programmed using flowcharts, BASIC and C, most are free [Computing link]
Requires PCBs
How to build them in to products – Projects that work
What knowledge and skills will I need?
£16.00
£18.00
Both have free versions of their IDE’s and use
USB for programming
Brian P Smith
23
How to aiming higher
•
Adding more capacity and intelligence with Small Board Computers (SBC’s):
–
–
–
–
–
–
–
Raspberry Pi
Arduino – Uno, LilyPad, TinyDuino etc
BeagleBone
Programmed in Python, C, most are free [Computing link]
Wide range of modules, shields
PCBs required for your additional electronics
Massive resource base on the web for help and support
Brian P Smith
24
What’s out there
•
The range of SBC modules is vast, here are some examples:
–
–
–
–
–
–
–
–
–
•
GPS
Accelerometers
LCD / LED displays
Motor drivers (DC, stepper, servo)
WiFi
Bluetooth
RGB LEDs
RGB LED matrixs
Audio playback (wav files)
Some of these are available in micro sizes, waterproof etc.
Brian P Smith
25
Coding your product
•
•
•
Coding or programming is an area we share with Computing
Learners have to:
use two or more programming languages, at least one of which is textual, .. design
and develop modular programs that use procedures or functions
•
•
•
•
•
The development of a coded solution is an example of iterative design:
The cyclic process of prototyping, testing, analyzing, and refining a product or process
Writing code isn’t difficult, all code is made up from standard sections.
These standard sections are known and are freely available online
It’s like using Lego – the blocks of code just need to click together in the right order.
Brian P Smith
27
Chips Ahoy! – The path to programmable components
THE PATH TO ....
The path to Programmable Components
•
•
•
I have been working on a pathway to link the new POS for KS2 & 3 with those of
Computing & Science
This pathway is intended to illustrate the progression from KS2 to 3, and the linkages
with supporting aspects from Computing & Science
The pathway is a suggestion what electronics within D&T might progress like in 2/3
years time
KS2/3 Electronic active
•
Introducing active electronic components and devices
Practical session 1
•
•
Lets have a break and make a typical electronic project in this Electronic active zone.
Touch Torch / Light
Two different kits: Torch version & Light version
Key points from your experience
•
Positives
•
Things to target / develop
•
What are your concerns?
Chips Ahoy! – The path to programmable components
CONFIGURABLE ELECTRONICS
KS3 Configurable Electronics
•
•
As a stepping stone from conventional components to programmable ones, I have add
a new category called Configurable Electronics
The are chips (PICs) that contain Firmware (a control program) which allows the chip to
function in a variety of ways depending upon the connections made to one of more
pins
SpinIt© a configurable chip
•
•
•
•
•
•
SpinIt© is a configurable chip that
contains 8 different games
The games are selected by the
student by making or not making a
link(s)
The outputs take on different
functions depending upon the game
selected
The information for SpinIt is supplied
as a datasheet
Using the datasheet and a base PCB,
students can select a game, create a
supporting circuit and gameboard or
housing
An introduction to programmable
components without programming
•
•
•
•
•
•
•
•
•
•
Benefits for students
Straight forward circuit
Allows a wide range of products from
one chip
Allows for individual solutions
Benefits for staff
Same basic circuit
Easy to fault find
All students are essentially using the
same one
No programs to troubleshoot
Allows a wide range of solutions, but
you are not running around trying to
sort 20+ different ones
Practical session 2
•
Lets take another break and use a configurable chip – no programming as yet
Key points from your experience
•
Positives
•
Things to target / develop
•
What are your concerns?
Time for a break
Brian P Smith
38
Chips Ahoy! – The path to programmable components
PROGRAMMABLE COMPONENTS
KS3 Programmable Components
•
This is the big one, with a number of ways to achieve its delivery, with plenty in reserve
to hit high aspirations, student progress and attainment
Practical session 3
•
Now its time to have a go with some programmable components
•
•
•
•
•
I have:
10 x Game boards with embedded components
6 x PICAXE 14M2 systems
6 x Arduino systems
We are going to add some ‘intelligence’ to the board using these devices
Intelligent Board Game
•
•
In this session we are going to make an Intelligent Board Game using the PICAXE &
Arduino
The board is 250mm x 250mm and is a 3 part construction:
–
–
•
Electronic parts:
–
–
–
–
–
–
•
Top & bottom – display card
Inner – 6mm foam board
R, G, B, Y and W mounted SMD LEDs (E-Textiles)
Sub Min Microswitches
Sub Min Reed switches (E-Textiles)
Piezo transducer
Vibe motor (E-Textiles)
Arduino
10 pin connector
–
+5V, 0V, and 8 user connections (to & from SBC)
Brian P Smith
42
Game board information
•
The 10 way connector has the following
layout (top to bottom):
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Magnetic switch
X
Neopixel
Yellow LED
Blue LED
Green LED
Red LED
Piezo Tx
+V (3V – 5V only)
0V
Starter for 10
•
Repeat loop
•
Pick a random number
•
Do task 1 if number = 1
•
Do task 2 if number = 2
•
If magnetic switch = 1 do task 3
•
Wait for 1 second
•
Loop back to start
Key points from your experience
•
Positives
•
Things to target / develop
•
What are your concerns?
Chips Ahoy! – The path to programmable components
IT’S A WRAP!
The challenges ahead
•
In developing this area the following will be needed:
–
–
–
–
New subject knowledge
Skills Training
Teacher support
Curriculum materials
•
•
•
•
Schemes of Work
How to guides
Example Projects
Case studies
– Advice to SLT
– Developing links with Computing/ICT
– Developing a support network
Brian P Smith
47
Connecting with Computing
•
D&T contributes to the Computing POS:
–
–
–
–
•
•
Developing algorithms / methods for problem solving
Apply IT technologies such as CADCAM, web-based researching
Control and programming of products that have been design and made
Be creative users of IT for the development of new products
There is a clear synergy between D&T and Computing, they are both applied
Technologies and as such support and feed upon each other, we see this in
everyday in the products we use and rely upon.
We need to develop this linkage in the projects and work we do, for our mutual
benefit and that of the learner.
Brian P Smith
48
Key points from the workshop
•
Positives
•
Things to target / develop
•
What are your concerns?
Plans for the future
•
List your key action points for the next academic year
•
•
•
•
•
•
1
2
3
4
5
6
Key points
•
New requirement for Sept 2014
–
•
Can be delivered in all aspects of D&T
–
•
Discussions with Computing and SLT might be needed
Allows learners to develop projects using a wide range of modules that add lift them
from the mundane to outstanding
–
•
Learners can develop their own projects and solutions
Links with Computing can be developed to share the development of coding skills
–
•
But the newer SBC systems offer the best way to move forward
PIC Clicker, Matrix ECIO, Arduino, Raspberry Pi
Embedded electronics allows learners to aim high – this is the expectation
–
•
Product Design, Graphics, Food, Textiles, Electronics, Systems & Control
Range of starting points
–
–
•
DATA will be offering guidance courses
Just take a look at any Arduino, Rasp Pi, Maker forums
Allows the use of other advanced technologies
–
Laser cutting, 3D printing etc
Brian P Smith
51
ICSAT
• We are here for you
• Look on our website: www.icsat.co.uk
• If you don’t see what you want talk to us, we can
tailor course and meetings to suit your needs.
• We can help with KS1, 2 & 3 for September 2014. We
have produced Departmental audits and individual
student trackers.
• Tell your colleagues about us.
Chips Ahoy! – The path to programmable components
RESOURCES
Arduino
• Book list:
• Software:
•
•
•
•
•
•
•
30 Arduino projects for the evil genius –
Simon Monk
Programming Arduino – Simon Monk
Programming Arduino Next Steps – Simon
Monk
Arduino Projects for Dummies
Arduino for Dummies
Arduino Cookbook
• Websites:
•
•
•
•
•
•
www.arduino.cc/en/
www.mikroe.com
www.doctormonk.com
www.matrixmultimedia.com
www.eshop.icsat.co.uk
www.designspark.com
Arduino IDE – free download
• Hardware:
•
•
•
Win PC
Mac’s
Linux
• Websites cont’d:
•
•
•
•
•
Brian P Smith
Rapid
Maplin
RS
Farnell
Technology Supplies Ltd
55
Programmable Software Links
•
Yenka
•
Logicator
•
http://www.yenka.com/technology/
•
http://www.logicator.net/
•
Genie
•
Flowol4
•
http://www.genieonline.com/
•
http://www.flowol.com/Flowol4.aspx
•
Picaxe
•
http://www.picaxe.com/
•
Arduino
•
http://www.arduino.cc/
Chips Ahoy! – The path to programmable components
BOOKLIST
Useful Books
Book
Author
ISBN
Comments
30 Arduino projects
Simon Monk
978007174133-0
A source of ideas
Programming Arduino – Getting
started
Simon Monk
978007178422-5
A good starter for coding
Programming Arduino – Next
steps
Simon Monk
978007183025-6
More coding with advanced
circuits
Dr Monk’s Arduino Shield
Projects Vol 1 - LEDs
Simon Monk
978148009192-4
Lots of LEDs circuits & ideas
Arduino Cookbook
Michael Margolis
978059680247-9
Arduino Bible of code and circuits
Mastering Microcontrollers –
Helped by Arduino
Clemens Valens
978190792023-3
Advanced coding & projects
Arduino for Dummies
John Nussey
978111844637-9
Getting started
Arduino Projects for Dummies
Brock Craft
978111855147-9
A range of fully worked projects
Exploring Arduino
Jeremy Blum
978111854936-0
Advanced coding & projects
Arduino Circuits & Projects
Guide
Gunter Spanner
978190792025-7
Introduction + some interesting
projects
Chips Ahoy! – The path to programmable components
EQUIPMENT SUPPLIERS
Useful Suppliers
Name
Website
Parts
Proto-Pic
http://proto-pic.co.uk/
Full range of Arduino + parts + robotics etc
Sparkfun
https://www.sparkfun.com/
Full range of Arduino + shields & interesting parts
Adafruit
https://www.adafruit.com/
Full range of Arduino + shields, innovative parts, good
learning & support sections
Arduino
http://arduino.cc/en/
Arduino official site with shop and software etc
Kitronik
http://www.kitronik.co.uk/
Arduino + other electronic parts & projects
TinyDuino
http://tiny-circuits.com/
TinyDuino official site with shop & distributors
TinkerKit
http://www.tinkerkit.com/
ICSAT eShop
http://eshop.icsat.co.uk/
TinyDuino Reseller
Rapid Electronics
http://rapidonline.com
Full range of parts + PICAXE, GENIE, Arduino
Chips Ahoy! – The path to programmable components
ARDUINO 101
Arduino 101
•
Bare Minimum code needed to get started
•
This example contains the bare minimum of code you need for an Arduino sketch to compile: the setup()
method and the loop() method.
•
Hardware Required
•
Arduino Board
•
Circuit
•
Only your Arduino Board is needed for this example.
•
Code
•
The setup() function is called when a sketch starts. Use it to initialize variables, pin modes, start using libraries,
etc. The setup function will only run once, after each powerup or reset of the Arduino board.
After creating a setup() function, the loop() function does precisely what its name suggests, and loops
consecutively, allowing your program to change and respond as it runs. Code in the loop() section of your sketch
is used to actively control the Arduino board.
The code below won't actually do anything, but it's structure is useful for copying and pasting to get you started
on any sketch of your own. It also shows you how to make comments in your code.
•
•
•
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
Brian P Smith
62
Blinking a LED
•
Blink
•
Code
•
This example shows the simplest thing you can do with an
Arduino to see physical output: it blinks an LED.
•
•
Hardware Required
/*
Blink
Turns on an LED on for one second, then off for one second,
repeatedly.
•
•
Arduino Board
LED
This example code is in the public domain.
*/
•
Circuit
•
To build the circuit, attach a 220-ohm resistor to pin 13. Then
attach the long leg of an LED (the positive leg, called the anode)
to the resistor. Attach the short leg (the negative leg, called the
cathode) to ground. Then plug your Arduino board into your
computer, start the Arduino program, and enter the code below.
Most Arduino boards already have an LED attached to pin 13 on
the board itself. If you run this example with no hardware
attached, you should see that LED blink.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
•
Brian P Smith
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage
level)
delay(1000);
// wait for a second
digitalWrite(led, LOW); // turn the LED off by making the
voltage LOW
delay(1000);
// wait for a second
}
63
Fading an LED
•
Fading
•
Code
•
Demonstrates the use of the analogWrite() function in fading
an LED off and on. AnalogWrite uses pulse width modulation
(PWM), turning a digital pin on and off very quickly, to create
a fading effect.
•
/*
Fade
•
Hardware Required
•
•
•
•
Arduino board
Breadboard
a LED
a 220 ohm resistor
•
Circuit
•
Connect the anode (the longer, positive leg) of your LED to digital
output pin 9 on your Arduino through a 220-ohm resistor. Connect
the cathode (the shorter, negative leg) directly to ground.
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int led = 9;
// the pin that the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
// declare pin 9 to be an output:
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// set the brightness of pin 9:
analogWrite(led, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
}
Brian P Smith
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
64
Checking a button
•
Button
•
Code
•
Pushbuttons or switches connect two points in a circuit when you
press them. This example turns on the built-in LED on pin 13
when you press the button.
•
/*
Button
•
Hardware
•
•
•
•
•
Arduino Board
momentary button or switch
10K ohm resistor
breadboard
hook-up wire
•
Circuit
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
This example code is in the public domain.
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0;
// variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
}
Brian P Smith
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
65
Reading an analogue value
•
Analog Input
•
Code
•
A potentiometer is a simple knob that provides a variable
resistance, which you can read into the Arduino board as an
analogue value. In this example, you'll connect a potentiometer
to one of the Arduino's analog inputs to control the rate at which
the built-in LED on pin 13 blinks.
•
The analogRead() command converts the input voltage range, 0 to 5
volts, to a digital value between 0 and 1023. This is done by a circuit
inside the Arduino called an analogue-to-digital converter or ADC.
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0
and turning on and off a light emitting diode(LED) connected to digital
pin 13. The amount of time the LED will be on and off depends on
the value obtained by analogRead().
•
Hardware Required
•
•
•
Arduino Board
Potentiometer
built-in LED on pin 13
•
Circuit
•
*/
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the
sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}
Brian P Smith
66
Playing a tune
•
Play a Melody using the tone() function
•
Code
•
This example shows how to use the tone() command to generate
notes. It plays a little melody you may have heard before.
•
•
Hardware Required
•
•
•
•
Arduino board
8 ohm small speaker or piezo transducer
100 ohm resistor
hook-up wire
The code below uses an extra file, pitches.h. This file contains all the
pitch values for typical notes.
/*
Melody circuit: * 8-ohm speaker on digital pin 8
This example code is in the public domain.
*/
#include "pitches.h"
•
Circuit
•
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3,
NOTE_C4};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {4, 8, 8, 4,4,4,4,4 };
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
}
}
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
void loop() {
// no need to repeat the melody.
}
Brian P Smith
67
Light to sound generator
•
Pitch follower using the tone() function
•
Code
•
This example shows how to use the tone() command to generate
a pitch that follows the values of an analog input
•
•
Hardware Required
•
•
•
•
•
•
8-ohm speaker
1 photocell
4.7K ohm resistor
100 ohm resistor
breadboard
hook up wire
The code for this example is very simple. Just take an analog input and
map its values to a range of audible pitches. Humans can hear from 20 20,000Hz, but 120 - 1500 usually works pretty well for this sketch.
The sketch is as follows:
/*
Pitch follower Plays a pitch that changes based on a changing analog
input
•
Circuit
•
•
circuit:
* 8-ohm speaker on digital pin 9
* photoresistor on analog 0 to 5V
* 4.7K resistor on analog 0 to ground
*/
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the analog input range (in this case, 400 - 1000 from the
photoresistor)
// to the output pitch range (120 - 1500Hz)
// change the minimum and maximum input numbers below
// depending on the range your sensor's giving:
int thisPitch = map(sensorReading, 400, 1000, 120, 1500);
}
Brian P Smith
// play the pitch:
tone(9, thisPitch, 10);
delay(1);
// delay in between reads for stability
68
LED Bar graph
•
LED Bar Graph
•
Code
•
The bar graph - a series of LEDs in a line, such as you see on
an audio display - is a common hardware display for analog
sensors. It's made up of a series of LEDs in a row, an analog
input like a potentiometer, and a little code in between.
The sketch works like this: first you read the input. You map
the input value to the output range, in this case ten LEDs.
Then you set up a for loop to iterate over the outputs. If the
output's number in the series is lower than the mapped input
range, you turn it on. If not, you turn it off.
•
/*
LED bar graph
•
•
Hardware Required
•
•
•
•
•
Arduino Board
(1) LED bar graph display or 10 LEDs
(10) 220 ohm resistors
hook-up wire
breadboard
•
Circuit
Turns on a series of LEDs based on the value of an analog sensor.
This method can be used to control any series of digital outputs that
depends on an analog input.
The circuit: LEDs from pins 2 through 11 to ground
*/
const int analogPin = A0; // the pin that the potentiometer is attached
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = { 2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of LED pins
void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
}
Brian P Smith
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
69
Chips Ahoy! – The path to programmable components
PICAXE 101
PICAXE 14M2 Pinouts
•
Below is the pinout for the PICAXE 14M2 and the pin names (note new format
PORT.PIN)
Electronics getting started
THE BASICS
Brian P Smith
Systems Approach
OPEN LOOP
INPUTS
PROCESS
CLOSED LOOP
Brian P Smith
OUTPUTS
Input Components / Systems
•
Sensors
– Temperature
– Light
– Position
– Touch
– Wet/dry
– Accelerometer
– Compass
– Humidity
•
Brian P Smith
Switches
– Toggle
– Slide
– Microswitch
– Push to make (PTM)
– Push to break (PTB)
– Membrane
– Magnetic
Sensor examples
Brian P Smith
Process Components / Systems
•
Digital
– Combinational
• Logic gates
– Sequential
• Counters
• Decoders
– Configurable
• Preprogrammed PICs / AVR
– Programmable
• PICs (PICAXE, Genie)
• SBCs (Arduino, Rpi, PIC
Clicker)
•
Brian P Smith
Analogue
– Transistors
– Op-amps
• Amplifier
• Comparator
The Transistor
Brian P Smith
Transistor circuits
Brian P Smith
Designing with Transistors
Brian P Smith
Output Components / Systems
•
Displays
– LEDs
• Standard
• Bi-colour
• RGB
• Neopixel
– Bulbs
– LCDs
– Electroluminescent panels
•
•
Brian P Smith
Sound
– Speakers
– Buzzers
– Piezo transducers
Motors
– DC motor
– Servo motor
• Standard 180°
• Continuous rotation
– Stepper
Systems ‘Glue’
•
•
•
•
Monostables
Astables
Latches
PSU’s
– Type
• Battery
• AA, AAA, PP3
• Coin / button cells
• LiPo
– Voltage regulator
•
Brian P Smith
Interface devices
– Transistors
• NPN
• MOSFET
– Relays
– Drivers
• Standard
– ULN2803A (8 drivers)
– ULN2003 (7 drivers)
• H-Bridge
– L293D
– 754410NE
Monostables
Brian P Smith
More monostables
Brian P Smith
Smart monostables
Brian P Smith
Astable timers
Brian P Smith
Logic gate astables
Brian P Smith
Other astables
Brian P Smith
Relays
Brian P Smith
Relay ratings
Brian P Smith
Power Supplies
Brian P Smith
Electronic Building Blocks
Brian P Smith
Support
•
•
•
•
•
CADCAM
PCB manufacture
Veroboard / Stripboard
Breadboards
3D Printing
– Cases
– Fitments / holders etc.
Brian P Smith
Electronics getting started
THE MATHS FOR DESIGN
Brian P Smith
Basic Calculations 1
•
•
•
•
•
Ohms Law
Used to calculate the voltage across a
component, the current flowing
through it or it’s resistance.
Vital for some components such as
LEDs, otherwise too much current
destroys them!
V=IxR
Voltage = current x resistance
Voltage – volts
Current – amps
Resistance - ohms
Brian P Smith
Basic Calculations 2
•
•
•
•
Power Law
Used to calculate the energy (heat)
generated by a component.
If the heat generated is greater than
it’s rating it will fail due to over
heating.
Used to ensure resistors or transistors
have the correct rating.
Power – Watts
Resistance – Ohms
Current - Amps
Brian P Smith
Resistor Colour code
Brian P Smith
Preferred values
Brian P Smith
Resistor in series
Brian P Smith
Electronics getting started
PROJECT IDEAS
Brian P Smith
Electronics getting started
NITE LIGHT
Brian P Smith
Nite Light
Brian P Smith
Investigation
Brian P Smith
Which blocks?
Brian P Smith
Circuit diagram
Brian P Smith
Assembly
Brian P Smith
Testing
Brian P Smith
Evaluation
Brian P Smith
Manufacture
Brian P Smith
Mass manufacture
Brian P Smith
Improvements to the project
Brian P Smith
Electronics getting started
MICROLIGHT
Brian P Smith
μLight (Microlight)
Brian P Smith
Project Analysis
Brian P Smith
Investigate
Brian P Smith
Disassembly
Brian P Smith
Building Blocks
Brian P Smith
Circuit Design
Brian P Smith
Circuit Assembly
Brian P Smith
Circuit testing
Brian P Smith
Plan of manufacture
Brian P Smith
Mass manufacture
Brian P Smith
Evaluation
Brian P Smith
Case Designs
Brian P Smith
Case detailing
Brian P Smith
Project review
Brian P Smith
Improvements to the project
Brian P Smith
Download