DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Problem with GPIO pins

Mon Jul 09, 2018 2:56 pm

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.
Enthusiast.

User avatar
joan
Posts: 14471
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Problem with GPIO pins

Mon Jul 09, 2018 3:13 pm

Run wiringPi's pintest or pigpio's gpiotest with nothing connected to the GPIO.

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

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

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? I think what means * sudo pigpiod * ? @joan
Enthusiast.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Problem with GPIO pins

Mon Jul 09, 2018 9:34 pm

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.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

DirkS
Posts: 10014
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Problem with GPIO pins

Mon Jul 09, 2018 9:55 pm

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.

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

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?
Enthusiast.

DirkS
Posts: 10014
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Problem with GPIO pins

Tue Jul 10, 2018 6:54 am

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

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

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 *
Enthusiast.

DirkS
Posts: 10014
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Problem with GPIO pins

Tue Jul 10, 2018 9:22 am

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)

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 10:11 am

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 ?
Enthusiast.

User avatar
joan
Posts: 14471
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Problem with GPIO pins

Tue Jul 10, 2018 10:26 am

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.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 11:39 am

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
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 1:09 pm

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.
Enthusiast.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 1:47 pm

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.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

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
Enthusiast.

User avatar
Z80 Refugee
Posts: 358
Joined: Sun Feb 09, 2014 1:53 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 5:10 pm

Bloody pictorials! I read (and understand) circuit diagrams.
Military and Automotive Electronics Design Engineer (retired)

For the best service: make your thread title properly descriptive, and put all relevant details in the first post (including links - don't make us search)!

User avatar
Burngate
Posts: 6091
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Problem with GPIO pins

Tue Jul 10, 2018 6:05 pm

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

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 6:07 pm

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.
Enthusiast.

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 6:08 pm

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?
Enthusiast.


User avatar
Burngate
Posts: 6091
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: Problem with GPIO pins

Tue Jul 10, 2018 6:15 pm

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.

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 7:49 pm

So, now in my C/C++ code I should write the WiringPi pin number or what?
Enthusiast.

User avatar
FTrevorGowen
Forum Moderator
Forum Moderator
Posts: 5195
Joined: Mon Mar 04, 2013 6:12 pm
Location: Bristol, U.K.
Contact: Website

Re: Problem with GPIO pins

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.
Still running Raspbian Jessie or Stretch on some older Pi's (an A, B1, B2, B+, P2B, 3xP0, P0W, 2xP3A+, P3B+, P3B, B+, A+ and a B2) but Buster on the P4B's. See: https://www.cpmspectrepi.uk/raspberry_pi/raspiidx.htm

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 8:11 pm

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.
Enthusiast.

DavidAtanasoski
Posts: 46
Joined: Mon Jul 09, 2018 2:37 pm

Re: Problem with GPIO pins

Tue Jul 10, 2018 9:26 pm

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:
Enthusiast.

Return to “Troubleshooting”