Tentacle Hat Software

Using the latest version of Raspian Stretch or Raspian Stretch Lite

First, make sure your PI is up to date by running

sudo apt-get update[code]
[code]sudo apt-get upgrade

 

Python users
Install Wiringpi2

sudo pip install wiringpi2

Load this test program into your PI

import wiringpi
import math

maxpwm=120
minpwm=75

val = 3.14159 / 180
pwmrange=maxpwm-minpwm

wiringpi.wiringPiSetup()

#set pwm outputs /clock at 50kHz (20us tick)
#range at 1000 ticks (20ms)
wiringpi.pinMode(26, wiringpi.PWM_OUTPUT)
wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
wiringpi.pwmSetClock(384)
wiringpi.pwmSetRange(1000)

wiringpi.pinMode(23, wiringpi.PWM_OUTPUT)
wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)
wiringpi.pwmSetClock(384)
wiringpi.pwmSetRange(1000)

while(1):
  for a in range(0, 360, 5):
    x=math.sin(a*val/3)*pwmrange+minpwm
    y=math.cos(a*val/4)*pwmrange+minpwm
    px=x
    py=y
    wiringpi.pwmWrite(26, int(x))
    wiringpi.pwmWrite(23, int(y))
    wiringpi.delay(20)


 

C users
Install the WiringPi library if you haven’t already
Load this test program into your PI
Compile with gcc -Wall 2tentacle.c -o 2tentacle -lwiringPi -lm

#2tentacle.c

#include <stdio.h>
#include <wiringPi.h>
#include <stdio.h>
#include <math.h>
int maxpwm=120;
int minpwm=75;
int pwmrange;
double val;
double x;
double y;
int px;
int py;

void main(void){
val = 3.14159 / 180;
#set range of servos
pwmrange=maxpwm-minpwm;

#initalise Wiring PI
if (wiringPiSetup () != -1){ //using wiringPi pin numbering

  #initilise servos
  pinMode(26, PWM_OUTPUT);
  pwmSetMode(PWM_MODE_MS);
  pwmSetClock(384); //clock at 50kHz (20us tick)
  pwmSetRange(1000); //range at 1000 ticks (20ms)

  pinMode(23, PWM_OUTPUT);
  pwmSetMode(PWM_MODE_MS);
  pwmSetClock(384); //clock at 50kHz (20us tick)
  pwmSetRange(1000); //range at 1000 ticks (20ms)

  #draw shapes with the two servos

  int a;
  while(1){
    for(a=0;a&lt;360*12;a=a+5){
      x=sin(a*val/3)*pwmrange+minpwm;
      y=cos(a*val/4)*pwmrange+minpwm;
      printf("x:%f-y:%f\n",x,y);
      px=x;
      py=y;

      pwmWrite(26, x);
      pwmWrite(23, y);
      delay(20);

      }
    }
  }
}

Please note that the Tentacle hat uses the same PWM that the audio used on the Raspberry Pi, so you can’t have audio out and the tentacle hat running at the same time.