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<br />
sudo apt-get upgrade


 

Python users
Install Wiringpi2

sudo pip install wiringpi2

Load this test program into your PI

<br />
import wiringpi<br />
import math</p>
<p>maxpwm=120<br />
minpwm=75</p>
<p>val = 3.14159 / 180<br />
pwmrange=maxpwm-minpwm</p>
<p>wiringpi.wiringPiSetup()</p>
<p>#set pwm outputs /clock at 50kHz (20us tick)<br />
#range at 1000 ticks (20ms)<br />
wiringpi.pinMode(26, wiringpi.PWM_OUTPUT)<br />
wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)<br />
wiringpi.pwmSetClock(384)<br />
wiringpi.pwmSetRange(1000)</p>
<p>wiringpi.pinMode(23, wiringpi.PWM_OUTPUT)<br />
wiringpi.pwmSetMode(wiringpi.PWM_MODE_MS)<br />
wiringpi.pwmSetClock(384)<br />
wiringpi.pwmSetRange(1000)</p>
<p>while(1):<br />
  for a in range(0, 360, 5):<br />
    x=math.sin(a*val/3)*pwmrange+minpwm<br />
    y=math.cos(a*val/4)*pwmrange+minpwm<br />
    px=x<br />
    py=y<br />
    wiringpi.pwmWrite(26, int(x))<br />
    wiringpi.pwmWrite(23, int(y))<br />
    wiringpi.delay(20)</p>
<p>


 

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

<br />
#2tentacle.c</p>
<p>#include &lt;stdio.h&gt;<br />
#include &lt;wiringPi.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;math.h&gt;<br />
int maxpwm=120;<br />
int minpwm=75;<br />
int pwmrange;<br />
double val;<br />
double x;<br />
double y;<br />
int px;<br />
int py;</p>
<p>void main(void){<br />
val = 3.14159 / 180;<br />
#set range of servos<br />
pwmrange=maxpwm-minpwm;</p>
<p>#initalise Wiring PI<br />
if (wiringPiSetup () != -1){ //using wiringPi pin numbering</p>
<p>  #initilise servos<br />
  pinMode(26, PWM_OUTPUT);<br />
  pwmSetMode(PWM_MODE_MS);<br />
  pwmSetClock(384); //clock at 50kHz (20us tick)<br />
  pwmSetRange(1000); //range at 1000 ticks (20ms)</p>
<p>  pinMode(23, PWM_OUTPUT);<br />
  pwmSetMode(PWM_MODE_MS);<br />
  pwmSetClock(384); //clock at 50kHz (20us tick)<br />
  pwmSetRange(1000); //range at 1000 ticks (20ms)</p>
<p>  #draw shapes with the two servos</p>
<p>  int a;<br />
  while(1){<br />
    for(a=0;a&amp;lt;360*12;a=a+5){<br />
      x=sin(a*val/3)*pwmrange+minpwm;<br />
      y=cos(a*val/4)*pwmrange+minpwm;<br />
      printf(&quot;x:%f-y:%f\n&quot;,x,y);<br />
      px=x;<br />
      py=y;</p>
<p>      pwmWrite(26, x);<br />
      pwmWrite(23, y);<br />
      delay(20);</p>
<p>      }<br />
    }<br />
  }<br />
}<br />

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.