Posts

arduino最小構成 (atmega328/8MHz/3.3V/内部クロック)FT232RLにてブートローダーの書き込み

Image
1.部品 ATMEGA328P-PU USBシリアル変換モジュールFT232RL 0.1μFコンデンサ ブレッドボード ジャンパーワイヤ 2.ROM,DRIVER,書き込み用ソフトの準備 breadboard-1-6-x.zip をダウンロードして展開します。 FTAVRW : FT232-AVR Writerの ftavrw_v121b.zip をダウンロードして展開します。 https://www.ftdichip.com/Drivers/VCP.htm FTDIドライバをダウンロードして展開、インストールします。 3.ブートローダーの書き込み 配線 下図はブレッドボード上に配線した例です。 ftavrwg.exeをクリックして実行します。 avr info ボタンを押下し、情報が取得されたら配線はOKです。 ATmegaBOOT_168_atmega328_pro_8MHz.hexを選択し、書き込みます。 下図のようなメッセージが出ましたら、書き込みが完了です。 boards.txtを確認して、FUSEを書き込みます。 下図のようなメッセージが出ましたら、書き込みが完了です。 4.スケッチの書き込み 配線 下図はスケッチの配線例です。注意: RESET に 0.1μF のコンデンサを噛ます必要があります arduino IDEを開いてexamples(Blink)を書き込んでみます。 書き込みは無事にできました。Blinkもちゃんと動いています。

[IoT] OPEN THE DOOR スマホでドアを開ける [ESP8266]Wi-Fiモジュール [arduino IDE]

Image
背景 会社の事務所の玄関ドアがめっちゃ古くてICカードも使えず鍵しか使えない、あるいはインタホンで室内の人呼び出し、ドアを開けてあげる。今Iotの時代がやって来て、こんなに面倒な入室システムは時代に遅れている、改造していきたいと思います。(物理的な破壊ぜず、今の入室システム影響無いように改造する)。 設計 ユースケース:入室しようとする人が玄関でルーム番号入力し「呼び出す」を押すと室内のインタホンが鳴り始めて、受話器を取って解除ボタンを押してドアが開く。 受話器の取り上げと解除ボタンの押下を自動的にすれば、実現できるはずです。 システム設計図: 機械調達 社内サーバーを用意します。 ebayにて購入したESP8266マイコンボードも無事に届きました。 コントローラーの設計 部品: ESP8266ボード X 1 基盤X1 トランジスター(NPN) X 2 5Vリレー X 2 ジャンパーワイヤー 若干 回路図: 半田付け後実物: ESP8266ボードの開発: usbシリアル変換ドライバのインストール、ARDUINO IDEのインストール、ESP8266ボードの追加など略にします。(GOOGLEで検索すれば、出るはずです。) ソースコード: #include #include const char* ssid = "xxxxxxxxxxx"; const char* password = "xxxxxxxxx"; WiFiUDP Udp; unsigned int localUdpPort = 4242; // local port to listen on char incomingPacket[255]; // buffer for incoming packets char replyPacket[] = "Hi there! Got the message :-)"; // a reply string to send back void setup() { Serial.begin(115200); delay(10); // prepare GPIO2 pinM...

PYTHON UnicodeEncodeError: 'ascii' codec can't encode character

import io,sys sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

Python3 + Django + uWSGI + Nginx On FreeBSD

1. uWSGI Installation. $ sudo pip-3.6 install uwsgi Collecting uwsgi Downloading uwsgi-2.0.17.tar.gz (798kB) 100% |################################| 798kB 709kB/s Installing collected packages: uwsgi Running setup.py install for uwsgi ... done Successfully installed uwsgi-2.0.17 1.1 Basic test Let’s start with a simple “Hello World” example: def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] As you can see, it is composed of a single Python function. It is called “application” as this is the default function that the uWSGI Python loader will search for (but you can obviously customize it). 1.2 Now start uWSGI to run an HTTP server/router passing requests to your WSGI application: uwsgi --http :9090 --wsgi-file foobar.py 2.Installing Django. Install Django into your virtualenv , create a new project $ mkproject django $ pip install Django Collecting Django ...

[FreeBSD] Installing and using Python's virtualenv using Python3

1. Installing Python3. $ sudo pkg install python36 Updating FreeBSD repository catalogue... FreeBSD repository is up to date. All repositories are up to date. The following 2 package(s) will be affected (of 0 checked): New packages to be INSTALLED: python36: 3.6.4 libffi: 3.2.1_2 Number of packages to be installed: 2 The process will require 103 MiB more space. 15 MiB to be downloaded. Proceed with this action? [y/N]: y [1/2] Fetching python36-3.6.4.txz: 100% 15 MiB 15.5MB/s 00:01 [2/2] Fetching libffi-3.2.1_2.txz: 100% 34 KiB 35.3kB/s 00:01 Checking integrity... done (0 conflicting) [1/2] Installing libffi-3.2.1_2... [1/2] Extracting libffi-3.2.1_2: 100% [2/2] Installing python36-3.6.4... Extracting python36-3.6.4: 100% Message from python36-3.6.4: =========================================================================== Note that some standard Python modules are provided as separate ports as they require additional dependencies. They are availabl...

[Python] Using Python to get weather data

Here's a simple Python code snippet for finding the weather. 1. #!/usr/bin/python3 # -*- coding: utf-8 -*- import urllib.request from contextlib import closing import xml.etree.ElementTree as ET rssurl = 'https://rss-weather.yahoo.co.jp/rss/days/4410.xml' with closing(urllib.request.urlopen(rssurl)) as res: xml = res.read() tree = ET.fromstring(xml) root = tree.findall('.') for item in root[0].iter('item'): title = item.find('title').text print(title[:title.index(' - Y')]) 2. import requests import json def get_weather(): url = 'http://weather.livedoor.com/forecast/webservice/json/v1' payload = {'city': '130010'} data = requests.get(url, params = payload).json() #resp = urllib2.urlopen('http://weather.livedoor.com/forecast/webservice/json/v1?city=%s'%citycode).read() #resp = json.loads(resp) print(data['description']['text']) ...

FreeBSD: Configuring Apache to permit CGI

In httpd.conf file make sure the "cgi" LoadModule directive has not been commented out. A correctly configured directive may look like this: <IfModule mpm_prefork_module> LoadModule cgi_module libexec/apache24/mod_cgi.so </IfModule> Explicitly using Options to permit CGI execution To allow CGI program execution for any file ending in .cgi in users' directories, you can use the following configuration. <VirtualHost *:80> DocumentRoot "/usr/local/www/apache24/e" ServerName www.example.com ErrorLog "/var/log/e-error_log" CustomLog "/var/log/e-access_log" common <Directory "/usr/local/www/apache24/e/"> Order allow,deny Allow from all Require all granted Options +ExecCGI AddHandler cgi-script .cgi </Directory> </VirtualHost> <Directory "/home/*/public_html"> Options +ExecCGI AddHandler cgi-script .cgi </Di...