Hey all,
i am working on a Sound station in a museum with the following setup: A Teensy 4.0 connected to 4 adafruit capacitive touch sensors, 2 joysticks, Buttons, Potis. The Teensy is connected to a mini PC, which is running ableton.
After months of work, everything seems to run fine. The problem is just, that after some hours, the computer looses connection with the teensy and i dont know why. Ableton doesnt show teensy as a midi input.
When we restart windows, everything connects again. The whole setup should be handled by the museum staff, so i dont want them to hassle around with the computers.
The Teensy still has current and seems to recognize capacitive touches (the sensors blink).
Does anyone have an idea? Overheating? The parts were not really hot.... Anything else?
Thanks in advance!!
Norbert
I can also post my code here (please dont be irritated how we handle switch button1, it is used to change the whole setup in ableton):
i am working on a Sound station in a museum with the following setup: A Teensy 4.0 connected to 4 adafruit capacitive touch sensors, 2 joysticks, Buttons, Potis. The Teensy is connected to a mini PC, which is running ableton.
After months of work, everything seems to run fine. The problem is just, that after some hours, the computer looses connection with the teensy and i dont know why. Ableton doesnt show teensy as a midi input.
When we restart windows, everything connects again. The whole setup should be handled by the museum staff, so i dont want them to hassle around with the computers.
The Teensy still has current and seems to recognize capacitive touches (the sensors blink).
Does anyone have an idea? Overheating? The parts were not really hot.... Anything else?
Thanks in advance!!
Norbert
I can also post my code here (please dont be irritated how we handle switch button1, it is used to change the whole setup in ableton):
Code:
#include <Wire.h>
#include <Adafruit_MPR121.h>
#include <ResponsiveAnalogRead.h>
#include <MIDI.h>
// Create an instance of the MIDI interface
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
// Define MIDI note numbers for each sensor
const uint8_t sensorNotes[12] = {36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47};
// Define capacitive touch sensors
Adafruit_MPR121 cap1;
Adafruit_MPR121 cap2;
Adafruit_MPR121 cap3;
Adafruit_MPR121 cap4;
uint16_t lasttouched1 = 0;
uint16_t currtouched1 = 0;
uint16_t lasttouched2 = 0;
uint16_t currtouched2 = 0;
uint16_t lasttouched3 = 0;
uint16_t currtouched3 = 0;
uint16_t lasttouched4 = 0;
uint16_t currtouched4 = 0;
// Define fader pins
const int faderPins[8] = {A0, A1, A2, A3, A6, A7, A8, A9};
ResponsiveAnalogRead faderReaders[8];
// Variables to store last fader values
int lastFaderValues[8] = {0};
// Define switch pins
const int switchPin1 = 0;
const int switchPin2 = 1;
const int switchPin3 = 2;
//Define Button Pins
const int switchPin4 = 3;
const int switchPin5 = 4;
// Variables to track previous switch- and button states
int switchButton1PrevState = HIGH;
int switchButton2PrevState = HIGH;
int switchButton3PrevState = HIGH;
int switchButton4PrevState = HIGH;
int switchButton5PrevState = HIGH;
// Define LED pin
const int ledPin1 = 11; // blau
const int ledPin2 = 12; // grün
void setup() {
Serial.begin(9600);
// Set the switch pins as input with internal pull-up resistors
pinMode(switchPin1, INPUT_PULLUP);
pinMode(switchPin2, INPUT_PULLUP);
pinMode(switchPin3, INPUT_PULLUP);
pinMode(switchPin4, INPUT_PULLUP);
pinMode(switchPin5, INPUT_PULLUP);
// Initialize capacitive touch sensors
if (!cap1.begin(0x5A)) {
Serial.println("MPR121 #1 not found, check wiring?");
while (1);
}
Serial.println("MPR121 #1 found!");
if (!cap2.begin(0x5B)) {
Serial.println("MPR121 #2 not found, check wiring?");
while (1);
}
Serial.println("MPR121 #2 found!");
if (!cap3.begin(0x5C)) {
Serial.println("MPR121 #3 not found, check wiring?");
while (1);
}
Serial.println("MPR121 #3 found!");
if (!cap4.begin(0x5D)) {
Serial.println("MPR121 #4 not found, check wiring?");
while (1);
}
Serial.println("MPR121 #4 found!");
// Initialize fader readers
for (int i = 0; i < 8; i++) {
faderReaders[i].begin(faderPins[i], true); // true enables auto calibration
}
// Set the LED pin as output
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
delay(1000);
}
void loop() {
// Set default MIDI channels based on the main switch
uint8_t midiChannel1 = 1;
uint8_t midiChannel2 = 2;
uint8_t midiChannel3 = 3;
uint8_t midiChannel4 = 4;
// Read the state of the switches
int switchButton1 = digitalRead(switchPin1);
int switchButton2 = digitalRead(switchPin2);
int switchButton3 = digitalRead(switchPin3);
int switchButton4 = digitalRead(switchPin4);
int switchButton5 = digitalRead(switchPin5);
/// Handle Button4 on the Side at first
if (switchButton4 != switchButton4PrevState) {
if (switchButton4 == LOW) {
usbMIDI.sendControlChange(100, 127, midiChannel1); // Send MIDI on press
} else {
usbMIDI.sendControlChange(100, 0, midiChannel1); // Send MIDI on release
}
switchButton4PrevState = switchButton4; // Update previous state
}
/// Handle Button5 on the Side at first
if (switchButton5 != switchButton5PrevState) {
if (switchButton5 == LOW) {
usbMIDI.sendControlChange(101, 127, midiChannel1); // Send MIDI on press
} else {
usbMIDI.sendControlChange(101, 0, midiChannel1); // Send MIDI on release
}
switchButton5PrevState = switchButton5; // Update previous state
}
//////////////HIER BEGINNT JETZT DER MAIN SWITCH
// Then handle switchButton1 state change
if (switchButton1 != switchButton1PrevState) {
if (switchButton1 == LOW) {
usbMIDI.sendControlChange(1, 127, midiChannel1); // Send MIDI on 1
usbMIDI.sendControlChange(1, 0, midiChannel1); // Send MIDI on 1
} else {
usbMIDI.sendControlChange(2, 127, midiChannel1); // Send MIDI on 2
usbMIDI.sendControlChange(2, 0, midiChannel1); // Send MIDI on 1
}
switchButton1PrevState = switchButton1; // Update previous state
}
// Adjust MIDI channels if the main switch is LOW
if (switchButton1 == LOW) {
// Read and ignore incoming MIDI messages
while (usbMIDI.read()) {
}
/// L E D
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
// If the main switch is HIGH, use default MIDI channels
midiChannel1 = 5;
midiChannel2 = 6;
midiChannel3 = 7;
midiChannel4 = 8;
// Read capacitive touch sensors
currtouched1 = cap1.touched();
currtouched2 = cap2.touched();
currtouched3 = cap3.touched();
currtouched4 = cap4.touched();
// Process each sensor separately with its own function
processSensor1(currtouched1, lasttouched1, sensorNotes, midiChannel1); // Sensor 1
processSensor2(currtouched2, lasttouched2, sensorNotes, midiChannel2); // Sensor 2
processSensor3(currtouched3, lasttouched3, sensorNotes, midiChannel3); // Sensor 3
processSensor4(currtouched4, lasttouched4, sensorNotes, midiChannel4); // Sensor 4
// Read and handle fader inputs
for (int i = 0; i < 8; i++) {
faderReaders[i].update();
int currentFaderValue = faderReaders[i].getValue();
// Check for fader value change
if (currentFaderValue != lastFaderValues[i]) {
// Send MIDI message on the current MIDI channel for all faders
usbMIDI.sendControlChange(sensorNotes[i], currentFaderValue >> 3, midiChannel1); // Send on specified MIDI channel
lastFaderValues[i] = currentFaderValue;
}
// Handle switchButton2 state change
if (switchButton2 != switchButton2PrevState) {
if (switchButton2 == LOW) {
usbMIDI.sendControlChange(34, 127, midiChannel2); // Send MIDI on press
} else {
usbMIDI.sendControlChange(34, 0, midiChannel2); // Send MIDI on release
}
switchButton2PrevState = switchButton2; // Update previous state
}
// Handle switchButton3 state change
if (switchButton3 != switchButton3PrevState) {
if (switchButton3 == LOW) {
usbMIDI.sendControlChange(35, 127, midiChannel3); // Send MIDI on press
} else {
usbMIDI.sendControlChange(35, 0, midiChannel3); // Send MIDI on press
}
switchButton3PrevState = switchButton3; // Update previous state
}
}
////////// ELSE ////////////
} else {
// If the main switch is HIGH, use default MIDI channels
midiChannel1 = 1;
midiChannel2 = 2;
midiChannel3 = 3;
midiChannel4 = 4;
// Read and ignore incoming MIDI messages
while (usbMIDI.read()) {
}
/// L E D
digitalWrite(ledPin1, HIGH); // Keep LED on
digitalWrite(ledPin2, LOW); // Keep LED on
// Read capacitive touch sensors
currtouched1 = cap1.touched();
currtouched2 = cap2.touched();
currtouched3 = cap3.touched();
currtouched4 = cap4.touched();
// Process each sensor separately with its own function
processSensor1(currtouched1, lasttouched1, sensorNotes, midiChannel1); // Sensor 1
processSensor2(currtouched2, lasttouched2, sensorNotes, midiChannel2); // Sensor 2
processSensor3(currtouched3, lasttouched3, sensorNotes, midiChannel3); // Sensor 3
processSensor4(currtouched4, lasttouched4, sensorNotes, midiChannel4); // Sensor 4
// Read and handle fader inputs
for (int i = 0; i < 8; i++) {
faderReaders[i].update();
int currentFaderValue = faderReaders[i].getValue();
// Check for fader value change
if (currentFaderValue != lastFaderValues[i]) {
// Send MIDI message on the current MIDI channel for all faders
usbMIDI.sendControlChange(sensorNotes[i], currentFaderValue >> 3, midiChannel1); // Send on specified MIDI channel
lastFaderValues[i] = currentFaderValue;
}
}
// Handle switchButton2 state change
if (switchButton2 != switchButton2PrevState) {
if (switchButton2 == LOW) {
usbMIDI.sendControlChange(33, 127, midiChannel2); // Send MIDI on press
} else {
usbMIDI.sendControlChange(33, 0, midiChannel2); // Send MIDI on release
}
switchButton2PrevState = switchButton2; // Update previous state
}
// Handle switchButton3 state change
if (switchButton3 != switchButton3PrevState) {
if (switchButton3 == LOW) {
usbMIDI.sendControlChange(32, 127, midiChannel3); // Send MIDI on press
} else {
usbMIDI.sendControlChange(32, 0, midiChannel3); // Send MIDI on release
}
switchButton3PrevState = switchButton3; // Update previous state
}
}
}
// Sensor 1 processing
void processSensor1(uint16_t currtouched, uint16_t &lasttouched, const uint8_t* sensorNotes, uint8_t midiChannel) {
for (uint8_t i = 0; i < 12; i++) {
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i))) {
usbMIDI.sendNoteOn(sensorNotes[i], 127, midiChannel); // Send MIDI Note On
}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i))) {
usbMIDI.sendNoteOff(sensorNotes[i], 0, midiChannel); // Send MIDI Note Off
}
}
lasttouched = currtouched;
}
// Sensor 2 processing
void processSensor2(uint16_t currtouched, uint16_t &lasttouched, const uint8_t* sensorNotes, uint8_t midiChannel) {
for (uint8_t i = 0; i < 12; i++) {
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i))) {
usbMIDI.sendNoteOn(sensorNotes[i], 127, midiChannel); // Send MIDI Note On
}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i))) {
usbMIDI.sendNoteOff(sensorNotes[i], 127, midiChannel); // Send MIDI Note Off
}
}
lasttouched = currtouched;
}
// Sensor 3 processing
void processSensor3(uint16_t currtouched, uint16_t &lasttouched, const uint8_t* sensorNotes, uint8_t midiChannel) {
for (uint8_t i = 0; i < 12; i++) {
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i))) {
usbMIDI.sendNoteOn(sensorNotes[i], 127, midiChannel); // Send MIDI Note On
}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i))) {
usbMIDI.sendNoteOff(sensorNotes[i], 0, midiChannel); // Send MIDI Note Off
}
}
lasttouched = currtouched;
}
// Sensor 4 processing
void processSensor4(uint16_t currtouched, uint16_t &lasttouched, const uint8_t* sensorNotes, uint8_t midiChannel) {
for (uint8_t i = 0; i < 12; i++) {
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i))) {
usbMIDI.sendNoteOn(sensorNotes[i], 127, midiChannel); // Send MIDI Note On
}
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i))) {
usbMIDI.sendNoteOff(sensorNotes[i], 0, midiChannel); // Send MIDI Note Off
}
}
lasttouched = currtouched;
}