Getting Started for Arduino users - Connecting CW01 (ESP8266) to WiFi

Getting Started for Arduino users - Connecting CW01 (ESP8266) to WiFi

Here is the third in our blog series for Arduino IDE users - this time connecting the ESP8266 to a WiFi access point. Previous blogs have covered:

  1. Getting Started with xChip Core CW01 (ESP8266) and IP01 programmer
  2. Programming CW01 (ESP8266) to drive Red, Green and Blue LEDs



  1. What you need
  2. Installations
  3. To do
  4. When things don't work as expected
  5. What to do next
  6. References
  7. Code file


1. What you need

  • the IP01 and CW01, set up as per our first blog in this series


          IP01 - switches                               IP01 - solder pads 

  • details for, and access to, a WiFi accesspoint
  • successful execution of the code in the second blog
  • the code at the bottom of this blog


      2. Installations

        •  see our first blog covering IP01 and CW01 Setup


        3. To do

        • set the switches on the IP01 so that the CW01 can be programmed (flashed)
          • the first version of the IP01 has 2 small switches - make sure SW1 is set to position B, and SW2 is set to the DCE position


                   top view                                    side view 

          • the second version of the IP01 does not have switches 
        • set the programmer to "Arduino as ISP" in the Tools->Programmer menu


        • open the Arduino Sketch file (at the bottom of this blog) in the Arduino IDE
        • find the line of code which reads as follows;
          • const char* WIFI_SSID = "<YOUR_SSID>";
          • replace <YOUR_SSID> with the name of your WiFi SSID, for example, if your WiFi accesspoint SSID is "Joe", the above line of code should read as follows
          • const char* WIFI_SSID = "Joe"; 
          • the same applies to <YOUR_SECRET_PASSWORD> in the line of code which reads as follows
          • const char* WIFI_PASS = "<YOUR_SECRET_PASSWORD>";
          • if your password is "my_secret", the above line of code should read as follows
          • const char* WIFI_PASS = "my_secret";
        • click the 'Verify' button or select Sketch->Verify/Compile or type CTRL+R, make sure no errors are reported, and that 'Done compiling' is reported


        • save the file using File->Save or CTRL+S if you have made any modifications to the code
        • once the compile is successful, click the 'Upload' button or select Sketch->Upload or type CTRL+U, and make sure 'Done uploading' is reported


        • observe the LEDs on the CW01, these should display Red while attempting to connect, and Green once the CW01 has connected with the WiFi access point (shown below)


        • select Tools->Serial Monitor to observe to messages output by the Serial.print("...") statements
        • when the Sketch starts, it will attempt connection with the WiFi access point, and will print "Connecting to : <YOUR_SSID >" where YOUR_SSID is the name you provided in {const char* WIFI_SSID = "<YOUR_SSID>";}
        • once the CW01 connects to the WiFi access point, 'Connection established!' and 'IP address:'
        • should be reported, where is the IP address which the ESP8266 obtained from the WiFi accesspoint



          4. When things don't work as expected
          • if you suspect something went wrong which is unrelated to the WiFi connection, follow the same 'when things don't work as expected' procedure as indicated in our second blog
          • if a WiFi connection related error is reported
            • first check the "const char* WIFI_SSID =..." and "const char* WIFI_PASS =..." code
            • make sure you have entered your WiFi accesspoint credentials correctly
            • if, for example, your WiFi accesspoint SSID is "Joe", the code should read [const char* WIFI_SSID = "Joe";] , excluding the [ and ] brackets
            • it is always a good idea to first double-check your WiFi accesspoint access credentials using your mobile phone


            5. What to do next

            • read and understand the code in this example, and move on to the next blog!


            6. References


            7. Code file

                This Sketch is an example for the XinaBox CW01 ESP8266 Board
                It demonstrates how to connect to a WiFi access point
                You can buy these devices on our store!
                Currently Supported on the following ☒CHIPs:
                - CW01
            /************************** Library Includes ********************************/
            /************************* WiFi Access Point *********************************/
            // Replace the contents between inverted commas with your WiFi details.
            // YOUR_SSID is the name of your WiFi access point.
            // YOUR_SECRET_PASSWORD is your WiFi access point password.
            const char* WIFI_SSID = "";
            const char* WIFI_PASS = "";
            /**************************** SYSTEM DEFINES *********************************/
            #define RED 12
            #define GREEN 13
            #define BLUE 5
            /***************************** Sketch Code ***********************************/
            void setup() {
              // Start the Serial Monitor
              // set ports as digital (on/off) OUTPUTs, the digitalWrite(...) statement is used to set digital ports on or off
              pinMode(RED, OUTPUT);
              pinMode(GREEN, OUTPUT);
              pinMode(BLUE, OUTPUT);
              // Connect to WIFI
            void loop() {
              // turn the RED LED on by writing a logic HIGH to the port
              digitalWrite(RED, HIGH);
              // turn the RED LED off by writing a logic LOW to the port
              digitalWrite(RED, LOW);
            // connect to WiFi network
            void WIFI_connect() {
              if (WiFi.status() != WL_CONNECTED) {
                digitalWrite(GREEN, LOW);
                // Connect to WiFi access point.
                Serial.println(); Serial.println();
                Serial.print("Connecting to : ");
                Serial.println(" ...");
                // Start ESP8266 STA mode
                WiFi.begin(WIFI_SSID, WIFI_PASS);
                // check connection status
                while (WiFi.status() != WL_CONNECTED) {
                  digitalWrite(RED, HIGH);
                  digitalWrite(RED, LOW);
                // if connected, show the IP address of the ESP8266
                if (WiFi.status() == WL_CONNECTED) {
                  digitalWrite(GREEN, HIGH);
                  Serial.println("Connection established!");
                  Serial.print("IP address:\t");
            Previous article Getting Started for Arduino users - Retrieving the time from a time server using ESP8266
            Next article Getting started for Arduino IDE users - Programming CW01 (ESP8266) to flash the LED

            Leave a comment

            Comments must be approved before appearing

            * Required fields