0

QT PY A0 output issues
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

QT PY A0 output issues

by Caducation on Tue Apr 13, 2021 8:41 pm

Hey all, I have a project where I am using PWM to control the ground on an LED motorcycle headlight. Without getting into all the specifics I will get to the main question/issues and add more detail below that.

Simple Question: How do you declare and use A0 as an analog output on a QT PY?

More details about what I am doing:

I have a test setup that works fine using a MicroView or standard Arduino UNO board, but I can't get to work with my QT PY. I am able to use A1 as a button input with no issues(I can control the brightness of the onboard NeoPixel) but I can't seem to use A0 as an output for a PWM. I have tried with and without declaring the pinMode (even though I know it says not to declare it). I have tried declaring the output pin as INT or #DEFINE with seemingly no change. I have A0 wired to the GATE of the NFET. I have 9v battery supplying the Anode to my small bank of LEDs with ground from the 9v also going to ground on the QTPY. I have the SOURCE of the NFET tied to ground(common to both the 9v and QTPY). This setup worked fine with the MicroView but can't get it to work with the QTPY.

Code: Select all | TOGGLE FULL SIZE
#include <Adafruit_NeoPixel.h>
#define pin 0
Adafruit_NeoPixel pixels(1, PIN_NEOPIXEL);

int buttonH = 1;
//int pin = 0;
int buttonHState = 0;


void setup() {

pixels.begin();  // initialize the pixel
   
//pinMode (pin, OUTPUT);
pinMode (buttonH, INPUT_PULLUP);
digitalWrite (buttonH, HIGH);

}

void loop() {
    // set the first pixel to red
    pixels.setPixelColor(0, pixels.Color(10, 0, 0));
    pixels.show();

  // Check the button state to see if its pressed   
  buttonHState = digitalRead(buttonH);
    if (buttonHState == LOW) { //If the button is pressed
      analogWrite(pin,255); //Output A0 PWM
      pixels.clear();
      pixels.setPixelColor(0, pixels.Color(255, 0, 0)); //Set neopixel to full bright
      pixels.show();
      delay(50);
    }else {
      analogWrite(pin, 100); //If button isn't pressed set the A0 low
    }
  }



So the bigger story, after I got the test setup working I ended up designing a custom PCB board and it wasn't until building the first board that I came across this because my test rig was not the QT PY. I just assumed i could use Pin A0 based on the datasheet. My Custom PCB will take 12v in from my motorcycle through a Vreg setup to get me a clean 5v. That will power the QT PY and also run to a voltage divider setup as i am bringing 12v in from switches to control High/Low signals that will alter the PWM. This all is going to the ground for the headlight as power runs straight from the bike to the headlight. So I have A0 as an output and A1 and A2 as inputs on my rig. My board has a lot of other stuff going on but the basis is that I already have a board that is setup to use A0 through an NFET and A1 and A2 go through BJTs with a vDivider so I am kinda stuck using those pins. I did set the board up to use all the pins either routed to proto space or to another connector but they won't go through the BJTs or NFET that I need so would really love to not scrap the work.

PS I haven't tried CircuitPython yet as everything is currently setup with Arduino and im testing apples to apples hopefully.

Thanks!

Caducation
 
Posts: 9
Joined: Tue Mar 02, 2021 7:09 pm

Re: QT PY A0 output issues

by Caducation on Tue Apr 13, 2021 8:48 pm

If its of any interest this is the board so kinda stuck on A0,A1 and A2 without some cluster in the small proto area, which is always an option. I ran traces from 3 input pins on the connector directly to the proto area and A3 on the QTPY with the intent on using this board for GPS/Datalogging maybe but its setup to have 2 SPI devices and still have the I2C STEMMA connector free. not using A0,A1 and A2 messes up future plans but the main function needed is for this PWM.

KTM BD Dimmer Board Layout rev2.png
KTM BD Dimmer Board Layout rev2.png (99.66 KiB) Viewed 217 times


PCB v 80.jpg
PCB v 80.jpg (185.14 KiB) Viewed 217 times


PCB v 80 Overview.jpg
PCB v 80 Overview.jpg (319.01 KiB) Viewed 217 times

Caducation
 
Posts: 9
Joined: Tue Mar 02, 2021 7:09 pm

Re: QT PY A0 output issues

by oesterle on Tue Apr 13, 2021 9:22 pm

Hi, Caducation!

Are you using the QT Py - SAMD21, or the QT Py RP2040?

The SAMD21’s A0 pin is special, in that it is a true analog pin, but can’t do PWM. Other pins, like A1, A2, and A3 can in fact do PWM.

You’ll find more in the Pinouts section of the QT Py SAMD21 primary guide.

Cheers,

Eric

oesterle
 
Posts: 790
Joined: Tue Sep 17, 2013 11:32 pm

Re: QT PY A0 output issues

by Caducation on Tue Apr 13, 2021 9:47 pm

I can't believe I did all that and missed that A0 does t have pwm!!! It's the samd21 version.

Well I guess I'll try A3 and use some jumper wires to the nfet and see if it works. Thanks for the quick reply and I'll post back after testing.

Thanks!

Caducation
 
Posts: 9
Joined: Tue Mar 02, 2021 7:09 pm

Re: QT PY A0 output issues

by Caducation on Wed Apr 14, 2021 9:11 am

oesterle wrote:Hi, Caducation!

Are you using the QT Py - SAMD21, or the QT Py RP2040?

The SAMD21’s A0 pin is special, in that it is a true analog pin, but can’t do PWM. Other pins, like A1, A2, and A3 can in fact do PWM.

You’ll find more in the Pinouts section of the QT Py SAMD21 primary guide.

Cheers,

Eric


Welp, A3 works just fine! Argg I am so mad for missing that. At least I have a work around.

thanks for your help!!

Caducation
 
Posts: 9
Joined: Tue Mar 02, 2021 7:09 pm

Re: QT PY A0 output issues

by Caducation on Mon Apr 19, 2021 9:08 am

Got the board working using A3 as my PWM output and A1 and A2 as inputs. Thanks again for the help! I will likely make a new PCB since the NFET i chose is not quite up to the task.

FYI for anyone looking to make their own boards. Digikeys Red service was great. Cheapest place in the states as my boards ended up about $3/each.

Caducation
 
Posts: 9
Joined: Tue Mar 02, 2021 7:09 pm

Re: QT PY A0 output issues

by Caducation on Tue Apr 20, 2021 2:31 pm

I spoke too soon. I do have an issue with the PWM Output (maybe). I have tried 2 different N channel Mostfets and both are getting hot, humming and generally getting ready to release the blue smoke.

I know this is more of an electronics question than specifically about the SAMD21 board, but maybe something in the fact that the pins also work for capacitive touch that might be affecting things and I don't know it.

So PWM from pin A3 to the Gate on an NFET. Source is ground and Drain is going to the ground line on an LED headlight. I have tried using a TO92 package NFET but the VGS curve likely was problematic. So I switched to a beefy TO220 NFET which appears to be able to handle what I am trying to do. The light in question is 26watt/2A on a 12v system. Power runs right to the headlight, in the most recent version ground was run external to the board common to the line that feeds the PCB ground plane and the QTPY.

https://www.adafruit.com/product/355?gc ... wHEALw_wcB


A bit long winded but is there something I am missing about the PWM output from the QTPY? By my estimates this should work just fine. It seems to get hotter faster when PWMing at 50% vs 100%. So is the VGS not saturating cause of something with the PWM from the board? Banging my head here.

Thanks for any and all input that might point me in the right direction!

Caducation
 
Posts: 9
Joined: Tue Mar 02, 2021 7:09 pm

Please be positive and constructive with your questions and comments.