jeffmer / TTGO-T-watch-2020-Micropython-OS

All micropython watch software for TTGO T-watch 2020 V1, V2 & V3
The Unlicense
19 stars 5 forks source link

Possible mpy-cross / mpy issue? #1

Closed andypiper closed 1 year ago

andypiper commented 1 year ago

This project looks exciting, but I'm failing to get it to work on my T-watch.

Installed the firmware successfully, using Thonny as suggested (nb I'm on a Mac). Incidentally, this ends up with a boot.py file visible on the device, with all of the lines commented out.

Edited config.py to add network and OpenWeatherMap keys.

Went to compile the code, realised that the compile.sh points to a local copy of mpy-cross, so edited it:

#CROSS="/home/jeff/pico/micropython/mpy-cross/build/mpy-cross -march=xtensawin"
CROSS="/opt/homebrew/bin/mpy-cross -march=xtensawin"

This then compiles the .mpy files. I have the latest MicroPython 1.19.1 from homebrew installed, but that may not be the same version as the "dirty" / newer build from the firmware binary now on the watch?

Went to install the files, realised I needed to adapt the script to use the correct USB device on my machine, did that, installed - nothing happened. Connected Thonny and noticed that boot.py did not contain the launcher call mentioned in the README; tried to import launcher in the REPL, but got an error about the mpy version being incorrect.

Then, realised that it had not copied over the boot.py file (the line in install.sh is edited out, and anyway, the file already existed); so, cleared the LittleFS, uncommented the line in install.sh, and ran it again. Still no response after a reset.

Now, import launcher in the REPL returns without any obvious change (I'm guessing because boot.py is failing to load it, so at that point, MicroPython already decided that's done).

Any thoughts? I'd love to try this out! How can I help to improve things for anyone else who wants to try it?

andypiper commented 1 year ago

Incidentally, do you have sources or customisations for the MicroPython build that generated firmware.bin?

jeffmer commented 1 year ago

In answer to your second question, the firmware is at jeffmer/micropython in the GPIO_WAKEUP branch and the code for GPIO wake-up is in https://github.com/jeffmer/micropython/blob/GPIO_WAKEUP/ports/esp32/machine_pin.c

Sorry about the shell files, I do need to make them more portable. If you have installed the firmware from the repository, the Micropython version for the cross compiler should be fine.

Not sure which watch version you have?

A good first step if it does not work is to comment out the import loader file in boot.py and then reset the watch and type import tempos In the Thonny REPL window This should load the drivers and you should see the text loading…. on the watch screen - and you are more likely to see explicit error messages.

Do let me know how you get on and thanks for the feedback.

PS I am assuming that by launcher you mean loader. I would very much appreciate your input on improving the README. Your comments above are a great start.

jeffmer commented 1 year ago

OOPS, also realised to get the weather app to work you will need to create a file named location.jsonwith your current location in it e.g. {"lat": 51.41317, "long": -0.30266}

andypiper commented 1 year ago

Thanks for the pointers (and yes I meant loader!)

So I tried the commenting out, restart and import tempos but...

$ mpremote u0
Connected to MicroPython at /dev/cu.usbserial-02249052
Use Ctrl-] to exit this shell
OK[04][04]>OK[04][04]>OK
MPY: soft reboot
raw REPL; CTRL-B to exit
>
MicroPython v1.19.1-887-gb11026689-dirty on 2023-02-24; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>> import tempos
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/andypiper/Development/third-party/TTGO-T-watch-2020-Micropython-OS/src/tempos.py", line 3, in <module>
  File "/Users/andypiper/Development/third-party/TTGO-T-watch-2020-Micropython-OS/src/drivers/st7789.py", line 16, in <module>
ValueError: incompatible .mpy file

Now, first of all I'm not sure why it is referring to UNIX paths from my local machine when I'm running in the REPL on the device, to me that implies I've done something else wrong when compiling....

You also prompted me by asking what version of the watch I have. I was sure it was v2... but in fact, it is v3! So, I realise that all bets are off here 🤦🏼 and at the very least, I would need to rebuild the firmware with the correct pins etc for the peripheral sensors and drivers. I might have a look at that later in the week if I have time.

Good catch on the weather config, another minor addition to the README file there. One thing worth also documenting is that you don't want to have Thonny open at the same time as you're trying to run the install script, as it will fail with the port already open.

It might be a good idea to have some kind of cleanup steps:

jeffmer commented 1 year ago

Actually, the error your are getting is because st7789.py at line 16 imports the graphics module which has a function compiled using micropython.viper i.e. machine code - and it looks like your cross-compiler has produced an incompatible mpy file - maybe ignoring the -march flag.

In any case, a simple test is to explicitly copy graphics.py using mpremote or Thonny which will be used instead of graphics.mpy and will be compiled to bytecode in the esp32.

Re: Pin out - your V3 is most like a V1 - the big difference is that the backlight is pin 15 (V1 is 12) and there is a reset pin for touch - which should not affect things if you set VERSION=1 although you can get better battery life if you later use it.

andypiper commented 1 year ago

Yep, this seems to be the issue with the cross-compiler. I've copied the three files that use the @micropython.viper decorator over as .py files, and now get to a clock face. There's an error loading the GPS module (which this model is missing, I believe), and I'm not seeing the screen swipes working, but I can look into the pin set up. Thanks for all the support so far - happy if you want to close this as currently unsupported on the v3 model.

jeffmer commented 1 year ago

Glad you got something to work. Touch may require you to toggle the touch reset pin. I will update the README based on your comments above

devnoname120 commented 1 year ago

@andypiper Did you make progress with getting it to work on a v3? I'm interested in getting it running and if possible I'd prefer to avoid reimplementing the changes that your already did. Thanks!

jeffmer commented 1 year ago

Afraid not. I have been away April and May but I will have a look next week as you are still interested.

devnoname120 commented 1 year ago

@jeffmer I'm definitely interested thanks. I expect to start looking into it in 2-3 weeks.

andypiper commented 1 year ago

Yeah sorry I haven't had another chance to play with this yet due to other things coming up. Happy to help with further tweaks and testing.

thiswillbeyourgithub commented 1 year ago

Hello everyone!

I'm a dev from the world of the pinetime wasp-os and just bought a V3.

I'm bad at hardware and low level but decently experience in python so I can't help with the porting.

But I just wanted to signal that as soon as someone get the micropython os working on the V3 my plan is to :

  1. first port my alarm clock app (has lots of features like body motion tracking, smooth and gradual wakeup, etc etc)
  2. and a few other apps (pomodoro app etc) to this new watch.
  3. But then, I want to use the microphone and connect it to speech to text engine (openai or self hosted on a computer) and make it easy to do stream of thought logging on logseq / obsidian
  4. as well as create flashcards on the go (I have most of the code for all of this already done because of various other side projects).
  5. Later also connect it to generalist chat ai for quick questions or other assistant stuff.
  6. probably more as time goes on

Can't wait to play with this!

Have a nice day everyone

jeffmer commented 1 year ago

Sounds great.

I hope to get do the V3 updates this week - will post here when I get it done.

thiswillbeyourgithub commented 1 year ago

Hello again, really don't want to be spamming here but I couldn't resist linking this video that was posted 48h after my comment. I think it really encapsulates what can be possible with a hackable watch that has access to python API and a microphone :)

Hope I'm not disturbing and have a nice day!

thiswillbeyourgithub commented 1 year ago

Hi! Was just wondering if @jeffmer had any luck porting to v3 :) Have a nice day

devnoname120 commented 1 year ago

@jeffmer I made a tentative implementation. https://github.com/jeffmer/TTGO-T-watch-2020-Micropython-OS/pull/2 Could you test it? Thanks!

jeffmer commented 1 year ago

Sadly no as I only have V1 and V2 watches. Maybe @andypiper can test as I think he has V3.

thiswillbeyourgithub commented 1 year ago

Can anyone give me a rundown of the ways I can recover from a flashing that went bad ? I have no idea of the ways to recover from issues happening when testing the new v3 port or any unstable manoeuvre. I'm chickening out of flashing this PR as I'm the less knowledgeable in hardware and would have no clue how to recover :/ That would be much appreciated! Thanks and thanks a lot to @devnoname120 for the progress!

Edit : what I'm looking for is ways to unbrick my watch, just to be safe

jeffmer commented 1 year ago

You can try flashing the standard Micropython distribution for Esp32 with PSRAM. If that works just reflash the firmware here. To be clear, the firmware is the same for V1, V2 and V3. It’s only some of the Micropython modules that differ between versions

devnoname120 commented 1 year ago

@jeffmer Is it possible to recover from any bad changes to the .py files (compiled to .mpy) of this OS?

In other words, is there some kind of recovery mode in the FW that can be started if the OS doesn't boot?

The idea would be to replace the OS .mpy files or flash an entirely different firmware through the USB-TTY bridge if something goes wrong.

jeffmer commented 1 year ago

The easiest way is to reflash the FW and choose the option to erase all flash. That gets rid of all py and mpy files. In future when testing its best to comment out the import loader line in boot.py. Then you can start the OS for test purposes by typing import loader on the REPL. If it hangs you can simply reboot to get back to the REPL.

thiswillbeyourgithub commented 1 year ago

The easiest way is to reflash the FW and choose the option to erase all flash. That gets rid of all py and mpy files. In future when testing its best to comment out the import loader line in boot.py. Then you can start the OS for test purposes by typing import loader on the REPL. If it hangs you can simply reboot to get back to the REPL.

This proved very useful. Thank you very much.

The draft pr from @devnoname120 seems to be working flawlessly, nice first try!