Where do the "D" PIN numbers on an Arduino come from? - arduino

I am trying to understand the (very confusing) pin numbering on an MKRWIFI1010. The documentation says pin 2 on the header (which is numbered DAC0/A0 physically) is the 10-bit DAC output.
When I check the SAMD21 datasheet, I find that the VOUT signal is on pin 3, which is I/O pin PA02 (which can be found on the Arduino pinout as well, but not in the datasheet).
However, when I want to program it, I have to use the D designation from the Arduino pinout, which is D15, so I need to use analogWrite(15, value).
I can find almost all info on the datasheets, except where that number D15 comes from, neither from the SAMD21 datasheet, or the Arduino datasheet.

Related

Built-in led glowing on code of led on arduino mega

I had written a code on atmel studio for blinking a led on pin 13. After uploading the code with xloader mega's builtin led was blinking.
I uploaded fade code on my mega and the builtin led was blinking instead of led. What should i do?
I am using arduino mega 2560.
int main(void)
{
DDRB=0b00000000;
while (1)
{
PORTB=0b10000000;
_delay_ms(1000);
PORTB=0b00000000;
}
}
What you should do? Read the manual.
Please refer to https://ww1.microchip.com/downloads/en/devicedoc/atmel-2549-8-bit-avr-microcontroller-atmega640-1280-1281-2560-2561_datasheet.pdf
Chapter 13.2.
The DDxn bit in the DDRx Register selects the direction of this pin.
If DDxn is written logic one, Pxn is configured as an output pin. If
DDxn is written logic zero, Pxn is configured as an input pin.
Working with registers doesn't make sense if you don't know what they do.
DDRB=0b00000000;
Gives you inputs only.
why would you use Arduino and try to program it without its conventional macros and functions?
If you are trying to blink an led or make it breath then use the Arduino IDE and its built-in functions analogWrite() to generate a pwm pulse for your led or any led on suitable pins which support analogwrite(). You shouldn't try to do any direct modifications on registers if you have no suitable knowledge, because your risk destroying your development kit and maybe burning some other stuff around. Please use your kit's schematics to spot the pins which support analogwrite() and then use the code in examples.
That way you will achieve your goal faster and without any issues.
TL/DR: you have to set 7th bit in DDRB to one.
In AVR ports are configured by bits in two registers: DDRx and PORTx.
When the corresponding bit in the DDRx register is set to one, the port is configured as output. And the corresponding bit in the PORTx register chooses which electrical level is output on the pin. If it is 0 then internal MOSFET shorts the pin to "ground" lane, and sinks current from external source. When the bit of the PORTx is one, then the pin is connected to "VCC", sourcing big amount of current enough to lit up a LED.
But if the pin is connected to something, what consumes too much of current, or the pin is shorted to GND or VCC (let's say you have a button connected and pressed), then output MOSFETS might be overloaded and damaged.
If the bit in DDRx is set to zero, then the pin is configured as input. If the corresponding bit in the PORTx is zero, then the pin has no internal connection to power lines, it is called "Hi-impedance" state, or Tri-state. It does not source or sink any current. So, if no external source of current is connected, then pin level is floating, influenced by electrical interference. Logical level is not detectable and can change occasionally. If you want to connect, for example, a button (between the pin and GND), then logical level will be defined only when button is pressed. When it is released, the logical level will be undefined.
But! If the bit in the PORTx is set to one, then internal MOSFET connects the pin thru a resistor (about 35 kOhm) to VCC line. This make the pin to source a little amount of current, setting its logical level to high. Therefore, if a button is connected, when it is released, then pin will have defined high level. This is called "pull-up resistor". When button is pressed, it will not short and damage the MCU, because current flowing thru the button is limited by the resistor, but the logical level will be defined low.
What if instead of button you have a LED connected to the pin? Very small amount of current will flow thru the LED, makes it barely glow.
Read more in the datasheet (chapter 13. I/O-Ports)

STM32DUINO and analogRead for stm32f103c8t6

I have custom board on which I can upload my code generated from platformio and as board bluepill_f103c8. And I can make led blink etc. but when I want to do analogRead it always returns 0.
I'm trying to read from PA8 pin.
In my setup I put that pin as INPUT_ANALOG, do I need to do something else in order to get the reading?
Voltage that's on pin is about 0.25V that I'm trying to read.
According to STM32F103 Datasheet, page 34, any of 3 onboard ADCs simply do not have the ability to connect to PA8. PA8 can only work as simple GPIO (default, reads only 0 and 1), or as USART1_CK, TIM1_CH1, MCO in alternative configuration.
Arduino can use it as PWM output, or software USART, but there is no way to get analog reading from it.
If you really need to read analog voltage coming to that line, you would have to modify your board and solder PA8 to one of PA0..PA7, PB0..PB1, PC0..PC5 and re-configure ADC to read from that line.
#TonoNam, regarding your problem: unless PA1 is permanently damaged, it is fully capable of working with ADC, so there is something wrong with initialization or reading procedure.
Reference the pinout diagram here https://wiki.stm32duino.com/index.php?title=File:Bluepillpinout.gif
analogRead will only work with the pins which have associated ADC channels.
So this is PA0 through PA7, and then PB0 and PB1, so I guess this is your issue.
Looks like PA8 is a PWM output.

Number of Digital Pins

Why "NUM_DIGITAL_PINS" returns 20 when I'm using Arduino Uno?
How can I get the number of digital pins in arduino?
I'm using Arduino 1.0.5 IDE
Thanks
If you are wondering why the number is 20 when the Uno's digital pins goes from 0-13, is because the six analog pins can actually act as digital pins as well. So the total digital pins is 20.
By convention, NUM_DIGITAL_PINS (all uppercase) is a macro. Its value is determined when you compile. It's in fact done by a literal text replacement. It doesn't "return" anything. Functions would return different values, but they tend to look more like GetNumDigitalPins().

Arduino: Attach an interrupt to one of the higher pin numbers?

I have an Arduino Mega 2560. Is is possible to attach an interrupt on the higher pin numbers, for instance, D20 to D25? I tried PcInt, but it doesn't work with the higher pin numbers for some reason.
I have a custom board and it's using these pins, so my hands are tied in terms of what pins to use.
The pin mapping of the Mega2560 says that pins 20-25 aren't candidates for PCINTs (but 20 and 21 would have INTs). So the layout of the board makes it simply incompatible for this Arduino.

read analog value from xbee (non serially)

I'm trying to send an analog value from xbee to another xbee (WHICH IS CONNECTED TO ARDUINO). But I don't want to read this value serially (x=Serial.read();).
I would like to read this value from an arduino's analog input (x=analogRead(A0);). Can I pass an analog value from 1st xbee input pin to 2nd xbee output pin and connect this pin with ex.arduino's analog input (A0) and process it? If it can be done, how does this occur? (sorry for my english)
This is indeed possible. Xbee's have DAC and digital line support. Check out the user manual found in this Manual
The information you're going to need is on page 12. This is for series one xbee's.
For series two xbee's the process is different and can be found in this manual
manual on page 41. Good luck!
I would suspect you would be better off using xbee API and just do an AT command to read pin, then transfer it over serial TX out to the arduino RX in.

Resources