Tutorial: como utilizar o Joystick Shield com Arduino

Adquira estes componentes na Loja do Lab de Garagem

O Joystick Shield é um shield para conectar em cima do Arduino. Este shield contém um joystick polegar de dois eixos, 5 botões de mudança momentânea (4 + 1 botão de seleção) e um botão de mudança momentânea para o reset.

Abaixo podemos ver o esquemático do Shield: (Caso queira ver mais detalhes, clique aqui)

A partir do esquemático, podemos ver sua pinagem referente a conexão com Arduino. Agora que sabemos a pinagem, podemos ir para a programação do Arduino:

Abaixo está a programação exemplo modificada tirada deste link:

//Create variables for each button on the Joystick Shield to assign the pin numbers
char button0=3, button1=4, button2=5, button3=6;
char sel=2;

void setup(void)
{
pinMode(sel, INPUT); //Set the Joystick 'Select'button as an input
digitalWrite(sel, HIGH); //Enable the pull-up resistor on the select button

pinMode(button0, INPUT); //Set the Joystick button 0 as an input
digitalWrite(button0, HIGH); //Enable the pull-up resistor on button 0

pinMode(button1, INPUT); //Set the Joystick button 1 as an input
digitalWrite(button1, HIGH); //Enable the pull-up resistor on button 1

pinMode(button2, INPUT); //Set the Joystick button 2 as an input
digitalWrite(button2, HIGH); //Enable the pull-up resistor on button 2

pinMode(button3, INPUT); //Set the Joystick button 3 as an input
digitalWrite(button3, HIGH); //Enable the pull-up resistor on button 3

Serial.begin(9600); //Turn on the Serial Port at 9600 bps
}

void loop(void)
{
Serial.print(analogRead(0)); //Read the position of the joysticks X axis and print it on the serial port.
Serial.print(",");
Serial.print(analogRead(1)); //Read the position of the joysticks Y axis and print it on the serial port.
Serial.print(",");
Serial.print(digitalRead(sel)); //Read the value of the select button and print it on the serial port.
Serial.print(",");
Serial.print(digitalRead(button0)); //Read the value of the button 0 and print it on the serial port.
Serial.print(",");
Serial.print(digitalRead(button1)); //Read the value of the button 1 and print it on the serial port.
Serial.print(",");
Serial.print(digitalRead(button2)); //Read the value of the button 2 and print it on the serial port.
Serial.print(",");
Serial.println(digitalRead(button3)); //Read the value of the button 3 and print it on the serial port.

//Wait for 100 ms, then go back to the beginning of 'loop' and repeat.
delay(100);
}

Abra a IDE do Arduino e cole a programação acima. Conecte o Joystick Shield no Arduino e depois o Arduino no PC. Selecione a versão da sua placa Arduino (UNO, Duemilanove, etc) e depois a porta (COMx, ttyUSBx, ttyACMx, etc)a qual o Arduino está conectado. Faça o UPLOAD e abra o Serial Monitor. Selecione "9600 baud" e "No line ending", você verá vários números como mostra a figura abaixo:

Ao mexer o joystick polegar, você verá os primeiros números variarem (510 e 523). Os números posteriores são o botão de seleção (botão do polegar) e os 4 botões restantes do Joystick Shield. Ao apertar um desses botões, você verá um valor "1" ir para "0". Você pode experimentar apertar todos os botões ao mesmo tempo e todos irão para "0".

Pronto! Agora você pode fazer seu projeto utilizando o Joystick Shield como protótipo! Se tiver dúvidas, poste aqui mesmo neste blog! Caso tenha sugestões para tutoriais, clique aqui! Para ver outros tutoriais e projetos desenvolvidos pela equipe LdG e por outros garagistas, clique aqui e aqui, respectivamente!

Referências:

http://www.sparkfun.com/products/9760

http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Dev/Arduino/Shields/...

http://www.sparkfun.com/Code/Joystick_Shield_Example.zip

Exibições: 11910

Comentar

Você precisa ser um membro de Laboratorio de Garagem (arduino, eletrônica, robotica, hacking) para adicionar comentários!

Entrar em Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)

Comentário de Thassilo Jahn em 2 julho 2013 às 21:20

Preciso de ajuda para utilizar o módulo joystick com o módulo bluetooth, alguém pode me ajudar?

 

Comentário de Marcos Vinícius Cândido em 9 dezembro 2012 às 9:17

Teria como colocar um tutorial do joystick controlado um motor de passo ou servomotor?Estou querendo fazer um braço mecânico com servomotor ou motor de passo e vou precisar de joystick.

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço