Hello World with Adafruit's Crickit

Hello World!

When beginning a new programming language, the first thing that you learn is how to write a simple code/program called hello world, and display it on a computer screen or print out. 

With Adafruit's Crickit robotics platform, we have a new challenge, how to do a simple program, that gives a hello world but with robotics The challenge was given on Adafruit's weekly you-tube video program Ask and Engineer. So having recently obtained a Crickit board to work, I just felt compelled to make this program... I posted it on Youtube linked below



Parts
  1. Circuit Playground Express
  2. Crickit board
  3. Micro Servo SRG51
  4. Speaker 
  5. 5v Power adapter to power Crickit
  6. Colour printer
  7. Glue Gun or Double Sided Tape 
  8. Card board
  9. recording software for the sound file I used Parrot on my Samsung S9 Phone

These are the parts that I used, that I had already purchased, and I borrowed the speaker from my Google Aiykit (that I currently wasn't using.)

The robot 
To be fair, I borrowed a lot of this from other projects I had finished, including the Make Makey bot.
Noe and Padro affiliates of Adafruit put together a Makey paper bot that waves on their Youtube program 3D Hangouts. where the Ruiz Brothers  use a cricket paper cutting machine, i just printed their layouts for the Makey bot, in colour and then cut the arm off and glued it to another piece of cardboad. I glued the rest of the robot to another piece of cardboard and used the Ruiz Brothers direction to attach the arm to a servo.

Makey Cutout - Downloaded the SVG file and printed on a colour printer.

Build Steps

  1. Attach mounting posts to the Cricket using provided screws and mounting post, follow the Assembly Guide here
  2. Attach the Circuit Playground Express (CPX) to the Crickit, using the include screws, be careful to watch how to connect the CPX to the Crickit board, 
  3. Connect the Micro Servo Tower to the Crickit, in Servo connection 1. The colour alignment of the wires on your Micro Servo Tower should be from left to right (from away from the CPX to the CPX) Brown, Yellow, Black  (Although depending on your Servo the first wire maybe another colour than Brown. 

Now you need to download a special file to put on the CPX, which allows you to write code to make use of your Crickit. 
The instructions are here.



Code
To get the actual voice of Hello world I had to use Circuit Python, a language and files that Adafruit uses to easily write scripts that work on their hardware. The easist way to get up and going without getting into coding is to use the block based emulator Makecode which does not require you to understand coding you just use predefined block to make code that you can upload quickly to your CPX.
As listed on the Adafruit Learning Guide I used the Mu editor
Getting started with Mu here
here is the code that I used to accomplish this...

from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo
import board
import time
import audioio

print("1 Servo demo!")

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

# Create servo object
pwm = PWMOut(seesaw, 17)    # Servo 1 is on s.s. pin 17
pwm.frequency = 50          # Servos like 50 Hz signals
my_servo = servo.Servo(pwm) # Create my_servo with pwm signal
wavfile = "hello.wav"
f = open(wavfile, "rb")
wav = audioio.WaveFile(f)
a = audioio.AudioOut(board.A0)
a.play(wav)

while True:
    my_servo.angle = 0      # right
    time.sleep(1)
    my_servo.angle = 90     # middle
    time.sleep(1)
# and repeat!
 
# Or wait for the audio to finish playing:
while a.playing:
    pass
 
f.close()

Honsestly there is probably a cleaner way to do this, like buttons, but I was having issues with getting the buttons to work with my servo, so this code will just keep going until you stop it.


The hello wav file. 
The CPX can only drive simple wav files to play sounds, so I used the free Google play app called Parrot which allowed me to record at the required 44100hz wav file, which was super easy, just click on the MP4 button in the lower left and side, choose wav, and then record with the mic button 



Special Thanks
Lady ada for making the board, and python coding, which I pulled from a lot of the demos on the crickit learn guide and all the help on Discord
Mike Barela for the Make it move learn guide, for  Crickit
The Ruiz Brothers for the Paper Makey Craft project 
As well as Kattni Rembor for the Circuit Playground learning guide and help in Discord
And everyone in the Discord Community that helped out


Comments

Post a Comment