2018年3月11日 星期日

How to fix Aruduino ESP32 flashing issues (A fatal error: Time out waiting for packet header)


I have successfully installed Arduino core for ESP32 Dev Module in my NB and iMac, and try to upload example program  of WiFiScan from Arduino IDE to ESP32 Dev Module. No matter what I did, I keep receiving "A fatal error occurred:  Time out waiting for packet header"


After a series of test, I found that the USB cable could be the key to fix the issue. So I tested 7 USB cables from different sources



and below are tested result

















Cable #
1
2
3
4
5
6
7
USB Cable from PQI Power Bank Charger Asus Mobile Phone Samsung Mobile Phone Sony Mobile Phone  Unknown Blue HTC Mobile Phone Unknown White
Cable Length (CM)
25
94
120
81
52
100
50








Test Result - Windows NB ESP32 dev. Module can’t be recognized Flash Error OK OK OK OK OK
Test Result - iMAC ESP32 dev. Module can’t be recognized ESP32 dev. Module can’t be recognized OK OK OK OK OK


In the beginning, I think it's because of long cable length but based on the test result above, it's not. It could be the quality of the cable.

So if you see "A fatal error occurred:  Time out waiting for Header packet .." on the Arduino IDE, the best way to fix the issue is to try another USB cable.

Successfully upload example file of WiFiScan from Arduino IDE to my NodeMCU-32S Lua ESP32S development module shown as below


2018年3月10日 星期六

如何解決安裝 Arduino ESP32 開發版程式的問題



我剛完成安裝 Arduino ESP32 Wifi BT開發版的程式 (https://github.com/espressif/arduino-esp32). 安裝成功,可是我找不到應該要顯示 "ESP32 dev module" ,即使我離開Arduino程式在重新進入程式裡面.

經過一連串的測試, 我發現是因為草稿簿路徑的問題,因為我不是用內定的路徑. 在我改成用內定的路徑(如下),


就可正常工作。



next => The first Arduino ESP32 Test program (to be continued)

How to fix installation issue of Arduino core for ESP32 Wifi chip in Mac



I just installed Arduino core (https://github.com/espressif/arduino-esp32) on NodeMCU-32S Lua ESP32 dev-kit . Installation is successful but I just can't find the "ESP32 dev module" which should be shown on the Arduino's submenu of development board even if I exit Arduino software and then re-open Arduino software.

After a series of test, I found that the issue is because of the location of the sketch books setting in the preference menu. After I change it to default settings as below,


It works now.



next => The first Arduino ESP32 Test program (to be continued)

如何將 NodeMCU-32S Lua ESP32 開發板改成 Arduino ESP32 Wifi+Bluetooth 開發板


之前都用 Arduino MEGA 2560 / UNO 在寫各種控制程式, 但是 MEGA 2560 和 UNO 用的是低階的 CPU,速度慢,記憶體小且開發板又貴。因為要做一些 IOT 的應用,因此需要 Wifi 的模組。之前的做法都是用 MEGA 2560 或 UNO 加 ESP8266 模組或 ESP32 模組,此做法不只價錢貴,模組多,體積大又耗電。在 espressif (ESP8266 Wifi & ESP32 Wifi/BT IC 的製造商) 還沒有提供 Arduino 的核心程式時, 我就只能使用很複雜的 Free RTOS 來開發單晶片 Wifi IOT的方案。既然 espressif 已提供Arduino 的核心程式,因此現在可以很簡單的利用 ESP8266或ESP32的模組來實現單晶片 Wifi IOT 的方案。

首先,要安裝 Arduino 的核心程式 (https://github.com/espressif/arduino-esp32) 在 NodeMCU-32S Lua ESP32 開發板上, 本機的 ESP32 開發板為安信可原廠 NodeMCU-32S Lua ESP32S
https://seller.shopee.tw/portal/product/928485364
http://goods.ruten.com.tw/item/show?21808691311673
在使用 Arduino IDE 時最大的好處就是在每一次上傳草稿(程式)到 ESP32 模組時不用在按 BOOT 和 RESET 鍵.


Mac 的安裝方式如下:

1. 打開 Terminal 程式
2. 然後在命令列下,輸入以下命令,每次只輸入一行的命令(不要全部拷貝和貼上)
  mkdir -p ~/Documents/Arduino/hardware/espressif && \
cd ~/Documents/Arduino/hardware/espressif && \
git clone https://github.com/espressif/arduino-esp32.git esp32 && \
cd esp32 && \
git submodule update --init --recursive && \
cd tools && \
python get.py

4. 完成後重新打開 Arduino 就可看到如下的 "ESP32 dev module"


如果沒有看到這個 "ESP32 dev Module"

請看這篇 ==> 如何解決安裝 Arduino ESP32 開發版程式的問題
https://www.blogger.com/blogger.g?blogID=7530656930048997875#editor/target=post;postID=9018136909947391513;onPublishedMenu=allposts;onClosedMenu=allposts;postNum=1;src=postname

下圖是安裝 ESP32核心程式前內建開發板的列表





在Windows底下的安裝方式可參考:
https://github.com/espressif/arduino-esp32/blob/master/docs/arduino-ide/windows.md

步驟如下:
- 到 git-scm.com 下載 git 程式並執行
- 執行後,選擇 Clone Existing Repository 
- 然後複製 https://github.com/espressif/arduino-esp32.git 到 Arduino 草稿簿目錄 (不可在別的目錄)
- 再來開啟 Windows 的命令列,並在 Arduino 草稿簿目錄下輸入 
    git submodule  --init  --recursive 
- 改變目錄到 hardware\expressif\esp32\tools
- 執行 get 執行檔,完成後,軟體安裝就完成了。然後把 USB 線插到 ESP32 開發板,此時電腦會自動下載驅動程式。
- 重新啟動 Arduino 主程式,到 Tools -> Board 下,就可以看到 "ESP32 Dev Module"
- 把開發板改成 "ESP32 Dev Module" 並選擇正確的 COM Port
- 按一下開發板上的 RESET 鍵,此時可看到如下圖右邊的資訊了並開始寫程式了。




先用 ESP32 的範例程式 (在 File -> Examples -> WiFi -> WiFiScan) 上傳到 ESP32 開發板, 成功後, 就可以看到附近所有的 WIFI AP 的名字和訊號強度 如下圖.




下一篇: Arduino ESP32 和 1.3" 12864 點陣 OLED 模組應用

2018年3月6日 星期二

How to use Arduino MEGA 2560 SPI interface and 1.3 inch dot-matrix OLED display module with built-in English&Chinese Font IC


u8g2 is a very good and powerful library for dot-matrix display panels. Due to short program flash memory of Arduino UNO/MEAG 2560, it can not dislpay Chinese font, either BIG5 code (Traditional Chinese character) or GB2312 code (Simplified Chinese character). Hence I adopt 1.3 inch OLED module with built-in Chinese/English font, and use u8g2 drawXBM function to display Chinese(16x16)/English (8x16) character.

There are some interfaces (8bit parallel/I2C/SPI) used in OLED display panels  in the market, the reason I chose SPI is because less pins than 8bit parallel bus and much higher speed than I2C. Access speed between CPU and OLED driver such as SSH1106 (the one I used) and CPU to Chinese/English   Font IC is very important due to there are many data to send and to receive between them and I don't want to see display lag issue in my design.

I use the panel below
https://seller.shopee.tw/portal/product/928548884
http://goods.ruten.com.tw/item/show?21808691338964.

Wire connections as below

Arduino MEGA 2560   1.3" OLED module
46                                  CS2 (chip select for font IC)              
47                                
48                                  CS1    (chip select for SH1106)              
49                                  DC     (Data/Command pin)                    
50 MISO                       FSO    (font IC bitmap data output)                  
51 MOSI                       MOSI (CPU data to font IC or SH1106)    
52 SCK                          CLK                                                
53 SS                              ------                                                
3.3V                               3.3V                                                   
GND                              GND                                                

Demo program show a test string with both Chinese&English characters on the OLED display module below.

uint8_t   TeststringGB231216by16[] = {'H','i','!',0xDC,0xBF,0xCD,0xA5,0xCA,0xF7,0xB9,0xA4,0xD7,0xF7,0xCA,0xD2,0};  // 芸(DCBF),"Hi!芸庭樹工作室"



part number for the font IC is GT20L16S1Y and data sheet below  (http://www.genitop.com/admin/upload/20150511105751675.pdf)

after received Chinese/English font data from font IC, bit map data conversions (subroutine convert8by16FontBitMapforU8G2XBM and convert16by16FontBitMapforU8G2XBM) are  required due to different bit map structure between u8g2.drawXBM and the font IC.

demo program as below

void convert8by16FontBitMapforU8G2XBM(uint8_t *pfont)
{
  uint8_t i,j,k,*pfont1,tempbuffer[16], *pfont2, *pfontbase;
  uint8_t data,mask;

  pfont1 = pfont;     // the last byte for Chinese font bitmap
  pfont2 = &tempbuffer[0];
  for(i=0;i<16;i++)
  {
    *pfont2++ = *pfont1++;
    //pfont2++; pfont1++;
  }
  //printFontToSerial(16);

  pfont2 = pfont;
  pfontbase = &tempbuffer[0];
  for(k=0;k<2;k++,pfontbase+=8) {
    //Serial.print("k="); Serial.print(k,HEX); Serial.println(' ');
    mask=0x01;
    for(i=0; i<8; i++,mask<<=1) {
      //Serial.print("M"); Serial.print(mask,HEX); Serial.print(',');
      for(j=0,data=0,pfont1=pfontbase; j<8; j++) {
        data >>= 1;
        if (*pfont1++ & mask)
          data |= 0x80; //0x8000;  
        //Serial.print(data,HEX); Serial.print(' ');
      }
      *pfont2++ = data;
      //Serial.print(",data="); Serial.print(data,HEX); Serial.println(' ');
    }
  }
  //printFontToSerial(16);
}

void convert16by16FontBitMapforU8G2XBM(uint8_t *pfont)
{
  uint8_t i,j,k,*pfont1,tempbuffer[32], *pfont2, *pfontbase, mask;
  uint16_t data;

  pfont1 = pfont;     // the last byte for Chinese font bitmap
  pfont2 = &tempbuffer[0];
  for(i=0;i<32;i++) {
    *pfont2++ = *pfont1++;
  }

  pfont2 = pfont;
  pfontbase = &tempbuffer[0];
  for(k=0; k<2; k++,pfontbase+=16) {
    for(i=0,mask=0x1,pfont1=pfontbase; i<8; i++,mask<<=1) {
      for(j=0,data=0,pfont1=pfontbase; j<16; j++) {    
          data >>= 1;
          if (*pfont1++ & mask)
            data |= 0x8000;  
          //Serial.print(data,HEX); Serial.print(' ');      
      }
      *pfont2 = data & 0xff;
      *(pfont2+1) = ((data & 0xff00)>>8);
      pfont2 += 2;
      //Serial.print(",data="); Serial.print(data,HEX); Serial.println(' ');
    }
  }
}

void drawFontIC(uint8_t x, uint8_t y, uint8_t *pCodeString)
{
  //uint8_t *ptr;
  //ptr = pCodeString;
  //while(*ptr) {
  //  Serial.print(*ptr++,HEX); Serial.print(' ');
  //while(1);
  //}

  while(*pCodeString) {
      fontIC.getFontBitMap(pCodeString,&FontBuffer[0]);
      //printFontToSerial(32);
      if (*pCodeString > 127) {
        convert16by16FontBitMapforU8G2XBM(&FontBuffer[0]);
        //printFontToSerial(32);    
        u8g2.drawXBM(x,y,16,16,&FontBuffer[0]);
        pCodeString += 2;
        x += 16;
      } else {
         convert8by16FontBitMapforU8G2XBM(&FontBuffer[0]);
         u8g2.drawXBM(x,y,8,16,&FontBuffer[0]);
         pCodeString++;
         x += 8;
      }  
  }
}

void setup(void) {
  Serial.begin(115200);
  pinMode(SPI_CS2,OUTPUT);
  digitalWrite(SPI_CS2,HIGH);
  pinMode(SPI_FSO,INPUT);
  u8g2.begin();
}

void loop(void) {

  u8g2.firstPage();
  do {
 
    u8g2.drawFrame(0,0,127,63);            //  U8G2::drawBox(u8g2_uint_t x, u8g2_uint_t y,   u8g2_uint_t w, u8g2_uint_t h)
 
    drawFontIC(3,3,&TeststringGB231216by16[0]);

    u8g2.setFont(u8g2_font_t0_11_tf);
    u8g2.drawStr(20,32,"Font IC Test OK");

    u8g2.drawTriangle(20,38,5,56,35,56);
    u8g2.drawCircle(64,48,10,U8G2_DRAW_ALL);   // void U8G2:drawCircle(u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t opt = U8G_DRAW_ALL)
    u8g2.drawFilledEllipse(100,50,15,5,U8G2_DRAW_ALL);
    Serial.print(F("\r\n\r\n\r\n"));
  } while ( u8g2.nextPage() );
  delay(2000);
  while(1);
}