Skip to content

Commit e4afe8f

Browse files
committed
monosynth1: add serial midi in, add start of display
1 parent 3a7da3b commit e4afe8f

File tree

2 files changed

+99
-32
lines changed

2 files changed

+99
-32
lines changed

arduino/hwtest/hwtest1/hwtest1.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
#define uart_tx_pin 16
2222

2323
const int touch_pins[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
24-
#define touch_count = sizeof(touch_pins) / sizeof(int);
25-
#define touch_threshold_adjust = 100;
24+
const int touch_count = sizeof(touch_pins) / sizeof(int);
25+
const int touch_threshold_adjust = 100;
2626
// display parameters
2727
#define oled_i2c_addr = 0x3C;
2828
#define dw = 128;

arduino/monosynth1/monosynth1.ino

Lines changed: 97 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@
1414
#include <Adafruit_TinyUSB.h>
1515
#include <MIDI.h>
1616
#include <TouchyTouch.h>
17+
#include <Wire.h>
18+
#include <Bounce2.h>
19+
#include <Adafruit_GFX.h>
20+
#include <Adafruit_SSD1306.h>
21+
#include "fonts/Dialog_plain_10.h"
22+
#include "fonts/Dialog_bold_12.h"
23+
#include "fonts/Dialog_plain_8.h"
24+
#define myfont Dialog_plain_10
25+
#define myfontB Dialog_bold_12
26+
#define myfontSM Dialog_plain_8
27+
28+
#include "SynthUI.h"
1729

1830
#include "MozziConfigValues.h" // for named option values
1931
#define MOZZI_AUDIO_MODE MOZZI_OUTPUT_I2S_DAC
@@ -24,7 +36,7 @@
2436
#define MOZZI_I2S_PIN_WS (MOZZI_I2S_PIN_BCK+1) // HAS TO BE NEXT TO pBCLK, i.e. default is 21
2537
#define MOZZI_I2S_PIN_DATA 22
2638
#define MOZZI_ANALOG_READ MOZZI_ANALOG_READ_NONE // we're using regular analogRead()
27-
//#define OSCIL_DITHER_PHASE 1
39+
// #define OSCIL_DITHER_PHASE 1
2840
// Mozzi's controller update rate, seems to have issues at 1024
2941
// If slower than 512 can't get all MIDI from Live
3042
#define MOZZI_CONTROL_RATE 512 // mozzi rate for updateControl()
@@ -43,29 +55,42 @@
4355
#include <mozzi_rand.h> // for rand()
4456

4557

46-
#define sw_pin 28
47-
#define knobB_pin 27
48-
#define knobA_pin 26
49-
#define led_pin 25 // regular LED, not neopixel
50-
#define pico_pwr_pin 23 // HIGH = improved ripple (lower noise) but less efficient
51-
#define i2s_data_pin 22 //
52-
#define i2s_lclk_pin 21
53-
#define i2s_bclk_pin 20
54-
#define i2c_scl_pin 19 // on I2C1 aka Wire1
55-
#define i2c_sda_pin 18
56-
#define uart_rx_pin 17 // on UART0 aka Serial1
57-
#define uart_tx_pin 16
58+
const int sw_pin = 28;
59+
const int knobB_pin = 27;
60+
const int knobA_pin = 26;
61+
const int led_pin = 25; // regular LED, not neopixel
62+
const int pico_pwr_pin = 23; // HIGH = improved ripple (lower noise) but less efficient
63+
const int i2s_data_pin = 22; //
64+
const int i2s_lclk_pin = 21;
65+
const int i2s_bclk_pin = 20;
66+
const int i2c_scl_pin = 19; // on I2C1 aka Wire1
67+
const int i2c_sda_pin = 18;
68+
const int uart_rx_pin = 17; // on UART0 aka Serial1
69+
const int uart_tx_pin = 16;
70+
71+
// DISPLAY PARAMTERS
72+
const int oled_i2c_addr = 0x3C;
73+
const int dw = 128;
74+
const int dh = 64;
5875

5976
Adafruit_USBD_MIDI usb_midi; // USB MIDI object
6077
MIDI_CREATE_INSTANCE(Adafruit_USBD_MIDI, usb_midi, MIDIusb); // USB MIDI
61-
// MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDIuart); // Serial MIDI
78+
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDIuart); // Serial MIDI
6279

6380
const int touch_pins[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
6481
const int touch_count = sizeof(touch_pins) / sizeof(int);
6582
const int touch_threshold_adjust = 100;
6683

6784
TouchyTouch touches[touch_count];
68-
bool touched[touch_count];
85+
Bounce2::Button button;
86+
Adafruit_SSD1306 display(dw, dh, &Wire1, -1);
87+
SynthUI synthui(&display);
88+
89+
// GUI LAYOUT PARAMETERS
90+
int num_disp_params = 3;
91+
int hilite_param = 0;
92+
int line_spacing = 12; // depends on font
93+
int param_offset = 0;
6994

7095
// SETTINGS
7196
//int portamento_time = 50; // milliseconds
@@ -103,14 +128,6 @@ typedef struct {
103128
float release_time;
104129
} Patch;
105130

106-
107-
//struct MySettings : public MIDI_NAMESPACE::DefaultSettings {
108-
// static const bool Use1ByteParsing = false; // Allow MIDI.read to handle all received data in one go
109-
// static const long BaudRate = 31250; // Doesn't build without this...
110-
//};
111-
//MIDI_CREATE_CUSTOM_INSTANCE(HardwareSerial, Serial1, MIDI, MySettings); // for USB-based SAMD
112-
//MIDI_CREATE_DEFAULT_INSTANCE();
113-
114131
//
115132
Oscil<SAW_ANALOGUE512_NUM_CELLS, MOZZI_AUDIO_RATE> aOsc1(SAW_ANALOGUE512_DATA);
116133
Oscil<SAW_ANALOGUE512_NUM_CELLS, MOZZI_AUDIO_RATE> aOsc2(SAW_ANALOGUE512_DATA);
@@ -126,23 +143,51 @@ uint32_t last_debug_millis;
126143

127144
// core0 is UI
128145
void setup() {
129-
pinMode(LED_BUILTIN, OUTPUT);
130-
131-
// Serial1.setRX(uart_rx_pin);
132-
// Serial1.setTX(uart_tx_pin);
146+
Serial1.setRX(uart_rx_pin);
147+
Serial1.setTX(uart_tx_pin);
133148

134149
Serial.begin(115200);
135150
MIDIusb.begin(MIDI_CHANNEL_OMNI);
136151
MIDIusb.turnThruOff(); // turn off echo
137-
// MIDIuart.begin(MIDI_CHANNEL_OMNI); // don't forget OMNI
138-
// MIDIuart.turnThruOff(); // turn off echo
152+
MIDIuart.begin(MIDI_CHANNEL_OMNI); // don't forget OMNI
153+
MIDIuart.turnThruOff(); // turn off echo
154+
155+
// KNOBS & BUTTON & LED
156+
pinMode(led_pin, OUTPUT);
157+
button.attach(sw_pin, INPUT_PULLUP);
158+
button.setPressedState(LOW);
139159

140160
// TOUCH
141161
for (int i = 0; i < touch_count; i++) {
142162
touches[i].begin(touch_pins[i]);
143163
touches[i].threshold += touch_threshold_adjust; // make a bit more noise-proof
144-
touched[i] = false;
145164
}
165+
166+
// DISPLAY
167+
Wire1.setSDA(i2c_sda_pin);
168+
Wire1.setSCL(i2c_scl_pin);
169+
Wire1.begin();
170+
171+
if (!display.begin(SSD1306_SWITCHCAPVCC, oled_i2c_addr)) {
172+
Serial.println(F("SSD1306 allocation failed"));
173+
for (;;) ; // Don't proceed, loop forever
174+
}
175+
display.setRotation(2); // rotated 180
176+
display.clearDisplay();
177+
178+
int16_t x1, y1;
179+
uint16_t w, h;
180+
display.setFont(&myfontB);
181+
display.getTextBounds("HELLO", 0, 20, &x1, &y1, &w, &h);
182+
line_spacing = h * 1.5;
183+
184+
synthui.print_text(0, line_spacing * 1, "PICO_TEST_SYNTH", &myfont);
185+
display.display();
186+
delay(500);
187+
synthui.print_text(15, line_spacing * 2, "MONOSYNTH1");
188+
//synthui.print_textf(0, line_spacing * 4, "params:%d patches:%d", num_patch_params, num_patches);
189+
display.display();
190+
delay(2500);
146191
}
147192

148193
// core0 is UI
@@ -153,6 +198,7 @@ void loop() {
153198

154199
if( millis() - last_debug_millis > 100 ) {
155200
last_debug_millis = millis();
201+
Serial.print("boop: ");
156202
for (int i = 0; i < touch_count; i++) {
157203
char t = touches[i].touched() ? '|' : ' '; // indicates a touched value
158204
int touchval = touches[i].raw_value / 100; // make a more printalbe value
@@ -165,6 +211,9 @@ void loop() {
165211

166212
// core1 is audio
167213
void setup1() {
214+
215+
delay(1000);
216+
168217
startMozzi(MOZZI_CONTROL_RATE);
169218
handleProgramChange(patch_num); // set our initial patch
170219
}
@@ -284,6 +333,24 @@ void handleMIDI() {
284333
break;
285334
}
286335
}
336+
while( MIDIuart.read() ) { // use while() to read all pending MIDI, shouldn't hang
337+
switch(MIDIuart.getType()) {
338+
case midi::ProgramChange:
339+
handleProgramChange(MIDIuart.getData1());
340+
break;
341+
case midi::ControlChange:
342+
handleControlChange(0, MIDIuart.getData1(), MIDIuart.getData2());
343+
break;
344+
case midi::NoteOn:
345+
handleNoteOn( 0, MIDIuart.getData1(),MIDIuart.getData2());
346+
break;
347+
case midi::NoteOff:
348+
handleNoteOff( 0, MIDIuart.getData1(),MIDIuart.getData2());
349+
break;
350+
default:
351+
break;
352+
}
353+
}
287354
}
288355

289356
void updateInputs() {

0 commit comments

Comments
 (0)