STM32F4 - External input source is not detected in GPIO.pulldown mode - microcontroller

I am currently working on a project that involves an STM32 F4 Discovery board where I am trying to use an external input source as the input to the GPIO pin. The external input source is a power supply set to 3.3V. The pins are set to mode GPIO_PULLDOWN such that the input is grounded when no particular value is assigned. However, I am unable to change the input value once it is grounded. When I set the power supply to give 3.3V to the input pin, it still stays grounded. But when I connect a 3.3V pin on the board to the input pin, it gets 3.3V as input. I have noticed one thing, which I find a bit strange: when I use a multimeter to measure the input pin, the multimeter measures 3.3V on the input pin when I use GND from the power supply and the VCC from the input pin. But when I use the GND pin from microcontroller and VCC from the input pin, it outputs 0V.
Any idea how I can solve this? I am quite fresh on this topic, so all advice would be appreciated. Thank you in advance.

Figured it out. The ground on the power supply is isolated, thus I needed to connect the ground on power supply with the microcontroller.

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)

Sim 900 GPRS shield pinout

I'm currently working on a project involving a GPRS Shield based on Sim 900 Chip
I was wondering if anyone would know which ones are the VIN Pin and the RING pin ?
It doesn't say on the board itself and all other searches have lead me to a dead end.
Also if you have a detailed pin layout it would be much appreciated.
Thank you
The GPRS shield is the one in the link below
http://imgur.com/a/1a2gx
Ring Pin
If you have a Multimeter with continuity testing, check where the RI pin (#4) on the Sim 900 chip is broken out to. Here is an overview of the pins:
If it isn't (some shields don't have them broken out) you could solder a wire to the RI pin with an LED and resistor to Ground, something like this:
[RI Pin]--------[wire]--------[LED]--------[Resistor (330Ohms?)]--------[Ground]
The ring indicator is HIGH by default and LOW when there is an incoming call. So, when there is no call the LED is on and off when there is an incoming call.
VIN
When the position of the switch (middle left in the image below) is set to "extern" (right), you have to supply power to the barrel connector. When you set the switch to the left position, the module takes power from the 5V pin of the arduino OR (dont attach both!) an external power supply you attach to that pin.
Hope it helps :)
PS: These SIM modules can have current peaks up to 2 Amps. I recommend you to use an external power source that can provide minimum 2A at 5V.
Edit:
This might be helpful:
http://wiki.seeed.cc/GPRS_Shield_v1.0/. I think its the same module as yours. Have a look at the "GPRS Shield v1.4 Schematic" at the bottom of the page.
Edit 2:
Comparing the board from the link and yours, i'm very certain that the ring pin is the one marked in red in the image above. Checking with a multimeter doesnt hurt though. You can add the same circuit i described above to that pin to add an LED indicator.

On NodeMCU or Arduino, what is the best rest state for a GPIO pin?

If a pin is unused, what should be its rest state?
I'm thinking gpio.INPUT makes sense, or maybe gpio.OUT set to gpio.LO, grounding the pin.
Is there a customary or preferred setting for unused pins?
For unconnected pins INPUT_PULLUP or OUTPUT. Using Pull-Up is better if there is any possibility that board layout will chance and someone connects this pin to ground/Vcc directly. It's better to sink small current to ground than short output pin to different logic level.
For connected pins INPUT (connection should be connected to LOW or HIGH level)

Can I use this to dim a 10w LED with an Arduino?

Currently I have this and a 12v power supply: http://www.ebay.com.au/itm/High-Power-10W-LED-Driver-MBI6651-PWM-DIM-
I want to dim a 12v 10w LED with PWM. Is there any way I can do this with an Arduino?
The pin description says this:
PWM terminal. When applied with +5v or suspended, full amount of current will be output and when connected with ground, output current will be 0.
So, as the Arduino runs off 5v, does that mean I can use the Arduino PWM to tell this board to DIM? Or I am I getting that totally wrong?
I'm a bit of an electronics noob, so forgive me if these questions are simple.
You can generate an PWM signal in the Arduino and link it to the PWM pin in the power supply, it should work as specified in the link.
PWM terminal. When applied with +5v or suspended, full amount of
current will be output and when connected with ground, output current
will be 0.
So if you generate a full signal, you will have the full power in the power supply, 100% light, 50% PWM will generate 50% power to the LED and so on...
You can check Arduino documentation for more information about how to use the PWM using analogWrite()
https://www.arduino.cc/en/Tutorial/PWM

Checking arduino code with multimeter

When we upload the code on arduino ,sometimes we do not get the desired results.
I saw a friend of mine doing the test on arduino using a multimeter to make sure that the code is right.
He said that we can make sure the code is right by checking the voltages on carious i/o pins on arduino. Like if the voltage on i/o pins is less than 5 V then the code is having some error,and also if we chckt the voltage on RX and Tx pins it should be 0.29 V.
I know question posted by me is not clear, but this is something which worked but i was not able to understand it properly.
So if anybody can deduce what this means and how it is done so, please proide an answer?
There are two main things to test with your multimeter: the voltage of the power to the Arduino (between 5v and Gnd), and the voltage of the IO pins (between them and Gnd).
Voltage of the power supply simply tells you if the Arduino is powered up correctly, if its power management circuits or power supply have failed, you'll be able to pick it up here.
Voltage of the outputs should be either 5v or 0v, relative to ground. By testing the voltage on a pin you can tell whether it is being written high (5v) or low (0v) by the Arduino, hence seeing what the code is doing to the pins.
I should make it clear that there is no right or wrong way to tell if the code in general is working based on the voltage of the pins.

Resources