Thursday
Feb042016

Windows Mobile 10: It's tough being a fan

About seven years ago, I got genuinely excited about a new consumer product.  That product had WP_20141110_009all kinds of promise: price, performance, looks, ease of use and the ability to be a small computer I could carry around with me to surf the web, read my mail, do some short writing stints and more. Oh, I could make and receive phone calls.  That device was the Palm Pre smartphone.

I laughed at people who waited in line, before a store even opened, for Apple products.  I thought it was absurd. Yet, there I was, with about 15 other good people, waiting in front of a Sprint store to get my Palm Pre.  I don't recall how much I paid, but, at that point, I didn't much care as it was not the seven hundred or so that the iPhone was then.

Oh boy, I got my phone and a haircut and rushed home to play with my new toy.  This thing was just spectacular.  Touch screen AND a keyboard (it was a slider phone that looked like big pebble) and was super easy to use.  And, its browser really worked...no more quasi browser like my Windows Mobile 5 powered Motorola Q.  The Pre was just great.  For about a year. That's when the cheapness of the poorly designed plastic body came into play.  See, the hardware, while attractive, was a disaster.  The body had lots strain from the sliding and would eventually crack.  The battery did last long either. It would die and not even be turned on.  And so ended my love for the Pre, but not WebOS.  There has not been anything close until last year.CIMG0118

Lets roll back time a bit.  The aforementioned Moto Q ran Windows Mobile 5, a cramped and poor copy of desktop Windows. Frankly, it was an abomination.  The interface was pretty bad.  The included applications were awful and the support from third parties was not great. In short, Windows Mobile 5, and all versions before it, was just awful.  It's only plus was the Windows Live application that, in many aspects, was similar to Google Now or Cortana. You could talk to it and it would, verbally as well as visually, answer you. I used it a lot in the last few months I used the Q.

myWin10PhoneFast forward a few years and Micorosoft is, once again, hawking a product called Windows Mobile for Phones.  This time, the operating system is just gorgeous. And functional.  It's everything that a mobile operating system should be and more.  It is as good today as webOS was then.  And, it can be used as a desktop operating system as well, via a feature called Continuum. Indeed, on its own, installed in desktop hardware, it could work wonderfully with a keyboard and a mouse. 

Yet, it gets little love and Microsoft is to blame, mostly,  They do not promote it or its capabilities. They port its great features to iOS and Android and even save it for last when developing apps for mobile devices.  It is treated like a distant cousin.  But, that doesn't mean it does not have fans or support. True, it has few of each, but they are there.  And, now, there are more and more hardware manufacturers jumping on board.  In addition to Microsoft, there are companies like Acer, HP, Asus, the former Sony brand turmyWin10Phone3ned company, VAIO, and a host of others.  The phones range from just OK to stellar.  Most are able to support Continuum (it requires a certain class of processor and 2gb of ram, minimum) and all run Windows 10. 

As a user and a fan, I often find it difficult to stay both when I see stories about its demise, when I see Microsoft putting it on the back burner for some lame iOS project or hear the CEO say in one sentence just how important it is while the next sentence he would, essentially, say it was not that important after all.  Indeed, it is difficult being a fan and staying enthusiastic about the platform. 

Windows Mobile 10, Windows 10 Mobile, or what ever they call it, has so much potential--more than its desktop companion, I think.  There's no reason why Microsoft could not port Visual Studion to WM10.  With a mouse and keyboard attached (in Continuum) a developer could very easily develop on the phone.  This powerful OS has the potential to, provided the hardware supports it, completely replace your desktop.  Hell, the iPhone could if Apple pulled its head out of its ass.

WP_20150107_003So, yeah, I went from one doomed smartphone to another seemingly doomed platform.  Oh, in between I had an Android and an iPhone 4. Didn't like them, hated the Android and, early on, liked the iPhone until i 'upgraded' to iOS 7...ugh, what a piece of crap that was.  But, I digress.

Even though I hated my Android phone, if I do get away from Windows Mobile, I think I would have to get a Samsung Galaxy whatever. They are beautiful phones and Android is, finally, getting useable. Some of the siliness is gone, but the fracturing is still there.  So, why not iPhone? Well, it's Apple and that means there are lots of costs.  The hardware is very nice and iOS 9 looks great. My son has a 6 and loves it.  I've played with it and it is far and away better than the version I had.  But, it is still Apple and that means you are married to them and that is one marriage I do not care to join.WP_20141110_018

So, how long do I have with my favorite mobile operating system? Well, until Microsoft says they won't support it or they dump the business they paid billions for, a few short years ago.  I am pining for the Lumia 950, but that Acer Jade Primo looks awfully nice too.  The VAIO looks good as well.  So, there are a few non-Microsoft phones that I would buy, but...I'd rather get a 950. Unfortunately, I have, yet again, picked the wrong carrier (Verizon, which hates Microsoft) and still have about a year left on my bloody contract.  I'm hoping there is a more drool worthy phone out by then. Until then, I'll continue along with my beat up ICON. It is still a great phone and works like a champ, running Windows Mobile 10. 

Did I mention I love Windows Mobile 10? Oh, right. 

Sunday
Jan242016

Building a WiFi based Room Monitor using an ESP8266 and an Arduino compatible

BeautifulPhoto635888272313367045Having purchased a few of the ESP8266 WiFi modules, I decided to devote one of them to a room monitoring device.  I live i a fairly good sized home, with an oversized garage. The room over the garage is a bedroom.  Well, the room, while nicely insulated, is huge and is difficult to maintain the same temperature as the rest of the upstairs.  And, since it is a bedroom where a child who has a problem maintaining his body temperature sleeps and plays, we need to keep an eye on the temp in that room.

I did have an Arduino UNO with the ethernet shield and a DHT11 sensor in the room, but the ethernet sheild did not work well with the WiFi extender I have in the room.  And, wanting to actually build something specifically for the purpose at hand, I decided to design and build a solution around the wifi module.

It needed to be simple and, preferably, run off of a battery.  While I have not yet gotten to WP_20160106_15_27_46_Pro_LIthe battery solution yet, I do have the rest built and am working on the code.

The whole thing fits on a 2.5 by 2inch perf board. It features an Atmega 328 chip, a Nokia 5110 LCD, DHT11 temp/humidity module, the aforementioned ESP8266 module, LED's, a few caps and resistors and a 16mhz crystal.

WP_20160112_22_25_33_Pro_LIAssembly was easy.  Remembering the cathode on an LED...that's hard, for me.  I always hated those damn things.  I love blinky lights, but can't stand to wire up the things.  UGH.  Anyway, I'm only using a few of the I/O pins on the 328: Serial in and out, D2, A4, A5 and, for the LCD, D3 through D7.  This leaves a few pins for you to use if you wish to expand the capabilities of the device.

I started out by soldering the socket for the chip.  Then, I wired up the reset, which is pin 1 to a WP_20160119_22_28_27_Pro_LImomentary push button connected to ground.  I then wired up pin 13 to an LED via a 150 ohm resistor, connected to ground. Power (pin 7) and  ground (pin 8) were next.  You can test, at this point, by inserting a 328 that has the standard Arduino bootloader and nothing else burned into the chip. Insert the chip, apply five volts and the LED should blink.  If so, congrats!

You can install a power on LED as well.  Solder an LED and 150 ohm resistor to ground and Pin 7. When power is applied, the LED should light up.

The crystal was next.  Solder the crystal to pins 9 and 10.  Solder a 22pF capacitor to each each pin of the crystal and tie them to ground.

If you are at this point, congratulations, you have built a very basic Arduino compatible microcontroller. 

WP_20160115_18_50_02_Pro_LIFrom this point, I soldered some headers so I could connect serial I/O, power and the connections for the DHT11 and RTC (1307).   I then soldered the Nokia 5110 to the board and connected it as follows:

pin 7 - Serial clock out (SCLK)
pin 6 - Serial data out (DIN)
pin 5 - Data/Command select (D/C)
pin 4 - LCD chip select (CS)
pin 3 - LCD reset (RST)

Connect pin 6 on the LCD to +5, pin 8 to Ground and pin 7 to +5 if you want the back light. I connected a switch to my display so I could turn the light on or off.  Add the swtich between the +5 and pin 7 if you wish.

I uploaded a demo 5110 sketch to make sure the screen worked. It did.

The DHT only has one data pin, the middle pin, and it goes to D2 on the chip.  Connect the others to +5 and ground.

WP_20160118_00_04_44_Pro_LI (2)As the ESP8266 is intolerant of higher voltages, I installed a 3.3v regulator to power the module.  I grab a five volt line, solder it to the right pin of the to220 regulator, the left most pin to ground and the middle pin to the VCC pin on the 8266.  The TX line from the 8266 goes to D0 on the 328, the RX line to D1 and, ground to ground. You also, if you have the v1 of the module, connect power to the chip select pin (4) of the 8266 as well as connect its RST pin to the reset pin of the 328. 

The RTC (real time clock) is connected:
SCL to A5 on 328
SDA to A4 on 328
VCC to +5
GND to ground

Connect it all up and you have a complete wifi based room monitor. For now, it returns the temperature and humidity.  At somepoint, I am going to return a timestamp so I graph the data and figure out when the temperature spikes or cools. 

Software

WP_20160122_13_12_55_Pro_LIGetting the LCD to display the date, time, temperature and humidity was simple.  The issue I have is with the wifi module. And it is also keeping me from posting a complete solution. So, I am going to post what I have. If one of you can figure out the webserver piece, please share it with us. I am sure it is something I am doing wrong. 

The code is at the end of this post.

Building things from 'scratch' is far more rewarding than just connecting a few sensors to an UNO or some other board.  But, you can do that if you wish.  At any rate, no matter what you do, YOU are still doing it and that is what matters. 

Code:

/*********************************************************************
* This sketch uses the Adafruit libraries for Monochrome Nokia 5110 LCD Displays
*
* Pick one up today in the adafruit shop!
* ------> http://www.adafruit.com/products/338
*
* These displays use SPI to communicate, 4 or 5 pins are required to
* interface
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Limor Fried/Ladyada  for Adafruit Industries.
* BSD license, check license.txt for more information
* All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>
#include "DHT.h"
#include <Wire.h>
#include "RTClib.h"

#define BUFFER_SIZE 128
char buffer[BUFFER_SIZE];

DHT dht;
RTC_DS1307 rtc;

// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// Workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734
#ifdef PROGMEM
#undef PROGMEM
#define PROGMEM __attribute__((section(".progmem.vars")))
#endif
const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000001, B10000000,
  B00000011, B11000000,
  B00000111, B11100000,
  B00001111, B11110000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000,
  B00000000, B00000000
};
#define SCREENWIDTH 84
#define SCREENHEIGHT 48

#define DEBUG true
const int ESP8266_CHPD = 4;
int isConnected = false;

void setup() {

  display.begin();
  Wire.begin();
  rtc.begin();
  //rtc.adjust(DateTime(__DATE__, __TIME__));
  if (! rtc.isrunning()) {
    display.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(__DATE__, __TIME__));
  }
  Serial.begin(115200); // your esp's baud rate might be different
  Serial.setTimeout(5000);
  Serial.println("AT+RST");

  if (Serial.find("ready"))
  {
    display.println("Module is ready");
    isConnected = true;
    display.drawBitmap(0, 0, logo16_glcd_bmp, 16, 16, BLACK);
    display.display();
  }
  else
  {
    display.println("Module have no response.");
    display.display();
    setup();
  }
  Serial.print("AT+CWMODE=1\r\n");
  Serial.print("AT+CWJAP=\"xxx\",\"xxx\"\r\n");  //replace xxx with your ssid and password
  Serial.print("AT+CIFSR\r\n");
  Serial.print("AT+CIPMUX=1\r\n");
  Serial.print("AT+CIPSERVER=1,80\r\n");
  display.println(Serial.read());
  display.setContrast(50);
  dht.setup(2); // data pin 2
  display.display(); // show splashscreen
  delay(2000);
  display.clearDisplay();   // clears the screen and buffer
  display.display();
  display.setTextSize(1);
  display.setTextColor(BLACK);
  display.println("HalfByte Room    Monitor");

  display.display();
  delay(3000);
  display.clearDisplay();
  display.setTextSize(1);
}

void loop() {
  int ch_id, packet_len;
  char *pb;
  Serial.readBytesUntil('\n', buffer, BUFFER_SIZE);

  delay(dht.getMinimumSamplingPeriod());

  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();

  display.clearDisplay();
  display.display();
  if (isConnected == true) {
    display.drawBitmap(70, 0, logo16_glcd_bmp, 16, 16, BLACK);
    display.display();
  }
  display.setCursor(3, 29);
  display.print("Humidity: ");
  display.setCursor(display.width() / 2, 38);
  display.print(humidity, 1);
  display.print("%");
  display.setCursor(3, 20);
  display.print("Temp: ");
  display.setCursor(40, 20);
  display.print(dht.toFahrenheit(temperature), 1);
  display.print("F");
  display.drawRect(0, 28, display.width(), 19, BLACK);
  display.display();

  DateTime now = rtc.now();
  display.setCursor((display.width() / 2) - 35, 1);
  if (now.month() < 10) display.print(0);
  display.print(now.month(), DEC);
  display.print('/');
  if (now.day() < 10) display.print(0);
  display.print(now.day(), DEC);
  display.print('/');
  display.print(now.year(), DEC);
  display.setCursor((display.width() / 2) - 30, 12);
  if (now.hour() < 10) display.print(0);
  display.print(now.hour(), DEC);
  display.print(':');
  if (now.minute() < 10) display.print(0);
  display.print(now.minute(), DEC);
  display.print(':');
  if (now.second() < 10) display.print(0);
  display.print(now.second(), DEC);
  display.display();

  if (strncmp(buffer, "+IPD,", 5) == 0) {
    // request: +IPD,ch,len:data
    sscanf(buffer + 5, "%d,%d", &ch_id, &packet_len);
    if (packet_len > 0) {
      // read serial until packet_len character received
      // start from :
      pb = buffer + 5;
      while (*pb != ':') pb++;
      pb++;
      if (strncmp(pb, "GET / ", 6) == 0)
        //if (Serial.available()) // check if the esp is sending a message
        //{
        if (Serial.find("+IPD,"))
        {
          //delay(1000);
          delay(100);
          clearSerialBuffer();
          int connectionId = Serial.read() - 48; // subtract 48 because the read() function returns
          display.print(connectionId);
          display.display();
          // the ASCII decimal value and 0 (the first decimal number) starts at 48
          homepage(connectionId);
        }
    }
  }
}

void homepage(int ch_id) {
  String Header;
  float temperature = dht.getTemperature();
  Header =  "HTTP/1.1 200 OK\r\n";
  Header += "Content-Type: text/html\r\n";
  Header += "Connection: close\r\n";
  Header += "Refresh: 5\r\n";

  String Content;
  Content = "Environmental Status:<br/>";
  Content += String("<B>Temperature:</b>");
  Content += String(dht.toFahrenheit(temperature));
  Content += String("<br><b>Humidity: </b>");
  Content += String(dht.getHumidity());
  Header += "Content-Length: ";
  Header += (int)(Content.length());
  Header += "\r\n\r\n";


  Serial.print("AT+CIPSEND=");
  Serial.print(ch_id);
  Serial.print(",");
  Serial.println(Header.length() + Content.length());
  delay(10);

  //if (Serial.find(">"))
  {
    Serial.print(Header);
    Serial.print(Content);
    Serial.println("AT+CIPCLOSE=0");

    delay(10);
  }
}


// Get the data from the WiFi module and send it to the debug serial port
String GetResponse(String AT_Command, int wait) {
  String tmpData;

  Serial.println(AT_Command);
  delay(10);
  while (Serial.available() > 0 )  {
    char c = Serial.read();
    tmpData += c;

    if ( tmpData.indexOf(AT_Command) > -1 )
      tmpData = "";
    else
      tmpData.trim();

  }
  return tmpData;
}

void clearSerialBuffer(void) {
  while ( Serial.available() > 0 ) {
    Serial.read();
  }
}

void clearBuffer(void) {
  for (int i = 0; i < BUFFER_SIZE; i++ ) {
    buffer[i] = 0;
  }
}

boolean connectWiFi(String NetworkSSID, String NetworkPASS) {
  String cmd = "AT+CWJAP=\"";
  cmd += NetworkSSID;
  cmd += "\",\"";
  cmd += NetworkPASS;
  cmd += "\"";

  GetResponse(cmd, 10);
}

Wednesday
Jan062016

Using a Max7219 8x8 LED Matrix with an ATTINY85, like Trinket or DigiSpark

While waiting for part two of the handheld construction article, I thought I’d give you a little distraction about interfacing an ATTINY85 to an 8x8 LED Matrix using the Max7219 chip.

ATTINY85LEDMatrix1Been working on getting either a DigiSpark or Trinket to work with one of my 8x8 LED matrix displays. Connection is simple, but the maxmatrix library doesn't seem to like the ATTINY85 processor. So, I went looking for something that did or, at least, getting enough knowledge to bit bang my way to displaying SOMETHING on the little display. Well, I found some code to do this, but it is not very pretty and doesn't do enough. However, it does give a good demo of how to make these arrays do something and, even better, work with the confines of the ATTINY85 processor.
The code shows how turn on and off pixels (a specific LED in the matrix, to be more precise) and send a 'bitmap' to the display.
Cool stuff. Could be another game or, perhaps, a temperature display, mood indicator, etc.

You can grab the code I used (middle of the page) here...http://www.avrfreaks.net/…/max7219-8x8-dot-matrix-led-drive…

FYI-To connect it:
PB0 -> DIN
PB1 -> CS
PB2 -> CLK
+5 -> VCC
GND -> GND

Pretty easy. ATTINY85LEDMatrix21

The code I found puts a smiley face, inverts the screen, frowny face, etc. up on the display. I took out the inversion as it takes too much time.  This code, which is unattributed as the poster on the AVR forum did not credit the code, is a good start, but needs work.  I thought about modifying it to handle ASCII text, but that will be a ways off yet. I have several things to finish up before then. 

I’d love to see what you can do with this, so drop us a note in the comments or send me an email and I’d be happy to write it up and post it here.

Code:

/*
  One MAX7219 connected to an 8x8 LED matrix.
 */

#include <avr/io.h>
#include <util/delay.h>

#define CLK_HIGH()  PORTB |= (1<<PB2)
#define CLK_LOW()   PORTB &= ~(1<<PB2)
#define CS_HIGH()   PORTB |= (1<<PB1)
#define CS_LOW()    PORTB &= ~(1<<PB1)
#define DATA_HIGH() PORTB |= (1<<PB0)
#define DATA_LOW()  PORTB &= ~(1<<PB0)
#define INIT_PORT() DDRB |= (1<<PB0) | (1<<PB1) | (1<<PB2)

uint8_t smile[8] = {
        0b00000000,
        0b01100110,
        0b01100110,
        0b00011000,
        0b00011000,
        0b10000001,
        0b01000010,
        0b00111100};

uint8_t sad[8] = {
        0b00000000,
        0b01100110,
        0b01100110,
        0b00011000,
        0b00011000,
        0b00000000,
        0b00111100,
        0b01000010,
};


void spi_send(uint8_t data)
{
    uint8_t i;

    for (i = 0; i < 8; i++, data <<= 1)
    {
  CLK_LOW();
  if (data & 0x80)
      DATA_HIGH();
  else
      DATA_LOW();
  CLK_HIGH();
    }
    
}

void max7219_writec(uint8_t high_byte, uint8_t low_byte)
{
    CS_LOW();
    spi_send(high_byte);
    spi_send(low_byte);
    CS_HIGH();
}

void max7219_clear(void)
{
    uint8_t i;
    for (i = 0; i < 8; i++)
    {
  max7219_writec(i+1, 0);
    }
}

void max7219_init(void)
{
    INIT_PORT();
    // Decode mode: none
    max7219_writec(0x09, 0);
    // Intensity: 3 (0-15)
    max7219_writec(0x0A, 1);
    // Scan limit: All "digits" (rows) on
    max7219_writec(0x0B, 7);
    // Shutdown register: Display on
    max7219_writec(0x0C, 1);
    // Display test: off
    max7219_writec(0x0F, 0);
    max7219_clear();
}


uint8_t display[8];

void update_display(void)
{
    uint8_t i;

    for (i = 0; i < 8; i++)
    {
  max7219_writec(i+1, display[i]);
    }
}

void image(uint8_t im[8])
{
    uint8_t i;

    for (i = 0; i < 8; i++)
  display[i] = im[i];
}

void set_pixel(uint8_t r, uint8_t c, uint8_t value)
{
    switch (value)
    {
    case 0: // Clear bit
  display[r] &= (uint8_t) ~(0x80 >> c);
  break;
    case 1: // Set bit
  display[r] |= (0x80 >> c);
  break;
    default: // XOR bit
  display[r] ^= (0x80 >> c);
  break;
    }
}


int main(void)
{
    uint8_t i;
    
    max7219_init();
    
    while(1)
    {
  image(sad);
  update_display();
  _delay_ms(500);
  image(smile);
  update_display();
  _delay_ms(500);

  // Invert display
//  for (i = 0 ; i < 8*8; i++)
//  {
//      set_pixel(i / 8, i % 8, 2);
//      update_display();
//      _delay_ms(10);
//  }
  _delay_ms(500);
    }
}

 

 

Wednesday
Jan062016

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.

Sunday
Nov292015

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