Baud Rate on ESP8266

Posted on
  • Hey there!

    I'm having a bit of trouble getting started with Espruino on esp-12ex. I've run NodeMCU successfully on it in the past, but as I lack a suitable usb-serial adaptor currently, I've been accessing the chip via a little bluetooth adaptor, which seems to only be happy running at 9600 baud.

    After a lot of confusion, it seems the ESP8266 port runs at 115200 by default, unlike the main espruino boards? I wonder if it's trivially easy for someone to pop out a 9600 baud build, or if perhaps that would be a more sensible default as it would be consistent with other boards and would enable interoperability with the audio jack serial stuff (which is super cool!)

    Should have an FTDI cable in a couple of weeks if all goes to plan, but I'm super excited to get started on this ASAP, as I want to build a rapid prototype for a robotics project and confirm everything works well enough before ordering parts to make a whole lot of little IP networked stepper motors.

  • here you go ... a one time special to get you going ... a build of Espruino for ESP8266 with a 9600 baud rate ...

    https://github.com/espruino/EspruinoBuil­ds/tree/master/ESP8266/Special_9600

  • Thanks @Kolban!

    Just to add, while 9600 is a bit slow, it was originally chosen because of the default config of bluetooth adaptors. It is handy in that it means that flow control isn't much of an issue because Espruino can crunch through data as fast as you can send it :)

    ... you can however set the Bluetooth adaptors to different baud rates, but then you need a USB-TTL adaptor to do that :)

  • 9600 seems.... anachronistic
    I certainly would not want to have to deal with 9600 baud!

  • 9600 is actually surprisingly usable - I know it seems like it wouldn't be :)

    The ESP8266 port should really honour the default baud rate option in BOARD.py though:

    At least then it's relatively easy for people to change - and also if boards aren't going to use 9600 by default we can make sure that every board reference page accurately reports what the default baud rate is.

  • Wonderful! Thanks @Kolban! I'll head over to my craft lab tomorrow and give this a go! 💙

    I'd like to see 9600 baud be the default on ESP8266, as it is more of a bootstrapping technology in my view - something you use to upload a telnet server if you want more speed or portability. It needs to be widely interoperable. Anything that makes the chip work with less stuff should be opt in - like could we have a function that sets the baud higher until reset? or some sort of autobauding like the chip's built in bootloader?

    Considering the 9600 compatibility of the chip's bootloader, the entire espruino firmware could be installed through an audio jack, perhaps even just as an 8bit mono wav file (or flac if you're so inclined). If it were gzipped it would compress down quite well I think! Could be really cool, continuing the experiments with webpages talking to espruino devices, to be able to flash the firmware itself right off a tablet or even an iPod. Something I'd be curious to look in to for sure.

  • Anything that makes the chip work with less stuff

    Like what? Anyone using esp8266 uses 115200 as default. I don't know of anyone that tries to talk to esp8266 using 9600 baud...

    the entire espruino firmware could be installed through an audio jack

    Please tr this and report back :-) Given how long it takes already at 115200 baud, you better prepare a sofa so you can take a nap. And how reliable is this? I bet it will crap out before done...

  • 9600 is actually surprisingly usable - I know it seems like it wouldn't be :)

    You must have more patience than I do... I find the upload from the IDE unbelievably slow. When I run a simple DS18B20 test the total code is just a couple of KB, yet it takes longer for the IDE to upload it and get it running than if I reprogram the entire esp8266 firmware!

  • @tve NodeMCU and Arduino default to 9600, so do the official espruino boards. I'm uploading the 9600baud espruino firmware now and it takes about ten minutes. More of a go make some tea kind of wait than a go have a nap kind of wait.

    It sounds like you must have another bottleneck than serial connection if your uploads are taking that long, even at 9600bd a kilobyte takes about one second to transfer, so a couple kb should be done in a couple seconds!

  • 10 minutes... If I had to wait that long each time I make a FW change... LOL
    Mhh, the arduino nano I just got flashes at 57600 or 115200 depending on clock frequency...
    Well, if you guys want to stay on 9600 baud, you're welcome to. Fortunately I can make my own Espruino builds :-)

  • The Web IDE's default is 9600, and I'll probably keep it at that so new users don't have to fiddle around in the settings.

    The whole setBootCode thing we'd been talking about would mean you could move from 9600 pretty simply once it was set up.

    As @bluebie says, I'm surprised about the DS18B20 upload taking so long as you've only got about 8k of usable memory, so the most it could take is 8 seconds before it totally filled up all your memory (unless something else is going on).

    Having said all that, the ESP8266 port seems to be for those willing to get their hands dirty at the moment - so asking them to change one setting in the Web IDE isn't really a big deal :)

  • Wow, GPIO is incredibly slow on this 9600baud build. I benchmarked running digitalWrite(D5, 1) and on average it takes 80ms to execute. It'll get a lot faster than that in the future, right?

    > s = getTime(); for (var i = 0; i < 25; i++) {
    :  digitalWrite(D5, 1);
    :}; e = getTime(); console.log("Seconds:" + (e-s) / 25);
    Seconds:0.08226768
    
  • Try taking out the digitalWrite to give us a base line. What is the cost of simply running the loop without the I/O?

  • could it be there are debug print statements in that build?

  • I don't see any debug stuff coming out of the serial console. Loop seems to run pretty fast.

    > s = getTime(); for(var i = 0; i < 500; i++) {
    :  void(0);
    :}; e = getTime(); console.log("Seconds:" + (e-s) / 500);
    Seconds:0.00035071399
    > s = getTime(); for(var i = 0; i < 500; i++) {
    :  getTime();
    :}; e = getTime(); console.log("Seconds:" + (e-s) / 500);
    Seconds:0.00046566599
    
  • I'm also seeing a lot of lost characters when trying to upload stuff using the Web IDE app in Chrome. have to hit upload again and again before it finally seems to work.

  • Try the following and see if it makes any difference:

    var ESP8266 = require("ESP8266");
    ESP8266.logDebug(false);
    s = getTime();
    for (var i = 0; i < 25; i++) {
      digitalWrite(D5, 1);
    }
    e = getTime();
    console.log("Seconds:" + (e-s) / 25);
    
  • Woah okay that sure did fix it! 0.00063072000 seconds! Cool!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Baud Rate on ESP8266

Posted by Avatar for bluebie @bluebie

Actions