Documentation for MiniBot!

docs minibot

Crickit Prerequisites

Setup Crickit for development

Note

No additional power supply is needed for the following steps

Update the Crickit

  1. Plug in USB cable into seesaw/Crickit
  2. Double-click the Crickit Reset button
https://cdn-learn.adafruit.com/assets/assets/000/067/690/thumb160/circuit_playground_seesawreset.jpg?1544825407
  1. Look for pulsing yellow LED
  2. Look for a New Disk on Your Computer [CRICKITBOOT]
https://cdn-learn.adafruit.com/assets/assets/000/057/191/medium640/circuit_playground_crickboot.png?1530833011
  1. Download the latest firmware
  2. Drag UF2 file onto CRICKITBOOT
https://cdn-learn.adafruit.com/assets/assets/000/057/192/medium640/circuit_playground_drag.png?1530840561
  1. Party!

Power Supply

Now plug in the included battery bank for power supply

Hint

For more help, refer to adafruit’s website for further guidance

Raspberry-Pi Prerequisites

Please run the following commands to setup the raspberry pi for code deployment

Note

Connect to a display using HDMI to run the code

Raspberry Pi password = raspberry

Power Supply

Use the included battery bank for power supply

Update distribution packages

First lets update your distribution packages

sudo apt-get update;

sudo apt-get upgrade;

sudo reboot;

Install git, python3 & pip

Next run the following commands to install git, python3 & pip

Attention

Python3 is required

sudo apt-get install -y python3 git python3-pip

Install CRICKIT Python3 lib.

Next run the following commands to install CRICKIT Python 3 libraries

sudo pip3 install RPI.GPIO adafruit-blinka

Install smbus i2c-tools

Next run the following commands to add SMBus and I2C support to Python

sudo apt-get install python-smbus;

sudo apt-get install -y i2c-tools

I2C Kernal Support

Installing Kernel Support for I2C devices

Run the following command for gui interface

sudo raspi-config

On the GUI select Interfacing Options followed by I2C

https://cdn-learn.adafruit.com/assets/assets/000/045/258/medium800/learn_raspberry_pi_interfacing.png?1502764684 https://cdn-learn.adafruit.com/assets/assets/000/022/832/medium800/learn_raspberry_pi_i2c.png?1423001363

When prompted to Enable I2C select ``yes``

https://cdn-learn.adafruit.com/assets/assets/000/022/834/medium800/learn_raspberry_pi_wouldyoukindly.png?1423001393

Reboot device to ensure I2C device support

To reboot run the following command

sudo reboot

Upon boot run the following command to see all the connected devices

sudo i2cdetect -y 1

it should show up at 0x40 (binary 1000000) as follows:

https://cdn-learn.adafruit.com/assets/assets/000/022/057/medium800/raspberry_pi_i2cdetect.png?1420234437

Install adafruit-circuitpython-crickit

To interact with the servos, install adafruit-circuitpython-crickit by running the following command

sudo pip3 install adafruit-circuitpython-crickit

Run all at once

# Installations
sudo apt-get update;
sudo apt-get upgrade;
sudo reboot;
sudo apt-get install -y python3 git python3-pip;
sudo pip3 install RPI.GPIO adafruit-blinka;
sudo apt-get install python-smbus;
sudo apt-get install -y i2c-tools;
# User input is required [select Interfacing Options>>I2C>>yes]
sudo raspi-config;

# Need to run separately
sudo reboot;
sudo i2cdetect -y 1

Hint

For more help, refer to adafruit’s website for further guidance

Motors and Servos

Ports for plugging in Motors and Servos

DC-Motors

Note

Crickit HAT only supports 2 DC Motors

Use with Motor port on the Crickit HAT

https://cdn-learn.adafruit.com/assets/assets/000/062/079/medium640/circuit_playground_Pi3-and-Crickit_HAT-Motors_bb.png?1537372525

Servos and Continious Servos

Note

Crickit HAT only supports 4 DC Motors

Use with Servo port on the Crickit HAT

https://cdn-learn.adafruit.com/assets/assets/000/062/077/medium640/circuit_playground_Pi3-and-Crickit_HAT-Servos_bb.png?1537371566

Setup

In order to start coding download the package minilib

Install minilib

Lets install minilib

pip3 install minilib

Party!

You’re done

Sample code

Sample code utilizing minilib package

Test driving

from minilib import Joystick, ArcadeDrive, Motor

left = Motor(0)
right = Motor(1)
jstick = Joystick(0)
robot = ArcadeDrive(left, right)

while True:
    forwardAxis = jstick.getAxis(1)
    steerAxis = jstick.getAxis(3)
    robot.drive(forwardAxis, steerAxis)

Test Motors

import time
from minilib import Motor

motor_1 = Motor(0)
motor_2 = Motor(1)

for _ in range(3):
    motor_1.throttle(1)
    motor_2.throttle(-1)
    time.sleep(1)

    motor_1.throttle(-0.5)
    motor_2.throttle(0.5)
    time.sleep(1.5)

    motor_1.throttle(1)
    motor_2.throttle(-1)
    time.sleep(1)

Test Servos

import time
from minilib import Servo

servo_1 = Servo(0)
servo_2 = Servo(1)

for _ in range(3):
    servo_1.angle(180)
    servo_2.angle(-180)
    time.sleep(1)

    servo_1.angle(-90)
    servo_2.angle(90)
    time.sleep(1.5)

    servo_1.angle(180)
    servo_2.angle(-180)
    time.sleep(1)

minilib Library

Documentation for the Library

minilib.ArcadeDrive

class minilib.Drive.ArcadeDrive(self, left, right)
__init__(self, left, right)

Setup Arcade drive

Parameters:
  • left – left side drive
  • rightServo (continuous_servo) – right side drive
drive(self, forwardPower, steerPower)

Drive given the forward and steer axis power Meant to be run inside a while loop

Parameters:
  • forwardPower (float) – Forward power from joystick axis
  • steerPower (float) – Steer power from joystick axis

minilib.TankDrive

class minilib.Drive.TankDrive(self, left, right)
__init__(self, left, right)

Setup Arcade drive

Parameters:
  • left – left side drive
  • rightServo (continuous_servo) – right side drive
drive(self, leftPower, rightPower)
Drive given the left and right axis power
Meant to be run inside a while loop
Parameters:
  • leftPower (float) – Forward power from joystick axis
  • rightPower (float) – Steer power from joystick axis

minilib.Joystick

class minilib.Joystick.Joystick(self, ID, deadband=0)
__init__(self, ID, deadband=0)

Setup Joystick control using pygame :param id: ID of the joystick :type id: int

getAxis(self, axisID)

Get the value of the axis

Parameters:axisID (int) – Id of the axis
Returns:value of the axis
Return type:float
getButton(self, buttonID)

Get the state of the button

Parameters:buttonID (int) – Id of the button
Returns:state of the button
Return type:bool

minilib.Motor

class minilib.Motor.Motor(self, ID)
__init__(self, ID)

Inintialize the DC Motor

Parameters:ID (int) – The ID of the Motor [0,1]
throttle(self, power)

Input power for the Motor

Parameters:power (float) – Value from -1 to 1

minilib.Servo

class minilib.Servo.Servo(self, ID)
__init__(self, ID)

Initialize a Servo

Parameters:ID (int) – ID of the Servo [0,1,2,3]
angle(self, degree)

Set the angle to rotate to

Parameters:degree (int) – degree of the Servo

minilib.Servo.ContiniousServo

class minilib.Servo.ContiniousServo(self, ID)
__init__(self, ID)

Initialize a Continious Servo

Parameters:ID (int) – ID of the Continious Servo [0,1,2,3]
throttle(self, power)

Set the throttle of the Continious Servo

Parameters:power (float) – Power of the Continious Servo -1 to 1

Indices and tables