Published © CC BY-NC-SA

ChatterBox - The Object Translator

A device that makes any object talk! Use with caution...

BeginnerFull instructions provided20 hours619
ChatterBox - The Object Translator

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Powerbank 2A
×1
USB Speaker
×1
Switch
×1
Button
×1
Breadboard (generic)
Breadboard (generic)
×1
Box
×1
Telephone Cord
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1

Software apps and online services

Tinkercad
Autodesk Tinkercad

Hand tools and fabrication machines

Drill / Driver, Cordless
Drill / Driver, Cordless
3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

ChatterBoxBottomPokey

ChatterBoxTopPokey

brace

Code

code.py

Python
import neopixel
import time
import RPi.GPIO as GPIO
import os
import random

GPIO.setmode(GPIO.BCM)

buttonPin = 21
switchPin = 22
GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

import board
pixels = neopixel.NeoPixel(board.D18, 50)

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

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

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

    #Play the audio
    os.system('mpg123 ' + name)
    time.sleep(0.2)

time.sleep(0.1)
pixels.brightness = 100
pixels.fill((255, 255, 255))

while True:

    if GPIO.input(switchPin) == GPIO.HIGH:
        if GPIO.input(buttonPin) == GPIO.HIGH:
            pixels.fill((0, 100, 0))
            playAudio()
        else:
            pixels.fill((255, 255, 255))
    else:
        pixels.fill((0, 0, 0))
        

    time.sleep(0.5)

Credits

Comments