Skip to content

Commit

Permalink
added arduino and sc slides
Browse files Browse the repository at this point in the history
  • Loading branch information
gufett0 committed Dec 12, 2024
1 parent d43313f commit 4eb59f4
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/marp-to-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
marp train4hackaton.md -o train4hackaton.html --verbose
marp webaudioprogramming.md -o webaudioprogramming.html --verbose
marp hack2instructions.md -o hack2instructions.html --verbose
marp embeddedprogramming.md -o embeddedprogramming.html --verbose
marp embeddedprogramming.md -o embeddedprogramming.html --verbose
marp embeddedprogramming2.md -o embeddedprogramming2.html --verbose
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

[webaudio hackathon](https://raw.githack.com/fbrusch/actam_2024/gh-pages/hack2instructions.html)

[intro to microbit](https://raw.githack.com/fbrusch/actam_2024/gh-pages/embeddedprogramming.html) ->[link alla registrazione](https://politecnicomilano.webex.com/webappng/sites/politecnicomilano/recording/bbb0bf42ff144bd6bd8956965029c1b2/playback)
[intro to microbit](https://raw.githack.com/fbrusch/actam_2024/gh-pages/embeddedprogramming.html) ->[link alla registrazione](https://politecnicomilano.webex.com/webappng/sites/politecnicomilano/recording/bbb0bf42ff144bd6bd8956965029c1b2/playback)

[intro to arduino](https://raw.githack.com/fbrusch/actam_2024/gh-pages/embeddedprogramming2.html)
174 changes: 174 additions & 0 deletions embeddedprogramming2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
---
marp: true
theme: default
paginate: true
---

# ACTAM - Embedded programming with Advanced tools
## 12/12/2024

---

## Goals: Introduce two new tools

1) Arduino
2) SuperCollider

---

## What is Arduino?
* An open-source electronics platform combining hardware and software
* Perfect for interactive music and sound projects
* Check these out https://www.arduino.cc/education/arduino-instruments/

--

### Available Boards
https://www.arduino.cc/en/hardware
* **Arduino Uno**: Basic board, good for simple audio projects
* **Arduino Due**:
- 12-bit DAC (Digital to Analog Converter)
- Higher processing power (84 MHz)
- Ideal for complex audio synthesis
* **Arduino Mega**: More I/O pins for multiple controllers/sensors

--

## How can I program it?

Get started with [this IDE](https://docs.arduino.cc/software/ide-v2/tutorials/getting-started-ide-v2/)
* Built-in examples and library manager
* Key audio libraries:
- `Tone`: Basic frequency generation (e.g. Pulse Width Modulation)
- `Mozzi`: Advanced audio synthesis (e.g. Algorithmic music)
- [Arduino Audio Tools](https://github.com/pschatzmann/arduino-audio-tools) for multiple effects and audio formats

* A good way to start: https://www.tomshardware.com/how-to/use-arduino-ide-2

--

## Basic tone generation

```cpp
const int speakerPin = 9;
void setup() {
pinMode(speakerPin, OUTPUT);
}

void loop() {
tone(speakerPin, 440, 500);
delay(1000);
}
```

## Mozzi Library Example
Advanced synthesis using the Mozzi library:

--

## Arduino as MIDI Controller
```cpp
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
// Map sensor to MIDI values (0-127)
byte midiValue = map(sensorValue, 0, 1023, 0, 127);
Serial.write(midiValue);
delay(10);
}
```
--

## Arduino with Web Audio API
```javascript
// Receiving Arduino data via Web Serial API
async function connectArduino() {
const port = await navigator.serial.requestPort();
await port.open({ baudRate: 9600 });

const reader = port.readable.getReader();
while (true) {
const { value, done } = await reader.read();
if (value) {
oscillator.frequency.value = value * 10;
}
}
}
```
--

## What's SuperCollider? Isn't SonicPi enough?

* lower level language (SCLang)
* real-time audio server (spectral analysis, manipulation, and resynthesis with FFT)
* can define your own synthesis algorithms

--

### Basic SuperCollider Syntax

```supercollider
(
SynthDef(\simpleSine, {
arg freq = 440;
var sig = SinOsc.ar(freq, 0, 0.5);
Out.ar(0, sig); // precise channel mapping
}).add;
)
// Play the synth
x = Synth(\simpleSine);
x.set(\freq, 880);
x.free; // Stop
```

--

### SuperCollider getting Arduino Data

```supercollider
SerialPort.listDevices; // List available ports
p = SerialPort.new("/dev/ttyACM0", 9600);
// Read incoming data
r = Routine({
var byte;
loop {
byte = p.read;
// Map byte to frequency (example)
{SinOsc.ar(byte * 10)}.play;
0.01.wait;
}
}).play;
```

### Arduino Code for SuperCollider
Same as for web audio api

```cpp
const int sensorPin = A0;

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(sensorPin);
Serial.write(map(sensorValue, 0, 1023, 0, 255));
delay(10);
}
```

--

## Project Ideas & Applications
You can create:
* Interactive sound installations
* MIDI controllers
* Gesture-controlled synthesizers
* Real-time audio effects processors
* Sensor-based music generators
* Interactive performance tools

0 comments on commit 4eb59f4

Please sign in to comment.