-
Notifications
You must be signed in to change notification settings - Fork 6
Class 1 notes
Arduino refers to hardware, code, and the software for getting the code on the hardware.
It’s also a community of thousands of examples and helpful code snippets.
We program devices compatible with the platform in the C language with lots of Arduino specific code libraries. There is no operating system or anything like that. The code you upload is (basically) all there is on the chip.
The Teensy device we use is based on a microprocessor chip that already existed. Paul Stoffregen of PJRC decided to make work with the Arduino platform and it’s become one of the main Arduino devices people use due to its price, form factor, and features. The original Arduino UNO is still a useful device but it can’t do audio at anywhere near the level we need it to.
A Teensy 3.2 and an Arduino UNO
Arduino hardware can run code like any other microcontroller but it differs form a device like a PC or phone.
With a laptop for example you communicate with the device though the keyboard or a USB mouse and get info though the screen. But that’s kind of the extent of interacting with it without adding on more hardware.
An Arduino device can arbitrarily read or write digital or analog signals to and from each of it’s pins. This might not seem like a big deal but it allows you to make relatively simple standalone devices that can:
- Read from a controls or sensors
- Turn this reading into data that we can manipulate
- Use this data to effect our output
Here’s a basic example. It uses this code.
I’ll be building it on a breadboard which you can read more about here but all I’m doing is making the connections shown in this diagram.
The Teensy reads the voltage from the potentiometer. We can think of it mixing between the high voltage, 3.3V and the low voltage, ground aka 0 Volts.
The Teensy takes this voltage reading and turns it into a number from 0 to 1023 which is 10 bits of precision.
The code takes this number, modifies it to go to a different range and uses this new variable to control how fast the LED will blink on and off.
When we code we're making logical comparisons and manipulating variables to get a desired output based on a certain input. That's pretty much it! Thought this course you'll be using these same basic tool to make much more complex devices.
Voltage can be used to power things but it’s also data.
Power (Watts) = Voltage * Current (Amps)
There is very little current going between the pot and the Teensy. We can just think of it as analog data.
We do need power to light up the LED. The Teensy can send about 20 milliamps out of each pin. This is more than enough to light up the little LED so a resistor is used to limit the current and voltage.
The Teensy is powered via USB and turns it into the 3.3V it needs. Don’t connect anything over 3.3V to any Teensy pin.
Audio is changing voltage. The headphone jack you’ll have is just enough wattage for headphones but couldn’t move a speaker.
A digital device an have analog inputs and outputs.
Analog means that there is information between two points. We can keep zooming in and find more info.
Digital can only be on or off. There's nothing between 0 and 1 but there is also no ambiguity.
The teensy or a phone are digital devices in that deep down all it are millions or billions of transistors that can either be on or off. But if you have 8 transistors you can count to 255. More on bits and bytes and digital vs analog thoughts later.
An analog pin can read voltage between 0 and 3.3V at a resolution of 12 bits, 0-4095.
A digital pin can read if something is high or low, that is it's over or under a certain threshold, or output 0 or 3.3V.
The Teensy can also output “pseudo” analog voltage on some of it’s pins. This is what's done in the better sound example. This PWM signal is great for LEDs but not audio. That’s why the Bleep Base uses the audio adapter which enables the Teensy to send and receive 16 bit analog signals easily.