Toran
12.09.2019, 14:45
Hallo Zusammen,
derzeit bin ich dabei einen Roboter zu programmieren. Das Steuerelement des Roboters ist ein Raspberry Pi Zero W. Damit ich genügend GPIOS bekomme habe ich zwei MCP23017 gekauft. Diese anzusteuern funktioniert allerdings noch nicht so gut. Ich verstehe nicht was mein Fehler ist, kann mir jemand dabei helfen? An den MCPs sind nur Drehwinkelgeber angeschlossen, die ausgelesen werden müssen. Wenn ich den Code ausführe und die Drehgeber bediene, wird nach wie vor eine 1 ausgegeben (pull up)
Grüße,
Thomas
#include <stdio.h>
#include <stdlib.h>
#include <pca9685.h>
#include <wiringPi.h>
#include <mcp23017.h>
void setup()
{
wiringPiSetup(); //setup of wiringPi lib
mcp23017Setup(PINBASE3,0x20); //setup of mcp23017
mcp23017Setup(PINBASE4,0x70); //setup of mcp23017
pinMode(PINBASE3,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3,PUD_UP); //pull up encoder
pinMode(PINBASE3+1,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3+1,PUD_UP); //pull up encoder
pinMode(PINBASE3+2,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+2,PUD_UP); //pull up encoder
pinMode(PINBASE3+3,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+3,PUD_UP); //pull up encoder
pinMode(PINBASE3+4,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+4,PUD_UP); //pull up encoder
pinMode(PINBASE3+5,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+5,PUD_UP); //pull up encoder
pinMode(PINBASE3+6,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+6,PUD_UP); //pull up encoder
pinMode(PINBASE3+7,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+7,PUD_UP); //pull up encoder
pinMode(PINBASE3+8,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+8,PUD_UP); //pull up encoder
pinMode(PINBASE3+9,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+9,PUD_UP); //pull up encoder
pinMode(PINBASE3+10,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+10,PUD_UP); //pull up encoder
pinMode(PINBASE3+11,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+11,PUD_UP); //pull up encoder
pinMode(PINBASE3+12,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+12,PUD_UP); //pull up encoder
pinMode(PINBASE3+13,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+13,PUD_UP); //pull up encoder
pinMode(PINBASE3,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3,PUD_UP); //pull up encoder
pinMode(PINBASE3+1,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3+1,PUD_UP); //pull up encoder
pinMode(PINBASE3+2,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+2,PUD_UP); //pull up encoder
pinMode(PINBASE3+3,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+3,PUD_UP); //pull up encoder
pinMode(PINBASE3+4,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+4,PUD_UP); //pull up encoder
pinMode(PINBASE3+5,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+5,PUD_UP); //pull up encoder
pinMode(PINBASE3+6,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+6,PUD_UP); //pull up encoder
pinMode(PINBASE3+7,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+7,PUD_UP); //pull up encoder
pinMode(PINBASE3+8,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+8,PUD_UP); //pull up encoder
pinMode(PINBASE3+9,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+9,PUD_UP); //pull up encoder
pinMode(PINBASE3+10,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+10,PUD_UP); //pull up encoder
pinMode(PINBASE3+11,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+11,PUD_UP); //pull up encoder
pinMode(PINBASE3+12,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+12,PUD_UP); //pull up encoder
pinMode(PINBASE3+13,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+13,PUD_UP); //pull up encoder
pinMode(PINBASE3+14,INPUT); //encoder 2 of leg 3
pullUpDnControl(PINBASE3+14,PUD_UP); //pull up encoder
pinMode(PINBASE3+15,INPUT); //encoder 2 of leg 3
pullUpDnControl(PINBASE3+15,PUD_UP); //pull up encoder
}
int main()
{
setup();
while(1)
{
for(int i=PINBASE3;i<PINBASE3+16;i++)
{
delay(500);
printf("%d) %d\n",i,digitalRead(i));
}
}
}
derzeit bin ich dabei einen Roboter zu programmieren. Das Steuerelement des Roboters ist ein Raspberry Pi Zero W. Damit ich genügend GPIOS bekomme habe ich zwei MCP23017 gekauft. Diese anzusteuern funktioniert allerdings noch nicht so gut. Ich verstehe nicht was mein Fehler ist, kann mir jemand dabei helfen? An den MCPs sind nur Drehwinkelgeber angeschlossen, die ausgelesen werden müssen. Wenn ich den Code ausführe und die Drehgeber bediene, wird nach wie vor eine 1 ausgegeben (pull up)
Grüße,
Thomas
#include <stdio.h>
#include <stdlib.h>
#include <pca9685.h>
#include <wiringPi.h>
#include <mcp23017.h>
void setup()
{
wiringPiSetup(); //setup of wiringPi lib
mcp23017Setup(PINBASE3,0x20); //setup of mcp23017
mcp23017Setup(PINBASE4,0x70); //setup of mcp23017
pinMode(PINBASE3,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3,PUD_UP); //pull up encoder
pinMode(PINBASE3+1,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3+1,PUD_UP); //pull up encoder
pinMode(PINBASE3+2,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+2,PUD_UP); //pull up encoder
pinMode(PINBASE3+3,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+3,PUD_UP); //pull up encoder
pinMode(PINBASE3+4,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+4,PUD_UP); //pull up encoder
pinMode(PINBASE3+5,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+5,PUD_UP); //pull up encoder
pinMode(PINBASE3+6,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+6,PUD_UP); //pull up encoder
pinMode(PINBASE3+7,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+7,PUD_UP); //pull up encoder
pinMode(PINBASE3+8,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+8,PUD_UP); //pull up encoder
pinMode(PINBASE3+9,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+9,PUD_UP); //pull up encoder
pinMode(PINBASE3+10,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+10,PUD_UP); //pull up encoder
pinMode(PINBASE3+11,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+11,PUD_UP); //pull up encoder
pinMode(PINBASE3+12,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+12,PUD_UP); //pull up encoder
pinMode(PINBASE3+13,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+13,PUD_UP); //pull up encoder
pinMode(PINBASE3,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3,PUD_UP); //pull up encoder
pinMode(PINBASE3+1,INPUT); //encoder 1 of leg 1
pullUpDnControl(PINBASE3+1,PUD_UP); //pull up encoder
pinMode(PINBASE3+2,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+2,PUD_UP); //pull up encoder
pinMode(PINBASE3+3,INPUT); //encoder 2 of leg 1
pullUpDnControl(PINBASE3+3,PUD_UP); //pull up encoder
pinMode(PINBASE3+4,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+4,PUD_UP); //pull up encoder
pinMode(PINBASE3+5,INPUT); //encoder 3 of leg 1
pullUpDnControl(PINBASE3+5,PUD_UP); //pull up encoder
pinMode(PINBASE3+6,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+6,PUD_UP); //pull up encoder
pinMode(PINBASE3+7,INPUT); //encoder 1 of leg 2
pullUpDnControl(PINBASE3+7,PUD_UP); //pull up encoder
pinMode(PINBASE3+8,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+8,PUD_UP); //pull up encoder
pinMode(PINBASE3+9,INPUT); //encoder 2 of leg 2
pullUpDnControl(PINBASE3+9,PUD_UP); //pull up encoder
pinMode(PINBASE3+10,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+10,PUD_UP); //pull up encoder
pinMode(PINBASE3+11,INPUT); //encoder 3 of leg 2
pullUpDnControl(PINBASE3+11,PUD_UP); //pull up encoder
pinMode(PINBASE3+12,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+12,PUD_UP); //pull up encoder
pinMode(PINBASE3+13,INPUT); //encoder 1 of leg 3
pullUpDnControl(PINBASE3+13,PUD_UP); //pull up encoder
pinMode(PINBASE3+14,INPUT); //encoder 2 of leg 3
pullUpDnControl(PINBASE3+14,PUD_UP); //pull up encoder
pinMode(PINBASE3+15,INPUT); //encoder 2 of leg 3
pullUpDnControl(PINBASE3+15,PUD_UP); //pull up encoder
}
int main()
{
setup();
while(1)
{
for(int i=PINBASE3;i<PINBASE3+16;i++)
{
delay(500);
printf("%d) %d\n",i,digitalRead(i));
}
}
}