Yeah sorry, it’s the one earlier in the thread. Here the relevant section
G1 is directly connected to the arduino pin.
Yeah sorry, it’s the one earlier in the thread. Here the relevant section
G1 is directly connected to the arduino pin.
You probably want a pull down resistor. 100k or so from G1 to ground. That means that when there’s nothing connected the non-inverting input of your opamp will go to ground, and output should be pretty close to ground too.
As you’ll be providing the pull down externally you should configure the arduino output to not use any pull down or pull up resistors. I don’t know if that’s possible, I’ve never played with any arduinos.
Cheers
Of course the other solution is to not power the module when you don’t have the Arduino plugged in. It’s not clear to me why you would want to do so.
Yes, that’s not what I’m worried about. But I think there might be the problem that the pins are floating when the Arduino is booting and there might be high voltage at the pins during this (short) time. I need to really check this though, maybe that’s not an issue at all
The GPIO pins are “tri-stated” after reset (i.e. high impedance, or effectively “not there”). Adding a high-value pull-down seems like the easiest fix here.
(the internal pullups are 20-50k, btw, so you accidentally enable them the output voltage will be a bit weird, but at low currents so you won’t break anything by doing that).
Okay, I will go with the pullups then! I have a question on the code that @fredrik suggested (the one from the gameboy minimachine):
// MIDI channel to listen to (1-16, set to 0 to listen to all channels).
constexpr bool MIDI_CHANNEL = 0;
I guess this bool
should be a byte
?
if (MIDI_CHANNEL and midi_channel + 1 != MIDI_CHANNEL)
return;
How does this determine if it’s the right midi channel? Is the and
doing a bitwise operation between MIDI_CHANNEL
and midi_channel
or are they evaluated for truth individually and then only the single truth (bool) value is evaluated with and
? Sorry, I am not so good with C.
I guess this
bool
should be abyte
?
Oops, indeed.
How does this determine if it’s the right midi channel?
and
is an alias for &&
(link) which is a short-circuiting logical and, and the !=
binds tighter than the logical and (link), so the code first checks if MIDI_CHANNEL
is non-zero (or true
with the above typo), and only does the second test if it is.
(I usually stick to &&
in C/C++ but seems my brain preferred Python syntax that day, and the compiler didn’t complain…)
EDIT: You can change the test to
if (MIDI_CHANNEL > 0 && midi_channel + 1 != MIDI_CHANNEL)
return;
to make it a bit clearer.
Cool, that makes sense! So, the &&
is the same as and
and the bitwise-and is done by a single &
right? Same as in python. Now I understand! Thank you! I am also mostly using python and then some Fortran if I have to, now and then
No Yes, &&
(and it’s alias and
) is a logical operator, and is “short-circuiting”, meaning that it only calculates things if it has to. If you write x && y
it first checks if x
is true, and only checks y
if it is (since if x
is false you don’t have to check y
to figure out that the overall result is false).
&
is a bitwise operator, and if you write x & y
it needs to calculate both sides before it can do anything.
This is mostly the same as in Python (where and
is the logical short-circuiting version), except that in C++ logical expressions always return true
or false
, while Python returns the last thing it checked (so in this case x
if it’s false, otherwise y
no matter what).
(Logical or
works the same way, but only checks the second part if the first part is true false.)
EDIT: Wrote a long reply that started with “No”, pressed save, then noticed that I misread the ‘and and’ bit Changing the “No” to “Yes” fixes that, I think. Leaving the rest in there for future reference.
Another question: If I want to add software midi thru, can I just add a
Serial.write(next);
after the
byte next = Serial.read();
in midi_next()
?
You could take a look at the Arduino MIDI library, which implements software MIDI thru with message filtering.
That’s a very nice midi library!
I have done it like this now and it appears to work, but I still have to figure out the mapping, my beatstep is sending out strange midi notes for the drums, I need to check the settings, but I need to find a windows computer first!
#include <MIDI.h>
constexpr byte GATE01 = 13;
constexpr byte GATE02 = 2;
constexpr byte GATE03 = 3;
constexpr byte GATE04 = 12;
constexpr byte GATE05 = 11;
constexpr byte GATE06 = 4;
constexpr byte GATE07 = 5;
constexpr byte GATE08 = 10;
constexpr byte GATE09 = 9;
constexpr byte GATE10 = 6;
constexpr byte GATE11 = 7;
constexpr byte GATE12 = 8;
byte gates[] = {GATE01, GATE02, GATE03, GATE04, GATE05, GATE06, GATE07, GATE08, GATE09, GATE10, GATE11, GATE12};
byte current_gate;
constexpr int ngates = 12;
// Settings
// MIDI note to map to the first LED (0-63).
constexpr byte FIRST_NOTE = 36;
uint8_t i;
MIDI_CREATE_DEFAULT_INSTANCE();
void handleNoteOn(byte channel, byte note, byte velocity)
{
if (channel == 10){
digitalWrite(gates[note-FIRST_NOTE], HIGH);
}
}
void handleNoteOff(byte channel, byte note, byte velocity)
{
if (channel == 10){
digitalWrite(gates[note-FIRST_NOTE], LOW);
}
}
void setup()
{
MIDI.setHandleNoteOn(handleNoteOn);
MIDI.setHandleNoteOff(handleNoteOff);
MIDI.begin(MIDI_CHANNEL_OMNI);
for( i = 0; i < ngates; ++i ){
pinMode(gates[i], OUTPUT);
}
}
void loop()
{ MIDI.read();
}
Hey has there been a fully updated schematic for this project?
Hi, my midi2gate is ready and working fine, look here:
Schematic is in the repo, maybe not yet as pdf. It could use some Pulldowns on the outputs, but it’s okay:-)