1
0
Fork 0

Presentation as given to LTS

This commit is contained in:
Shawn Nock 2017-11-22 07:26:54 -05:00
parent 48652df346
commit 2719b55a00
31 changed files with 23918 additions and 203 deletions

16629
art/Arduino-annotated.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

BIN
art/Arduino_Uno.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 916 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 274 KiB

After

Width:  |  Height:  |  Size: 203 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 394 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

View File

@ -0,0 +1,55 @@
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include "Adafruit_CCS811.h"
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
Adafruit_CCS811 ccs;
DHT dht(DHTPIN, DHTTYPE);
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
void setup() {
Serial.begin(9600);
Serial.println("Let's Talk Science!");
dht.begin();
ccs.begin();
tsl.begin();
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
tsl.enableAutoRange(true);
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
}
void loop() {
delay(500);
float humidity = dht.readHumidity();
float temp = dht.readTemperature();
Serial.print(humidity);
Serial.print(" ");
Serial.print(temp);
Serial.print(" ");
ccs.readData();
int co2 = ccs.geteCO2();
int tvoc = ccs.getTVOC();
Serial.print(co2/100);
Serial.print(" ");
Serial.print(tvoc/10);
Serial.print(" ");
sensors_event_t event;
tsl.getEvent(&event);
Serial.print(event.light/10);
Serial.println("");
}

@ -0,0 +1 @@
Subproject commit 9383ee8daacada2e1091092c334ed11c03dc5f27

@ -0,0 +1 @@
Subproject commit e985f2253a687ef377cde3dcfb1f788830d1bc09

@ -0,0 +1 @@
Subproject commit 0c88fba4e7658a9425bbcaca78a58e6a7abfd17e

@ -0,0 +1 @@
Subproject commit c97897771807613d456b318236e18a04b013410b

View File

@ -1,9 +1,14 @@
[file]
talk.ebook.pdf
[skip]
7,8,9,
[end_user_slide]
6
[notes]
### 2
29### 4
Nuit Blanche - Take over the city w/ interactive art
Work in Practice @ Explode (Illustrators explaining their artistic practice and portfolio feedback)### 22
Work in Practice @ Explode (Illustrators explaining their artistic practice and portfolio feedback)### 9
### 22
Devices that are 'on' have current flowing through them. Most of what we'll do today is getting current to flow through devices in various ways.### 23
Potential is the push that moves current.

View File

@ -11,9 +11,9 @@ colorlinks: true
By the end of this class, you'll:
- Know how to create programs for Arduino and run them.
- Be familiar with basic electionics concepts
-
- Assemble a kit of sensors into a complete system
- Know how to program the Arduino platform to collect and plot the sensor data
## UnPacked / Unlondon
@ -30,51 +30,6 @@ membership and the community-at-large.
- ExplodeConf
- Nuit Blanche
## Shawn: Day Job
Embedded Systems Designer, Monadnock Systems
- Indoor location tracking w/ Bluetooth
- Keychain / Fitness Band Widgets
- Joystick for VR
- Remote Controls
- Internet of S*#t
## Shawn: The Fun Stuff
Hacker, Church of the Weird Machine, Odd Duck
\begin{columns}[c]
\column{0.50\textwidth}
\begin{itemize}
\item Arduino compatible implant
\item EEG Games / Toy Hacking
\item Brain Stimulation
\item Be Weird, Make Weird, Have Fun!
\end{itemize}
\column{0.50\textwidth}
\begin{center}
\includegraphics[width=0.95\textwidth]{images/timbo.jpg}
\vspace{5mm}
\includegraphics[width=0.95\textwidth]{images/circadia.jpg}
\end{center}
\end{columns}
## Titus: Day Job
Executive Director, UnPacked
- 121Studios
- St. Thomas STEM Centre
- &c
## Titus: The Fun Stuff
Thinker, Jack of all Trades
# What's in your kit?
## Kit Contents
@ -88,10 +43,11 @@ Thinker, Jack of all Trades
###Sensors
- Temperature / Humidity
- Light Sensor
- CO2 Gas Sensor
## What is Arduino?
<Missing Arduino graphic>
\center{\includegraphics[width=0.75\textwidth]{images/arduino-annotated.png}}
It's a kit (on a board) with the bare minimum components to easily use the $\mu$C
hardware. They do the basic, boring design needed for any board, so users only
@ -101,11 +57,14 @@ need to add the neat stuff.
The Arduino folks also adapted an *Integrated Development Environment*
(IDE) to their boards. This IDE allows us to easily write programs for
their boards and then write the programs to the $\mu$C.
their boards and then transfer the programs to the $\mu$C.
\Large Get the Arduino IDE:
[https://www.arduino.cc/en/Main/Software](https://www.arduino.cc/en/Main/Software)
Get the libraries and sample code for this workshop:
[https://monadnock.ca/lts-workshop-Nov2017.zip](https://monadnock.ca/lts-workshop.zip)
<!-- ## Installation -->
<!-- \Large Get installing -->
@ -240,7 +199,7 @@ Can be a:
* Batteries
* Solar Panel
In our circuits, your laptop is converting it's power source to $\SI{5}{\volt}$ and
In our circuits, your computer is converting it's power source to $\SI{5}{\volt}$ and
delivering power to our circuit via USB.
## $\mu$Controller
@ -279,7 +238,7 @@ repeat^[some commands change the address of the next fetched command]
Most of the pins on the Arduino can be set for INPUT or OUTPUT mode.
- INPUT mode pins listen for a signal ($0$ or $1$) from another device
- INPUT mode pins listen for a signal (High or Low) from another device
- OUTPUT mode pins drive the pin High or Low
## Floating Pins
@ -314,14 +273,24 @@ will not flow and the LED is off.
* Board: Arduino/Genuino UNO
* Port: \ldots
<!-- ## Fetch the Class Code -->
## Fetch the Class Code
<!-- - Download and extract: [https://nocko.se/assets/arduino-medway.zip](https://nocko.se/assets/arduino-medway.zip) -->
<!-- - File$\rightarrow$Preferences -->
<!-- - Browse for sketchbook -->
<!-- - Point it at the `sketchbook` subfolder of the extracted download -->
<!-- - You should now see a list of projects in the -->
<!-- File$\rightarrow$Sketchbook menu. -->
Download and extract: [https://monadnock.ca/static/lts-workshop-Nov2017.zip](https://monadnock.ca/static/lts-workshop-Nov2017.zip)
- File$\rightarrow$Preferences
- Browse for sketchbook
- Point it at the `sketchbook` subfolder of the extracted download
- You should now see a list of projects in the
File$\rightarrow$Sketchbook menu.
## Setup the Sensor Libraries (Sketchbook)
\begin{center}
\includegraphics[width=0.5\textwidth]{images/preferences.png}
\includegraphics[width=0.5\textwidth]{images/preferences2.png}
\end{center}
For the *Sketchbook Location* browse to the extracted lts-workshop-Nov2017/sketchbook directory.
## The Code Environment
@ -349,12 +318,13 @@ void loop() {
~~~
# Add Some Parts
# Lets Add Some Parts
## Breadboard
![Breadboard](images/breadboard.png)\
- Connectors gently pinch component leads, wires.
- Have internal connections
@ -364,25 +334,28 @@ We use the long rows to distribute power. The Arduino outputs
$\SI{5}{\volt}$ on the pin marked `5V`, the reference (GND) is marked
`GND`.
![Arduino + Breadboard](images/bb+uno.png)
## Buzzer & Button: Hardware
\begin{center}
\includegraphics[width=0.98\textwidth]{images/buzzer-breadboard.png}
\includegraphics[width=0.92\textwidth]{images/rails.png}
\end{center}
## Push Button: Zoom
## DHT11: Temperature and Humidity Sensor
\begin{center}
\includegraphics[width=0.98\textwidth]{images/bb+switch+zoom.png}
\includegraphics[width=0.98\textwidth]{images/dht11-wide.png}
\end{center}
## DHT11: Zoom
\begin{center}
\includegraphics[width=0.25\textwidth]{images/dht11-zoom.png}
\end{center}
Connect left pin to Vcc rail ($+$) and right pin to GND ($-$) rail. Second from left connects to Arduino pin #2 *and* a resistor to Vcc
## Pullup / Pulldown Resistors
Reading a floating pin is **bad**. A switch only connects
and disconnects a wire. When the wire is disconnected... the INPUT pin
is floating!
The DHT11 uses an *Open Collector* output that switches between *Not Connected* and *Connected to Ground*. When it's not connected, the pin is left *floating*. How do we make a floating pin look like a High signal?
\vfill
@ -391,40 +364,28 @@ is floating!
Connect the pin to Vcc so that it reads High; use a
resistor to prevent short circuit (limit current).
## Buzzer: Zoom
## DHT11: Run example code
We can test the sensor by running sample code from the library.
Open the sample: File$\rightarrow$Examples$\rightarrow$DHT Sensor Library$\rightarrow$DHTtester
Once the sample is loaded click the *upload* button (looks like right arrow)
## Arduino Serial Monitor
Once the sample code is uploaded, you can open the *Serial Monitor* to view the output. It can be found under:
Tools$\rightarrow$Serial Monitor
## DHTtester Output
\begin{center}
\includegraphics[width=0.98\textwidth]{images/buzzer-zoom.png}
\includegraphics[width=0.98\textwidth]{images/monitor-dht.png}
\end{center}
## Buzzer / Button: Software (Part 1)
~~~ C
#define BUTTON 2
#define BUZZER 8
int button_state;
void setup() {
pinMode(BUTTON, INPUT);
pinMode(BUZZER, OUTPUT);
digitalWrite(BUZZER, LOW); /* Start w/ LED off */
}
~~~
## Programming Note: Variables
Declare a variable:
~~~ C
int button_state = HIGH;
~~~
`<type> <name> [= <initial value>];` (value optional)
It's a name, like a preprocessor `#define`, but the value can change
at *runtime*
## Programming Note: *If* Statement
<!-- ## Programming Note: *If* Statement
~~~ C
if (condition) {
@ -446,129 +407,207 @@ In C-like languages, the `==` operator checks if two things
- It returns `1` if the items are equal, *or*
- It returns `0` if the items are not equal
-->
## Programming Note: Functions
Functions make it easy to reuse code. You already know / use several
functions:
- pinMode
- digitalWrite
- delay
digitalRead(pin number) returns HIGH or LOW depending on current state
of any **INPUT** pin.
You can write your own functions!
## Programming Note: Writing Functions
~~~ C
void my_function(int arg1, ...) {
// Do fun things
}
~~~
void:
: Return type. Void means nothing returned. Can be any type.
my_function:
: A name for your function
arguments:
: A type and name for any parameters you want to use in your function
from the outside.
Define a function once, you can use it again and again. Better than
copy/pasting.
## Push Button: Software (Part 2)
~~~ C
void buzz(int ms) {
digitalWrite(BUZZER, HIGH);
delay(ms);
digitalWrite(BUZZER, LOW);
}
void loop() {
button_state = digitalRead(BUTTON);
if (button_state == LOW) {
buzz(100);
}
}
~~~
# More Parts
## Potentiometer
*Puh - ten - she - ometer*
- *Pot* for short
- A Voltage Divider
- Voltage at *Wiper* is somewhere between potential at the two
terminals.
- The exact wiper potential depends on the position of the knob/lever.
## ADC: Analog to Digital Converter
- A peripheral of the $\mu$Controller
- Measures Potential, outputs a number
- In our case, $\SI{0}{\volt}\rightarrow0$ and
$\SI{5}{\volt}\rightarrow1023$
- A0-A5 pins on Arduino can be used
- Fun uses: Reading pot position, sampling audio, reading from sensors
## The Pot Hookup
## TSL2561: Ambient Light Sensor
\begin{center}
\includegraphics[width=0.98\textwidth]{images/bb+switch+pot.png}
\includegraphics[width=0.98\textwidth]{images/tsl2561-wide.png}
\end{center}
Connect center pin to `A0`, outer pins to ($+$) and ($-$) rails
## TSL2561: Zoom
## Pot Code
\begin{center}
\includegraphics[width=0.3 \textwidth]{images/tsl-zoom.png}
\end{center}
`analogRead(`*pin*`)` returns the voltage at the pin (0--1023), it can
be used directly or via variable.
Connect Vin to ($+$) rail, GND to ($-$) rail, SDA to Arduino pin A4 and SCL to A5
## TSL2561: Run example code
We can test the sensor by running sample code from the library.
Open the sample: File$\rightarrow$Examples$\rightarrow$Adafruit TSL2561$\rightarrow$sensorapi
Once the sample is loaded click the *upload* button (looks like right arrow)
## TSL2561 Sample Output
\begin{center}
\includegraphics[width=0.98\textwidth]{images/monitor-tsl.png}
\end{center}
## CCS811: Gas Sensor
\begin{center}
\includegraphics[width=0.98\textwidth]{images/CCS811-wide.png}
\end{center}
## CCS811: Zoom
\begin{center}
\includegraphics[width=0.3\textwidth]{images/ccs11-zoom.png}
\end{center}
*Vin* to ($+$) rail, GND *and* WAKE to ($-$) rail, SDA to TSL2561 SDA, SCL to TSL2561 SCL
## CCS811: Run example code
We can test the sensor by running sample code from the library.
Open the sample: File$\rightarrow$Examples$\rightarrow$Adafruit CCS811 Library$\rightarrow$CCS811_test
Once the sample is loaded click the *upload* button (looks like right arrow)
## CCS811 Sample Output
\begin{center}
\includegraphics[width=0.98\textwidth]{images/monitor-ccs.png}
\end{center}
# Programming
## Part 1; Includes
~~~ C
#define LED 13
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
#include "Adafruit_CCS811.h"
#include "DHT.h"
~~~
## Part 2; Definitions
~~~ C
#define DHTPIN 2
#define DHTTYPE DHT11
~~~
## Part 3; Objects
~~~ C
Adafruit_CCS811 ccs;
DHT dht(DHTPIN, DHTTYPE);
Adafruit_TSL2561_Unified tsl =
Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
~~~
## Programming Note: Variables
Declare a variable:
~~~ C
int button_state = HIGH;
~~~
`<type> <name> [= <initial value>];` (value optional)
It's a name, like a preprocessor `#define`, but the value can change
at *runtime*
## Part 4; Setup
~~~ C
void setup() {
pinMode(LED, OUTPUT);
Serial.begin(9600);
Serial.println("Let's Talk Science!");
dht.begin();
ccs.begin();
tsl.begin();
while(!ccs.available());
float temp = ccs.calculateTemperature();
ccs.setTempOffset(temp - 25.0);
tsl.enableAutoRange(true);
tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);
}
void loop() {
digitalWrite(LED, HIGH);
delay(analogRead(A0));
digitalWrite(LED, LOW);
delay(analogRead(A0));
~~~
## Part 4; Main Loop
~~~ C
loop () {
delay(500);
...
}
~~~
Since the delay() calls use the result of analogRead (0-1023), the
blink rate changes with knob position.
## Part 4a; Temperature / Humity Sensor Read
# Shall we play a game?
~~~ C
loop () {
...
float humidity = dht.readHumidity();
float temp = dht.readTemperature();
## Hooking up a bunch of LEDs
Serial.print(humidity);
Serial.print(" ");
Serial.print(temp);
Serial.print(" ");
...
}
~~~
## Part 4b; Gas Sensor Read
~~~ C
loop () {
...
ccs.readData();
int co2 = ccs.geteCO2();
int tvoc = ccs.getTVOC();
Serial.print(co2/100);
Serial.print(" ");
Serial.print(tvoc/10);
Serial.print(" ");
}
~~~
## Part 4c; Light Sensor Read
~~~ C
loop () {
...
sensors_event_t event;
tsl.getEvent(&event);
Serial.print(event.light/10);
...
}
~~~
## Part 4d; Ending the output
~~~ C
loop () {
...
Serial.println("");
}
~~~
## Complete Sensor Output
\begin{center}
\includegraphics[width=0.65\textwidth]{images/bb+switch+pot+leds.png}
\includegraphics[width=0.98\textwidth]{images/monitor-all.png}
\end{center}
## LEDs, the first one
## Arduino Serial Plotter
Looks complicated, but for each LED: The short leg goes to ground, the
long leg goes to one end of a resistor, and the other end of the
resistor goes to the arduino pin.
Why such a terse, boring output format?
Arduino has a feature where it will plot data in this specific format. You can see the plotted output by closing the Arduino Serial Monitor and Opening *Arduino Serial Plotter* (Tools$\rightarrow$Serial Plotter)
## Arduino Serial Plotter Output
\begin{center}
\includegraphics[width=0.55\textwidth]{images/one-led.png}
\includegraphics[width=0.98\textwidth]{images/plotter.png}
\end{center}
## Programming Note: `for` Loop
<!-- ## Programming Note: `for` Loop
~~~ C
for ( initializer ; condition; increment ) {
@ -618,9 +657,9 @@ void loop () {
delay(delay_ms);
}
}
~~~
~~~ -->
## Programming Note: `while` Loop
<!-- ## Programming Note: `while` Loop
~~~ C
while ( statement ) {
@ -639,9 +678,9 @@ condition
increment
: Runs *after* each loop. Often used to increment variables.
\center{*All fields are optional*}
\center{*All fields are optional*} -->
## Winner, Winner, Chicken Dinner
<!-- ## Winner, Winner, Chicken Dinner
~~~ C
#define WINNER 5
@ -700,9 +739,28 @@ loop () {
check_delay(i, delay_ms);
}
}
~~~
~~~ -->
# The End?
# Undiscussed Issues
## Obtaining the kit
- Educators would need to order several different parts (SKUs).
- Vendors keep very little stock (~4 dozen).
- Educators may need to "google around" to find parts, most likely from abroad (US or China)
## Installing the Software
- School machines may prevent software installation
- School machines may not be conventional computers (iPads, Chromebooks)
## Troubleshooting the Build
- Breadboards aren't rugged.
- Sockets wear out quickly
- Parts may need to be wiggled
- Some parts may be DoA
- Most troubleshooting requires a Multimeter (and training on how to use it)
# Extra Credit
## Ohm's Law