Tuesday, June 30, 2015

Making Yun WiFi connection stable

I trying the following scheme to ensure the stable WiFi connection with Yun device.

1. on connection failure : reboot Yun (WiFi core)
2. set the bridge started variable to 0
3. begin the bridge again

bridge lib change :

extern Serial_ Serial;

void BridgeClass::begin() {
  char c;
 
  if (started) {
    uint8_t quit_cmd[] = {'X', 'X', 'X', 'X', 'X'};
    max_retries = 1;
    transfer(quit_cmd, 5);
   
    stream.print(CTRL_C);
    delay(250);
   
    stream.println("boot");        //in case we are in the bootloader
    stream.println("reboot");    //in case we are in the shell
  }
   
  started = true;

  stream.setTimeout(5000);
 
  // Wait for U-boot to finish startup
  while(stream.readBytes(&c, 1)) Serial.print(c);
 
  stream.setTimeout(1000);

Sunday, March 8, 2015

How to configure ESP8266 to the newest firmware

I got quite trouble for setting up ESP8266, so I'd like to share the way to configure it here (or memo it -_-)


HW configuration

ESP8266 uses all 3.3v for VCC, input, output. So I used 3.3v Adapter to power-up ESP8266, and FTDI USB-to-Serial with 3.3v. The basic PIN connection is as the following.
http://forum.hobbycomponents.com/viewtopic.php?f=74&t=1777
My module is ESP-07 which is different from the article, but the pin out is the same.

Pin configuration :
ESP8266 GPIO0 -> HIGH
ESP8266 GPIO2 -> HIGH
ESP8266 GPIO15 -> GND
ESP8266 CH_PD -> HIGH
ESP8266 TXD -> FTDI RXI
ESP8266 RXD -> FTDI TXO


How to update FW :
  1. GPIO0 to GND
  2. connect ESP8266 to TX/RX/GND of FTDI
  3. Download the following ESP8266 SDK and downloader
    SDK : http://bbs.espressif.com/viewtopic.php?f=5&t=154
    Flash Downloader : http://bbs.espressif.com/viewtopic.php?f=7&t=25&p=70&hilit=FLASH_DOWNLOAD_TOOLS_v0.9.3.1_141118#p70 
  4. There is a README file. :  esp_iot_sdk_v0.9.5_15_01_23\esp_iot_sdk_v0.9.5\bin\at. I used "new" way, and the following is the address for each images.
    boot_v1.2.bin      0x00000
    user1.512.new.bin  0x01000
    blank.bin          0x3e000
    balnk.bin          0x7e000
  5. GPIO0 to HIGH
  6. Set the default configuration and update FW through OTA. The settings are stored in the flash, so this is just a one time thing.
    AT+CWMODE=1 -> Station mode

    AT+CWAUTOCONN=0 -> auto AP connection disable
    AT+RSTAT+CWJAP="leekwon2G","x" -> AP connection
    AT+CIUPDATE -> OTA update
    AT+UART=9600,8,1,0,0 -> UART setting
  7. The final version after the procedure. :
    AT version:0.21.0.0
    SDK version:0.9.5
      

Tuesday, March 3, 2015

Using optiboot for Arduino pro mini 3.3v to enable watchdog with Arduino IDE 1.6

My Arduino Mega and Arduino Pro Mini does not reset properly after watchdog. In case of Arduino Mega, the watchdog works properly after writing down bootloader using another Arduino, but Pro Mini does not reset properly even after writing bootloaer. After some Googling I found that optiboot is a default for Arduino IDE 1.6.0 for Mega, and Pro Mini has traditional bootloader image. In short, watchdog reset works fine with optiboot image. The following is a stitch of various material that I googled to burn the optiboot to Pro Mini 3.3v 8MHz.

1. building optiboot contained in Arduino IDE 1.6
Arduino IDE 1.6 does not have make utility. So I had to use external make utility from cygwin.

2. Modifying the Makefile
Open C:\Program Files (x86)\Arduino\hardware\arduino\avr\bootloaders\optiboot\Makefile and modify the following line. I got the information that FTDI USB serial chipset cannot handle 115200bps download and reset speed properly.

atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=57600'

3. Build the bootloader for Pro Mini 3.3v
In the cygwin, run the following command

$ make atmega328_pro8

4. Adding entry to boards list.

Edit the following file to look like this. :
C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt

## Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328 - Optiboot 57.6k
## --------------------------------------------------
pro.menu.cpu.8MHzatmega328ob=ATmega328 (3.3V, 8 MHz, Optiboot 57.6k)
pro.menu.cpu.8MHzatmega328ob.upload.maximum_size=32256
pro.menu.cpu.8MHzatmega328ob.upload.maximum_data_size=2048
pro.menu.cpu.8MHzatmega328ob.upload.speed=57600
pro.menu.cpu.8MHzatmega328ob.bootloader.low_fuses=0xFF
pro.menu.cpu.8MHzatmega328ob.bootloader.high_fuses=0xDE
pro.menu.cpu.8MHzatmega328ob.bootloader.extended_fuses=0x05
pro.menu.cpu.8MHzatmega328ob.bootloader.file=optiboot/optiboot_atmega328_pro_8MHz.hex
pro.menu.cpu.8MHzatmega328ob.build.mcu=atmega328p
pro.menu.cpu.8MHzatmega328ob.build.f_cpu=8000000L

## Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
## -------------------------------------------------

5. Restart Arduino IDE


References :
http://yveaux.blogspot.tw/2014/07/changing-arduino-bootloader-to-optiboot.html
https://code.google.com/p/optiboot/issues/detail?id=28

Sunday, March 1, 2015

It looks like peek() of AltSoftSerial is not working

It looks like peek() function of AltSoftSerial is not working. I think the following is the right code fragment. (Working for me anyways).

int AltSoftSerial::peek(void)
{
    uint8_t head, tail;

    head = rx_buffer_head;
    tail = rx_buffer_tail;
    if (head == tail) return -1;
    if (tail + 1 < RX_BUFFER_SIZE)
        return rx_buffer[tail+1];
    else
        return rx_buffer[0];
}

Saturday, February 28, 2015

Arduino Library for ESP8266

There are many ESP8266 libraries, but I cannot find the one that for me, so I made it from scratch. It is simple library that the object is small sensor client, so many function is omitting. The following is the function list.

  • Scan
  • MAC address API
  • AP connection (of course)
  • only TCP client socket read / write

The memory footprint is a pro of this library. My sensor node with this library has the following memory foot print.


Sketch uses 19,934 bytes (64%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,030 bytes (50%) of dynamic memory, leaving 1,018 bytes for local variables. Maximum is 2,048 bytes.


Adafruit CC3000 version of the sensor node has the following foot print. :

Sketch uses 29,406 bytes (95%) of program storage space. Maximum is 30,720 bytes.
Global variables use 1,311 bytes (64%) of dynamic memory, leaving 737 bytes for local variables. Maximum is 2,048 bytes.

Still there are many problems due to firmware version and timing issue of the response. However, I hope this may be used.

The firmware version and HW that I used is :
Firmware version : AT version:0.21.0.0 SDK version:0.9.5
Aduino pro mini
ESP8266MOD from Ai-thinker

This library is designed to used with AltSoftSerial with some patch included.

The source code : https://github.com/chiknhed/esp8266_client

Happy Arduino Life ~

The following is public member function list. :
ESP8266ClientClass();
wl_status_t begin(char * ssid = NULL, char * password = NULL, byte * mac = NULL);
wl_status_t status(void);
bool connect(char * host, unsigned int port);
bool isConnected(void);
void disconnect(void);
void print(char * buffer);
void print(const __FlashStringHelper *ifsh);
void readLoop(void);
void setTimeout(long timeout);
byte readBytes(char* buffer, byte buffer_size);
bool startScan(void);
bool scanEntry(char * ssid, char * rssi, byte *security);
void getMac(byte mac[6]);

Wednesday, February 25, 2015

A GUI for MS Windows to setup Arduino Board

I openned the source code in Github. You may build the application using Visual Studio 2013 Community edition. (Visual C++ MFC Dialog based)

https://github.com/chiknhed/arduino_setting_from_pc

Funtionality :
  • Communication with server to create an account
  • Find UART port for Arduino
  • Communicate with Arduino through UART for setup
  • Specify SSID and password
  • Scan through Arduino device if the functionality is supported
 ToDo :
  • More general application framework (?)
  • Add sample UART output of my sensor node Arduino board

Sunday, February 22, 2015

RSSI value of Adafruit CC3000

I don't know if I made a mistake, but CC3000 library returns RSSI value as positive value in scanning. It looks like the correct dBm value is -128 + returned_value.

I posted a question to Adafruit forum as the following. : https://forums.adafruit.com/viewtopic.php?f=22&t=68901

Saturday, February 21, 2015

Test Acccount for sensor output

The test account is running for sensor output processing. (The sensor is at my home.. -_-;)

http://galvanic-cirrus-841.appspot.com  pinebud /22222222

MS Windows GUI utility to setup the sensor node

We made a Windows application to setup the sensor node.

HI-LINK RM04 WiFi module driver for Arduino Uno

We published Arduino library for HI-LINK RM04 WiFi module with Aruino Uno board. Uno board provides just one UART for PC communication, so we used AltSoftSerial library to use software serial port to communicate with RM04 module. Because of the limited memory of Uno, the library only provides web client functionality. Even scan function was removed from the original driver.

Original driver from Chunlinhan : https://github.com/chunlinhan/WiFiRM04
Modified smaller driver : https://github.com/chiknhed/small_wifi_rm04

Adafruit CC3000 has a bug getting DNS server

We identified a bug with Adafruit CC3000 WiFi module. The module does not update DNS server entry from DHCP server properly.

Following is the result with my home WiFi AP.
IP Addr: 192.168.25.23
Netmask: 255.255.255.0
Gateway: 192.168.25.1
DHCPsrv: 192.168.25.1
DNSserv: 192.168.1.1

Following is the result with my iPhone WiFi tethering
IP Addr: 172.20.10.11
Netmask: 255.255.255.240
Gateway: 172.20.10.1
DHCPsrv: 172.20.10.1
DNSserv: 192.168.1.1

Adafruit support team said there seems to be a glitch in the firmware to save DNS server entry for some time.

The following seems to be the workaround.

cc3000.setDHCP();
while (!cc3000.connectToAP(ssid, passwd, WLAN_SECURITY)) {
Serial.println(F("Connection Failed!"));
}

Link to the bug reporting post : https://forums.adafruit.com/viewtopic.php?f=22&t=52616