Bottom Page

Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Receive Serial Data and store in different Variables in Python
#1
Hi, I am using a wireless modem which is connected with FTDI32 chip. The modem is receiving the values from Wireless Temperature sensor.
I am working on a project in which I want to receive the values of the wireless sensor which is transmitted to the wireless modem in my laptop and with the help of python code, I want to convert the data and display in my message box.

As in mentioned below manual, there are different registers which contain hexadecimal values and I need to store the register values in different variables using python

Any suggestion on this will be a great help.

https://ncd.io/long-range-iot-wireless-t...ct-manual/
Quote
#2
What is your question?
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#3
Hi, Actually, I have created this code in which I am receiving the data from Arduino using serial communication in string format.

import serial
ard = serial.Serial('COM4', 9600);
while True:
  k = ard.readline().decode('ascii');
  print(k)


I want to store the information in 3 different python variables. Do I need to use a buffer to store the received data? how will the code be?

According to my search on the internet, the buffer is used to slice the string.
As beginner python world I need some suggestion which helps me to create the temperature monitoring system.
Will be looking forward to your advice on this.
Quote
#4
It depends on what the contents of k are here. For example, you could do something like this
k = "1,2,3"
a, b, c = k.split()
Make sure to provide enough detail for us to help (e.g. what k looks like).
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Quote
#5
Thanks for the help, Actually I am receiving the data as mentioned below

hello\r\n
hello1\r\n
hello2\r\n

I just want to store the data in such a way that
>hello will be stored in variable a
>hello1 will be stored in variable b
>hello2 will be stored in variable c

and the \n\r will be minimized from the serial data
Quote
#6
jenkins43 Wrote:>hello will be stored in variable a
Store it in a dictionary,that's what Python dos Think
If look closer at it when do a = 'hello',so do Python store this is in globals() dictionary.
>>> a = 'hello'

# how it look in globals 
'a': 'hello',

# Use this dictionary
>>> globals()['a']
'hello'
So this make a visible dictionary record.
import io

# Simulate serial data
ard = io.StringIO('''\
hello\r\n
hello1\r\n
hello2\r\n''')

record = {}
lst =  ['a', 'b', 'c']
while True:
    k = ard.readline()
    if k == '':
        break
    try:
        if k == '\n':
            pass
        else:
            record[lst.pop(0)] = k.strip('\r\n')
    except IndexError:
        pass 
Test:
>>> record
{'a': 'hello', 'b': 'hello1', 'c': 'hello2'}
>>> record['b']
'hello1'
>>> record['c']
'hello2'
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Can't transmit serial fast Python to Arduino pyserial mRKlean 0 47 Mar-29-2020, 08:12 PM
Last Post: mRKlean
  Read Data from Serial Port PA3040 3 202 Feb-16-2020, 04:54 AM
Last Post: PA3040
  Read csv file, parse data, and store in a dictionary markellefultz20 4 546 Nov-26-2019, 03:33 PM
Last Post: DeaD_EyE
  Reading blob data from database by python and store it in .zip format Adityasi 2 341 Nov-18-2019, 05:22 PM
Last Post: ibreeden
  How do I install apps from google play store? using python + selenium.. mongo 0 380 Aug-05-2019, 12:41 AM
Last Post: mongo
  How to reuse data from variables? LsGam91 2 315 Jul-27-2019, 06:09 AM
Last Post: LsGam91
  Receive data from Redis RQ worker process freak14 0 317 Jul-15-2019, 12:39 PM
Last Post: freak14
  Store a python list of lists in a database to use for searches later on klllmmm 3 592 Jun-20-2019, 07:54 AM
Last Post: buran
  Serial to telnet using Python Charles_Linquist 2 1,166 Jun-17-2019, 04:37 PM
Last Post: DeaD_EyE
  a contact book - a class made to store data apollo 2 435 Jun-12-2019, 04:33 PM
Last Post: apollo

Forum Jump:


Users browsing this thread: 1 Guest(s)