Arduino LCD and Potentiometer Writing

Post here to discuss all things Arduino!

Moderators: Chuckt, Garth, bitfogav

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Arduino LCD and Potentiometer Writing

Post by Saimaster13 » Wed Sep 12, 2012 4:48 am

I had this idea, and it would eventually be integrated into a bigger project:

What if one hooked up 26 buttons (for 26 letters) with a different resistor value for each and make a voltage divider, each button having a different value?

Better yet, hook up 1 potentiometer instead of the 26 buttons, and it could be rotated to select each letter. Also wouldn't be bad to add a space and maybe some characters (such as !?.$) in there.

Then hook it up to a LCD, rotate the potentiometer to the desired letter or character, which the LCD screen shows which character is currently selected
(such as: |a | then move the potentiometer one letter: |b | another: |c | )

Press a select button, and it would lock that character in and move to the next.
(start with |c | press select: |cc | then you could move the second letter: |cd | again: |ce | )


The problem with this idea: I do not know how to code it.
Anyone have any ideas on how you could code it? Especially how the analog input could change something on the LCD, and lock it in, and go to the next space on the LCD?
Joshua

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Arduino LCD and Potentiometer Writing

Post by bitfogav » Wed Sep 12, 2012 6:55 am

We could do this quite easy with Swordfish Basic, I'm abit rusty when it comes to Arduino.

What you could start with is looking up ADC (reading Analog), if you look at the link you will see that reading from the ADC pin we can get a value between 0-1023, the value that we get will depend on the position of the POT.

We then could use a Switch Case Statement to allow us to compare the value from the ADC pin.

And then we could use the LCD Library to send what data we want to the LCD. Obviously theres going to be some little things we will have to do inbetween and setup a button :)
Saimaster13 wrote:The problem with this idea: I do not know how to code it.
When you say you dont know how to code it? do you have any knowledge of Arduino or any programming language?.
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by Saimaster13 » Wed Sep 12, 2012 10:35 am

I have very little programming experience, I am in the process of learning in between school, projects, and everything else.

But no, I don't know any arduino programming other than if statements, making digital pins inputs or outputs, and the blink program.
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by brad » Wed Sep 12, 2012 12:31 pm

I'm off to work but will come back and check this post and read it properly later.

You can certainly use an ADC (10-bits for most pic devices) giving you 1024 combinations, that means you could have one pot and rotate it through one end to the other and you would get 1024 different combinations! 00000000 to 11111111

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Arduino LCD and Potentiometer Writing

Post by bitfogav » Wed Sep 12, 2012 7:35 pm

I think you ment 0000000000 to 1111111111 Brad? 10bit ADC :)
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by brad » Thu Sep 13, 2012 12:01 am

I was in a rush and am so used to using 8-bits!

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Arduino LCD and Potentiometer Writing

Post by bitfogav » Thu Sep 13, 2012 6:11 am

Too read anolog pin using a POT, this bit of code would take care of that.

Pot connected to A0 pin

Code: Select all

int sensorPin = A0;    // input pin for the pot
int potValue = 0;      // variable to store the value from the pot 

void loop() {
  // read the value from the pot:
  potValue = analogRead(sensorPin);                    
}
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by Saimaster13 » Thu Sep 13, 2012 11:39 am

I have not had time to test the code yet... and thanks bitfogav for the analog code!

Code: Select all

Code removed due to bad coding.
See later posts for working code.
Last edited by Saimaster13 on Fri Sep 14, 2012 11:58 am, edited 1 time in total.
Joshua

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Arduino LCD and Potentiometer Writing

Post by bitfogav » Fri Sep 14, 2012 2:45 am

Nice to see some code Joshua, let us know how the testing goes? :)
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by Saimaster13 » Fri Sep 14, 2012 6:09 am

Will do when I test it, been sick and busy lately.
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by brad » Fri Sep 14, 2012 9:10 am

Have you thought about putting all those characters and then just calling them?

for example in psuedo code you would have

chartable "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
lcd.print = chartable(analogread)


I haven't looked into how to do it with arduino exactly, but as you vary the analog value, you would call a different character from the table. If the analog value was 0 it would call position 0 from the table which is the letter a. and so on.

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by Saimaster13 » Fri Sep 14, 2012 10:36 am

Nope, haven't even heard of that Brad, I'm definitively going to look into it though! Anyway, the last code sucked, but this works!

Arduino pin 7 is pulled down with a 10k resistor and is attached to a button to +5v.
Arduino analog pin A0 is connected to the middle of a 10k potentiometer one side is connected to ground and the other +5v.
The rest of the pins are connected to a 16x2 LCD like an Arduino normally is.
How to hook up an Arduino to a LCD: Arduino LCD page

Code: Select all

Code was further condensed. See later posts.
Last edited by Saimaster13 on Fri Sep 14, 2012 3:44 pm, edited 1 time in total.
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by Saimaster13 » Fri Sep 14, 2012 12:29 pm

Pictures:

Image

Image
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by Saimaster13 » Fri Sep 14, 2012 3:46 pm

Updated codes: One with a full explanation and one condensed, hopefully suited to be included in a bigger project.

Full Explanation:

Code: Select all




#include <LiquidCrystal.h>  // include the LCD library

char Str2[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?@'_ "; //Potentiometer characters, in order

int basePot = 32;      // Dividing the potentiometer values into 32 different options to allow for 32 different characters (1024/32=32)
int sensorPin = A0;    // input pin for the Potentiometer voltage divider and character selector (connect one outside pin to ground, other outside to +5V, middle pin to A0)
int potValue = 0;      // variable to store the value from the potentiometer character selector

char var;  //Stores the character selector potentiometer's character


char Str1[18] = "_________________"; //what begins at the top row of the LCD when the code starts, this string also defines each of the columns of the top row of the LCD, 
                                     //displaying the corresponding character defined by when each string element is set to the var character with the "next" button
                                     //(when the "next" button is pressed, the corresponding Str1 number is set to the character select potentiometer) 

int next = 7;    //The "next" button pin, the button that writes the characters to the LCD and moves onto the next one. Pin 7 (or whatever you changed "next" to)should
                 //have a 10k pulldown resistor to ground and also be connected to a button that supplies pin 7 (or the "next" pin) with +5V.
                 
int nextState = 0;  //Stores the state of the "next" variable, whether it is HIGH or LOW

int nextStateAdd = 0; //makes so next has 17 different possitions, or 0 to 16




LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // LCD Pins: RS=12, Enable=11, D4=5, D5=4, D6=3, D7=2
                                       // Note: Connect a voltage divider 10k potentiometer to V0 (one outside pin to ground, other outside to +5V, middle pin to V0)
                                       // Also connect VSS and RW to ground and VDD to +5v





void setup(){ 
  pinMode(next, INPUT); //Sets the "enter" pin, or button, as an input
 
 
  lcd.begin(16, 2); //defines the amount of rows and columns that the LCD has
  
  lcd.setCursor(3,1);      //sets the LCD screen to column 4, row 2      
lcd.print("receiving...");  //and writes "receiving..." at that location

  lcd.setCursor(0,0);      //sets the LCD screen to column 0, row 0      
lcd.print("________________");  //and writes "________________" across the whole top row

}

void loop() {
  
   
  potValue = analogRead(sensorPin);     //Sets the variable potValue to take on the value of the character select potentiometer, ranging from 0 to 1023
  
   lcd.setCursor(0, 1);   //Sets the LCD to the first column, second row
lcd.print(var);           //writes the character of the character select potentiometer to the LCD (var has the character of the potentiometer)
  
 nextState = digitalRead(next);  //Sets the variable "nextState" to record whether the "next" pin, or button, is HIGH or LOW
  
  
  
   if(nextState==1){nextStateAdd++;  //if the "next" pin, or button, is HIGH then run the following code and add 1 to the variable "nextStateAdd" 
                                     //(nextStateAdd allows the next button to have 17 possitions, 1 to 16)
                                     
for(int x = 1; x<17; x++){              //x starts at 1 and runs through the following code each time and adds 1 to x until x is no longer less than 17
                                        //(x goes through the code starting at 1, and each time it runs through the code 1 is added to x until x has run through the code as 16)
 if (nextStateAdd==x){Str1[x] = var;}          //The LCD column position's character equalling the "next" button's "position" (or nextStateAdd) is defined by
}                                              //the character select potentiometer's current character (defined by var). This code runs through all 16 characters to get the right one.
                                              
 if (nextStateAdd==17){nextStateAdd = 0;     //if the "next" button position, or nextStateAnd is 17, set it to 0 and
 for(int y = 1; y < 17; y++){                //clear the top row of the LCD (all underscores)
Str1[y] = '_';}
 }                                   
 
 
 for(int z = 1; z < 17; z++){
  lcd.setCursor(z-1, 0);          //write the display characters, defined by Str1[1-16], to the LCD
lcd.print(Str1[z]);
 }
 
 
   if (nextStateAdd==16){          
  lcd.setCursor(3,1);               //when all characters on the LCD have been defined, write "Done!" to the display and wait for 1 second.
lcd.print("Done!        ");       
delay(1000);
}

    if (nextStateAdd==0){
  lcd.setCursor(3,1);              //If all the characters have not been difined write "receiving..." to the display.
lcd.print("receiving...");         //this is written when the "position" of the "next" button (nextStateAnd) goes to 0
    }
  
 
 
  delay(500);}       //Amount of time between button presses. If the "next" button is HIGH when delay ends, the next LCD character will be defined.
  


                                                     //This for loop defines the characters of thee Potentiometer
for(int q = 0; q < 32; q++){                         //32 Different characters
if (potValue>=q*basePot && potValue<(1+q)*basePot)  //Potentiometer characters are Str[2]
{var = Str2[q];}                                    //var is defined as the current character of the Potentiometer


}}

Condensed:

Code: Select all

#include <LiquidCrystal.h>
int potValue = 0;
char var;
int nextState = 0;
int nextStateAdd = 0;

char Str2[33] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?@'_ "; //set characters of Potentiometer
int basePot = 32; //set amount of characters (use formula: 1024/number of characters wanted=x) (be sure to change the character "for" loop)
 char Str1[18] = "_________________"; //define what the LCD Displays on startup
 
int sensorPin = A0; //Potentiometer pin
int next = 7;   //next pin
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //defines LCD pins (RS, Enable, D4, D5, D6, D7)


void setup(){ 
  pinMode(next, INPUT);
 
lcd.begin(16, 2); //Define LCD rows and Columns
  
  lcd.setCursor(3,1); //set where to display starting message
lcd.print("receiving..."); //set starting message
lcd.setCursor(0,0); //set where to display starting characters
  lcd.print("________________"); //set what top row starts at
}

void loop() {
  potValue = analogRead(sensorPin);
lcd.setCursor(0, 1);   //Set where to display var
lcd.print(var);
nextState = digitalRead(next);
if(nextState==1){nextStateAdd++;
for(int x = 1; x<17; x++){  //set amount of LCD characters (must correspond with Str1)
if (nextStateAdd==x){Str1[x] = var;}
if (nextStateAdd==17){nextStateAdd = 0; //set amount of LCD characters (must correspond with Str1)
 for(int y = 1; y < 17; y++){ //set amount of LCD characters (must correspond with Str1)
Str1[y] = '_';}}  //set what character the LCD resets to
lcd.setCursor(x-1, 0);
lcd.print(Str1[x]);}
if (nextStateAdd==16){  //set amount of LCD characters (must correspond with Str1)
  lcd.setCursor(3,1); //set where to put finished message
lcd.print("Done!        "); //set finished message
delay(1000);} //set delay when finished
if (nextStateAdd==0){
  lcd.setCursor(3,1); //set where to put in progress message
lcd.print("receiving...");} //set progress message
  delay(500);} //set delay after each next press
for(int q = 0; q < 32; q++){ //set number of different potentiometer characters                        
if (potValue>=q*basePot && potValue<(1+q)*basePot)
{var = Str2[q];}}}
Last edited by Saimaster13 on Sat Sep 15, 2012 10:36 am, edited 2 times in total.
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: Arduino LCD and Potentiometer Writing

Post by brad » Sat Sep 15, 2012 9:18 am

Nice work!

Thanks for posting the pics too - it's always great to see someones project in action :)

How long where you working on it for? Any chance of youtube video clip?

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 11 guests