Wa Koodu

Koodu Arduino lati lo joystick XY oni-apa meji pẹlu iboju LCD Nokia 5110

Koodu Arduino lati lo joystick XY oni-apa meji pẹlu iboju LCD Nokia 5110

Àkọ́kọ́tún yìí yóò ṣe ìtọ́sọ́nà rẹ nínú ìlànà lílo joystick XY oní-ẹ̀yà méjì láti ṣàkóso àmì tí a fihan lórí iboju LCD Nokia 5110. Iṣẹ́ àṣefihàn yìí ní kíkà ipò joystick àti mímú àtúnṣe iboju náà. Ní ìparí ìtọ́sọ́nà yìí, ìwọ yóò ní ètò tí ó ṣiṣẹ́ níbi tí gbígbé joystick yóò ti yí ipò àmì padà lórí iboju (nínú fídíò ní 00:00).

Nokia 5110_LCD

Nínú iṣẹ́ àṣefihàn yìí, ìwọ yóò lo àwọn àbájáde analog ti joystick láti pinnu ipò rẹ̀ lórí àwọn ẹ̀yà X àti Y. Àwọn ìwé kíkà láti joystick yóò jẹ́ fífà sí àwọn iwọn iboju LCD, tí yóò gbà fún gbígbé àmì náà ní ìrọ̀rùn. Ní àfikún, ìwọ yóò kọ́ bí a ṣe ń ka ìfisílẹ̀ joystick, èyí tí a lè lò fún àwọn ìbáṣepọ̀ síwájú síi.

Ohun èlò Tí A Ṣàlàyé

Àwọn èròjà pàtàkì fún iṣẹ́ àṣefihàn yìí ni Arduino, joystick XY oní-ẹ̀yà méjì, àti iboju LCD Nokia 5110. Arduino ṣiṣẹ́ gẹ́gẹ́ bí olùdarí micro, tí ń ṣiṣẹ́ lórí àwọn ìfisílẹ̀ láti joystick àti ṣíṣàkóso iboju LCD.

Joystick náà ní àwọn potentiometer méjì—ọ̀kan fún ẹ̀yà X àti ọ̀kan fún ẹ̀yà Y. Bí o ṣe ń gbé joystick, àwọn pots wọ̀nyí yóò yí resistance padà, tí wọn yóò rán àwọn ipele foltiage tí ó yàtọ̀ sí àwọn pinni ìfisílẹ̀ analog ti Arduino. Iboju LCD Nokia 5110 ni a ń ṣàkóso nípasẹ̀ ìbánisọ̀rọ̀ SPI, èyí tí ó gbà fún gbígbé data àti àtúnṣe iboju ní ìmúyọ́.

Àwọn Àlàyé Datasheet

OlùṣelọpọTexas Instruments
Nọ́mbà apáL293D
Foltiage Logic/IO5 V
Foltiage ìpèsè4.5–36 V
Ìwọ̀n àbájáde (fún ikanni)600 mA
Ìwọ̀n tí ó ga jùlọ (fún ikanni)1.2 A
Ìtọ́sọ́nà ìgbohùnsáfẹ́fẹ́ PWM20 kHz
Àwọn ìpele ìfisílẹ̀ logicTTL compatible
Ìrẹwẹ́si foltiage / RDS(on) / saturation1.5 V max
Àwọn ìwọ̀n ooru150 °C
ÀpótíDIP-16
Àwọn àkíyèsí / àwọn oríṣiWọ́n ń lò ó lọ́pọ̀lọpọ̀ nínú àwọn ohun èlò awakọ̀ motor

  • Rí i dájú pé o ṣe heat-sinking tí ó tọ́ fún iṣẹ́ tí ń lọ lọ́wọ́.
  • Lo àwọn capacitors decoupling fún ìpèsè agbára tí ó dúró ṣinṣin.
  • Ṣàyẹ̀wò àwọn ìwọ̀n foltiage láti yẹra fún bí bàjẹ́ àwọn èròjà.
  • Ṣọ́ra pẹ̀lú àwọn àmì PWM; rí i dájú pé wọ́n wà nínú àwọn ìwọ̀n tí a sọ̀ kalẹ̀.
  • Ṣàyẹ̀wò àwọn ìsopọ̀ waya láti yẹra fún àwọn ìsopọ̀ kúkúrú.

Àwọn Ìtọ́sọ́nà Wiring

Arduino wiring for Nokia 5110 LCD  with Joystick
Arduino wiring for Nokia 5110 LCD with Joystick

Láti sopọ̀ joystick àti iboju LCD sí Arduino, bẹ̀rẹ̀ nípa sísopọ̀ pinni VCC ti joystick sí 5V ti Arduino àti pinni GND sí GND ti Arduino. Sopọ̀ àbájáde ẹ̀yà X ti joystick sí pinni analog A0 àti àbájáde ẹ̀yà Y sí pinni analog A1. Àbájáde ìfisílẹ̀ joystick yẹ kí a sopọ̀ sí pinni oní nọ́mbà 2.

Fún iboju LCD Nokia 5110, sopọ̀ àwọn pinni wọ̀nyí: VCC sí 5V, GND sí GND, SCE sí pinni 7, RST sí pinni 6, D/C sí pinni 5, DN(MOSI) sí pinni 11, àti SCLK sí pinni 13. Ní ìparí, sopọ̀ pinni LED nípasẹ̀ resistor 330 Ohm sí pinni 9 fún ìṣàkóso ìmọ́lẹ̀ ẹ̀yìn.

Àwọn Àpẹẹrẹ Kóòdù & Ìtọ́sọ́nà

Nínú iṣẹ́ ìṣètò, a bẹ̀rẹ̀ ìbánisọ̀rọ̀ serial àti LCD. Àṣẹ lcdBegin() ṣètò àwọn pinni àti bẹ̀rẹ̀ iboju náà. A ṣètò ìyàtọ̀ fún ìríran tí ó dára jùlọ.

void setup() {
  Serial.begin(9600);
  lcdBegin(); 
  setContrast(40); 
  delay(1000);
  clearDisplay(BLACK);
  updateDisplay();
}

Èyí bẹ̀rẹ̀ àwọn èròjà pàtàkì fún iṣẹ́ àṣefihàn yìí, tí ó rí i dájú pé iboju LCD ti ṣetán láti fi àlàyé hàn.

Nokia 5110_LCD back view

Nínú iṣẹ́ loop, a ka ipò joystick àti fà á sí àwọn iwọn iboju. A mú ipò àmì náà ṣe àtúnṣe nípa lílo àwọn iye X àti Y ti joystick.

void loop() {
  int x = analogRead(A0); // ka ipò x ti joystick
  int y = analogRead(A1); // ka ipò y ti joystick
  int xPos = map(x, 0, 1023, 0, screenWidth); // fà x sí iboju
  int yPos = map(y, 0, 1023, 0, screenHeight); // fà y sí iboju
  setCircle(xPos, yPos, thickness, BLACK, 2); // fi àmì náà hàn
  updateDisplay();
  delay(10);
}

Kóòdù yìí ń mú ipò àmì náà ṣe àtúnṣe lórí LCD ní ìgbà gbogbo nípa lílo gbígbé joystick.

Ìfihàn / Ohun Tí O Yẹ Kí O Rí

Nígbà tí o bá tan ètò náà, LCD yóò fi àmì kan hàn. Gbígbé joystick yóò yí ipò àmì náà padà ní àkókò gidi nípa lílo àwọn gbígbé X àti Y ti joystick. Bí a bá tẹ ìfisílẹ̀ joystick, ó lè mú àwọn iṣẹ́ àfikún tí o lè ṣe àmúlò wá. Ṣọ́ra fún àwọn ìfisílẹ̀ tí ń fò fún ìgbà kan bí joystick kò bá wà ní àárín, èyí tí ó lè yọrí sí gbígbé àmì náà láìretí (nínú fídíò ní 01:30).

Àwọn Àkókò Fídíò

  • 00:00 - Ìfihàn sí iṣẹ́ àṣefihàn yìí
  • 01:30 - Àlàyé wiring
  • 02:45 - Ìtọ́sọ́nà kóòdù
  • 04:10 - Ìfihàn iṣẹ́ tí ó ń ṣiṣẹ́

Aworan

Nokia 5110_LCD back view
Nokia 5110_LCD back view
Arduino wiring for Nokia 5110 LCD  with Joystick
Arduino wiring for Nokia 5110 LCD with Joystick
Nokia 5110_LCD
Nokia 5110_LCD
81-Arduino code: Dual-axis joystick with Nokia 5110 screen to display dots
Ede: C++
/*
 * This is Arduino code to use a dual-axis XY joystick with a Nokia 5110 screen to move a dot on the screen.
 * It also reads the switch.
 * Other Arduino libraries and videos: https://robojax.com
 
 * Watch the video for this code to learn it fully.
  * Watch the video here: https://youtu.be/zqDZybR5JSE
 * This code is offered "as is" without any warranty.
 * If you are sharing this code, you must keep this copyright note.
 */
 /*
/* Nokia 5100 LCD Example Code with Added Joystick by Robojax
   Graphics driver and PCD8544 interface code for SparkFun's
   84x48 Graphic LCD.
   https://www.sparkfun.com/products/10168
   Original source code:
https://github.com/sparkfun/GraphicLCD_Nokia_5110

  This stuff could all be put into a library, but we wanted to
  leave it all in one sketch to keep it as transparent as possible.

  Hardware: (Note most of these pins can be swapped)
    Graphic LCD Pin ---------- Arduino Pin
       1-VCC       ----------------  5V
       2-GND       ----------------  GND
       3-SCE       ----------------  7
       4-RST       ----------------  6
       5-D/C       ----------------  5
       6-DN(MOSI)  ----------------  11
       7-SCLK      ----------------  13
       8-LED       - 330 Ohm res --  9
   The SCLK, DN(MOSI), must remain where they are, but the other 
   pins can be swapped. The LED pin should remain a PWM-capable
   pin. Don't forget to stick a current-limiting resistor in line
   between the LCD's LED pin and Arduino pin 9!
   Modified by Ahmad S. for Robojax.com
   on Mar 11, 2018 at 20:49 at Ajax, Ontario, Canada
*/
#include <SPI.h>
#include "LCD_Functions.h"

#define sw 2 // pint 2 is used for joystick switch input
#define screenWidth 83 // NOkia screen width
#define screenHeight 47 // Nokia screen height
int thickness =1;// the thickness of the dot


void setup()
{
  // Robojax Dual Axis joystick  with Nokia 5110 LCD screen project
  Serial.begin(9600);

  lcdBegin(); // This will setup our pins, and initialize the LCD
  //updateDisplay(); // with displayMap untouched, SFE logo
  setContrast(40); // Good values range from 40-60
  delay(1000);

  clearDisplay(BLACK);
  updateDisplay();
}


void loop()
{
  clearDisplay(WHITE);  
   // Robojax Dual Axis joystick  with Nokia 5110 LCD screen project
  int x = analogRead(A0);// read the x position of joystick
  int y = analogRead(A1); // read the y position of joystick
  int xPos = map(x, 0, 1023,0,screenWidth);// map or translate the x of joystick to x of screen
  int yPos = map(y, 0, 1023,0,screenHeight); // map or translate the y of joystick to y of screen
  int sStat = digitalRead(sw);//read the switch from pin 2
  Serial.print("X: ");
  Serial.print(xPos);
  Serial.print(" Y: ");
  Serial.println(yPos);// Robojax prints y

  // Robojax Dual Axis joystick  with Nokia 5110 LCD screen project
   //setCircle(xPos, yPos, thicness, BLACK, 2);
   // xPos is the position of x
   // yPos is the position of y
   // thickness
  setCircle(xPos, yPos, thickness, BLACK, 2);// display the dot on the screen
    updateDisplay();
  delay(10);


}

Ohun ti o le nilo

Orisun & itọkasi

Ko si awọn orisun sibẹsibẹ.

Fáìlìs📁

Faili ti a beere (.h)

Fayile Fritzing