![]() PK0 should only be defined when you're compiling for ATmega640, ATmega1280, or ATmega2560. Serial:4: error: 'PK0' was not declared in this scope I can't reproduce that: Arduino: 1.8.5 (Windows 7), Board: "Arduino Nano, ATmega328P"Ĭ:\Users\per\AppData\Local\Temp\arduino_modified_sketch_807778\serial.ino: In function 'void setup()': The odd thing is that I thought that changing to a Nano, the compiler would recognize that PK0 wasn't an allowed variable, but it didn't. You just need to stop thinking you can plug anything other than Arduino pin numbers into functions that are written to take Arduino pin numbers. It just didn't have your intended result. So of course the Arduino core library functions allow you to use PK0 as an argument since indeed there is a pin 0. So there's no magic to PK0, it's just the bit number in the PORTK register for that pin. If you look at line 1177 of /hardware/tools/avr/avr/include/avr/iomxx0_1.h you see: # define PK0 0 So "PK0" is obviously defined in the IDE-does that mean it is only appropriate in a certain class of statements, eg, direct port manipulation, but not in things like digitalWrite()? You can even use assembly if you want.īut neither of your responses answer the question of why "A8" works in the compiler, but "PK0" does not, yet it doesn't create a compiler error. All the more efficient operations are still available to you. Sure, the Arduino pin functions are just intended to make the code more understandable to beginners and also make the code portable between different hardware. I'm betting that they can be manipulated using direct port commands such as "PORTB |= _BV(7)" as in KRUPSKI'S example. You will sometimes see it written as D14 to indicate "digital pin" 14 but you can't use that pin notation in the Arduino IDE. Is that just "14" or can it also be "D14" Public License along with this library if not, write to theįree Software Foundation, Inc., 59 Temple Place, Suite 330, You should have received a copy of the GNU Lesser General Lesser General Public License for more details. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This library is distributed in the hope that it will be useful,īut WITHOUT ANY WARRANTY without even the implied warranty of Version 2.1 of the License, or (at your option) any later version. License as published by the Free Software Foundation either Modify it under the terms of the GNU Lesser General Public This library is free software you can redistribute it and/or Pins_arduino.h - Pin definition functions for Arduino Here it is for the Mega 2560: arduino/ArduinoCore-avr/blob/master/variants/mega/pins_arduino.h /* Maybe it would be helpful for you to study the code that is used for the Arduino pin definitions. They don't even really know what an ATmega2560 is or that its pins have different names in the datasheet and so long as they are using the Arduino functions they don't need to. A beginner will look at the numbers on the silkscreen on their board and just use them and it works fine without any confusion. It's interesting how your extra knowledge is actually hindering you in being able to use the Arduino core API. The numbers in pink are the Arduino pin numbers. More advanced users like to access pins and ports directly (such as " PORTB |= _BV(7) " to turn bit 7 on Port B on, but that statement will only work on the particular Atmel chip (2560, 328p, etc.) being used.ĭirect access bypasses the Arduino "translation" layers and gives you a bit more speed, but in most cases it's easier to say something like " digitalWrite (13, HIGH)" than it is to turn on a particular bit in a particular port to do the same thing.įor some reason I thought that these graphics that are common around the web would have some relation to the pin names used in the IDE However, the exact PIN that is used for pin 13 (such as "PB7" or "PK0" will be different from board to board. For example, "Pin 13" will always respond to programming such as "digitalWrite (13)" no matter what board you have. The various Arduino boards are setup to be easy to use. ![]() I've been using Nanos and Pro-minis almost exclusively up till now, and they don't have any repeated/duplicate pin names. this only took an hour to figure out why I couldn't get pin 89/8 to function properly. Why is pin 53/PC0 along the bottom edge also labeled A8? Addressing this pin as PK0, eg, pinMode(PK0, OUTPUT), does not create an error message, but it also doesn't set the pin. When you do a pinMode(A8, OUTPUT), the pin that is set is 89/8 on the left side. Along the bottom edge, pin 53 is also shown as A8. On the mega, along the left side, port K (PK0) is shown variously as pin 8, pin 89, PK0, A8, and ADC8.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |