JOS – Open Source Menu Interface for Arduino/TFTLCD

***UPDATE*** There is updated code that works with the current Adafruit libraries! New post is here. 🙂

So I ordered a 2.8″ TFTLCD with touchscreen from Adafruit and really wanted to do more than 1 “screenfull” of stuff. So I stayed up all night and wrote this. Now I want to share it. I was waiting to post this until I got my code a little cleaned up and put in a good number of comments. My code might not be as optimal as it could be, so go easy on me, I’m still a newbie..

Here is a video about what this does.

And here is a video about the code.

JOS stands for Jeremy’s Operating System and is open source. I encourage you to use it, hack it, and do what ever you want with it. I know some might say “it’s not an operating system!” I know, but it’s just a name. It is based on Lady Ada’s TFTLCD and TouchScreen libraries. It shares some of the code from Lady Ada’s tftpaint sketch found in the TFTLCD library. It is written in the Arduino IDE and works perfect with the 2.8″ TFTLCD breakout board and the Touch Shield. This version does not support and SD card/bitmap functions as I do not have a touch shield yet. I will write these in when I get a Touch shield some day.

Here is a feature List:

Menu driven button screens

5 different menu screens, 6 buttons per screen for a total of 30 separate functions

Customizable title bar for indicators, custom icons and titles

Easily adjustable dual color signal indicator (for wireless application) for the title bar

Home icon for easy navigation

Dedicated message box for notifications

PWM controlled adjustable backlight

Settings menu with adjustable sleep time and backlight

Sleep and backlight settings saved in EEPROM – retains settings after power down

Sleep mode, for backlight, including fade in from sleep  and fade out to sleep

Template for 3rd adjustable item on settings menu

Dual color battery icon with active and adjustable monitoring

LED output for button press indication – adjustable or removable

2 LED outputs for indication – adjustable or removable

All LED activity used only 2 pins

pins 0 and 1 not used and reserved for for serial communication

pins 11, A0, A1, A4, A5 open for I/O

Code is commented to explain function

Hardware Wiring: The same wiring as found in the Adafruit TFTLCD tutorial here.

ATmega328 Pins and Arduino pins:

(2) 0: N/C (open for communication)

(3) 1: N/C (open for communication)

(4) 2: data 2

(5) 3: data 3

(6) 4: data 4

(11) 5: data 5

(12) 6: data 6

(13) 7: data 7

(14) 8: data 0 && X+

(15) 9: data 1 && Y-

(16) 10: backlight

(17) 11: N/C

(18) 12: red LED

(19) 13: green LED

(23) 14(A0): N/C

(24) 15(A1): N/C

(25) 16(A2): X-

(26) 17(A3): Y+

(27) 18(A4): N/C

(28) 19(A5): N/C

(1) Reset: LCD Reset

You can download the code here. (Arduino 22 .pde file)

 

33 thoughts on “JOS – Open Source Menu Interface for Arduino/TFTLCD

  1. Hi,

    Very nice work !

    If have a few questions about your battery status. I see that you use the “Secret Voltmeter” hidden in the 328 chips. If you use this on an arduino, what do you actually measure ? The output of the 5V regulator, right ? Or the 5V coming from the USB cable if you use one ?
    My goal is to use a little battery to power my Arduino and the touch shield. I’m not sure I can get the battery voltage directly, unless I power the whole Arduino from the battery, without going through the regulator. But in this case, can I power the Arduino by injecting 3.7V (or less, if battery is low) in 5V rail ?

    I would like to get your advice about this.

    Thanks !

    • Good question Simon, and thank for the complement! The “secret volt meter” that this code uses actually compares the 1.1 V internal reference to the incoming VCC, and then figures out VCC according to the known accurate 1.1 volt reference. So it’s actually measuring the supply voltage of the 328 itself, on the clean side of the regulator.
      I have powered many Arduino’s by injecting up to 5 volts (regulated) into the 5V pin on the Arduino, that will work without a problem, just make sure the voltage is regulated, because since you are applying voltage on the other side of the regulator, there is little room for error. If you are you are using a LI-Po or other battery, this should not be a problem at all. Hope your project turns out well!

      • Thank you for your fast answer !
        I’ll do some tests tomorrow (trying to run the arduino with 3-4V).
        I haven’t received the shield yet, and I’m not sure the screen can work with only 3.7V. Could you please test your JOS-hardware with one Lithium battery (so, 3.7V) if you have some spare time ?
        Thank you so much !

  2. Just tried powering an Arduino, 2.8″ Adafruit Touch Shield with a 3.7V 1000mAh Li-Po battery, and it worked like a charm, screen brightness was great. 🙂

  3. Jeremy,

    I would like to thank you soo much for sharing this! It has become the beginnings of a touch screen controller for my room!

    The only thing that I would suggest is that there be a check for the settings page, so if a value is not changed it does not write the eeprom. I have incorporated it into the version that I am using, and it works great! Here is the code:


    // home
    if (p.y > 280 && p.y 5 && p.x < 52) { // if the home icon is pressed if (page == 6) { // if you are leaving the settings page clearmessage(); // clear the battery voltage out of the message box int esleepeeprom; int blveeprom; esleepeeprom = EEPROM.read(1); blveeprom = EEPROM.read(2); if (esleep != esleepeeprom || blv != blveeprom) { EEPROM.write(1, esleep); // write the sleep value to EEPROM, so it will not lose settings without power EEPROM.write(2, blv); // write the backlight value to EEPROM, so it will not lose settings without power tft.drawString(12, 213, "Settings Saved", RED, 2); // display settings saved in message box } else { tft.drawString(12, 213, "No Changes Made", YELLOW, 2); } clearsettings(); // erase all the drawings on the settings page } if (page == 0) { // if you are already on the home page drawhomeiconred(); // draw the home icon red delay(250); // wait a bit drawhomeicon(); // draw the home icon back to white return; // if you were on the home page, stop. } else { // if you are not on the settings, home, or keyboard page page = prevpage; // a value to keep track of what WAS on the screen to redraw/erase only what needs to be page = 0; // make the current page home redraw(); // redraw the page } }

    I hope this displays right...

      • Take a look at my post below… I figured out (at least for the mega) why the touch shield wasn’t working…

        • And I see that you have that corrected in the beta… the beta still does, for me however, give the red screen of death. I copied over the ‘getBandgap’ part of a version of your code JOS TFT Touch Beta version v2.0 from sobisource.com and it solved that issue… Still getting the random green line in the door of the home icon and a freeze though.

      • Jeremy,

        I know this is old, but I just wanted to let you know that I am getting random lines on the rectangles using a touch shield. The battery fill, backlight fill and random others produce a vertical line as long as the object, pointing straight up.

        Have you figured out the problem/asked ladyada about it?

        Thanks!!

  4. Just tried to load your code. Came up with “TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);”
    ‘TouchScreen’ does not name a type.

    what does that mean? what have i done wrong? (which is almost nothing!)
    have i got wrong software version? i apperantly have the latest!

    • Hello, I believe the error you are getting is being generated by a missing “TouchScreen.h” file. I would double check the file to make sure it’s there, restart the Arduino IDE and try again.
      I have renamed my TouchScreen.h file and restarted the Arduino IDE and got the same error, so fixing this file should fix the problem. Hope this helps!

  5. I am able to get it to load, however, can’t press anything on the screen. I hooked it up just as adafruit did, and their paint sketch works just fine. I also noticed that the battery meter actually goes over the the other side of the status bar too, like its too long, as well.

    I’m using a UNO, any ideas?

  6. Jeremy,

    I’m having the same problem as Chris. I’m using the Arduino Uno and the touchscreen without the shield. The paint example works fine, but JOS program doesn’t recognize touch inputs. Any suggestions on how to fix this would be greatly appreciated.

  7. Jeremy,

    First off, EXCELLENT job at a menu based control system!!! I’d be SO lost without your code! Also, your comments are phenomenal! Nothing but great!

    So my equipment is as follows: Arduino Mega 2560 with touch shield from Adafruit.

    And my problems are as follows…
    -When I boot your program, the screen went red after the JOS logo screen. After looking closely, it seemed as if the battery fill was trying to fill the entire screen. I commented out any lines that drew the battery fill. Now, I get the full home screen, but no battery fill (obviously), so I’m sure thats where the whole thing is getting messed up. You said earlier that you don’t have a touch shield, so I’ll understand if you can’t help, but any pointers would be great!
    -I can’t use the touch function, but I’m still troubleshooting this… I’ll let you know if I find anything.

  8. So I found the issue with the touch not working… At least for those using the Mega 2560. (AND TOUCH SHIELD) You must use

    #define YP A1 // must be an analog pin, use “An” notation!
    #define XM A2 // must be an analog pin, use “An” notation!
    #define YM 7 // can be a digital pin—–uno=9 mega=23
    #define XP 6 // can be a digital pin—–uno=8 mega=22

    instead of whatever is there… This maps the correct inputs to the pins.

  9. Hi, thanks for your code, but I can’t press anything on the screen either.
    I tried the excample “tftpaintshield” and it works fine, pins: YP A1, XM A2, YM 7 and XP 6. I also have an uno and the adafruit shield. When I tried your pins, so YM 9 and XP 8, nothing works. Any idea what I’m doing wrong?
    Thanks in advance

  10. I am having the same issue as previous poster, with one added symptom: the screen draws a red rectangle over 75% of the screen.

    I am running the TFT breakout on an Arduino Mega 2560…

  11. Hi,

    Great job !! i have a similar TFT on a arduino shield and im very new at all this (just starting ) , can you please teach me how to change your TFT ( i think that they are defined in TFTLCD file but i dont have knowledge) the pins of my TFT on the arduino shield?
    my shield pin are:

    #define DB10 2
    #define DB11 3
    #define DB12 4
    #define DB13 5
    #define DB14 6
    #define DB15 7
    #define DB16 8
    #define DB17 9
    #define CS 11
    #define RS 13
    #define WR 12
    #define RD A0
    #define RESET 10

    Thanks a lot for charing your hard work

  12. Hello:

    Thanks for all your hard work, I’m having a little trouble. I recently purchased the 2.8 touchscreen(not the shield) from ladyADA. I’ve gotten it working fine with their examples, however your menu sketch won’t compile for me, it keeps saying that “TFTLCD does not name a type” that usually means that it can’t find the library. I am sure that I have it in the correct spot. Do you have any ideas what may be the problem. I did notice that LadyADA has changed their github files recently. Would you know where I could get an older copy of the LCDTFT h and ccp files?

  13. Hi

    Do you have any update on this, I just got a an TFT touch screen shield, and I really wna to test this great work of yours

    Thanks

  14. Hello Jeremy,

    First of all Kudoz with the JOS!! 🙂
    I’m trying to compile your JOS with Arduino 1.0.1 after installing the libraries found at adafruit. I think the libraries are altered, because i get some serious errors while compiling.
    ‘TFTLCD’ does not name a type.

    In file included from JOS.cpp:3:
    C:\Temp\arduino-1.0.1\libraries\TFTLCD/TFTLCD.h:88: error: expected class-name before ‘{‘ token
    JOS:47: error: ‘TFTLCD’ does not name a type
    JOS.cpp: In function ‘void setup()’:
    JOS:134: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void loop()’:
    JOS:234: error: ‘tft’ was not declared in this scope
    JOS:240: error: ‘tft’ was not declared in this scope
    JOS:246: error: ‘tft’ was not declared in this scope
    JOS:252: error: ‘tft’ was not declared in this scope
    JOS:258: error: ‘tft’ was not declared in this scope
    JOS:271: error: ‘tft’ was not declared in this scope
    JOS:277: error: ‘tft’ was not declared in this scope
    JOS:283: error: ‘tft’ was not declared in this scope
    JOS:289: error: ‘tft’ was not declared in this scope
    JOS:295: error: ‘tft’ was not declared in this scope
    JOS:308: error: ‘tft’ was not declared in this scope
    JOS:314: error: ‘tft’ was not declared in this scope
    JOS:320: error: ‘tft’ was not declared in this scope
    JOS:326: error: ‘tft’ was not declared in this scope
    JOS:332: error: ‘tft’ was not declared in this scope
    JOS:345: error: ‘tft’ was not declared in this scope
    JOS:351: error: ‘tft’ was not declared in this scope
    JOS:357: error: ‘tft’ was not declared in this scope
    JOS:363: error: ‘tft’ was not declared in this scope
    JOS:369: error: ‘tft’ was not declared in this scope
    JOS:382: error: ‘tft’ was not declared in this scope
    JOS:388: error: ‘tft’ was not declared in this scope
    JOS:394: error: ‘tft’ was not declared in this scope
    JOS:400: error: ‘tft’ was not declared in this scope
    JOS:406: error: ‘tft’ was not declared in this scope
    JOS:419: error: ‘tft’ was not declared in this scope
    JOS:425: error: ‘tft’ was not declared in this scope
    JOS:431: error: ‘tft’ was not declared in this scope
    JOS:437: error: ‘tft’ was not declared in this scope
    JOS:443: error: ‘tft’ was not declared in this scope
    JOS:456: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void clearcenter()’:
    JOS:565: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void clearsettings()’:
    JOS:579: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void homescr()’:
    JOS:585: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void menu1()’:
    JOS:594: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void menu2()’:
    JOS:603: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void menu3()’:
    JOS:612: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void menu4()’:
    JOS:621: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void menu5()’:
    JOS:630: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void settingsscr()’:
    JOS:639: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void showsleep()’:
    JOS:800: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void blbar()’:
    JOS:923: error: ‘tft’ was not declared in this scope
    JOS:926: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void ant()’:
    JOS:931: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void boxes()’:
    JOS:934: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void signal()’:
    JOS:942: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void signalact()’:
    JOS:962: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void drawhomeicon()’:
    JOS:982: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void drawhomeiconred()’:
    JOS:994: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void clearmessage()’:
    JOS:1006: error: ‘tft’ was not declared in this scope
    JOS.cpp: In function ‘void drawbatt()’:
    JOS:1011: error: ‘tft’ was not declared in this scope
    JOS:1015: error: ‘tft’ was not declared in this scope
    JOS:1018: error: ‘tft’ was not declared in this scope

    Can you supply the original libraries (maybe a downloadlink) so i can test with those?

    With kind regards,

    Billie

    • have the same issue…. figured this was a great way of starting a controller for a clothes dryer, in the end i aim for both touchscreen control and webpage…

  15. Billie,

    I too had trouble with it compiling. So I started going back in the Github history for the Adafruit TFT library and I found the most recent one that will work is the one from 3/30/2012. You should also download Arduino IDE vers 0022 and install it separately. Both of these combined should get the code to compile no problem.

    • Thanks Chris, I have an updated version of this software for the touchshield I will be posting within the next few days. It works with all the current libraries! 🙂

  16. Any update on the new software? Would really really love to use your menu on my screen and get it doing all kinds of cool stuff.
    Appreciate it,
    Nate

  17. Pingback: JOS – Updated!!! | The Custom Geek

Comments are closed.