Pico / ESP8266 newbie (idiot?) question !

Posted on
Page
of 2
/ 2
Next
  • I'm not getting out of the starting blocks with this.

    With this simple code

    Serial2.setup(9600, { rx: A3, tx : A2 });
    var wifi = require("ESP8266WiFi").connect(Serial2,
       function(err) {if (err) throw err;wifi.getAPs(print);});
    

    I get ..

    >reset();
    =undefined
     _____                 _
    |   __|___ ___ ___ _ _|_|___ ___
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v79 Copyright 2015 G.Williams
    >echo(0);
    =undefined
    >Uncaught No 'ready' after AT+RST
     at line 1 col 17
    {if (err) throw err;wifi.getAPs(print);}
                     ^
    in function "a" called from line 1 col 100
    ...a("No 'ready' after AT+RST");else return c}
                                   ^
    in function "b" called from line 1 col 16
    {c=void 0;b&&b()}
                    ^
    in function called from system
     
    

    So it looks like I am not even talking to the 8266. Cabling is Ok. I have a 47uF cap across the power lines. Cabling possibly a bit hacky, have the 8266 board attached via header cable to breadboard where the Pico is plugged in. Have checked usual shorts and that all the pins are happy. They are. And that

    URXD -> Pico A2
    UTXD _> Pico A3
    VCC -> +3.3
    GND -> GND
    CH_RD -> +3.3 (is this right? permanently tied to +3.3?)

    My iPhone is actually seeing a WiFi Network called ESP8266 appear when I boot, though. So I guess the module is alive. When it boots, I see a steady red led on the board, and a couple of flashes from the blue led.

    Have tried 115,200 as baud rate too. Same problem.

    Any ideas please ?

    Thanks!

    Pat

  • Try instantiating the wifi adapter, w/out trying to connect to anything, and do:

    wlan.at.cmd("AT+GMR\r\n",1000,console.lo­­g);

  • Thanks !

    Tried this ..

    Serial2.setup(9600, { rx: A3, tx : A2 });
    wlan.at.cmd("AT+GMR\r\n",1000,console.lo­g);

    Got

    echo(0);
    =undefined
    Uncaught Error: Field or method "at" does not already exist, and can't create it on undefined
    at line 1 col 5
    wlan.at.cmd("AT+GMR\r\n",1000,console.lo­g);

    Have I got the right firmware ? Is there a special build to support the 8266 ?

  • Sorry, wifi.at (or whatever you called it in the initial require call, var wifi=require(...) )

  • I'm sorry. Lost. Too newbie, I suspect ! This ?

    Serial2.setup(9600, { rx: A3, tx : A2 });
    var wifi = require("ESP8266WiFi");
    wifi.at.cmd("AT+GMR\r\n",1000,console.lo­g);

    Don't understand how (without the connect) I talk down Serial2.
    Anyway, this code errors with ...

    Uncaught Error: Field or method "cmd" does not already exist, and can't create it on undefined
    at line 1 col 8
    wifi.at.cmd("AT+GMR\r\n",1000,console.lo­g);

  • You need to do the require().connect(...), not just require, sorry for unclearness. If you don't call connect, there's nothing there - connect is what gives you the wifi object.

    Also, easier command is wifi.getVersion()

    You can fire that off from the callback in connect().

    I was posting that from the phone while waiting, and didn't do a very good job of giving a helpful post.

  • Your wiring sounds good - the red LED and WiFi network seem like a good start!

    Actually, where did you get your ESP8266 from? They often have different versions of firmware on them, and different versions have different baud rates (the ones I sent with the KickStarter should use 9600 baud).

    A simple way to check, which you can copy/paste onto the left-hand side of the IDE is:

    Serial2.setup(9600, { rx: A3, tx : A2 });
    Serial2.on('data',function(d) { console.log(JSON.stringify(d)); });
    Serial2.write("AT+GMR\r\n");
    

    That should output some text (you should also see the blue light on the ESP8266 flash). For example mine shows:

    >Serial2.write("AT+GMR\r\n");
    =undefined
    "A"
    "T+"
    "GM"
    "R\r"
    "\r\n"
    "00"
    "18"
    "00"
    "09"
    "02"
    "-A"
    "I"
    "03"
    "\r\n"
    "\r\n"
    "OK"
    "\r\n"
    

    Sounds like you tried with 115200, but maybe you could also try 57600 as well?

    If that does work, you may find you still have some problems though. It's not just the baud rates that are different between versions :( However let us know how you get on - it might be there are some simple tweaks that could be made that would make it work.

  • Hey guys.

    Was having a similar problem. After I shortened a few wires and moved the 1117 right in close to the Pico would it start returning anything of value. (on a bread board)

    My mfg says its 9200 but only 115200 would not return gibberish. But my pico only works on every other try... sometime with the need of a reset(). (code run from the right side of the console). The following is where I am getting stuck...... don't know where the sdcard bit is coming from??

    
    ERROR: SD card must be setup with E.connectSDCard first
    WARNING: Module "AT" not found
    =undefined
    Uncaught Error: Field or method "connect" does not already exist, and can't create it on undefined
     at line 1 col 22
    {h.at=d=require("AT").connect(a);require­("NetworkJS").create...
                          ^
    in function "connect" called from line 2 col 58
       function(err) {if (err) throw err;wifi.getAPs(print);});
    
    
  • It's not recognizing the AT module (it mentions the SD card because, seeing the unrecognized module, checks if it can load it from an SD card) - Are you typing things into the left-hand side of IDE? Are you not connected to the internet?

    For using modules, you need to "send to espruino" from the right-hand side - the IDE intercepts it, detects the modules that are needed, fetches them from espruino.com/modules/modulename.min.js, and sends that to the Espruino.

  • No I am using the right hand side, and on the internet..... Ill try closing the console and reopening it.


    1 Attachment

    • Screenshot 2015-06-22 at 23.31.48.png
  • reset didn't help. Here is what I get on the version:

    "AT+GMR\r\r\nAT ve"
    "rsio"
    "n:0."
    "21."
    "0.0\r"
    "\nSD"
    "K ve"
    "rsion"
    ":0.9"
    ".5\r\n"
    "\r\nO"
    "K\r\n"
    
  • Not sure why it said AT wasn't found - but from the screenshot it looks like it works intermittently? The line null [] implies that all the software is loaded up.

    As @DrAzzy says it could be something with your internet connection - maybe the Web IDE couldn't load the AT module off the website sometimes?

    Thanks for trying the version. When you add the strings up you'd yet:

    AT version:0.21.0.0
    SDK version:0.9.5
    

    So it's not the version of the ESP8266 firmware that Espruino's driver was designed for - the one it was made for is 0018000902-AI03. It explains why it won't be working for you. It's frustrating that EspressIF seem to tweak the protocol every version - even tweaking the way the version is reported!

    So I guess you have two options - either you plug the ESP8266 into a USB-TTL converter and then update its firmware to the one Espruino is expecting (just google how to update it), or we can try and figure out what's not working and update the ESP8266 driver to work with it - you might not want to do that though?

  • Ordered the USB-TTL converter and another (hopefully correct version) of the board.

  • So I have my new ESP8266 and it is up and running. Couple problems. I'm still having problems with the "AT wasn't found". Happens way too often and I have a great internet connection.

    The second part is creating an access point. This works:

    
    Serial2.setup(115200, { rx: A3, tx : A2 });
    var wifi = require("ESP8266WiFi").connect(Serial2, function(err) {
      if (err) throw err;
      wifi.reset(function(err) {
        if (err) throw err;
        console.log("Connecting to WiFi");
        wifi.createAP("Test", "guest", 1, "wep", function(err) {
          console.log("Connected");
          require("http").createServer(function (req, res) {
            res.writeHead(200, {'Content-Type': 'text/plain'});
            res.write('Hello World');
            res.end();
          }).listen(80);
        });
      });
    });
    
    

    But this is having issues:

    
    function onPageRequest(req, res) {
      var a = url.parse(req.url, true);
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.write('<html><body>');
      res.write('<p>Pin is '+(BTN.read()?'on':'off')+'</p>');
      res.write('<a href="?led=1">on</a><br/><a href="?led=0">off</a>');
      res.end('</body></html>');
      if ("led" in a.query) digitalWrite(LED1, a.query["led"]);
    }
    
    Serial2.setup(115200, { rx: A3, tx : A2 });
    var wifi = require("ESP8266WiFi").connect(Serial2, function(err) {
      if (err) throw err;
      wifi.reset(function(err) {
        if (err) throw err;
        console.log("Connecting to WiFi");
        wifi.createAP("Test", "guest", 1, "wep", function(err) {
          console.log("Connected");
          require("http").createServer(onPageReque­st).listen(80);
        });
      });
    });
    
    

    says this:

    
    Uncaught Error: Field or method "led" does not already exist, and can't create it on null
     at line 8 col 57
      if ("led" in a.query) digitalWrite(LED1, a.query["led"]);
    
    
  • Interesting, thanks - I'll file a bug for it. The issue is that a.query is null sometimes (if there is no query?), and "led" in null is returning "led" for some reason in espruino.

    Try:

    if (a.query && "led" in a.query) digitalWrite(LED1, a.query["led"]);
    
  • I think the reason for the "AT was not found" was due to the load modules from npm being turned on....... and your suggestion works!

    EDIT: after further testing I am still having the AT module issue.

  • Great, glad you're getting somewhere!

    Not sure about the AT issue - if you download the IDE straight from GitHub then you can access the debug console in Chrome by right-clicking and doing inspect element - it might help to show you some error messages about what's gone wrong.

  • Just a little FYI. I found that changing the original ESP8266 (ESP8266_AT_V00180902_04.bin) Baud Rate to 115200 made it much more reliable. Serial2.write("AT+CIOBAUD=115200")

  • Ahh - very interesting - thanks for letting us know.

    I guess it might be worth updating the documentation on it? Annoyingly because the module doesn't know what pins TX and RX are, it can't automatically reset the baud rate on Serial2 - if if did it could do everything automatically.

  • Wait, so if you don't specify the pins when doing serial.setup(), and only specify the baud, it will change the pins? To what???

  • IIRC it changes them to the defaults (lowest numbered/ported pins capable of doing what was required). Now you mention it, I could change that behaviour so if no second argument is supplied it uses the one that was supplied last time (which is saved anyway, so the Serial port can be re-initialised when code is saved).

  • Yeah - thats what I would have assumed it did - I would have been very surprised if I ran into that behavior. IMO, as long as the serial has already been set up, and setup is called again, only options specified in the second call should be applied.

    Maybe you'd need serial.setup() (no arguments) to return the serial to it's default state (just like pinMode with no mode)

  • Any idea as to why the slower baud was cause issues where the higher works fine? Is anyone else able to confirm what I am seeing?

  • With a slower baud rate causing issues, my stab - without knowing any details - to anser that would be: the communication may block and prevent some interrupts or polls from the network side beeing taken care of in a timely manner. I could be totally wrong, because in a completely interrupt driven world this conclusion is very questionable.

  • I got the impression that the problem with the lower baud was related to the ESP8266 itself...?

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

Pico / ESP8266 newbie (idiot?) question !

Posted by Avatar for Pat @Pat

Actions