Thursday, May 21, 2015

Addicore Joystick with Push Button

Here is a nice little joystick from Addicore with push button action.  It's easy to use on the MSP430F5529LP.  It uses dual potentiometers for the x and y axis.  Note that there is a commented out line that you can use if desired to change the numeric value for the y axis so that zero voltage is down instead of up.  The x axis goes from zero at left to 4095 at right.  The F5529 has analog resolution of 4096 - you will need to change this to 1023 for Arduino or lower resolution MSP430s.



The Energia sketch below demonstrates how it works.

 /*
 Read Joystick and Push Button - display to Serial Monitor
 Tested with MSP540F5529LP
 Addicore joystick with push button
 https://www.addicore.com/Dual-Axis-XY-Joystick-Module-with-Push-Button-p/139.htm

 F. Milburn 5/19/2015

 Joystick  MSP430F5529LP
 --------  -------------
 GND       GND
 +5V       3V3
 VRX       P6.0
 VRY       P6.1
 SW        P3.4

 */

 int xPin = P6_0;           // x direction potentiometer pin
 int yPin = P6_1;           // y direction potentiometer pin
 int pushPin = P3_4;        // Push button pin
 int xValue = 0;            // x direction potentiometer value (0 to 4095)
 int yValue = 0;            // y direction potentiometer value (0 to 4095)
 int pushState = 0;         // Push button state (0 or 1)

 void setup()
 {
   Serial.begin(9600);
   Serial.println("Starting...");
   pinMode(pushPin, INPUT_PULLUP);
 }

 void loop()
 {
   // Read joystick position
   xValue = analogRead(xPin);         // Read x     (x0 left)
   yValue = analogRead(yPin);         // Read y     (y0 top)
   // yValue = abs(4095 - yValue);    // Reverse y direction  
  
   Serial.print("X = ");
   Serial.print(xValue);
   Serial.print("   ");
   Serial.print("Y = ");
   Serial.print(yValue);
   Serial.print("   ");
  
   // Read button status
   pushState = digitalRead(pushPin);  // See if joystick has been pushed in
  
   Serial.print("Joystick is ");
   if (pushState == 0)
   {
     Serial.println("pushed in");
   }
   else
   {
     Serial.println("not pushed");
   }
  
   delay(200); 
 }

Addicore 20 x 4 Serial LCD using I2C and BS170 MOSFETs

This is a very nice 20 column, 4 line display from Addicore - big and easy to read.  I've ordered several things from them recently and have been pleased.  They have free mailing in the U.S. for orders over $25 and are quick and responsive.  Recommended....

Here is what it looks like when up and running on the MSP430F5529 LaunchPad.



Note that this is a 5V device!  I've translated signals using BS170 MOSFETs and the following circuit.



I got it up and running easily using a library from DFRobot.

Here is the test code running in the display above.

//Using library from DFRobot.com
//Compatible with the Arduino IDE 1.0
//Library version:1.1
/*
 * 20x4 Serial LCD from Addicore
 * https://www.addicore.com/2004-20x4-Character-LCD-with-I2C-backpack-p/157.htm
 * Tested on MSP430F5529LP
 * NOTE: This is a 5V device!
 * Need to translate 3V3 <---> 5V (used two BS170 MOSFETs)
 * F Milburn   21 May 2015
*/
#include <Wire.h>
#include "LiquidCrystal_I2C.h"

LiquidCrystal_I2C lcd(0x27,20,4);  // set for a 20 character 4 line display

void setup()
{
  lcd.init();                      // initialize the lcd
  // LINE 0
  // Print a message to the LCD.
  lcd.backlight();
  lcd.print("First line");
}

void loop()
{
  // LINE 1 - Number of columns
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  lcd.print("Second line");
 
  // LINE 2 - ENERGIA
  lcd.setCursor(0, 2);
  lcd.print("Third line");
 
  // LINE 3 - Count seconds
  lcd.setCursor(0, 3);
  lcd.print("Time since reset:");
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}