Author Topic: Digispark Pro pin confusion  (Read 1408 times)

N9LO

  • Newbie
  • *
  • Posts: 5
Digispark Pro pin confusion
« on: November 26, 2016, 09:22:46 pm »
I'm kind of new at this.  In the sample of my code below on a Digispark Pro where I use 1, 2, and 5 for outputs and they are on physical pins PB1, PB2, and PB5.  For the analog input light-sensor, a light dependent resistor and 10k pull down, I use 0 but it shows up on physical pin PA0 which is also called A6 using Digispark Pro Pin-out Diagram V2.  I want to use 2 of the PA pins to use with a 4 digit LED display.  I am confused when it comes what to call pins to have them do what I want them to do.  Is there short reference article I can get to get my brain on the right track?  Thank you for the help.

Code: [Select]
int LIGHTsensor = 0;
int READY_LED = 2;
int RUN_LED = 5;
int MOTOR_SPEED = 1; 

void setup()
{
  pinMode(LIGHTsensor, INPUT);
  pinMode(READY_LED, OUTPUT);
  pinMode(RUN_LED, OUTPUT);
  pinMode(MOTOR_SPEED, OUTPUT);
  analogWrite(MOTOR_SPEED, 0);
}
void loop()
{
   val2 = analogRead(LIGHTsensor);
« Last Edit: November 26, 2016, 09:26:58 pm by N9LO »

exeng

  • Sr. Member
  • ****
  • Posts: 437
Re: Digispark Pro pin confusion
« Reply #1 on: November 27, 2016, 09:58:14 am »
If I understand the diagram correctly for the Digispark Pro, you use the Digital or Analog pin designations. For example, you want to use A6 for your light sensor, that is actually pin 6 on the Digispark Pro. Alternatively, you could use the static const A6 (e.g. analogRead(A6);). You can only use the Ax constants for analogRead();

I think the PAx and PBx in the diagram are port mappings with are not intended to be used at the user sketch level and only there for reference. So use either the digital pins number or the Ax if you want for analogReads only.

I believe that SS,SCK, MISO and MOSI are also defined constants for the matching pins but haven't tried using them.

Hope this helps.

N9LO

  • Newbie
  • *
  • Posts: 5
Re: Digispark Pro pin confusion
« Reply #2 on: November 27, 2016, 12:15:37 pm »
Thanks, it does help.   But the funny part is when I call for analog read on 0 it reads pin 6 also called A6.

PeterF

  • Hero Member
  • *****
  • Posts: 794
Re: Digispark Pro pin confusion
« Reply #3 on: November 27, 2016, 10:17:39 pm »
Yup, exeng has it on the nail.

When you look at the pinout diagram, for analog stuff you use the cyan pin names (so the Ax constants), and for the digital stuff you use the yellow ones.

From the source code, there is a note that "Ax constants cannot be used for digitalRead/digitalWrite/analogWrite functions, only analogRead()" - which is because of the re-defining of the pin numbers. i.e. A6 will map to 14 - so for A6 you should be able to use 14 or A6. Now, why 0 also addresses P(in)6 works I can't tell you... I haven't look that deeply into the code...

The P(ort)A and P(ort)B references are there to make life easier if you're looking at the datasheet of the ATiny167 powering the Digispark Pro or want to do port manipulation (manipulating multiple I/O pins simultaneously).

N9LO

  • Newbie
  • *
  • Posts: 5
Re: Digispark Pro pin confusion
« Reply #4 on: November 28, 2016, 06:57:38 am »
Thank you all for the help.  As for the analog read 0 going to pin 6, I'll just move that to the "Mysteries of the Electron" folder in my brain.  Its not alone in there either.