Import error message

I have been trying to write some python code to manipulate a motor with the PI and ThunderBorg board.
When I try to write an import function to use the ThunderBorg.py file I am met with an error message (see photo attached).
I have expanded the working directory to include the ThunderBorg filepath but this has not made a difference.
I have already gone through the initial installation for Thunder Borg without any problems.

Any suggestions as to how I fix this would be great

Thank you

Images: 
piborg's picture

The error is that the ThunderBorg.py script cannot be found. There are three simple ways to fix this.

1. Change to the ThunderBorg directory

This is the solution you are already trying, the problem is that the path needs to be the ~/thunderborg directory itself.

import os
os.chdir('/home/pi/thunderborg')
import ThunderBorg

Pro: This is probably the simplest solution.
Con: If you need to import other scripts it can get confusing.

2. Add the ThunderBorg directory to the search path

This is my usual choice as I sometimes need the current directory to stay where it is. You can also add multiple directories this way for different imports.

import sys
sys.path.insert(0, "/home/pi/thunderborg")
import ThunderBorg

Pro: Does not change the directory.
Con: The path order matters if you have the same script name in different directories.

3. Copy the ThunderBorg.py script into the same directory

This is the easiest to understand. Simply copy the ThunderBorg.py script into the same directory as the script you are writing.

Pro: No code changes required, just import normally.
Con: There are multiple stored copies of the same script.

Hi,
I have been trying to use the ThunderBorg GUI but it does not load.
Similarly the ThunderBorg is not found in the code I wrote (attached).
Initially I thought that the TunderBorg was not on the right address so I set a new address in the terminal to match with the address suggested by the output code.
However I am still getting an error message.

Images: 
piborg's picture

The default address for ThunderBorg is 21, which is also written as 0x15.

If you change the address number to 21 both the scripts should start working again :)

how do i change the bus

when i do
.runMonsterJoy.sh
its says

loading thunderborg on bus 1, adress 15
missing thunderbord at 15
are you sure its it properly attracted, the correct address is used, and i2c drivers are running
no thunder borg boards found

I have no clue whats wrong

piborg's picture

I have posted a reply on your other thread: No ThunderBorg found

Subscribe to Comments for "Import error message"