Wednesday, July 19, 2017

ESP01 - Introduction

Pin configuration of the ESP01 is shown below:


Connection of ESP01 to the Arduino:

ESP01 Arduino
TX Pin 3
CH_PD 3.3V
RST No Connection
VCC 3.3V
RX Pin 4*
GPIO0 No Connection
GPIO2 No Connection
GND GND

* A resistor network to be used to drop the 5V signal from the Arduino to 3.3V for the ESP01.

A typical Arduino sketch to communicate with the ESP01:

#include <SoftwareSerial.h>

#define DEBUG true

// UNO's D3 connected to ESP's TX
// UNO's D4 connected to ESP's RX via resistor network
SoftwareSerial ESP01(3, 4); // RX, TX

String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete

void setup() {                  
  Serial.begin(9600); 
  while (!Serial);
  Serial.println("Starting...");
  ESP01.begin(9600);
  inputString.reserve(200); // reserve 200 bytes for the inputString:
}

void loop() {
  if (stringComplete) {
    sendData(inputString,2000,DEBUG);  // print the string when a newline arrives:
    inputString = "";   // clear the string:
    stringComplete = false;
  }
  delay(100);
}

void serialEvent() {
  while (Serial.available()) {      
    char inChar = (char)Serial.read();      // get the new byte:
    
    inputString += inChar;                  // add it to the inputString:
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    ESP01.print(command);
    long int time = millis();
    while( (time+timeout) > millis())
    {
      while(ESP01.available())
      {
        // "Construct" response from ESP01 as follows - this is to be displayed on Serial Monitor. 
        char c = ESP01.read(); // read the next character.
        response+=c;
      }  
    }
    if(debug) Serial.print(response);
    return (response);
}

Monday, June 27, 2016

Passion Gadgets mifi Powerbank


1. Switch the Powerbank to "C" for charging; and to "R" for mifi function.
2. Plug in the 3G doggle into the USB connector, and then turn on the mifi function. Wait for a while for the 3G to be connected.
3. To change the setting of the wifi router, go to http://192.168.169.1. The account and password is on the body of the Powerbank.

A similar product user guide is here: https://drive.google.com/file/d/0B8rNxnVUXy0DN0RkdFVEWlF4aHc/edit

Sunday, August 28, 2011

Arduino Basics

1. All variables declared in the loop function are not static. That is, their values are not retained after each loop.

2. To view the values of variables in the Arduino during program execution, use the serial communication facilities within the software to transmit those values back. In the setup function, add "Serial.begin(9600);". And then in the loop function, add "Serial.println(k);" to send the value of k back periodically. Then at the Arduino software menu: Tools>>Serial Monitor. The communication screen (like that of hyperterminal) will appear!


Saturday, June 11, 2011

Screen capture in MAC OS

  • To capture the entire desktop, press Command-Shift-3. The screen shot will be automatically saved as a PNG file on your desktop.
  • To copy the entire desktop, press Command-Control-Shift-3. The screen shot will be placed on your clipboard for you to paste into another program.
  • To capture a portion of the desktop, press Command-Shift-4. A cross-hair cursor will appear and you can click and drag to select the area you wish to capture. When you release the mouse button, the screen shot will be automatically saved as a PNG file on your desktop.
  • To capture a specific application window, press Command-Shift-4, then press the Spacebar. The cursor will change to a camera, and you can move it around the screen. As you move the cursor over an application window, the window will be highlighted. The entire window does not need to be visible for you to capture it. When you have the cursor over a window you want to capture, just click the mouse button and the screen shot will be saved as a PNG file on your desktop.
  • Add Control to the two shortcuts above to place the screen shot on the clipboard instead of saving it to the desktop.

Reference: http://graphicssoft.about.com/od/screencapturemac/ht/macscreenshot.htm

Create gif in Photoshop CS5

  1. Open a new document matching the dimensions of your source images.
  2. Select all of the source images to be animated and drag them together into Photoshop. Release them over the general workspace. The first image should show up with a superimposed “X.” New to Photoshop CS5, the images will stack one at a time as layers in your current document when you hit “Enter”. Keep hitting “Enter” until all of the images are loaded as individual layers. However, you may only see one image on your screen. This is because the other images are hidden under the first image. Click on the visibility button on the layer menu to deselect all images except the one you want to view.
  3. Rearrange the layers into the correct order, if necessary.
  4. Open the Animation palette (Window > Animation). You should observe a storyboard-like sequence showing all the layers at the bottom of the screen. This is the animation palette.
  5. In the Animation palette menu (found at the top right corner of the palette), click Make Frames From Layers. You can also click Reverse Frames if needed. This will take each layer in your document and set it as an individual frame in the animation.
  6. Make sure you are in frame view, not timeline view. If you do not see thumbnail icons of your layers in the Animation palette, click the icon in the lower right corner (the hover text will say “Convert to Frame Animation”).
  7. Now we will change the duration of each frame. Click the drop down button just underneath each frame image (circled in red in the image below). This will bring up a menu where you can set a duration.
  8. The drop down button at the left bottom of the animation palette will change how many times the animation will loop; either a fixed number of times, or forever.
  9. Once the frame order and timing as been set up, it is time to save the image! Click File > Save for Web & Devices, make sure the file format is set to GIF, change any other options if needed, and save the image!

Reference: http://www.briandalessandro.com/blog/create-an-animated-gif-in-photoshop-cs5/

Thursday, September 03, 2009

Zigbee module configuration for multi-pole comm

By default, the Zigbee module from Maxstream can communicate with one another as serial comm port. However, in my project, I need one of the modules to talk to two different modules - a form of master/slave communication.

Without making things difficult, I resort to using the master in the broadcast mode while the rest remains in unicast mode. First I change the slaves source address to 0x0008 while leaving the destination address unchanged. Then I change the destination address of the master to 0xFFFF to enable broadcast mode. The source address of the master remains unchanged at 0x0000.

To configure the master module:
+++ // Enter into command mode
ATDLFFFF<CR> // Change Dest Addr Lo to 0xFFFF
ATWR<CR> // Write to non-volatile mem
ATCN<CR> // Exit command mode

To configure the slave module:
+++ // Enter into command mode
ATMY0008<CR> // Change Source Addr to 0x0008
ATWR<CR> // Write to non-volatile mem
ATCN<CR> // Exit command mode

HTML code for image

A simple html code to insert a picture in a blog:

<a href="http://www.blogger.com/..."><img align="left" hspace="30" src="...jpg" /></a>