Help creating horizontal bar graph
Moderators: adafruit_support_bill, adafruit

Help creating horizontal bar graph

by the_prawn on Tue Nov 20, 2012 7:01 am

Hi all, I'm extremely new to programming and am fumbling my way through so far.
I purchased a Uno, breadboard and 16x2 RGB negative backlight LCD, as well as a MPX4250AP pressure sensor.
My goal is to build a boost sensor/gauge for the turbo on my car.
So far, I'm doing OK. I've got a pot hooked up in place of the actual sensor for testing but everything seems to be going as it should - keep in mind I'm cutting and pasting and modifying bits of code and trying to get them to work together.
On my top line I have a reading of boost pressure in PSI, calibrated to my location/altitude, starting from the left. I have a dividing line "|" at position 10 and after that I have the peak/max boost value stored (resets when engine/power off).
I also have the display set so that it changes colour when a critical boost (eg overboost) pressure is reached.
I'm pretty happy with all that so far!

Now, my problem is I would like a horizontal bar graph on the second line coming from the left side, just as a visual representation and just because I have an empty second line.
I'm able to write characters to the second line but not much else. So far I just have it displaying "bar graph here".

I've downloaded and installed the LCDBarGraph library from arduino.cc but am now at a loss as to how I code it to display my graph. I need to get it to read the pressure values from "analogue 0" where the sensor will be installed, then I assume I can use a pot to adjust and calibrate my graph to the pressure range I want? I've been searching for a week or so but am struggling to find appropriate code that I can modify to suit my needs and my skill is not up to making it from scratch yet.

Any help would be appreciated.
the_prawn
 
Posts: 3
Joined: Sat Sep 15, 2012 6:40 am

Re: Help creating horizontal bar graph

by the_prawn on Tue Nov 20, 2012 7:20 am

OK, I've inserted the following code into the void loop

lcd.setCursor(0,1);
lbg.drawValue( analogRead(sensorPin), 1024);

and now I get my bar graph but its on line one. Sad face.
the_prawn
 
Posts: 3
Joined: Sat Sep 15, 2012 6:40 am

Re: Help creating horizontal bar graph

by Arctic_Eddie on Tue Nov 20, 2012 9:42 am

The LCD row and column numbers start at 0. The columns will then have a range of 0-15 and the rows will be 0-1. To use the top row, set the cursor to 0,0. If the bar graph range is the same as columns then you will need to map the ADC range 0-1023 to the LCD range 0-15. It will be easier to just divide the ADC reading by 64 to keep the bar on the screen.

PS - It appears that the bargraph command already has the correct scaling built in to the library. See link in the following post.
Last edited by Arctic_Eddie on Tue Nov 20, 2012 10:06 am, edited 1 time in total.
Arctic_Eddie
 
Posts: 208
Joined: Tue Feb 28, 2012 6:01 pm
Location: St. Petersburg, FL

Re: Help creating horizontal bar graph

by Arctic_Eddie on Tue Nov 20, 2012 10:04 am

Arctic_Eddie
 
Posts: 208
Joined: Tue Feb 28, 2012 6:01 pm
Location: St. Petersburg, FL

Re: Help creating horizontal bar graph

by the_prawn on Tue Nov 20, 2012 8:17 pm

Cheers Eddie, I had seen that blog before but missed the part where he edited the library to set the graph on line 2.

Problem solved, thanks for your help.
the_prawn
 
Posts: 3
Joined: Sat Sep 15, 2012 6:40 am