loboris / MicroPython_ESP32_psRAM_LoBo

MicroPython for ESP32 with psRAM support
Other
829 stars 344 forks source link

Noob Question: How to run the examples? #227

Closed justinmoon closed 6 years ago

justinmoon commented 6 years ago

I'm a Python developer brand new to MicroPython . How can I run the examples?

Sorry for such a basic question but I don't see instructions anywhere and don't know enough MicroPython to figure it out ...

yeyeto2788 commented 6 years ago

Hello @superquest,

I would suggest that after installing the firmware onto the board try running the example scripts with Adafruit's ampy tool

To flash the firmware first erase flash memory by typing esptool.py --chip esp32 -p /dev/tty.SLAB_USBtoUART erase_flash where the /dev/tty.SLAB_USBtoUART should be your serial port, after successfully erasing flash try to flash the firmware with this info.

Take into account that the flash.sh is using the /dev/ttyUSB0 port to write the firmware into the board, so you might need to do something like this ../flash.sh -p <your_comm_port> -b <baud_rate>

NOTE: remember to update the esptool.py to latest version.

Hope it helps.

justinmoon commented 6 years ago

Thanks @yeyeto2788.

What do you mean by "your serial port"?

I interpreted it to be /dev/ttyUSB0 because that shows up when I plug the m5stack in.

But when I run:

esptool.py --chip esp32 -p /dev/ttyUSB0 erase_flash
cd firmware/esp32
../flash -p /dev/ttyUSB0
ampy -p /dev/ttyUSB0 ls

it just hangs ...

 picocom -b 460800 /dev/ttyUSB0

Also hangs ...

yeyeto2788 commented 6 years ago

If you look at the output for dmesg | grep tty you should see the output with some serial ports, one of those should be the one of the board. Depending on the board you might need also to install drivers for the USB to serial converter. In some cases, it is used the CH340 or the CP2102 or another USB to serial converted chip.

What kind of board are you using?

justinmoon commented 6 years ago

Update: after hitting the reset button on my m5stack I now get this output

$ ampy -p /dev/ttyUSB0 ls
flash

But picocom still fails to enter a >>> python repl. I've gotten picocom to work before with an esp8266 board so I know how that should work.

@yeyeto2788: yes it is /dev/ttyUSB0 then. That's the only candidate that shows up after executing the dmesg | grep tty.

So -- how might I find the needed drivers to talk to m5stack from my Arch Linux machine?

And note: I did get the board to work using the m5stack cloud editor -- it just seemed kind of sketchy security-wise. They store router passwords in plaintext ...

Thanks again for your kind help :)

In the mean time I'm going to try flashing the generic micropython firmware to this board. Haven't actually done that yet ...

yeyeto2788 commented 6 years ago

From the internet I have found this link it seems to have the CP2104 USB to serial chip.

The weird thing is that if ampy got connected to the board showing the flash directory, so it is not something related to the serial port neither the drivers.

It seems that you are trying to connect to the board through picocom at baud rate different than the one set on firmware which is 115200.

Try with picocom -b 115200 /dev/ttyUSB0

justinmoon commented 6 years ago

Try with picocom -b 115200 /dev/ttyUSB0

That worked! Hallelujah!!!

BTW I'm going to help you guys write a guide for noobs if I get everything working. I'm teaching a python class where we're going to try a MicroPython project so I'll need to write such a guide in any case ...

The logging here could be improved:

$ ../flash.sh
esptool.py v2.5.1
Serial port /dev/ttyUSB0
Connecting........_
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse
MAC: 84:0d:8e:21:10:94
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 21232 bytes to 12495...
Wrote 21232 bytes (12495 compressed) at 0x00001000 in 0.3 seconds (effective 572.5 kbit/s)...
Hash of data verified.
Compressed 144 bytes to 69...
Wrote 144 bytes (69 compressed) at 0x0000f000 in 0.0 seconds (effective 309.8 kbit/s)...
Hash of data verified.
Compressed 1539680 bytes to 930617...
Wrote 1539680 bytes (930617 compressed) at 0x00010000 in 22.2 seconds (effective 555.1 kbit/s)...
Hash of data verified.
Compressed 3072 bytes to 126...
Wrote 3072 bytes (126 compressed) at 0x00008000 in 0.0 seconds (effective 5722.2 kbit/s)...
Hash of data verified.

Leaving...
Staying in bootloader.

That output is why I was using the wrong baud rate.

@yeyeto2788 Now, how can I run the Paint example or another example like it? Just trying to get something to show up on my screen ... I still don't understand where to put a main.py file in order to write "hello world".

yeyeto2788 commented 6 years ago

@superquest you should be able to do it, before doing so remember that the m5stack does not have touch controller.

I would suggest to try the tftdemo.py as is since it have the tft setup for the m5stack.

There are also another scripts that you can use like these scripts.

As far as I know there is no way to disable those logs since those are boot logs (not an expert :disappointed: )

Regards.

justinmoon commented 6 years ago

But what do I do with those files? How do I put them on the board / run them?

Edit: got this to show some colorful output on the screen: ampy -p /dev/ttyUSB0 run tftdemo.py

Edit: ampy run works beautifully. ampy put hasn't been able to transfer any files to the device. So still don't know how to put any code persistently on the board. ...

justinmoon commented 6 years ago

OK I figured out a good way. I basically forked https://github.com/tuupola/micropython-m5stack for my actual application.