32
Let’s begin IoT with $10 session1: Introduction, LED brink without solder, and ping reply makoto

Let's begin io t with $10

Embed Size (px)

Citation preview

Page 1: Let's begin io t with $10

Let’s begin IoT with $10session1: Introduction, LED brink without solder, and ping reply

makoto

Page 2: Let's begin io t with $10

About myselfName: Makoto

Career: Infrastructure operation(Server,Network)

Dark past: 15 years ago, I tried to PIC micro-controller but, I couldn’t

make it work.I broke it, so had lost tens dollars, several times.

Introduction: I found Arduino as a easier technology for IoT and rejoin

microcontroller world.

It’s my hobby, do not belongs to any ordanizations

Page 3: Let's begin io t with $10

Terget groupTarget persons

familiar with basic knowledge of TCP/IP

familiar with CLI of OSX,Linux commands

able to spent less than $10

Excluding

Mnemonics programing fundamentalists

A-List Arduino supporters (like Genuino101)

Page 4: Let's begin io t with $10

Goal

Linux ArduinoSerial communication (over USB)

Concept- Lower cost (less than $5)- Easier Microcomputer technology- Attainment of minimum IP connection(ping) GoalTo prepare mininum Arduino R&D environment, to add IP address to Arduino, then connect PC to Arduino with serial comunication, then do ping  

IP IP

Page 5: Let's begin io t with $10

Tradeoff slider

Cost

Newer Tech

Easer Tech

importantunimportant

Compliance toLocal radio lows

Elegant Tech

Page 6: Let's begin io t with $10

Scope

SensorMCP

GatewayGatewayAPP

MotorMCP

PCServer Public cloud

Internet/Intranet - wifi - Ether - 3G/4G

Arduino Linux ARMs (Raspberry pi etc.)mbed

SensorsGPSMotor Driveretc.

Page 7: Let's begin io t with $10

Why Arduino clone?easy architecture

Arduino Linux系ARM mbed互換

examples Arduino mini cloneArduino nano clone $1.3〜 include shipping

Raspbbery PI zero($6,but difficult to get)Orange Pi($10)C.H.I.P($9)

Nucleo series($15)

computing week(ATMega8bit/8Mhz〜)

enough(ARM) enough(ARM)

IDE Special IDE(C++like) Linux itself Web IDE(C++like)

memo There are a lot of strange, cheap Arduino and their copy

if you are a linuxer, you may be a little bit boring.

I can give up devices even if i would play it with beer then break these devices

Page 8: Let's begin io t with $10

Whay Arduino copy?cheap

expensive

easy technology(as beginner)Difficult

technology

●Arduino mini clone

●Arduino nano clone

●Raspberry Pi zero

● mbed compatible●Orange Pi

●Arduino for geek(Digispark etc)

●昔からあるマイコン (PIC/H8とか)

My Scope

●A-List Arduino(Genuino101 etc.)

Page 9: Let's begin io t with $10

Picture:Raspberry Pi zero and Arduino clones

Raspberry PiDigispark(Arduino)

Arduino pro miniclone

Arduino nanoclone NodeMCU/Amica

clone(*1)WeMosclone(*1)

Japanese radio regulation doesn’t permit to use NodeMCU/WeMos because of uncertified devices. If you want to use WiFi connection, You can use “wroom-02” as a certified device.

Page 10: Let's begin io t with $10

Arduinoscheap Arduino clones

Digispark Arduino pro miniclone

Arduino nanoclone

Arduino unoclone

NodeMCU

lowest price $1.15 free shipping

$1.25 free shipping $1.71 free shipping $2.6 free shipping $3.23 free shipping

Micro-controller

ATTiny85(8bit) ATmega168(8bit), ATmega328P(8bit)

ATmega168(8bit), ATmega328P(8bit)

ATmega328P(8bit) ESP8266(32bit +WiFi)

Ingerface(driver)

micro USB(libusb)

raw UART mini USB (CH341, fishy?)

mini USB (CH341,fishy?)

micro USB(CP210x)

IDE CustomizedArduino IDE

Arduino IDE Arduino IDE Arduino IDE ArduinoIDE+liberary addon

Pros. smallest,cheepest

cheep,small, 3.3,v5v selectable

famous,a lot of information

a lot of informationno need of solder

WiFi a lot of information

Cons special and low version IDE

lack of USBrequired UART

USB is fishy “mini” USB is rare

“mini” USB is rareI don’t own it

Japanese regulation doesn’t permit to use it

My selecion

Page 11: Let's begin io t with $10

Example:Arduino nano 328P on “Aliexpress”

Page 12: Let's begin io t with $10

Arduino basic information

❖ No operation system. program keeps running directly on the devices ➢ no standard TCP/IP library. selectable, so you should choice fitting one.

❖ With “UART”, You write program(sketch) to devices and communicate with it. ➢ most of Arduinos have USB controller. use USB to suply power and communicate via UART.➢ In this case,Arduino seems to be a com port(Serial port) from PC(you can use teraterm)

➢ Physically , Audiono use lower voltage comparing to RS232C(Typical Serial communication for PC)

PCUSB

Arduino本体USB Controller UART

Example:Arduino nano

Power supply

Page 13: Let's begin io t with $10

Arduino basic information

❖ How to use➢ With C++ like language, make program on its IDE➢ compiling and write to Arduino via IDE➢ Run the programs by reboot, reset or automatically

❖ Weakness of computing comparing to ARMs, such as Raspberry Pi1(a hundredth)❖ Too small memory space(very surprising for server engineer )

➢ no DRAM, only SRAM➢ Sometimes “Hanoi tower” stack makes memory leak before CPU limitation

Page 14: Let's begin io t with $10

Develop environment

USB cable

Arduino nano本体

PC

Arduino IDE(Software)

Hardware● PC(OSX,in my case)● USB cable

(USB mini, in this case)● Arduino nano clone

Software● Arduino IDE● SerialIP Library● SUB uart driver

No need(at least today)● Solder● bread-board、cable● register、LED● sensors

Page 15: Let's begin io t with $10

Develop environment(Hardware)● PC(Mac, in my case)

○ Basically, at least Mac/Windows/Linux is OK.○ Today, Linux is requried to use SLIP. MAC/Windows already had ended the

“SLIP”Li Linux on Virtualbox or other hypervisors with USB pass through is acceptable.

● USBケーブル○ Arduino nano require mini USB. It is different from micro USB(typical USB)○ mini USB is legacy in macro world, but common in Arduino world○ There are some USB cable to supply power without data wires.

● Arduino nano clone○ 2type processor(ATMega168 and 328P)

■ ATmega168: Flash 16KB/SRAM 1KB/ EEPROM 512B/ 180円〜 ■ ATmega328: Flash 32KB/SRAM 2KB/ EEPROM 1KB/ 209円〜

○ I recommend online like Aliexpress(http://www.aliexpress.com/)○ Standard Arduino with the emblem cost 10 times higher!!

We use it!

Today, 168 is not okbecause of memory

Page 16: Let's begin io t with $10

Hardware memorandum

● All devices that I ordered could arrive without loss within 3 weeks , but one of them took more than 1 month.

● I recommend that you order 2 arduinos at different shops as insurance. Even though, it is cheep.

● Today we don’t use solder, but you cannot escape from it in this field. A simple and cheep kit is enough. It may cost less than $20.

● How to enjoy1. Order some cheep devices from your smartphone as your killing time 2. Forget the order3. After 2weeks, It may arrive. you may develop it with beer and break it 4 Soon, spare one may arrive.5 Finally you can make it work. cheers!

Page 17: Let's begin io t with $10

開発環境:Arduino IDE

❖ Arduino IDE➢ Download

https://www.arduino.cc/en/Main/Software➢ Current version is1.6.8. simply uszip it and run.➢ You push OK button, then work directory “/User/[user name]

/Documents/Arduino” will be created

Page 18: Let's begin io t with $10

❖ SUB uart driver➢ http://www.wch.cn/download/CH341SER_MAC_ZIP.html➢ OSX and Win are required to install a USB driver(ubuntu14 are not required)➢ Google said lot of developers are using it and I try to believe this driver. ➢ OSX detect Arduino nano as a serial device with crazy name as below.➢ This device name may cause problem1(I write it later)

Takahashi-no-MacBook-Pro:~ makotaka$ sudo ls -al /dev/ | grep cucrw-rw-rw- 1 root wheel 18, 3 4 3 15:24 cu.Bluetooth-Modemcrw-rw-rw- 1 root wheel 18, 1 4 3 15:24 cu.Bluetooth-PDA-Synccrw-rw-rw- 1 root wheel 18, 93 4 24 14:23 cu.wch ch341 USB=>RS232

開発環境: USB driver

Page 19: Let's begin io t with $10

❖ Use embedded LED blinking sample sketch without revising ➢ “File” → ”Example” → ”01.Basics”→”Blink”

❖ Arduino developer call source cord “Sketch”

LED brink:Let’ try to work

Page 20: Let's begin io t with $10

❖ Select Board/Processor/Serial port➢ “Tool” → select “Arduino nano” then “ATmega 328” as processor and

correct usb serial port. ➢ The sample code means

■ Set PIN 13 as OUTPUTPIN 13 is connected to embedded LED

■ Set voltage High,then wait 1sec■ Set voltage Low,then wait 1sec■ Loop above actions

LED brink:Let’ try to run

Page 21: Let's begin io t with $10

LED brink:Let’ try to fail(in case of OSX)

❖ Let’ try to write into your Arduino

❖ You may get failed

Page 22: Let's begin io t with $10

LED brink:Let’ try to make it

❖ Spaces in device name caused the error.❖ A solution is to make a symbolic link named “cu.wch”-rw- 1 root wheel 18, 93 4 24 14:23 cu.wch ch341 USB=

$ sudo ln -s "/dev/cu.wch ch341 USB=>RS232 fd120" /dev/cu.wchPassword:$ ls -al /dev/cu.*crw-rw-rw- 1 root wheel 18, 3 4 3 15:24 /dev/cu.Bluetooth-Modemcrw-rw-rw- 1 root wheel 18, 1 4 3 15:24 /dev/cu.Bluetooth-PDA-Synclrwxr-xr-x 1 root wheel 0 4 24 14:20 /dev/cu.wch -> /dev/cu.wch ch341 USB=>RS232 fd120crw-rw-rw- 1 root wheel 18, 97 4 24 14:46 /dev/cu.wch ch341 USB=>RS232 fd120 ダメなデバイス名

Page 23: Let's begin io t with $10

LED brink:Let’ try to rerun

1. Reselect the symbolic link as a serial port

2. rewrite3. may succeed

3- LED may brink every 1 sec- Next, you can try to change brink time

Page 24: Let's begin io t with $10

❖ Some Arduino nanos are not ready to be written. ❖ push “Reset Button” then when compiling, then release the button just before

IDE start to write binary to your Arduino clone.-rw- 1 root wheel 18, 93 4 24 14:23 cu.wch ch341 USB=

LED brink:If your arduino clone is not writable,

コレ

Page 25: Let's begin io t with $10

Ping: Installation of Serial IP library❖ SerialIP Library

➢ It’s serial ip communication library for SLIP(historical protocol)➢ Download

■ http://www.shikadi.net/files/arduino/SerialIP-1.0.zip➢ Install the library

“Sketch” → “Include Library” → “Add zip Library”Choose “SerialIP-1.0.zip” you downloaded

Page 26: Let's begin io t with $10

Ping:compiling failire

1. File → Example→SerialIP2. Select “hellowWorlddServer”3. Try to compile4. Then get failed

Page 27: Let's begin io t with $10

❖ The reason is that the library is little bit old for newer IDE. ❖ IDE version is 1.0 or later, you should change a line in 3 files

➢ Open /libraries/SerialIP/SerialIP.h in your work directory➢ Change WProgram.h to Arduino.h at line 24➢ Line 21 in clock-arch.c, and line 21 in SerialIP.cppのshould be change

as the same way.$vi /Users/ユーザ名/Documents/Arduino/libraries/SerialIP/SerialIP.h

24: #include <WProgram.h> #Befroe24: #include <Arduino.h> #After

Ping:Rewrite SerialIP Files

$vi /Users/ユーザ名/Documents/Arduino/libraries/SerialIP/clock-arch.c〜略〜

$vi /Users/ユーザ名/Documents/Arduino/libraries/SerialIP1/SerialIP.cpp〜略〜

Page 28: Let's begin io t with $10

❖ Arduino may be ready.

Ping:Arduino is ready

congratulations!

Page 29: Let's begin io t with $10

❖ Unfortunately, Windows/OSX had ended “SLIP” support.❖ At least Linux PC support SLIP.❖ I don’t have another PC, Inevitably, I use ubuntu14 on VirtualBox with USB

pass-through.

Ping:Ping対向の設定

Virtual Box (MAC)

Arduino

Serial Communication(SLIP over USB)

IP

VM(ubuntu14)

IP

Arduino nano

IP

(*)SLIP is historical serial protocol older than PPP. evoking nostargia

Page 30: Let's begin io t with $10

Ping:ubuntu configuration, Ping to arduino $sudo modprobe slip$sudo slattach -L -s 115200 -p slip /dev/ttyUSB0 & #background$sudo fconfig sl0 192.168.5.1 dstaddr 192.168.5.2$ping 192.168.5.2PING 192.168.5.2 (192.168.5.2) 56(84) bytes of data.64 bytes from 192.168.5.2: icmp_seq=1 ttl=64 time=29.8 ms64 bytes from 192.168.5.2: icmp_seq=2 ttl=64 time=32.8 ms64 bytes from 192.168.5.2: icmp_seq=3 ttl=64 time=36.5 ms^C--- 192.168.5.2 ping statistics ---3 packets transmitted, 3 received, 0% packet loss, time 2003msrtt min/avg/max/mdev = 29.850/33.060/36.528/2.740 ms$ifconfig sl0sl0 Link encap:シリアルラインIP inetアドレス:192.168.5.1 P-t-P:192.168.5.2 マスク:255.255.255.255 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:296 メトリック:1 RXパケット:3 エラー:0 損失:0 オーバラン:0 フレーム:0 TXパケット:3 エラー:0 損失:0 オーバラン:0 キャリア:0 衝突(Collisions):0 TXキュー長:10 RXバイト:252 (252.0 B) TXバイト:252 (252.0 B)

Page 31: Let's begin io t with $10

Ping:TCP connection ❖ ordinary, this example sketch is for Arduino TCP listen. So you can connect to   TCP port 1000 by telnet. You can also customize the example sketch.

Page 32: Let's begin io t with $10

NEXT session: Ethernet+MQTT

LAN Cable($.99)

F-F cable7wires($0.7/20wires. I suggest that you buy M-M/M-F cable at once. It may be required)

“ENC28J60” , cheap Ethernet module($2.4)

Arduino nano(We used today)

Arduino nano

ENC28J60

MQTT broker(Linux)

SPI

Ethernet

1. Next, devices&tools totally costs less than $5 are needed. Solder is also required. 2. We just need a cheap solder kit. you can study 3. you can study solder at https://www.youtube.com/watch?v=37mW1i_oEpA

LAN