0

MCP2221 + PM25 Circuit Python Not Running
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Sun Jan 10, 2021 8:34 pm

Following this tutorial to read the PM2.5 AQ sensor to Python thru MCP2221: https://learn.adafruit.com/pmsa003i/python-circuitpython

Installed Library following setup of MCP2221 to working with Blinka: [url]pip3 install adafruit-circuitpython-pm25[/url]

Have Python 3.7.4 and thought I installed it: see list [img]
Adafruit_list_PM25.JPG
[/img]

Plugged in and added the RST to GPIO 0, error ensured: Why?

Code Error:
Code: Select all | TOGGLE FULL SIZE
  File "A_Sensor_PM25_AQ_R0.py", line 10, in <module>
    from adafruit_pm25.i2c import PM25_I2C
ModuleNotFoundError: No module named 'adafruit_pm25.i2c'; 'adafruit_pm25' is not a package


Adapted for windows with COM4 port:
Code: Select all | TOGGLE FULL SIZE
# pylint: disable=unused-import
import time
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
from adafruit_pm25.i2c import PM25_I2C


reset_pin = None
# If you have a GPIO, its not a bad idea to connect it to the RESET pin
reset_pin = DigitalInOut(board.G0)
reset_pin.direction = Direction.OUTPUT
reset_pin.value = False


# For use with a computer running Windows:
import serial
uart = serial.Serial("COM4", baudrate=9600, timeout=1)

# For use with microcontroller board:
# (Connect the sensor TX pin to the board/computer RX pin)
# uart = busio.UART(board.TX, board.RX, baudrate=9600)

# For use with Raspberry Pi/Linux:
# import serial
# uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.25)

# For use with USB-to-serial cable:
# import serial
# uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25)

# Connect to a PM2.5 sensor over UART
# from adafruit_pm25.uart import PM25_UART
# pm25 = PM25_UART(uart, reset_pin)

# Create library object, use 'slow' 100KHz frequency!
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
# Connect to a PM2.5 sensor over I2C
pm25 = PM25_I2C(i2c, reset_pin)

print("Found PM2.5 sensor, reading data...")

while True:
    time.sleep(1)

    try:
        aqdata = pm25.read()
        # print(aqdata)
    except RuntimeError:
        print("Unable to read from sensor, retrying...")
        continue

    print()
    print("Concentration Units (standard)")
    print("---------------------------------------")
    print(
        "PM 1.0: %d\tPM2.5: %d\tPM10: %d"
        % (aqdata["pm10 standard"], aqdata["pm25 standard"], aqdata["pm100 standard"])
    )
    print("Concentration Units (environmental)")
    print("---------------------------------------")
    print(
        "PM 1.0: %d\tPM2.5: %d\tPM10: %d"
        % (aqdata["pm10 env"], aqdata["pm25 env"], aqdata["pm100 env"])
    )
    print("---------------------------------------")
    print("Particles > 0.3um / 0.1L air:", aqdata["particles 03um"])
    print("Particles > 0.5um / 0.1L air:", aqdata["particles 05um"])
    print("Particles > 1.0um / 0.1L air:", aqdata["particles 10um"])
    print("Particles > 2.5um / 0.1L air:", aqdata["particles 25um"])
    print("Particles > 5.0um / 0.1L air:", aqdata["particles 50um"])
    print("Particles > 10 um / 0.1L air:", aqdata["particles 100um"])
    print("---------------------------------------")
Attachments
Adafruit_list_PM25.JPG
Adafruit_list_PM25.JPG (125.15 KiB) Viewed 158 times

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by adafruit_support_carter on Mon Jan 11, 2021 1:39 pm

Something with your Python setup is not finding the module. Do you get the same thing if you try a simple import from a Python REPL prompt?
Code: Select all | TOGGLE FULL SIZE
import adafruit_pm25

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Thu Jan 14, 2021 2:12 am

Got further except the call for the "PM25_I2C", tried subbing with "adafruit_pm25" and keeping removing the "
Code: Select all | TOGGLE FULL SIZE
from adafruit_pm25.i2c import PM25_I2C
"

Code: Select all | TOGGLE FULL SIZE
Traceback (most recent call last):
  File "A_Sensor_PM25_AQ_R0.py", line 47, in <module>
    pm25 = PM25_I2C(i2c, reset_pin)
NameError: name 'PM25_I2C' is not defined


Code:
Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
 
"""
Example sketch to connect to PM2.5 sensor with either I2C or UART.
"""
 
# pylint: disable=unused-import
import time
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
import adafruit_pm25
#from adafruit_pm25.i2c import PM25_I2C
 
 
reset_pin = None
# If you have a GPIO, its not a bad idea to connect it to the RESET pin
# reset_pin = DigitalInOut(board.G0)
# reset_pin.direction = Direction.OUTPUT
# reset_pin.value = False
 
 
# For use with a computer running Windows:
import serial
uart = serial.Serial("COM4", baudrate=9600, timeout=1)
 
# For use with microcontroller board:
# (Connect the sensor TX pin to the board/computer RX pin)
#uart = busio.UART(board.TX, board.RX, baudrate=9600)
 
# For use with Raspberry Pi/Linux:
# import serial
# uart = serial.Serial("/dev/ttyS0", baudrate=9600, timeout=0.25)
 
# For use with USB-to-serial cable:
# import serial
# uart = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=0.25)
 
# Connect to a PM2.5 sensor over UART
# from adafruit_pm25.uart import PM25_UART
# pm25 = PM25_UART(uart, reset_pin)
 
# Create library object, use 'slow' 100KHz frequency!
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
# Connect to a PM2.5 sensor over I2C
pm25 = PM25_I2C(i2c, reset_pin)
 
print("Found PM2.5 sensor, reading data...")
 
while True:
    time.sleep(1)
 
    try:
        aqdata = pm25.read()
        # print(aqdata)
    except RuntimeError:
        print("Unable to read from sensor, retrying...")
        continue
 
    print()
    print("Concentration Units (standard)")
    print("---------------------------------------")
    print(
        "PM 1.0: %d\tPM2.5: %d\tPM10: %d"
        % (aqdata["pm10 standard"], aqdata["pm25 standard"], aqdata["pm100 standard"])
    )
    print("Concentration Units (environmental)")
    print("---------------------------------------")
    print(
        "PM 1.0: %d\tPM2.5: %d\tPM10: %d"
        % (aqdata["pm10 env"], aqdata["pm25 env"], aqdata["pm100 env"])
    )
    print("---------------------------------------")
    print("Particles > 0.3um / 0.1L air:", aqdata["particles 03um"])
    print("Particles > 0.5um / 0.1L air:", aqdata["particles 05um"])
    print("Particles > 1.0um / 0.1L air:", aqdata["particles 10um"])
    print("Particles > 2.5um / 0.1L air:", aqdata["particles 25um"])
    print("Particles > 5.0um / 0.1L air:", aqdata["particles 50um"])
    print("Particles > 10 um / 0.1L air:", aqdata["particles 100um"])
    print("---------------------------------------")

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Thu Jan 14, 2021 2:14 am

ALso: to show I installed it:

Code: Select all | TOGGLE FULL SIZE
(base) D:\Michael_Master\Engineering\Python_Coding\029_Serial_MP_USB_C>pip install adafruit-circuitpython-pm25
Requirement already satisfied: adafruit-circuitpython-pm25 in c:\programdata\anaconda3\lib\site-packages (1.0.3)
Requirement already satisfied: Adafruit-Blinka in c:\programdata\anaconda3\lib\site-packages (from adafruit-circuitpython-pm25) (5.7.0)
Requirement already satisfied: adafruit-circuitpython-busdevice in c:\programdata\anaconda3\lib\site-packages (from adafruit-circuitpython-pm25) (5.0.1)
Requirement already satisfied: Adafruit-PlatformDetect>=2.18.1 in c:\programdata\anaconda3\lib\site-packages (from Adafruit-Blinka->adafruit-circuitpython-pm25) (2.21.0)
Requirement already satisfied: pyftdi>=0.40.0 in c:\programdata\anaconda3\lib\site-packages (from Adafruit-Blinka->adafruit-circuitpython-pm25) (0.52.0)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in c:\programdata\anaconda3\lib\site-packages (from Adafruit-Blinka->adafruit-circuitpython-pm25) (1.1.7)
Requirement already satisfied: pyserial>=3.0 in c:\programdata\anaconda3\lib\site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-pm25) (3.4)
Requirement already satisfied: pyusb>=1.0.0 in c:\programdata\anaconda3\lib\site-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-pm25) (

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by adafruit_support_carter on Thu Jan 14, 2021 12:35 pm

Looks like you are using an anaconda setup. Not sure if that matters, but does that require anything special for installing packages? Instead of just regular pip?

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Fri Jan 15, 2021 1:53 am

Most of the time, not a problem, unless it has to be a specific environment.
Code: Select all | TOGGLE FULL SIZE
'pip3' is not recognized as an internal or external command,
operable program or batch file.


Python 3. All other adafruit items seem to be installing and working.

And it gets past the import library down to lines beyond the import, indicating it found the library, so it's something to do with the i2c library class call or pathing either in guthub or the install package, methinks with limited knowledge of the libraries :)

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by adafruit_support_carter on Fri Jan 15, 2021 1:21 pm

So it's not finding pip3 in your setup? Try running:
Code: Select all | TOGGLE FULL SIZE
pip --version

and see what it reports.

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Sat Jan 16, 2021 1:49 am

Code: Select all | TOGGLE FULL SIZE
pip 19.2.3 from C:\ProgramData\Anaconda3\lib\site-packages\pip (python 3.7)

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Sat Jan 16, 2021 1:50 am

adafruit_support_carter wrote:So it's not finding pip3 in your setup? Try running:
Code: Select all | TOGGLE FULL SIZE
pip --version

and see what it reports.

normally I have to just use pip install xxxxx to get packages, not pip3.

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by adafruit_support_carter on Mon Jan 18, 2021 11:45 am

Thanks. That seems to look OK. How about trying a forced re-install of the PM25 library and see if it can find it then?

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Mon Jan 18, 2021 7:06 pm

adafruit_support_carter wrote:Thanks. That seems to look OK. How about trying a forced re-install of the PM25 library and see if it can find it then?



Were the directions there for that and do I have to figure out the python for removal of what's there?

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by adafruit_support_carter on Tue Jan 19, 2021 12:07 pm

Try:
Code: Select all | TOGGLE FULL SIZE
pip install --upgrade --force-reinstall adafruit-circuitpython-pm25

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Tue Jan 19, 2021 3:18 pm

Well, Well, that Worked (thanks)... but here's what's bizarre:
It works without the need to uncooment the windows lines for UART;
[img]
pm25_running.JPG
[/img]

or with it:
[img]
pm25_running2.JPG
[/img]

How come?
Attachments
pm25_running2.JPG
pm25_running2.JPG (208.95 KiB) Viewed 49 times
pm25_running.JPG
pm25_running.JPG (206.27 KiB) Viewed 49 times

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Re: MCP2221 + PM25 Circuit Python Not Running

by adafruit_support_carter on Tue Jan 19, 2021 3:44 pm

Are you using I2C in both cases maybe? Can't see those lines in the screen cap showing the uart setup.

adafruit_support_carter
 
Posts: 18190
Joined: Tue Nov 29, 2016 2:45 pm

Re: MCP2221 + PM25 Circuit Python Not Running

by scotch1 on Tue Jan 19, 2021 6:48 pm

yeah: i2C running:
[img]
pm25_running3.JPG
[/img]
Attachments
pm25_running3.JPG
pm25_running3.JPG (222.54 KiB) Viewed 26 times

scotch1
 
Posts: 146
Joined: Mon Nov 26, 2012 12:13 am

Please be positive and constructive with your questions and comments.