[Fixed]Analog pins definition

Please post bugs and enhancements for the STM core here
fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

[Fixed]Analog pins definition

Post by fpiSTM » Fri Jun 23, 2017 9:35 am

Hi all,
I've raised a discussion around the Analog pins definition:
https://github.com/stm32duino/Arduino_C ... /issues/37

Hope I described my thought clearly :roll:
Any feedback are welcome and greatly appreciate in this topic or in the github issue.
Last edited by fpiSTM on Wed Jun 28, 2017 7:26 am, edited 2 times in total.

User avatar
RogerClark
Posts: 6909
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Analog pins definition

Post by RogerClark » Fri Jun 23, 2017 10:09 am

The A0 - Ax pin names are not defined in LibMaple at all, because none of the supported boards have pins labelled like this.

So in answer to your first question

Is it required to define more than A0 to A5 by default ?


I would say no. Only the names A0 to A5 need to be defined, and only for Nucleo boards which have this on their silkscreen.


Sorry. Its been so long since I used AVR that I can't answer the question about pin mapping of AnalogRead(A0) vs AnalogRead(0)
and AnalogWrite(0) == AnalogWrite(D0)

Apart from AnalogWrite gets tricky if the board has DAC, because AnalogWrite on AVR always means PWM and is not always used to convert to analogue voltage, e.g. Servo's use the pulse width to set the position and probably do not convert to a voltage first.

fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Analog pins definition

Post by fpiSTM » Fri Jun 23, 2017 12:44 pm

Thnaks for your quick answer
RogerClark wrote:
Fri Jun 23, 2017 10:09 am
I would say no. Only the names A0 to A5 need to be defined, and only for Nucleo boards which have this on their silkscreen.
My brain will explode :lol:
It's sound good but I think lot of sketch will not compile as they use often A0.

I think to avoid any mismatch/confusion:
All pin defined as ADC in PinMap_ADC should be alias with Ax and NUM_ANALOG_INPUTS set to this number.

For example, some libs do a loop from 0 to NUM_ANALOG_INPUTS with analogRead(i).
RogerClark wrote:
Fri Jun 23, 2017 10:09 am
Sorry. Its been so long since I used AVR that I can't answer the question about pin mapping of AnalogRead(A0) vs AnalogRead(0) and AnalogWrite(0) == AnalogWrite(D0)
This could be considering OK; I think. As Arduino guy told me this should be like this.
RogerClark wrote:
Fri Jun 23, 2017 10:09 am
Apart from AnalogWrite gets tricky if the board has DAC, because AnalogWrite on AVR always means PWM and is not always used to convert to analogue voltage, e.g. Servo's use the pulse width to set the position and probably do not convert to a voltage first.
On STM32 core, if pin is DAC, it is used else we check if it is PWM and use it else it is only IO then we set high or low depending of the value.

User avatar
RogerClark
Posts: 6909
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Analog pins definition

Post by RogerClark » Fri Jun 23, 2017 9:59 pm

Hi Frederic

I mean, to only define A0 to A5, and only do this for Nucleo variants.

No need to define A6 etc as no board has a pin labelled A6 on the PCB silk screen.

And for variants like the Discovery, I do not think you need to define A0 etc, as the pins are labelled In the style PAx, PBx etc

fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Analog pins definition

Post by fpiSTM » Fri Jun 23, 2017 10:23 pm

RogerClark wrote:
Fri Jun 23, 2017 9:59 pm
Hi Frederic

I mean, to only define A0 to A5, and only do this for Nucleo variants.

No need to define A6 etc as no board has a pin labelled A6 on the PCB silk screen.

And for variants like the Discovery, I do not think you need to define A0 etc, as the pins are labelled In the style PAx, PBx etc
Ok this is not on PCB silk screen but for lot of sketches using a loop until the MAX ANALOG INPUT this will raise an error.
For Firmata also as it iterate over the pin number.
Sketches use the pin number not the Pin name PYx,...

As our goal is to reused as much as possible standard Arduino sketch even if the PCB silkscreen has no Ax, Ax should be defined.
Last edited by fpiSTM on Fri Jun 23, 2017 10:37 pm, edited 1 time in total.

User avatar
RogerClark
Posts: 6909
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Analog pins definition

Post by RogerClark » Fri Jun 23, 2017 10:36 pm

Arrghh..

Are the sketches that fail part of the examples that the IDE installs?

I dont think its practical to support all sketches that anyone has written for AVR.

fpiSTM
Posts: 192
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Analog pins definition

Post by fpiSTM » Fri Jun 23, 2017 10:49 pm

Yes and some other provided with libraries.
Moreover, as I said Firmata need this.

That's why I try to fit Arduino naming.

User avatar
RogerClark
Posts: 6909
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Analog pins definition

Post by RogerClark » Fri Jun 23, 2017 11:23 pm

fpiSTM wrote:
Fri Jun 23, 2017 10:49 pm
Yes and some other provided with libraries.
Moreover, as I said Firmata need this.

That's why I try to fit Arduino naming.
Ah OK.

I see I need for it :-(

danieleff
Posts: 336
Joined: Thu Sep 01, 2016 8:52 pm
Location: Hungary
Contact:

Re: Analog pins definition

Post by danieleff » Sat Jun 24, 2017 5:07 am

RogerClark wrote:
Fri Jun 23, 2017 9:59 pm
No need to define A6 etc as no board has a pin labelled A6 on the PCB silk screen.
Arduino nano / Nucleo-32 has A6/A7 on silkscreen. Nucleo-144 has A6/A7/A8 on the paper thingie that comes with it.

User avatar
RogerClark
Posts: 6909
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Analog pins definition

Post by RogerClark » Sat Jun 24, 2017 5:58 am

Thanks Daniel.
I looked at my Nucleo boards but I don't have either of those variants

Post Reply