ImportError: No module named Adafruit_PureIO.smbus

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
HiredGun
 
Posts: 7
Joined: Fri Jan 27, 2023 5:24 pm

ImportError: No module named Adafruit_PureIO.smbus

Post by HiredGun »

Hello

I am following the following Instructables guide (original is in Spanish and I have translated it via Google):

https://www.instructables.com/Sombrero- ... pberry-Pi/

I have followed all of the steps successfully and when I get to the step to execute simpletest.py I get the following error:

Adafruit MPR121 Capacitive Touch Sensor Test
Traceback (most recent call last):
File "simpletest.py", line 34, in <module>
if not cap.begin():
File "build/bdist.linux-armv7l/egg/Adafruit_MPR121/MPR121.py", line 92, in begin
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 66, in get_i2c_device
File "build/bdist.linux-armv7l/egg/Adafruit_GPIO/I2C.py", line 98, in __init__
ImportError: No module named Adafruit_PureIO.smbus

I have performed some Google-ing but am not sure how to proceed. Any help would be greatly appreciated.

Thanks!

User avatar
mikeysklar
 
Posts: 13823
Joined: Mon Aug 01, 2016 8:10 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by mikeysklar »

Does your MPR121 work with the current Adafruit simpletest.py?

Code: Select all

 1# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple test of the MPR121 capacitive touch sensor library.
 5# Will print out a message when any of the 12 capacitive touch inputs of the
 6# board are touched.  Open the serial REPL after running to see the output.
 7# Author: Tony DiCola
 8import time
 9import board
10import busio
11
12# Import MPR121 module.
13import adafruit_mpr121
14
15# Create I2C bus.
16i2c = busio.I2C(board.SCL, board.SDA)
17
18# Create MPR121 object.
19mpr121 = adafruit_mpr121.MPR121(i2c)
20
21# Note you can optionally change the address of the device:
22# mpr121 = adafruit_mpr121.MPR121(i2c, address=0x91)
23
24# Loop forever testing each input and printing when they're touched.
25while True:
26    # Loop through all 12 inputs (0-11).
27    for i in range(12):
28        # Call is_touched and pass it then number of the input.  If it's touched
29        # it will return True, otherwise it will return False.
30        if mpr121[i].value:
31            print("Input {} touched!".format(i))
32    time.sleep(0.25)  # Small delay to keep from spamming output messages.
https://docs.circuitpython.org/projects ... mples.html

User avatar
HiredGun
 
Posts: 7
Joined: Fri Jan 27, 2023 5:24 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by HiredGun »

Thanks for your reply. I went back and repeated the installation steps from the Instructables guide and I think my Python install is actually not correct. When I run the following commands:

Code: Select all

sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus python-pip git
cd ~
git clone https://github.com/tejonbiker/Adafruit_Python_MPR121.git
cd Adafruit_Python_MPR121
sudo python setup.py install
They work but the Python installation gives the following syntax error -- Traceback shown below:

Code: Select all

Traceback (most recent call last):
  File "setup.py", line 14, in <module>
    packages          = find_packages())
  File "/usr/lib/python2.7/dist-packages/setuptools/__init__.py", line 145, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/install.py", line 117, in do_egg_install
    cmd.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 443, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 685, in easy_install
    return self.install_item(None, spec, tmpdir, deps, True)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 732, in install_item
    self.process_distribution(spec, dist, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 777, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 782, in resolve
    replace_conflicting=replace_conflicting
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1065, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1077, in obtain
    return installer(requirement)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 704, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 730, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 915, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1183, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1169, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 253, in run_setup
    raise
  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 166, in save_modules
    saved_exc.resume()
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 141, in resume
    six.reraise(type, exc, self._tb)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 250, in run_setup
    _execfile(setup_script, ns)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 45, in _execfile
    exec(code, globals, locals)
  File "/tmp/easy_install-Va1Xlx/Adafruit_PureIO-1.1.9/setup.py", line 51, in <module>
    
  File "/usr/lib/python2.7/dist-packages/setuptools/__init__.py", line 144, in setup
    _install_setup_requires(attrs)
  File "/usr/lib/python2.7/dist-packages/setuptools/__init__.py", line 139, in _install_setup_requires
    dist.fetch_build_eggs(dist.setup_requires)
  File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 724, in fetch_build_eggs
    replace_conflicting=True,
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 782, in resolve
    replace_conflicting=replace_conflicting
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1065, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1077, in obtain
    return installer(requirement)
  File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 791, in fetch_build_egg
    return cmd.easy_install(req)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 704, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 730, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 915, in install_eggs
    return self.build_and_install(setup_script, setup_base)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1183, in build_and_install
    self.run_setup(setup_script, setup_base, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 1169, in run_setup
    run_setup(setup_script, args)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 253, in run_setup
    raise
  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 166, in save_modules
    saved_exc.resume()
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 141, in resume
    six.reraise(type, exc, self._tb)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 154, in save_modules
    yield saved
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 195, in setup_context
    yield
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 250, in run_setup
    _execfile(setup_script, ns)
  File "/usr/lib/python2.7/dist-packages/setuptools/sandbox.py", line 44, in _execfile
    code = compile(script, filename, 'exec')
  File "/tmp/easy_install-Va1Xlx/Adafruit_PureIO-1.1.9/temp/easy_install-FU_qnX/setuptools_scm-7.1.0/setup.py", line 20
    def scm_version() -> str:
                      ^
SyntaxError: invalid syntax

User avatar
mikeysklar
 
Posts: 13823
Joined: Mon Aug 01, 2016 8:10 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by mikeysklar »

You need to be running python3.

Are you running Pi OS? Maybe an older installation of Pi OS? The current release is Bullseye (release date Sep. 22nd).

1) Make sure you running the latest version of Adafruit CircuitPython.

https://learn.adafruit.com/welcome-to-c ... cuitpython

2) Then install the mpr121 library via pip3.

Code: Select all

sudo pip3 install adafruit-circuitpython-mpr121
https://learn.adafruit.com/adafruit-mpr ... ry-2999004

User avatar
HiredGun
 
Posts: 7
Joined: Fri Jan 27, 2023 5:24 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by HiredGun »

Thanks for your help. Looks like I was using an older version of the OS and am reinstalling the latest version. I will install CircuitPython as directed. Since I am following a guide, it also asks me to close the following GitHub library, do I still need to do that?

https://github.com/tejonbiker/Adafruit_Python_MPR121

Apologies for the newbie questions, am new to Raspberry Pi and thought that following an Instructables guide would be easy!

User avatar
HiredGun
 
Posts: 7
Joined: Fri Jan 27, 2023 5:24 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by HiredGun »

Sorry, one more question re. CircuitPython:

I am using a Raspberry Pi 3B V1.2 and the Adafruit Capacitive Touch HAT but don't see an option for CircuitPython for that board. Do I need a different RPi?

User avatar
mikeysklar
 
Posts: 13823
Joined: Mon Aug 01, 2016 8:10 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by mikeysklar »

The captouch hat still uses the MPR121 so follow this guide in terms of Python/CircuitPython setup:

https://learn.adafruit.com/adafruit-mpr ... cuitpython

I’m not sure what you mean by “close the github library”. I would stick with the Adafruit guide above to get the libraries and sample code going then you can adapt the setup to the instructables project.

User avatar
HiredGun
 
Posts: 7
Joined: Fri Jan 27, 2023 5:24 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by HiredGun »

Sorry, meant "clone" not "close"...silly typo on my part.

Here's what I was able to do:

1) Updated the RPi with the latest OS version successfully
2) Installed CircuitPython successfully
3) Installed mpr121 library successfully
4) Created a sample Python script to test that the HAT is working correctly

One question I have is where do the sample files get installed? In the Instructables link the files get stored in a folder (Adafruit_Python_MPR121) in the root and so I was able to find the example files (even though they didn't work).

With CircuitPython I am not sure where (path) the sample files are stored?

User avatar
HiredGun
 
Posts: 7
Joined: Fri Jan 27, 2023 5:24 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by HiredGun »

My final code is as follows:

Code: Select all

import pygame
import pygame.midi
from time import sleep
import time
import adafruit_mpr121.MPR121 as MPR121
i2c = busio.I2C(board.SCL, board.SDA)
MPR121 = adafruit_mpr121.MPR121(i2c)

notes=[28,29,31,33,35,36,38,40,41,43,45,47,48,50]

def setup_capacitive_hat():
        # Create MPR121 instance.
        cap = MPR121.MPR121()

        # Initialize communication with MPR121 using default I2C bus of device, and
        # default I2C address (0x5A).  On BeagleBone Black will default to I2C bus 0.
        if not cap.begin():
                print ('Error initializing MPR121.  Check your wiring!')
                sys.exit(1)

        # Alternatively, specify a custom I2C address such as 0x5B (ADDR tied to 3.3V),
        # 0x5C (ADDR tied to SDA), or 0x5D (ADDR tied to SCL).
        #cap.begin(address=0x5B)

        # Also you can specify an optional I2C bus with the bus keyword parameter.
        #cap.begin(bus=1)

        #Stop the chip to set a new threshold value 0x00 -> ECR
        cap._i2c_retry(cap._device.write8,0x5E,0x00)

        #I found this threshold works well with medium fruits (like peaches)
        #Change this for your needs
        cap.set_thresholds(50, 10)

        #I will check if the register are written correctly (debug purposes)
        #tth=cap._i2c_retry(cap._device.readU8,0x41);
        #rth=cap._i2c_retry(cap._device.readU8,0x42);
        #print "Touch TH:" + str(tth) + "Release TH: " +str(rth)

        #Start again the ic
        cap._i2c_retry(cap._device.write8,0x5E,0x8F)

        return cap

def midiExample():
# Things to consider when using pygame.midi:
#
# 1) Initialize the midi module with a to pygame.midi.init().
# 2) Create a midi.Output instance for the desired output device port.
# 3) Select instruments with set_instrument() method calls.
# 4) Play notes with note_on() and note_off() method calls.
# 5) Call pygame.midi.Quit() when finished. Though the midi module tries
#    to ensure that midi is properly shut down, it is best to do it
#    explicitly. A try/finally statement is the safest way to do this.
#
        #Not all instruments will work :(, I only tested this
        GRAND_PIANO=0
        CHURCH_ORGAN=19
        GUITAR=25
        DRUMB=115
        SAX=65
        VIOLA=42
        TROMBONE=58

        instrument_array=[GRAND_PIANO,CHURCH_ORGAN,GUITAR,DRUMB,SAX,VIOLA,TROMBONE]
        current_instrument=0

        #Init the pygame system
        pygame.init()

        #Init the pygame midi system
        pygame.midi.init()

        #Setup the output number 2, this is the timidity interface (check the beginning of the file)
        midi_out = pygame.midi.Output(2, 0)

        #Setup the HAT
        cap=setup_capacitive_hat();

        #shift example to the tones (this line have no effect)
        octave=0
        notes_offset=[x+12*octave for x in notes]

        #Here goes the body of the program (loop)
        try:
                midi_out.set_instrument(instrument_array[current_instrument])

        #Main loop to print a message every time a pin is touched.
        print ('Press Ctrl-C to quit.')
        last_touched = cap.touched()

                while True:
                        current_touched = cap.touched()
                        # Check each pin's last and current state to see if it was pressed or released.
                        for i in range(12):
                                # Each pin is represented by a bit in the touched value.  A value of 1
                                # means the pin is being touched, and 0 means it is not being touched.
                                pin_bit = 1 << i
                                # First check if transitioned from not touched to touched.
                                if current_touched & pin_bit and not last_touched & pin_bit:
                                        print '{0} touched!'.format(i)
                                        #Here we will trigger the MIDI tones
                                        if i == 11:
                                                print "Changing instrument"
                                                current_instrument+=1
                                                current_instrument=current_instrument%len(instrument_array)
                                                midi_out.set_instrument(instrument_array[current_instrument])
                                        elif i== 10:
                                                #Increment the tones
                                                print "Octave increased, actual: "+str(octave)
                                                octave+=1
                                                if octave>8:
                                                        octave=8

                                                #We need shut down all the notes before change
                                                #to avoid "hang" notes
                                                for i in notes_offset:
                                                        midi_out.note_off(i,127)
                                                notes_offset=[x+12*octave for x in notes]
                                        elif i==9:
                                                #Do nothing, se need reserve this case for the
                                                #Decrement event
                                                print ""
                                        else:
                                                midi_out.note_on(notes_offset[i],127)

                              # Next check if transitioned from touched to not touched.
                                if not current_touched & pin_bit and last_touched & pin_bit:
                                        print '{0} released!'.format(i)

                                        if i== 9:
                                                #Decrement the tones
                                                print "Octave decremented, actual: "+str(octave)
                                                octave-=1
                                                if octave<0:
                                                        octave=0

                                                #We need shut down all the notes before change
                                                #to avoid "hang" notes
                                                for i in notes_offset:
                                                        midi_out.note_off(i,127)

                                                notes_offset=[x+12*octave for x in notes]
                                        else:
                                        #Here we will stop the midi tones
                                                midi_out.note_off(notes_offset[i],127)
                                # Update last state and wait a short period before repeating.
                        last_touched = current_touched
                        time.sleep(0.1)

        finally:
                del midi_out
                pygame.midi.quit()

midiExample()
When executing the above code, I get the following error:

Code: Select all

  File "/home/pi/Documents/fruit_piano.py", line 108
    print ('Press Ctrl-C to quit.')
    ^
SyntaxError: invalid syntax
Not sure how to proceed and hoping there is a simple fix.

User avatar
mikeysklar
 
Posts: 13823
Joined: Mon Aug 01, 2016 8:10 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by mikeysklar »

Now that you have everything going you can always run 'git clone' for easy access to the example code.

The pip3 install of circuitpython library puts them into your home directory under ~/.local/lib.

Syntax error on line 8 is like the lack of space you have here:

Code: Select all

elif i== 10:
should be:

Code: Select all

elif i == 10:

User avatar
HiredGun
 
Posts: 7
Joined: Fri Jan 27, 2023 5:24 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by HiredGun »

Thanks, I fixed that syntax error and few others but still get the same syntax error in the same location.

Code: Select all

import pygame
import pygame.midi
from time import sleep
import time
import adafruit_mpr121.MPR121 as MPR121
i2c = busio.I2C(board.SCL, board.SDA)
MPR121 = adafruit_mpr121.MPR121(i2c)

notes = [28,29,31,33,35,36,38,40,41,43,45,47,48,50]

def setup_capacitive_hat():
        # Create MPR121 instance.
        cap = MPR121.MPR121()

        # Initialize communication with MPR121 using default I2C bus of device, and
        # default I2C address (0x5A).  On BeagleBone Black will default to I2C bus 0.
        if not cap.begin():
                print ('Error initializing MPR121.  Check your wiring!')
                sys.exit(1)

        # Alternatively, specify a custom I2C address such as 0x5B (ADDR tied to 3.3V),
        # 0x5C (ADDR tied to SDA), or 0x5D (ADDR tied to SCL).
        #cap.begin(address=0x5B)

        # Also you can specify an optional I2C bus with the bus keyword parameter.
        #cap.begin(bus=1)

        #Stop the chip to set a new threshold value 0x00 -> ECR
        cap._i2c_retry(cap._device.write8,0x5E,0x00)

        #I found this threshold works well with medium fruits (like peaches)
        #Change this for your needs
        cap.set_thresholds(50, 10)

        #I will check if the register are written correctly (debug purposes)
        #tth=cap._i2c_retry(cap._device.readU8,0x41);
        #rth=cap._i2c_retry(cap._device.readU8,0x42);
        #print "Touch TH:" + str(tth) + "Release TH: " +str(rth)

        #Start again the ic
        cap._i2c_retry(cap._device.write8,0x5E,0x8F)

        return cap

def midiExample():
# Things to consider when using pygame.midi:
#
# 1) Initialize the midi module with a to pygame.midi.init().
# 2) Create a midi.Output instance for the desired output device port.
# 3) Select instruments with set_instrument() method calls.
# 4) Play notes with note_on() and note_off() method calls.
# 5) Call pygame.midi.Quit() when finished. Though the midi module tries
#    to ensure that midi is properly shut down, it is best to do it
#    explicitly. A try/finally statement is the safest way to do this.
#

        #Not all instruments will work :(, I only tested this
        GRAND_PIANO = 0
        CHURCH_ORGAN = 19
        GUITAR = 25
        DRUMB = 115
        SAX = 65
        VIOLA = 42
        TROMBONE = 58

        instrument_array = [GRAND_PIANO,CHURCH_ORGAN,GUITAR,DRUMB,SAX,VIOLA,TROMBONE]
        current_instrument = 0

        #Init the pygame system
        pygame.init()

        #Init the pygame midi system
        pygame.midi.init()

        #Setup the output number 2, this is the timidity interface (check the beginning of the file)
        midi_out = pygame.midi.Output(2, 0)

        #Setup the HAT
        cap=setup_capacitive_hat();

        #shift example to the tones (this line have no effect)
        octave = 0
        notes_offset = [x+12*octave for x in notes]

        #Here goes the body of the program (loop)
        try:
                midi_out.set_instrument(instrument_array[current_instrument])

        #Main loop to print a message every time a pin is touched.
        print ('Press Ctrl-C to quit.')
        last_touched = cap.touched()

                while True:
                        current_touched = cap.touched()
                        # Check each pin's last and current state to see if it was pressed or released.
                        for i in range(12):
                                # Each pin is represented by a bit in the touched value.  A value of 1
                                # means the pin is being touched, and 0 means it is not being touched.
                                pin_bit = 1 << i
                                # First check if transitioned from not touched to touched.
                                if current_touched & pin_bit and not last_touched & pin_bit:
                                        print '{0} touched!'.format(i)
                                        #Here we will trigger the MIDI tones
                                        if i == 11:
                                                print "Changing instrument"
                                                current_instrument+=1
                                                current_instrument=current_instrument%len(instrument_array)
                                                midi_out.set_instrument(instrument_array[current_instrument])
                                        elif i == 10:
                                                #Increment the tones
                                                print "Octave increased, actual: "+str(octave)
                                                octave+=1
                                                if octave>8:
                                                        octave=8

                                                #We need shut down all the notes before change
                                                #to avoid "hang" notes
                                                for i in notes_offset:
                                                        midi_out.note_off(i,127)
                                                notes_offset=[x+12*octave for x in notes]
                                        elif i == 9:
                                                #Do nothing, se need reserve this case for the
                                                #Decrement event
                                                print ""
                                        else:
                                                midi_out.note_on(notes_offset[i],127)

                                # Next check if transitioned from touched to not touched.
                                if not current_touched & pin_bit and last_touched & pin_bit:
                                        print '{0} released!'.format(i)

                                        if i == 9:
                                                #Decrement the tones
                                                print "Octave decremented, actual: "+str(octave)
                                                octave-=1
                                                if octave<0:
                                                        octave=0

                                                #We need shut down all the notes before change
                                                #to avoid "hang" notes
                                                for i in notes_offset:
                                                        midi_out.note_off(i,127)

                                                notes_offset=[x+12*octave for x in notes]
                                        else:
                                        #Here we will stop the midi tones
                                                midi_out.note_off(notes_offset[i],127)
                                # Update last state and wait a short period before repeating.
                        last_touched = current_touched
                        time.sleep(0.1)

        finally:
                del midi_out
                pygame.midi.quit()

midiExample()


User avatar
mikeysklar
 
Posts: 13823
Joined: Mon Aug 01, 2016 8:10 pm

Re: ImportError: No module named Adafruit_PureIO.smbus

Post by mikeysklar »

The syntax and whitespace look correct to me. Start commenting out the line numbers that are erroring out and the ones just before it (one at a time between test runs). It is probably something silly.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”