Score:0

Put timestamps on data gathered from serial port

kr flag

I use this code: https://www.pythonpool.com/python-serial-read/ and more specifically the code under the paragraph: Reading Data From Arduino Boards using Python Serial Read. The data I get are like this:

123,344,555,661

124,345,674,611

1024,555,643,677

So it puts a line between 2 lines of data. I checked it with the command python3 mycode.py > output.txt and the problem is the same: an empty line between 2 lines of data. I have two questions:

  1. How do I delete the empty lines?
  2. How do I put timestamp in front of each line of data?
Score:1
US flag

You would probably want to add some code to your python script to include the date in the print statement on line 15.

This stackoverflow article talks about dates & times : https://stackoverflow.com/questions/2158347/how-do-i-turn-a-python-datetime-into-a-string-with-readable-format-date

Python is a very powerful tool - and has lots of easy to use features hiding within. Google is your friend for learning more about them.

Good luck!

just_learning avatar
kr flag
Ok, I managed to fix it, BUT the code writes each character to a different cell. I need to write for example the number "1023" to one cell, and NOT "1" to one cell, then "0" to another cell, "2" to another cell etc... What should I do?
Charles Bedford avatar
md
Hard to say without seeing the code you have. Cust and paste your print statement, and we'll talk :)
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.