tedthetoaster
Posts: 3
Joined: Wed May 17, 2017 4:20 pm

Segmentation Fault

Thu May 18, 2017 1:30 pm

Hello Everyone! I was coding my Raspberry Pi in Python, and I am trying to use Pyo to accomplish this. When I run the code, I get a segmentation fault. Please help.

Code: Select all

# Servo Control
import time
import RPi.GPIO as GPIO
import wiringpi
# use 'GPIO naming'
GPIO.setmode(GPIO.BCM)
# set #18 to be a PWM output
GPIO.setup(18, GPIO.OUT)
# set the PWM mode to milliseconds stype
wiringpi.pwmSetMode(wiringpi.GPIO.PWM_MODE_MS)
# divide down clock
wiringpi.pwmSetClock(192)
wiringpi.pwmSetRange(2000)
delay_period = 0.01
# DO THE PWM SETUP
# pwm = GPIO.PWM(18, 1000)
# pwm.start(50)
#while True:
p = GPIO.PWM(18, 50)

def onPoseEdge(pose, edge):
	if (pose == "fist") and (edge == "on"): 
		GPIO.output(18, GPIO.HIGH)
	pwm = GPIO.PWM(18, 1000)
	p.start(7.5)

	if (pose == "fingersSpread") and (edge == "on"): 
		GPIO.output(18, GPIO.LOW)
	pwm = GPIO.PWM(18, 1000)
	p.start(2.5)
	

#def onPoseEdge(pose, edge):
#	if myo.title_contains("YouTube"):
#		if (pose == "waveOut") and (edge == "on"): 
#			myo.keyboard("right_arrow","press","")
#		if (pose == "waveIn") and (edge == "on"): 
#			myo.keyboard("left_arrow","press","")
#		if (pose == "fist") and (edge == "on"): 
#			myo.keyboard("space","press","")

Thank You,

Ted

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

Re: Segmentation Fault

Thu May 18, 2017 6:30 pm

Welcome to the forums.

In the absence of any more skilled response to your question -

It isn't my area of expertise (some unkind people might suggest I don't have one... ) but my counter-question would be to ask whether you have any documentation that indicates that hybrid use of the RPi.GPIO and wiringpi libraries is supported as you are attempting?

I wonder if using either one or the other might give you clearer diagnostics?

User avatar
davef21370
Posts: 874
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: Segmentation Fault

Fri May 19, 2017 4:27 pm

I'll go with B.Goode's suggestion that mixing the libraries could be the problem. Could you post the error in full?

Dave.
Apple say... Monkey do !!

User avatar
DougieLawson
Posts: 29337
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

Re: Segmentation Fault

Sun May 21, 2017 1:49 pm

Who's code gets the segfault? Where did you get the python library for WiringPi? What version of WiringPi is installed?

That's aside from the problem of mixing library functions.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

Since 2012: 1B*5, 2B*2, B+, A+, Zero*2, 3B*3

Please post ALL technical questions on the forum. Do not send private messages.

tedthetoaster
Posts: 3
Joined: Wed May 17, 2017 4:20 pm

Re: Segmentation Fault

Sun May 21, 2017 7:33 pm

davef21370 wrote:I'll go with B.Goode's suggestion that mixing the libraries could be the problem. Could you post the error in full?

Dave.
B.Goode wrote:Welcome to the forums.

In the absence of any more skilled response to your question -

It isn't my area of expertise (some unkind people might suggest I don't have one... ) but my counter-question would be to ask whether you have any documentation that indicates that hybrid use of the RPi.GPIO and wiringpi libraries is supported as you are attempting?

I wonder if using either one or the other might give you clearer diagnostics?
The only thing that it says when I try to run the code is Segmentation fault.

I attached an image of when the error occurs - I highlighted in red something that may be causing the problem, but I am unsure. The black boxes are for privacy concerns
Attachments
IMG_3734_opt.jpg
IMG_3734_opt.jpg (14.15 KiB) Viewed 441 times

AshPowers
Posts: 76
Joined: Thu Apr 20, 2017 12:10 am
Location: Ormond Beach, FL
Contact: Website

Re: Segmentation Fault

Mon May 22, 2017 7:55 pm

I just recently went through this. In Python, go to Build, Set Build Components. In the Execute entry at the bottom, add "sudo" at the front of the other text in the window to it's right.

Seems that you need superuser privileges to run most programs..

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

Re: Segmentation Fault

Tue May 23, 2017 10:27 am

AshPowers wrote:I just recently went through this. In Python, go to Build, Set Build Components. In the Execute entry at the bottom, add "sudo" at the front of the other text in the window to it's right.

Seems that you need superuser privileges to run most programs..
There seem to be some misunderstandings here.

The python interpreter, if run interactively, is a command line application. It does not itself have a graphical interface, so there is no opportunity to make the configuration changes you suggest.

You might be forgiven for confusing the IDLE IDE with the python interpreter since 'python' is the name that the Raspberry Pi interface designers have given to the menu entry for IDLE on the Raspbian desktop. But the IDLE IDE does not have a Build - Set Build Components - Execute option available in its menu system.

" Build - Set Build Components - Execute" looks as though it may be related to the Geany editor.
Seems that you need superuser privileges to run most programs.
On the contrary - it should rarely, if ever, be necessary to run a python script with root/superuser privileges. In particular, Raspbian does not require 'sudo' for a python script to be able to access the gpio pins of an RPi.

tedthetoaster
Posts: 3
Joined: Wed May 17, 2017 4:20 pm

Re: Segmentation Fault

Tue May 23, 2017 12:45 pm

Thank you everyone for your help, it was very well appreciated.

But another problem has come up. The only problem was that I had an indentation error after the if statements - I needed to indent ALL of the information after the if statement, not just the line following.

Now I have encountered another problem. I am not exactly sure how to move the servo for a longer set amount of time.

Would I adjust the p.start command?

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

Re: Segmentation Fault

Tue May 23, 2017 4:22 pm

I am not exactly sure how to move the servo for a longer set amount of time.
I might be misunderstanding, but isn't the point of a servo that it can be commanded to move to a selected angular position? How long it takes to get there will be a function of the speed of the servo motor itself and the angle through which it has to rotate.

If your intention is to use pwm from python to control a 'hobby' servo you will probably find it simpler to use one of the libraries already written for that task, such as pigpio. http://abyz.co.uk/rpi/pigpio/python.html

Return to “Python”

Who is online

Users browsing this forum: No registered users and 13 guests