Close

Fixed Firmware

A project log for Tote HaD

Special edition of Tote for the Belgrade workshop.

dehipudeʃhipu 04/11/2016 at 20:5028 Comments

As promised, I fixed the firmware for the robot -- now it will start walking immediately after being switched on, and after connecting you can control it. Below are flashing instructions.

  1. Download the firmware-combined.bin file, and save in the current directory.
  2. Download the esptool.py file, and save in the current directory.
  3. Connect the USB2TTL to the pins on the side of the robot:
    • gnd ↔ gnd
    • rx ↔ tx
    • tx ↔ rx
  4. Connect together two pin holes (or pins, if you soldered pins in there) on the other side of the robot (leave the third pin alone):
    • gnd ↔ sda
  5. Connect the USB2TTL to your computer.
  6. Switch on the robot.
  7. Run the flashing command:
    $ python esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 firmware-combined.bin
  8. On Windows/Mac change the path to the USB2TTL port accordingly.

  9. Wait for the firmware to flash. If you get an error, try again.
  10. Switch the robot off.
  11. Remove the connector from the pin holes.
  12. Switch the robot on and see it walk. Congratulations, you have the new firmware.

Note, that flashing new firmware will not delete the network information from the board, if you had the robot connect to some network. If you want to do that, you can with this command (before flashing the firmware):

$ python esptool.py --port /dev/ttyUSB0 erase_flash

Discussions

davedarko wrote 04/16/2016 at 22:18 point

So my creeper is crawling, I can see it in my home network but it won't listen to telnet commands on 1010. Latest firmware is on the ESP. It seems that main.py and boot.py won't start as well. when I stop the program with ctrl+c it says:

"could not open file 'boot.py' for reading"

"could not open file 'main.py' for reading" 

"import server" and then "server.main()" gives me

>>> server.main()
Traceback (most recent call last):
  File "", line 1, in
  File "", line 13, in main
OSError: 112

EHOSTDOWN 112 /* Host is down */ - that would be "localhost" / the esp in that case, right? I'm out of Ideas, I'm going to bed :) 

  Are you sure? yes | no

deʃhipu wrote 04/16/2016 at 23:14 point

What does "import network; network.WLAN(network.STA_IF).ifconfig()" say?

Line 13 is https://bitbucket.org/thesheep/tote-had/src/455a46355e7256e0a192444fccd4ff201bb100d8/python/server.py?at=default&fileviewer=file-view-default#server.py-13

So that at least makes some sense... But if it gets an error at that point, then it should not be walking...

  Are you sure? yes | no

Nebojša Arežina wrote 04/12/2016 at 20:36 point

I erased flash and wrote new firmware, as per instructions, and it's still not moving by itself when powered on. Where should I start troubleshooting? How can I verify if new firmware got uploaded to the board?

  Are you sure? yes | no

deʃhipu wrote 04/12/2016 at 20:45 point

Make sure you removed the connection between SDA and GND. If that still doesn't work, check if there are any error messages on the console -- connect the USB2TTL, run "screen /dev/ttyUSB0 115200", and switch the robot on. If that doesn't give you any clues, press ctrl+c to get into the interactive console and try making the robot walk manually -- how I described in the previous log. If that works, try "import server" and then "server.main()".

  Are you sure? yes | no

Nebojša Arežina wrote 04/12/2016 at 20:58 point

Yup, removed connection between SDA and GND, that's all fine. I can manually make robot walk, that's ok too. Importing server and running server.main() results in following:

>>> import server
>>> server.main()
Traceback (most recent call last):
  File "", line 1, in
  File "", line 20, in main
OSError: 116

Any ideas? Did I maybe fail to follow instructions properly?

  Are you sure? yes | no

deʃhipu wrote 04/12/2016 at 22:04 point

That is strange. I guess there is a bug in the traceback code computing line numbers, because line 20 in the main() functions is a while loop: https://bitbucket.org/thesheep/tote-had/src/8c572672fd5e3d472f247c249817594c48985b2f/python/server.py?at=default&fileviewer=file-view-default#server.py-20

OSError 116 also doesn't make much sense in this context: https://github.com/pfalcon/esp-open-lwip/blob/e2f8daeba1328ca0af7e73ab167c5810551959fe/include/lwip/arch.h#L196

On the other hand, I can't imagine how not following instructions could lead to this kind of error. In fact, I have a hard time imagining how such an error is possible, except for an bug in error reporting itself.

Is your robot connected to a network or does it work as an access point? Could you try the other mode?

When you switch the robot on with the USB2TTL connected, do you get a python prompt right away, or do you have to press ctrl+c first? Any messages in there?

  Are you sure? yes | no

deʃhipu wrote 04/12/2016 at 22:13 point

Oh, and can you make sure that it actually updated? What version does it show when you press ctrl+d on the python prompt? If it's "v1.6-374-g2c407bc-dirty", then it's still the old firmware.

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 09:36 point

I'll debug it more this evening, when I get home from work. I went to sleep last night before seeing your message.

When connected using USB2TTL I first get some garbage, as expected, and then I need to press CTRL+C to get to the Python prompt.

I switched it to network mode at some point, but I'm not sure anymore if it's in AP or Network mode. How can I verify in which mode it is currently? This is all new to me, I've never seen ESP8266, and I haven't used Python in few years.

While I'm at it, can you point me to some documentation on how compile sources to new firmware image?

(and I hope I'm replying to your last message, since this board is a tad confusing)

  Are you sure? yes | no

deʃhipu wrote 04/13/2016 at 11:50 point

OK, I think that at this point the most likely explanation is that the flashing of new firmware somehow failed, and you still have the old firmware there.

I will write a log about compiling Micropython and preparing the firmware for the robot.

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 14:09 point

OK, I'll check if firmware flashing is failing, and if it is, I'll try to figure out why. Thanks.

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 19:37 point

I checked the firmware version after another attempted update, and it's "v1.6-374-g2c407bc-dirty". For some reason firmware update is failing, even though esptool.py reports that everything went fine.

  Are you sure? yes | no

deʃhipu wrote 04/13/2016 at 19:49 point

Argh, sorry, that version is the new firmware. I don't know what version the old one had :(

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 20:03 point

Are you sure? It says "MicroPython v1.6-374-g2c407bc-dirty on 2016-04-07". That date was last Thursday.

  Are you sure? yes | no

deʃhipu wrote 04/13/2016 at 20:57 point

Seems like both the old and the new versions of firmware have the same version number.

Say, do you have any other usb2ttl connected to your computer? What does esptool.py display exactly?

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 21:10 point

This is output of "python2 esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 ../firmware-combined.bin" is:


Connecting...
Erasing flash...
Took 2.37s to erase flash block
Wrote 440320 bytes at 0x00000000 in 13.2 seconds (266.6 kbit/s)...


Leaving...

I got few times these error messages:

A fatal error occurred: Failed to write to target Flash after seq 1 (got result 0x1, 0x7)

A fatal error occurred: Failed to enter Flash download mode (result "0x1, 0x5")

A fatal error occurred: Failed to enter Flash download mode (result "0x1, 0x6")

But disconnecting USB2TTL and power-cycling tote solved that problem.

And nope, I didn't have anything connected to my laptops' USB ports at the time.

  Are you sure? yes | no

deʃhipu wrote 04/13/2016 at 21:22 point

That looks correct. Have you tried to do erase_flash and then flash again?

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 21:36 point

Did it again just now, still the same - it's not walking by itself when powered on, and throws "OSError: 116" when running "server.main()".

Can I maybe debug python code while it's executing on uC?

  Are you sure? yes | no

deʃhipu wrote 04/13/2016 at 21:48 point

Well, sure, you can try executing the code line-by-line in the console. The code is in the bitbucket repository. But the problem seems to be that the wrong code is executing...

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 22:10 point

I was thinking more of PDB or something like that, so I can single step through instructions, analyze stack and so on.

I'll try to devote some time in next couple of days to reading your code and figure out how it exactly works, so I can start drawing some conclusions on what's going on.

  Are you sure? yes | no

deʃhipu wrote 04/13/2016 at 22:20 point

Sorry, no pdb for Micropython yet, as far as I know. I just wrote the log about building the firmware (sorry, I redirect to the official README for building the Micropython itself, as it doesn't make much sense to repeat it, and it may change).

  Are you sure? yes | no

Nebojša Arežina wrote 04/13/2016 at 22:28 point

No problem, I'm used to reading documentation, after all, I do code for living. I'll hopefully give it a read tomorrow.

There is one more thing about that error, I remember seeing it when battery ran out of juice.

I was showing tote to my coworkers, and I think that battery has lost its power, because robot started acting spastically, and I could see in terminal that it was printing out a bunch of "OSError:116" messages.

I don't know if that has anything to do with this, but I just thought that I should mention it.

Also, since I don't have anything to charge the small battery with, it's happily running on Samsung S3 phone battery :-)

  Are you sure? yes | no

Nebojša Arežina wrote 04/15/2016 at 21:48 point

Just to give a quick update, I managed to build new firmware binary. Setting up Micropython and ESP toolchain was just a matter of following instructions.

Tote is now almost working properly, I can control it via client application when it connects to my home network, with a bit fiddling.

When booting Tote, I'll get following errors on console:

"could not open file 'boot.py' for reading
could not open file 'main.py' for reading".

Since server is started from main.py, it's not started on boot, and I have to start it manually.

I tried using Mpfshell to manipulate files on ESP, but it's not able to import some things from

serial.tools.miniterm. My best guess is that there is miniterm version mismatch between version used by Mpfshell author and version installed on my system. I'll look into that during next few days.

**update**: fix for Mpfshell was trivial, I just replaced

"from serial.tools.miniterm import Miniterm, console, CONVERT_CRLF, NEWLINE_CONVERISON_MAP"

to

"from serial.tools.miniterm import Miniterm, Console, CRLF, EOL_TRANSFORMATIONS"

in mp/mpfshell.py, and updated references to those imports in the code.

I copied main.py to ESP flash and Tote is now working as it was originally intended.

  Are you sure? yes | no

deʃhipu wrote 04/16/2016 at 09:52 point

I'm glad you got it to work. Really sorry for the trouble.

  Are you sure? yes | no

Nebojša Arežina wrote 04/16/2016 at 10:24 point

No trouble at all, this was genuinely fun. I already have some ideas I can implement in firmware, and an Android client would be nifty. I'll ping you if I make something useful.

  Are you sure? yes | no

deʃhipu wrote 04/16/2016 at 10:29 point

Don't hesitate to write a log on this project.

  Are you sure? yes | no

M.daSilva wrote 04/12/2016 at 17:25 point

Perfect, it's walking right after switching it on! Just a small correction to the command line: 

python esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m firmware-combined.bin

is missing the address agrument

python esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=8m 0 firmware-combined.bin

did the trick!

(I had to run it as root)

Now, I still have to fix one servo : it looks like it's not receiving the signal from the board, maybe one connection between the Arduino and the PCB went bad :p

  Are you sure? yes | no

deʃhipu wrote 04/12/2016 at 17:49 point

Ah, sorry about that, thanks, I will fix the instructions. Yeah, soldering the Arduinos on that board is tricky, try melting the solder and inserting a thin wire into those holes, that should help.

  Are you sure? yes | no

M.daSilva wrote 04/12/2016 at 17:51 point

Yeah, I'll do that! Worst case I'll just leave the piece of wire in there. Easy fix!

  Are you sure? yes | no