attiny84 Wrong pin mapping

I moved a working project from attiny85 to the attiny84 as I needed more pins

I downloaded the latest version of the Arduino Tiny from github
For some reason the pin mapping seems to be wrong. (for me)

E.g Using the following code I would expect PA4 to blink but PA6 does instead.

Is there a logical answer?
I have the correct board selected etc and have burnt the boot loader.

Sorry if this is a stupid question.

Rob

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 

int led = PA4;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

PA4 is not a digital pin number.

If you look at an Uno for example, digital pin 12, what does that correspond to?

There is a mapping going on in the core (both Arduino and Tiny) which convert from a 'digital pin number' to an 'avr register name and bit' Somewhere in the core you will find a file which describes the 'digital pin' numbers and how they map to the real pin numbers.


Now if you want to know what PA4 means, then try this:

const byte led = PA4;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  PORTA |= _BV(led);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  PORTA &= ~_BV(led)    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Have you looked at this thread in which there seems to be a similar problem http://forum.arduino.cc/index.php?topic=211202.msg1552012#msg1552012

...R

123tcpip: I downloaded the latest version of the Arduino Tiny from github

This? https://github.com/damellis/attiny

or this one? https://github.com/TCWORLD/ATTinyCore

Thanks for the responses

This one https://code.google.com/p/arduino-tiny/downloads/detail?name=arduino-tiny-0150-0020.zip&can=2&q=

Pin mapping for the t84 processor... https://code.google.com/p/arduino-tiny/source/browse/avr/cores/tiny/pins_arduino.c?repo=core1-0150#164

int led = PA4;

PA4 is defined as "4" (meaning "bit 4") so the line becomes...

int led = 4;

Digital pin 4 is physical pin 7 / PA6 in the lower-right corner of the processor.

Make sense?

CodingBadly

Thank you for the reply.

Digital pin 4 would make sense if I saw D4 in any of the references I’m using.
I thought Arduino did all the clever stuff and I could just reference the pic without having to resort to reading and learning :slight_smile:
I was using the following attached files as my reference.

My problems started when I could address PA0 to PA5 but not PA6 & PA7
To test the PCB I had made I used the blink sketch to test each port, (Relay, Piezo, LEDs) I could address PA0 to 5 but not 6 & 7 (6&7 go to a Bipolar LED).

Having just come back to Arduino after a year break I am rusty and tried every variaition to talk to the pins.
In hind sight I think I have made a bad choice of what pins I use.

Any more pointers would be welcome.

Rob

123tcpip:
Digital pin 4 would make sense if I saw D4 in any of the references I’m using.

Did you follow the link I posted?

// ATMEL ATTINY84 / ARDUINO
//
// ±/-+
// VCC 1| |14 GND
// (D 0) PB0 2| |13 AREF (D 10)
// (D 1) PB1 3| |12 PA1 (D 9)
// PB3 4| |11 PA2 (D 8)
// PWM INT0 (D 2) PB2 5| |10 PA3 (D 7)
// PWM (D 3) PA7 6| |9 PA4 (D 6)
// PWM (D 4) PA6 7| |8 PA5 (D 5) PWM
// ±—+

I thought Arduino did all the clever stuff and I could just reference the pic without having to resort to reading and learning

It does. You just have to have the right pic.

I was using the following attached files as my reference.

I assume that latter image is the pin mapping for the core I referenced in Reply #3 but I honestly don’t know.

My problems started when I could address PA0 to PA5 but not PA6 & PA7

They should be digital pins 10 through 5 and digital pins 4 and 3.

To test the PCB I had made I used the blink sketch to test each port, (Relay, Piezo, LEDs) I could address PA0 to 5 but not 6 & 7 (6&7 go to a Bipolar LED).

PA6 is digital pin 4. PA7 is digital pin 3.

The digital pins form a U starting with the upper-left physical pin and ending with the upper-right; just like the ATmega328 pin mapping.

The analog numbering matches the PA-number; just like the ATmega328 (port C). PA0 is analog input 0, PA1 is analog input 1, etcetera.

Coding Badly

I have now looked at the link you sent and tested and as always you are correct.

I admit I don’t fully understand how addressing the pins D0 to D10 is derived but I assume it’s somewhere within the Tiny code.
Where would i find this information in future for other ATTinys?

Lastly I’m using serial for debugging which by default comes out on D0, I have tried various things to move this but again I can’t figure this out.
Is this possible?
http://arduino.cc/en/reference/serial

123tcpip: ...and as always you are correct.

Ha! I wish!

I admit I don't fully understand how addressing the pins D0 to D10 is derived but I assume it's somewhere within the Tiny code.

Lower down from that link. The seven arrays below define the pin mapping for digital pins.

The analog pins are not really mapped. The value passed to analogRead is used to set the Analog Channel (ADMUX register).

Where would i find this information in future for other ATTinys?

Same source file just above and below the link.

Lastly I'm using serial for debugging which by default comes out on D0...

https://code.google.com/p/arduino-tiny/source/browse/avr/cores/tiny/TinyDebugSerial.h?repo=core1-0150#596 Looks like it should be B0 for a clock of 8 MHz or less. A0 for a clock more than 8 Mhz. Are you certain you are getting serial output on D0?

Oh, wait. You mean digital pin zero. Never mind.

I have tried various things to move this but again I can't figure this out.

Unfortunately, as you can see, the register is specified by address... https://code.google.com/p/arduino-tiny/source/browse/avr/cores/tiny/TinyDebugSerial.h?repo=core1-0150#599 Change TINY_DEBUG_SERIAL_REGISTER to 0x1B if you want serial output on port A otherwise leave it at 0x18 for port B. Change TINY_DEBUG_SERIAL_BIT to whichever bit you want.

Erni has information you may find helpful... http://www.ernstc.dk/arduino/tinycom.html

[quote author=Coding Badly link=topic=211843.msg1554336#msg1554336 date=1390207356][/quote]

123tcpip:

I thought Arduino did all the clever stuff and I could just reference the pic without having to resort to reading and learning

It does. You just have to have the right pic.

I am too confused with pin numbering to be used in Arduino IDE. Is there a place where one can find all those PAx and PBx pins neatly mapped against pin numbers to be used in Arduino IDE ? I think the beauty of Arduino and its family chips is that one can start using them without deep knowledge of electronics. But failure to find clear pin mappings is a big disadvantage, I believe.

There are two cores for the ATtiny84 processor. They have different pin mappings. Both mappings are available by following links in this thread.

Is there a place where one can find all those PAx and PBx pins neatly mapped against pin numbers to be used in Arduino IDE ?

By following the link in this thread for the core you are using.

But failure to find clear pin mappings is a big disadvantage, I believe.

No one is stopping you from creating such a document.

Which link? I went to this one: https://code.google.com/p/arduino-tiny/source/browse/avr/cores/tiny/pins_arduino.c?repo=core1-0150#164 . It is not very evident how to derive pin numbers to be used in Arduino IDE for, say, PA0 or PB0.

By following the link in this thread for the core you are using.

gv445:
Which link? I went to this one…

Is that the core you are using?

Hi, I am not sure I know what core means. I am looking for pinout for Attiny84 to be programmed on Arduino IDE 1.0.5. I believe I found the description I was looking for on this site:

http://academy.cba.mit.edu/content/tutorials/akf/embedded_programming_arduinoIDE.html

This cheet sheet might be useful if you are using the core (or files) found here https://code.google.com/p/arduino-tiny/

http://www.akafugu.jp/images/microcontroller-reference-sheet.png