DTR付のCP2102 をゲット

お買い物ついでに、忘れないようDTR付のUSBシリアル変換をゲットしました。

cp2102a

動作確認してみました。

cp2102b

いやぁ、便利ですね。

スクリーンショット_2015_05_17_0_58

前のCP2102 は ESP8266 用にしてこっちは、ProMini用にします。

cp2102

映像はこちら。

[youtube https://www.youtube.com/watch?v=xDVnZ8GZNqc]

5V 18650 リチウムバッテリー充電モジュール

今までで最速で届いた、パーツです。5/1 に発注して9日に到着。このストアはすごくいいですね。

10個で買ったので、1個あたり97円です。

32248603467

保護回路付で、よくできています。

メインのIDは、TP4056 でNanJing Top Power ASIC Corp製。保護回路に、DW01A と ML8205A が乗っています。

 

TP4056.pdf

http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Prototyping/TP4056.pdf

 

DW01x-DS-17_EN.pdf

http://www.ic-fortune.com/upload/Download/DW01x-DS-17_EN.pdf

 

ML8205A

http://www.datasheet4u.com/datasheet/M/L/8/ML8205A-MEILAI.pdf.html

 

2015_05_10_2_14

マイクロUSBから給電すると、ブルーLEDがつきます。電池がないと赤LEDは点滅する感じ。

IMG_0275

OUT側の内側は、バッテリーへ。OUT+- は出力へ。

IMG_0276 IMG_0277 

ジュリアンさんの解説映像がわかりやすいです。発音もいいですしね。

[youtube https://www.youtube.com/watch?v=Qw4psECqpwI]

IoTデバイス用にと思っていますが、まだ電池ボックスがないんですよね。あぁ、3Dプリンターがほしいぃ。

ESP12単体で光センサーアナログ読み

Aliexpress経由で購入した素材で遊びました。

20個で、98円のGL5528光センサーをつけてみました。

IMG_0269

20個で98円ということは、1個あたり約5円ですね。

esp12-cde_fzz_-_Fritzing_-__ブレッドボード_ビュー_

ADC にこんな感じでつけてみました。

当初ADC Pinにつけても値が拾えず、抵抗値を可変で調整したらうまく値が取れました。このADC-GND間の電圧は、強い光を当てた状態で約1.13Vくらいです。夜、電気をつけた状態で0.98Vくらい。手で覆うと0.6Vくらいになる感じです。

 

コードは以下のようです。エラー処理が抜けているのか、バグがあるのかわかりませんがちょっと不安定です。

/*
 ESP8266 HTTP get webclient.
 ADC Read test.
 https://thingspeak.com/channels/37124
 Arduino-compatible IDE with ESP8266
 arduino-1.6.1-macosx-java-latest-signed.zip
 https://github.com/esp8266/Arduino
 JunkHack 2015.05.09
 */
 
#include <ESP8266WiFi.h>
 
const char* ssid     = "JunkHack";
const char* password = "testtest";
 
const char* host = "184.106.153.149";

int WiFiConLed = 13;
int WEBconLed = 12;

void setup() {
  pinMode(WiFiConLed, OUTPUT);
  pinMode(WEBconLed, OUTPUT);
  Serial.begin(115200);
  delay(10);
 
  // We start by connecting to a WiFi network
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    digitalWrite(WiFiConLed, HIGH);
    delay(400);
    digitalWrite(WiFiConLed, LOW);
    delay(100);
  }
 
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
int value = 0;
int count = 0;
int adc = 0;

void loop() {
  delay(5000);
  ++value;
 
  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
  
  digitalWrite(WEBconLed, HIGH);
  delay(1000);
  count += 1;

  Serial.print("ADC: ");
  adc = analogRead(A0);
  Serial.println(adc);
 
  // We now create a URI for the request
  String url = "/update?key=5GPL7J7EVNB5R8GE&field1=";
  url += adc;
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(10);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  // Close connection
  Serial.println();
  Serial.println("closing connection");
  digitalWrite(WEBconLed, LOW);
}

 

とりあえず、こんな感じで、データが投げられています。

ESP12_-_ThingSpeak

ESP12単体でwifi connection

単体でWifi に接続して、データをThingSpeak に投げるテストをしてみました。

 

IMG_0269

配線はこんな感じで、GPIO12 と 13 にLEDをくっ付けてみました。アクセスポイントにコネクションしたときにダブルブリンク、WEBにコネクションしているときは、点灯する感じです。

スクリーンショット 2015-05-09 16.13.41

まだ、センサーとかはつけていないのでカウンター値を上げてみました。

imageほほー、簡単ですね。

 

コードはこんな感じです。

/*
 ESP8266 HTTP get webclient test.
 https://thingspeak.com/channels/37124
 Arduino-compatible IDE with ESP8266
 arduino-1.6.1-macosx-java-latest-signed.zip
 https://github.com/esp8266/Arduino
 JunkHack 2015.05.09
 */
 
#include <ESP8266WiFi.h>
 
const char* ssid     = "JunkHack";
const char* password = "testtest";
 
const char* host = "184.106.153.149";
 
void setup() {
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  Serial.begin(115200);
  delay(10);
 
  // We start by connecting to a WiFi network
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    digitalWrite(13, HIGH);
    delay(400);
    digitalWrite(13, LOW);
    delay(100);
  }
 
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
 
int value = 0;
int count = 0;
 
void loop() {
  delay(5000);
  ++value;
 
  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
  
  digitalWrite(12, HIGH);
  delay(1000);
  count += 1;

 
  // We now create a URI for the request
  String url = "/update?key=5GPL7J7EVNB5R8GE&field1=";
  url += count;
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(10);
 
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  // Close connection
  Serial.println();
  Serial.println("closing connection");
  digitalWrite(12, LOW);
}

ArduinoIDE のシリアルモニターでも見れますが、osx のCoolTermでは以下のように見れます。

Connection_Options__CoolTerm_0__と_CoolTerm_0

 

Menubar_と_Connection_Options__CoolTerm_0__と_CoolTerm_0

 

Connection_Options__CoolTerm_0__と_CoolTerm_0 2

 

Menubar_と_CoolTerm_0_と_Windows7__Running_

 

参考にさせて頂いたページ

ESP8266モジュールをArduinoとして使う

http://ehbtj.com/electronics/esp8266-as-arduino

 

ESP8266をUSB-TTLシリアル変換してWi-Fiの確認する

http://qiita.com/masato/items/a3b71f8a17b876be8f76

 

ESP8266 Wifi Temperature Logger

http://www.instructables.com/id/ESP8266-Wifi-Temperature-Logger/?lang=ja&ALLSTEPS

ESP8266 ESP-12 DoubleBlink

ESP8266 チップを使った WiFiモジュールの ESP-12 を触ってみました。

面白いことに、このモジュール単体でGPIOがあり、ArduinoIDEでプログラムを書き込みできてしまうという点です。

まずは、ハードウェアのHelloWorldであるLED点滅をやってみました。

ESP8266-DoubleBlink.mov 2015.05.08 08.45.29.660

モジュールはこんな感じでちっこいです。3.3Vで動作します。ブレッドボードに刺さらない2mmピッチなので下駄を履かせています。 基盤のしたにジャンパーを伸ばしてやらないと配線できませぬ。

ESP8266-DoubleBlink.mov 2015.05.08 08.46.59.348

そのうち、オフィシャルのArduinoIDE にも入るかと思いますが、以下からESP8266 をサポートしたIDEをゲットします。

 

esp8266/Arduino · GitHub

https://github.com/esp8266/Arduino

 

ESP8266-DoubleBlink.mov 2015.05.08 08.49.25.402

ボードにESP8266 が入っています。

ESP8266-DoubleBlink.mov 2015.05.08 08.49.36.091

書き込み装置には、esptool が入っています。

ESP8266-DoubleBlink.mov 2015.05.08 08.49.46.156

配線は以下のようにします。上にあるのは、5V to 3V のレギュレーターです。書き込みするときは、GPIO0 をGND に落としてやります。

aacf887cc59654663f08674be38c52c9

コードはダブルブリンクを以下のようにしてみました。

/*
 ESP8266 Double Blink Sample.
 Arduino-compatible IDE with ESP8266
 arduino-1.6.1-macosx-java-latest-signed.zip
 https://github.com/esp8266/Arduino
 JunkHack 2015.05.08
 */
 
void setup() {
  pinMode(0, OUTPUT);
}
 
void loop() {
  digitalWrite(0, HIGH);
  delay(400);
  digitalWrite(0, LOW);
  delay(100);
  digitalWrite(0, HIGH);
  delay(500);
  digitalWrite(0, LOW);
  delay(1000);
}

IDE から書き込みすると以下のようになります。

ESP8266-DoubleBlink.mov 2015.05.08 08.50.15.224

とりあえず、書き込み方法はわかりました。

映像は以下をどうぞ。

[youtube https://www.youtube.com/watch?v=9TUboOLnz6A]

次回は、WiFi でコネクションする何かをやりたいですね。

面白いことに、透過モードにするファームウェアもあるので試してみたいですね。

 

ESP8266-transparent-bridge

https://github.com/beckdac/ESP8266-transparent-bridge

nWorld ESP8266で透過モードを使ってみた。

http://firtel.blogspot.jp/2015/01/esp8266.html