Question:
Python Program Problem?
Cy
2013-04-15 21:23:20 UTC
Keep getting this error message from the program running on a raspberry pi chip. Need some help understanding.

Thanks...


#!/usr/bin/python

import smbus
import time
import subprocess

bus = smbus.SMBus(1)
address = 0x04
pin = 1

pinMode = ""
pinMode += "gpio mode "
pinMode += str(pin)
pinMode += " pwm"

#print pinMode

from subprocess import call
call(pinMode, shell=True)

while True:
data = ""
bashCommand = ""
for i in range(0, 5):
data += chr(bus.read_byte(address));
print data

bashCommand += 'gpio pwm '
bashCommand += str(pin)
bashCommand += ' '
bashCommand += str(data)

call(bashCommand, shell=True)

time.sleep(1)


pi@raspberrypi ~ $ sudo python ./i2cPython2.py
1023
Traceback (most recent call last):
File "./i2cPython2.py", line 33, in
call(bashCommand, shell=True)
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
TypeError: execv() arg 2 must contain only strings
Four answers:
Greywolf
2013-04-16 03:23:49 UTC
You might want to install the WiringPi library, then you can do GPIO directly from a Python program without having to create commands to run in the Bash shell. Much easier to write.



Details here https://projects.drogon.net/raspberry-pi/wiringpi/
satish
2013-04-15 21:50:19 UTC
looks like your execcv doesn't accept numbers as the second argumnet. It has to be string.



when you are calling the bashCommmand

this is actually executed bu the execv system call. whose second argumnet is having problem

my understanding is your command should be

gpio pwm 1

but it is

gpio pwn1 due to missing space, this is giving problem

so replace

bashCommand += 'gpio pwm' with

bashCommand += 'gpio pwm '

just add space
?
2016-11-07 13:35:14 UTC
according to hazard you do have Turtle put in. Did you call the report turtle.py? attempt saving it as xyz.py and run it. you won't be in a position to call the python report as something which you import. while i became messing around with the random module to get random numbers I named my report random.py and have been given the comparable variety of messege.
Nikola
2013-04-17 04:51:37 UTC
Hmm...im not into a programming like you, i could suggest you to try to look for the answer on myraspberry-pi.org , i had saw some things about raspberry and Python...I hope it will be helpful for you..


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...