Microsoft MakeCode

Analog joystick on the PyGamer

How do I read the analogue position for the joystick on the PyGamer? I’ve just done a quick test of dx and dy. These looked promising but testing so far (on the default scaling of 100) shows 0 in the middle (good), far left shows -2.2, -2.1, -2 and occasionally -2.3 (reasonable), half way to left is 0 (not so good). Is dx supposed to give an analogue value? Is this just an overly large deadzone? If so, should that zone be smaller and (less important) is it configurable? Or is there another way to read the analogue joystick? That hardware feature looks unique to the PyGamer at the moment?

BTW, i think there’s a broken link in docs. dx is ok on but dy gives an error - note controller vs keys in URL.

The joystick is currently treated as digital with a hard coded dead zone. It would be good to fix dx/dy to be analog though. Or maybe introduce a new api. The current dx/dy are just scaled by frame time.

I started a PR here: but it’s far from complete. It would be useful to get a few data points on what you see when the joystick is idle with the program attached there. I’m thinking dead zone of -50 to 50.

If you want to do something right now, you can use this program, though it will fail in the simulator:

I guess you could check if the config value is 0, and don’t do the analog read then.

I put the code onto my PyGamer:

  • first center reading -6,3
  • left is -512,6
  • top is -8,-512
  • right is 511,-4
  • down is 5,511
  • centre is -6,4

I was pushing the joystick around carefully but not being super precise. I thought I’d try the diagonals, the values aren’t what I expected, I thought they would all go to magnitude 512:

  • top left, -373,-409
  • top right 412,-467
  • bottom right 422,441
  • bottom left -341, 395

Feeling the joystick at its outer range there is a circular range of travel rather than square so this does make sense.

I’m seeing similar numbers to kjw when I test it on my PyGamer. I made some tweaks to the code, but for some reason it crashes after a seemingly random amount of time. Anything obvious that I’m doing wrong that could cause the crash?

@auxin It would be interesting if you could post your actual numbers. These are important to inform a decision on ranges to encompass hardware variation and user variation. The latter may be significant on the diagonals.

What form does your crash take? Do you get the frown face and a number? Many of the error codes are listed on

I have:

  • Center -18, -29
  • Left -512, -40
  • Up -29, -512
  • Right 511, -40
  • Down 511, -20

Up-Left: -420, -473
Up-Right: 511, -380
Down-Left: -450, 294
Down-Right: 511, 320

It would be interesting to see if these values change over time due to components wearing down… :warning:

My exact values are:
Center: 11, -10
Left: -512, -11
Right: 511, -17
Up: -3, -512
Down: 7, 511

Up-Left: -455, -438
Up-Right: 480, -481
Down-Left: -445, 440
Down-Right: 436, 445

When it crashes it is just freezing completely up. I can’t bring up the menu and it doesn’t give the frowny face either.