Error message when run sample code

I’m trying to do programming, and firstly I try to run this samples code,( and then My motor wouldn’t rotate, and I got some error message.

That is;
When I push run,

Traceback (most recent call last):
packages/serial/”,line 265,
in open
Self self.portstr, os0_RDWR |
os.0_NOCTTY | os.0_NONBLOCK)
PermissionError: [errno 13] permission denied:

And I can’t figure out how to fix the problem….

I’ll paste sample code which I use to make sure below:

from BrickPi import * #import file to use BrickPi operations
roller =PORT_A
arm= PORT_B
BrickPiSetup() #setup the serial port for communication
BrickPi.MotorEnable[roller] = 1 #Enable the Motor A
BrickPi.MotorEnable[arm] = 1 #Enable the Motor B
BrickPiSetupSensors() #Send the properties of sensors to BrickPi

while True:
#Move the roller to bring up the page
BrickPi.MotorSpeed[roller] = -speed_roller
ot = time.time()
while(time.time() - ot < t1):
time.sleep(.1) # sleep for 100 ms

BrickPi.MotorSpeed[roller] = -50
BrickPi.MotorSpeed[arm] = speed_arm  

#Rotate the arm to flip the page and stop at the initial position
while True:
		BrickPi.MotorSpeed[arm] = -85
		BrickPi.MotorSpeed[arm] = 0
	time.sleep(.01)              # sleep for 100 ms

#Move the roller to bring pages down
BrickPi.MotorSpeed[roller] = 60
BrickPi.MotorSpeed[arm] = 0  
ot = time.time()
while(time.time() - ot < 3):    #running while loop for 3 seconds
	BrickPiUpdateValues()       # Ask BrickPi to update values for sensors/motors
	time.sleep(.1)             # sleep for 100 ms
1 Like

Sorry - I don’t understand “push run”.

Typically, when I see Permission Denied when running a Python program, I try running the the program by typing “sudo” in front of the command to run the program:

sudo python
1 Like

What operating system are you using?

Are you running as the “pi” user?

I can’t speak for the brick-Pi, but most, (if not all), of the Dexter Industries software/operating systems expect you to be the “pi” user.  Others have tried running this stuff as a different user and had nothing but problems.

1 Like

I’m afraid, do you meant to open terminal ( looks like command prompt) and type Sudo Python ?

I tried that and replied ;
Python: can’t open file ‘’ : [errno 2] no such file or directory

But I don’t understand because I have my Python file on the desktop for sure…. It says no such file…

1 Like

I’m using vnc .
And sorry for my foolishness,
I don’t know what pi user is. I’ll try to find out , but i never asked an password and username while I enter to VNC.
so, how can I running as a pi user??
Sorry to ask so basic question but I’m really in trouble I hope you to help me…


Yes, to use sudo the command must be issued from a terminal. When you open a terminal it will usually open in the user’s home directory.

To find out what user you are, type “whoami”. Most of the time on Raspberry Pi, the user is “pi”

$ whoami

To see what “working directory” your terminal is currently, type “pwd” (stands for print working directory):

$ pwd

To see what subfolders exist, and to find your program you created “on the desktop”, list the files and subfolders of the current working directory:

$ ls
Bookshelf  Desktop  di_update  Downloads   Public   Scratch  Templates  Videos
Dexter   Documents  ipcount    ip.number    Music   Pictures   sdcard_expansion  usb_disk

So the current working directory is /home/pi and the Desktop is a subfolder (/home/pi/Desktop) and your should be in the Desktop subfolder. Look for it by listing the files of the Desktop:

(assuming pwd returned /home/pi)
$ ls Desktop
... ...

In order to run we need to either change the working directory to be the Desktop, or copy the file from the desktop to the current directory.

Changing to the Desktop will probably work best for you:

To change the working directory to the Desktop folder, we use “cd” (stands for change directory):

(again assuming the terminal opened in /home/pi)
$ cd Desktop
$ pwd
$ ls
... ...

So now that the terminal working directory contains the file we want to run, we can execute our command with sudo:

$ sudo python

Hopefully this will get you a little further along.

1 Like

I’m so grateful for your quick reply…!
And I allowed all of you instruction, and it seems worked perfectly ( cause it really same as your instruction) until in the end, while I typed $ sudo python,
Then it reply with new error message!
It says;
Traceback (most recent call last):
File “”,line 29, in
If (BrickPi.Encoder[arm]-init_pos>710):
TypeError: unsupported operand type (s) for -: ‘NoneType’ and ‘NoneType’

…the directory has changed to desktop and I have no idea is this about any error on the programming code?

Sorry to ask you frequently…
I don’t really get this error message…

1 Like

It is trying to tell you that BrickPi.Encoder[arm] did not return a number here or before when saved in init_pos.

Start by printing out the value of init_pos and try to find out why the encoder value is not being returned or is not a number.

1 Like

Thank you for explaining.
I’m totally new to python and not to good in coding…
I take a look at my code and , find this line,

While true :
If (BrickPi. Encoder[arm]-init_pos>710);
BrickPi.MotorSpeed[arm]= -85
BrickPi.MotorSpeed[arm] = 0

And I think it’s refer to the error message.

And I browse ( about None) and find the article say, The sole value of the type NoneType. None is frequently used to represent the absence of a value, as when default arguments are not passed to a function. Assignments to None are illegal and raise a SyntaxError.

But, this leave me wondering, where can I put value?
How to printing out the value of init_pos?

1 Like

Spend an hour learning the basics of Python. Invest in yourself.

1 Like

When Python throws an error, there is usually both an error message and a “traceback” containing a lot of useful data.

Can you capture and send the entire error and traceback?

@cyclicalobsessive is absolutely correct.

Any programming language is a tool you need to learn how to use.

What is your native language and where are you from?

Depending on where you live, it might be possible to get books on Python in your native language, which will make understanding Python much easier for you.

You also need to learn how to use the programming tools, (like Thonny or Geany), as they have features that will allow you to understand exactly what the problem might be.

I have a suggestion for you:

Is it possible for you to stop working on your robot for a while?

It would be very helpful if you can just hook up a Raspberry Pi by itself, (in a case is best), and just practice using and programming the Raspberry Pi?

There are a number of good “beginner” books for the Raspberry Pi.  Unfortunately all the ones that I know of are in English, but it is very possible that good books exist in your native language as well.

See what you find and ask any questions you want, even if it’s not exactly about your robot.
:+1: :wink:

1 Like