18650 電壓範圍 3.6-4.2V
要產生3.3V, 只有找到 TPS63020, TPS63060, TPS63070
LM1117 要求 Vin - Vout = 1.2V
3.6V - 1.2V = 2.4V
使用 TL431
注意在 750 Ohm, 上有一個較高的電壓(12V)
這裡可不能接 18650
Vout = 2.5 * (1 + 4.7 / 22) = 3.0V
PN2222 的 Vb為 3.0V + 0.7V = 3.7V
Ib = (12 - 3.7) / 750 = 11mA (在TL431 的 Ika 1~100mA 範圍內)
PN2222 的最小 β 為 35
Iout(max) = 11 * 35 = 387mA
2018年1月4日 星期四
2017年12月18日 星期一
使用 Arduino Pro Micro 當成 Arduino ISP 燒錄程式到 Atmega328P-PU 之二
請參考 上一篇 和 From Arduino to a Microcontroller on a Breadboard
雖然他只有提供 breadboard-1-6-x.zip,並沒有 1.8.5 的版本,是可以用的
C:\Arduino\arduino-1.8.5-windows\arduino-1.8.5\hardware\arduino\avr\boards.txt
##############################################################
atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)
atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600
atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F
atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard
##############################################################
Tools/Programmer/Arduino as ISP(Pro Micro)
Tools/Burn Bootloader
秘訣是 Arduino IDE 不要使用安裝檔,使用 Windows zip file for non admin install
解開後取出 boards.txt 的內容加入 arduino-1.8.5 的 boards.txt
解開後取出 boards.txt 的內容加入 arduino-1.8.5 的 boards.txt
之前使用安裝檔,一直失敗
C:\Arduino\arduino-1.8.5-windows\arduino-1.8.5\hardware\arduino\avr\boards.txt
##############################################################
atmega328bb.name=ATmega328 on a breadboard (8 MHz internal clock)
atmega328bb.upload.protocol=arduino
atmega328bb.upload.maximum_size=30720
atmega328bb.upload.speed=57600
atmega328bb.bootloader.low_fuses=0xE2
atmega328bb.bootloader.high_fuses=0xDA
atmega328bb.bootloader.extended_fuses=0x05
atmega328bb.bootloader.file=atmega/ATmegaBOOT_168_atmega328_pro_8MHz.hex
atmega328bb.bootloader.unlock_bits=0x3F
atmega328bb.bootloader.lock_bits=0x0F
atmega328bb.build.mcu=atmega328p
atmega328bb.build.f_cpu=8000000L
atmega328bb.build.core=arduino:arduino
atmega328bb.build.variant=arduino:standard
參考 上一篇 ProMicro 到 Atmega328P 接線
先燒錄 Bootloader
Tools/Board:ATmega328 on a breadboard (8 MHz internal clock)
Tools/Port 選正確Tools/Programmer/Arduino as ISP(Pro Micro)
Tools/Burn Bootloader
Bootloader 燒錄完成後,即可透過 RS-232 燒錄程式
USB轉RS-232(如 FT232RL)
FTDI -> Atmega328P
GND -> GND
CTS -> GND
VCC -> VCC
TXO -> 2(RXD)
RXI -> 3(TXD)
DTL -> 1(RESET)
DTL 接 RESET 請參考 Arduino Pro Mini 電路
中間串接 0.1uF, Atmega328P 端的 Reset 要 Pull Up 10K
Tools/Board:ATmega328 on a breadboard (8 MHz internal clock)
Tools/Port 選RS-232 的 Port
Sketch/Upload (不要 Using Programmer)
2017年12月12日 星期二
使用 Arduino Pro Micro 當成 Arduino ISP 燒錄程式到 Atmega328P-PU
Arduino 1.8.5
File/Preferences/Additional Boards Manager URLs
https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json
Tools/Board/Boards Manager
安裝 SparkFun AVR Boards
修改 File/Examples/11.ArduinoISP/ArduinoISP
重新定義下列程式碼
#define RESET 10 // Use pin 10 to reset the target rather than SS
#define LED_HB 9
#define LED_ERR 8
#define LED_PMODE 7
#define PIN_SCK 15
#define PIN_MOSI 16
#define PIN_MISO 14
https://github.com/Optiboot/optiboot/releases/download/v6.2/package_optiboot_optiboot-additional_index.json
Tools/Board/Boards Manager
安裝 Optiboot 6.2
若找不到, 並且有錯誤訊息
Error downloading https://github.com/Optiboot/optiboot/releases/download/v6.2/package_optiboot_optiboot-additional_index.json
下載並置於
C:\Arduino\arduino-1.8.5-windows\arduino-1.8.5\hardware/package_optiboot_optiboot-additional_index.json
更改 File/Preferences/Additional Boards Manager URLs 為
File/Preferences/Additional Boards Manager URLs
https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json
Tools/Board/Boards Manager
安裝 SparkFun AVR Boards
修改 File/Examples/11.ArduinoISP/ArduinoISP
重新定義下列程式碼
#define RESET 10 // Use pin 10 to reset the target rather than SS
#define LED_HB 9
#define LED_ERR 8
#define LED_PMODE 7
#define PIN_SCK 15
#define PIN_MOSI 16
#define PIN_MISO 14
Tools/Board/SparkFun Pro Micro
Tools/Processor/Atmega32U4(5V,16MHz)
Tools/Port/(選正確 Com)
Sketch/Upload
主要接線
ProMicro -> Atmega328P-PU
VCC -> 7(VCC)
GND -> 8(GND)
VCC -> 20(AVCC)
15(SCK) -> 19(SCK)
14(MISO) -> 18(MISO)
16(MOSI) -> 17(MOSI)
10 -> 1(RESET)
File/Preferences/Additional Boards Manager URLshttps://github.com/Optiboot/optiboot/releases/download/v6.2/package_optiboot_optiboot-additional_index.json
Tools/Board/Boards Manager
安裝 Optiboot 6.2
若找不到, 並且有錯誤訊息
Error downloading https://github.com/Optiboot/optiboot/releases/download/v6.2/package_optiboot_optiboot-additional_index.json
下載並置於
C:\Arduino\arduino-1.8.5-windows\arduino-1.8.5\hardware/package_optiboot_optiboot-additional_index.json
更改 File/Preferences/Additional Boards Manager URLs 為
file://C:\Arduino\arduino-1.8.5-windows\arduino-1.8.5\hardware/package_optiboot_optiboot-additional_index.json
修改 C:\Arduino\arduino-1.8.5-windows\arduino-1.8.5\hardware\arduino\avr\programmers.txt
增加
arduinopromicro.name=Arduino as ISP(Pro Micro)
arduinopromicro.communication=serial
arduinopromicro.protocol=arduino
arduinopromicro.speed=19200
arduinopromicro.program.protocol=stk500v1
arduinopromicro.program.speed=19200
arduinopromicro.program.tool=avrdude
arduinopromicro.program.extra_params=-P{serial.port} -b{program.speed}
Tools/Programmer/Arduino as ISP(Pro Micro)
Tools/Processor/Atmega328p
Tools/Board/Optiboot on 28-pin cpus
Tools/CPU Speed/8MHz (int) (不使用外部震盪晶體)
Tools/Burn Bootloader (好像可以不用,但是時脈會錯誤)
燒錄程式需使用 Sketch/Upload Using Programmer, 不能使用 Upload
2017年11月24日 星期五
如何控制 DC-DC 輸出電壓
以下文章參考 Output voltage control of DC/DC converters
Vref 固定,且沒有電流
期望輸出電壓範圍 Vo1 ~ Vo2 (Vo1 < Vo2)
期望控制電壓範圍 Vc2 ~ Vc1(Vc1 < Vc2)
即是 Vc1 輸出 Vo1,Vc2 輸出 Vo2
以中間的節點來說 Ir1 + Ir2 + Ir3 = 0
Vref/R3 + (Vo1 - Vref)/R1 + (Vc1 - Vref)/R2 = 0
Vref/R3 + (Vo2 - Vref)/R1 + (Vc2 - Vref)/R2 = 0
Vref 固定,且沒有電流
期望輸出電壓範圍 Vo1 ~ Vo2 (Vo1 < Vo2)
期望控制電壓範圍 Vc2 ~ Vc1(Vc1 < Vc2)
即是 Vc1 輸出 Vo1,Vc2 輸出 Vo2
以中間的節點來說 Ir1 + Ir2 + Ir3 = 0
Vref/R3 + (Vo1 - Vref)/R1 + (Vc1 - Vref)/R2 = 0
Vref/R3 + (Vo2 - Vref)/R1 + (Vc2 - Vref)/R2 = 0
因為 R3 固定,所以可以由聯立方程式解出 R1, R2
在上述範例中使用 LM2596(降壓),我使用 TL431(升壓)
須注意上方的電阻值,至少要能提供 TL431 1mA,才能正常工作
原先是想用 LM317-ADJ(降壓)
Vout = 1.25(1 + R2/R1)
請注意此時的 Vref = Vout - Vadj = 1.25
Vref/R1 + [Vc1 - (Vo1 - Vref)]/R2 + (Vo1 - Vref)/R3 = 0
Vref/R1 + [Vc2 - (Vo2 - Vref)]/R2 + (Vo2 - Vref)/R3 = 0
以上沒有試過,請小心
沒猜錯 XL6003(升壓) 也可以
2017年9月15日 星期五
Arduino pro mini
1. 製造 Arduino 燒錄器
接腳 FT232RL -> Arduino Pro Mini
DTR->DTR
RX->TXO
TX->RXI
VCC->VCC
CTX->GND
GND->GNC
選擇要當燒錄器的 Boards(Arduino Pro or Pro Mini) 和 Port
File/Examples/11.ArduinoISP/ArduinoISP
Sketch/Upload
2. 燒錄 bootloader
接腳 Arduino Pro Mini(Arduino 燒錄器)->Arduino Pro Mini
VCC->VCC
GND->GND
10->RST
11(MOSI)->11(MOSI)
12(MISO)->12(MISO)
13(SCK)->13(SCK)
File/Examples/01.Basics/Blank
接腳 FT232RL -> Arduino Pro Mini
DTR->DTR
RX->TXO
TX->RXI
VCC->VCC
CTX->GND
GND->GNC
選擇要當燒錄器的 Boards(Arduino Pro or Pro Mini) 和 Port
File/Examples/11.ArduinoISP/ArduinoISP
Sketch/Upload
2. 燒錄 bootloader
接腳 Arduino Pro Mini(Arduino 燒錄器)->Arduino Pro Mini
VCC->VCC
GND->GND
10->RST
11(MOSI)->11(MOSI)
12(MISO)->12(MISO)
13(SCK)->13(SCK)
File/Examples/01.Basics/Blank
選擇目標 Boards(Arduino Pro or Pro Mini)
Tools/Programmer/Arduino as ISP
Tools/Brun Bootloader
Sketch/Upload Using Programmer
2017年9月5日 星期二
SSL, RaspberryPi Server, Android Client
請參考 Android 與 Raspberry 證書 和 SSL 網路程式設計 的 Server 端
在此提供 Android 的 Client
在此提供 Android 的 Client
package com.example.mark.sslclient; import android.content.Context; import android.content.res.AssetManager; import android.util.Log; import java.io.IOException; import java.io.InputStream; import java.security.KeyManagementException; import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.UnrecoverableKeyException; import java.security.cert.Certificate; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; /** * Created by mark on 2017/9/1. */ public class SSLClient { static SSLContext ssl_ctx; public SSLClient(Context context) { try { Log.d("SSLClient", "SSLClient"); // Setup truststore KeyStore trustStore = KeyStore.getInstance("BKS"); InputStream trustStoreStream = context.getResources().openRawResource(R.raw.android); trustStore.load(trustStoreStream, "store1234".toCharArray()); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(trustStore); Log.d("SSLClient", "Trust " + trustStore.size()); Log.d("SSLClient", "trustManagerFactory " + trustManagerFactory.getTrustManagers().length); // Setup keystore KeyStore keyStore = KeyStore.getInstance("BKS"); KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); InputStream keyStoreStream = context.getResources().openRawResource(R.raw.android); keyStore.load(keyStoreStream, "store1234".toCharArray()); keyManagerFactory.init(keyStore, "key1234".toCharArray()); Log.d("SSLClient", "Key " + keyStore.size()); Log.d("SSLClient", "keyManagerFactory " + keyManagerFactory.getKeyManagers().length); // Setup the SSL context to use the truststore and keystore ssl_ctx = SSLContext.getInstance("TLS"); if (true) { ssl_ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); } else { TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] chain, String authTyhpe) throws CertificateException { } public void checkServerTrusted(X509Certificate[] chain, String authTyhpe) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ssl_ctx.init(null, new TrustManager[] { tm }, null); } } catch (KeyStoreException e) { Log.d("SSLClient", e.getMessage()); } catch (NoSuchAlgorithmException e) { Log.d("SSLClient", e.getMessage()); } catch (CertificateException e) { Log.d("SSLClient", e.getMessage()); } catch (IOException e) { Log.d("SSLClient", e.getMessage()); } catch (KeyManagementException e) { Log.d("SSLClient", e.getMessage()); } catch (UnrecoverableKeyException e) { Log.d("SSLClient", e.getMessage()); } } }
package com.example.mark.sslclient; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private SSLClient sslClient; private Runnable threadMain = new Runnable() { @Override public void run() { SSLSocketFactory socketFactory = (SSLSocketFactory)sslClient.ssl_ctx.getSocketFactory(); try { Log.d(TAG, "threadMain createSocket a"); SSLSocket socket = (SSLSocket)socketFactory.createSocket("192.168.1.61", 8080); Log.d(TAG, "threadMain createSocket b"); PrintWriter output = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); BufferedReader input = new BufferedReader((new InputStreamReader(socket.getInputStream()))); output.println("\nthis is from client+++++++++++++++client send to server"); output.flush(); Log.d(TAG, "threadMain input.readLine() a"); String line = input.readLine(); while (line != null) { Log.d(TAG, line); line = input.readLine(); } Log.d(TAG, "threadMain input.readLine() b"); } catch (IOException e) { e.printStackTrace(); } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate a"); setContentView(R.layout.activity_main); sslClient = new SSLClient(this); Thread thread = new Thread(threadMain); thread.start(); Log.d(TAG, "onCreate b"); } }
2017年9月4日 星期一
Huawei 在 Android Studio 沒有 logcat
撥打 *#*#2846579#*#*
Project Menu > Background Setting > Log setting
選擇 AP Log
Project Menu > Background Setting > Log setting
選擇 AP Log
訂閱:
文章 (Atom)



