0
\$\begingroup\$

I am new to electronics, but have a fair bit of general programming experience, be gentle :)

I have an existing PCB with an STMF103RCT6 where the available pins are GPIO D 0 and GPIO D 1.

I would like to be able to read values of a variable resistor (joystick) - I can see the voltage dropping gradually as I move the joystick forward, but at the moment I am only able to differentiate between full forward (1) and about halfway towards center. I understand that this is where the threshold is crossed, but not sure if there is a way to get at the 'distance' to threshold or the like - I have set the pins to be GPIO_Mode_AIN but not sure if this is a dead end, or if not, where to actually read analog data from.

Do I have options other than involving ADC or adding a capacitor and capturing how long it takes to fill?

Thanks!

\$\endgroup\$
  • 3
    \$\begingroup\$ Those pins aren't connected to the internal ADC of that microcontroller, so setting the mode to GPIO_Mode_AIN won't help. Without a respin of your board to free up some pins connected to the ADC, your options really are an external ADC and bit bang an interface on those two GPIOs. \$\endgroup\$ – Colin Nov 7 '17 at 12:09
  • \$\begingroup\$ Agree with Colin__s, or connect an external Joystick to one of already existing ADC modules.There are enough ADC channels on that chip. :) \$\endgroup\$ – Abel Tom Mar 13 '18 at 7:09
2
\$\begingroup\$

The short answer is you will need, at some point, to connect the joystick to the ADC. D0 and D1 are not suitable pins for reading an analog signal.

Before you get to plugging things in though, you are missing quite a bit of information. I suggest reading though MC's Data Acquisition handbook. It is short enough to be approachable and doesn't assume too much prior information. You can find it here: https://www.mccdaq.com/support/Data-Acquisition-Handbook.aspx

Once you have read it, you'll be in a position to revise your question to make it answerable. For this question to be answerable by us, we'll need to have you posting schematics of the circuit you're working on, specific part numbers (and possibly datasheet links), and code snippets.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.