Card image cap

HWT905-TTL MPU-9250 + python 1

HWT905-TTL MPU-9250 (WITMOTION)

I used asyncio and matplotlib to implement visualization of HWT905-TTL MPU-9250 angular data output.

However, this program has an issue where the plot updates are not performed within the asyncio event loop.

This can lead to problems...

2024/02/13 update

  • Added Threading and logging
handler = RotatingFileHandler("app.log", maxBytes=6000000, backupCount=5)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
  • asyncio move to other thread.
# I wrapped the asyncio event loop in a function.
def start_asyncio_loop():
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(readerAndWriter(loop))
    loop.close

def main():
    async_thread = threading.Thread(target=start_asyncio_loop)
    async_thread.daemon = True
    async_thread.start()

    plot_data()


if __name__ == "__main__":
    main()

git hub: serial_async

Category : Python, Posted : Feb. 12, 2024, 11:33 p.m.,
Update : Feb. 26, 2024, 11:03 p.m., By : koki,

Profile

Hello, my name is Koki. I am currently learning the web framework Django and English. In my free time, I enjoy hiking, cycling, and visiting shrines and temples. At work, I make software for programmable logic controllers (PLCs), I work especially with OMRON and Mitsubishi PLCs. Please feel free to contact me for any inquiries, job requests, or just to chat. We look forward to hearing from you via email!

Category

10 Latest articles