logo elektroda
logo elektroda
X
logo elektroda

Reading/writing errors on tuya mini switches - issues with arduinos?

donut343 1113 16
ADVERTISEMENT
  • #1 21097337
    donut343
    Level 2  
    Hi all, I'm new to the tuya flashing world! I have two of the switches listed in this thread, but can't manage to flash them, they have firmware 1.3.10 v102. I wired them up like was shown in the first post of said thread.
    I get several errors during the flashing process after repeatedly clicking the "write only" button, I added them at the bottom of this post. Things I tried:

    - Swapped arduino nano for uno
    - Used SoftwareSerial (see added code)
    - Wiped arduinos and used Rx Tx pins with gnd and reset pins shorted (cant set baud rate with that setup)
    - Tried standalone psu @ 3.3v instead of arduino 3.3v pin
    - Tried hid_download_py and to flash through CMD, to no avail. It fails to set baud rate.
    - Tried different USB ports

    Does anyone have some advice? I ordered some USB to TTL uart bridge adapters to try instead of the arduinos but they'll take some time to arrive.

    Arduino Nano connected to a PCB on a breadboard.

    Arduino code:
    
    #include <SoftwareSerial.h>
    
    // Define the pins for SoftwareSerial
    SoftwareSerial tuyaSerial(9, 10); // RX, TX
    
    void setup() {
      // Start the hardware serial for communication with the PC
      Serial.begin(115200);
    
      // Start the software serial for communication with the Tuya WiFi chip
      tuyaSerial.begin(115200);
    }
    
    void loop() {
      // Read from PC and send to Tuya
      if (Serial.available()) {
        char c = Serial.read();
        tuyaSerial.write(c);
      }
    
      // Read from Tuya and send to PC
      if (tuyaSerial.available()) {
        char c = tuyaSerial.read();
        Serial.write(c);
      }
    }
    


    Errors:
    
    Starting flash new (no backup)!
    Now is: Saturday, May 25, 2024 11:40:32 AM.
    Flasher mode: BK7231N
    Going to open port: COM7.
    Serial port open!
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Will try to read device flash MID (for unprotect N):
    Flash MID loaded: 1560EB
    Will now search for Flash def in out database...
    Flash def found! For: 1560EB
    Flash information: mid: 1560EB, icName: TH25Q_16HB, manufacturer: TH, szMem: 1000000, szSR: 2, cwUnp: 0, cwEnp: 7, cwMsk: 407C, sb: 2, lb: 5, cwdRd: 05-35-FF-FF, cwdWr: 01-FF-FF-FF
    Entering SetProtectState(True)...
    sr: 0
    sr: 0
    final sr: 0
    msk: 407c
    cw: 0, sb: 2, lb: 5
    bfd: 0
    SetProtectState(True) success!
    Reading file firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Loaded 1220464 bytes from firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Preparing to write data file to chip - resetting bus and baud...
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Failed to set baud rate!
    
    Starting flash new (no backup)!
    Now is: Saturday, May 25, 2024 11:40:39 AM.
    Flasher mode: BK7231N
    Going to open port: COM7.
    Serial port open!
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Will try to read device flash MID (for unprotect N):
    Flash MID loaded: 1560EB
    Will now search for Flash def in out database...
    Flash def found! For: 1560EB
    Flash information: mid: 1560EB, icName: TH25Q_16HB, manufacturer: TH, szMem: 1000000, szSR: 2, cwUnp: 0, cwEnp: 7, cwMsk: 407C, sb: 2, lb: 5, cwdRd: 05-35-FF-FF, cwdWr: 01-FF-FF-FF
    Entering SetProtectState(True)...
    sr: 0
    sr: 0
    final sr: 0
    msk: 407c
    cw: 0, sb: 2, lb: 5
    bfd: 0
    SetProtectState(True) success!
    Reading file firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Loaded 1220464 bytes from firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Preparing to write data file to chip - resetting bus and baud...
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Will try to read device flash MID (for unprotect N):
    Flash MID loaded: 1560EB
    Will now search for Flash def in out database...
    Flash def found! For: 1560EB
    Flash information: mid: 1560EB, icName: TH25Q_16HB, manufacturer: TH, szMem: 1000000, szSR: 2, cwUnp: 0, cwEnp: 7, cwMsk: 407C, sb: 2, lb: 5, cwdRd: 05-35-FF-FF, cwdWr: 01-FF-FF-FF
    Entering SetProtectState(True)...
    sr: 0
    sr: 0
    final sr: 0
    msk: 407c
    cw: 0, sb: 2, lb: 5
    bfd: 0
    SetProtectState(True) success!
    Going to do erase, start 0, sec count 298!
    Erasing sector 0... ok! Erasing sector 4096... ok! Erasing sector 8192... ok! Erasing sector 12288... ok! Erasing sector 16384... ok! Erasing sector 20480... ok! Erasing sector 24576... ok! Erasing sector 28672... ok! Erasing sector 32768... ok! Erasing sector 36864... ok! Erasing sector 40960... ok! Erasing sector 45056... Erasing sector 45056 failed!
    Writing file data to chip failed.
    
    Starting flash new (no backup)!
    Now is: Saturday, May 25, 2024 11:41:35 AM.
    Flasher mode: BK7231N
    Going to open port: COM7.
    Serial port open!
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Will try to read device flash MID (for unprotect N):
    CheckRespond_FlashGetMID: bad value returned?
    Failed to read device MID!
    Reading file firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Loaded 1220464 bytes from firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Preparing to write data file to chip - resetting bus and baud...
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Will try to read device flash MID (for unprotect N):
    CheckRespond_FlashGetMID: bad value returned?
    Failed to read device MID!
    Going to do erase, start 0, sec count 298!
    Erasing sector 0... Erasing sector 0 failed!
    Writing file data to chip failed.
    
    Starting flash new (no backup)!
    Now is: Saturday, May 25, 2024 11:42:06 AM.
    Flasher mode: BK7231N
    Going to open port: COM7.
    Serial port open!
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Will try to read device flash MID (for unprotect N):
    CheckRespond_FlashGetMID: bad value returned?
    Failed to read device MID!
    Reading file firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Loaded 1220464 bytes from firmwares/OpenBK7231N_QIO_1.17.592.bin...
    Preparing to write data file to chip - resetting bus and baud...
    Getting bus... (now, please do reboot by CEN or by power off/on)
    Getting bus success!
    Going to set baud rate setting (115200)!
    Will try to read device flash MID (for unprotect N):
    CheckRespond_FlashGetMID: bad value returned?
    Failed to read device MID!
    Going to do erase, start 0, sec count 298!
    Erasing sector 0... ok! Erasing sector 4096... ok! Erasing sector 8192... ok! Erasing sector 12288... ok! Erasing sector 16384... ok! Erasing sector 20480... ok! Erasing sector 24576... ok! Erasing sector 28672... ok! Erasing sector 32768... ok! Erasing sector 36864... ok! Erasing sector 40960... ok! Erasing sector 45056... ok! Erasing sector 49152... ok! Erasing sector 53248... ok! Erasing sector 57344... ok! Erasing sector 61440... ok! Erasing sector 65536... ok! Erasing sector 69632... ok! Erasing sector 73728... ok! Erasing sector 77824... ok! Erasing sector 81920... ok! Erasing sector 86016... ok! Erasing sector 90112... ok! Erasing sector 94208... ok! Erasing sector 98304... ok! Erasing sector 102400... ok! Erasing sector 106496... ok! Erasing sector 110592... ok! Erasing sector 114688... ok! Erasing sector 118784... ok! Erasing sector 122880... ok! Erasing sector 126976... ok! Erasing sector 131072... ok! Erasing sector 135168... ok! Erasing sector 139264... ok! Erasing sector 143360... ok! Erasing sector 147456... ok! Erasing sector 151552... ok! Erasing sector 155648... ok! Erasing sector 159744... ok! Erasing sector 163840... ok! Erasing sector 167936... ok! Erasing sector 172032... ok! Erasing sector 176128... ok! Erasing sector 180224... ok! Erasing sector 184320... ok! Erasing sector 188416... ok! Erasing sector 192512... ok! Erasing sector 196608... ok! Erasing sector 200704... ok! Erasing sector 204800... ok! Erasing sector 208896... ok! Erasing sector 212992... ok! Erasing sector 217088... ok! Erasing sector 221184... ok! Erasing sector 225280... ok! Erasing sector 229376... ok! Erasing sector 233472... Erasing sector 233472 failed!
    Writing file data to chip failed.
    
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 21097589
    p.kaczmarek2
    Moderator Smart Home
    Timings may be a bit more crucial here, I'd just try using the USB to UART converter that we've used on our videos:
    [youtube]https://www.youtube.com/watch?v=YQdR7r6lXRY [/youtube]
    Try it out once your converter arrives and let us know if it worked better.

    Have you tried flashing at lower baud rates?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21097618
    donut343
    Level 2  

    Thanks for getting back to me! Could you elaborate on timings being more crucial? I only had to connect and disconnect the PSU the first try @ 115200 baud rate, after that I could just re-click the "write only" button and it would recognize without any manual interference. I'm hoping the USB converters work out, of course I'll update this thread once I receive them, should be a week or so.

    The flashing tool only listed 115200 and up, with respect to baud rates. If I understand what you mean correctly, I tried to manually type 9600 in the flashing tool. I had also flashed the Arduinos with SoftwareSerial with 9600 baud rate, but couldn't get the Tuya chip to be recognized by the flashing tool, only 115200 resulted in recognized bus. Higher baud rates I also couldn't get working with the Arduinos..
  • #4 21097627
    p.kaczmarek2
    Moderator Smart Home
    I haven't investigated the timings with scope but I know that there are even issues with running my flasher (BK7231 easy uart flasher) on Mono on Linux because they have slightly different UART implementation. I also remember situations when using different USB to UART converter helped, so I am speaking from the experience.

    what else can we do... well, there is one hack that worked few times for me. Do the following:
    1. disconnect VDD of module from your 3.3V supply
    2. temporarily connect VDD of module side to GND (not the 3.3V of your power supply! do not do short!)
    3. start flashing in the flasher (so it's getting bus)
    4. disconnect module VDD from GND and connect it to 3.3V

    Alternatively you can also use the CEN method.... but in general, I've flashed hundreds of devices, once you get setup right, it's 100% reliable, it may not be worth trying to use complicated methods when a simple converter works just fine.

    The last thing you can try (I am often doing that) is feeding 5V to the input of the LDO on the board with Beken. Do this instead of connecting 3.3V. I am sometimes using this method when there is a clearly visible AMS1117-3.3V or a step down (5V to 3.3V or so) converter on the board.

    That being said, I kinda remember there were people who have successfully used NodeMCU (with MCU in RESET state) for flashing,..

    Wait, to be clear - when trying to use USB to UART converter from Arduino UNO, do you put Arduino in RESET state by shorting it's RESET pin to ground?
    Helpful post? Buy me a coffee.
  • #5 21097647
    donut343
    Level 2  

    Thanks for your advice, really appreciated. I think I will do as follows:

    1. Wait for the USB-UART converters (I ordered a 3-pack containing a PL2303, CP2102, and CH340G based converter)
    2. Try your suggested hack
    3. Try your second suggested hack of feeding 5V to the LDO instead of 3.3V

    I've tried with both an Arduino Uno and a Nano by shorting reset-gnd to bypass the MCU and then just using RX and TX pin; doing so I couldn't get the Tuya chip to be recognized by the tool. I also tried SoftwareSerial with digital pins as RX and TX pins, like shown in the code block in my first post; that method at least got the tool to start erasing sectors.
    But first, I'll wait for the USB-UART converters and follow the setup in the video - I'll likely use my ATX benchtop PSU to output 3.3V instead of the USB + LDO though.
  • ADVERTISEMENT
  • #6 21106060
    donut343
    Level 2  

    So using a new USB-UART TTL converter did the trick, I successfully managed to flash the chip with new firmware.

    However, on desoldering the wires I accidentally desoldered an SMD component and then it sprung off my PCB when I tried to resolder it and I lost it haha, pretty stupid!! Just hooked it up and it did set up an access point, I'll see if the missing component results in real noticeable errors :3

    I do have 2 more chips to flash and it was only a few dollars, still a shame though lol. At least I know the flashing works! See attached image for the component I lost circled in red.. I'll update after I flash some firmware on them and test them with home assistant.
    Image of a printed circuit board with a red circle marking the spot where an SMD component is missing.
  • #7 21106091
    p.kaczmarek2
    Moderator Smart Home
    Looks like a part of WiFi antenna circuit, is your WiFi range still ok?
    Helpful post? Buy me a coffee.
  • #8 21106112
    donut343
    Level 2  

    Hmm so the access point is showing up (full bars) but I can't connect to it with my MacBook.. With my phone I can, but then can't reach it over 193.168.4.1 - tomorrow I'll try flashing the other identical chip I have and be more careful with the near components 😅
  • #9 21106131
    p.kaczmarek2
    Moderator Smart Home
    That's strange, but still, you can configure your device WiFi via our flasher itself.
    Helpful post? Buy me a coffee.
  • #10 21106151
    donut343
    Level 2  

    I'll resolder the wires and check it out tomorrow, unfortunately I have no more time tonight, I'll keep you posted on my progress!
  • #11 21106241
    p.kaczmarek2
    Moderator Smart Home
    Still, issue is most likely caused by missing capacitor. Can you solder a replacement? Here is a schematic:
    Electrical schematic with a missing capacitor.
    Helpful post? Buy me a coffee.
  • #12 21106259
    max4elektroda
    Level 20  
    donut343 wrote:
    With my phone i can, but then cant reach it over 193.168.4.1

    Just to make sure this is a typo? IP is 192.168.4.1
  • #13 21106265
    p.kaczmarek2
    Moderator Smart Home
    Nice spotting, it could have been a typo, let's wait for @donut343 to recheck...
    Helpful post? Buy me a coffee.
  • #14 21106318
    donut343
    Level 2  

    yes, sorry, that was a typo indeed haha. Thanks for the schematic, hope I can locally source a capacitor or I'll have to wait for a while. Would that be c9 or am I misreading the schematic you sent over? Sorry for my oblivious questions, I'm quite inexperienced with all this stuff.
  • #15 21107467
    donut343
    Level 2  

    Okay so for some reason my (android) phone and macbook didn't work, but my windows desktop did, using a wifi dongle I had plugged in a rpi, I just changed wifi ssid / pass in settings and seems to connect fine, wifi signal seems okay! Now to flash the actual firmware and test :)

    Thanks for all the time you spent on helping me, regardless! Much appreciate, I've been recommending your tool / forum to interested people around me!
    OpenBK7231N control panel with system information.
  • #16 21107604
    p.kaczmarek2
    Moderator Smart Home
    I see, that's a very good news. Don't forget that we're building a supported devices list here:
    https://openbekeniot.github.io/webapp/devicesList.html
    And you can contribute:
    https://www.elektroda.com/rtvforum/topic3950844.html
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #17 21108636
    donut343
    Level 2  

    Yeah I will do, once I get it up and running! I think others have reported this one already (https://www.elektroda.com/rtvforum/topic3977701-60.html#21095539) but I'll report regardless :)

Topic summary

The discussion revolves around difficulties encountered while flashing Tuya mini switches with firmware version 1.3.10 v102 using Arduino boards. The user faced multiple errors during the flashing process, despite trying various methods including swapping Arduino models, using SoftwareSerial, and different power supplies. Suggestions from other users included using a USB to UART converter, adjusting baud rates, and employing specific flashing techniques. Ultimately, the user successfully flashed the chip using a new USB-UART TTL converter but accidentally desoldered an SMD component during the process. The conversation also touched on troubleshooting WiFi connectivity issues post-flashing and the importance of ensuring proper component connections.
Summary generated by the language model.
ADVERTISEMENT