Listing 4
Beispielprogramm für Paul
#include <wiringPiI2C.h>
#include <unistd.h>
#include <stdio.h>
#define I2C_DEVICE 0x40
int left[9][2]= {{300,400}, {250,350}, {200,300},
{350,350}, {300,300}, {250,250},
{400,300}, {350,250}, {300,200}};
int right[9][2]={{300,400}, {250,350}, {200,300},
{350,350}, {300,300}, {250,250},
{400,300}, {350,250}, {300,200}};
int handle;
void eyeLeft(int position){
wiringPiI2CWriteReg8 (handle, 0x6, (left[position][0] & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0x7, ((left[position][0]>>0x08) & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0xA, (left[position][1] & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0xB, ((left[position][1]>>0x08) & 0xFF)) ;
}
void eyeRight(int position){
wiringPiI2CWriteReg8 (handle, 0xE, (right[position][0] & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0xF, ((right[position][0]>>0x08) & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0x12, (right[position][1] & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0x13, ((right[position][1]>>0x08) & 0xFF)) ;
}
void teeth(int position){
wiringPiI2CWriteReg8 (handle, 0x16, (position & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0x17, (position >> 0x08) & 0xFF) ;
}
void neck(int position){
wiringPiI2CWriteReg8 (handle, 0x1A, (position & 0xFF)) ;
wiringPiI2CWriteReg8 (handle, 0x1B, (position >> 0x08) & 0xFF) ;
}
void init(void){
handle = wiringPiI2CSetup (I2C_DEVICE) ;
wiringPiI2CWriteReg8 (handle, 0x00, 0x10) ;
wiringPiI2CWriteReg8 (handle, 0xFE, 0x79) ;
wiringPiI2CWriteReg8 (handle, 0x01, 0x14) ;
wiringPiI2CWriteReg8 (handle, 0x00, 0x00) ;
wiringPiI2CWriteReg8 (handle, 0xFA, 0x00) ;
wiringPiI2CWriteReg8 (handle, 0xFB, 0x00) ;
wiringPiI2CWriteReg8 (handle, 0xFC, 0x00) ;
wiringPiI2CWriteReg8 (handle, 0xFD, 0x00) ;
}
int main (void){
init();
for (int i=0;i<9;i++){
eyeLeft(i);
eyeRight(i);
usleep(500000);
}// for
eyeLeft(4);
eyeRight(4);
teeth(360);//open
sleep(1);
teeth(300);//close
sleep(1);
neck(310);
sleep(2);
neck(360);
sleep(2);
neck(260);
sleep(2);
neck(310);
}// main
Fazit
Paul zum Leben zu erwecken gestaltet sich als ein kurzweiliges Projekt mit hohem Spaßfaktor. Das Beispielprogramm zeigt nur grob, was Paul so alles kann – es lassen sich durchaus komplexere Bewegungsabläufe programmieren. Das PCA9685-Modul steuert bis zu 16 Servos an. Es stellt also kein Problem dar, dem Kopf noch mehr Bewegungsmöglichkeit zu verleihen oder ein komplettes Skelett zum Leben zu erwecken. Es wäre auch möglich, synchron zu den Bewegungen eine Tonspur abzuspielen. Das würde den Eindruck erwecken, dass Paul etwas erzählt.
Insgesamt kann das Projekt als gute Basis für Ihre eigene Halloween-Dekoration dienen. Der Autor wünscht Ihnen auf jeden Fall viel Spaß beim Entwickeln eigener Choreografien für Paul. Hoffen wir, dass im nächsten Jahr wieder ein richtiges Halloween stattfindet. (tle)
Der Autor
Martin Mohr erlebte die komplette Entwicklung der modernen Computertechnik live mit. Nach dem Studium entwickelte er überwiegend Java-Applikationen. Mit dem RasPi erwachte seine alte Liebe zur Elektronik wieder.
Infos
- PCA-Modul: https://www.az-delivery.de/en/products/pca9685-servotreiber
- Kleiner Servo: https://www.az-delivery.de/en/products/mg90s-micro-servomotor
- Großer Servo: https://www.az-delivery.de/en/products/az-delivery-servo-mg996r
- Pauls Körper (Kopf): https://www.amazon.de/Boland-74515-Skelett-ca-160/dp/B007Y4U07S/
- Pauls Augen: https://www.amazon.de/gp/product/B01HZV274I/
- Kardangelenke für Pauls Augen: https://www.amazon.de/gp/product/B08HCS9H2Z/
- Raspberry Pi Imager: https://www.raspberrypi.org/software/
- Datenblatt zum PCA9685: https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf
- Wiring Pi: http://wiringpi.com/reference/i2c-library/
- Paul auf Youtube: https://youtu.be/WJdMMINPbPk





