Mega pinout question

I'm making a Arduino Drum and use Mega2560, I try to connect the pin from (analog pin) A0 to A15, (digital pin) D46 to D52, write the pin code (0-15), (46-52), but pin A0 to A15 is working, and D46 to D52 isn't working, is the pin code wrong?

Hello willtcs

Post your sketch, well formated, with well-tempered comments and in so called
code tags "< code >" and schematic to see how we can help.

here is the schematic and code, thank you

byte KICK[6] = {100, 55, 25 30, 36, 1};
byte SNARE[10] = {100, 10, 30, 10, 10,  3,  1, 38, 40,  37};
byte TOM1[6] = {100, 55, 25, 30, 71, 1};
byte TOM2[6] = {100, 10, 10, 30, 69, 1};
byte TOM3[6] = {100, 10, 10, 30, 67, 1};

/////////////////////////////////////////////////////////////////////////////////////

#include <hellodrum.h>
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();

HelloDrum kick(0);
HelloDrum snare(1,2);
HelloDrum tom1(3);
HelloDrum tom2(50);
HelloDrum tom3(52);


void setup()
{
  MIDI.begin();
  Serial.begin(38400);

  //Set Curve Type
  kick.setCurve(KICK[5]);
  snare.setCurve(SNARE[6]);
  tom1.setCurve(TOM1[5]);
  tom2.setCurve(TOM2[5]);
  tom3.setCurve(TOM3[5]);
}

void loop()
{
  kick.singlePiezo(KICK[0], KICK[1], KICK[2], KICK[3]);
  snare.dualPiezo(SNARE[0], SNARE[1], SNARE[2], SNARE[3], SNARE[4], SNARE[5]);
  tom1.singlePiezo(TOM1[0], TOM1[1], TOM1[2], TOM1[3]);
  tom2.singlePiezo(TOM2[0], TOM2[1], TOM2[2], TOM2[3]);
  tom3.singlePiezo(TOM3[0], TOM3[1], TOM3[2], TOM3[3]);


  if (kick.hit == true)
  {
    MIDI.sendNoteOn(KICK[4], kick.velocity, 10); //(note, velocity, channel)
    MIDI.sendNoteOff(KICK[4], 0, 10);
  }

  if (snare.hit == true)
  {
    MIDI.sendNoteOn(SNARE[7], snare.velocity, 10); //(note, velocity, channel)
    MIDI.sendNoteOff(SNARE[7], 0, 10);
  }
  //RIM
  else if (snare.hitRim == true)
  {
    if (snare.velocity > 60)
    {
      MIDI.sendNoteOn(SNARE[8], snare.velocity, 10); //(note, velocity, channel)
      MIDI.sendNoteOff(SNARE[8], 0, 10);
    }
    else
    {
      MIDI.sendNoteOn(SNARE[9], snare.velocity * 2, 10); //(note, velocity, channel)
      MIDI.sendNoteOff(SNARE[9], 0, 10);
    }
  }

  if (tom1.hit == true)
  {
    MIDI.sendNoteOn(TOM1[4], tom1.velocity, 10); //(note, velocity, channel)
    MIDI.sendNoteOff(TOM1[4], 0, 10);
  }

  if (tom2.hit == true)
  {
    MIDI.sendNoteOn(TOM2[4], tom2.velocity, 10); //(note, velocity, channel)
    MIDI.sendNoteOff(TOM2[4], 0, 10);
  }
  if (tom3.hit == true)
  {
    MIDI.sendNoteOn(TOM3[4], tom3.velocity, 10); //(note, velocity, channel)
    MIDI.sendNoteOff(TOM3[4], 0, 10);
  }
}

Does the hellodrum library require the use of analog pins for the drum inputs?

I'm beginner of Arduino, I have checked the Hellodrum library. It's just use "byte pinx", is it mean use analog pin only? Do I add "pinMode" into code?

class HelloDrum
{
public:
  HelloDrum(byte pin1, byte pin2);
  HelloDrum(byte pin1);


private:
  byte pin_1;
  byte pin_2;
};

Somewhere in the sketch the pinMode for the pin has to be set.

Did you run a tutorial using the hellodrum.h libary already?

Yes I run the sketch using hellodrum.h library. So how I set the pinMode to both use analog and digital pin? Or I upload the library here?

I´m wrong.

The inputs of an Arduino are set to "INPUT" per default.

@willtcs
A0-A15 is the same as D54-D69 NOT D46-D52

I connect 18 piezo to both analog and digital pin.

The piezos need to connect to analog pins, so you can only have 16

So I add more 2 to 18, I want to connect all 18 piezo. Should I need to modify the pinMode on Hellodrum.h library?

The Mega2560 only has 16 analog inputs, you can't add more using the hellodrum lib

The library appears to support multiplexing, but I'm not familiar with the library so not sure how many devices this can support. See the diagram at the bottom of this page: https://github.com/RyoKosaka/HelloDrum-arduino-Library/blob/master/docs/circuit.md

You are right I was wrong, you can add more.

Yes as RyoKosaka he used UNO with multiplexing to run Hellodrum as most as 16 piezo. I tried to change UNO to Mega2560 without multiplexing and connect more than 16 piezo, first 16 piezo connect to analog pin (A0-A15) was working and other piezo connect to digital pin (D46-52) wasn't working. So I think is Hellodrum library is not support more than 16 piezo or digital pin.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.