cyber:bot Library Reference

This Micropython library is for the Parallax cyber:bot robot (#32700). It merges a micro:bit module with robot chassis hardware. An onboard Propeller multicore microcontroller pre-loaded with cyber:bot firmware assists the micro:bit, handling real-time servo control and sensor circuits on the breadboard. The micro:bit communicates with the Propeller through an I2C bus, no direct Propeller programming required.

The cyberbot module has a minimal list of core methods to support the cyber:bot robot kit and main tutorials. The additional modules can be imported as needed for use with additional hardware.

Version Compatibility

  • Library version: 0.6.1
  • cyber:bot board: Rev A
  • cyber:bot board firmware version: 1.0.2
  • Recommend micro:bit firmware version 0250 or higher
  • Recommend Mu version 1.0.2
  • Requires Online Python Editor v2.

cyberbot library downloads

API List - Overview

Throughout, pin parameters refer to Propeller I/O pin connections labeled P0-P22 on the cyber:bot board.  Note that pinN is an exception. I/O pin ranges are contiguous.

cyberbot module, bot class

Use from cyberbot import * at the top of your program.

  • Use only when the micro:bit is connected to the cyber:bot board
  • The 3-position PWR switch on the cyber:bot board must be set to position 1 or 2.
  • You don't need microbit import* if you are using cyberbot import * - as the latter takes care of the former, and saves code space.
  • If you don't need the cyberbot module but your micro:bit is mounted on the cyber:bot board, use  microbit import * instead.

Analog I/O

bot(pin).write_analog(lsb)

  • pin: 20...21 (voltage output), 0...19 (PWM output)
  • lsb range 0...1024 x 3.2227 mv or us high in 1024 us period
  • Max PWM signals: 4, max voltage outputs: 2

 lsb = pinN.read_analog()

  • Note: read_analog is a microbit module pin class method
  • N in pinN can be 0, 1, or 2 to correspond with voltages measured at the
  • cyberbot board A/D/0, 1, or 2 sockets.
  • lsb range 0...1023 is the number of 3.2227 mV units measured.

Communication

bot().detach()

  • Closes communication between micro:bit and cyber:bot board. 
  • Recommended at the end of any program that does not stay in an infinite loop that uses bot method calls.
  • Not needed if the program runs in an endless loop. 
  • Note: bot().attach() is not an object/method.  It occurs automatically at the beginning of programs that import from cyberbot.

Digital I/O

bot(pin).write_digital(state)

  • pin: 0...22, state: 0...1

state = bot(pin).read_digital()

  • pin: 0...19, state: 0...1

Infrared Object Detection

state = bot(pin_tx, pin_rx).ir_detect(f)

  • pin_tx: 0...15 to IR LED, pin_rx: 0...15 from IR detector
  • state: object reflection 1 not detected or 0 is detected

Timed I/O

bot(pin).pulse_out(us)

  • pin: 0...22, us: 1 to 26,843,545 

us = bot(pin).pulse_in

  • pin:  0...19, us: 1...250,000

cycles = bot(pin).pulse_count(ms)

  • pin: 0...19, ms up to 26000
  • cycles: 0 to 1.04 M (approx)

us = bot(pin).rc_time(state)
us = bot(pin).rc_time(state, uspc, da_lsb)

  • us: charge discharge time measured, up to 250,000
  • state: 1 pre-charges circuit to 3.3 V, 0 pre-charges to 0 V
  • Optional:
    • uspc: pre-charge time 10...26,000 (default is 1000)
    • da_lsb: pre-charge volts 0...1023 in 3.2227 mV units

bot(pin).tone(f, ms)

  • f: tone frequency in Hz 1 to 20,000 for audible.  Up to 128 MHz.  
  • Optional:
    • ms: tone duration (0...26,000) default 500

Servo Control

bot(pin).servo_angle(theta)

  • Use with the Parallax Standard Servo (#900-00005)
  • pin:16...19 recommended, 0...15 also supported
  • theta: 0 to 180 degrees (approx)
  • Use None to stop control signal, another _speed call to resume.

bot(pin).servo_speed(v)
bot(pinL, pinR).servo_speed(vL, vR)

bot(pin).servo_accelerate(a)

  • a: 1...200 %speed signal change/50th s. 
  • Note, this setting needs to be re-established if None is used in either servo_speed or servo_angle.

feedback360 module

Use from feedback360 import * at the top of program.

Use when replacing the cyber:bot default Continuous Rotation Servos (#900-0008) with Feedback360° servos (#900-00360)

drive class

drive().connect()

  • Use: P16 yellow left, P17 yellow right
  • P18 white left, P19 white right
  • Set P18 P19 jumper to VIN

drive.goto(L, R)

  • L, R: 1/64th wheel turn increments from current position.  
  • + is forward, - is backward.  Limits: +/- 93,000 cumulative


drive.speed(L, R)

  • L, R in 1/64th wheel turn increments/second. + is forward, - is backward.
  • Limits: +/- 128

drive.set_acceleration(m, a)

  • m: 0 for speed, 1 for goto, a: 64ths of a turn / s² from 50 to 2000
  • defaults: 600 for speed, 400 for goto

group_io module

Use from group_io import * at the top of program.

io class

io(pinH, pinL).states(pattern)

  • pinH...pinL defines range to set output states.  Rule: 7 >= pinH - pinL >= 0
  • pattern: 0...255 = 0b00000000...0b11111111 is binary output 1/0 states of pinH...pinL, where pinL is lsb.

pattern = io(pinH, pinL).states()

  • pinH...pinL defines range to check.  Rule: 7 >= pinH - pinL >= 0
  • pattern: 0...255 = 0b00000000...0b11111111. 
  • For pins set to output 1 is 3.3 V and 0 is 0 V. 
  • For pins set to input, 1 is above 1.6 V and 0 is below. 
  • The binary value of the lsb corresponds to pinL

io(pinH, pinL).directions(pattern)

  • pinH...pinL defines range to set directions.  Rule: 7 >= pinH - pinL >= 0
  • pattern: 0...255 = 0b00000000...0b11111111 with each binary 1/0 setting the output/input direction of an I/O pin.  pinL is lsb.

pattern = io(pinH, pinL).directions()

  • pinH...pinL defines range to check.  Rule: 7 >= pinH - pinL >= 0
  • pattern: 0...255 = 0b00000000...0b11111111. 
  • The binary value of the lsb corresponds to pinL, and each binary 1 indicates a pin set to output and 0 indicates a bin set to input.

i2c_repeat module

Use from i2c_repeat import * at the top of program.

i2c_repeat class

i2c_repeat(scl, sda).connect()

  • Extends micro:bit I2C bus to a pair of cyber:bot board I/O pins.  
  • scl: 0...15, sda: 0...15

ping module

For PING))) Ultrasonic Distance Sensor (#28015) and LaserPING laser rangefinder (#28041)

Use from ping import * at the top of program.

ping class

dist = ping(pin).distance()
dist = ping(pin).distance(units)

  • pin: 0...15, units: None -> us echo time, ‘in’ -> inches, ‘cm’ -> centimeters

qti module

For the QTI Line Follower AppKit (#28108)

Use from qti import * at the top of program.

qti class

pattern = qti(pinH, pinL).read()

  • pinH...pinL defines a contiguous range of 1 to 8 pins to check.  Rule: 7 >= pinH - pinL >= 0
  • pattern: 0...255 = 0b00000000...0b11111111. 
  • 1 reflection detected, 0 reflection not detected. 
  • The binary value of the lsb corresponds to pinL.

shift module

Use from shift import * at the top of program.

shift class

shift(clk, din).tx(order, bits, data)

  • clk, din: 0..15
  • order: 0 lsb first, 1 msb first
  • bits: 1...32 bit data size
  • data: value to transmit

data = shift(clk, dout).rx(order, bits)

  • clk, dout: 0..15
  • order: 0 msb pre-clock, 1 lsb pre-clock, 2 msb post-clock, 3 lsb post clock. bits: 1...32 bit data size
  • data: value to receive

tv_remote module

Use with the Universal Remote (#020-00001) programmed for Sony protocol

Use from tv_remote import * at the top of program.

ir class

code = ir(pin).remote()

  • pin: 0...15
  • code: SONY 0...9 digits, 11 ENTER, 16 CH_UP, 17 CH_DN, 18 VOL_UP, 19 VOL_DN, 20 MUTE, 21 PWR, 51 R, 52 L, 53 UP, 54 DN, 59 PREV_CH