Offline
Newbie
Karma: 0
Posts: 8
|
 |
« on: November 20, 2012, 08:30:22 am » |
Hi, I hooked 3 pots(100k each) to pins (A0, A1, A2) in my Arduino UNO (Rev 3). I want to map() each pot value to a LCD. I'm using the 3-wire (595 shift register) with the lcd. The problem is I got very messy readings from the pots. Sometimes in the middle position of pot A1 the LCD is showing 987...I never get 0 - 255 exactly. Here part of my code void loop () { iLCD.home (); currentColorValueRed = analogRead(redPotPin); delay(2); currentColorValueBlue = analogRead(bluePotPin); delay(2); currentColorValueGreen = analogRead(greenPotPin); delay(2); iLCD.print("R:"); iLCD.print(map(currentColorValueRed, 0, 1023, 0, 255 )); iLCD.setCursor(5, 0); iLCD.print("G:"); iLCD.print(map(currentColorValueGreen, 0, 1023, 0, 255 )); iLCD.setCursor(10, 0); iLCD.print("B:"); iLCD.print(map(currentColorValueBlue, 0, 1023, 0, 255 )); }
|
|
|
|
|
Logged
|
|
|
|
|
Yorkshire England
Offline
Sr. Member
Karma: 1
Posts: 253
Arduino good init
|
 |
« Reply #1 on: November 20, 2012, 08:44:26 am » |
You need to look at smoothing the value. Check the Arduino web site for examples. Basically to take a certain number of samples and then average them. Not sure how many you need. Fewer will be quicker but less actuate and more will be slower and more accurate. It doesn't matter to much about that for most applications i've had 8/10.. more pots connected to an Uno using multiplexing and smoothing with no real noticeable delay.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #2 on: November 20, 2012, 08:58:46 am » |
You need to look at smoothing the value. Check the Arduino web site for examples. Basically to take a certain number of samples and then average them. Not sure how many you need. Fewer will be quicker but less actuate and more will be slower and more accurate. It doesn't matter to much about that for most applications i've had 8/10.. more pots connected to an Uno using multiplexing and smoothing with no real noticeable delay.
I'd like to use 0-255 range since my goal is to control a RGB LED. (each pot corresponds to a color value R, G, B). The strange behavior is getting 001 or 0041 instead of 0 or random numbers wher it shoulbe be 255... Maybe it's a LCD problem since it print 789 or 999 that's a value out of the map() range??
|
|
|
|
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 279
Posts: 15314
Measurement changes behavior
|
 |
« Reply #3 on: November 20, 2012, 09:16:02 am » |
One thing you could change is your pot values. Arduino analog input pins are designed to be driven by a source resistance of 10,000 ohms or less. Your 100K ohm pots are sure to give unstable conversation values.
Lefty
|
|
|
|
|
Logged
|
|
|
|
|
Norfolk UK
Offline
Edison Member
Karma: 23
Posts: 1320
|
 |
« Reply #4 on: November 20, 2012, 09:40:28 am » |
Could it be something as simple as LCD artefacts? Your using setCursor to set print position so if the first value printed is 129 and the second value printed is 55 then the 9 on the end of 129 will be appended to 55 making 559.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 4
|
 |
« Reply #5 on: November 20, 2012, 11:33:02 am » |
Smaller value pots are probably a good idea, better exchange them for 10k what kind of pot are you using? wirewound potmeters have a very rough (stepwise) resolution, which could also give problems. For very smooth control better use cermet or even better plastic film potentiometers http://www.resistorguide.com/potentiometer/
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Edison Member
Karma: 114
Posts: 2205
|
 |
« Reply #6 on: November 20, 2012, 11:40:32 am » |
If you are not looking for fast transients from the pot, put a small capacitor, like 1n - 11n, on the wiper / adc pin. It will help alleviate charge transfer when high output impedance is involved.
Also, slowing down the adc is helpful too.
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 88
Posts: 9392
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #7 on: November 20, 2012, 01:25:48 pm » |
bad connections between pot arduino gnd and 5V ? seen them before
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #8 on: November 20, 2012, 02:01:07 pm » |
Solved! Thank's all for the help... I changed the 3 pot to 10k and rewrite my code... char buffer[16]="";
void setup ( ) { iLCD.begin ( 16, 2 );
}
void loop () { iLCD.home (); currentColorValueRed = (255 - map(analogRead(redPotPin), 0, 1023, 0, 255 )); delay(1); currentColorValueGreen = (255 - map(analogRead(greenPotPin), 0, 1023, 0, 255 )); delay(1); currentColorValueBlue = (255 - map(analogRead(bluePotPin), 0, 1023, 0, 255 )); delay(1); sprintf(buffer, "R:%3dG:%3dB:%3d", currentColorValueRed, currentColorValueGreen, currentColorValueBlue); iLCD.print(buffer); }
|
|
|
|
|
Logged
|
|
|
|
|
Netherlands
Offline
Tesla Member
Karma: 88
Posts: 9392
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #9 on: November 20, 2012, 04:20:18 pm » |
why currentColorValueRed = (255 - map(analogRead(redPotPin), 0, 1023, 0, 255 ));
and not
currentColorValueRed = analogRead(redPotPin) /4; // works almost the same (only inverted)
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 8
|
 |
« Reply #10 on: November 20, 2012, 05:20:41 pm » |
why currentColorValueRed = (255 - map(analogRead(redPotPin), 0, 1023, 0, 255 ));
and not
currentColorValueRed = analogRead(redPotPin) /4; // works almost the same (only inverted)
I figured that was the way to reverse the value...I'll try your way to test...
|
|
|
|
|
Logged
|
|
|
|
|
0
Online
Tesla Member
Karma: 71
Posts: 6611
Arduino rocks
|
 |
« Reply #11 on: November 20, 2012, 05:50:59 pm » |
Smaller value pots are probably a good idea, better exchange them for 10k what kind of pot are you using? wirewound potmeters have a very rough (stepwise) resolution, which could also give problems. For very smooth control better use cermet or even better plastic film potentiometers http://www.resistorguide.com/potentiometer/High value pots are not a problem if you add a 0.1uF capacitor to ground from the wiper - this will stiffen up the output and kill noise and allow reliable conversion.
|
|
|
|
|
Logged
|
|
|
|
|
|