Page 1 of 2

Problem with GPIO pins

Posted: Mon Jul 09, 2018 2:56 pm
by DavidAtanasoski
I have been doing some projects recently on my Raspberry Pi 3B. I've made DC motor control in Python using the L293D chip. That went okey. After I've made it in Python, I tried to make it in C/C++. I wrote the code and it compiled successfully , so I run it. The code was running with no problems, but on the GPIO's I didn't receive the signals. I don't know why. After it, I tried the program written in python that was running okey, now I couldn't control DC motor even in Python. I checked every GPIO separately with LED and resistor and it doesn't what to work. Even I reinstall the system, but unfortunately it wasn't successful.

To make it clear I think the problem is not with the code or the wiring the electronics components. It must be something else.

Python code:

Code: Select all

import RPi.GPIO as GPIO
from time import sleep
 
 
try:
	 GPIO.setmode(GPIO.BOARD)
	 
	 Motor1A = 16
	 Motor1B = 18
	 Motor1E = 22
	 
	 
	 GPIO.setup(Motor1A,GPIO.OUT)
	 GPIO.setup(Motor1B,GPIO.OUT)
	 GPIO.setup(Motor1E,GPIO.OUT)
	 
	 while True:
		  
		 print "Raboti"
		 
		 GPIO.output(Motor1A,GPIO.HIGH)
		 GPIO.output(Motor1B,GPIO.LOW)
		 GPIO.output(Motor1E,GPIO.HIGH)
		  
	
except KeyboardInterrupt:
	
	print "Stop"
	GPIO.output(Motor1E,GPIO.LOW)
	GPIO.cleanup()
C/C++ code:

Code: Select all

#include <iostream>
#include <wiringPi.h>

using namespace std;
#define Motor1A 16
#define Motor1B 18
#define Motor1E 22


int main()
{
	//if(wiringPiSetup()==-1)
	//{
	//	cout<<"Setup wiring pi failed";
	//	return 1;
	//}

	wiringPiSetupGpio();

	pinMode(Motor1A,OUTPUT);
	pinMode(Motor1B,OUTPUT);
	pinMode(Motor1E,OUTPUT);


	for(;;)
	{
		printf("OK");

		digitalWrite(Motor1A,HIGH);

		digitalWrite(Motor1B,HIGH);

		digitalWrite(Motor1E,LOW);

		delay(5000);

		digitalWrite(Motor1A,HIGH);

		digitalWrite(Motor1B,LOW);

		digitalWrite(Motor1E,HIGH);

		cout<<" After 5 sec "<<endl;
	}

    return 0;
}
Note: I've tried the python program on different pins and it went OK. The problem is with those 3 pins mentioned in the codes. Also, I've tried the C/C++ program on different pins and now they are not working.

I've tried with * gpio readall * and when i send signal to these pins, the value should be changed to 1, but in my case it isn't. If you have any questions or suggestions please let me know. I need to know if they're permanently damaged or not.

Re: Problem with GPIO pins

Posted: Mon Jul 09, 2018 3:13 pm
by joan
Run wiringPi's pintest or pigpio's gpiotest with nothing connected to the GPIO.

https://elinux.org/R-Pi_Troubleshooting#Testing

Re: Problem with GPIO pins

Posted: Mon Jul 09, 2018 6:38 pm
by DavidAtanasoski
I start the the * gpiotest *, but it closes instantly when it finish, so I can't see what's going on. Can you tell me how to test it properly? I think what means * sudo pigpiod * ? @joan

Re: Problem with GPIO pins

Posted: Mon Jul 09, 2018 9:34 pm
by Z80 Refugee
DavidAtanasoski wrote:
Mon Jul 09, 2018 2:56 pm
To make it clear I think the problem is not with the code or the wiring the electronics components. It must be something else...

...I need to know if they're permanently damaged or not.
Those two sentences are mutually contradictory. If the GPIO pins have been damaged, it is because you have wired them incorrectly.

Re: Problem with GPIO pins

Posted: Mon Jul 09, 2018 9:55 pm
by DirkS
DavidAtanasoski wrote:
Mon Jul 09, 2018 6:38 pm
I start the the * gpiotest *, but it closes instantly when it finish, so I can't see what's going on. Can you tell me how to test it properly?
Open a terminal window and run it from the command line.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 6:50 am
by DavidAtanasoski
DirkS wrote:
Open a terminal window and run it from the command line.
What should i write ? How?

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 6:54 am
by DirkS
DavidAtanasoski wrote:
Tue Jul 10, 2018 6:50 am
DirkS wrote:
Open a terminal window and run it from the command line.
What should i write ? How?
Open a terminal window (Menu / accessories / terminal) and type

Code: Select all

gpiotest

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 9:12 am
by DavidAtanasoski
DirkS wrote: Open a terminal window (Menu / accessories / terminal) and type

Code: Select all

gpiotest
It says: * bash: gpiotest: command not found *

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 9:22 am
by DirkS
DavidAtanasoski wrote:
Tue Jul 10, 2018 9:12 am
DirkS wrote: Open a terminal window (Menu / accessories / terminal) and type

Code: Select all

gpiotest
It says: * bash: gpiotest: command not found *
Follow the link @joan posted above for instructions on testing (viewtopic.php?p=1339021#p1338730)

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 10:11 am
by DavidAtanasoski
Here i have the results, which are bad:

Code: Select all

This program checks the Pi's (user) gpios.

The program reads and writes all the gpios.  Make sure NOTHING
is connected to the gpios during this test.

The program uses the pigpio daemon which must be running.

To start the daemon use the command sudo pigpiod.

Press the ENTER key to continue or ctrl-C to abort...

Testing...
Write 1 to gpio 15 failed.
Pull up on gpio 15 failed.
Write 1 to gpio 16 failed.
Pull up on gpio 16 failed.
Write 0 to gpio 23 failed.
Pull down on gpio 23 failed.
Write 1 to gpio 24 failed.
Skipped non-user gpios: 0 1 28 29 30 31 
Tested user gpios: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 
Failed user gpios: 15 16 23 24 
Are these pins permanently damaged? And what caused it ?

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 10:26 am
by joan
That indicates a permanent failure (assuming nothing was connected to the failing GPIO during the test). The likely cause is connecting more than 3.3V to one of those GPIO.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 11:39 am
by Z80 Refugee
DavidAtanasoski wrote:
Tue Jul 10, 2018 10:11 am
Are these pins permanently damaged?
No reason to think otherwise (I assume you ran the test with nothing connected, as you were instructed).
DavidAtanasoski wrote:
Tue Jul 10, 2018 10:11 am
And what caused it ?
How would we know? We don't know what you've done (deliberately or accidentally). Read this: Beginners Guide to Wiring Things to the GPIO

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 1:09 pm
by DavidAtanasoski
I'm feeling bad now for my Raspberry Pi. I will need to raise money to buy a new one. Poor me.

In fact, I don't know how i damaged, I've just tried to control a DC motor in C++. Everything was connected as same as when I was working in python.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 1:47 pm
by Z80 Refugee
But since you have not given any details of how the motor was connected when it ran in Python, we can't offer an opinion whether it was safe or a ticking time bomb.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 4:35 pm
by DavidAtanasoski
There you have a picture that shows how everything is connected.

Image

By the way, Is there anyone who wants to donate me a Raspberry Pi ? :D

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 5:10 pm
by Z80 Refugee
Bloody pictorials! I read (and understand) circuit diagrams.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 6:05 pm
by Burngate
Z80 Refugee wrote:
Tue Jul 10, 2018 5:10 pm
Bloody pictorials! I read (and understand) circuit diagrams.
I'm with him on that!

I'm not a C-coder, so I could be wrong ...
In your Python code you've selected

Code: Select all

GPIO.setmode(GPIO.BOARD)
But in your C code you've said

Code: Select all

#include <wiringPi.h>
Now, in Python at any rate, GPIO.BOARD means the physical pin numbering - and pins 16, 18 & 20 are the ones your picture uses.

But WiringPi uses a different numbering system, and the pins your picture uses should be 4, 5 & 6

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 6:07 pm
by DavidAtanasoski
There you have, to be precise check this link:

https://business.tutsplus.com/tutorials ... -cms-20051


I have connected everything like this:

GPIO 25–Pin 22 > L293D–Pin 1
GPIO 24–Pin 18 > L293D–Pin 2
GPIO 23–Pin 16 > L293D–Pin 7

On the L293D - Pin 16 I have connected 5V from Raspberry Pi; On the L293D - Pin 8 I have connected 12V power supply for the chip itself. And pins 4, 5, 12, 13 of the chip are connected to ground.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 6:08 pm
by DavidAtanasoski
Burngate wrote:
Tue Jul 10, 2018 6:05 pm

I'm with him on that!

I'm not a C-coder, so I could be wrong ...
In your Python code you've selected

Code: Select all

GPIO.setmode(GPIO.BOARD)
But in your C code you've said

Code: Select all

#include <wiringPi.h>
Now, in Python at any rate, GPIO.BOARD means the physical pin numbering - and pins 16, 18 & 20 are the ones your picture uses.

But WiringPi uses a different numbering system, and the pins your picture uses should be 4, 5 & 6
Can you provide me the whole numbering system of the WiringPi?

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 6:13 pm
by gordon77

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 6:15 pm
by Burngate
Hmm. I did rather let myself in for that one, didn't I?

I've got a spreadsheet with all the GPIOs, what they're called and what they do on the various Pi's, but it's a bit out of date at the moment (every time I get close, they bring out another Pi. Tell them we DON'T need Pi 4!)

Give me half an hour and I'll see what I can do.

EDIT: Gordon's link is even better, so ignore me.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 7:49 pm
by DavidAtanasoski
So, now in my C/C++ code I should write the WiringPi pin number or what?

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 8:00 pm
by FTrevorGowen
DavidAtanasoski wrote:
Tue Jul 10, 2018 4:35 pm
There you have a picture that shows how everything is connected.

Image

By the way, Is there anyone who wants to donate me a Raspberry Pi ? :D
Are you really using 4 x AA cells to power a P3B + the motor? !!! (Or is it an old, early B?)
Trev.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 8:11 pm
by DavidAtanasoski
FTrevorGowen wrote:
Tue Jul 10, 2018 8:00 pm
DavidAtanasoski wrote:
Tue Jul 10, 2018 4:35 pm
There you have a picture that shows how everything is connected.

Image

By the way, Is there anyone who wants to donate me a Raspberry Pi ? :D
Are you really using 4 x AA cells to power a P3B + the motor? !!! (Or is it an old, early B?)
Trev.
Actually no, this is just a picture from the internet. I have Raspberry PI 3B and I'm using 12V adaptor to power the driver/chip.

Re: Problem with GPIO pins

Posted: Tue Jul 10, 2018 9:26 pm
by DavidAtanasoski
Thanks for all the support. I wish that I knew the pin numbering earlier... I permanently damaged 4 GPIO's, now I don't know what I'm gonna do. Is there anyone who wants to donate me a Raspberry PI ? :lol: :lol: