vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Reg: Python programming

Mon Jun 06, 2016 4:19 am

Hi,
I have to connect 4 servomotors, 2,12v DC motors ,LCD display and 4 sensors to raspberry. Is it possible to program everything in a single python file. Can anyone suggest a good method to get this done?

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

Re: Reg: Python programming

Mon Jun 06, 2016 7:57 am

Of course it is possible.

Start off getting one device to work and then add more.

http://elinux.org/RPi_GPIO_Code_Samples#Python

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: Reg: Python programming

Tue Jun 07, 2016 5:05 am

I tried, but I am facing some time delay issues as I have to use "time.sleep()" function in the program multiple times.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Reg: Python programming

Tue Jun 07, 2016 6:16 am

vishnuvkv wrote: Is it possible to program everything in a single python file.
Of course its possible ...

... but you probably don't want to do that. Joan's advice is sound; do that, but also think about this: you may want to control various devices in similar ways using similar naming conventions. If you place the device control header information (function definitions, globals, dictionaries, &c) in separate files then you can have your devices in different 'namespaces' in Python. Examples:

import RPi.GPIO as GPIO

GPIO becomes a namespace. Names within this space can be the SAME as names in other spaces because we're going to qualify with GPIO... GPIO.setup()

import motor_driver as MOTOR

import relay_driver as RELAY1

... you get the idea. Each of those namespaces should be in a separate file:

motor_driver.py

relay_driver.py

&c

You are free to stuff everything in ONE file... but its bad form, and it will cause you difficulties galore as your project becomes non trivial.

marcus
marcus
:ugeek:

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: Reg: Python programming

Tue Jun 07, 2016 9:49 am

Thank you guys :)

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: PWM

Sun Jun 12, 2016 2:38 pm

Hi..
I am using Raspberry pi 2 B+. I need to run a servomotor and a 12Vdc motor at a time and I also need to control the speed of the dc motor so i am using a driver circuit. So both servo and dc motor is using PWM. Is there any problem in running two PWM signals at a time?Because, when I tried to run the motor was not working properly.

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

Re: Reg: Python programming

Sun Jun 12, 2016 2:43 pm

There is no problem in providing multiple PWM from the Pi.

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Writing to a text file

Fri Jun 17, 2016 1:24 pm

Hi...I wrote a number to a text file using the command " f.write(str(number))" and I need to read this number in other .py file and compare that value. How can I do this?? Please help...


vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Threading

Thu Jun 30, 2016 11:32 am

I am a beginer in RPi ,my program is slowing down while using threading. How can this be rectified?
Please help

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Python Program for robotic arm with 3 servo motor.

Fri Jul 01, 2016 9:07 am

Code: Select all

import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(13,GPIO.OUT)
p1=GPIO.PWM(13,50)#base
GPIO.setup(26,GPIO.OUT)
p2=GPIO.PWM(26,50)#side
GPIO.setup(19,GPIO.OUT)
p3=GPIO.PWM(19,50)#top
GPIO.setup(2,GPIO.IN,pull_up_down=GPIO.PUD_UP)#start/stop
GPIO.setup(3,GPIO.IN,pull_up_down=GPIO.PUD_UP)#fault


GPIO.setup(5,GPIO.IN)
scrap_count =0

while True:
   
         a=GPIO.input(2)
         a1=GPIO.input(3)
         a2=GPIO.input(5)
      
       # print a,a1
         if (a==0 and a1==1 and a2==1): 
            
              time.sleep(10)
              p3.start(7)
              time.sleep(1)
              p2.start(10.5)
              time.sleep(1)
              p3.ChangeDutyCycle(10)
              time.sleep(1)
              p2.ChangeDutyCycle(12)
              time.sleep(1)
              p1.start(6)
              time.sleep(1)
              p2.ChangeDutyCycle(10.5)
              time.sleep(1)
              p3.ChangeDutyCycle(7)
              time.sleep(1)
              p2.ChangeDutyCycle(12)
              time.sleep(1)
              p1.ChangeDutyCycle(10)
              time.sleep(1)
              scrap_count=scrap_count+1
              print "Scrap Count = ",scrap_count
              k=open('/home/pi/Hari/text_output_files/arm.txt','w')
              k.write("Scrap Count = "+ str(scrap_count))
          
        else:
           
               p1.stop()
               p2.stop()
               p3.stop()
            
        elif a==1:
           
              scrap_count=0
              k=open('/home/pi/Hari/text_output_files/arm.txt','w')
              k.truncate()
           
As a part of my project , I have writting the above code for a robotic arm with 3 servo motors. Here when the process is stopped and started agian arm is not working properly. How this code can be modified? Please help...I am stucked here.
Last edited by vishnuvkv on Thu Jul 21, 2016 4:31 am, edited 11 times in total.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Reg: Python programming

Fri Jul 01, 2016 9:19 am

Please edit your post to include your script within [ CODE ] markers, using the 'button' at the top of the message edit screen.

Without indentation your While and If blocks are meaningless.

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: Reg: Python programming

Fri Jul 01, 2016 10:17 am

I have edited the post .Please check the code.
Last edited by vishnuvkv on Tue Jul 19, 2016 11:27 am, edited 1 time in total.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Reg: Python programming

Fri Jul 01, 2016 10:47 am

vishnuvkv wrote:I have edited the post .Please check
You can, and should, preview your own post before submitting it. It looks unchanged to me.

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: Reg: Python programming

Sat Jul 02, 2016 6:56 am

B.Goode wrote:
vishnuvkv wrote:I have edited the post .Please check
You can, and should, preview your own post before submitting it. It looks unchanged to me.

Sir,
How to use that

Code: Select all

 makers. I am using this for the 1st time that is why I am asking.

User avatar
bensimmo
Posts: 4622
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Reg: Python programming

Sat Jul 02, 2016 8:09 am


vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

lcd display

Wed Jul 13, 2016 9:05 am

Hi,
I am using a motor driver and 20*4 lcd display. When the motor is started lcd is displaying wrong characters. What may be the reason? please help

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: Reg: Python programming

Tue Jul 19, 2016 11:33 am

vishnuvkv wrote:
B.Goode wrote:
vishnuvkv wrote:I have edited the post .Please check
You can, and should, preview your own post before submitting it. It looks unchanged to me.

Sir,
I have edited the code please check.
Thank you

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: lcd display

Tue Jul 19, 2016 2:14 pm

vishnuvkv wrote:Hi,
I am using a motor driver and 20*4 lcd display. When the motor is started lcd is displaying wrong characters. What may be the reason? please help
The code you have posted does not appear to make any use of an LCD display so this will be impossible to diagnose.

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: lcd display

Wed Jul 20, 2016 4:43 am

B.Goode wrote:
vishnuvkv wrote:Hi,
I am using a motor driver and 20*4 lcd display. When the motor is started lcd is displaying wrong characters. What may be the reason? please help
The code you have posted does not appear to make any use of an LCD display so this will be impossible to diagnose.
Sir,
The code which I have posted is for robotic arm with 3 servo motors. Can u please check on that also? And what may be the reason for printing unwanted characters in LCD display when motor is started? Do I have to post the code?

Thank you

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Running files in background

Thu Sep 01, 2016 5:50 am

Hi,

I will be running two python files in background using "&" operator but I am not able to stop them .Please help.

Thankyou

User avatar
bensimmo
Posts: 4622
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Running files in background

Thu Sep 01, 2016 6:32 am

vishnuvkv wrote:Hi,

I will be running two python files in background using "&" operator but I am not able to stop them .Please help.

Thankyou
Killall python
Should stop all python programmes

Quick search on that and this gives more info
http://www.linfo.org/killall.html

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: Reg: Python programming

Thu Sep 01, 2016 6:50 am

Thank you.

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Re: Running files in background

Thu Sep 01, 2016 6:51 am

[/quote]

Killall python
Should stop all python programmes

Quick search on that and this gives more info
http://www.linfo.org/killall.html[/quote]

Thank you.

vishnuvkv
Posts: 33
Joined: Mon Jun 06, 2016 4:13 am

Date and time

Fri Sep 02, 2016 2:38 pm

Hi,

Do we have to update date and time every time when raspberry is turned on , if we are not using internet connection?

Thankyou

Return to “Python”