Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

CPX and Servos beyond A1 + A2
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

CPX and Servos beyond A1 + A2

by gallaugher on Sun Oct 27, 2019 4:03 pm

Hi,
I'm wiring up a simple candy dispenser based on the Cat Treat Dispenser at:
https://learn.adafruit.com/automatic-ca ... -dispenser

All 3 SG92R servos share ground & VOUT, but I've got the signals wired separately to A1, A2, and A3.
I hadn't realized until it came time to program servo 3 that MakeCode doesn't seem to offer an option to control servos beyond A1 and A2. Is there any way to get the third servo signal? I'm not using a Crickit, just connecting directly to the CPX.

If I can't do this in MakeCode, is it possible if I switch to CIrcuitPython?
Thanks!
John

servo-write-pins.png
servo-write-pins.png (196.65 KiB) Viewed 265 times

thee tubes.jpg
thee tubes.jpg (211.33 KiB) Viewed 265 times

gallaugher
 
Posts: 166
Joined: Tue Aug 14, 2018 12:42 pm

Re: CPX and Servos beyond A1 + A2

by V2man on Sun Oct 27, 2019 5:00 pm

Note: The extended equivalent SERVO green blocks in Crickit also only have only two options: A1 and A2

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPX and Servos beyond A1 + A2

by gallaugher on Sun Oct 27, 2019 5:15 pm

Thanks - I'm not using a Crickit. Was able to shift to Circuit Python & get all three servos operating with capacitive touch, sharing ground & VOUT, but on A1, A2, and A3, and cap touch on A4, A5, A6. Do you know if MakeCode allows for the addition of pins beyond A1 and A2 or is this a CircuitPython-only option.
Thanks,
John

gallaugher
 
Posts: 166
Joined: Tue Aug 14, 2018 12:42 pm

Re: CPX and Servos beyond A1 + A2

by V2man on Sun Oct 27, 2019 9:45 pm

@ gallaugher
I do not know if Makecode allows for more pins than A1 and A2. I am looking at Makecode now.

I know you are not using Crickit but I wish to correct my previous statement. You can control up to 4 servos with crickit set servo block.
I am not sure where I was in Makecode for CPX before when I saw some other blocks which I cannot find now.

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPX and Servos beyond A1 + A2

by V2man on Sun Oct 27, 2019 11:24 pm

I don't know much about Makecode but I came up with this:
Servo PWM outputs available: A0 thru A7, SCL, SDA, RX, TX
A pull-down resistor is required on the PWM output A3 in the example below.
What do you think?

PWMonPinsOtherThanA1nA2.JPG
PWMonPinsOtherThanA1nA2.JPG (48.19 KiB) Viewed 225 times


MakecodePWMOutputChoices.png
MakecodePWMOutputChoices.png (233.03 KiB) Viewed 225 times

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPX and Servos beyond A1 + A2

by V2man on Mon Oct 28, 2019 8:12 pm

@ gallaugher
Forgot to attach the uf2 file.
While this file is able to produce a periodic digital signal, I don't know if the actual frequency is 1/2500us or 400 HZ.
I don't know how much time the digital write to pin A3 takes.
Attachments
circuitplayground-PWMonPinsOtherThanA1nA2.uf2
(264 KiB) Downloaded 11 times

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPX and Servos beyond A1 + A2

by V2man on Tue Oct 29, 2019 12:57 pm

@gallaugher and @johnpark
I tried a variation of the previous uf2 attached below.
In this example the ratio variable is set to 0.8 on power up.
When button A on the CPX board is pressed the ratio variable is set 0.8.
When button B on the CPX board is pressed the ratio variable is set 0.2.
State_A changes from true to false depending on whether button A or B is pressed.
An oscilloscope monitoring pin A3 always shows the same waveform.
About 6 ms high and 29 ms low for a period of ~ 35 ms or frequency of 28.57 Hz.
No where near the period I was expecting of 1/2500 us or 400 Hz.
My conclusion is you cannot use pins other than A1 and A2 for PWM in Makecode.
Does anyone see anything wrong with what I did?
Attachments
circuitplayground-PWMonPinsOtherThanA1nA2X.uf2
(271 KiB) Downloaded 10 times

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPX and Servos beyond A1 + A2

by V2man on Wed Oct 30, 2019 3:47 am

This works for the values shown but if I set Tperiod = 20 ms and PW1 = O.5 ms and PW2 = 2.5 ms for a servo it fails.
So you can use the other pins for non-servo PWM applications!

PWMonPinsOtherThanA1nA2s.JPG
PWMonPinsOtherThanA1nA2s.JPG (88.91 KiB) Viewed 173 times
Attachments
circuitplayground-PWMonPinsOtherThanA1nA2s.uf2
(272.5 KiB) Downloaded 9 times

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Re: CPX and Servos beyond A1 + A2

by V2man on Wed Oct 30, 2019 12:48 pm

Sorry I did have an error in the duty cycle definitions. Should have divided instead of multiplied. The correction is below:

PWMonPinsOtherThanA1nA2s1.JPG
PWMonPinsOtherThanA1nA2s1.JPG (86.32 KiB) Viewed 154 times
Attachments
circuitplayground-PWMonPinsOtherThanA1nA2s1.uf2
(273 KiB) Downloaded 10 times

V2man
 
Posts: 704
Joined: Mon Dec 03, 2018 12:38 am

Please be positive and constructive with your questions and comments.