Connections
We can test connections using the parts in the diagram below. Feel free to omit anything you do not wish to control, this example shows testing a number of things to give you an idea what can be done.
Signals
Signal 2 to LED (long lead +), LED (short lead -) to GND (breadboard common ground)
Signal 7 to leg of switch, opposite diagonal switch leg to ground
Signal 8 to Potentiometer middle pin. Ground to one outer pin, 3.3V to the other outer pin.
Servo
Servo connected to Servo block port 1, darkest wires facing towards micro:bit slot
Motor
Motor connected to Motor port 1 (color connections do not matter)
Plug in the micro:bit and Power
The micro:bit unfortunately fits into Crickit in either orientation but only one is correct. See the board markings which says "Micro:bit LED grid facing this way" - ensure the micro:bit LEDs face the direction shown.
Use a 5 volt 2A power supply plugged into the barrel jack of the Crickit. Ensure the tiny switch next to the barrel jack is in the On position. The green LED on CRICKIT with the smiley face (shown below) shows that CRICKIT is happy with its power supply.
The following MicroPython program tests the CRICKIT and micro:bit:
- The Motor drive
- The Digital In on the Signals block
- The Digital Out on the Signals block
- The Analog In on the Signals block
- Servo drive on the Servo block
The code also has a demonstration of the Drive block setting various levels not used here.
The following capabilities are currently not written into the seesaw.py driver:
- Sound (this does not need a driver, use the standard micro:bit sound pin 0 to output sound to the CRICKIT amplifier).
- NeoPixel control via micro:bit pin 16 (use the default micropython NeoPixel driver and use pin #16!)
- Stepper motor control on either the Motor or Drive blocks. (We wanted to keep things simple)
Code
Click download to get the main.py file below via the tutorial GitHub repo. Save the file as main.py in your mu_code
folder mentioned on the previous page.
# SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries # SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries # # SPDX-License-Identifier: MIT # main.py - code to test the Adafruit CRICKIT board with # the BBC micro:bit and MicroPython (NOT CircuitPython) # MIT License by Limor Fried and Anne Barela, 2019 # This code requires the seesaw.py module as a driver import time import seesaw seesaw.init() while True: # Touch test - check with the Mu plotter! print("Touch: \n(", end="") for i in range(1, 5): print(seesaw.read_touch(i), end=", \t") print(")") # analog read signal test - assumes analog input pin 8 print("Analog signal:\n(", end="") print(seesaw.analog_read(8), end=", \t") print(")") seesaw.write_digital(2, 0) # Assumes LED on Signal pin 2 time.sleep(0.1) seesaw.write_digital(2, 1) time.sleep(0.1) if seesaw.read_digital(7): # Assumes button on Signal pin 7 print("pin high") else: print("pin low") # Servo test - assumes servo on Servo position 1 on CRICKIT seesaw.servo(1, 0, min=0.5, max=2.5) time.sleep(0.5) seesaw.servo(1, 90, min=0.5, max=2.5) time.sleep(0.5) seesaw.servo(1, 180, min=0.5, max=2.5) time.sleep(0.5) # Drive test # seesaw.drive(1, 0.2) # seesaw.drive(2, 0.4) # seesaw.drive(3, 0.6) # seesaw.drive(4, 0.8) # motor test - assumes a DC motor on CRICKIT Motor 1 terminals seesaw.motor(1, 1) time.sleep(0.5) seesaw.motor(1, 0) time.sleep(0.5) seesaw.motor(1, -1) time.sleep(0.5) seesaw.motor(1, 0) time.sleep(0.1)
Moving the Code to the micro:bit
Click the Mu Files icon. Your files that are in your mu_code
folder will show up to the right. Using your cursor, drag seesaw.py to the left pane. Then do the same for main.py. This will copy the files onto the micro:bit.
The code should run. It might take a reset of the micro:bit and/or CRICKIT (both have reset buttons on them) to work.
To use the REPL to see the output of the code, click the Files icon once more to close that window, then click the REPL button. The program output can now be viewed. If the code isn't running and you've reset the boards, press on the keyboard to do a soft reboot.
Use
The program will continually be testing various functions as a demonstration. The LED will blink, the servo will turn, and the motor will turn on and off.
Values for the capacitive touch pads, the potentiometer, and the status of the switch will be printed out in the REPL window.
Page last edited January 21, 2025
Text editor powered by tinymce.