Skip to content
A Python library to help control a Picoh Robot. Includes text to speech, led matrix control, sensor reading and setting base colour.
Python
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.images update Sep 17, 2019
Docs Update VoiceDoc_Pi.md Sep 21, 2019
examples Update simpleMouseAndKeyboard.py Sep 21, 2019
picoh updated Sep 17, 2019
tools Merge branch 'master' of https://github.com/ohbot/picoh-python Sep 17, 2019
.gitignore update Sep 11, 2019
MANIFEST added playsound function Sep 14, 2019
README.md Update README.md Sep 21, 2019
_config.yml Add files via upload Aug 29, 2019
setup.cfg Add files via upload Aug 29, 2019
setup.py update Sep 17, 2019

README.md

Picoh for Python

Choose your platform and click the links to get started!

macOS Getting Started Examples Text to speech documentation
Windows Getting Started Examples Text to speech documentation
Pi Getting Started Examples Text to speech documentation

If you are new to Python here is a short guide explaining some of the key concepts: Programming Picoh in Python

To be expanded soon!

picohData Folder

The first time you run a Picoh program a new folder called picohData is created in your working directory. This folder is used to store various files that you can read from within your Picoh programs, these include a SpeechDatabase file, a Motor Definitions file and an EyeShapes file.

There are a various tools you can use to help edit these data files. When using a tool please download it and save it in the same folder as the your Picoh program file, this will ensure it is reading and writing to the correct folder.

The data files include:

  • Ohbot.obe - Containing eye shape patterns for Picoh's matrix display edited with the Eyeshape Designer Tool. Eye shapes are accessed in Picoh programs using picoh.setEyeShape(), see below for examples.

  • picohspeech.csv - Holds phrases for Picoh to say. Edit using the Speech Database Tool. Phrases are accessed using picoh.getPhrase(), see below for more information.

  • MotorDefinitionsPicoh.omd - Holds motor minimums, maximums and ranges. Modified using the Calibrate Tool. Just calibrates the lip for now but will soon be able to calibrate all motors.

  • Sounds/... - A folder that can be accessed using the picoh.playSound() function. See the lightAndSounds example for more information. The picoh library copies 5 sounds to get you started, add your own by putting move sound files in the sounds folder. .wav's only for now. Preloaded sounds are: 'spring', 'smash', 'loop', 'ohbot' and 'fanfare'

If you delete a file in picohData (or the whole folder) the default files will be copied back over from the picoh library folder.

You can share the picohData between multiple programs by saving them in the same folder.

For example:

picohProgramsFolder
│   picohTest1.py
|   picohTest2.py
│   EyeShapeDesigner.py 
|   SpeechDatabse.py 
│   Calibrate.py   
|
└───picohData (Created Automatically)
    |   Ohbot.obe
    |   MotorDefinitionsPicoh.omd
    |   picohspeech.csv
    └───Sounds/...

Alternatively you can have seperate picohData folders by saving your programs in different folders, you will need a copy of the tools you want to use in the folder as well:

picohProgramsFolder
└───folderOne
│   │   picohTest1.py
│   │   Calibrate.py 
│   │   EyeShapeDesigner.py
|   |   SpeechDatabase.py
|   |   
│   └───picohData (Created Automatically)
│       |   Ohbot.obe
│       |   MotorDefinitionsPicoh.omd
│       |   picohspeech.csv
|       └───Sounds/...
|
└───folderTwo
    │   picohTest2.py
    │   Calibrate.py 
    │   EyeShapeDesigner.py
    |   SpeechDatabase.py
    |   
    └───picohData (Created Automatically)
        |   Ohbot.obe
        |   MotorDefinitionsPicoh.omd
        |   picohspeech.csv
        └───Sounds/...
        

Functions

picoh.init(portName)

Called internally looking for a port with name containing "USB Serial Device" 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. This is likely with Operating Systems in languages other than English.

picoh.move(m, pos, speed=5, eye =0)

Name Range Description Default
m 0-6 (int) Motor Number -
pos 0-10 (int) Desired Position -
speed 0-10 (int) Motor Speed 5
eye 0-2 (int) Eye to move. 0 - Both, 1 - Right, 2 - Left 0 (Both)

For Example:

picoh.move(1,7)

or

picoh.move(2,3,1) 

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

picoh.move(picoh.EYETURN,3) 

to move just one eye

picoh.move(picoh.EYETURN,2, eye = 1) 

Motor index reference:

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

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

Name Range Description Default
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:

picoh.say('Hello I am Picoh')

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

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

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

More info on speech

Platform specific documentation for setting voices and languages:

picoh.wait(seconds)

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

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

For Example:

picoh.wait(2)

picoh.wait(0.5)

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

For Example:

picoh.move(1,7,2)

picoh.wait(2)

picoh.move(1,4,2)

picoh.setEyeShape(shapeNameRight,shapeNameLeft)

shapeNameRight: String - Eyeshape name. shapeNameLeft: String - Eyeshape name.

Use picoh.setEyeShape() to change the shape of pixels displayed on Picoh's matrix display. To see available eye shapes and design your own have a look at the EyeShape designer tool.

For Example:

picoh.setEyeShape("Glasses")

or set pupils to different shapes using:

picoh.setEyeShape("Sad","Angry")
picoh.wait(1)
picoh.setEyeShape("Large","Heart")

Default options for eye shapes:

"Angry", "BoxLeft", "BoxRight", "Crying", "Eyeball", "Glasses", "Heart", "Large", "Sad", "SmallBall", "Square", "SunGlasses", "VerySad"

picoh.setEyeBrightness(val)

Name Range Description
val 0-10 (int or float) Desired Brightness

Use picoh.setEyeBrightness() to change the brightness of the pixels on Picoh's matrix display.

For Example:

picoh.setEyeBrightness(3)
picoh.wait(1)

or loop set in a loop:

for x in range(0,10):
    picoh.setEyeBrightness(x)
    picoh.wait(0.2)

picoh.getPhrase(set,variable)

set: Int - The desired set for phrase. variable: Int - The desired variable for phrase.

Use picoh.getPhrase() to retrieve a phrase from Picoh's speech database.

You can view and edit the speech database using the Speech Databse tool. Each entry in the speech database has a set and a variable associated with it. When you use getPhrase() you can choose to get phrases with specific values for set and/or variable.

If more than one phrase matches the set and variable provided a random match is returned.

To see available phrases and write your own see the Speech Database Tool.

For Example:

picoh.say(picoh.getPhrase(1,2))

or get a random phrase from a specific set:

picoh.say(picoh.getPhrase(set=1)))
# Picoh will say a random phrase from set 1.

picoh.say(picoh.getPhrase(variable=2))
# Picoh will say a random phrase with variable = 2.

or get a random phrase from the whole database:

picoh.say(picoh.getPhrase())

picoh.baseColour(r, g, b)

Set the colour of Picoh’s eyes.

Name Range Description Default
r 0-10 (int) Red -
g 0-10 (int) Green -
b 0-10 (int) Blue -

For Example:

picoh.baseColour(2,3,8)

picoh.reset()

Resets Picoh's motors and matrix back to rest positions and turns off Picoh's base LEDs. Useful to start programs with this. You may need an picoh.wait() after this to give time for the motors to move.

For Example:

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

picoh.close()

Call to detach all Picoh's motors which stops them using power, you can call picoh.attach(m) or picoh.detach(m) for individual motors.

For Example:

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

picoh.close()

picoh.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 = picoh.readSensor(3)

picoh.move(picoh.HEADTURN, reading)

picoh.playSound(sound,untilDone = True)

sound - string name of sound.

untilDone - wait till sound has finished before moving to next line in your program. Defaults to True. This is useful if you want to move Picoh while a sound is playing.

sounds are read from picohData/Sounds/ add new sound files to this folder to access them. .wav files only for the moment. When writing the file name in your program please do not include the .wav file extension.

Some demo sounds will be pre installed:

  • fanfare
  • loop
  • ohbot
  • smash
  • spring

For Example:

picoh.playSound('fanfare')

or

picoh.playSound('spring',False)
You can’t perform that action at this time.