Sending serial commands from python
Posted: Thu Apr 21, 2022 11:20 am
Hi, I'm new to micropython (and loving it so far), so maybe this is an easy to solve problem, but I've been stuck for a while.
Let's say the following code is uploaded to the main.py file on the microcontroller:
I want to then run python code on a laptop that sends, for example, led.value(1) to the microcontroller and have the microcontroller execute it, similar to the repl console. I don't want to use the repl console itself, as this should eventually be automated and integrated into a bigger system running in python on the laptop.
So far I have managed to send it, but not execute it. I run the following code on the laptop:
but the led does not turn on until I run ser.close() and then connect the repl console. This let's me think the microcontroller successfully received led.value(1), but does not run it until the repl console connects.
Is there something I can do to make the microcontroller run it without having to connect to the repl console? I've tried ser.write(b'\n') but it doesn't do anything.
I'm using the pico go extension in vs code on windows 10
Thanks in advance
Let's say the following code is uploaded to the main.py file on the microcontroller:
Code: Select all
from machine import Pin
led = Pin(25, Pin.OUT)
So far I have managed to send it, but not execute it. I run the following code on the laptop:
Code: Select all
import serial
ser = serial.Serial(port='/COM3', baudrate = 115200, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, timeout=1)
ser.write(b'led.value(1)')
Is there something I can do to make the microcontroller run it without having to connect to the repl console? I've tried ser.write(b'\n') but it doesn't do anything.
I'm using the pico go extension in vs code on windows 10
Thanks in advance