pinout questions: Meduino Mega2560 R3 Pro Mini ATMEGA16U2

To start:

to anyone here that is annoyed that i'm asking a question on this board. please move one, i didn't post this to annoy.

to anyone else:

i'm looking for some "basic" information on pinout for this particular board that i believe anyone with some basic understanding and experience with arduino and this particular board can answer, that i can not, not at the moment without intensive research, for which i do not have the time at the moment.

so PLEASE, don't understand this as me being lazy to look it up! i'm just requesting an answer if you are already have the knowledge, i'm not asking others to do my work!! but im in a building stage and this information is needed to place the wires at the right pins, whicnh needs to be done now. all other work will be done in a few months or a year time, when i can research but for now i need the wires to be at the right place.

the arduino part is only a small part of a (for me) large project of years now that i need to finish. all the rest can be done later. yes maybe this is in the wrong order.. but at this moment it is a necessity.

the pinout information i have i got from this site:

http://wiki.epalsite.com/index.php?title=Mega2560_Pro_Mini

and

The Mega2560 Pro Mini board has all the IOs of Arduino Mega2560 R3, following are the parameters.

Microcontroller ATmega2560
Operating Voltage 5V
Input Voltage (recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 54 (of which 15 provide PWM output)
Analog Input Pins 16
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 256 KB of which 8 KB used by bootloader
SRAM 8 KB
EEPROM 4 KB
Clock Speed 16 MHz

so i'm missing extensive pin out information one would get with a genuine arduino board like this.

https://arduino-info.wikispaces.com/file/view/Mega2-900.jpg/421499040/Mega2-900.jpg

now my questions are:

  1. which 15 of the 54 digital pinouts are the PWM outputs, or basically.. how do i / you know that those are them?
    as it is not printed on the board in a way that i understand it.

  2. SDA and SCL pins:
    there is a print on the board that SDA is pin 20 and SCL is pin 21 but those pins are digital pins while on genuine arduino boards the SDA and SCl are analog pins (4 and 5) or seperate SDA and SCL pins.

if the SDA and SCL are indeed the digital 20 and 21 pins, then that would be ideal to me, can you confirm that i can use D20 and D21 as SDA and SCL pins.

  1. the meaning of the little "squares" on the upper right of Digital pin 2 till 13

any answers on these three questions would be highly appreciated.

for now i'll return to the books.

Kind regards

Matthieu

The pinout is exactly the same as the regular Mega.

spikey1973:

  1. which 15 of the 54 digital pinouts are the PWM outputs, or basically.. how do i / you know that those are them?
    as it is not printed on the board in a way that i understand it.

...

  1. the meaning of the little "squares" on the upper right of Digital pin 2 till 13

You answered your own question. 2-13 are PWM, just like on the Mega.

spikey1973:
2) SDA and SCL pins:
there is a print on the board that SDA is pin 20 and SCL is pin 21 but those pins are digital pins while on genuine arduino boards the SDA and SCl are analog pins (4 and 5) or seperate SDA and SCL pins.

You're thinking of the ATmega328P boards like the Uno. SDA is 20 and SCL is 21 on the Mega.

thank you very much for your reply! (and a quick one too)

about the pmw pins, i had an idea it might.. but as it says 15 pmw's and 2-13 is only 12 pins so i thought i had to be wrong with that assumption. any idea where the other 3 could located then? i only need one, and due to placing the excess to those ports are to say at the least trouble some.

my analog pins are all in use, and digital ports are accessible from pin 16 on, so i hope i can use another as such, this would make me really happy as it is basically the last issue i have before i can move on.

about SDA and SCl: indeed.. my bad, now i understand.. i was looking ad the pins SDA and SCl for the R3, which indeed is on a different spot.

much appreciated thanks

Matthieu

Pins 44, 45, 46 are also PWM. Those also aren't marked on the Mega but they are noted in the pin mapping diagram provided on the Mega's product page:

indeed!

it isn't marked on the images i posted links for but it is marked on the 2e board which i have to test on..
it was just difficult to see because of the headers i soldered on that one.

you have no idea how happy i am right now and how greatfull i am for your reply.
i can now complete the wiring (first the diagram and then the actual wiring and finish it all up!

much much appreciated.

wishing you the best weekend ever!

kind regards

I'm glad if I was able to be of some assistance. Enjoy!

you definately were.

also learned how to interpret / use the fact that it is also uses an atmega2560 chip, which will help me solve similar questions in the future.

i will added another karma point. but i had to wait an hour.

kind regards

Matt

Ah, I see. The "Pro Mini" part of the name was misleading. I suppose "Pro Mega" would have been a better choice of names by the manufacturer.

indeed also the mentioning of the 16u2 chip in the name confused me, together i kinda assumped that is sort of simulated the mega by adding a second chip. kiving it all the same options, but leaving me in doubt on the pin structure.

once again.. it is never good to assume anything.

i now understand now that has nothing to do with it, and the mega itself also has this 16u2 chip so it really doesn't make a difference what so every (that is how i understand it. please correct me if i'm wrong)

kind regards

Matt

The ATmega2560 uses serial communication for getting uploaded sketches and communication with the Arduino IDE Serial Monitor (e.g. Serial.prinln()) but most computers these days don't have a true serial port. Nowadays we use USB to connect devices to our computers. The ATmega2560 is a very nice microcontroller but it doesn't have any USB capabilities. For this reason a separate chip is usually added to Arduino boards that acts as a bridge between the serial communication of the ATmega2560 and the USB of your computer. The computer then creates a virtual COM port that makes it seem like your board is connected to a serial port on your computer even though it's connected via USB. The ATmega16U2 is a microcontroller that has native USB capabilities so it can be programmed to act as a serial-USB bridge.

Other Arduino boards use chips that are specifically designed for this use. The most common are the FTDI FT232 (AKA "FTDI") and the CH340.

Typically the only reason you will need to think about this chip is if you need to install the correct drivers for it in order for your board to be recognized by your computer. The Arduino IDE comes with the drivers for the ATmega16U2 and FT232 so usually you will only have troubles with that if you get one of the clone Arduino boards that use the CH340 (that's the cheapest of the three chips so it's quite common on the cheap clones).

There are some Arduino boards that use microcontrollers with native USB capabilities. These boards do not require a separate bridge chip, they can communicate directly over USB. The most common are the Arduino Leonardo and the Pro Micro.

thank you fro this extensive explaination! again much appreciated.

kind regards

Matthieu

can i ask another question..? it is related though!

the program that i'm going to use will be put together mainly from parts i scrap together from the internet. overall it will be rather basic.

one part of the code will be very similar to the code below (copied from this link):

it is intended to use the rotary encoder to set the light intensity of a ledstrip (ws2812b strip) manually, as the apperatus will be used in the dark as in light. therefor one would want it brighter or dimmer according to the circumstances, maybe i can do an automatic adjustment. but ifso i will also have this manual override.

basic idea is to get some temp sensors to measure an average temp and change the colour of the led strip accordingly.

as it is a machine that will be used in dark and light conditions i want the light intensity to be able to be set manually. for this i'm using a rotary encoder and this code as basis.

the coding and actually getting things to work will be a long time from now, the main thing is to get the hardware ready to be fully assembled. then i can use a second board with a test setup to get things working with the wires in the same place, but before i can do that i need to be sure that things will work with the way it is wired.
as access by then will be very complex, and i'd rather avoid that at all.

as also said i have some major limitations with the pins i can use, for now you've been a saving angle, as all pieces have fallen together, just realized though that there maybe one final issue, the interrupt in this code, as for now i have only one available., with some effort i can get a 2e one available but i rather not, so if i don't need to i won't

anyway so this code works with an interrupt. all i really need to know is. for this code to work do i need to have both pinA and pinB to be an interrupt pin, or is one of them enough?

looking at the first part of the code.. i thought pinA would need to be but,
looking at the interrupt part, it sounds like pinB is called.. which makes me think pinB needs to be an interrupt.

i know it isn't your code, but maybe you can answer with a quick glance?

again it would be very helpfull.

// Used for generating interrupts using CLK signal
const int PinA = 3; 

// Used for reading DT signal
const int PinB = 4;  

// Used for the push button switch
const int PinSW = 8;  

// Simple PWM LED pin
#define PinLED 11

// Keep track of last rotary value
int lastCount = 50;

// Updated by the ISR (Interrupt Service Routine)
volatile int virtualPosition = 50;

// ------------------------------------------------------------------
// INTERRUPT     INTERRUPT     INTERRUPT     INTERRUPT     INTERRUPT 
// ------------------------------------------------------------------
void isr ()  {
  static unsigned long lastInterruptTime = 0;
  unsigned long interruptTime = millis();

  // If interrupts come faster than 5ms, assume it's a bounce and ignore
  if (interruptTime - lastInterruptTime > 5) {
    if (digitalRead(PinB) == LOW)
    {
      virtualPosition-- ; // Could be -5 or -10
    }
    else {
      virtualPosition++ ; // Could be +5 or +10
    }

    // Restrict value from 0 to +100
    virtualPosition = min(100, max(0, virtualPosition));

    // Keep track of when we were here last (no more than every 5ms)
    lastInterruptTime = interruptTime;
  }
}

// ------------------------------------------------------------------
// SETUP    SETUP    SETUP    SETUP    SETUP    SETUP    SETUP    
// ------------------------------------------------------------------
void setup() {
  // Just whilst we debug, view output on serial monitor
  Serial.begin(9600);

  // Rotary pulses are INPUTs
  pinMode(PinA, INPUT);
  pinMode(PinB, INPUT);

  // Switch is floating so use the in-built PULLUP so we don't need a resistor
  pinMode(PinSW, INPUT_PULLUP);

  // Attach the routine to service the interrupts
  attachInterrupt(digitalPinToInterrupt(PinA), isr, LOW);

  // Ready to go!
  Serial.println("Start");
}

// ------------------------------------------------------------------
// MAIN LOOP     MAIN LOOP     MAIN LOOP     MAIN LOOP     MAIN LOOP
// ------------------------------------------------------------------
void loop() {

  // Is someone pressing the rotary switch?
  if ((!digitalRead(PinSW))) {
    virtualPosition = 50;
    while (!digitalRead(PinSW))
      delay(10);
    Serial.println("Reset");
  }

  // If the current rotary switch position has changed then update everything
  if (virtualPosition != lastCount) {
    
    // Our LED gets brighter or dimmer
    analogWrite(PinLED, virtualPosition);

    // Write out to serial monitor the value and direction
    Serial.print(virtualPosition > lastCount ? "Up  :" : "Down:");
    Serial.println(virtualPosition);

    // Keep track of this new value
    lastCount = virtualPosition ;
  }
}

as said, this is not my code, so all credit for it goes to: Ralph S Bacon

i got a reply from the author, it is only pin A that needs to be an interrupt :smiley:

none the less, thanks very much for all your help.

grtz Matt