Hi all,
I've been trying to copy this circuit from Arduino, and using it with my GEMMA M0 on the A0 Pin.
The circuit is:
And you measure the resistance as each button is pressed.
I "kind" of have it working - but the AnalogIn just gives random values between 0 and 3v - in waves, as seen in the CircuitPython guide here:
https://learn.adafruit.com/adafruit-gem ... nalog-in-2
With no contact on A2 - why is the Analog value not 0v? If the voltage was just 0v, until a button was pressed, it would be very easy to do this project.
The guide I followed is here:
https://www.instructables.com/How-to-Mu ... rduino-Tu/
Any advice would be great.
GEMMA M0 - Multiple Buttons on 1 Analog Pin
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- JohnBottle
- Posts: 23
- Joined: Sat Apr 09, 2022 2:32 pm
- dastels
- Posts: 15656
- Joined: Tue Oct 20, 2015 3:22 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
With the 100K as the bottom of the divider you may want larger values on the top sides to space out the values more. Maybe ones that are 10 times bigger? So instead of 4.95v, 4.9v, 4.85v, and 4.5v you would get 4.5v, 4.16v, 3.12, and 2.5v. The bigger spacing will make it easier to discern which switch is pressed and make resistor tolerances less of an issue.
With the SAMD21 analog input you probably want to use 3.3v rather than 5v.
Dave
With the SAMD21 analog input you probably want to use 3.3v rather than 5v.
Dave
- JohnBottle
- Posts: 23
- Joined: Sat Apr 09, 2022 2:32 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
Thanks for the reply Dave!
I should have said - I’m using the 3.3v out.
So should this be technically possible with the Gemma, and only 3.3v??
The analog output just seems to be a continuous wave from 0v to 3v - with no buttons being pressed - so at some point in the wave, the code “thinks” a button has been pressed.
The demo here shows it perfectly - the analog is never just “0v” - even with no connections or voltage to the pin.
https://learn.adafruit.com/adafruit-gem ... nalog-in-2
I should have said - I’m using the 3.3v out.
So should this be technically possible with the Gemma, and only 3.3v??
The analog output just seems to be a continuous wave from 0v to 3v - with no buttons being pressed - so at some point in the wave, the code “thinks” a button has been pressed.
The demo here shows it perfectly - the analog is never just “0v” - even with no connections or voltage to the pin.
https://learn.adafruit.com/adafruit-gem ... nalog-in-2
- dastels
- Posts: 15656
- Joined: Tue Oct 20, 2015 3:22 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
Yes, the Gemma M0 should have no trouble doing this.
"Output"?
Anyway, can you run the top example on https://learn.adafruit.com/adafruit-gem ... nalog-in-2 and post the output with no buttons pressed?
Dave
"Output"?
Anyway, can you run the top example on https://learn.adafruit.com/adafruit-gem ... nalog-in-2 and post the output with no buttons pressed?
Dave
- JohnBottle
- Posts: 23
- Joined: Sat Apr 09, 2022 2:32 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
Thanks again for the follow up.
I get exactly the results you see in the example/demo when no pin is touched. Like this:
No pin being touched - gives results like this:
(You would imagine it would just be 0v?)
When 3.3 is applied to the pin - it does show (3.3) repeated. But as soon as you let go, it goes back to the random values between 0 and 3
I get exactly the results you see in the example/demo when no pin is touched. Like this:
No pin being touched - gives results like this:
(You would imagine it would just be 0v?)
Code: Select all
(2.13199 ,)
(1.28498,)
(0.778171,)
(0.851939,)
(1.6638,)
(2.47666,)
(2.95236,)
(2.397 ,)
(1.57215,)
(0.879432,)
(0.44951,)
(0.596443,)
(1.18533,)
(1.87221,)
(2.56569,)
(2.72385,)
(1.97936,)
(1.3017,)
(0.693928,)
- adafruit_support_bill
- Posts: 88089
- Joined: Sat Feb 07, 2009 10:11 am
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
Looks like the input is floating. Check the connections on your 100K pull-down resistor.
- dastels
- Posts: 15656
- Joined: Tue Oct 20, 2015 3:22 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
Yes, it's acting like a touch input. And yes, check the resistor connections.
Dave
Dave
- JohnBottle
- Posts: 23
- Joined: Sat Apr 09, 2022 2:32 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
Do I need to tell the code that it is not a touch input somewhere? I've checked the resistor connections - and they look fine.dastels wrote:Yes, it's acting like a touch input. And yes, check the resistor connections.
Dave
This is my circuit - i've decided to try it on the 5v out - as it let's me copy another circuit design i found here: http://www.ignorantofthings.com/2018/07 ... istor.html
This is my code:
Code: Select all
import time
import board
from analogio import AnalogIn
analog_in = AnalogIn(board.A1)
# Helper to convert analog input to voltage
def get_voltage(pin):
return (pin.value * 3.3) / 65536
while True:
print((get_voltage(analog_in),))
time.sleep(0.1)
And this is the serial and plotter results when NO buttons are pressed - i'm sure my soldering is fine.
Code: Select all
(2.67883,)
(2.64016,)
(2.46453,)
(2.03108,)
(1.51223,)
(0.924902,)
(0.749267,)
(0.384302,)
(0.501929,)
(0.652588,)
(1.02642,)
(1.66611,)
(2.02222,)
(2.32192,)
Code: Select all
(1.28664,)
(1.42522,)
(1.43972,)
(1.43247,)
Thanks so much for any help with this!
- dastels
- Posts: 15656
- Joined: Tue Oct 20, 2015 3:22 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
You need to use 3.3v. The SAMD21 is a 3.3v MCU and can only measure between 0v and 3.3v. Putting more then 3.3v on an input can damage the MCU. Also, your code assumed a 3.3v max.
If you use AnalogIn you will be fine.
Another circuit to try is the one described in #5 on https://www.baldengineer.com/5-voltage- ... cuits.html.
The thing is that you've added wires that are acting like antenna and picking up EMF which gets read as a voltage. How long are the wires? What's the frequency of that rough sine wave you're seeing?
Dave
If you use AnalogIn you will be fine.
Another circuit to try is the one described in #5 on https://www.baldengineer.com/5-voltage- ... cuits.html.
The thing is that you've added wires that are acting like antenna and picking up EMF which gets read as a voltage. How long are the wires? What's the frequency of that rough sine wave you're seeing?
Dave
- JohnBottle
- Posts: 23
- Joined: Sat Apr 09, 2022 2:32 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
Guys... I have found the problem, but I am unsure what the reason is.
It comes down to a single wire - going from the start of the resistors - to the A1 pin on the Gemma - shown here:
If i use a crocodile clip - everything works fine!!
If I use my soldered wire - the voltage goes up, and down, up, and down.
But the soldering looks fine!! I really do not know what problem is. On big projects - how can you possibly track down if a wire is not working correctly.
Thanks for your help through this issue anyway!
It comes down to a single wire - going from the start of the resistors - to the A1 pin on the Gemma - shown here:
If i use a crocodile clip - everything works fine!!
If I use my soldered wire - the voltage goes up, and down, up, and down.
But the soldering looks fine!! I really do not know what problem is. On big projects - how can you possibly track down if a wire is not working correctly.
Thanks for your help through this issue anyway!
- dastels
- Posts: 15656
- Joined: Tue Oct 20, 2015 3:22 pm
Re: GEMMA M0 - Multiple Buttons on 1 Analog Pin
It happens. Maybe a weak point or break in the wire from being bent too often.
Dave
Dave
Please be positive and constructive with your questions and comments.