Skip to content
Ohbot module for Python 3 (Pi Version)
Python
Branch: master
Clone or download
Latest commit c847c10 Aug 29, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples Update pico2waveSpeech.py Jun 14, 2018
images Delete Screen Shot 2017-04-16 at 14.34.56.png Apr 16, 2017
ohbot Update ohbot.py Nov 28, 2018
.gitignore Create .gitignore Aug 29, 2019
MANIFEST Update MANIFEST Apr 3, 2017
README.md Update README.md Oct 9, 2018
_config.yml Set theme jekyll-theme-cayman Apr 16, 2017
setup.cfg Rename setup.cfg.txt to setup.cfg Apr 3, 2017
setup.py Update setup.py Nov 28, 2018

README.md

ohbot for python

This package is a starting point for people wanting to use Python 3 to control Ohbot.

More information about Ohbot can be found on ohbot.co.uk

Dependencies

If you don't have pip3 (the python 3 package manager) installed, open terminal and execute the following:

sudo apt-get install python3-pip

Ohbot requires the some libraries to be installed.

To install libraries execute the corresponding terminal commands in your Raspberry Pi terminal:

Library Use Terminal command to install Link
ohbot Interface with Ohbot sudo pip3 install ohbot ohbot
festival Generate text to speech sudo apt-get install festival -
espeak (optional) Generate text to speech sudo apt-get install espeak espeak
pico2wave (optional) Generate text to speech sudo apt-get install libttspico-utils -
lxml Import settings file sudo apt-get install python3-lxml lxml
serial Communicate with serial port Included with Ohbot pyserial
threading Run multiple threads Included in Python 3 -
os Send commands to festival Included in Python 3 -
time Run timers Included in Python 3 -

You only need to install ohbot, lxml and festival, serial should be installed automatically during the install of ohbot.

Additonal voices can be used by installing espeak and pico2wave

Ohbot is tested with Python 3 running on a Raspberry Pi 3 Model B.

To upgrade to the latest version of the library run the following in the console: sudo pip3 install ohbot --upgrade

Ohbot library files (these will be installed with the pip3 install ohbot command above):

File Use
ohbot.py Ohbot package
MotorDefinionsv21.omd Motor settings file

Note: The text to speech module Festival will generate an audio file, ‘ohbotspeech.wav’ and a text file ‘phonemes.txt’ inside your working folder.


Hardware

Required:

  • Raspberry Pi
  • Ohbot
  • USB Y Cable
  • A 5 volt 1 amp USB power supply (for Ohbot)
  • Speakers/headphones with 3.5mm headphone jack

Setup:

Plug the middle of USB Y cable into Raspberry Pi and the other large USB plug into the power adaptor. Then plug the mini USB into Ohbot. Finally plug your speakers into your Raspberry Pi.


Writing Programs

  1. Open Python 3 (IDLE)
  2. Click File → New File
  3. Save your file as a python script (.py) in a new folder called Ohbot somewhere on your Pi.

Import

Make sure you import ohbot at the start of your program.

from ohbot import ohbot

Functions

ohbot.init(portName)

Called internally using portName = "ttyACM" but if your port is different you can call it and override this port name. It returns True if the port is found and opened successfully, otherwise it returns false.

ohbot.move(m, pos, speed=3)

Name Range Description Default
m 0-6 (int) Motor Number -
pos 0-10 (int) Desired Position -
speed 0-10 (int) Motor Speed 3

For Example:

ohbot.move(1,7)

or

ohbot.move(2,3,1) 

or you can use a constant from the library to specify the motor:

ohbot.move(ohbot.EYETURN,3,1) 

Motor index reference:

m 0 1 2 3 4 5 6
constant HEADNOD HEADTURN EYETURN LIDBLINK TOPLIP BOTTOMLIP EYETILT

ohbot.say(text, untilDone=True, lipSync=True, hdmiAudio=False, soundDelay=0)

Name Range Description Defualt
text 'A string with no punctuation' Words to say -
untilDone bool Return when finished speaking True
lipSync bool Move lips in time with speech True
hdmiAudio bool Fixes missing start of phrase when HDMI audio output is being used False
soundDelay float Set to positive if lip movement is lagging behind sound and negative if sound is lagging behind lip movement 0

For Example:

ohbot.say('Hello I am Ohbot')

ohbot.say('Goodbye',False,False)

ohbot.say('Goodbye',False,False,True)

ohbot.say('Goodbye',soundDelay = 0.3)

ohbot.wait(seconds)

Seconds - float or int required wait time. ohbot.wait(1.5)

Name Range Description
seconds float or int Length of wait in seconds

For Example:

ohbot.wait(2)

ohbot.wait(0.5)

Note: It is important to use ohbot.wait() commands between motor sequential commands for the same motor.

For Example:

ohbot.move(1,7,2)

ohbot.wait(2)

ohbot.move(1,4,2)

ohbot.eyeColour(r, g, b, swapRandG=False)

Set the colour of Ohbot’s eyes.

Name Range Description Default
r 0-10 (int) Red -
g 0-10 (int) Green -
b 0-10 (int) Blue -
swapRandG bool swap r and g value for some older Ohbots False

For Example:

ohbot.eyeColour(2,3,8)

or

ohbot.eyeColour(2,3,8,True)

ohbot.reset()

Resets Ohbot’s motors back to rest positions and turns off Ohbot’s eyes. Useful to start programs with this. You may need an ohbot.wait() after this to give time for the motors to move.

For Example:

ohbot.reset()
ohbot.move(1,7,2)
ohbot.wait(1)
ohbot.move(1,1)
...

ohbot.close()

Call to detach all Ohbot’s motors which stops them using power, you can call ohbot.attach(m) or ohbot.detach(m) for individual motors.

For Example:

ohbot.move(1,7,2)
ohbot.wait(1)
ohbot.move(1,1)

ohbot.close()

ohbot.readSensor(sensorNumber)

Name Range Description
sensorNumber 0-6 (int) the pin the sensor is connected to

returns the value as a float 0 - 10.

For Example:

reading = ohbot.readSensor(3)

ohbot.move(ohbot.HEADTURN, reading)

ohbot.setSynthesizer(synth)

synth Full Name
“festival” festival speech
“espeak” espeak speech
“pico2wave” pico2wave speech

For Example:

ohbot.setSynthesizer("espeak")

ohbot.setVoice(voice)

Use ohbot.setVoice() to set the voice synthesizer:

Using ESPEAK

http://espeak.sourceforge.net/commands.html

Name Description
-v followed by a letter code enter 'espeak --voices' in terminal to see what's available
+m1 to m7 male voices
+f1 to f4 remale voices
+croak or whisper tone
-a0 to a200 amplitude
-s80 to s500 speed
-p0 to p99 pitch

Examples:

Command Result
ohbot.setVoice("-ven+croak") English croaky voice
ohbot.setVoice("-vzh+m2 -s26") Chinese male voice, Fast
ohbot.setVoice("-vfr+f1 -p99 -s180") French female whisper voice, medium speed and high pitched

More examples can be found in our espeakVoices example program.

Press fn + f5 to run your program

You can’t perform that action at this time.