How to Plot Real Time Serial Data on Python GUI??

Поделиться
HTML-код
  • Опубликовано: 26 окт 2024

Комментарии • 131

  • @pabloc.izaguirreartavia828
    @pabloc.izaguirreartavia828 3 года назад +1

    Thanks from Costa Rica, !! I´m sure if I hadn´t come to your channel , i would never have learned this usefull code !!

  • @boutheinahaddad6803
    @boutheinahaddad6803 3 года назад +3

    thank you for this video it is very clear but can you do the video for saving the signal in the file in the real time

  • @anthonyv6962
    @anthonyv6962 Месяц назад

    Thank you this was very helpful.

  • @phamngocquapham5472
    @phamngocquapham5472 10 месяцев назад +1

    Great Video! Thank you very much.

    • @sachinsharmajcbro
      @sachinsharmajcbro  Месяц назад

      Free Free...Get the AVR Bare Metal course for free. Limited Time offer....use the following link:
      www.udemy.com/course/bare-metal-programming-of-avr-micro-controllers/?couponCode=9F5E62DD80CD1D54D816

  • @kanhaconsciousness704
    @kanhaconsciousness704 4 месяца назад +1

    what if instead of arduino I connect an oscilloscope , will the code have any changes or is this code compatible with that too? Someone please clear this doubt !!

    • @sachinsharmajcbro
      @sachinsharmajcbro  Месяц назад

      Free Free...Get the AVR Bare Metal course for free. Limited Time offer....use the following link:
      www.udemy.com/course/bare-metal-programming-of-avr-micro-controllers/?couponCode=9F5E62DD80CD1D54D816

  • @vishwakchella
    @vishwakchella Год назад +1

    sir can you please make a video for plotting multiple data on the gui, having trouble parsing the data into 2 variables

  • @Omgtired
    @Omgtired Год назад

    Thank you very much. Just what I was looking for. Great example project applicable for many real applications

  • @nityanandadas5575
    @nityanandadas5575 Год назад +1

    Very nice and useful video.
    Sir, can you please help me about how to change the program for plotting data of voltage output from a power supply which is installed and connected through?
    Please.

  • @dani_flyingdutchman5495
    @dani_flyingdutchman5495 2 года назад +1

    Very helpful video prof! Thanks you

  • @chitchatYT144
    @chitchatYT144 2 года назад +1

    Hello sir.can u make a video on how to show real time data on screen through tkinter python!!!

  • @ExatasDistribuidas
    @ExatasDistribuidas 3 года назад +1

    Thank you! From Brazil

  • @nickst2797
    @nickst2797 3 года назад +2

    Thank you very much! Could you make a video, not on how to plot, but how to display the serial text data, on a tkinter region? Maybe with a scrolling bar and autoscroll option? Thanks!

  • @AlexandreCes
    @AlexandreCes 2 года назад +1

    merci beaucoup, cela m'aide énormément .

  • @lydiaewande8813
    @lydiaewande8813 3 года назад +2

    Thank you so much for this video. I have a question : How can i use this GUI program without working or opening Python? How can i save it on a computer so that i can use IT anytime without depending on Python? I need your answer please.

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      in order to do that you have to create the executable file of the program.

    • @lydiaewande8813
      @lydiaewande8813 3 года назад

      @@sachinsharmajcbro Thank you for answer, how can i create an executable file in that case ?

  • @robertovalenzuela8860
    @robertovalenzuela8860 3 года назад +1

    When I press start the program crash and stop, also It doesn't show any graph signal, It Is only for Arduino? I'm using a Chatillon pull test connected via DB9 yo USB

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад +1

      There must some problem with opening the serial port or program routines. further, the same program can run for any board as long as data is being sent to the serial port is captured properly.

  • @Kennerdoll
    @Kennerdoll 3 года назад +2

    Can the live plot graph be saved and how can the width of the plotting area be increased?

  • @dimaskurniawan1924
    @dimaskurniawan1924 2 года назад +1

    thank you, this is a great video, but sir can u help me to solve the delay, i have tried to change the baudrate but still have delay

  • @modugulakavyasri1581
    @modugulakavyasri1581 2 года назад +1

    Sir can we plot real data from gyrosensors on a website

  • @susilo5667
    @susilo5667 2 года назад +1

    Is there tutorials plotting realtime data on web server?

  • @tuyen3586
    @tuyen3586 3 года назад +1

    Many thanks!

  • @dioutoroo
    @dioutoroo 2 года назад +1

    Hello Sir, thank you for your video! I have a question. Can I implement the same code for my Nidaq USB - 6009 instead of arduino? Appreciate your help!

    • @sachinsharmajcbro
      @sachinsharmajcbro  Год назад +1

      If I am right then Nidaq USB doesn't support serial communication. Labview driver needs to be installed for that in order to use the same in MATLAB and LabVIEW

    • @dioutoroo
      @dioutoroo Год назад

      @@sachinsharmajcbro that is true. I'm using NImax and using Nidaq modules in python, but I can't really get output in python GUI. One more question Sir, if we use arduino, then we need to write the script in IDE first then go to Python, am I right?
      Thank you for your help, Sir

    • @sachinsharmajcbro
      @sachinsharmajcbro  Год назад +1

      @@dioutoroo yes

  • @gerardoulisesperezrodrigue6560
    @gerardoulisesperezrodrigue6560 3 года назад +1

    I have coded your example ant it works BUUT, if I let the program run it suddenly stops after a few minutes. My arduino and python program works perfectly good if I test it using only the terminal without the plot. Can you share me any suggestion to solve it?

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      I am not sure about this issue. After how much time, does program stops responding?

    • @gerardoulisesperezrodrigue6560
      @gerardoulisesperezrodrigue6560 3 года назад +1

      @@sachinsharmajcbro I inserted an "sleep(0.1)" function. I deleted this and the problem was solved. Thank you very much for your support. And also thank you for your video you're a really good teacher!!!

  • @ThingsMadeOfOtherThings
    @ThingsMadeOfOtherThings Год назад +1

    Dear Sir, thank you for sharing this guide. I am doing a similar project but using a raspberry pi and the INA260 sensor connected to gpio pins 2 and 3. Is there a simple way to modify your code to make it work? Thank you so much for any information.

    • @sachinsharmajcbro
      @sachinsharmajcbro  Год назад

      Code can be modified. You can contact me at info@jcbrolabs.org for customization.

  • @bennguyen1313
    @bennguyen1313 3 года назад +1

    It seems the syntax for matplotlib and PyQt-Graph is not compatible. Any thoughts on when one may be better suited over the other?
    I'm trying to plot real-time data coming in from the serial port ("5, 0x1234, 1.938
    ") , but I start to lose data after a few seconds.. any suggestions on either using concurrency (queue/collections.deque, threading, asyncio, multiprocessing) or whether to use matplotlib-blit, or PyQtGraph-split... or PyQt vs tkinter.... or any approach that would maximize the throughput so that no data gets dropped from the serial during the GUI update?
    I'm running on a PC, but I saw an example of a fast oscilloscope on a Raspberry Pi using OpenGL/freeglut , however, the use of the GPU looks intimidating and perhaps overkill for my needs!

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      Actually, If you are sending data at fast rate and python is reading that data from a function only then you will loose samples. In this case you should use a thread to read the data from serial port. Further, if you keep appending the data in an array then too you will start loosing sample after some duration.

  • @rverm1000
    @rverm1000 4 года назад +1

    best video ive seen so far.

  • @pikpik6078
    @pikpik6078 4 года назад +2

    thank sir for tutorial i really appreciate
    one question sir, how to make plot real time with distance sensor (HC-SR04) using guide matlab ?

    • @sachinsharmajcbro
      @sachinsharmajcbro  4 года назад

      Hi, Separate code has to be written for that. If you want to get this done then you can contact us at: info@jcbrolabs.org

    • @pikpik6078
      @pikpik6078 4 года назад

      @@sachinsharmajcbro ok sir i have contacted that email

  • @dr.gauravgoyal6243
    @dr.gauravgoyal6243 4 года назад +1

    Hello Really a nice video... After executing it I am facing two problems.
    1. The data is not changing
    2. could not convert string to float: error in line data[99] = float(a[0:4])

    • @sachinsharmajcbro
      @sachinsharmajcbro  4 года назад +1

      Hi, if serial data is not received properly then this error will arise. You can try to use, try and except

  • @huseyinkucuktoka
    @huseyinkucuktoka 3 года назад +2

    Hello sir,
    I want to make a project that live plot data from raspberry pi. I cant take serial data dallas sensor from raspberry pi. what should I do. Thanks.

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад +1

      Dear, Your requirements are not clear. Please send me an email at info@jcbrolabs.org with more clear description of your requirements.

  • @darshanpanchal3046
    @darshanpanchal3046 Год назад

    Sir i am really stuck here, please give video doing same with threading 🙏 please 🙏

  • @TheCarloszoom3000
    @TheCarloszoom3000 4 года назад +2

    One thing i noticed is that the signal has a delay or lag in the signal displayed in the Python GUI.
    I even changed the baudrate to 250000, but i still have a 2 seconds lag in the signal.
    The Arduino IDE shows the singal smoothly.
    I appreciate your help.
    Regards,

    • @sachinsharmajcbro
      @sachinsharmajcbro  4 года назад

      Actually, yes this is the problem and I also noticed it while working on a "Real time display and data acquisition project". This problem also doesn't collect the required number of samples.
      You can solve this issue with the help of threading.
      Regards

    • @TheCarloszoom3000
      @TheCarloszoom3000 4 года назад

      @@sachinsharmajcbro Thanks for replying. I see that one makes a better use of system memory (making the program faster). I also tried making the Gui an .exe file with Pyinstaller.exe and there's barely a lag. Thanks again.

    • @Varman199
      @Varman199 3 года назад

      @@TheCarloszoom3000 Hi, Unable to make exe file and showing error like-
      Traceback (most recent call last):
      File "real.py", line 5, in
      ModuleNotFoundError: No module named 'serial'
      how to resolve this issue, I even tried with hidden import. Still not working
      Thankyou

    • @dimaskurniawan1924
      @dimaskurniawan1924 2 года назад

      i have tried code in this video and having a same trouble, how u can solve that trouble sir? can u explain it to me please? thank you

  • @chathudilrukshi9609
    @chathudilrukshi9609 3 года назад +1

    Very helpful video. Could you also please suggest a way to display real time data with another loop running background? Every time I try to do that, my window GUI freezes until the loop ends. Thank you

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      Hi, yes there is another way of doing it by using threads. You can contact us at: info@jcbrolabs.org for more information

  • @krmona95
    @krmona95 3 года назад +1

    Hi, thanks for the video!
    Do you know how to add the plot settings? Eg. Zoom, save, etc

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      I have not tried but can be done easily.

    • @krmona95
      @krmona95 3 года назад

      @@sachinsharmajcbro any advices in how can I do it?

  • @mubin04sheikh
    @mubin04sheikh 4 года назад +1

    Please make a videio on PID Control in python

  • @nicolasbolivar7647
    @nicolasbolivar7647 3 года назад +1

    i have a problem, the part of root.after(1, plot_data) isnt working, it doesnt do the loop to make it graph

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      It takes time in ms. In my view try to increase the time.

  • @kangwei9429
    @kangwei9429 4 года назад +1

    Hi sir, I am facing an issue that there is no signal in my plot even I had press the start button, the graph is empty. I have checked and there are no errors for the coding. May I know what is the problem?

    • @sachinsharmajcbro
      @sachinsharmajcbro  4 года назад

      Hi, actually, I can't help you without looking at the code. You can send a mail at: info@jcbrolabs.org

    • @blasvega2
      @blasvega2 3 года назад

      try this code in the Arduino program:
      void setup(){
      Serial.begin(115200);
      }
      void loop(){
      //send a float number 5.6
      Serial.write(53); //5
      Serial.write(46); //.
      Serial.write(54); //6
      Serial.print("
      ");
      //send a number
      Serial.write(56); //8
      Serial.print("
      ");
      delay(200);
      }

  • @arbaazkhan5868
    @arbaazkhan5868 3 года назад +1

    how should i fix this error
    SerialException: could not open port 'COM3': PermissionError(13, 'Access is denied.', None, 5)

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад +1

      First confirm that no other application is accessing the same port. Then check whether you have enough permissions to access the port or not.

    • @arbaazkhan5868
      @arbaazkhan5868 3 года назад

      @@sachinsharmajcbro brother how to check whether you have enough permission to access the port

  • @karanmistry5724
    @karanmistry5724 4 года назад +1

    its good
    nice description sir

  • @RohanHazara
    @RohanHazara 3 года назад +1

    Thank you so much.

  • @kuchalaggyan2502
    @kuchalaggyan2502 3 года назад +1

    Hi,
    I want to show the 3d graph. can you help to do this. I am reading the value of the accelerometer. I want to show the line graph in Tkinter.

    • @kuchalaggyan2502
      @kuchalaggyan2502 3 года назад +1

      there are some changes in the line of code. I try myself to make desired output but I fail to do this, can u help me to make the desired ouput.

    • @kuchalaggyan2502
      @kuchalaggyan2502 3 года назад +1

      lines= ax.plot([],[])[0] can u explain this line of code. what does do? and what all changes it needs to make 2d graph to 3d graph, if I generate the 3rd coordinate by using random.random().

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      Hi, It can be done. Please contact us at: info@jcbrolabs.org

    • @kuchalaggyan2502
      @kuchalaggyan2502 3 года назад

      @@sachinsharmajcbro Ok, Thank u for giving me your contact address. Thank u in advance. I send u a mail. Plz, reply as soon as possible.

    • @kuchalaggyan2502
      @kuchalaggyan2502 3 года назад

      @@sachinsharmajcbro I am getting error when I pass these "lines.set_zdata(data)" and the error is 'Line2D' object has no attribute 'set_zdata'.... what all changes it need to run these line "lines.set_zdata(data)".

  • @juansebastianforeroromero8023
    @juansebastianforeroromero8023 3 года назад +1

    Dude, isn't it possible for you to provide Arduino code? I swear I've tried with default one but it is not working. I don't know if maybe if using a wrong one

    • @blasvega2
      @blasvega2 3 года назад

      Try this code for the Arduino program: void setup(){
      Serial.begin(115200);
      }
      void loop(){
      //send a float number 5.6
      Serial.write(53); //5
      Serial.write(46); //.
      Serial.write(54); //6
      Serial.print("
      ");
      //send
      Serial.write(56); //8
      Serial.print("
      ");
      delay(200);
      }

  • @robertstockmann4720
    @robertstockmann4720 3 года назад +2

    Hello sir, your code works very well! Thank you first of all. But i am facing a little problem, when running the code again, i recieve an warning in the console:
    invalid command name "2073612564416plot_data"
    while executing
    "2073612564416plot_data"
    ("after" script)
    The GUI still works when i run it a second time, but i guess it has an old after.loop running in background which collides and throws the warning or something like that. Do you know how to solve this 'problem'?

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад +1

      I can not say exactly without seeing the code.

    • @robertstockmann4720
      @robertstockmann4720 3 года назад

      @@sachinsharmajcbro i solved it on my own, the root.after loop was still running in background as i expected. So i defined a condition to exit the loop when closing the GUI and now it throws no warning anymore. I appreciate your work!

    • @Global_Info
      @Global_Info 3 года назад

      @@robertstockmann4720and @sachin sharma, I receive the same error as you mentioned here "2073612564416plot_data". However, in my case, the GUI appears but the data don't appear on the plot window. Though, I can receive the serial data while using the serial arduino terminal. Can anyone of you plz help.

  • @itzikovadia851
    @itzikovadia851 4 года назад +2

    sir in line 28 it gives me an error couldnt convert string to float. the data is coming from arduino serial port by println command can u please help me

    • @sachinsharmajcbro
      @sachinsharmajcbro  4 года назад +1

      If some part of the received data is missing then it throws that error. If you are reading in continuous mode then you should use, try and except block

    • @itzikovadia851
      @itzikovadia851 4 года назад

      @@sachinsharmajcbro thank u sir i will try it. the problem that the data are sent after the start button pushed and the received data is NONE ""

    • @blasvega2
      @blasvega2 3 года назад

      @@itzikovadia851 Try this code in the Arduino program: void setup(){
      Serial.begin(115200);
      }
      void loop(){
      //send a float number 5.6
      Serial.write(53); //5
      Serial.write(46); //.
      Serial.write(54); //6
      Serial.print("
      ");
      //send
      Serial.write(56); //8
      Serial.print("
      ");
      delay(200);
      }

  • @vijayakumarp6831
    @vijayakumarp6831 4 года назад +1

    This video is very useful.i want modify one small thing.in that x axis instead of 50 samples i want to plot the sensor data for last 24 hours data.can you help me

  • @virajitviru
    @virajitviru 3 года назад +1

    Why is there the Swastik symbol ? just curious

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      Apart from being a religious symbol in India, I am more inspired by the ancient science and technology knowledge of our heritage. But it is taken up by west people for totally different meaning which I never imagined.

  • @TheCarloszoom3000
    @TheCarloszoom3000 4 года назад +1

    I'm working on plotting 2 signals (from Arduino).
    Those are 2 float values separated by ",".
    So far i have 2 graphs in the same canvas and the code stops receiveing data as it shows "List index out of range error".
    I appreciate your help.
    ------
    from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
    from matplotlib.figure import Figure
    import tkinter as tk
    import numpy as np
    import serial as sr
    # ------global variables
    data = np.array([])
    data2 = np.array([])
    cond = False
    # -----plot data-----
    def plot_data():
    global cond, data, data2
    if (cond == True):
    a = s.readline().decode() # Reads data from Arduino and creates a object

    dataArray = a.split(',')
    a = dataArray[0]
    a2 = dataArray[1]

    if (len(data) < 99):
    data = np.append(data, float(a[0:4]))
    data2 = np.append(data2, float(a2[0:4]))
    print(data, data2)
    else:
    data[0:98] = data[1:99]
    data[98] = float(a[0:4])
    data2[0:98] = data2[1:99]
    data2[98] = float(a2[0:4])
    lines.set_xdata(np.arange(0, len(data))) # Returns a ndarray object containing evenly spaced values within the given range
    lines.set_ydata(data)
    lines2.set_xdata(np.arange(0, len(data2))) # Returns a ndarray object containing evenly spaced values within the given range
    lines2.set_ydata(data2)
    canvas.draw()
    root.after(1, plot_data)
    def plot_start():
    global cond
    cond = True
    s.reset_input_buffer()
    def plot_stop():
    global cond
    cond = False
    # -----Main GUI code-----
    root = tk.Tk()
    root.title('Real Time Plot')
    root.configure(background='light gray')
    root.geometry("1200x800") # set the window size
    # ------create Plot object on GUI----------
    # add figure canvas
    fig = Figure()
    ax1 = fig.add_subplot(111)
    ax2 = fig.add_subplot(121)
    # ax = plt.axes(xlim=(0,100),ylim=(120,150)); #displaying only 100 samples
    ax1.set_title('Serial Data')
    ax1.set_xlabel('Sample')
    ax1.set_ylabel('Readings')
    ax1.set_xlim(0, 100)
    ax1.set_ylim(200, 800) # Set Y axe min and max limits: depend on reading from Arduino
    ax1.grid()
    ax2.grid()
    ax2.set_xlim(0, 100)
    ax2.set_ylim(200, 800)
    lines = ax1.plot([], [])[0]
    lines2 = ax2.plot([], [])[0]
    canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea.
    canvas.get_tk_widget().place(x=20, y=20, width=750, height=600)
    canvas.draw()
    # ----------create button---------
    root.update()
    start = tk.Button(root, text="Start", font=('verdana', 10), command=lambda: plot_start())
    start.place(x=650, y=630)
    root.update()
    stop = tk.Button(root, text="Stop", font=('verdana', 10), command=lambda: plot_stop())
    stop.place(x=start.winfo_x() + start.winfo_reqwidth() + 20, y=630)
    # ----start serial port----
    s = sr.Serial('COM3', 9600)
    s.reset_input_buffer()
    root.after(1, plot_data)
    root.mainloop()
    ----

    • @bennguyen1313
      @bennguyen1313 3 года назад

      Where you able to get this working? Did you have any issues of dropped-data?

  • @nisansalathenuwara1416
    @nisansalathenuwara1416 3 года назад +1

    Sir, how to plot multiple real time data in the python?

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      If you wish some customized work then please contact us at: info@jcbrolabs.org

  • @rverm1000
    @rverm1000 4 года назад +1

    i got the code to work in the previous video. but i cant seem this code to work

  • @ismailnasri7241
    @ismailnasri7241 4 года назад +1

    Hey siiir...i wana just know how can i plot in real.time an variable in my script python and plot it ik GUI

    • @sachinsharmajcbro
      @sachinsharmajcbro  4 года назад +1

      Procedure will be same as in this video

    • @ismailnasri7241
      @ismailnasri7241 4 года назад

      @@sachinsharmajcbro with what can i remplace this if i have an int variable
      #----start serial port---- s = sr.Serial('COM8',115200); s.reset_input_buffer()

  • @akaludi
    @akaludi 3 года назад +1

    Please provide the Arduino Code on website also - only Python code for PC is given - One side is not enough and is DISCARD by all of people and students - provide the code for Arduino and write and explain to students to feel satisfied

    • @blasvega2
      @blasvega2 3 года назад

      You can star with this code in the Arduino:
      void setup(){
      Serial.begin(115200);
      }
      void loop(){
      //send a float number 5.6
      Serial.write(53); //5
      Serial.write(46); //.
      Serial.write(54); //6
      Serial.print("
      ");
      //send
      Serial.write(56); //8
      Serial.print("
      ");
      delay(200);
      }

  • @stefanjelic8704
    @stefanjelic8704 3 года назад +2

    Can You post the code please? 😁

  • @franciscomiranda3239
    @franciscomiranda3239 3 года назад +1

    Source code direct link??

  • @somebody9887
    @somebody9887 3 года назад +1

    There is Threading problem with this code

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      If you want to acquire data at faster rate then you have to use threading.

  • @Global_Info
    @Global_Info 3 года назад +1

    May I get the Arduino code for this project?

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      That is simple serial communication program in arduino...

  • @itzikovadia851
    @itzikovadia851 4 года назад +1

    excellent but it is poor that the code file is missing nevertheless thanks

  • @pantelapost8607
    @pantelapost8607 3 года назад

    Sooo we gonna pretend that we don't see the swastika?

    • @sachinsharmajcbro
      @sachinsharmajcbro  3 года назад

      Dear you don't need to pretend. You just need to understand that this is a part of religious symbol in several parts of the world.

  • @anthonypeters1797
    @anthonypeters1797 2 года назад

    whats up with the nazi sign

    • @sachinsharmajcbro
      @sachinsharmajcbro  2 года назад +1

      The sign is not related to Nazi symbol. It is an Indian symbol Swastika, which represent prosperity and well being for all. Please do some google search for the same.

    • @zachzion762
      @zachzion762 9 месяцев назад

      ⁠@@sachinsharmajcbroyeah the swastica threw me off too. I would consider changing it.