clearskyer
Member
Hi ! Trying to make a midi to cv with my teensy 4.1 with a MPC4822 DAC.
From now, I believe the teensy receive the messages but the outputs of the 4822 are only +- 0.5v at maximum and doesnt really follow my automations.
I feed the Dac with the 5v of the teensy.
Board set to midix4, 600mhz, fastest.
Here's my code :
#include <MIDI.h>
#include <SPI.h>
// Define the MIDI channel and CC number you want to use for CV output
const int midiChannel = 1; // MIDI channel (1-16)
const int ccNumber = 39; // Control Change (CC) number (0-127)
// Define the CV output pin
const int cvOutputPin = 16; // Digital pin number (0-39) on Teensy 4.1
// Define MCP4822-related pins
const int chipSelectPin = 10; // Chip select (CS) pin
const int dataOutPin = 11; // SPI MOSI pin
const int clockPin = 13; // SPI clock pin
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
void setup() {
// Initialize the CV output pin
pinMode(cvOutputPin, OUTPUT);
// Initialize MCP4822-related pins
pinMode(chipSelectPin, OUTPUT);
// Initialize SPI communication
SPI.begin();
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0)); // Adjust the SPI clock speed if needed
// Initialize the MIDI interface
Serial1.begin(31250); // Set baud rate for MIDI communication
MIDI.begin(MIDI_CHANNEL_OMNI); // Set MIDI channel mode to Omni
// Set up MIDI CC callback function
MIDI.setHandleControlChange(OnControlChange);
}
void loop() {
// Process incoming MIDI messages
MIDI.read();
}
void OnControlChange(unsigned char channel, unsigned char control, unsigned char value)
{
// Check if the received MIDI message matches the specified CC number and channel
if (control == ccNumber && channel == midiChannel) {
// Map the CC value (0-127) to the desired CV range (e.g., 0-4095)
uint16_t cvValue = map(value, 0, 127, 0, 4095);
// Output the CV value to the MCP4822 chip
digitalWrite(chipSelectPin, LOW); // Enable MCP4822 communication
// Construct the 16-bit value to be sent to the MCP4822
uint16_t spiData = 0b0111000000000000 | (cvValue & 0b0000111111111111);
// Send the data to the MCP4822
SPI.transfer16(spiData);
digitalWrite(chipSelectPin, HIGH); // Disable MCP4822 communication
}
}
Im really not into code im trying to make music haha
If someone made one already and have a clue that would be incredible!
Thanks a lot !
From now, I believe the teensy receive the messages but the outputs of the 4822 are only +- 0.5v at maximum and doesnt really follow my automations.
I feed the Dac with the 5v of the teensy.
Board set to midix4, 600mhz, fastest.
Here's my code :
#include <MIDI.h>
#include <SPI.h>
// Define the MIDI channel and CC number you want to use for CV output
const int midiChannel = 1; // MIDI channel (1-16)
const int ccNumber = 39; // Control Change (CC) number (0-127)
// Define the CV output pin
const int cvOutputPin = 16; // Digital pin number (0-39) on Teensy 4.1
// Define MCP4822-related pins
const int chipSelectPin = 10; // Chip select (CS) pin
const int dataOutPin = 11; // SPI MOSI pin
const int clockPin = 13; // SPI clock pin
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
void setup() {
// Initialize the CV output pin
pinMode(cvOutputPin, OUTPUT);
// Initialize MCP4822-related pins
pinMode(chipSelectPin, OUTPUT);
// Initialize SPI communication
SPI.begin();
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0)); // Adjust the SPI clock speed if needed
// Initialize the MIDI interface
Serial1.begin(31250); // Set baud rate for MIDI communication
MIDI.begin(MIDI_CHANNEL_OMNI); // Set MIDI channel mode to Omni
// Set up MIDI CC callback function
MIDI.setHandleControlChange(OnControlChange);
}
void loop() {
// Process incoming MIDI messages
MIDI.read();
}
void OnControlChange(unsigned char channel, unsigned char control, unsigned char value)
{
// Check if the received MIDI message matches the specified CC number and channel
if (control == ccNumber && channel == midiChannel) {
// Map the CC value (0-127) to the desired CV range (e.g., 0-4095)
uint16_t cvValue = map(value, 0, 127, 0, 4095);
// Output the CV value to the MCP4822 chip
digitalWrite(chipSelectPin, LOW); // Enable MCP4822 communication
// Construct the 16-bit value to be sent to the MCP4822
uint16_t spiData = 0b0111000000000000 | (cvValue & 0b0000111111111111);
// Send the data to the MCP4822
SPI.transfer16(spiData);
digitalWrite(chipSelectPin, HIGH); // Disable MCP4822 communication
}
}
Im really not into code im trying to make music haha
If someone made one already and have a clue that would be incredible!
Thanks a lot !