Pin numbers of PB6 and 7?

Hi, probably easy to answer, but I cannot find it ... AFAIR, when using the internal oscillator, the pins for the external one are free digital IOs. hat are the pin numbers in the Arduino IDE for those?

  1. I assume that you are referring to the ATmega328 of the Arduino Board.

  2. The 16 MHz crytsal of the Arduino Board is already connected with Pin-9 (XTAL2/PB6) and
    Pin-10 (XTAL1/PB7).

  3. If you want to use the internal oscillator of this MCU, you need to change Fuse Bits. Pin-9 and Pin-10
    are now free, and they could now be used as digital IO.

  4. In Arduino Board, these two pins (PB6 and PB7) are not available as DPins on the connectors
    of the Board. There is no reference of these pins in the Arduino IDE.

You need to modify pins_arduino.h for the board type you are using to have those usable (as well the already mentioned fuse change).
In the older IDEs, there were 3 arrays that needed to be changed. I don't know if it is that simple still.

Well, it's a little trickier, some other areas to touch as well, but not too bad. See my <<< comments in the file.
(well, Notes really, as << won't compile as comments)
In IDE 1.8.1, it's in the Arduino/hardware/avr/variants/standard folder for an Uno for example.
Maybe a real programmer can tweak it up to work.

pins_arduino - modified.h (7.34 KB)

Thanks, I also had look at pins_arduino.h by now. Obviously, I did not think the pins would magically beam the signal through the external oszilator to my LEDs, after I yell loud enough at the IC to use the internal clock ... -_-
So, yes, I was referring to the ATMEGA328, should have made that clear, sorry. Obviously not in an Arduino board with a clock attached, but standalone with the fuses set accordingly.

I thought I had in the back of my mind that there where pin numbers defined, but looking at pins_arduino.h, I seem to have that confused with something.
Since I don't really need the pins, I'll not going through the hassle of changing header files. I guess grounding is the way to go?

There are none; they are not supported in the stock core's digitalWrite()/digitalRead()/pinMode() functions.

See pins_arduino.h :

#define NUM_DIGITAL_PINS            20

...

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
 _BV(0), /* 0, port D */
 _BV(1),
 _BV(2),
 _BV(3),
 _BV(4),
 _BV(5),
 _BV(6),
 _BV(7),
 _BV(0), /* 8, port B */
 _BV(1),
 _BV(2),
 _BV(3),
 _BV(4),
 _BV(5),
 _BV(0), /* 14, port C */
 _BV(1),
 _BV(2),
 _BV(3),
 _BV(4),
 _BV(5),
};

Stops after PC5 (pin 19)

Use Hansibul/MCUdude's MiniCore (it also provides a ready-made board def for internal oscillator or any other clocking option you can imagine) - this adds these two pins as pins 20 and 21. GitHub - MCUdude/MiniCore: Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB

Sounds like a good idea, thanks. Perhaps I read it there before.

Hey, Guys...

Sparkfun includes a "pins_arduino.h" file in their Serial7Segment project that uses an ATMEGA328P-AU chip which maps PB6 and PB7 to D22 and D23. Could this file be modified for use with the PDIP ATMEGA328P-PU chip which doesn't have A6 and A7 inputs?

TIA... Cheerful regards, Mike

/*
  pins_arduino.h - Pin definition functions for Arduino
  Part of Arduino - http://www.arduino.cc/

  Copyright (c) 2007 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA

  $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
  
  11-4-2012: Added pin definitions for PB6 and PB7 (oscillator pins)
  to map to D22 and D23.
*/

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

#define NUM_DIGITAL_PINS            22
#define NUM_ANALOG_INPUTS           8
#define analogInputToDigitalPin(p)  ((p < 6) ? (p) + 14 : -1)

#if defined(__AVR_ATmega8__)
#define digitalPinHasPWM(p)         ((p) == 9 || (p) == 10 || (p) == 11)
#else
#define digitalPinHasPWM(p)         ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
#endif

static const uint8_t SS   = 10;
static const uint8_t MOSI = 11;
static const uint8_t MISO = 12;
static const uint8_t SCK  = 13;

static const uint8_t SDA = 18;
static const uint8_t SCL = 19;
static const uint8_t LED_BUILTIN = 13;

static const uint8_t A0 = 14;
static const uint8_t A1 = 15;
static const uint8_t A2 = 16;
static const uint8_t A3 = 17;
static const uint8_t A4 = 18;
static const uint8_t A5 = 19;
static const uint8_t A6 = 20;
static const uint8_t A7 = 21;

#define digitalPinToPCICR(p)    (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
#define digitalPinToPCMSK(p)    (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
#define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))

#ifdef ARDUINO_MAIN

// On the Arduino board, digital pins are also used
// for the analog output (software PWM).  Analog input
// pins are a separate set.

// ATMEL ATMEGA8 & 168 / ARDUINO
//
//                  +-\/-+
//            PC6  1|    |28  PC5 (AI 5)
//      (D 0) PD0  2|    |27  PC4 (AI 4)
//      (D 1) PD1  3|    |26  PC3 (AI 3)
//      (D 2) PD2  4|    |25  PC2 (AI 2)
// PWM+ (D 3) PD3  5|    |24  PC1 (AI 1)
//      (D 4) PD4  6|    |23  PC0 (AI 0)
//            VCC  7|    |22  GND
//            GND  8|    |21  AREF
//      (D22) PB6  9|    |20  AVCC
//      (D23) PB7 10|    |19  PB5 (D 13)
// PWM+ (D 5) PD5 11|    |18  PB4 (D 12)
// PWM+ (D 6) PD6 12|    |17  PB3 (D 11) PWM
//      (D 7) PD7 13|    |16  PB2 (D 10) PWM
//      (D 8) PB0 14|    |15  PB1 (D 9) PWM
//                  +----+
//
// (PWM+ indicates the additional PWM pins on the ATmega168.)

// ATMEL ATMEGA1280 / ARDUINO
//
// 0-7 PE0-PE7   works
// 8-13 PB0-PB5  works
// 14-21 PA0-PA7 works 
// 22-29 PH0-PH7 works
// 30-35 PG5-PG0 works
// 36-43 PC7-PC0 works
// 44-51 PJ7-PJ0 works
// 52-59 PL7-PL0 works
// 60-67 PD7-PD0 works
// A0-A7 PF0-PF7
// A8-A15 PK0-PK7


// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
	NOT_A_PORT,
	NOT_A_PORT,
	(uint16_t) &DDRB,
	(uint16_t) &DDRC,
	(uint16_t) &DDRD,
};

const uint16_t PROGMEM port_to_output_PGM[] = {
	NOT_A_PORT,
	NOT_A_PORT,
	(uint16_t) &PORTB,
	(uint16_t) &PORTC,
	(uint16_t) &PORTD,
};

const uint16_t PROGMEM port_to_input_PGM[] = {
	NOT_A_PORT,
	NOT_A_PORT,
	(uint16_t) &PINB,
	(uint16_t) &PINC,
	(uint16_t) &PIND,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
	PD, /* 0 */
	PD,
	PD,
	PD,
	PD,
	PD,
	PD,
	PD,
	PB, /* 8 */
	PB,
	PB,
	PB,
	PB,
	PB,
	PC, /* 14 */
	PC,
	PC,
	PC,
	PC,
	PC,
	PC, //Add ADC6 as A6
	PC, //Add ADC7 as A7
	PB, //Add PB6 as D22
	PB, //Add PB7 as D23
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
	_BV(0), /* 0, port D */
	_BV(1),
	_BV(2),
	_BV(3),
	_BV(4),
	_BV(5),
	_BV(6),
	_BV(7),
	_BV(0), /* 8, port B */
	_BV(1),
	_BV(2),
	_BV(3),
	_BV(4),
	_BV(5),
	_BV(0), /* 14, port C */
	_BV(1),
	_BV(2),
	_BV(3),
	_BV(4),
	_BV(5),
	_BV(6), //Add ADC6 as A6
	_BV(7), //Add ADC7 as A7
	_BV(6), //Add PB6 as D22
	_BV(7), //Add PB7 as D23
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
	NOT_ON_TIMER, /* 0 - port D */
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	// on the ATmega168, digital pin 3 has hardware pwm
#if defined(__AVR_ATmega8__)
	NOT_ON_TIMER,
#else
	TIMER2B,
#endif
	NOT_ON_TIMER,
	// on the ATmega168, digital pins 5 and 6 have hardware pwm
#if defined(__AVR_ATmega8__)
	NOT_ON_TIMER,
	NOT_ON_TIMER,
#else
	TIMER0B,
	TIMER0A,
#endif
	NOT_ON_TIMER,
	NOT_ON_TIMER, /* 8 - port B */
	TIMER1A,
	TIMER1B,
#if defined(__AVR_ATmega8__)
	TIMER2,
#else
	TIMER2A,
#endif
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER, /* 14 - port C */
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER,
	NOT_ON_TIMER, //Adding PB6 as D22
	NOT_ON_TIMER, //Adding PB7 as D23
};

#endif

#endif

It will work without modification on PDIP chips. Just don't expect attempts at reading A6 and A7 to work. The code/sketch can't tell whether it's PDIP or TQFP - you'll just get garbage if you try to read A6 and A7.

BUT - why not just use MCUDude/Hansibul's MiniCore? It has an incredible set of options, in addition to making those pins work?

Thanks for the info'.

I found MCUDude/Hansibul MiniCore and I will check it out.

Cheerful regards, Mike