Python Forum
Save Arduino data in mysql server via raspberrypi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save Arduino data in mysql server via raspberrypi
#1
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'
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 509 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  Mysql and mysql.connector error lostintime 2 611 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Trying to Get Arduino sensor data over to excel using Python. eh5713 1 1,616 Dec-01-2022, 01:52 PM
Last Post: deanhystad
  In SQL Server, mix data types. shiv11 0 854 Sep-21-2022, 12:50 PM
Last Post: shiv11
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,176 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,675 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Save data frame to .csv df.to.csv() mcva 1 1,496 Feb-03-2022, 07:05 PM
Last Post: mcva
  How to take the tar backup files form remote server to local server sivareddy 0 1,871 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,113 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Reading data from mysql. stsxbel 2 2,162 May-23-2021, 06:56 PM
Last Post: stsxbel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020