Close

Python script

A project log for Butter Robot

A little rover robot to keep an eye on my prints inspired by the butter passing robot in Rick and Morty.

brambram 07/24/2017 at 07:220 Comments

Blynk pin configuration

The Python script is really simple and the only module you need to install is the Blynk library and ServoBlaster needs to be install in the same directory.

Pin V0 and V1 control the movement of the left motor and pin V2 and V3 control the movement of the right motor. The slider on pin V4 controls the servo in the neck.

The slider in the Blynk app should be setup so it writes on an interval while sliding and not just on release. I set it up to write every 100ms for a smooth movement.

Installing ServoBlaster

Python script

import BlynkLib
import RPi.GPIO as GPIO
import os
import time
os.system("./servod --p1pins=12,16,18")
GPIO.setmode(GPIO.BCM)
GPIO.setup(20, GPIO.OUT)
GPIO.setup(21, GPIO.OUT)
GPIO.setup(19, GPIO.OUT)
GPIO.setup(26, GPIO.OUT)
GPIO.output(20, GPIO.LOW)
GPIO.output(21, GPIO.LOW)
GPIO.output(19, GPIO.LOW)
GPIO.output(26, GPIO.LOW)
BLYNK_AUTH = ''
blynk = BlynkLib.Blynk(BLYNK_AUTH)
@blynk.VIRTUAL_WRITE(0)
def my_write_handler(value):
        if int(value) == 1:
                GPIO.output(19, GPIO.HIGH)
                print("press")
        else:
                GPIO.output(19, GPIO.LOW)
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
        if int(value) == 1:
                GPIO.output(26, GPIO.HIGH)
        else:
                GPIO.output(26, GPIO.LOW)
@blynk.VIRTUAL_WRITE(2)
def my_write_handler(value):
        if int(value) == 1:
                GPIO.output(20, GPIO.HIGH)
                print("press")
        else:
                GPIO.output(20, GPIO.LOW)
@blynk.VIRTUAL_WRITE(3)
def my_write_handler(value):
        if int(value) == 1:
                GPIO.output(21, GPIO.HIGH)
        else:
                GPIO.output(21, GPIO.LOW)
@blynk.VIRTUAL_WRITE(4)
def my_write_handler(value):
        os.system("echo 2=%d  > /dev/servoblaster" % (int(value)))
blynk.run()

Discussions