<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How to send Lopy received data to a computer via serial port?]]></title><description><![CDATA[<p dir="auto">Dear all,</p>
<p dir="auto">I have a big problem, as I cannot find a way to send data from my Lopy to my computer via serial port.<br />
From the beggining: I have to lopys that communicate through LORA to each other sending short messages if they are within the range to connect to each other (one asking if in range and receiving the answer, second one listening and answering if it is in range). What I want to do now, is to be able to see the answer &quot;in range&quot; on my computer, when lopy is connected to it via serial port.  I understand that first I need to modify my code on lopy so it is sending the message to the PC and later in py write a code to read it but I do not know how to do that and where to start....</p>
<p dir="auto">any help will be much appreciated!!!!!</p>
<p dir="auto">Monika</p>
]]></description><link>https://forum.pycom.io/topic/2000/how-to-send-lopy-received-data-to-a-computer-via-serial-port</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 16:07:58 GMT</lastBuildDate><atom:link href="https://forum.pycom.io/topic/2000.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 17 Oct 2017 13:49:12 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Tue, 17 Oct 2017 13:49:12 GMT]]></title><description><![CDATA[<p dir="auto">Dear all,</p>
<p dir="auto">I have a big problem, as I cannot find a way to send data from my Lopy to my computer via serial port.<br />
From the beggining: I have to lopys that communicate through LORA to each other sending short messages if they are within the range to connect to each other (one asking if in range and receiving the answer, second one listening and answering if it is in range). What I want to do now, is to be able to see the answer &quot;in range&quot; on my computer, when lopy is connected to it via serial port.  I understand that first I need to modify my code on lopy so it is sending the message to the PC and later in py write a code to read it but I do not know how to do that and where to start....</p>
<p dir="auto">any help will be much appreciated!!!!!</p>
<p dir="auto">Monika</p>
]]></description><link>https://forum.pycom.io/post/11900</link><guid isPermaLink="true">https://forum.pycom.io/post/11900</guid><dc:creator><![CDATA[monersss]]></dc:creator><pubDate>Tue, 17 Oct 2017 13:49:12 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Tue, 17 Oct 2017 15:49:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1814">@monersss</a> Like you said, you need an instance to a) send data from the LoPy and to b) receive it on the PC. Lets assume you decide to use printable characters in the messages.<br />
a) This is easy, especially if you decide to use UART0, since by default in _boot.py UART 0 is connected to the REPL. To get data about of UART 0, simple use print statements. UART0 is connected to the SERIAL/USB bridge on the expansion board, so this is pretty convenient. Otherwise, you have to open a UART and write to it, like using UART 1 at 115200 baud.</p>
<pre><code>from machine import UART
uart = UART(1, 115200)
...
uart.write(&quot;value = %d\n&quot; % value)
</code></pre>
<p dir="auto">value is here an arbitrary name for something to send. I use here \n at the end of the write to send the data nicely in lines, so you could see it in the PC well ordered, even with a terminal software<br />
b) This is an example of  a little python3 script, which receives the data from the USB serial and puts it optionally into a file. It requires <a href="http://pyserial.py" target="_blank" rel="noopener noreferrer nofollow">pyserial.py</a> to be installed beforehand, with <code>pip3 install pyserial</code></p>
<pre><code>import sys
import serial
from time import sleep


def main():
    if len(sys.argv) &gt; 1:
        port = sys.argv[1]
        if len(sys.argv) &gt; 2:
            filename = sys.argv[2]
            try:
                f = open(filename, &quot;w&quot;)
            except:
                print(&quot;Could not open file:&quot;, filename)
                return
        else:
            f = None
# open file
        try:
            ser = serial.Serial(port, 115200)
            sleep(3)
            ser.reset_input_buffer()
        except Exception as err:
            print(&quot;Could not connect: {!r}&quot;.format(err))
            return
        print(&quot;Data connection at:&quot;, port)
        while True:
            try:
                line = ser.readline().decode().rstrip(&quot;\r\n&quot;)
                if line != '': # Still alive?
                    print(line)
                    if f is not None:
                        f.write(line + &quot;\r\n&quot;)
                else: # EOF
                    break
            except Exception as err:
                print(&quot;{!r}&quot;.format(err))
                break
            except KeyboardInterrupt:
                print(&quot;Interrupted!&quot;)
                break
        if f is not None:
            f.close()
    else:
        print(&quot;Usage: usbrecv port [filename]&quot;)

if __name__ == &quot;__main__&quot;:
    main()
</code></pre>
]]></description><link>https://forum.pycom.io/post/11904</link><guid isPermaLink="true">https://forum.pycom.io/post/11904</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Tue, 17 Oct 2017 15:49:06 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Tue, 17 Oct 2017 16:49:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> Hello, thanks for a fast answer. I still cannot get anything printed out on my putty screet. The code in my <a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow">main.py</a> in first lopy is this one:</p>
<p dir="auto">from network import LoRa<br />
import socket<br />
import time<br />
from machine import UART</p>
<p dir="auto">uart = UART(1, 115200)</p>
<p dir="auto">lora = LoRa(mode=LoRa.LORA, frequency=863000000)<br />
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)<br />
s.setblocking(False)<br />
while True:<br />
s.send('In range?')<br />
my_message = s.recv(64)</p>
<pre><code>if len(my_message) &gt; 0:
    uart.write(&quot;my_message\n&quot;)
else:
    uart.write(&quot;out of range\n&quot;)

time.sleep(10)
</code></pre>
<p dir="auto">it is connected via serial to PC and when i connect via Putty I get nothing</p>
<p dir="auto">the code on second lopy is this one:</p>
<p dir="auto">from network import LoRa<br />
import socket<br />
import time</p>
<p dir="auto">lora = LoRa(mode=LoRa.LORA, frequency=863000000)<br />
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)<br />
s.setblocking(False)</p>
<p dir="auto">while True:<br />
if s.recv(64) == b'In range?':<br />
s.send('You are within LORA range!')</p>
<pre><code>time.sleep(10)
</code></pre>
<p dir="auto">everything works perfect when i operate with Atom....</p>
<p dir="auto">Where do i make a mistake??</p>
]]></description><link>https://forum.pycom.io/post/11907</link><guid isPermaLink="true">https://forum.pycom.io/post/11907</guid><dc:creator><![CDATA[monersss]]></dc:creator><pubDate>Tue, 17 Oct 2017 16:49:36 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Tue, 17 Oct 2017 18:27:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1814">@monersss</a> Which USB/UART connection do you use? If you use the expansion board, the you have to open UART 0. So the line above must read as:<br />
uart = UART(0, 115200)<br />
Then you should see something in Putty.<br />
Another reason why you may not see messages with Putty may be its flow control. Please set Putty's flow control to 'off'.</p>
]]></description><link>https://forum.pycom.io/post/11911</link><guid isPermaLink="true">https://forum.pycom.io/post/11911</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Tue, 17 Oct 2017 18:27:53 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Tue, 17 Oct 2017 20:47:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> I am connecting via expantion board micro usb, so I understand that i need to update my code changing uart:  uart = UART(0, 115200) right?<br />
PS there are two uart buses that i can connect to, does it mean i can connect lopy to one device to receive data from one source and to another one to receive data from another data source?</p>
]]></description><link>https://forum.pycom.io/post/11913</link><guid isPermaLink="true">https://forum.pycom.io/post/11913</guid><dc:creator><![CDATA[monersss]]></dc:creator><pubDate>Tue, 17 Oct 2017 20:47:42 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 06:24:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1814">@monersss</a> Yes, you can use both UARTs.But only one of them is connected to the USB/Serial bridge on the expansion board. UART1, connected to P3/P4, has just it's digital outputs. So if you want to use it for USB or standard RS232, you have to add an appropriate adapter.</p>
]]></description><link>https://forum.pycom.io/post/11920</link><guid isPermaLink="true">https://forum.pycom.io/post/11920</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Wed, 18 Oct 2017 06:24:04 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 09:33:42 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> i cannot see the messages on putty. I have set the flow control to none and still not working. The code is ok, when running it from atom i am getting response, so it seems there is a problem with my uart code i guess?</p>
]]></description><link>https://forum.pycom.io/post/11928</link><guid isPermaLink="true">https://forum.pycom.io/post/11928</guid><dc:creator><![CDATA[monersss]]></dc:creator><pubDate>Wed, 18 Oct 2017 09:33:42 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 09:51:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1814">@monersss</a> How do you connect with Atom? Are you using Telnet? If not, did you close Atom when you tried to use the UART? And are you sure that you are using the right COM port on your PC?</p>
]]></description><link>https://forum.pycom.io/post/11929</link><guid isPermaLink="true">https://forum.pycom.io/post/11929</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Wed, 18 Oct 2017 09:51:53 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 09:58:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> i connect to atom via serial, before trying to connect with putty to serial port i disconnect with atom. the port i am using is ok. serial setting are speed 115200, data bits 8, stop bits 1, parity none, flow control none.</p>
<p dir="auto">Maybe i am missing part of the code where i define data bits and stop bits so they are defined exactly like the ones in putty?</p>
<p dir="auto">PS i have updated the firmware on my lopys and running my code from <a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow">main.py</a> on both. in atom everything is ok</p>
]]></description><link>https://forum.pycom.io/post/11930</link><guid isPermaLink="true">https://forum.pycom.io/post/11930</guid><dc:creator><![CDATA[monersss]]></dc:creator><pubDate>Wed, 18 Oct 2017 09:58:16 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 10:15:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1814">@monersss</a> 8 data bits/1 stop bit is the default.<br />
When you have connected Putty and push reset, do you see the boot messages ot the bootstrap loader in Putty, and the first Microypthon Banner? Because these are definitely sent to UART0. If not, then there is a problem with Putty. If yes, then UART0 is properly connected, and unless you changed _boot.py, REPL is connecetd to the UART, and you can for instance terminate your code with Ctrl-C.  If you want to disconnect REPL from the UART, you have to use the statement <code>os.dupterm(None)</code><br />
If you keep REPL connected to UART, you can use print() statements instead of uart.write() in your code.</p>
]]></description><link>https://forum.pycom.io/post/11931</link><guid isPermaLink="true">https://forum.pycom.io/post/11931</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Wed, 18 Oct 2017 10:15:37 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 10:23:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> yes i can see the rester going on on putty and the micropython prompt. I did not change <a href="http://boot.py" target="_blank" rel="noopener noreferrer nofollow">boot.py</a>, only <a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow">main.py</a> which looks like that now:</p>
<p dir="auto">from network import LoRa<br />
import socket<br />
import time<br />
from machine import UART<br />
uart = UART(0, 115200)<br />
lora = LoRa(mode=LoRa.LORA, frequency=863000000)<br />
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)<br />
s.setblocking(False)<br />
while True:<br />
s.send('In range?')<br />
my_message = s.recv(64)<br />
if len(my_message) &gt; 0:<br />
uart.write(my_message)<br />
else:<br />
uart.write(&quot;out of range&quot;)<br />
time.sleep(10)</p>
<p dir="auto">I do not want to run a code from putty but to run it from main and only see messages sent between two lopys in putty, the final step will be to receive through spyder, but as a first step i wanted to see if they are sent by lopy to a computer correctly.</p>
]]></description><link>https://forum.pycom.io/post/11933</link><guid isPermaLink="true">https://forum.pycom.io/post/11933</guid><dc:creator><![CDATA[monersss]]></dc:creator><pubDate>Wed, 18 Oct 2017 10:23:21 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 10:45:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/98">@robert-hh</a> maybe here is the answer:</p>
<p dir="auto">seems that there is some error in <a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow">main.py</a> line 6 OSError: the requested operation failed, thats what i get when restarting the board:</p>
<p dir="auto">rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)<br />
ets Jun  8 2016 00:22:57</p>
<p dir="auto">rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)<br />
configsip: 0, SPIWP:0xee<br />
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00<br />
mode:DIO, clock div:1<br />
load:0x3fff9010,len:12<br />
ho 0 tail 12 room 4<br />
load:0x3fff9020,len:388<br />
load:0x40078000,len:11584<br />
load:0x4009fb00,len:848<br />
entry 0x4009fc9c<br />
Traceback (most recent call last):<br />
File &quot;<a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow">main.py</a>&quot;, line 6, in &lt;module&gt;<br />
OSError: the requested operation failed<br />
MicroPython v1.8.6-796-g489fafa0 on 2017-10-15; LoPy with ESP32<br />
Type &quot;help()&quot; for more information.</p>
<blockquote>
<blockquote>
<blockquote></blockquote>
</blockquote>
</blockquote>
<p dir="auto">and the line 6 in <a href="http://main.py" target="_blank" rel="noopener noreferrer nofollow">main.py</a> is an uart line:<br />
uart = UART(0, 115200)</p>
]]></description><link>https://forum.pycom.io/post/11935</link><guid isPermaLink="true">https://forum.pycom.io/post/11935</guid><dc:creator><![CDATA[monersss]]></dc:creator><pubDate>Wed, 18 Oct 2017 10:45:17 GMT</pubDate></item><item><title><![CDATA[Reply to How to send Lopy received data to a computer via serial port? on Wed, 18 Oct 2017 10:45:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://forum.pycom.io/uid/1814">@monersss</a> Then, start your script with:</p>
<pre><code>from network import LoRa
import socket
import time
import os
os.dupterm(None)
...
</code></pre>
]]></description><link>https://forum.pycom.io/post/11936</link><guid isPermaLink="true">https://forum.pycom.io/post/11936</guid><dc:creator><![CDATA[robert-hh]]></dc:creator><pubDate>Wed, 18 Oct 2017 10:45:43 GMT</pubDate></item></channel></rss>