How to see print() output and REPL from VSCode?



  • I followed all the instructions to install VSCode on Windows, and the M5Stack plugin for VSCode, I am able to blink the LED on my M5Stick-C so far.

    How can I view the outputs of my print statements?

    How can I use the MicroPython REPL?

    The "OUTPUT" tab of VSCode is always blank, and none of these options shows me the REPL or serial print output

    0_1653536864625_b9ffe56b-4a5c-4a58-907c-390c4a5995a3-image.png

    The "TERMINAL" tab is always showing me Windows Powershell

    When VSCode is connected to the M5Stick, no other serial port terminal program (such as Putty, TeraTerm, RealTerm, etc) is able to access the COM port. I cannot just run some sort of command line serial port terminal through Powershell since the port is occupied

    If I disconnect VSCode, I get the error 0_1653536701744_1b8925ae-9caf-49e5-83f9-587e178273cd-image.png , so disconnecting to use an external terminal app is not an option

    I feel like I am missing something obvious... Please help me view my print output from within VSCode without disconnecting the COM port





  • @robalstona said in How to see print() output and REPL from VSCode?:

    Try this extension
    https://marketplace.visualstudio.com/items?itemName=curdeveryday.vscode-m5stack-mpy

    Thanks I have already installed that. Where in that extension can you see serial port print output while simultaneously being able to access the files?



  • I have the same problem Frank. I have yet to be able to do this. It's very frustrating and a real limitation of the devices IMHO. I really wish they would make this work as they hardware is perfect for small IOT devices, or if there is some way to do it they would TELL US!

    As a work around I set up an MQTT publish to send the equivalent of print statements to a MQTT mosquitto server so I can subscribe and read them on another device . Here's an example of the micropython below. Note that I run mqtt.start() in the main.py because I am also using subscribe in main app for another purpose.

    Note that you need to supply the ip of the mqtt server. And choose your own topic of course
    It should act like a real print statement so you can mix and match object types, plus I added a "name" argument so you can specify where the code is coming from . The print statement prints "{name} -- {print contents}

    Tailor to suit .
    e.g
    in main.py

    from mprint import *
    
    try:
        m=1.008
        b= 29       
        mPrint("slope",m,"intercept",b)
        mPrint("slope: {}, intercept: {}".format(m,b))
        mPrint(json.dumps(records),name="imuTest")
        mPrint(dir(imi))
    except Exception as e:
        mPrint("failed",e)
    

    mprint.py

    from m5mqtt import M5mqtt
    import io
    
    try:
    	mqtt
    except:
    	mqtt = M5mqtt('servo','192.168.x.x', 1883,'','',300)
    
    def mPrint(*args,name =__name__,**kwargs):
    	outs = ptos(*args,**kwargs)
    	x="{}  -- {}".format(name,outs)
    	mqtt.publish(str('m5logs'),x)
    
    def ptos(*args,**kwargs):
    	output = io.StringIO()
    	print(*args, file=output, **kwargs)
    	contents = output.getvalue()
    	output.close()
    	return contents
    
    
    if __name__ == "flow.m5ucloud":
    	mqtt.start()
    	mPrint("test message")
    


  • While not quite the same, on the Core 2, Tough and Fire boards you can use Advanced > BLE UART in UIFlow (or the equivalent Micropython/ Arduino/ESP-IDF/Zephyr code) to wirelessly send logs to any Nordic BLE UART terminal, including web NUS consoles like https://wiki.makerdiary.com/web-device-cli/

    Just visit that page on a BLE enabled desktop using Chrome or Firefox and pair your device once it has BLE UART running. Even works to send commands back to the M5stack if you set up receiving in your esp32 app.



  • Currently my solution is that I wrote software that tunnels data between a virtual serial port and a real one, while displaying it to me. It uses com0com to setup the fake serial port.

    Basically, m5stick is COM4, com0com is configured with fake COM6 and COM7. COM6 is connected to COM4 via my app and I can see the text in between them and inject keystroke too. VSCode talks with COM7 and all of the data from COM7 goes to COM6, to my screen, then to COM4

    I also coded it so if I hit ESC, it sends the CTRL-C signal to the terminal so it brings up REPL. (pressing CTRL-C will quit the whole terminal lol)

    This solution still sucks, exceptions are still printed to the LCD instead of to the COM port