Hardware Open Source

32
Hardware Open Source Tiago Maluta 16 de outubro de 2009 Tiago Maluta Hardware Open Source

description

Slides da palestra Hardware Open Source feita no Encontro Mineiro de Software Livre na Universidade Federal de Itajuba. Trata-se de uma conversa sobre a utilizaçao de hardware open source e uma apresentaçao de projetos com o Arduino.

Transcript of Hardware Open Source

Page 1: Hardware Open Source

Hardware Open Source

Tiago Maluta

16 de outubro de 2009

Tiago Maluta Hardware Open Source

Page 2: Hardware Open Source

Hardware Open Source

Desenvolvido no mesmo modelo do FOSS1

Refere-se a informacao sobre o design

EsquemasLista de Materiais (BOM)PCB layout

Hardware Description Language (HDL)

FPGA (Xilinx, Altera, ...)

Comum entre hobistas (DIY)

1Free and Open Source SoftwareTiago Maluta Hardware Open Source

Page 3: Hardware Open Source

Colaborac~ao

"Hardware engineers do the same thing as softwareengineers: they use high-level design patterns.They memorize circuits for accomplishing certain

things and then plug them together."

Tiago Maluta Hardware Open Source

Page 4: Hardware Open Source

Como um hardware pode ser ”open”?

1 Acesso a informacao sobre como hardware funciona, para serusado livremente.

2 O design deve ser publico, para que outros implementem eaprendam a partir do projeto.

3 As ferramentas utilizadas na construcao do hardware devemser disponıveis, para outros desenvolverem e alterarem odesign.

Tiago Maluta Hardware Open Source

Page 5: Hardware Open Source

Casos de sucesso

Arduinowww.arduinio.cc

BeagleBoardwww.beagleboard.org

Gumstixwww.gumstix.com

Tiago Maluta Hardware Open Source

Page 6: Hardware Open Source

Prototipo

http://www.flickr.com/photos/justinmclean/3846230883/in/set-72157622114963090/

Tiago Maluta Hardware Open Source

Page 7: Hardware Open Source

Design

Software

Electronic Design Automation (EDA)

Esquematico, PCB, simulacao

Exemplos:

Eaglehttp://www.cadsoft.de/

gEDAhttp://www.gpleda.org/

Fritzinghttp://fritzing.org/

KiCadhttp://kicad.sf.net

Tiago Maluta Hardware Open Source

Page 8: Hardware Open Source

Printed Circuit Board (PCB)

Tiago Maluta Hardware Open Source

Page 9: Hardware Open Source

Como facilitar?

1 Prototipagem rapida

2 Hardware em camadas

3 Desenvolvimento acessıvel

4 Bibliotecas de Software

Tiago Maluta Hardware Open Source

Page 10: Hardware Open Source

Arduino

Plataforma open-source flexıvelAs versoes mais populares utilizam microcontrolador de 8-bits da ATMEL (ATMega)

Focado na criacao de objetos interativos

Bem documentadohttp://www.arduino.cc/

Aprox. US$ 35.00

Hardware em camadas (Wiishield, Ethernet, Bluetooth, GPS,etc)

Alimentacao pela USB (5V)

Tiago Maluta Hardware Open Source

Page 11: Hardware Open Source

Compilador: AVR toolchain

/usr/i686-pc-linux-gnu/avr/gcc-bin/4.4.1/avr-gccbug/usr/i686-pc-linux-gnu/avr/gcc-bin/4.4.1/avr-gcov/usr/i686-pc-linux-gnu/avr/gcc-bin/4.4.1/avr-gcc-4.4.1/usr/i686-pc-linux-gnu/avr/gcc-bin/4.4.1/avr-c++/usr/i686-pc-linux-gnu/avr/gcc-bin/4.4.1/avr-g++/usr/i686-pc-linux-gnu/avr/gcc-bin/4.4.1/avr-cpp

Tiago Maluta Hardware Open Source

Page 12: Hardware Open Source

Programacao

Ambiente de desenvolvimento integrado (IDE) (Windows/Linux/OSX)

Processing

Arduino Programming Language

Baseado na linguagem C/C++

Sketch e o nome dado a um programa no Arduino

Gravacao pela USB2

2Nao sao todos os modelosTiago Maluta Hardware Open Source

Page 13: Hardware Open Source

Arduino Programming Language

Dividido em tres partes principais.

Estrutural

Valores

Funcoes

Tiago Maluta Hardware Open Source

Page 14: Hardware Open Source

Estrutural

void setup()Executado apenas uma vez

Inicializacao

void loop()Executada repetida vezes

”Coracao”do scketch

if

if...else

for

switch case

while

do...while

break

continue

return

Tiago Maluta Hardware Open Source

Page 15: Hardware Open Source

Valores

Tipos:

boolean (true ou false)

char (8 bits)

byte (8 bits)

int (2 bytes)

unsigned int (2 bytes)

long (4 bytes)

unsigned long (4

bytes)

float (4 bytes)

double (=float)

array ([])

string (array + ’\0’)

void (somente na

declaracao de funcoes)

Conversao:

char()byte()int()long()float()

Constantes

HIGH | LOW

INPUT | OUTPUT

true | false

Integer constants

decimal (11)

binario (B1011)

hex (0xB)

octal (013)

Floating point constants

3.14E5(3.14 x 10∧5)25e-6(0.000025)

Formatadores U & L

long1000lunsigned1000uunsigned long1000ul

Tiago Maluta Hardware Open Source

Page 16: Hardware Open Source

Funcoes

Digital I/O

pinMode(pin,mode)

digitalWrite(pin, value)

int digitalRead(pin)

Analog I/O

int analogRead(pin)

analogWrite(pin,value)

Time

unsigned long millis()

unsigned long micros()

delay(ms)

delayMicroseconds(us)

Math

min(x,y)

max(x,y)

abs(x)

constrain(x,a,b)

map(value, fromLow,

fromHigh, toLow, toHigh)

pow(base, exponent)

sq(x)

sqrt(x)

Trigonometry

sin(rad)

cos(rad)

tan(rad)

Random Numbers

randomSeed(seed)

long random(max)

random(min,max)

Communication

Serial

Tiago Maluta Hardware Open Source

Page 17: Hardware Open Source

Hello World

void setup(){pinMode(13, OUTPUT);

}

void loop(){digitalWrite(13, HIGH);delay(500);digitalWrite(13, LOW);delay(500);

}

Tiago Maluta Hardware Open Source

Page 18: Hardware Open Source

Coracao do Arduino: Arquitetura AVR

I/O Memory Adderess

Data Direction Register(DDRx)Data (PORTx)Port Input Pins (PINx)

Harvard architecture

Tiago Maluta Hardware Open Source

Page 19: Hardware Open Source

Projetos

Conhecer os protocolos de comunicacao.

I2C, SPI, UART (RS232)

Acesso a documentacao to microcontrolador

ATMega168 ou ATMega328 http://www.msarnoff.org/chipdb/ATmega168

Tiago Maluta Hardware Open Source

Page 20: Hardware Open Source

Projeto #1: LCD Display

http://www.flickr.com/photos/maluta/3804133584/in/set-72157621867976757/

Tiago Maluta Hardware Open Source

Page 21: Hardware Open Source

Projeto #1: LCD Display

2x16 LCD (Hitachi HD44780)

Register Select (RS)Read/Write (R/W)Enable8x DataDisplay ConstrastPower supplyBacklight

Tiago Maluta Hardware Open Source

Page 22: Hardware Open Source

LCD pin ArduinoRS → digital pin 12

Enable → digital pin 11D4 → digital pin 5D5 → digital pin 4D6 → digital pin 3D7 → digital pin 2

Tiago Maluta Hardware Open Source

Page 23: Hardware Open Source

#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {// set up the LCD’s number of rows and columns:

lcd.begin(16, 2);

// Print a message to the LCD.

lcd.print("hello, world!");

}

void loop() {// set the cursor to column 0, line 1

// (note: line 1 is the second row, since counting begins with 0):

lcd.setCursor(0, 1);

// print the number of seconds since reset:

lcd.print(millis()/1000);

}

Tiago Maluta Hardware Open Source

Page 24: Hardware Open Source

Projeto #2: Webserver

http://www.flickr.com/photos/maluta/4015803466/in/set-72157621867976757/

Tiago Maluta Hardware Open Source

Page 25: Hardware Open Source

Projeto #2: Webserver

Ethershield

Utiliza um chip dedicado da Microchip (ENC28J60)Stand-Alone Ethernet Controller with SPI Interface

http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en022889

O modelo ”oficial”utiliza o chip da Wiznet (W5100)http://www.wiznet.co.kr/en/pro02.php?&ss%5B2%5D=1&page=1&num=25

Tiago Maluta Hardware Open Source

Page 26: Hardware Open Source

#include "etherShield.h"

static uint8 t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};

static uint8 t myip[4] = {10,0,0,25};

#define MYWWWPORT 80

#define BUFFER SIZE 550

static uint8 t buf[BUFFER SIZE+1];

EtherShield es = EtherShield();

Tiago Maluta Hardware Open Source

Page 27: Hardware Open Source

uint16 t http200ok(void)

{return(es.ES fill tcp data p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type:

text/html\r\nPragma: no-cache\r\n\r\n")));}

// prepare the webpage by writing the data to the tcp send buffer

uint16 t print webpage(uint8 t ∗buf){

uint16 t plen;

plen=http200ok();

plen=es.ES fill tcp data p(buf,plen,PSTR("<html><head><title>Arduino ENC28J60 Ethernet Shield

V1.0</title></head><body>"));

plen=es.ES fill tcp data p(buf,plen,PSTR("<center><h1>Hardware Open Source</h1>"));

plen=es.ES fill tcp data p(buf,plen,PSTR("<hr><br><h2><font color=\’’blue\’’>-- EMSL’09 --

<br>Encontro Mineiro de Software Livre"));

plen=es.ES fill tcp data p(buf,plen,PSTR("<br> "));

plen=es.ES fill tcp data p(buf,plen,PSTR("<br> "));

plen=es.ES fill tcp data p(buf,plen,PSTR("<br></font></h2>") );

plen=es.ES fill tcp data p(buf,plen,PSTR("</center><hr>"));

plen=es.ES fill tcp data p(buf,plen,PSTR("Tiago Maluta [email protected] "));

plen=es.ES fill tcp data p(buf,plen,PSTR("<a

href=\’’http://www.coding.com.br\’’>www.coding.com.br</a>"));plen=es.ES fill tcp data p(buf,plen,PSTR("</body></html>"));

return(plen);

}

Tiago Maluta Hardware Open Source

Page 28: Hardware Open Source

void setup(){

// initialize enc28j60

es.ES enc28j60Init(mymac);

// init the ethernet/ip layer:

es.ES init ip arp udp tcp(mymac,myip, MYWWWPORT);

}

Tiago Maluta Hardware Open Source

Page 29: Hardware Open Source

void loop(){uint16 t plen, dat p;

while(1) {// read packet, handle ping and wait for a tcp packet:

dat p=es.ES packetloop icmp tcp(buf,es.ES enc28j60PacketReceive(BUFFER SIZE, buf));

/∗ dat p will be unequal to zero if there is a valid

∗ http get ∗/if(dat p==0){

// no http request

continue;

}// tcp port 80 begin

if (strncmp("GET ",(char ∗)&(buf[dat p]),4)!=0){// head, post and other methods:

dat p=http200ok();

dat p=es.ES fill tcp data p(buf,dat p,PSTR("<h1>200 OK</h1>"));

goto SENDTCP;

}// just one web page in the "root directory" of the web server

if (strncmp("/ ",(char ∗)&(buf[dat p+4]),2)==0){dat p=print webpage(buf);

goto SENDTCP;

}else{

dat p=es.ES fill tcp data p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type:text/html\r\n\r\n<h1>401 Unauthorized</h1>"));

goto SENDTCP;

}SENDTCP:

es.ES www server reply(buf,dat p); // send web page data

}

Tiago Maluta Hardware Open Source

Page 30: Hardware Open Source

Outros projetos

Twitter

Paineis Solares

Sintetizador de som

GPS

Sensores (Umidade, Luz, etc)

Compartilhamento atraves do Pachube(http://community.pachube.com/)

Tiago Maluta Hardware Open Source

Page 31: Hardware Open Source

Consideracoes

Consumo eletrico

Custo (R$)

Documentacao

Esquematico

BOM

PCB

Propriedade Intelectual

Licenca Compatıvel

Sugestao: Creative Commons

Comunidade de Usuarios

Tiago Maluta Hardware Open Source

Page 32: Hardware Open Source

Referencias

http://del.icio.us.com/maluta/arduinohttp://www.coding.com.br

Tiago Maluta Hardware Open Source