Hello, I'm trying to help my son with his end of year 6th grade project. His design vision was "color to sound".
The hardware implementation is
||TCS3200 Color Sensor > SparkFun MIDI Shield mounted on Arduino R4 WiFi > 5 pin DIN from the SparkFun MIDI Out > MPC Key 61 MIDI In||
The color sensor is wired per this schematic:
and the MIDI shield is mated directly to the R4 with headers.
On the software side, we've attempted to use a mishmash of sample code piece by piece to get things going. This library is referenced; This is the code:
// TCS230 or TCS3200 pins wiring to Arduino
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
// Stores frequency read by the photodiodes
int redFrequency = 0;
int greenFrequency = 0;
int blueFrequency = 0;
// Stores the red. green and blue colors
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
void setup() {
// Setting the outputs
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
MIDI.begin(4); // Launch MIDI and listen to channel 4
// Setting the sensorOut as an input
pinMode(sensorOut, INPUT);
// Setting frequency scaling to 100%
digitalWrite(S0,HIGH);
digitalWrite(S1,HIGH);
// Begins serial communication
Serial.begin(31250);
}
void loop() {
// Setting RED (R) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
redFrequency = pulseIn(sensorOut, LOW);
// Remaping the value of the RED (R) frequency from 0 to 255
// You must replace with your own values. Here's an example:
// redColor = map(redFrequency, 70, 120, 255,0);
redColor = map(redFrequency,1150,100,0,127);
// Printing the RED (R) value
Serial.print(" R = ");
Serial.print(redColor);
delay(100);
// Setting GREEN (G) filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
greenFrequency = pulseIn(sensorOut, LOW);
// Remaping the value of the GREEN (G) frequency from 0 to 255
// You must replace with your own values. Here's an example:
// greenColor = map(greenFrequency, 100, 199, 255, 0);
greenColor = map(greenFrequency, 8000, 127, 0, 127);
// Printing the GREEN (G) value
Serial.print(" G = ");
Serial.print(greenColor);
delay(100);
// Setting BLUE (B) filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
blueFrequency = pulseIn(sensorOut, LOW);
// Remaping the value of the BLUE (B) frequency from 0 to 255
// You must replace with your own values. Here's an example:
// blueColor = map(blueFrequency, 38, 84, 255, 0);
blueColor = map(blueFrequency, 1000, 74, 0, 127);
// Printing the BLUE (B) value
Serial.print(" B = ");
Serial.print(blueColor);
delay(100);
// Checks the current detected color and prints
// a message in the serial monitor
if(redColor > greenColor && redColor > blueColor){
Serial.println(" - RED detected!");
}
if(greenColor > redColor && greenColor > blueColor){
Serial.println(" - GREEN detected!");
}
if(blueColor > redColor && blueColor > greenColor){
Serial.println(" - BLUE detected!");
}
{
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
delay(1); // Wait for a second
Serial.print("note played!");
MIDI.sendNoteOff(42, 0, 1); // Stop the note
}
}
as it stands; at this point I'm just trying to get any message to come from the MIDI out on the shield to the MPC with no luck. I think I'm missing something with declaring/configuring the serial port, but I am short on time and losing faith. Any help would be great; my messages in the discord are instantly flagged as spam so I'm trying this, thank you in advance!





