12 月 212023
 

cpu stress:

from multiprocessing import Pool
from multiprocessing import cpu_count

def f(x):
    while True:
        x*x

if __name__ == '__main__':
    processes = cpu_count()
    print('utilizing %d cores\n' % processes)
    pool = Pool(processes)
    pool.map(f, range(processes))

memory stress:

# Eats about 1GB of memory
x = bytearray(1*1024*1024*1024)

Source:

Continue reading »
7 月 032023
 

Source: MicroPython umqtt 連線/斷線的的注意事項

MicroPython 提供有 umqtt 模組可以使用 MQTT 協定, 不過在 umqtt 裡面有再分為 simple 和 robust 模組, 這兩種模組功能基本相同, 但如果設計純訂閱端 (只收資料不送資料) 這樣的程式, 在使用上就必須多加留意。

Continue reading »
4 月 112021
 

Source: 燒錄Hex code到Arduino

最近考慮到要怎麼用Arduino來幫廠商開發一個專案,但又不想將source code分享給廠商,所以就上網找了一下如何用直接燒錄Hex code到Arduino上,上網一查還蠻多人有這樣的需求,也有前輩分享了他的使用經驗,所以就將網頁轉帖過來,做一個保留以便自己日後可以回憶。

Continue reading »
4 月 112021
 

Source: hex 檔

hex 檔是原始碼編譯過後產生的檔案,你可以將 hex 檔上傳給 Arduino,它的功用等同於你寫的程式。

如果你想把自己寫的程式給別人安裝在他的 Arduino 板子上來炫耀一下自己有多麼聰明,又不想讓他看到程式碼是怎麼寫的,那麼你可以把 hex 檔交給他即可。像這樣的方式也可以算是保護智慧權的一種。

產生 hex 檔案

在編譯或上傳程式到 Arduino 板子時,Arduino 會順便產生一些檔案,這些檔案會被放置到
C:\Documents and Settings\USER\Local Settings\Temp\build<一堆數字>.tmp 資料夾裏,其中一個就是 hex 檔。如果你的程式名稱是 blink.ino,那麼這個 hex 檔會被命名為 blink.cpp.hex。

將 hex 安裝到 Arduino

網路有很多應用軟體都可以將 hex 安裝到 Arduino 上,像是 XLoader、 Arduino UNO Uploader Tool …等。大部分像這樣的軟體都會使用 Arduino 內建的 avrdude 程式作為上傳媒介。

您可以打開命令列視窗,並切換到 hex 檔所在路徑,鍵入下列命令可以將 hex 安裝到 Arduino。

/hardware/tools/avrdude -V -F -C /hardware/tools/avrdude.conf -p atmega328p -P COM5 -c stk500v1 -b 57600 -U flash:w:applet/blink.cpp.hex

使用應用軟體安裝 hex

下載 Arduino UNO Uploader Tool
網址 https://github.com/downloads/rlangoy/Arduino-Uno-Uploader-Tool/AUTSetupVer1_18.zip

下載 Xloader
網址 http://xloader.russemotto.com/XLoader.zip
教學 http://pizgchen.blogspot.tw/2015/06/upload-hex.html

使用自己熟悉的軟體安裝 hex

如果您熟悉 Python、C 和 VB …這樣的程式語言,您也可以使用這些程式語言將 hex 安裝到 Arduino。

4 月 112021
 

Source: Extracting Code from an Arduino

Your avrdude command and options should look somthing like…

avrdude -p atmega2560 -c stk500v2 -P COM10 -b 115200 -U flash:r:flash_backup_file.hex

-c stk500v2 is how the bootloader in MEGA2560 talks
-P is the serial port, that may be the address thing you were seeing (not sure) but you need to know which port
-b 115200 is the baud rate (not sure if it is 57600 or 115200, it should not hurt to try both)
-U flash:r:flash_backup_file.hex is the key to reading … notice the r … where the :r: is … that is for reading.

to backup the eeprom (a good idea)

avrdude -p atmega2560 -c stk500v2 -P COM10 -b 115200 -U eeprom:r:eeprom_backup_file.hex

if you want to write it back to the board

avrdude -p atmega2560 -c stk500v2 -P COM10 -b 115200 -e -U flash:w:flash_backup_file.hex

-e will nuke everything which you probably need to do befor writing.

avrdude -p atmega2560 -c stk500v2 -P COM10 -b 115200 -U eeprom:w:eeprom_backup_file.hex

an explicite erase is not needed with eeprom.