Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65424

Re: Logging data from Arduino using PySerial

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'log:': 0.05; 'float': 0.07; 'slow.': 0.09; 'subject:using': 0.09; 'python': 0.11; 'csv': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'once.': 0.16; 'received:192.168.1.4': 0.16; 'storing': 0.16; 'subject:Logging': 0.16; 'subject:PySerial': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'written': 0.21; 'header:User-Agent:1': 0.23; 'file.': 0.24; "i've": 0.25; 'script': 0.25; 'header:In-Reply- To:1': 0.27; "i'm": 0.30; 'quite': 0.32; 'subject:from': 0.34; 'could': 0.34; 'convert': 0.35; 'but': 0.35; 'there': 0.35; 'subject:data': 0.36; 'done': 0.36; 'doing': 0.36; 'skip:o 20': 0.38; 'filter': 0.38; 'to:addr:python-list': 0.38; 'moving': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'experts': 0.60; 'new': 0.61; "you're": 0.61; 'thomas': 0.65; 'here': 0.66; "'for'": 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=eZmzft0H c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=5FYZ9MsUIQAA:10 a=O_qnyQjlGLMA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=PV-7yLr6PzEA:10 a=ETQvedASZYBJXYooK58A:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett:2500
Date Tue, 04 Feb 2014 14:05:06 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Logging data from Arduino using PySerial
References <e3b195f8-5a17-4536-9926-2b2ab193719c@googlegroups.com>
In-Reply-To <e3b195f8-5a17-4536-9926-2b2ab193719c@googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6388.1391522708.18130.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1391522708 news.xs4all.nl 2911 [2001:888:2000:d::a6]:60519
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:65424

Show key headers only | View raw


On 2014-02-04 04:07, Thomas wrote:
> I've written a script to log data from my Arduino to a csv file. The script works well enough but it's very, very slow. I'm quite new to Python and I just wanted to put this out there to see if any Python experts could help optimise my code. Here it is:
>
[snip]
>      # Cleaning the data_log and storing it in data.csv
>      with open('data.csv','wb') as csvfile:
>          for line in data_log:
>              line_data = re.findall('\d*\.\d*',line) # Find all digits
>              line_data = filter(None,line_data)    # Filter out empty strings
>              line_data = [float(x) for x in line_data] # Convert Strings to float
>
>              for i in range(1,len(line_data)):
>                  line_data[i]=map(line_data[i],0,1023,0,5)
>
You're doing this for every in line the log:

>              csvwrite = csv.writer(csvfile)
[snip]

Try moving before the 'for' loop so it's done only once.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Logging data from Arduino using PySerial Thomas <t.tchorzewski@gmail.com> - 2014-02-03 20:07 -0800
  Re: Logging data from Arduino using PySerial Chris Angelico <rosuav@gmail.com> - 2014-02-04 15:47 +1100
    Re: Logging data from Arduino using PySerial Thomas <t.tchorzewski@gmail.com> - 2014-02-03 20:57 -0800
      Re: Logging data from Arduino using PySerial Chris Angelico <rosuav@gmail.com> - 2014-02-04 16:18 +1100
  Re: Logging data from Arduino using PySerial Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-04 08:56 -0500
  Re: Logging data from Arduino using PySerial MRAB <python@mrabarnett.plus.com> - 2014-02-04 14:05 +0000

csiph-web