I am attempting to graph data from a particulate sensor using Python. However, I keep getting an import error of the following.
from numpy.core._multiarray_umath import (
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory
I followed the link to the following troubleshooting guide but still am having troubles.
please any guidance here is greatly appreciated.
full code below
import time
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
from adafruit_pm25.i2c import PM25_I2C
from datetime import datetime
import tkinter as tk
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import matplotlib.pyplot as plt
datetime1 = str(datetime.now())
reset_pin = None
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
pm25 = PM25_I2C(i2c, reset_pin)
extension = ".csv"
file_name = datetime1 + extension
def start_collection():
global collecting
collecting = True
start_button.config(state="disabled")
stop_button.config(state="normal")
collect_data()
def stop_collection():
global collecting
collecting = False
start_button.config(state="normal")
stop_button.config(state="disabled")
def collect_data():
if collecting:
try:
aqdata = pm25.read()
concentration_units = (
"Concentration Units (standard)\n"
"---------------------------------------\n"
"PM 1.0: {}\tPM2.5: {}\tPM10: {}\n"
"Concentration Units (environmental)\n"
"---------------------------------------\n"
"PM 1.0: {}\tPM2.5: {}\tPM10: {}\n"
"---------------------------------------\n"
"Particles > 0.3um / 0.1L air: {}\n"
"Particles > 0.5um / 0.1L air: {}\n"
"Particles > 1.0um / 0.1L air: {}\n"
"Particles > 2.5um / 0.1L air: {}\n"
"Particles > 5.0um / 0.1L air: {}\n"
"Particles > 10 um / 0.1L air: {}\n"
"---------------------------------------"
).format(
aqdata["pm10 standard"], aqdata["pm25 standard"], aqdata["pm100 standard"],
aqdata["pm10 env"], aqdata["pm25 env"], aqdata["pm100 env"],
aqdata["particles 03um"], aqdata["particles 05um"], aqdata["particles 10um"],
aqdata["particles 25um"], aqdata["particles 50um"], aqdata["particles 100um"]
)
label.config(text=concentration_units, font=("Arial", 14)) # Increase font size
with open(file_name, 'a') as file1:
datetime2 = datetime.now()
data = "{},{},{},{},{},{},{}".format(
datetime2, aqdata["particles 03um"], aqdata["particles 05um"],
aqdata["particles 10um"], aqdata["particles 25um"],
aqdata["particles 50um"], aqdata["particles 100um"])
file1.write('\n')
file1.write(data)
# Update the graph
times.append(datetime2)
pm25_values.append(aqdata["particles 03um"])
ax.clear()
ax.plot(times, pm25_values, label='PM 2.5')
ax.legend(loc='upper right')
ax.set_xlabel('Time')
ax.set_ylabel('PM 2.5 Value')
ax.set_title('PM 2.5 Value Over Time')
fig.canvas.draw()
root.after(1000, collect_data) # Repeat after 1 second
except RuntimeError:
print("Unable to read from sensor, retrying...")
root.after(1000, collect_data) # Retry after 1 second
root = tk.Tk()
root.title("PM2.5 Sensor Data")
root.configure(bg="black")
root.geometry("800x600") # Set initial size of the window
label = tk.Label(root, text="", fg="white", bg="black")
label.pack(side="top", pady=10) # Center the label
frame = tk.Frame(root, bg="black")
frame.pack(side="top", pady=10) # Center the frame containing buttons
start_button = tk.Button(frame, text="Start", command=start_collection)
start_button.pack(side="left", padx=10) # Center the start button
stop_button = tk.Button(frame, text="Stop", command=stop_collection, state="disabled")
stop_button.pack(side="left", padx=10) # Center the stop button
collecting = False
# Setup graph
fig, ax = plt.subplots()
ax.set_xlabel('Time')
ax.set_ylabel('PM 2.5 Value')
ax.set_title('PM 2.5 Value Over Time')
times = []
pm25_values = []
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
root.mainloop()
I uninstalled numpy and installed a clean version, made sure it was the latest 1.26.4. I also added the following library to remedy this error with no success.
sudo apt-get install libatlas-base-dev