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 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

piborg's picture

The error is that the 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
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 script into the same directory

This is the easiest to understand. Simply copy the 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.

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.

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 :)

Subscribe to Comments for "Import error message"