The main ohbot-python library now supports Mac so this version is deprecated. All future development will be on ohbot-python.
These instructions allow you to program your Ohbot using Python on a Mac.
More information about Ohbot can be found on ohbot.co.uk.
Install the latest version of Python from here.
Open the Terminal app and type the folloing:
sudo pip3 install ohbotMac
You can find the Terminal app by searching for it in spotlight.
The pip3 install ohbotMac
command will install the following libraries:
Library | Use | Terminal command to install | Link |
---|---|---|---|
ohbotMac | Interface with Ohbot | pip3 install ohbotMac |
ohbot |
serial | Communicate with serial port | pip3 install pyserial |
pyserial |
lxml | Import settings file | pip3 install lxml |
lxml |
playsound | Play sound files | pip3 install playsound |
playsound |
pyobjc | Python Objective C library | pip3 install objc |
pyobjc |
To upgrade to the latest version of the library run the following in the console:
sudo pip3 install ohbotMac --upgrade
Ohbot library files (these will be installed with the sudo pip3 install ohbotMac
command above):
File | Use |
---|---|
ohbot.py | Ohbot package |
MotorDefinionsv21.omd | Motor settings file |
Note: The text to speech module will generate an audio file, ‘ohbotspeech.wav’ and a text file ‘phonemes.txt’ inside your working folder.
Required:
Setup:
Plug the middle of USB Y cable into the PC and the other large USB plug into the power adaptor. Then plug the mini USB into Ohbot. (Note with newer devices the power adaptor may not be required.)
Open IDLE from Applications.
Select New from the File menu.
Go to the hellworldohbot example on Github, copy the code and paste it into the new Python window.
Select Run Module from the Run menu.
Ohbot should speak and move.
More example programs can be found here.
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 a versions of OSX in languages other than English.
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 |
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:
ohbot.say('Hello I am Ohbot')
ohbot.say('Goodbye',False,False)
ohbot.say('Goodbye',False,False,True)
ohbot.say('Goodbye',soundDelay = 0.3)
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)
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)
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)
...
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()
Seconds - float or int required wait time. ohbot.wait(1.5)
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)
Allows override of default OSX say command.
Use ohbot.setVoice() to set the voice:
For Example:
ohbot.setVoice("Oliver")
ohbot.say("Hello this is Oliver")
ohbot.setVoice("Kate")
ohbot.say("Hello this is Kate")
Available voices can be found in System Preferences -> Accessibility -> Speech in the System Voice Menu. Click customize to view voices in other languages.
A full list of voices can also be displayed by entering the following command in Terminal:
say -v ?
Use ohbot.speechSpeed() to set speech rate in words per minute:
Range: (int) 90+
For Example:
ohbot.setVoice("Oliver")
ohbot.speechSpeed(90)
ohbot.say("Hello this is Oliver Slow")
ohbot.speechSpeed(400)
ohbot.say("Hello this is Oliver Fast")