Published © CC BY-NC-SA

Corporate Companion

The ultimate business accessory, a robot companion for all your corporate needs. Including inspirational quotes and buzzwords!

BeginnerFull instructions provided12 hours1,410

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Adafruit Mini External USB Stereo Speaker
×1
MG995
×1
Powerbank
×1
Plastic ornament balls
×2
Felt furniture pads
×2
Spraypaint
×1
Popsicle stick
×1
Tie
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian
ttsmp3

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Tape, Duct
Tape, Duct

Story

Read more

Code

Code

Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import json
import RPi.GPIO as GPIO
import time
from random import randint

servoPIN = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(servoPIN, GPIO.OUT)

p = GPIO.PWM(servoPIN, 50)  # GPIO 17 for PWM with 50Hz
p.start(2.5)  # Initialization

try:
    while True:

        p.ChangeDutyCycle(4)

        # Collect all the names of the images in out folder and the amount
        names = [name for name in os.listdir('/home/pi/Desktop/corporate/audio')]
        total = len([name for name in os.listdir('/home/pi/Desktop/corporate/audio')])

        # Generate a random number, -1 because our index start at 0
        random = randint(0, total-1)
        print(total)

        # Fetch the name belonging to this random number
        name = '/home/pi/Desktop/corporate/audio/'+names[random]
        print(name)

        #Play the audio
        os.system('mpg123 ' + name)
        time.sleep(0.2)
        p.ChangeDutyCycle(5)
        sleep = randint(10, 60)
        print(sleep)
        time.sleep(5)

except KeyboardInterrupt:

    p.stop()


		

Credits

Comments