How To Guides How to install Arduino libraries Arduino libraries are collections of code that are designed to provide additional, reusable functionality or to simplify using external electronic modules. Libraries typically come with examples of how to use them. The library developer usually provides online documentation and explains how it possibly relates to what you are trying to achieve. Installing a library There are three different ways to install libraries; we'll show you each of them. Arduino Library Manager The simplest method of installing libraries is using the Library Manager built into the Arduino IDE. You can access the Library Manager from the menu bar: A new window will open: From here you can search for libraries to use in your code. Only a few libraries are currently available this way, as this feature is relatively new. You will often have to manually download and install a library, following the other two processes. ZIP library Locate and download a library you wish to use. Sometimes the library will download as a *.zip archive, which can sometimes be installed directly without restarting the Arduino IDE. Similar to the Library Manager, this option is in the menu bar: Use the file dialog to locate and select the zip file from your Downloads folder. You will be notified if the installation has been successful – otherwise you'll need to install manually. Manually adding libraries This is the original method of adding libraries. Locate the Arduino folder inside your Documents directory. Open the libraries folder. If not found, create a new folder with that name (must be lowercase). Unzip the library archive that you wish to install. Inside the archive you should find a folder bearing the name of the library – for example 'MPR121'. Copy this entire folder (named 'MPR121' in our example) into the Arduino's libraries folder. Restart the Arduino IDE. In the menu bar, select Sketch > Include Library . You should now see that your library is listed: Powering an Arduino Here is some resources about powering Arduino or other electronic projects: General How to power an Arduino How to power a project What adapter? Portable / Battery powered For portable projects some info on battery usage. http://www.instructables.com/id/Powering-Arduino-with-a-Battery/ https://learn.adafruit.com/all-about-batteries/overview https://www.open-electronics.org/the-power-of-arduino-this-unknown/ 9V batteries are bad Using an MPR121 capacitive touch sensor The MPR121 is a tiny microchip formerly manufactured by NXP, now under Resurgent Semiconductor, it is a tiny surface mount device that provides 12 capacitive touch electrodes through an I2C interface. What is capacitive touch? Capacitive touch the the technology used on modern touch sensitive devices such as phone and tablet screens, trackpads and computer mice like Apple's Magic Mouse. Capacitive touch takes advantage of the human body being electrically conductive, this is why using a pen on a smart phone doesn't work and styluses for these devices are made of metal so they will make an electrical connection. Capacitive touch is relatively complex to understand but fundamentally the sensor can detect when you are in proximity or actually touching the electrode, or any conductive part between the chip and the end of the wire. If you extend a wire from the electrode, even if it is shielded with plastic, it will probably detect you touching the wire just the same as the exposed metal part. Adafruit MPR121 Power input: 3.3V to 5V Address: 0x5A, it is also relatively easy to configure the address to 0x5B, 0x5C or 0x5D allowing up to 48 electrodes (12 x 4). Wiring Wiring is pretty simple, it's an I2C component so it's relatively standard. Older Arduino boards Some older Arduino boards do not have SDA and SCL pins as shown in the diagrams, in this case you'll need to look it up on the boards documentation, however most Arduino boards used A4 as SDA and A5 as SCL. More info here: https://www.arduino.cc/en/reference/wire Adafruit MPR121 Library Adafruit, Sparkfun, Seeedstudio and Bare Conductive all provide Arduino libraries, however by far the best which includes tools for visualising the data is the Bare Conductive Touch Board library and grapher . All libraries should all work interchangeably as long as you get the correct address and IRQ pin. The key thing to remember when using examples from the Bare Conductive library is that they use the address 0x5C rather than the default 0x5A address used on both the Sparkfun and Adafruit boards, also ensure that you use the correct IRQ pin based on the example you are using. We have a tutorial on how to install a library here. Getting started After installing the library and wiring the board, go ahead and use the examples in the File > Examples menu in Arduino, the Simple Touch example is particularly good as it's simple to check it's working. Basic Example This is a basic example of using the MPR121 with the Bare Conductive MPR121 library to get the proximity value and touch status, this can easily be extrapolated into a project. Sketch: Basic Example CSV Example This is an example using the MPR121 with the Bare Conductive MPR121 library to output each electrode's touch status to the serial port as a comma separated string. This example can be modified to work with MaxMSP easily by changing the delimiter line to a space instead of a comma: #define DELIMITER " " You could also modify this example to output the proximity data, instead of the touch data by modifying the updateTouchData line to: MPR121.updateFilteredData(); And the getTouchData line to: Serial.print( MPR121.getFilteredData( i ) ); Sketch: CSV Example Using a Sparkfun MP3 Trigger The MP3 trigger is a board made by Sparkfun electronics that provides a way to play MP3 files from a Micro SD card via either one of 18 TRIG inputs on the board, or serial communication with the board. The MP3 Trigger has a headphone output which can be connected to powered speakers, or to your headphones for testing. Loading files You must us a micro SDSC (up to 2GB) card, or a SDHC (up to 32GB) card formatted in FAT16 or FAT32. After inserting the card you must power cycle the MP3 Trigger so it detects the card, this can be done by switching the USB <-> EXT switch back and forth. USB : means power from the Arduino. This isn't done via a 'USB' connector, but instead by connecting the FTDI pins (see below). If you are connecting to the board using an arduino, use this option EXT : means power via the 2.1mm connector to the left of the switch. If you are only using trigger pins with no Arduino control, get an external power source and use this option. Play Files Using The Trigger Pins File Naming If you want to play tracks on the board using the trigger pins, files should be named 001.MP3 through 018.MP3, and the MP3 Trigger will match the file name to the value on the pressed TRIG pin. If you have fewer than 18 files, you do not need to use all the pins -- just number as many files as you have, and trigger the pins accordingly. Hidden files are less likely to cause issues in this setup, though if you are having problems it's worth checking the instructions below. Wiring As all the control takes place on the MP3 Trigger, you have the option of using an external power source, but you can also use an Arduino to supply a basic voltage over the FTDI pins (you just need to make sure you select the correct power input on the USB <-> EXT switch described above). If you do want to power the MP3 Trigger via Arduino, you need 2 wires: Ground (GND on the on the MP3 Trigger connects to GND on the Arduino) Power (VCC on the MP3 Trigger connects to 5V on the Arduino) To test the trigger, take a jumper and try connecting together both pins of Trig1. The file with the name 001.mp3 should start to play. You can continue to test in this manner for all of your files. If you would like to incorporate this triggering into a project, you can think about using switches to trigger this connection. Play Files Using Serial Input File naming To control the MP3 Trigger using serial (as in the example below), you need to send it a track number to play. The command is sent in 2 parts: a 'p' which tells the board you want to play something, and then a number (start counting at 1). It looks like (in Leonardo code): Serial1.print("p") Serial1.write(1) This will get the MP3 Trigger to play the 'first' track. Note that the order of tracks is not the alphabetical or numeric order, but instead the order that the files appear on the SD card. If you are having trouble getting tracks playing in the correct order, it's good to check this. This means that while you can name the files anything you like, it's good to have a clear order to allow you to keep track. Important: If you are using a Mac to write the .mp3 files Macs do a weird thing where every time you plug in a memory stick, it creates a bunch of hidden files. This shouldn't be an issue if you're playing tracks using the triggers (as those target files with particular names) but it causes a lot of issues if you're trying to play files using serial. These files can't be removed in Finder, and instead need to be removed by opening up the volume using the terminal. You will need to repeat this step EVERY TIME you plug the SD card in (though you might only have to remove 1 or 2 files). Once you have finished copying your .mp3 files to the SD card, open up a mac terminal and type in the following: $ cd /Volumes/ # this navigates to the correct volume $ ls -a # verify what's in the output of this $ rm ._*.mp3 # this removes all of the thumbnails $ rm -r .Spotlight-V100 # deletes the .Spotlight-V100 folder $ rm -r .fseventsd # deletes the .fseventsd folder $ rm -r .Trashes # deletes the .Trashes folder $ ls -a # this shows all the files you have left Warning Be very careful when you are running the rm -r command: this will recursively delete files and is NOT reversible. Only run it when you know you are in the correct folder, and make sure you know which folder you are deleting) e.g. see below: I use ls -a multiple times to check what I still need to delete. At the end, all that's left is the .mp3s and the . and .. shortcuts (these aren't file and can be ignored). Wiring To connect the board to an Arduino, you need to connect the FTDI pins. This requires only 3 wires. Ground (GND on the on the MP3 Trigger connects to GND on the Arduino) Power (VCC on the MP3 Trigger connects to 5V on the Arduino) Data (RX on the MP3 Trigger to TX on the Arduino) Optionally you can connect the TX on the MP3 Trigger back to the RX on the Arduino if you wish to get playback status information. Basic Serial Input Example There are libraries available for the Sparkfun MP3 Trigger, but as it's very simple, it's easier to use Serial.print (or Serial1.print on Leonardo) to control it rather than a library. This Arduino code example will play 1.mp3 - 5.mp3 from the SD card with a 1 second delay between playing each. Sketch: Basic example - Arduino Uno Sketch: Basic example - Arduino Leonardo Warning Arduino Leonardo, unlike Arduino Uno has two serial ports. This tutorial contains code for both cases. The core difference is, if you want to use Arduino Leonardo you'll need to use Serial1 which is the RX/TX pins on pins 0 and 1, rather than Serial which is the USB serial monitor. Read more Sample MP3 files To help you get up and running quickly there are 5 example mp3's you can use with the basic example of Tom saying 1-5. If the files are getting played in a weird order, or some of them aren't playing, it's likely that you are having issues with hidden files. Please see the instructions above for more details. Example MP3 Files Convert your audio files to work with the MP3 trigger Once you have the example files working, you probably want to add your own audio files. We discovered they work best with audio files in the MP3 format, at between 4800-9200kHz. Your files may already be another format, so we need to convert them for the trigger to read them properly. There are a few programs with GUIs that do this, but this is also a great opportunity to learn about a command line program called ffmpeg , which is a very powerful program that converts media between formats. The full instructions are here: https://www.ffmpeg.org/ffmpeg.html . If you don't have ffmpeg installed, you can usually install it according to the instructions here: https://ffmpeg.org/download.html . To check whether you have it installed, open a terminal and try typing ffmpeg -- it should print out a help page. Ffmpeg takes an input file (preceded with '-i') and and output file (sometimes preceded with -o, but not always needed) and then you put in the settings you want it to use to do the conversion. So a simple line of code can change your MP4, ACC etc to our desired MP3 format: ffmpeg -i filename.mp4 -b:a 92K filename.mp3 Resources Sparkfun Hookup Guide -> this has lots more details about other features on the board, and how file naming works Making sounds with a piezo 'Piezo' normally refers to an electrical component which can be used to make sound, however more broadly a piezo is a component that is susceptible to the two-way piezoelectric effect where pressing or squeezing the piezo element can create a small voltage, and vice versa a small voltage can create a small expanding/contracting movement. Practically this means you can use a piezo to make sounds like a simple speaker, or act as a contact microphone. In this tutorial we'll look at wiring it up to Arduino with the Tone feature to create a melody. Wiring Wiring is simple, there are just two wires, applying power causes the piezo to expand, just as applying power to an LED causes it to illuminate. Ground Power Getting started To get started quickly you can use one of the examples from the Arduino examples menu: Read more about tone() Using a Sparkfun Sound Detector The Sound Detector is a board made by Sparkfun electronics that provides a way to detect ambient sound levels. There are three connections on the board: Audio - This is the raw audio from the microphone. Envelope - This is a analog value representing the volume of the ambient sound. Gate - This is a digital value representing if sound levels are low or high. Wiring There are two options for wiring, you can use both at the same time: Digital Wired up in digital mode the sound detector signals if the sound level is low with a LOW signal, and high with a HIGH signal. This method requires: Power (VCC to 5V) Ground (GND to GND) Gate to a digital pin on the Arduino (turquoise wire in the diagram) Analog Wired up in analog mode the sound detector provides voltage proportional to the sound level. This method requires: Power (VCC to 5V) Ground (GND to GND) Envelope to a analog pin on the Arduino (pink wire in the diagram) There are three wires: Diagram Getting started Once wired, the code is that of a standard digitalRead or analogRead to obtain the value. Example code reading envelope #define envelopePin A0 void setup() { Serial.begin( 9600 ); pinMode( envelopePin, INPUT ); } void loop() { Serial.println( analogRead( envelopePin ) ); } Example code reading gate #define gatePin 2 void setup() { Serial.begin( 9600 ); pinMode( gatePin, INPUT ); } void loop() { Serial.println( digitalRead( gatePin ) ); } Resources Sparkfun Hookup Guide How to connect a push button or switch Buttons and switches are a way of opening and closing a circuit, i.e. making and breaking a connection as one of the most rudimentary forms of sensor you can use with an Arduino. There are dozens of different types of switches and buttons, but at their most basic is the momentary push button which we'll be focusing on in the wiring and getting started sections below. However the same approach applies to these as it does to any other type of button or switch. Different types Rocker switch Push button Tactile button Reed switch Tilt switch Key operated switch Rotary switch Slide switch Micro switch Toggle switch There are many different types for different purposes: Push buttons ] Push buttons like those found in a computer keyboard are really useful for activating an action, like a start video button. Rocker, slide and toggle switches ] Rocker, slide and toggle switches work more like light switches holding their position, they can be a good way of indicating the mode of a device, such as playing video forward or backwards. Microswitches ] Micro switches can with motors to detect when it has reached the end of movement, such as in a 3D printer to stop the motor going too far over the end, or to detect if a draw is open or closed. Wiring Wiring up buttons and switches is simple, however there is a complexity you might not have thought about. Although a push button like that in the diagram only has two connections, which are closed by pressing the button, you have to add a resistor to make the circuit work properly. When the button is pressed the current on one side is able to flow to the other, however when the button is released the circuit is broken and the wire to the Arduino is known as floating, the voltage is indeterminate, so we need to connect it to ground to ensure the Arduino reads 0V. It's not possible however to do this otherwise when you apply 5V by closing the circuit you would create a short circuit, instead we connect the Arduino pin through a high value 10KΩ resistor to ground, this allows the circuit to quickly reach 0V when the button is released but prevents large amounts of current flowing when the button is pressed. Getting started The following is a simple circuit that will get your button controlling the LED built into the Arduino. #define ledPin 13 #define buttonPin 7 void setup() { pinMode( ledPin, OUTPUT ); pinMode( buttonPin, INPUT ); } void loop() { boolean btnState = digitalRead( buttonPin ); if ( btnState == HIGH ) { digitalWrite( ledPin, HIGH ); } else { digitalWrite( ledPin, LOW ); } } If you want to add a toggle functionality such that one press causes the LED to come on, and another press then turns it off, so you don't have to hold the button down things get a little bit more complex. The Arduino is a powerful computer and operates many times faster than human perception, as such when the mechanical push button is closed there is a small amount of 'bounce' where the circuit makes and breaks the connection a few times before it settles, this is detected by the Arduino as multiple presses. ] This diagram shows the signal bouncing up and down over a period of 10µS (0.00001 seconds) In effect this means that each time you press the button to toggle just once it toggles multiple times, you can fix this either with a small capacitor, or modifications to your Arduino sketch. The code here adds two major changes, first it tracks the current and previous button state through each loop meaning it can see if the button has changed from LOW to HIGH , and then adds a delay of 75ms to allow the button to settle but keep it fast enough that the user doesn't perceive this delay. #define ledPin 13 #define buttonPin 7 boolean ledState = LOW; boolean prevBtnState = LOW; void setup() { pinMode( ledPin, OUTPUT ); pinMode( buttonPin, INPUT ); } void loop() { boolean btnState = digitalRead( buttonPin ); if ( btnState == HIGH && prevBtnState == LOW ) { ledState = ! ledState; delay( 75 ); } digitalWrite( ledPin, ledState ); prevBtnState = btnState; } Using a HC-SR04 distance sensor The HC-SR04 is a ultrasonic distance sensor, it uses ultrasound to send out a ping and measure how long the sound takes to come back, exactly like bats use to fly in the dark. The sensor works between 2-400cm however if the ping sound is reflected away from the sensor by an a divergent (not parallel) surface, or absorbed by a soft surface like fabric there may no measurement. There are other types of distance sensors that are more accurate for projects where needed, this is a cheap < £5 sensor, while more accurate ones are over £100. Wiring Wiring up buttons and switches is simple: Power (VCC to 5V) Ground (GND to GND) Echo to digital pin 8 Trigger to digital pin 7 ] Additionally in this diagram there is a LED attached to digital pin 13 for the getting started example code, however this isn't required for other projects. Getting started This example turns on an LED when the distance measured is less than 50cm and back off when the distance goes over 60cm. #include #define trigPin 7 #define echoPin 8 #define maxDistance 400 NewPing sonar( trigPin, echoPin, maxDistance); void setup() { Serial.begin( 9600 ); } void loop() { Serial.println( sonar.ping_cm() ); delay( 100 ); } To use this code you will need the NewPing Library . We have a tutorial on how to install a library here. Connecting a Potentiometer A potentiometer (often abbreviated to pot) is an electronic component with three connections, the main purpose of the pot is to create a variable voltage as an input to a circuit, for example controlling how loud your speakers should be. Inside a potentiometer is a large resistive area between pin #1 and #3, the middle pin #2 is called the wiper, and by actuating the pot you can select a position along that resistive area to create a proportional to the voltage between pins #1 and #3. For example if you have Ground (0V) on pin #1, and 5V on pin #3, you could select a voltage between 0V to 5V, at the half way the voltage on pin #2 would be 2.5V. Different types There are two main types: Rotary Potenitometer Rotary Potentiometers like those found on speakers to control the volume. Slide Potentiometer Slide Potentiometer like those found on audio mixing desks. Wiring Wiring up buttons and switches is simple, both are fundamentally the same, however it can be tricky identifying pins #1, #2, and #3 (more on this later). At its most basic, pins #1 and #3 need to be connected to Power and Ground, for example 5V and GND on an Arduino. Pin #2 the wiper needs to be connected to the analog input pins: Rotary Potentiometer Wiring Slide Potentiometer Wiring Identifying the pins of a potentiometer The most common type of potentiometer to use is a 10KΩ potentiometer, that means the resistance between pin #1 and #3 is fixed at 10KΩ or thereabouts, and that the resistance between pin #2 and either of the other two will be proportional to the position of the potentiometer rotation/sliding. In other words, using a multimeter set to resistance/ohms/Ω measurement you can find the two pins that don't change at all, and measure a resistance close to the rating marked on it. The remaining leg is likely the wiper. Getting started The following is a simple sketch that will get a potentiometer controlling the LED built into the Arduino. This sketch will make the LED blink at a rate between 0ms to 1023ms, this is because the function analogRead returns a value between 0-1023. #define ledPin 13 #define potPin A0 void setup() { pinMode( ledPin, OUTPUT ); pinMode( potPin, INPUT ); } void loop() { digitalWrite( ledPin, HIGH ); delay( analogRead( potPin ) ); digitalWrite( ledPin, LOW ); delay( analogRead( potPin ) ); } How to connect a Light Dependent Resistor (LDR) An LDR or Light Dependent Resistor is a component which restricts how much power can flow through a circuit based on how much or little light hits the sensitive part on the top. Wiring To use a Light Dependent Resistor, we have to use it in combination with a fixed value resistor, the combination of these two components acts a little like a kitchen mixer tap, we can vary the temperature (voltage) by adjusting the tap. The zig-zag lines indicate resistors, the voltage output we measure with the Arduino comes from this middle point between the two, as the value of the LDR varies it changes the voltage between Ground (0V) and 5V (VCC). Getting started The following code uses analogRead() to get a integer between 0-1023 representing the voltage, where 0 is 0V and 1023 is 5V. The code below uses the serial port to output the value every 50ms to the Serial Monitor . #define ldrPin A0 void setup() { Serial.begin( 9600 ); pinMode( ldrPin, INPUT ); } void loop() { Serial.println( analogRead( ldrPin ) ); delay( 50 ); } How to use a rotary encoder A rotary encoder is a device used to measure the rotation of something, similar to a rotary potentiometer but not limited to how many rotations can be made, a common example of a rotary encoder is the volume dial on a car radio, which can be turned infinitely but still only goes from 0 to 100% volume. Rotary encoders come in a number of different types, typically either with or without 'detents' that is physical feedback as the encoder rotates, and in varying levels of resolution for more or less precise applications. Wiring Wiring is simple... There are four wires: Ground 5V A switch B switch Getting started Rotary encoders work using two switches which are operated slightly out of phase, meaning that in one direction switch A then B pulse from LOW to HIGH, and in the other direction switch B then A pulse LOW then HIGH, enabling you to detect both that a pulse happened i.e. that it was rotated, but also in which direction. Basic Example In this basic example the encoder outputs the value as a positive or negative number from it's starting position. #define enc1A_pin 2 #define enc1B_pin 3 boolean enc1A_prev; boolean enc1B_prev; long enc1 = 0; long prev_enc1 = 0; void setup() { pinMode( enc1A_pin, INPUT_PULLUP ); pinMode( enc1B_pin, INPUT_PULLUP ); Serial.begin( 9600 ); } void loop() { boolean enc1A = !digitalRead( enc1A_pin ); boolean enc1B = !digitalRead( enc1B_pin ); if ( enc1A_prev == 0 && enc1A == 1 && enc1B_prev == 1 && enc1B == 1 ) enc1++; else if ( enc1A_prev == 1 && enc1A == 1 && enc1B_prev == 0 && enc1B == 1 ) enc1--; if ( prev_enc1 != enc1 ) { Serial.println( enc1 ); } if ( enc1A_prev != enc1A ) enc1A_prev = enc1A; if ( enc1B_prev != enc1B ) enc1B_prev = enc1B; prev_enc1 = enc1; } Using the serial monitor and serial logger Serial communication is a type of communication between two devices, normally between a computer and a microcontroller (such as an Arduino), between computers, or between Arduinos. Serial communication can be over physical cables between two Arduinos, or via an XBee wireless shield, USB or Bluetooth serial emulators. However at it's most basic serial communication is a sequence of binary digits (0s and 1s) that convey information. Serial monitor The serial monitor on the Arduino is able to display messages the Arduino board sends via USB serial (note that Arduino Leonardo and some other boards based around the 32u4 chip have a seperate USB serial and hardware serial, and you cannot directly monitor the hardware serial [Serial1] output using this method). You can also send basic messages from the serial monitor screen back to the Arduino board. Above is a screenshot of the serial monitor, the first text field is where you can type text and press the send button to transmit to the Arduino. The main window below is where ASCII text will be displayed which the Arduino is transmitting. In the middle at the bottom you can specify what character should be sent after each message you send, it's common to send a newline character to indicate each distinct message. There is also an option "9600 baud" this is the communication speed. One of the fundamental parts of serial communication is establishing a common communication speed in bits (binary digits) per second, 9600 baud, is 9,600 bits per second. This drop down allows you to modify this setting, the default is 9600. Serial plotter The serial plotter is a way to visually graph the data being received, a common way to transmit multiple values is in a format called CSV (comma-seperated values) this is because when transmitting numbers you need to be able to distinguish between each number, if I transmitted the number 100 and the number 50 without a seperator they would look like this: 10050 and it would be impossible to decypher where one numbers starts and the next begins, instead we use a comma to seperate each value, thus the number becomes 100,50 and now we can easily see each value. Also because we print a newline character (using println ) after each loop we can see when each frame of data ends, thus allowing us to presume the numbers between the newline and the comma must be the first number. Some Arduino boards transmit data much faster than others, in the case of the Arduino Leonardo it is perfectly possible to overload the computer with too much information and crash the Arduino application, so by adding a 1/20th second (50ms) delay we can slow the rate to a more than acceptable level. This code example outputs the value of all 6 analog input pins on the Arduino: void setup() { Serial.begin(9600); } void loop() { Serial.print(analogRead(A0)); Serial.print(","); Serial.print(analogRead(A1)); Serial.print(","); Serial.print(analogRead(A2)); Serial.print(","); Serial.print(analogRead(A3)); Serial.print(","); Serial.print(analogRead(A4)); Serial.print(","); Serial.print(analogRead(A5)); Serial.println(); delay(50); } The serial plotter has in built support detecting CSV data and displaying it as a graph over time. The biggest drawback is that it scales the graph to the current minimum and maximum, which can cause the graph to jump scale. A simple fix to this problem is to include two fake piece of data which are the minimum and maximum of your data range, by modifying the Serial.println() to: Serial.println(",0,1023"); In this case the minimum is 0, and because analogRead's on most Arduinos are only 10-bit this means the maximum number would be 1023. void setup() { Serial.begin(9600); } void loop() { Serial.print(analogRead(A0)); Serial.print(","); Serial.print(analogRead(A1)); Serial.print(","); Serial.print(analogRead(A2)); Serial.print(","); Serial.print(analogRead(A3)); Serial.print(","); Serial.print(analogRead(A4)); Serial.print(","); Serial.print(analogRead(A5)); Serial.println(",0,1023"); delay(50); } Using Arduino Leonardo to send USB MIDI data One of the secrets of Arduino Leonardo is the in-built USB MIDI support. This is really useful for sending data from Arduino to applications like MadMapper, Max and Ableton Live. In order use this you'll need to follow the guide on How to install libraries to install the MIDIUSB library. The following is a modification of the basic MIDIUSB write example, by wrapping the noteOn and noteOff code in logic you could attach this to a button or sensor. #include "MIDIUSB.h" void setup() { Serial.begin(115200); } void loop() { Serial.println("Sending note on"); noteOn(0, 48, 64); // Channel 0, middle C, normal velocity MidiUSB.flush(); delay(500); Serial.println("Sending note off"); noteOff(0, 48, 64); // Channel 0, middle C, normal velocity MidiUSB.flush(); delay(1500); // controlChange(0, 10, 65); // Set the value of controller 10 on channel 0 to 65 } void noteOn(byte channel, byte pitch, byte velocity) { midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity}; MidiUSB.sendMIDI(noteOn); } void noteOff(byte channel, byte pitch, byte velocity) { midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity}; MidiUSB.sendMIDI(noteOff); } void controlChange(byte channel, byte control, byte value) { midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value}; MidiUSB.sendMIDI(event); } DFPlayer Mini The DFPlayer Mini is a small (cheap!) and flexible mp3 player unit that can be controlled via an Arduino. Unless you have a specific need for a 'trigger' function (where individual tracks are tripped using specific linked buttons) it's a nifty alternative to the larger and more expensive Sparkfun mp3 trigger . Full details here: https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299 Preparing files Like the Sparkfun Mp3 trigger, some preparatory steps are required to have files play reliably from the SD card. The files you use should be in mp3 format, and their names should be numbered from 1 (e.g. 1.mp3, 2.mp3, 3.mp3... and so on). Macs do a weird thing where every time you use a SD card or memory stick, it creates a bunch of hidden files, which can cause some strange errors. These hidden files and folders can't be easily removed in Finder, and instead need to be removed by opening up the volume using the terminal. You will need to repeat this step EVERY TIME you plug the SD card in (though you might only have to remove 1 or 2 files). Once you have finished copying your .mp3 files to the SD card, open up a mac terminal and type in the following (change '' with the name of your SD card): dot_clean /Volumes/ If that doesn't work, IE your MP3s don't play, we will have to do it manually like so: $ cd /Volumes/ # this navigates to the correct volume $ ls -a # verify what's in the output of this $ rm ._*.mp3 # this removes all of the thumbnails $ rm -r .Spotlight-V100 # deletes the .Spotlight-V100 folder $ rm -r .fseventsd # deletes the .fseventsd folder $ rm -r .Trashes # deletes the .Trashes folder $ ls -a # this shows all the files you have left Warning Be very careful when you are running the rm -r command: this will recursively delete files and is NOT reversible. Only run it when you know you are in the correct folder, and make sure you know which folder you are deleting) Operation not Permitted error Sometimes on a mac you might get an error "operation not permitted". If you have this, follow these instructions to allow your Terminal to change files e.g. see below: I use ls -a multiple times to check what I still need to delete. At the end, all that's left is the .mp3s and the . and .. shortcuts (these aren't file and can be ignored). Wiring the DFPlayer These diagrams are taken from the thorough tutorial on DFPlayer wiring found here . In both instances, the two resistors on the RX pin protect the input. Arduino Leonardo If you are using an Arduino Leonardo, these come with a secondary serial port readily enabled, and you don't need to add any code. Connections: RX and TX on the DFPlayer connected to 0 and 1 of the Arduino, connect DFPlayer RX through a 1k resistor). RX stands for 'receiver' and TX stands for 'transmitter' -- so you need to connect the pin marked RX on the DFPlayer to the pin marked TX on the Arduino, and vice versa. Mono audio (speaker with Leonardo) Ensure you have the board the right way around. Wire either side of the speaker into SPK1 and SPK2. Wiring for stereo (Leonardo) The DFPlayer also supports stereo audio; in order to use this feature, you need to use the DAC L and R channels instead of SPK1 and SPK2, as below: Arduino Uno If you are using an Arduino Uno, you need to enable software serial, to configure pins 2 and 3 to be serial pins. You will also need to uncomment the lines of code labelled 'Uno' below. Connections: RX and TX on the DFPlayer connected to 2 and 3 of the Arduino, connect DFPlayer RX through a 1k resistor). As before, RX stands for 'receiver' and TX stands for 'transmitter' -- so you need to connect the pin marked RX on the DFPlayer to the pin marked TX on the Arduino, and vice versa. Mono audio (speaker with UNO) Ensure you have the board the right way around. Wire either side of the speaker into SPK1 and SPK2. Wiring for stereo (UNO) The DFPlayer also supports stereo audio; in order to use this feature, you need to use the DAC L and R channels instead of SPK1 and SPK2, as below: DFPlayer Code There's a number of different Arduino libraries for communicating with the DFPlayer on line, though the simplest is probably the one made by the manufacturers, DFRobotDFPlayerMini . Install it using the Arduino library manager, instructions here. This sample code is adapted from the library's 'Getting Started' example, and will play tracks while also showing any error messages over the serial monitor. #include "DFRobotDFPlayerMini.h" //Uncomment next 2 lines if you're using an Uno -> //#include "SoftwareSerial.h" //SoftwareSerial Serial1(10, 11); //RX, TX DFRobotDFPlayerMini myDFPlayer; void setup() { Serial.begin(115200); Serial1.begin(9600); Serial.println(); Serial.println(F("DFRobot DFPlayer Mini")); Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); //Use softwareSerial to communicate with board if (!myDFPlayer.begin(Serial1)) { Serial.println(F("Unable to begin:")); Serial.println(F("1.Please recheck the connection!")); Serial.println(F("2.Please insert the SD card!")); while(true); } Serial.println(F("DFPlayer Mini online.")); myDFPlayer.volume(0); delay(100); myDFPlayer.volume(15); //Set volume value. From 0 to 30 myDFPlayer.play(1); //Play the first mp3. to loop, exchange 'play' for 'loop' } void loop() { if (myDFPlayer.available()) { printDetail(myDFPlayer.readType(), myDFPlayer.read()); } } void printDetail(uint8_t type, int value){ switch (type) { case TimeOut: Serial.println(F("Time Out!")); break; case WrongStack: Serial.println(F("Stack Wrong!")); break; case DFPlayerCardInserted: Serial.println(F("Card Inserted!")); break; case DFPlayerCardRemoved: Serial.println(F("Card Removed!")); break; case DFPlayerCardOnline: Serial.println(F("Card Online!")); break; case DFPlayerPlayFinished: Serial.print(F("Number:")); Serial.print(value); Serial.println(F(" Play Finished!")); break; case DFPlayerError: Serial.print(F("DFPlayerError:")); switch (value) { case Busy: Serial.println(F("Card not found")); break; case Sleeping: Serial.println(F("Sleeping")); break; case SerialWrongStack: Serial.println(F("Get Wrong Stack")); break; case CheckSumNotMatch: Serial.println(F("Check Sum Not Match")); break; case FileIndexOut: Serial.println(F("File Index Out of Bound")); break; case FileMismatch: Serial.println(F("Cannot Find File")); break; case Advertise: Serial.println(F("In Advertise")); break; default: break; } break; default: break; } } See the DFRobot documention for more commands: https://wiki.dfrobot.com/DFPlayer_Mini_SKU_DFR0299 How to revive a broken Arduino using a Mac These are instructions for doing this on a mac -- there are a few extra steps which might be a lot less hassle to do on windows but I haven't tried. If you're a student reading this, chances are you don't have an Atmel-ICE programmer to hand: if you're having Arduino trouble chat to one of us first to make sure this is the right solution to your issue. Get the right configuration of avrdude Mac permissions mean that using the AVR ISP you get some weird hassle and it won't work properly in the IDE. You can get around this by rebuilding avrdude to make sure it includes a library called HIDAPI. I followed the steps in this comment , which explains everything really well. I reproduced the steps here for clarity as a few things had changed / there were a couple of external instructions to follow. round 1: HIDAPI setup brew install autoconf automake git clone git://github.com/libusb/hidapi.git cd hidapi then ./bootstrap (this should run fine) run to get the configuration for your OS ./configure compile: make install: sudo make install round 2: avrdude rebuild (leave the hidapi folder to do this) download latest version of avrdude: git clone git@github.com:avrdudes/avrdude.git edit avrdude/src/configure.ac (NB: I'm not actually sure if you have to do this anymore you could try it without. But I did do this and it didn't cause any issues, so). You want to change this: AH_TEMPLATE([HAVE_LIBHIDAPI], [Define if HID support is enabled via libhidapi]) AC_SEARCH_LIBS([hid_init], [hidapi hidapi-libusb hidapi-hidraw], [have_libhidapi=yes]) to this: AH_TEMPLATE([HAVE_LIBHIDAPI], [Define if HID support is enabled via libhidapi]) for _hidapi_lib in hidapi hidapi-hidraw hidapi-libusb; do PKG_CHECK_MODULES([hidapi],[$_hidapi_lib],[have_libhidapi=yes],[true]) done AC_SEARCH_LIBS([hid_init], [hidapi hidapi-libusb hidapi-hidraw], [have_libhidapi=yes]) run ./build.sh , and check that when it prints the Configuration Summary it managed to successfully find libhidapi (should look like this): -- Configuration summary: -- ---------------------- -- DON'T HAVE libelf -- DO HAVE libusb -- DO HAVE libusb_1_0 -- DO HAVE libhidapi ... -- ---------------------- final bit: run sudo cmake --build build_darwin --target install to install. Check the install locations it prints -- you care about where the main and the conf files are for later in the process: -- Install configuration: "RelWithDebInfo" -- Installing: /usr/local/bin/avrdude <- important -- Installing: /usr/local/lib/libavrdude.a -- Installing: /usr/local/include/libavrdude.h -- Installing: /usr/local/etc/avrdude.conf <- important -- Installing: /usr/local/share/man/man1/avrdude.1 Once you're at this step you're in a good place to use avrdude directly from the command line. Using avrdude to burn new bootloader to the arduino afaik you don't actually need to do things to the fuses like the Arduino bootloader instructions suggest (and I have a horrible feeling that the 2 that ended up not working were the ones where I messed with the fuse settings). Instead, I just used the ATMEL-ICE tool to burn the hex file directly to the Arduino. This is something of a shame as I did find this amazing AVR fuse calculator website and I wanted an excuse to show it to someone. Hardware setup The Arduino needs to be externally powered (I used a USB wall supply to avoid confusing my computer) and the ISP header inserted the correct way round into the Arduino. The below image is for an Uno but it's still correct -- the little bump on the SCK pin faces toward the centre of the board. Lastly, connect the ATMEL-ICE to the computer (I used USB-C to micro-USB) Finding and burning the bootloader The Arduino IDE has a bunch of bootloaders saved locally, in the folder /Applications/Arduino.app/Contents/Java/hardware/arduino/avr/bootloaders/ . You can also browse them online in the Arduino Core AVR repository . For Leonardo, we want to use the Caterina-Leonardo bootloader. The command that I ran was: /usr/local/bin/avrdude -C /usr/local/etc/avrdude.conf -v -p atmega32u4 -c atmelice_isp -P usb -U flash:w:/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/bootloaders/caterina/Caterina-Leonardo.hex:i NB -- I'm pointing to the avrdude and conf files that are the specific ones that were installed in the previous step. By default your system installation of avrdude is probably not this one (but you can type which avrdude to check/reset). Note also that this configuration is for the Arduino Leonardo, using the Atmel ICE ISP. For an Uno, for example, you'd want -p atmega328p and to find what the current Uno bootloader is. If you get the error: avrdude stk500v2_command() error: command failed avrdude main() error: initialization failed, rc=-1 it's worth trying appending -B 200kHz -F to the avrdude like they suggest to remedy it, but if then you get the error: avrdude: device signature = 0x000000 avrdude main() error: Yikes! Invalid device signature. I think ur arduino is borked beyond repair. RIP dude. Stepper motor with TB6000 Microstep driver We have the 42BYGHM809 Stepper motors with the TB6600 Stepper motor microstep driver to the Arduino using the BasicStepperDriver.h library. Connect the stepper and driver as shown: Download and install the driver to arduino from here . (If you need help, check the manual library installation wiki page here ). Try this stepper Motor 42BYGHM809 / TB6600 Test Program note the steps are 12800 for a 360 turn (guestimated!). /* Simple demo, should work with any driver board Connect STEP, DIR as indicated Copyright (C)2015-2017 Laurentiu Badea This file may be redistributed under the terms of the MIT license. A copy of this license has been included with this distribution in the file LICENSE. Modified for CCI by Matt Jarvis */ #include #include "BasicStepperDriver.h" // Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step #define MOTOR_STEPS 12800 #define RPM 120 // Since microstepping is set externally, make sure this matches the selected mode // If it doesn't, the motor will move at a different RPM than chosen // 1=full step, 2=half step etc. #define MICROSTEPS 1 // All the wires needed for full functionality #define DIR 6 #define STEP 7 //Comment or uncomment line to use enable/disable ENABLE functionality #define ENABLE 5 // 2-wire basic config, microstepping is hardwired on the driver (use this if not needing to use the enable pin) //BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP); //Uncomment line to use enable/disable functionality BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, ENABLE); void setup() { stepper.begin(RPM, MICROSTEPS); // if using enable/disable on ENABLE pin (active LOW) instead of SLEEP uncomment next line stepper.setEnableActiveState(HIGH); } void loop() { // energize the coils stepper.enable(); /* Moving motor one full revolution using the degree notation and wait for 2 seconds */ stepper.rotate(360); delay(2000); /* Moving motor to original position using steps */ stepper.move(-MOTOR_STEPS * MICROSTEPS); // release the coils, (disable motor and allow the motor to be moved by hand) stepper.disable(); // delay 5 seconds delay(5000); } 5V Air Pump Guide We have a number of small 5V air pumps and silicone tubing available for students to borrow for small-scale inflatable projects, which include the single and inflate-deflate air pump control. These can't fill a lot of space, so for inflatables larger than about a balloon's worth of volume, you might want to get something more powerful. They are ideal for silicon soft robotics projects! These pumps cannot be used to pump water: for liquid pumps please come and chat to us, as we have a small number of peristaltic pumps available to borrow. The other main constraint of these pumps is that they are unidirectional -- to both inflate and deflate something you will need two! Parts List All of these parts may be borrowed from the technical office. Arduino Leonardo (Uno is also fine) 5V air pump (you need to solder connecting wires to the pins on the bottom if not already done) Three ports Air Valve (for inflate and deflate system) IRF520 MOS Module(for one pump) or LM298N Module(for two pump / inflate-deflate) 5v Power supply (because these are 5V pumps -- don't use a higher one!) DC terminal barrel jack (socket type) Connecting wires, silicon tubing, etc etc Screwdrivers for attaching the wires to the screw terminal blocks on the module and DC barrel jack ] Basic Setup The setup for an air pump is basically equivalent to that of a DC motor, and like a DC motor requires the use of an external power supply, to manage the flow of current to the pump. Soldering: Pins are on the base of the pumps. Wrap the wire through the small hole, add a blob of solder and trim any excess wire to prevent shorts. Give the wires a gentle tug to make sure they're properly secured. Attaching screw terminal: Make sure when you're attaching things to screw terminals that the wires are attached tightly and do not show exposed metal. This is not a part of your circuit where you want a short! Once they are screwed in, give the wires a gentle tug to make sure they're properly secured. One Air Pump system The easiest way to do this is to use one of the IRF520 MOS modules we have in stock, which can be controlled using an Arduino. These can be used to control DC motors or things like air pumps, using a PWM signal. You want to wire up the components according to the diagram below: Out+ and Out- connect to your pump Vin and Gnd (on the screw terminal blocks) connect to the + and - of the barrel jack of your power supply. Very important -- Vin connects to + and Gnd connects to - SIG , VCC and GND (e.g. the non-screw terminal connector) connect to a PWM pin (e.g. pin 3), 5V and GND , on your Arduino. Connection diagram Sample Arduino code Once your circuit is wired up, you want to plug in your 5V power supply (and plug it into the jack), and plug your Arduino in to your computer. This code assumes you have connected SIG on the board to Pin 3 of the Arduino. #define PWM 3 void setup() { Serial.begin(9600); pinMode(PWM,OUTPUT); } void loop() { # turn on analogWrite(PWM,255); delay(3000); # turn off analogWrite(PWM,0); delay(3000); } Inflate-deflate system The pumps we have are not bidirectional -- this means that if you want something that inflates and deflates, you need to use 2 pumps linked by a splitter. The circuit to drive each pump will be the same, but you can connect both SIG pins to different PWM pins on the same Arduino. We have valves and splitters available in the tech office. If you have the 2-motor driver... If you are trying to drive 2 pumps, we might have given you the LM298N board , which can drive 2 motors at once. These are a little more tricky to understand, as they also allow you to change the direction of the motors. Before you choosing the extra power supply for the LM298N board, check the Rated /Operating voltage of the motors you wanna control. The LM298N board will make a slight voltage drop (around 1v) , which means the voltage of power adaptor could be slightly bigger. Connection diagram For each motor, 2 pins control the motion: IN1 and IN2 control the first motor, and IN3 and IN4 control the second. For the motor to be running, one of these should be high and the other low. Depending on which is which, the motor will run either forward or backward: air pump motors can only run forward, so we want to set IN1 and IN3 as HIGH, and IN2 and IN4 as LOW. Sample Arduino code Once your circuit is wired up, you want to plug in your power supply (and plug it into the jack), and plug your Arduino into your computer. This code assumes you have connected Pin 2 to connect the air valve, Pin 3 and Pin 4 to control the inflating, and Pin 5 and Pin 6 to control the deflating(as you need to connect it as shown in the connection diagram). const int valve = 2; const int inflate1 = 3; const int inflate2 = 4; const int deflate1 = 5; const int deflate2 = 6; void setup() { Serial.begin(9600); //pin settings //valve pinMode(valve,OUTPUT); digitalWrite(valve,LOW); pinMode(inflate1, OUTPUT); digitalWrite(inflate1, LOW); pinMode(inflate2, OUTPUT); digitalWrite(inflate2, LOW); pinMode(deflate1, OUTPUT); digitalWrite(deflate1, LOW); pinMode(deflate2, OUTPUT); digitalWrite(deflate2, LOW); } void loop() { //PUMP inflating digitalWrite(valve,HIGH); digitalWrite(inflate1,HIGH); digitalWrite(inflate2,LOW); digitalWrite(deflate1,LOW); digitalWrite(deflate2,LOW); delay(2000); //for two seconds //PUMP deflating digitalWrite(valve,LOW); digitalWrite(inflate1,LOW); digitalWrite(inflate2,LOW); digitalWrite(deflate1,HIGH); digitalWrite(deflate2,LOW); delay(2000); // for two seconds } Mini 360 Degree Continuous Servo Code Continuous servos have a different structure to them than regular servos. A regular servo simply goes to t degree angle to tell it, where as continuous servos of course keep going around, so we must program them slightly differently, like so: // Include the servo library #include // Create the servo object Servo myservo; // Setup void setup() { myservo.attach(9); // attach the servo to our servo object myservo.write(90); // stop the motor } // Main loop void loop() { myservo.write(45); // rotate the motor counter-clockwise delay(5000); // keeps rotating for 5000 milliseconds (5 seconds) myservo.write(90); // stop the motor delay(5000); // stay stopped myservo.write(135); // rotate the motor clockwise delay(5000); // keeps rotating } How to build your own flex sensor You will need: Velostat Copper tape Foam Soldering kit Silicon wire (thin threaded wire is also fine) Tape of some sort Arduino wiring: Arduino code: /* Simple code to light up an LED based on resistance sensor Matt Jarvis - Creative Computing Institute */ int ledPin = 3; // pin 3 has PWM int flexPin = A0; // pin A0 is analog input int value; // save analog value void setup(){ pinMode(ledPin, OUTPUT); //Set pin 3 as 'output' Serial.begin(9600); //Begin serial communication } void loop(){ value = analogRead(flexPin); // Read and save analog value from resistor device Serial.println(value); // Print value to serial value = map(value, 700, 900, 0, 255); // Map value from analogue (0-1023) to digital (0-255) (PWM) analogWrite(ledPin, value); // Send PWM value to led delay(100); // Small delay } Beyond Arduino: Choosing Boards for your Project For projects requiring greater complexity, or more specific features than is possible with an Arduino (particularly: anything requiring image processing, handling multiple peripherals, multithreading) you might want to explore some of the other boards (both microcontroller- and single-board-computers) that we have at the CCI. Here, I'm going to make a distinction between microcontroller boards like Arduino (which run the same program again and again until you change it), and single board computers (see below) which run an operating system, and are used like a computer. In general, microcontrollers can be more straightforward to use and configure, but there's plenty of applications where using a SBC like a Raspberry Pi (e.g. doing multiple tasks simultaneously) is a better idea and can save you a lot of hassle. Below is a short guide to choosing boards in different scenarios + more details about resources for getting started with different boards. This guide assumes you are already familiar with Arduino, but are encountering its limitations (or curious about other approaches). I just need more pins -- Arduino Mega I need something cheap so I can buy 20 -- It used to be cheaper to buy boards -- right now probably the best option is probably not to use Atmega. You can also buy supercheap Arduino clones on ebay but do be wary that you might end up with some dud boards. I need something smaller/wearable -- Arduino Nano BLE is a good bet, or the ESP32 if you prefer to use Wifi and need to communicate externally (this can be nice as you can do processing on a server). I need multiple boards to do wireless communication -- don't do peer-to-peer communication with Bluetooth it will make you very sad! Try using packet radio instead I need to do longer range networking than Bluetooth -- you could consider one of the Adafruit Feather packet radios (for range up to a couple of hundred metres), or their LoRa boards , which can reach a couple of km, provided there is line of sight! I need to do multithreading/fast operations -- consider programming in C on the RP2040 chip -- it has 2 cores, as well as a number of interrupt registers. I need to connect to an external server -- use a WiFi board, like an ESP32 or ESP8266 (the ESP32 is just the more recent version -- it's slightly faster and has more GPIO, but both broadly work the same). I want to program using CircuitPython -- (this is a cool thing to want to do for lots of reasons) -- the RP2040 and many of the Adafruit Feather Boards. For a full list of boards that currently support CircuitPython, see Adafruit's Download Guide . I need to do image processing / run a printer / use a camera -- This is where you start wanting to get into using a Raspberry Pi. If size is an issue / you want to do something quite classic, you might want to consider a purpose-built computer vision board like the OpenMV (be warned though -- they can be quite inflexible and it's difficult to generate your own models for these). I need to do machine learning -- The larger Raspberry Pi boards are on the edge of doing stuff, you can also use a purpose built board like the Nvidia series (but depending on what you're doing, it might well be more cost effective just to use a Pi and communicate with an external server). Microcontrollers Adafruit's How To Choose A Microcontroller is also a good guide to look at, but 90% of the boards it recommends are the Adafruit Feather series. One thing to be wary of -- lots of these microcontrollers don't run at 5V, but 3.3V! Be careful that you don't fry them by just sticking them into the same circuit you were using with a Leonardo. Arduino Mega The Arduino Mega is based on the ATmega2560 chip, which is a larger version of the ATmega328p chip used for the standard Arduino boards. It has 54 digital input/output pins (of which 15 can be used as PWM outputs), 16 analog inputs and 4 hardware Serial ports. It's big!!! (we have 2) Arduino Nano BLE We have loads of these little bluetooth boards, which are particularly well-suited Interestingly, unlike most other Arduino boards, these are not made using the ATMEGA chips but instead Nordic's nrf52 series, which are speedy little Bluetooth chips! They can still be programmed using the Ardiuno IDE, but note that not all the libraries will work in the same way. RP2040 / Raspberry Pi Pico If you simply need more speed / simple multithreading, you could also consider switching from Arduino to a Raspberry Pi Pico -- these are not the same as other Raspberry Pis: they don't run an operating system, and are instead an interface to a microcontroller called the RP2040. The other nice thing about RP2040 boards is that some people make them really pretty small -- Solder Party's RP2040 stamp comes in at 1x1 inch (careful, though, as the headers are 2mm rather than the more common 2.54mm pitch, so the rest of your circuit will need to reflect that). You can also sacrifice some pins for easier interfacing with the Seeed XIAO RP2040 , which is a similar size but 2.54mm pitch. Adafruit Feather Series The Feathers are not a single board, or even family of boards based on the same chip, but instead a flexible collection of different chips mixed with different communication protocols, all with the same dimensions and layout, battery charging, Arduino IDE compatibility etc etc. It's worth looking through their whole range (if you are into such things), but my particular favourites are: M0 RFM69HCW Packet Radio -- really effective little radio boards, with a range of up to 350m. Great for peer-to-peer communication projects. Single-board computers Raspberry Pi Nvidia ?? Workshop: Knitted Synthesisers These notes are based on a workshop run by Agnes Cameron, and were developed as part of B Claxton and Eva Sajovic's Hack'n the Knit workshop series. These instructions are based on a tutorial for making two-stage astable oscillators on the website Electronics Tutorials , which also gives a lot more information on the electronic theory. you will need 3.5mm jack breakout (socket) a speaker or pair of headphones a breadboard 2x 555 timers jumper wires 5V power supply 4 crocodile clip cables a 100kΩ resistor a 10kΩ resistor a 10kΩ variable resistor a 100kΩ variable resistor a 10$\mu$F capacitor a 100nF capacitor some conductive knit samples Theory making waves Electrical signals travel round circuits as 'waves' -- signals that carry information. In the simplest circuits, these waves don't change at all -- the circuit is simply on or off. In circuits used to make noises, however, waves change constantly -- it's the changes in the wave that are what creates noise. The way a speaker works is to take one of these changing waves and pass the signal into a coil of wire. If brought close to a magnet, the coil of wire vibrates, making sounds! The circuit we are making in this tutorial allows us to create and change a wave using simple electronic components. waves and sounds The kind of sound a wave makes depends on two key things: the frequency (how often the wave changes, or oscillates per second), and the amplitude (how 'big' the wave gets). The frequency of the wave determines the pitch: a high-frequency wave (lots of oscillations per second) is a high pitch, and vice versa. The amplitude determines the 'loudness' of the wave. A wave with a changing frequency will sound like a changing note. After this, there's a bunch of different things that can change the quality of the sound. Often this has a lot to do with the shape of a wave. The wave that comes out of a simple resistor-capacitor (RC) timing circuit is called a sawtooth wave -- these sound pretty unpleasant! We're going to use another component -- a 555 timer -- to make a square wave. These sound much cleaner. resistors and capacitors The most important components that determine how this circuit behaves are called resistors and capacitors. A resistor is something that resists the flow of electrical current, making it harder for current to pass through. You could think of it as a pipe which can be quite wide (low resistance) or very narrow (high resistance). A capacitor collects electrical charge, meaning that as current flows into the capacitor, the voltage at the top of the component will slowly increase. When the voltage goes above a certain value, all of the charge will drain out through the capacitor and flow into ground. The bigger the capacitor, the longer this takes -- kind of like an electronic bucket. When used together, these components can be used to make a very simple timing circuit -- current flow through the resistor can be controlled, changing the amount of time it takes for the capacitor to fill and empty. If we measure the voltage across the capacitor over time, we can see that it times in a regular interval: this becomes the basis for our sound wave! Smaller resistors = faster oscillation = higher pitch. the astable multivibrator The circuit given by the diagram below is the one we're going to make! It's called 'astable' because it's a circuit that switches between two states -- the switching is what makes our sound wave. The diagram below contains two timing circuits -- those parts are the pairs of resistors and capacitors. The signal on the capacitor goes into Pin 3 of the 555 timer -- this signal 'times' the component, which produces a much cleaner wave on the output. Further in this document are photos of what the circuit looks like assembled. This circuit has 2 stages, to allow us to make more interesting sounds! The first stage 'modulates' the second, mixing the waves together. variable resistors Lots of synthesisers use variable resistors to control the sounds that are made, by changing the speed of the timing circuit. Typically these are rotating dial components, but anything with a changing resistance can be used to change sounds. This brings us to... variable resistors and conductive yarn Typically, conductive yarn is used differently to conductive thread: it has much higher resistance, which means that it's not used to directly connect components unless they are very close together. However, because the conductive properties of fabrics knitted with conductive yarns change according to the state of the material, they make great sensors. When a knitted sample is relaxed, it has a high resistance as the fibres in the yarn do not make contact with one another, meaning that current can pass only along a few strands. When the sample is stretched, however, the fibres are pulled into closer contact, reducing the resistance and allowing the flow of an electric current. This means that the inclusion of a conductive yarn allows you to sense movement in the material, creating a stretch sensor. Practice knitting with conductive yarn To develop sensitive patches, I like to mix one strand of conductive yarn with one strand of regular cotton/lambswoll yarn. This has the effect of spacing out the conductive threads, making the patch’s resistance change more as it is stretched and relaxed. measuring the resistance of a sample Attach the crocodile clips to the edge of the sample, and connect the other ends to the multimeter. Move the wheel of the multimeter to the setting with the Ω symbol, and press the 'mode' button until you also see a Ω on the screen. Once the system is connected, you should see a reading of the sample's resistance on the multimeter. Try stretching the sample and the number should decrease! Note that the letters next to Ω refer to the magnitude: k stands for 'kilo' (x1000), and M stands for 'mega' (x 10,000). You want your sample to be at least a few kΩ for this to work. circuit diagrams On a chip like the 555 timer, pins are numbered from 1-8, and are numbered counter-clockwise, beginning with the pin to the left of the notched end. On the circuit diagram, pins don't appear in this order -- this allows the wires to be represented without needing to cross over one another, but can be confusing when translating into reality. breadboards for circuit layout Breadboards are really useful tools for electronic prototyping, used to connect components together without any soldering. The legs of components are placed in holes on the board: in the middle of the breadboard, these are connected together vertically -- at the top and bottom they’re connected horizontally in long rails. Here’s how the circuit from the diagrams above looks when wired into a breadboard: using an oscilloscope for debugging A really helpful tool when making these kinds of circuit is an oscilloscope -- this allows us to see a visual representation of what the wave looks like in the circuit at different times! In the CCI we have a RIGOL MSO5072 Oscilloscope, which is used for analysing electronic circuits. If you've not used an oscilloscope before it's worth being shown this by one of the technicians (either Tom or Agnes), but if you have used one before, the layout is not too dissimilar to other mixed-signal oscilloscopes. Using Raspberry Pi for Projects In the CCI we have a large number of pre-configured Raspberry Pi 4 boards for use by students, as well as a range of other boards (some Pi Zeros, a couple of Pi 5s). We often recommend these to students who are pursuing installation / physical computing projects that are too complex, or require too much processing power to be run on an Arduino. Getting started with Raspberry Pi can be a bit of a learning curve, but really worth doing if you're interested in making durable installation work! Raspberry Pi vs Arduino Although they are often talked about in similar contexts, Raspberry Pis are very different to Arduinos, and using them requires a different (but related) set of skills. Crucially, a Raspberry Pi is a computer, running an operating system, and capable of running lots of different programs simultaneously. An Arduino is a microcontroller, and can only run one program at a time. This difference means that Raspberry Pis are well-suited to more complex projects, including anything involving handling files (as operating systems have a filesystem), images, or peripherals like thermal printers. They also require a lot more setup and configuration, and it's a good idea to talk to the technicians about what's the right approach for your project (if you only have a small amount of time it might be worth scaling back your ideas rather than trying to get set up with a Pi in a short space of time). Getting Started By default, Raspberry Pis we will give you run a variant of the Debian operating system called Raspberry Pi OS. This is installed on an SD card -- if you want to change the system the Pi is running, you can overwrite this SD card, or swap in a new one. If you are configuring a pi from scratch, Raspberry Pi's website has a thorough setup tutorial . You will not need to go through these steps if you are using a preconfigured pi that we have given you. Capabilities Raspberry Pi's documentation includes a long guide to Raspberry Pi OS , which includes a detailed description of Just like Arduinos, Raspberry Pis have a GPIO that allows electronic components to be connected directly to a set of pins that can be read and written to programatically. Connecting to Wifi It's very difficult to connect devices like Raspberry Pi to the UAL Wifi network. To get around this, the IT department maintains a separate network for "Internet of Things" devices, including Raspberry Pis. UAL-IoT is connected to UAL-WiFi, so it's possible to SSH into a Raspberry Pi connected to UAL-IoT from a device connected to UAL-Wifi. New devices have to be registered in order to connect to the UAL-IoT network. We have done this process already for the Raspberry Pi 4s, but other devices may not be registered. A guide to this process is available here . Helpfully, the IoT network may require a different password depending on what building you are in and what device you are using. Talk to technicians to get the correct password for your pi!