SyntaxHigh

Wednesday, April 23, 2014

Programming Arduino Pro Mini and CP2102

Summary


  • There are small differences, not essential, between different USB-serial controllers: The USB-serial converter of Arduino Uno and CP2102 that I am using now.
  • Being cautious on sending and receiving all serial messages is important for making the program work in both platforms. 
  • Testing in different platforms in earlier stages is important.
  • PyQt is good for developing testing GUI.
Arduino Uno で使っていたプログラムのセット(ino と .py) をそのまま使うとうまくいかない。

The program (ino and py) that worked for Arduino Uno did not work for Uno and CP2102 as it is. This is probably because timeout policies of two USB-serial converter chips are different. I deleted the lines that wrote unnecessary serial lines sent from micro-controller to PC. Now it's working fine on both platforms.

CP2102 is slower than ATMega8u2. The round-trip time of PC-Arduino-PC is a bit longer. I don't know why, but it does not matter in my application.

I am using Arduino pro mini because I broke a lot of Uno's and lost some of my little money. But since getting cautious in avoiding short circuit (mainly by making custom shields), less boards have broken.

In my project, three microcontrollers are needed for the device and another one is for testing single modules. I have 15 more Arduino pro mini and 10 CP2102 modules. Hope those are not run out.

By the way, PyQt is a very nice platform for developing simple GUI such for test purpose. I am using python add-in for Visual Studio in programming python and Qt designer in designing UI.


Left: Arduino Pro Mini and CP2102. Right: Arduino Uno
Circuit topology is basically identical except for USB-serial module and trivial differences between Uno and pro mini.

特に、arduino から println しているものを PC 側で処理しないと、arduino からの送信が詰まってしまって(多分)通信がうまく行かなくなる。

これはおそらく CP2102 と Arduino Uno の USB-Serial(8U2だったかな) チップの処理の違いで、タイムアウトのポリシーが違うからだろう。

無駄な Serial.println を削ってやるとどちらでも動くようになった。

また、CP2102 を使ってるモジュールのほうが Arduino Uno よりもシリアルのレスポンスが若干遅い。同じボーレートを使っても、少しずつ遅れる。多分 Serial.write を始めるまでに時間がかかるからだろう(数百マイクロセカンド程度)これが原因かわからないが、シリアルポートを閉じてから再度開くまでに少し時間を開けないと正しくリセットされなかった。

USB-Serial のモジュールで安価に売っているものは、CP2102 の他に PL2303, CH340, FT2303 等があり、FT2303 が一番高い。一つ$4 程度なのでこちらを買っておいてもよかったかもしれない。ATMega8U2 が採用されるまでは Uno はこれを使っていたわけだし。

以前は不注意でUnoを壊しまくっていたので(5,6個は壊した)、安価なpromini にしたのだけど、ある程度注意できるようになってくると Uno でもいいのかもしれない。でもやっぱり一つ壊して$10と、$3 程度では心理的負担が異なる。Unoでも、328p のチップだけなら 3$ ぐらいで交換できるんだけれども。

Promini はコンパクトなままシリアル通信のデバイスを替えられる(bluetooth-serialとか)ので、きっと色々役に立つだろう。

No comments:

Post a Comment