Sonoff Touch with ESP8285 and Micropython

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Sonoff Touch with ESP8285 and Micropython

Post by torwag » Wed Feb 01, 2017 3:33 pm

Hi,
did someone already try to get Micropython running on the itead.cc SonSoff Touch wall light switch.
I managed to flash micropython on the (what looks to me like the PSF-A85 from itead.cc) board. Some people reported here that they managed to get MP running on that board. However, I can't get a REPL after flashing looks like I have a the wrong baud rate set. Tried different but beside of garbage text after a reset I could not get further.

I read that they might come with strange or different baud settings due to a different clock speed but could not find detailed infos.

As for flashing it took me a while until I found the correct way to reset the board into flashing mode. I will report this in the next posts.

Would be glad if people like to share their experience with the light switch or the PSF-A85.

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Sonoff Touch with ESP8285 and Micropython

Post by torwag » Thu Feb 02, 2017 10:47 pm

Seems to be a micropython problem. Today I tried an arduino sketch without problem. Serial terminal of the arduino ide as well as picocom worked at 115200 baud.

Could be a problem of the external oscillator being 24 MHz instead of the usual 40MHz?

Flashing seemed to work, verifying was okay, copied back the first few hundred bytes and checked manually, they are identical with the original firmware file.

Thus, it might be that the wrong divider is used, to set the baudrate of the uart, as soon as it jumps into user space.

Tried to check the code for the esp but did not found something. There are settings for baudrate and uart clk, but could not identify a certain divider or relationship to the external clock. Sure there is something, would be glad if someone can help me and point to it.

Thanks

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Sonoff Touch with ESP8285 and Micropython

Post by kfricke » Thu Feb 02, 2017 10:59 pm

The ESP8266 boots up with 26 MHz oscillator and then has a 74880 for the initial boot messages (maybe internal osci?). Then after switching to 40 MHz this becomes the better supported 115200 baud.

So i'd guess that there is this 2880 multiplier, which might help!?

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Sonoff Touch with ESP8285 and Micropython

Post by torwag » Sat Feb 04, 2017 2:21 pm

Hi,

@kfricke thanks for looking into it.
I looked a bit more into it. Indeed the oscillator on the PSF-A85 (which I believe is what they soldered on the sonoff touch) is a 26MHz version. And that should be e.g. identical with the WeMos units.
Thus, different or strange baud rates could not be the reason.

Furthermore, I added a main.py to the script folder and compiled that. It should periodically blink the on board LED which it does not!.

Thus, it was clear that MP is not running at all. After some more fiddling, I tried different serial terminals and miniterm.py under Linux was capable of reading at boot with the inital baudrate of 74880. picocom denied the baudrate and putty seemed to work but only showed garbage.

Flashing procedure I used is
1. ground GPIO 0
2. power cycle
3. flashing
This seems to work as flashing is indicated to be successful. And the very same method works for the arduino and platformio system (see below), which makes me feel good that this should be sufficient to initiated a proper UART flashing cycle. (I tried to pull down GPIO 15 and pull up GPIO2) but it seems to make no differences)
I flashed with e.g.

Code: Select all

esptool.py --port /dev/ttyUSB0 --baud 115200 write_flash -fm dio -fs 8m -ff 40m 0x00000 ~/micropython/micropython/esp8266/build/firmware-combined.bin --verify 
esptool.py v1.3
Connecting....
Running Cesanta flasher stub...
Flash params set to 0x0220
Wrote 573440 bytes at 0x0 in 49.7 seconds (92.3 kbit/s)...
Leaving...
Verifying just-written flash...
Flash params set to 0x0220
Verifying 0x8bcdc (572636) bytes @ 0x00000000 in flash against /home/torsten/micropython/micropython/esp8266/build/firmware-combined.bin...
After power cycling and reset I get :

Code: Select all

miniterm.py /dev/ttyUSB0 74880
--- Miniterm on /dev/ttyUSB0  74880,8,N,1 ---                                       
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---

 ets Jan  8 2013,rst cause:2, boot mode:(3,1)

load 0x40100000, len 32024, room 16 
tail 8
chksum 0xef
load 0x00000000, len 0, room 0 
tail 0
chksum 0xef
load 0x00000000, len 0, room 8 
tail 0
chksum 0xef
csum 0xef
csum err
ets_main.c 
Thus, it seems something went wrong.
Interestingly, I can use the arduino IDE or the plaformio system to compile and upload an arduino-based firmware and this works.

Trying to upload the same firmware manually with esptool.py does not work. However, it could be that the generated firmware does not contain the bootloader.

Now I am checking what does the arduino IDE and the platformio system differently to my manual approach of uploading the firmware. Any suggestions are welcome.

cartere
Posts: 25
Joined: Sat Feb 04, 2017 9:26 pm

Re: Sonoff Touch with ESP8285 and Micropython

Post by cartere » Sat Feb 04, 2017 9:30 pm

Have you tried qio instead of dio?

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Sonoff Touch with ESP8285 and Micropython

Post by torwag » Mon Feb 06, 2017 8:59 am

@cartere:
Thanks for the input. From what I read, I have to use dio, since the internal flash rom is connected in the "Dual I/O" mode (-fm dio).
I don't think that anything on the hardware site is going wrong, since I can upload arduino-based firmwares without a problem.

It has to do something with either me misusing the esptool.py program, or something within MP which is not yet compatible with the esp8285.

cartere
Posts: 25
Joined: Sat Feb 04, 2017 9:26 pm

Re: Sonoff Touch with ESP8285 and Micropython

Post by cartere » Mon Feb 06, 2017 2:09 pm

Very interested in what you are doing with the Touch, the main reason I brought this up was perhaps unrelated but in this video pertaining to ESP32 there were very similar error codes generated by a dio/qio conflict.

https://www.youtube.com/watch?v=qa2406iiSbI

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Sonoff Touch with ESP8285 and Micropython

Post by torwag » Wed Feb 08, 2017 8:09 pm

Yesterday, I noticed another annoying fact which is going to be a project killer for many of us.
I tried to install the switch for testing and noticed that the frame of the switch is 86mm x 86mm. At least in Germany the space between two junction boxes in a row (or column) has to be 71mm. This is a standard which guarantees that all frames and switches fit within the installed junction boxes.

The 86mm seem to be UK standard.

That results in the fact that (at least for Germany) one can only replace already existing installation with the sonoff touch switch only without a frame and only if they exist as a single unit. Multiple units (several switches or in combination with a power outlet) will definitely not work. Unfortunately, combo-frames are rather common in Germany. BTW. not the only touch-glass -based switch currently sold with the "wrong" size. Ebay and Co are full of them.
Someone need to tell the manufactures that there is nothing like an EU-standard for this ;)

Just want to point this out here before people start to make bigger investments.

User avatar
kfricke
Posts: 342
Joined: Mon May 05, 2014 9:13 am
Location: Germany

Re: Sonoff Touch with ESP8285 and Micropython

Post by kfricke » Wed Feb 08, 2017 8:45 pm

At least it is smaller ;)

Have you got plans to fill the 2x 1,5 mm gap? Or is the part too small to fit into the mounting frame?

torwag
Posts: 220
Joined: Fri Dec 13, 2013 9:25 am

Re: Sonoff Touch with ESP8285 and Micropython

Post by torwag » Wed Feb 08, 2017 9:47 pm

no not smaller.... bigger

86mm frame vs. 71mm drill distance for German junction boxes.... that means you can't get two of those switches in a row nor does the switch fit in a standard 2x, 3x, or 4x frame as we know it in Germany.

Well basically, the touch is a single tiny sensor plate of a few cm right in the centre behind the glas frame not connected to the glas slide in any way. One could think of cutting the glas down to make it fit inside a standard frame but this is a kind of a hack I really would not want to do.

Argghhh I already started to look wether I build my own unit which has two digital inputs to connect the original switch, two gang switch (if possible based on an SSR), a watchdog circuit in case the uC hangs, and all this within a size that it fits in the standard 60mm junction box behind a power outlet or a wall switch. The PSF-A85 .... if I ever get it running would be a good start, what is needed is a safe and super efficient power supply, the relay circuit and the watchdog circuit.
I found ultra compact all in one power supply modules 230V-3.3V already which would fit... looking into suitable watchdog circuits right now.

Post Reply