The ESP8266 WiFi Module–how to get it to work with an Arduino

WP_20160106_15_27_46_Pro_LIFinally got around to playing with the ESP8266 WiFi Module with an Arduino UNO.  I am using the UNO simply because it has a steady, 3.3v output while the HalfByte Console isn’t as steady and the module is, from everything I have read, is not tolerant of much more than the 3.3 volts.  Until I fix the console’s 3.3volt output, I will use the UNO.

Before I go on, I have to say, this little board isn’t very reliable. It is only connecting about a third of the time.

The documentation is spotty, even though it has been out for quite sometime now.  So, I hope to help anyone who just wants to use it as a WiFi module and not reprogram it to play Tic Tac Toe.

First, it is important to know which module you have as there are quite a few variations.  You go here to figure that out. The board I have is an ESP-01 Rev 2.  The Rev is important as you have a couple of extra steps from the rev 1 board.

From the wiki, here’s the pin out for the rev 2 board:

image

In order for this thing to work, you MUST jumper the CHIP_EN (or CHIP_PD) pin to the VCC pin, pulling the pin high.  This enables the whole thing to, you know, work. 

One other important detail…the baud rate is 115,200.  Most documentation I read said it was 9600, but, at least on mine, it is 115,200 baud.

Those two things were the key for me to get my module to connect and work.

Wiring it up is easy:image

ESP8266 ARDUINO
UTX RX (pin 0)
URX TX (pin 1)
GND GND
VCC 3.3V
CHIP_EN 3.3V
RST Reset

The code is straightforward enough. I copied an example from the wiki and modified it to work with my module and took out some extraneous junk.WP_20160106_15_59_14_Pro_LI (2)

Code:

#include <SoftwareSerial.h>
#define SSID        “xxx”
#define PASS        “xxx”
#define DST_IP      “173.194.116.116”    //google.com
SoftwareSerial dbgSerial(10, 11); // RX, TX
void setup() 
{
    // Open serial communications and wait for port to open:
    Serial.begin(115200);
    Serial.setTimeout(5000);
    dbgSerial.begin(9600);  //can’t be faster than 19200 for softserial
    dbgSerial.println(“ESP8266 Demo”);
    //test if the module is ready
    Serial.println(“AT+RST”);
    delay(1000);
    if(Serial.find(“ready”))
    {
        dbgSerial.println(“Module is ready”);
     }
    else
    {
        dbgSerial.println(“Module have no response.”);
        while(1);
     }
    delay(1000);
    //connect to the wifi
    boolean connected=false;
    for(int i=0;i<5;i++)
    {
    if(connectWiFi())
      {
      connected = true;
      break;
      }
    }
    if (!connected){while(1);}
      delay(5000);
      //set the single connection mode
      Serial.println(“AT+CIPMUX=0”);
}
void loop()
{
  String cmd = “AT+CIPSTART=\”TCP\”,\””;
  cmd += DST_IP;
  cmd += “\”,80″;
  Serial.println(cmd);
  dbgSerial.println(cmd);
  if(Serial.find(“Error”)) return;
  cmd = “GET / HTTP/1.0\r\n\r\n”;
  Serial.print(“AT+CIPSEND=”);
  Serial.println(cmd.length());
  if(Serial.find(“>”))
  {
    dbgSerial.print(“>”);
  }else
  {
    Serial.println(“AT+CIPCLOSE”);
    dbgSerial.println(“connect timeout”);
    delay(1000);
    return;
  }
  Serial.print(cmd);
  delay(2000);
  //Serial.find(“+IPD”);
  while (Serial.available())
  {
  char c = Serial.read();
  dbgSerial.write(c);
  if(c==’\r’) dbgSerial.print(‘\n’);
  }
  dbgSerial.println(“====”);
  delay(1000);
}
boolean connectWiFi()
{
  Serial.println(“AT+CWMODE=1”);
  String cmd=”AT+CWJAP=\””;
  cmd+=SSID;
  cmd+=”\”,\””;
  cmd+=PASS;
  cmd+=”\””;
  dbgSerial.println(cmd);
  Serial.println(cmd);
  delay(2000);
  if(Serial.find(“OK”))
  {
    dbgSerial.println(“OK, Connected to WiFi.”);
    return true;
  }else
  {
    dbgSerial.println(“Can not connect to the WiFi.”);
    return false;
  }
}

Because I am using the serial I/O on the UNO for the module, I used softwareserial to talk to a HalfByte Console running the HalfByte graphical terminal sketch so I could see the output of the module.  Normally, you would, likely, not have any kind of output on the Arduino as you’d be using the WiFi module for your I/O. I’m guessing.

I may order a few more of these things to play with reprogramming them and running code directly on them.  There is a Basic Language interpreter, LUA and Javascript for them, so I may play with that.  For now, IF I can get it working reliably, I may pair one with an ATTINY85, like a Trinket or DigiSpark, and a DHT11 temp sensor and set up a network of wireless thermometers in the house. 

I can see the potential, but the reliability is an issue.

Building your own hand held gaming console Part 1

WP_20151111_23_02_12_RichSince getting involved with Arduino and other Microcontrollers, I have designed and built several ‘consoles’ with the most involved one, the HalfByte Console Computer having its own PC Board designed and fabricated.  That was a fun project, well, they all have been, but this one was special: it was my first PC board design that was ‘produced’.   I also managed to design another console, but this was a game rig that went in an old Gameboy case.  This was only partially my design, as the 328 was actually an Arduino Mini Pro.  I added a sound amp, the screen and controller circuitry. So, it wasn’t entirely my design and it was a bit less satisfying. So…

I designed my own hand held from the ground up. This one, currently, lacks sound, and has a simpler controller: three buttons which translate into an action button, a left/up and right/down set of buttons. There is also a reset switch.

This design is very simple: it is a minimalist Arduino 328 compatible with four switches and a Nokia 5110 LCD screen.

WP_20151103_22_17_58_Rich_LIThe whole thing is on a perf board (in this case, it was a freebie board from Bay Area Circuits, go to their website and request the free boards, there Is a link for the request. These are very nice boards and a cool blue color.)

I started out by placing the parts on the board to see if I had room.  I did.

Be sure to photograph the board with the parts located where you wish to place them, this way you have a record of where you put them.

WP_20151103_23_11_54_Rich (2)

My initial design had only left and right buttons, no third button. I added that and the reset button to give me a bit more flexibility.

And, one lesson learned: socket the screen.  On the 5110, the thicker part of the bezel is the TOP, not the bottom.

For this project, you will need:

Quantity

Part Name

Value

2

Ceramic Capacitor

22pF

1

16MHZ Crystal

16MHZ

3

Resistor

220 ohm

1

AtMega 328P

328

1

28 DIP Socket

28 pin

4

Momentary Push Buttons

 

1

Red, LED

 

1

Resistor

150 ohm

1

Four pin header

 

1

5110 LCD

 

Parts placement is up to you, but I put the crystal and two caps under the screen, but you can put them where ever you want.

HalfByteHandheld2_schemI would start by placing the 28 pin socket and header on the board first. Solder them in place, use ample solder because you will have to solder wire to the socket and header. Use tape to hold them on the board while you solder them in place.

The LED is the only part that could be soldered in wrong because the key is hard to see. It is the flat side of the LED that is soldered to the resistor.

WP_20151109_22_44_49_Rich_LIOnce everything is soldered in place, insert your 328 controller chip and apply power.  If the 328 contains the standard Arduino boot loader, the pin 13 LED should blink.  If it does, congratulations! You now have a fully functional computer in your hand.

Some things I plan to add are sound and, perhaps, two more buttons.  I may add a video out option, but this is meant to be a handheld, so the video may not happen.

Stay tuned for part two, the software.

WP_20151111_23_04_16_Rich_LI

 

Short Video

Holiday Greetings from Half-Byte!

To celebrate the season, I give you  a little code snippet for Half-Byte Tiny Basic:WP_20141221_13_57_19_Pro
100 CLS
110 LINE 40,2,20,22,1
120 LINE 40,2,60,22,1
130 LINE 20,22,60,22,1
140 BOX 38,22,4,2,1
150 SET 40,1
160 SET 38,10
170 SET 30,15
180 SET 45,17
190 SET 24,18
200 SET 48,19
210 SET 36,12
220 SET 32,16: RESET 37,14
230 DELAY 1000
240 # Seasons Greetings!
250 CURSOR 8,5
260 PRINT “Merry”
270 CURSOR 6,6
280 PRINT “Christmas!”
290 DELAY 1000
300 RESET 45,17
310 RESET 38,15
320 RESET 36,12
330 SET 37,14
340 SCROLL “Merry Christmas!        ”
350 DELAY 1000
500 GOTO  100

WP_20141221_13_49_32_Pro

NOTE: remove line 340 if you do not have Half-Byte Tiny Basic V2.2.

Holiday Greetings from Half-Byte!

To celebrate the season, I give you  a little code snippet for Half-Byte Tiny Basic:WP_20141221_13_57_19_Pro
100 CLS
110 LINE 40,2,20,22,1
120 LINE 40,2,60,22,1
130 LINE 20,22,60,22,1
140 BOX 38,22,4,2,1
150 SET 40,1
160 SET 38,10
170 SET 30,15
180 SET 45,17
190 SET 24,18
200 SET 48,19
210 SET 36,12
220 SET 32,16: RESET 37,14
230 DELAY 1000
240 # Seasons Greetings!
250 CURSOR 8,5
260 PRINT “Merry”
270 CURSOR 6,6
280 PRINT “Christmas!”
290 DELAY 1000
300 RESET 45,17
310 RESET 38,15
320 RESET 36,12
330 SET 37,14
340 SCROLL “Merry Christmas!        “
350 DELAY 1000
500 GOTO  100

WP_20141221_13_49_32_Pro

Hacking the Half-Byte Console and Tiny Basic v2 (or, making Tiny Basic tell me the temperature)

WP_20140826_22_19_55_ProI had one main goal in mind when I designed the Half-Byte Console: to bring together parent and child in a learning experience. Now that the console is a reality and a few are out in the wild, I want it to do other things.  So, I thought ‘what can this do that isn’t expensive and would be easy to add to the Tiny Basic as well?’

Looking around my office, I see a DHT-11 temperature and humidity sensor. Ah ha! These are cheap, just a few dollars each.  They are also easy to access in code and, with only three pins, easy to connect.  So, this is the Half-Byte Console’s first hack: measuring indoor environment.

The DHT-11 has three pins: +5, data and Ground (-).  I chose to use D5 on the console as it is safe to use and won’t interfere with video or the keyboard.  Plus, it is easy to get to on the board. I loaded the example sketch and changed the pin reference to make sure it worked. It did. WP_20140826_22_20_22_Pro

Next, I added support for the sensor to Tiny Basic.  I am working on Version 2 and this support will be part of that release (which should be ready very soon.)

Support comes in the form of two functions:

  • x=Temp(1)
  • x=Humidity (1)

The parameter for Temp actually has meaning: if the parameter is a zero, the temperature is returned as Celsius. If it is a 1, it is returned as Fahrenheit. Any non-zero parameter defaults to Fahrenheit.WP_20140826_22_20_46_Pro

So, now the console can do something useful.  I’m anxious to get the release of Tiny Basic out and see what you all can do with this new functionality.  I am going to post more on the new features of Tiny Basic (hint…more graphics, LIST is fixed…)

In the mean time, if you have any suggestions for Tiny Basic, please let me know in the comments.

Half-Byte Tiny Basic Type In Game: Invader

WP_20140719_003Yep, I use ‘Invader’ a lot. Here’s a version, just for Half-Byte Tiny Basic. It features Wii Nunchuck support, sound and AWESOME graphics! Just awesome!

100 CLS
110 X=0:Y=0:D=1:Z=75
120 LINE 0,38,79,38,1
130 B=9:C=5:U=4:V=0
140 CURSOR 0,7:?”Score:”;
150 GOSUB 800
160 GOSUB 900
170 P=PAD(3)
180 IF P=1 S=1
185 IF P=1 TONE 1024,100
190 IF S=1 GOSUB 700
290 GOTO 150
700 CURSOR B,U:?CHR(142);
710 DELAY Z:CURSOR B,U:?”  “;
720 U=U-1
730 IF U<1 IF B<>X U=4:S=0
740 IF U<1 IF B=X GOSUB 1000
790 RETURN
800 CURSOR B,C:?CHR(151);
890 RETURN
900 CURSOR X,Y:?CHR(152);:DELAY X:CURSOR X,Y:?CHR(153);:DELAY Z:CURSOR X,Y:?”  “;
910 X=X+D:IF X>17 D=-1:X=17
920 CURSOR X,Y:?”  “;
930 IF X<2 D=1:X=2
990 RETURN
1000 CURSOR B,U:?”*”;:DELAY 3*X:CURSOR B,U:?” “;:DELAY 3*Z:?”*”;:DELAY 3*Z:CURSOR B,U:?” “;
1010 S=0:V=V+100
1020 CURSOR 0,7:?”Score:”,V;
1030 U=4
1040 TONE 2,400
1090 RETURN

There’s room let to add code to move your ‘tank’ and, perhaps, have the moon guy shoot back.

It is a simple little, but I found it a bit difficult to shoot the moon guy.  The rules are simple: use the ‘Z’ button on the Wii Nunchuck to fire a missile at the moon guy. You get 100 points for each hit. Play continues until you get bored.  Tinker with the code, add more gameplay and share it with us.

Have fun!

Half-Byte Console, now available

We have kits and an assembled and tested unit for sale on our eBay store.

For information on the Programmer’s Kit, click here.

For information on Half-Byte Tiny Basic, click here.

For sample HB Tiny Basic code, click here.