วันอังคารที่ 20 กุมภาพันธ์ พ.ศ. 2561

Raspberrypi: How to install OS-Image

Raspberrypi: How to install OS-Image

File OS raspbian
- 2017-xx-xx-raspbian-stretch.img




- ใช้โปรแกรม Etcher  ในการ Flash image

- เมื่อดำเนินการ Flash เรียบร้อยแล้ว ให้  Unmount  and  mount  SDcard กลับเข้าไปอีกครั้ง

- สร้างไฟล์เปล่าๆ  ssh   [ห้ามมี  .txt]  วางลงใน SDcard  path แรก  เพื่ออนุญาติให้ SSH


จากนั้นเข้าไปตั้งค่า Static IP
https://microstor.blogspot.com/2017/11/raspberrypi-how-to-connect-rpi-ethernet.html


วันเสาร์ที่ 11 พฤศจิกายน พ.ศ. 2560

Error: Your local changes to the following files [git pull ESP32-Arduino]

Git pull ในการอัพเดท Library Esp32




Error: Your local changes to the following files would be overwritten by merge:

Error ดังกล่าว หมายถึง ท่านได้เข้าไป Edit file ซึ่งทำให้ไม่ Git pull ให้อัพเดท Library ต่อ

*ก่อนหน้านี้ 11/2017 ผมเองก็ได้ Edit ไฟล์พวกนี้ไว้นานแล้ว แต่ไม่เคยเกิด Error สงสังว่า Github คงจะมีการตรวจสอบข้อมูล หากมีการ Edit file แตกต่างจากต้นฉบับจะไม่ดำเนินการต่อ

วิธีแก้ไข: กลับไปลบข้อมูลที่ทำการ Edit file กลับตามเดิมก่อน แล้วสั่ง git pull ใหม่อีกรอบ


อัพเดทได้เรียบร้อย




วันพุธที่ 8 พฤศจิกายน พ.ศ. 2560

Raspberrypi: How to setting static IP

การตั้งค่า IP [Ethernet and WiFi]

+----------------------------------------------------+
$ sudo nano /etc/network/interfaces                |
+----------------------------------------------------+
# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

#iface eth0 inet manual
auto eth0
iface eth0 inet static
    address 192.168.100.10
    #gateway 192.168.100.1
    netmask 255.255.255.0
    network 192.168.100.0
    broadcast 192.168.100.255

allow-hotplug wlan0
#iface wlan0 inet manual
iface wlan0 inet static
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
    address 192.168.1.160
    gateway 192.168.1.1
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    dns-nameservers 8.8.8.8 8.8.4.4


allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf




+----------------------------------------------------+
+----------------------------------------------------+
save and exit
Ctrl + X >> Y

+----------------------------------------------------+
Restart network or Reboot
# /etc/init.d/networking reload

# reboot

+----------------------------------------------------+
Show IP
# ifconfig


Raspberrypi: How to setting WiFi [SSID Password]

การเชื่อมต่อ WiFi

+--------------------------------------------------------------------------+
$ sudo nano /etc/wpa_supplicant/wpa_supplicant.conf               |
+--------------------------------------------------------------------------+

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=TH

network={
        ssid="SSID"
        psk="Your_Password"
        key_mgmt=WPA-PSK
}



+----------------------------------------------------+
+----------------------------------------------------+
save and exit
Ctrl + X >> Y

+----------------------------------------------------+
Restart network
# /etc/init.d/networking reload

+----------------------------------------------------+
Show IP
# ifconfig

Raspberrypi: How to connect Rpi Ethernet notebook [No Display]

วิธีการเชื่อมต่อ Raspberry PI กับ Notebook ผ่าน LAN 
*การตั้งค่าต่อไปนี้ไม่ได้เป็นการ Share internet แต่จะสามารถประยุกต์ได้ต่อไป


การใช้งาน raspberry pi สิ่งแรกที่ต้องการ คือ เราจะ connect ssh ไปยัง Command line [cmd] ได้อย่างไร กรณีที่ต่อจอ HDMI ได้ก็สามารถตั้งค่า IP ได้ผ่านหน้า Desktop ได้เลย แต่สำหรับผมแล้ว raspberry pi คือ Server ดีๆตัวนึง ซึ่งไม่จำเป็นจะต้องต่อจอเพื่อแสดงผล ดังนั้น การควบคุมทำงานของ raspberry pi จะต้องผ่านการ ssh ไปเท่านั้น จึงหาวิธีการและสรุปได้ ดังต่อไปนี้

- ทำการติดตั้ง OS ของ raspberry pi ใหม่
- เชื่อมต่อ raspberry pi กับคอมพิวเตอร์ด้วย port LAN
*ในตอนนี้เราจะไม่รู้ข้อมูล IP ของ raspberry pi

- Notebook ไปยังการตั้งค่า IP port LAN ตั้งค่าเป็น DHCP(Dynamic Host Configuration Protocol)

Control Panel >> Network and Sharing Center >> Click Local area network
*หากไม่ได้เชื่อต่อ raspberry pi ด้วย port LAN สถานะ Local area network จะไม่มีการแสดงผล


- ตรวจสอบ Network Detail จะไม่มีการแจก IP
>> Click Details.....



- ไปยังการตั้งค่า  WiFi เพื่อแชร์ Internet ให้กับ port LAN เพื่อต้องการแจก IP ให้กับ port LAN (ซึ่งจะได้ IP ชุด 192.168.137.xxx)

Control Panel >> Network and Sharing Center >> Click

- Interface card WiFi set sharing
  >Properties
  >Tab bar sharing
  >Select is 2 position [Allow other network]
  >Drop down Select [Local network]
  >OK



- จากนั้นกด setting เพื่ออนุญาติให้ใช้ Service  Remote desktop, Https, Http

select 1.Remote desktop 2.Https 3.Http  OK.



- ไปยัง port LAN เพื่อตรวจสอบการ share internet จาก WiFi ซึ่งจะได้ IP 192.168.137.xx

- Interface card lan will has ip 192.168.137.xx


- เปิดโปรแกรม Advanced IP Scanner
กำหนดให้แสกน IP 192.168.137.1 - 192.168.137.254   
จากตั้วอย่าง raspberry pi IP 192.168.137.24
*กรณีไม่เจอ IP ของ raspberry pi จะต้องตรวจสอบการตั้งค่าตามขั้นต้นอีกครั้ง




- ทดสอบด้วยการ ping ip 192.168.137.24


- ssh IP 192.168.137.24 เพื่อไปตั้งค่า IP

รหัสผ่าน
user    pi
pass    raspberry

- เข้าไปแก้ไขข้อมูลในไฟล์
# nano /etc/network/interfaces

ตั้งค่า Static IP ดังนี้
*ตัวอย่าง จะใช้ IP 192.168.100.xxx ในการติดต่อกับ raspberry pi

#iface eth0 inet manual
auto eth0
iface eth0 inet static
    address 192.168.100.10
    #gateway 192.168.100.1
    netmask 255.255.255.0
    network 192.168.100.0
    broadcast 192.168.100.255


*ค้นหาเพิ่มเติม Static กับ DHCP ต่างกันอย่างไร?


- เมื่อตั้งค่าเรียบร้อยแล้ว บันทึกและออก
Ctrl + X  >>  Y

- restart service
# /etc/init.d/networking reload

หรือรีสตาร์ท
# reboot

*เมื่อสั่ง restart service การ ssh ก็จะหลุดไปเพราะ IP raspberry pi กับ computer คนละชุดกัน
ดังนั้นจะต้องกลับไปตั้ง IP port LAN ที่คอมพิวเตอร์ให้เป็นวงเดียว 192.168.100.xx
แต่จะต้องกลับไปปิดการ Share WiFi จากตอนต้น

Interface card WiFi set sharing
  > Unselect [Allow other network]


- ถึงขั้นตอนนี้ Computer ไม่สามารถติดต่อกับ raspberry pi ได้ด้วย IP 192.168.100.xx ดังนั้นต้องกลับไม่ตั้งค่า IP ที่ port LAN ให้เป็นแบบ Static ด้วยเช่นกัน

*ทำไมต้องตั้งค่า Static IP เพราะหากเลือกใช้ DHCP จาก WiFi Sharing ก็สามารถใช้ได้ แต่จะต้องมา Scan IP ทุกครั้ง เพราะเมื่อไหร่ที่สั่ง Reboot หรือ Restart network ก็จะได้ IP ใหม่ 192.168.137.xx 

- port LAN ตั้งค่า IP  192.168.100.5 สำคัญที่ Subnet Mask จะต้องเป็น 255.255.255.0 เมื่อตั้งค่า IP Address เรียบร้อยแล้ว กด Tab ระบบจะใส่ให้อัตโนมัติ


- ทดสอบโดยการ Ping IP raspberry pi

ping 192.168.100.10


- ssh ไปยัง IP 192.168.100.10



- สามารถ Connect raspberry pi ด้วย port LAN ได้ตลอดและ IP ก็จะไม่เปลี่ยน


เสร็จเรียบร้อย

เพิ่มเติม: การตั้งค่า Static IP และการเข้าไป Setting WiFi SSID
Raspberrypi: How to setting WiFi [SSID Password]

Raspberrypi: How to setting static IP


Blog เรื่องนี้ที่เขียนเนื้อหาอาจจะไม่ได้ลงรายละเอียด 100% มีบางขั้นตอนอาจจะมีข้ามไปบ้าง หากท่านติดปัญหาในส่วนใด สามารถสอบถามได้ทาง Inbox facebook

Contacht: https://www.facebook.com/dan.thummaratkmitl

วันศุกร์ที่ 3 มีนาคม พ.ศ. 2560

Software serial arduino vs NodeMCU

Software serial Arduino vs NodeMCU




Hardware Connection

// Arduino UNO          9               8
//                                  |                 |
//                                  |                 |
// NodeMCU            14(D6)       12(D5)


Software serial  เป็นไลบลารีตัวนึงที่มีประโยชน์ และนำไปใช้บ่อยมาก เกี่ยวกับงานที่ต้องใช้ Uart TTL มากกว่า 1 ช่อง

โดยทั่วหากนำไลบลารี SoftwareSerial.h มาใช้เลยมันก็ง่าย แต่มันจะมีปัญหาในส่วนที่ ใช้กับ MCU คนละตัวกัน และ NodeMCU ไม่สามารถใช้ไลบลารีร่วมกับ UNO ได้นั้นเอง

แก้ปัญหา ดังนี้
//   MCU                     Library                        inculed
// Arduino UNO       AltSoftSerial                   AltSoftSerial.h
// NodeMCU            espsoftwareserial            SoftwareSerial.h

สาเหตุที่ Arduino UNO ต้องใช้ไลบลารี AltSoftSerial  เนื่องด้วยหากติดตั้งไบลารี SoftwareSerial.h ของ UNO จะชนกับไลบลารีของ NodeMCU นั้นเอง


จากการทดสอบ board rate NodeMCU รับได้เพียงแค่ 9600 เท่านั้น



<<===Arduino UNO========================>>
#include <AltSoftSerial.h>

AltSoftSerial altSerial;
// Board            Serial1 TX   AltSoftSerial RX
// -----            ----------   ----------------
// Arduino UNO          9               8

void setup() {
  Serial.begin(9600);
  Serial.println("AltSoftSerial Test Begin");
  altSerial.begin(9600);
  altSerial.println("Hello World");
}

void loop() {
  String content;

  if (altSerial.available()) {
    content = altSerial.readStringUntil('\r');
    Serial.print(content);
  }

  altSerial.println("Hello World");
  delay(500);
}
<<======================================>>


<<===NodeMCU ===========================>>
#include <SoftwareSerial.h>

//SoftwareSerial swSer(14, 12, false, 256);   //Rx  Tx
SoftwareSerial swSer(D5, D6, false, 256);   //Rx  Tx
// Board            Serial TX       Serial RX
// -----            ----------      -----------
// NodeMCU            14(D6)          12(D5)

void setup() {
  Serial.begin(9600);
  swSer.begin(9600);

  Serial.println("\nSoftware serial test started");
  for (char ch = ' '; ch <= 'z'; ch++) {
    swSer.write(ch);
  }
  swSer.println("");
}
void loop() {
  String content;
  while (swSer.available() > 0) {
    content = swSer.readStringUntil('\r');
    Serial.print(content);
  }
//  swSer.println("Hello World");
//  delay(1000);
}
<<======================================>>

วันเสาร์ที่ 25 กุมภาพันธ์ พ.ศ. 2560

Esp32 arduino error [File "get.py", line 25]


เมื่อติดตั้ง Esp32 ใหม่ เกิด Error หรือไม่สามารถรันคำสั่ง python get.py เพื่อติดตั้ง toolchain  [xtensa-esp32-elf-win32]

$ python get.py
Traceback (most recent call last):
  File "get.py", line 25, in <module>
    import requests
ImportError: No module named requests



จากการใช้โปรแกรม MSYS2  ในการติดตั้งหรือรัน Command พบว่าครั้งนี้เจอปัญหาไม่สามารถรันคำสั่ง python get.py ได้

แก้ไขโดยการใช้ Command line on windows สามารถรันคำสั่ง python get.py ได้ปกติ