Quantcast
Viewing all articles
Browse latest Browse all 4897

Automation, sensing and robotics • Re: Wiring multiple photoelectric sensors to RPI 4

Your code is wrong to set the GPIO.

If sensorPinWRoll,sensorPinRoll, sensorPinWRotate and sensorPinRotate are all the output of the sensor then you should set them All in input mode.

And like I said earlier, the output Is NPN this mean that the sensor only short to ground for signal! it can't pull the signal to 3.3V.
you need pull-up.

So Set All sensors GPIO to INPUT with internal pull up at least.

Code:

void motorController::initializeRoll(){    qDebug() << "Initialize roll() called!";    QString motorUsed = "roll";    setDirection(clockwise, directionPinNegRoll, directionPinPosRoll);    gpioSetMode(sensorPinWRoll,PI_INPUT);    gpioSetMode(sensorPinRoll, PI_INPUT);    gpioSetPullUpDown(sensorPinWRoll, PI_PUD_UP);    gpioSetPullUpDown(sensorPinRoll, PI_PUD_UP);         //// and on       void motorController::initializeRotate() //This correlates to Wrist/Rotate motors.{    qDebug() << "Initialize rotate() called!";    QString motorUsed = "rotate";    setDirection(clockwise, directionPinNegRotate, directionPinPosRotate);    gpioSetMode(sensorPinWRotate, PI_INPUT);    gpioSetMode(sensorPinRotate, PI_INPUT);    gpioSetPullUpDown(sensorPinWRotate, PI_PUD_UP);    gpioSetPullUpDown(sensorPinRotate, PI_PUD_UP);            

I've switched it in the code. Thanks for that!

I'm having difficulty figuring out where to put the pull-up resistors in my diagram while referencing the sensor diagram that danjperron referenced. Are they supposed to be between the output (white) wires and the GPIO input pin? Or am I supposed to connect the 5V pin to a resistor to the sensor V+ wire?

Additionally, is the wire that is connected from the 5V pin to the terminal block in the right place? I'm trying to reference tutorials, and am unsure if that wire needs to go from 5V to another input pin?

Statistics: Posted by dij0nmustard — Thu Mar 07, 2024 6:38 pm



Viewing all articles
Browse latest Browse all 4897

Trending Articles