Python Forum

Full Version: Save Arduino data in mysql server via raspberrypi
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I need help in saving Arduino data in phpmyadmin mysql server in raspberry pi. I connected the Arduino to raspberry pi 3B+ via usb i wrote a code and got this error.

Python code:

import serial
import time
import MySQLdb as mdb

arduino = serial.Serial("/dev/ttyACM0")
arduino.boudrate = 9600
data = arduino.readline()

time.sleep(2)
data = arduino.readline()
pieces = data.split("\t")

temp = pieces[0]
hum = pieces[1]
con=mdb.connect('localhost','root','12345678','testdb');

with con:
    
    cursor=con.cursor()
    cursor.execute("INSERT INTO TempDB (temp,hum) VALUES (?, ?)")
    con.commit()
    cursor.close()
Error message:
Error:
Traceback (most recent call last): File "./name.py", line 3, in <module> import MySQLdb as mdb ModuleNotFoundError: No module named 'MySQLdb'
you need to install the mysqldb package
must have internet access when running command below
from command line (not in python shell) run pip install mysqlclient