This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Serial data plotting

Other Parts Discussed in Thread: MSP430F5438A

hi to all,

         I am working with MSP430F5438A microcontroller. In that i have configured ADC and UART, now i want to plot the data instead of seeing the data on tera term.

I am thinking python could be a could solution. Any one can tell me how to use python for plotting the data of msp430. If there is any sample code, please share with me.

                                                   Thank you

  • Hi Prasanth,

    I would recommend you look into GUI composer: processors.wiki.ti.com/.../Category:GUI_Composer

    Regards,
    Ryan
  • Hello all,

    I am facing a problem about Real time uart data plotting on python
    Actually i am using msp430f5438a microcontroller, and i am trying to plot sine waveform(which is given by a function generator) on python.

    My doubt is => it is possible to plot the higher frequency signal on python by using msp430 microcontroller?
    The frequency range is about 5khz

    My experiment: Here, I am sending the data from msp430 as a formatted reading which i have mentioned below,
    sprintf(str,"%03d",ADC_result);

    ADC Configuration is
    8-bit configuration, 460800 baud rate,
    USCI module clk frequency = 12mhz
    ADC12CLK frequency is = 4mhz
    My sampling frequency is = 15khz

    According to my understanding i am converting each sample of adc to 3-bytes(or character) to transfer through uart.

    Wright now my problem is Where i am unable to plot a sine waveform which frequency is more than 10 hz.

    If i got solution for this, i will really feel blessed.. Thanks in advance...

    i am attaching the python code below:


    import sys
    import serial
    import numpy as np
    import matplotlib.pyplot as plt
    from collections import deque

    port = "COM14"

    baud = 460800

    timeout=1

    ser = serial.Serial()
    ser.port = port
    ser.baudrate = baud
    ser.timeout = timeout

    a1 = deque(([0.0])*1000)
    plt.title("Real Time Data Monitoring")
    line, = plt.plot(a1)
    plt.ion()
    plt.xlabel("Time_Period")
    plt.ylabel("Amplitude")
    plt.ylim([0,300])
    plt.grid()

    try:
    ser.open()
    except:
    sys.stderr.write("Error opening serial port %s\n" % (ser.portstr) )
    sys.exit(1)

    while 1:
    data = ser.read(3)
    reading = int(data)
    print(a1)
    a1.appendleft((data))
    datatoplot = a1.pop()
    line.set_ydata(a1)
    plt.draw()
    plt.pause(0.0001)
  • >ADC Configuration is
    You missed to specify ADC configuration, at least sample rate.
    >Wright now my problem is Where i am unable to plot a sine waveform which frequency is more than 10 hz.
    Please describe what you mean by saying "i am unable". What results you are getting when you are able to plot and when you are not? Maybe show some plots?
    >sprintf(str,"%03d",ADC_result);
    You are not using any delimiter. How python code knows where one sample ends and another begins? If just single char is lost then everything after that will be garbled.
  • Dear Ilmars,

    I already have mentioned about the Sampling Rate of ADC12_A of MSP430F5438A in my previous post.

    1) Once again I am telling it the configuration of ADC12_A is
    Resolution : 8-bit
    ADC12A_CLK : 4 Mhz
    Sampling rate : 15094 Samples per second
    (Or)
    15 ksps

    2) Actually I am using a function generator to give an input signal to the ADC of MSP430

    I am trying to reproduce that signal on python for various input signal frequency ranges(My requirement is ranging from 0 hz- 5000 hz).

    But I am unable to reproduce it more than 10hz(as a sine waveform).

    If you want I can attach that image for various frequency ranges that I have verified.


    3) I have attached the sample data receiving format on python from UART of MSP430.

    deque(['066', '117', '206', '108', '212', '063', '117', '206', '057', '130', '197', '048', '138', '068', '111', '188', '042', '154', '178', '035', '100', '216', '070', '108', '218', '073', '105', '214', '067', '117', '208', '056', '126', '207', '058', '123', '204', '047', '140', '190', '046', '140', '191', '042', '152', '180', '035', '101', '215', '066', '112', '182', '037', '088', '211', '062', '118', '206', '055', '127', '197', '048', '095', '218', '044', '093', '219', '076', '101', '214', '066', '113', '209', '059', '135', '194', '069', '044', '144', '186', '037', '156', '177', '034', '094', '209', '059', '092', '220', '076', '100', '216', '066', '115', '204', '054', '128', '198', '048', '138', '188', '041', '154', '175', '041', '151', '181', '035', '137'])

    Now you can tell me where I have to add delimeter and why??

    Now my question is,
    What is the maximum Input signal frequency range that I can reproduce on python by using MSP430F5438A??

    Thanks in advance.
  • PRASANTH S said:
    I already have mentioned about the Sampling Rate of ADC12_A of MSP430F5438A in my previous post.

    So what? You started new thread. As you did not mention your previous post while starting this one, it is clearly your problem that you had to tell ADC configuration again. I probably did not see it and you can't blame me for that.

    PRASANTH S said:
    3) I have attached the sample data receiving format on python from UART of MSP430.

    Well, please. - Because it is hard to see any picture in data array you provided.

    PRASANTH S said:
    What is the maximum Input signal frequency range that I can reproduce on python by using MSP430F5438A??

    While sampling 5KHz sine signal at 15KHz sample rate, you have 3 points per sine period. Try to draw sine on paper just using three dots - any success?

    I cannot tell anything about python (it's your problem), but ADC of MSP430F5438 is capable of 200 Ksps. Without sinc interpolation/filtering of sampled data, you can start to see sine pattern when there's around 10 or more samples per period, so at 200Ksps with your approach of direct sample plotting max sine frequency would be 20KHz. At 15KHz sample rate accordingly 1.5KHz.

    PRASANTH S said:
    Now you can tell me where I have to add delimeter

    Thank you, I am glad to get your permission.

    Comma delimiter marked red:

    sprintf(str,"%03d,",ADC_result);

    PRASANTH S said:
    and why??

    I already told you. It's so sad that many like you do not even bother to read whole answer carefully. It strongly demotivates to continue helping.

  • Ilmars said:
    I already told you. It's so sad that many like you do not even bother to read whole answer carefully. It strongly demotivates to continue helping.

    Quite true. Sometimes, I can "smell" that from the very first post, and avoid to get involved at all.

    This is a help forum, not a "get my stuff done" forum. A certain level of understanding and willingness on the side od the enquirer can/ must be expected. This is not the place to regurgitate the C language basics, Kirchoff's law, or the datasheet.

    And Phyton-related question are better posted on a Phyton forum, or Stackexchange.com. That raises the chance for a proper answer exponentially.

**Attention** This is a public forum