Pybadge / Makecode. Can you access pin values to make a battery indicator?

Microsoft's MakeCode platform for easy blocks-style programming

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Post Reply
User avatar
krztoff
 
Posts: 5
Joined: Tue Apr 20, 2010 6:45 pm

Pybadge / Makecode. Can you access pin values to make a battery indicator?

Post by krztoff »

Hello,

I got my son a pybadge so he can learn to code using blocks in makecode arcade. We're wondering if there's a way to read the analog pin that carries the battery charge level using blocks via an extension perhaps?

Thanks in advance

User avatar
mikeysklar
 
Posts: 11727
Joined: Mon Aug 01, 2016 8:10 pm

Re: Pybadge / Makecode. Can you access pin values to make a battery indicator?

Post by mikeysklar »

From the PyBadge pinout page things looks good. A6 in the magic battery pin.
Pin A6 is connected to a voltage divider which gives half the current battery voltage. You can read the battery voltage by using the Arcada library function readBatterySensor() (it multiplies by two to give the actual voltage), by using analogRead(A6) in Arduino, or by using analogio.AnalogIn(board.A6) in CircuitPython.
You should be able to use the read analog pin block.

User avatar
krztoff
 
Posts: 5
Joined: Tue Apr 20, 2010 6:45 pm

Re: Pybadge / Makecode. Can you access pin values to make a battery indicator?

Post by krztoff »

I don't have that block. Is there an extension specifically for the pybadge that adds that? I see the edgeconnector extension which allows something similar, but A6 isn't an option (only Px where x= 0 - 31)

User avatar
mikeysklar
 
Posts: 11727
Joined: Mon Aug 01, 2016 8:10 pm

Re: Pybadge / Makecode. Can you access pin values to make a battery indicator?

Post by mikeysklar »

Read analog should be available to all MakeCode builds with analog pins.

Is this the block in question or a different one?
Screenshot 2023-09-07 at 11.16.37 AM.png
Screenshot 2023-09-07 at 11.16.37 AM.png (11.6 KiB) Viewed 342 times

Another code block example which might be helpful to finding those analog pins.

Screenshot 2023-09-07 at 11.58.12 AM.png
Screenshot 2023-09-07 at 11.58.12 AM.png (28.51 KiB) Viewed 338 times

User avatar
krztoff
 
Posts: 5
Joined: Tue Apr 20, 2010 6:45 pm

Re: Pybadge / Makecode. Can you access pin values to make a battery indicator?

Post by krztoff »

I think part of my confusion is that there exists both:

makecode.adafruit.com

and

arcade.makecode.com

The instructions I've seen refer to the latter as being the correct site on which to program for the PyBadge. This is further reinforced by the fact that the PyBadge is specifically listed as an option when you choose to download your project and it asks you to specify your hardware. However arcade.makecode.com doesn't have an extension that opens up access to the PyBadge's pins as far as I can tell. I can only find an equivalent to what you posted on the makecode.adafruit.com page, but on that page we don't have any way to program for the PyBadge as it only appears to support the "Adafruit Circuit Playground Express".

I'm sure i'm doing something wrong here, but I promise I've tried and tried to answer this myself.

Here's what's available on arcade.makecode.com by default:
Screenshot 2023-09-07 at 12.44.46 PM.png
Screenshot 2023-09-07 at 12.44.46 PM.png (165.24 KiB) Viewed 333 times

User avatar
krztoff
 
Posts: 5
Joined: Tue Apr 20, 2010 6:45 pm

Re: Pybadge / Makecode. Can you access pin values to make a battery indicator?

Post by krztoff »

mikeysklar wrote: Thu Sep 07, 2023 2:17 pm Read analog should be available to all MakeCode builds with analog pins.

Is this the block in question or a different one?

Screenshot 2023-09-07 at 11.16.37 AM.png


Another code block example which might be helpful to finding those analog pins.


Screenshot 2023-09-07 at 11.58.12 AM.png
I guess to summarize, my question is: How do I get these blocks into arcade.makecode.com so they can be used to develop for my son's specific device and it's capabilities?

User avatar
krztoff
 
Posts: 5
Joined: Tue Apr 20, 2010 6:45 pm

Re: Pybadge / Makecode. Can you access pin values to make a battery indicator?

Post by krztoff »

does anyone have any ideas?

Post Reply
Please be positive and constructive with your questions and comments.

Return to “MakeCode”