Before going much further, it's a good idea to make sure our motors and code will work as expected.
If you haven't used MakeCode before, this guide is a good place to start.
Your Circuit Playground Express board comes ready to work with CircuitPython. When you connect the board to your computer for the first time, it will appear as a flash (or thumb) drive named CIRCUITPY.
We'd like to make it work with MakeCode, which is done by putting it into "bootloader mode". All that's required to do this is to connect the board to your computer with a micro USB cable and click the small reset button in the center of the board. The available thumb drive should change from CIRCUITPY to CPLAYBOOT. Your code file will be placed on CPLAYBOOT.
Click this link or enter the portal below to interact with and change the code used in this project.
How to upload code
To upload code, connect you Circuit Playground Express to your computer using the micro USB cable, click the Download button in the above portal to download the .uf2 file to your computer, and drag 'n drop it onto the CPLAYBOOT drive.
The drive will automatically eject itself. (Your computer may give you a "failed to eject drive correctly" error, you can ignore this.)
The code for this project is as simple as it gets, and that's ok! All we need is a start and stop function for the servo motor, so we can start and stop firing ping pong balls when we want.
If you'd like to make changes, such as increasing or decreasing the rate at which balls are launched, you can change the value in the
servo write pin A1 block from
180 to something smaller, like
120, and the motor will turn slower, thus launching balls at a slower rate.
Once your code is uploaded to Circuit Playground Express, connect the motors (one at a time is easiest to manage), and test that they both respond as expected.
The motor that will provide the power to launch the balls is a DC motor, of the variety originally used in CD and DVD players. This type of motor only needs to be connected to a power source to run, so connecting to a ground pad and power pad on the Circuit Playground Express will automatically start it spinning.
Use alligator clips to connect the Black wire to GND, then connect a second alligator clip to the red wire and touch the 3.3V pad with the tip. Your motor should respond right away by spinning up to full speed.
The motor that will push the ping pong balls into the path of the spinning wheel is a continuous rotation servo (not to be confused with a regular servo motor, which can only turn 90 degrees in either direction). This motor can't spin as fast as a DC motor, but can be controlled with much greater precision.
Connect the servo motor to Circuit Playground Express by running the:
- Brown wire to GND,
- Red wire to Vout, and
- Yellow wire to the A1 pad
When you press the A Button the motor should start slowly spinning, pressing the B Button will bring it to a stop.
Problem: My motor isn't spinning!
Solution: Make sure that your Circuit Playground Express is connected to a power source (anywhere between 3V-5V is safe). If you're using a AAAx3 battery pack, check that the switch on the battery pack is set to "ON".
Problem: My Circuit Playground Express doesn't show up as CPLAYBOOT!
Solution: Your Circuit Playground Express board comes ready to work with CircuitPython, and will show up as a flash drive named CIRCUITPY the first time it's connected to your computer. To switch over to work with MakeCode, connect the board to your computer with a micro USB cable and click the small reset button in the center of the board.
When Circuit Playground Express is in Bootloader mode, all the LEDs will flash red briefly, then turn green. Your computer should now show removable drive called CPLAYBOOT. Now you can copy the MakeCode file to the CPLAYBOOT flash drive.