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.
2. Hardware Open Source
Desenvolvido no mesmo modelo do FOSS1
Refere-se a informa¸c˜ao sobre o design
Esquemas
Lista de Materiais (BOM)
PCB layout
Hardware Description Language (HDL)
FPGA (Xilinx, Altera, ...)
Comum entre hobistas (DIY)
1
Free and Open Source Software
Tiago Maluta Hardware Open Source
3. Colabora¸c~ao
"Hardware engineers do the same thing as software
engineers: they use high-level design patterns.
They memorize circuits for accomplishing certain
things and then plug them together."
Tiago Maluta Hardware Open Source
4. Como um hardware pode ser ”open”?
1 Acesso a informa¸c˜ao sobre como hardware funciona, para ser
usado livremente.
2 O design deve ser p´ublico, para que outros implementem e
aprendam a partir do projeto.
3 As ferramentas utilizadas na constru¸c˜ao do hardware devem
ser dispon´ıveis, para outros desenvolverem e alterarem o
design.
Tiago Maluta Hardware Open Source
9. Como facilitar?
1 Prototipagem r´apida
2 Hardware em camadas
3 Desenvolvimento acess´ıvel
4 Bibliotecas de Software
Tiago Maluta Hardware Open Source
10. Arduino
Plataforma open-source flex´ıvel
As vers˜oes mais populares utilizam microcontrolador de 8-bits da ATMEL (ATMega)
Focado na cria¸c˜ao de objetos interativos
Bem documentado
http://www.arduino.cc/
Aprox. US$ 35.00
Hardware em camadas (Wiishield, Ethernet, Bluetooth, GPS,
etc)
Alimenta¸c˜ao pela USB (5V)
Tiago Maluta Hardware Open Source
12. Programa¸c˜ao
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
Grava¸c˜ao pela USB2
2
N˜ao s˜ao todos os modelos
Tiago Maluta Hardware Open Source
14. Estrutural
void setup()
Executado apenas uma vez
Inicializa¸c˜ao
void loop()
Executada repetida vezes
”Cora¸c˜ao”do scketch
if
if...else
for
switch case
while
do...while
break
continue
return
Tiago Maluta Hardware Open Source
15. 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
declara¸c˜ao de fun¸c˜oes)
Convers˜ao:
char()
byte()
int()
long()
float()
Constantes
HIGH | LOW
INPUT | OUTPUT
true | false
Integer constants
decimal (11)
bin´ario (B1011)
hex (0xB)
octal (013)
Floating point constants
3.14E5
(3.14 x 10∧5)
25e-6
(0.000025)
Formatadores U & L
long
1000l
unsigned
1000u
unsigned long
1000ul
Tiago Maluta Hardware Open Source
16. Fun¸c˜oes
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
18. Cora¸c˜ao 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
19. Projetos
Conhecer os protocolos de comunica¸c˜ao.
I2C, SPI, UART (RS232)
Acesso a documenta¸c˜ao to microcontrolador
ATMega168 ou ATMega328 http://www.msarnoff.org/chipdb/ATmega168
Tiago Maluta Hardware Open Source
20. Projeto #1: LCD Display
http://www.flickr.com/photos/maluta/3804133584/in/set-72157621867976757/
Tiago Maluta Hardware Open Source
21. Projeto #1: LCD Display
2x16 LCD (Hitachi HD44780)
Register Select (RS)
Read/Write (R/W)
Enable
8x Data
Display Constrast
Power supply
Backlight
Tiago Maluta Hardware Open Source
22. LCD pin Arduino
RS → digital pin 12
Enable → digital pin 11
D4 → digital pin 5
D5 → digital pin 4
D6 → digital pin 3
D7 → digital pin 2
Tiago Maluta Hardware Open Source
23. #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
25. 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
26. #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
27. uint16 t http200ok(void)
{
return(es.ES fill tcp data p(buf,0,PSTR("HTTP/1.0 200 OKrnContent-Type:
text/htmlrnPragma: no-cachernrn")));
}
// 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 maluta@unifei.edu.br "));
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
28. 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
29. 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 UnauthorizedrnContent-Type:
text/htmlrnrn<h1>401 Unauthorized</h1>"));
goto SENDTCP;
}
SENDTCP:
es.ES www server reply(buf,dat p); // send web page data
}
Tiago Maluta Hardware Open Source