My IDE configuration using Notepad++, ampy and Tera Term

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
User avatar
aivarannamaa
Posts: 40
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by aivarannamaa » Sun Mar 01, 2020 2:53 pm

stanely wrote:
Sun Mar 01, 2020 2:18 pm
This is probably off topic from this thread, but are you using flow control when communicating to MicroPython targets? I'm using Ampy and esptool at crazy fast baud rates without any issues, ever. I can't imagine all of that would work reliably without use of CTS/RTS flow control.
I assumed I can't use CTS/RTS if MicroPython also supports it. How did you use it? I don't see any reference to CTS/RTS in Ampy code: https://github.com/scientifichackers/am ... rd.py#L133

stanely
Posts: 40
Joined: Fri Jan 17, 2020 5:19 am
Location: Ohio, USA

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by stanely » Sun Mar 01, 2020 5:06 pm

aivarannamaa wrote:
Sun Mar 01, 2020 2:53 pm
stanely wrote:
Sun Mar 01, 2020 2:18 pm
This is probably off topic from this thread, but are you using flow control when communicating to MicroPython targets? I'm using Ampy and esptool at crazy fast baud rates without any issues, ever. I can't imagine all of that would work reliably without use of CTS/RTS flow control.
I assumed I can't use CTS/RTS if MicroPython also supports it. How did you use it? I don't see any reference to CTS/RTS in Ampy code: https://github.com/scientifichackers/am ... rd.py#L133
You're right, I see no mention of flow control. I don't know. Does this happen mostly when you're receiving or sending data?

User avatar
aivarannamaa
Posts: 40
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by aivarannamaa » Mon Mar 02, 2020 5:53 pm

stanely wrote:
Sun Mar 01, 2020 5:06 pm
Does this happen mostly when you're receiving or sending data?
I don't know, it is not clear from the reports.

pmulvey
Posts: 42
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by pmulvey » Tue Mar 24, 2020 9:44 pm

I get bouts of ampy complaining that it cannot enter raw REPL on the ESP8266. I say bouts because sometimes it's fine but after a while it starts to act up. I tried out the ESP32 and the problem became almost constant. I delved into the ampy module "pyboard.py" and noticed that the code made just one attempt at entering raw REPL with a 2 CTRL-C's followed by a CTRL-A. I changed the code to do multiple retries.
The original looks like this starting at line 184:

Code: Select all

        while n > 0:
            self.serial.read(n)
            n = self.serial.inWaiting()


        self.serial.write(b'\r\x01') # ctrl-A: enter raw REPL
        data = self.read_until(1, b'raw REPL; CTRL-B to exit\r\n>')

        if not data.endswith(b'raw REPL; CTRL-B to exit\r\n>'):
            print(data)
            raise PyboardError('could not enter raw repl')
Made the following change:

Code: Select all

        while n > 0:
            self.serial.read(n)
            n = self.serial.inWaiting()

        for retries in range(0, 8):
            self.serial.write(b'\r\x03\x03')
            time.sleep(.1)
            self.serial.write(b'\r\x01') # ctrl-A: enter raw REPL
            data = self.read_until(1, b'raw REPL; CTRL-B to exit\r\n>', .2)
            if data.endswith(b'raw REPL; CTRL-B to exit\r\n>'):
                break
            print (retries)
        
        if not data.endswith(b'raw REPL; CTRL-B to exit\r\n>'):
            print(data)
            raise PyboardError('could not enter raw repl')
Ampy now gets the raw REPL everytime on the ESP32, will have to monitor its performance with ESP8266 over a period of time because as I said it was working a lot of the time.
Paul Mulvey

User avatar
dhylands
Posts: 3393
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by dhylands » Tue Mar 24, 2020 11:36 pm

Yeah - I had to make a similar change to rshell to get it working more reliably on ESP8266 and ESP32.

rshell sends a Control-C every 100 milliseconds until it gets a >>> before continuing with pyboard.py.

The reason is that the boards can take a while before micropython starts up, and with some boards, opening the serial port causes the board to reset, and the startup delay then pushes the micrpython start beyond where pyboard.py expects the Control-C's to work.

schillerx
Posts: 1
Joined: Wed Mar 25, 2020 10:57 am

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by schillerx » Thu Mar 26, 2020 5:08 am

Hello,

I'm using Thonny and are happy most of the time, especially because I haven't found so much alternative IDEs. Thank you for your work on this!!!

One question: is there a way to get auto completion?

Sometimes the serial connection to the boards and the access to the filesystems seems to be buggy.

For example:

- when I open files directly on the device the below window of thonnys shows all files and the connection is broken.
- I have to reconnect the cable and press the start/stop button

--> I can prevent this by doing the following after connect the device with Thonny:
- in the repl console:
-> import os
-> os.listdir()

Sounds crazy I know but works for me... :)

Im using TTGO boards with Wrover and Wroom Chips of ESP32 (TTGO T-Energy T18 / ESP-WROOM-32 ESP-32s). It is everytime the same experiences. I also tried to update my windows 10 drivers but without success.

If you are interested I can try to help you to find and debug this issues...


Greetings!

User avatar
aivarannamaa
Posts: 40
Joined: Fri Sep 22, 2017 3:19 pm
Location: Estonia
Contact:

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by aivarannamaa » Thu Mar 26, 2020 6:21 am

schillerx wrote:
Thu Mar 26, 2020 5:08 am
If you are interested I can try to help you to find and debug this issues...
Sure! Please copy your issue and workaround to https://github.com/thonny/thonny/issues

I have started refactoring the MicroPython part of Thonny. Hopefully next version will be more reliable.

Code completion can be invoked with Ctrl+Space, but at the moment you can't have it automatically (https://github.com/thonny/thonny/issues/625)

pmulvey
Posts: 42
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by pmulvey » Tue Mar 31, 2020 8:23 am

With my code on the ESP8266 getting bigger by the day I was now running into the "memory allocation" errors. Having pulled out all of my hair and exposing skull bone I think that I have a solution. For some reason I have only now discovered the simple way to use mpy_cross [https://pypi.org/project/mpy-cross/] rather than using VMs on windows etc. Just install it as per PyPi. I have now modified the Notepad++ NppExec script as follows and added more comments and everything is working... so far! Someone out there will tell me what horrible mistakes I am making, but for now all is good. My project has been extended now from an educational development board for ESP8266 to include an expansion IO board. On this board I have 4 Arduinos as I2C slaves on the same bus, all running identical programs. They set their individual I2C addresses by reading their own analogue port which has different resistor dividers. I just throw commands at them from the ESP to carry out all sorts of IO (Read/Write/Servo/PWM/IR etc). Speed-wise I can get a 900Hz output on the Arduino having sent On/Off commands and having them processed by a command handler on the Arduinos. I can only make 600Hz with the python code on the dev board addressing the board's own PCF8574 chips! I'm including a photo of the work in progress, I'm making great progress thanks to Covid-19... silver lining etc!

Notepad++ NppExec script:

Code: Select all

// disable output to the Console
NPP_CONSOLE -

set port = COM4

// Set this variable to point at the path to python
set PyPath = C:\Users\Me\AppData\Local\Programs\Python\Python38-32\

set PyExec = $(PyPath)python.exe

// make sure we are in the directory of the file we are editing
cd  $(CURRENT_DIRECTORY)

//  check and see if this is the folder that has the boot.py file in it
//  because the folder below this is Globals and this script runs differently
//  for the file there where all of my library file are

//  capture the output of the next command in $(OUTPUTL) variable
npe_console v+
cmd /c if exist "boot.py" echo Exists
npe_console v-

if "$(OUTPUTL)" = "Exists"
    //  the boot.py file is here so we know that the edited file is in the workspace folder
    //  save this file first
    NPP_SAVE

    //   step up one folder to get at the DisTeraTerm.py script
    //   DisTeraTerm finds the TeraTerm app and sends key strokes to it to disconnect the COM port
    cd..
    
    //   show results of DisTeraTerm and ampy on the console
    NPP_CONSOLE +
    $(PyExec) DisTeraTerm.py $(port)

    //   now send the file to the device using ampy
    $(PyPath)scripts\ampy --port $(port) put $(FULL_CURRENT_PATH)

    //   File is downloaded so we send a CTRL-D to the device for a soft reboot
    $(PyExec) SendCTRLD.py $(port)

    //   Reconnect TeraTerm to COM port
    $(PyExec) ConTeraTerm.py
else
    //  this file is not in the workspace folder, must be in Globals
    NPP_SAVE
    
    //  need to step up twice to get at DisTeraTerm
    cd..
    cd..
    NPP_CONSOLE + 
    $(PyExec) DisTeraTerm.py $(port)
    
    //  every file in the Globals folder will be cross-compiled first
    //  as it is assumed to be a library file and removes the need for the device
    //  to compile it which causes "memory allocation" errors sometimes
    $(PyExec) -m mpy_cross $(FULL_CURRENT_PATH)

    //  for some reason ampy was not running with the newly created .mpy file
    //  I stuck in a delay of 300ms as a temporary kludge 
    sleep 300
    
    //  this ampy line is different from the previous one because I had to
    //  build the name of the file with the .mpy extension rather than use $(FULL_CURRENT_PATH)
    //  also the file needs to be put into the Globals folder on the device
    $(PyPath)scripts\ampy --port $(port) put $(CURRENT_DIRECTORY)\$(NAME_PART).MPY \Globals\$(NAME_PART).MPY
   
    $(PyExec) SendCTRLD.py $(port)
    $(PyExec) ConTeraTerm.py
    NPP_CONSOLE +   
exit

echo No
Attachments
20200331_091159.jpg
20200331_091159.jpg (254.1 KiB) Viewed 428 times
Paul Mulvey

bitninja
Posts: 131
Joined: Thu Sep 15, 2016 4:09 pm
Location: Spring, Texas

Alternative Updated

Post by bitninja » Fri Apr 03, 2020 6:25 am

All of this discussion on IDEs has inspired me to work on some improvement for the tool I use.

https://github.com/joewez/AmpyFileManager

It's an editor wrapped around the ampy utility with a few extra features to make life easier. :D .
afm.png
afm.png (57.31 KiB) Viewed 379 times

pmulvey
Posts: 42
Joined: Sun Jul 29, 2018 8:12 am
Location: Athlone, Ireland

Re: My IDE configuration using Notepad++, ampy and Tera Term

Post by pmulvey » Wed Apr 15, 2020 3:00 pm

I downloaded the zipped binary but it will not connect to my ESP8266. Refresh seems to be doing something but nothing appears. I edited the xml file to launch my TeraTerm:

Code: Select all

      <add key="TerminalApp" value="C:\Program Files (x86)\TeraTerm\ttermpro.exe"/>
      <add key="TerminalAppArgs" value="-serial COM4"/>
      
I just get Invalid Host from TeraTerm.
Paul Mulvey

Post Reply