Shop OBEX P1 Docs P2 Docs Learn Events
Capacitive Multi-Touch example code — Parallax Forums

Capacitive Multi-Touch example code

RaymanRayman Posts: 14,670
edited 2012-10-08 14:04 in Propeller 1
Here's an example of how to interface to the Newhaven 5" capacitive touch touchscreen.
I'm using our DVI Graphics shield along with the touchscreen plugin.
But, this can also work with our NH4 adapter, Newhaven's adapter or your own adapter.
Should work with the 4.3" capacitive screens too with required changes to the display portion of the demo.

The interface is I2C, so it's was really easy to write the driver.
It tracks up to 5 fingertips, so it's kinda cool.

Also, it can detect the zoom in and out gestures all by itself.

5p0_CapTouchTest1 - Archive [Date 2012.07.15 Time 15.36].zip

Update: Now have it working with the low cost NH4 adapter and have a $3 breakout for the capacitive touch connector:
NH4_CapTouch_4p3.jpg

You just have to run 4 jumper wires as shown in the photo above...

Update2: Now demonstrated to work with Newhaven 5" LCDs...
«1

Comments

  • RaymanRayman Posts: 14,670
    edited 2012-07-16 03:25
    Here's a photo of how I've wired it up. There wasn't room for the 6-pin connector on this board, when I learned about these multi-touch screens, but I did fit in a 4-pin header to connect to the external 6-pin adapter. You only need 4 wires (vdd, gnd, SCL, SDA) to make it work.
    CT_Wiring.jpg


    Just be careful because pins 3&4 are reversed between board and 6-pin connector...
    1024 x 768 - 99K
  • TubularTubular Posts: 4,703
    edited 2012-07-16 17:05
    Nice work again Rayman

    Do you by chance offer a standing subscription service where we can just sign up, and you send us these goodies + bill as you get each device/chip up and running? :)
  • RaymanRayman Posts: 14,670
    edited 2012-07-16 17:18
    Sounds like a great idea :)
    The 5" multi-touch screens are little pricey, but I now see that multi-touch is really nice and probably worth the extra expense.
    You also don't have to calculate and judge Z (how hard you're pressing), the chip does all this for you...
  • T ChapT Chap Posts: 4,223
    edited 2012-08-16 14:01
    Rayman

    I unzipped the parts and put them into my prop folder. I get two errors that state:

    PSB2_i2cdriver relocation pointer error 0228
    PSB2_i2cdriver fatal unable to locate object to fix up 40

    This is on 2 different computers, the object is in the folder as I can load it. I was trying to test on the 4.3. Any thoughts?

    Ok that was BST, Proptool loads.
  • RaymanRayman Posts: 14,670
    edited 2012-08-16 15:09
    I've never seen that error before... Is this with the Parallax Prop Tool?
    You may have different versions of PSB2_i2cdriver now... Maybe try renaming this new one to something else...
  • T ChapT Chap Posts: 4,223
    edited 2012-08-16 16:31
    Well it loads with proptool but I do not have an sd card on my test rig so it is a blank screen. I will try to figure out how to adapt the 4.3 resistive demo graphics to the new capacitive demo. BTW if anyone is available to help program a demo for me please get in touch via PM. I have a newhaven 4.3 capacitive and need to get this up and running asap and have no experience with graphics or touch.
  • RaymanRayman Posts: 14,670
    edited 2012-08-16 16:50
    T Chap, I think you have the NH4 Paint Demo.
    What you might try is replace the PSB2_i2cdriver in that one with this new one.
    Then, copy the touchscreen example code from here into the paint program.
    Next, you could either have the code set pixels in the graphics area or draw text on the text area...


    BTW: How are you connecting to the I2C touchscreen 6-pin tail connector?
  • T ChapT Chap Posts: 4,223
    edited 2012-08-16 16:56
    I am doing just as the ribbon wire calls out the order. 1 = 3v3 2 gnd 3 scl 4 sda nc 5/6

    I will try that idea in a few minutes, thanks.
  • RaymanRayman Posts: 14,670
    edited 2012-08-16 17:28
    Ok, I've adapted the paint example for the Newhaven 4.3" capacitive touch touchscreen...
    Been putting it off for a long time, so thanks for asking for it...

    Let me know if this doesn't work for you:
    NH4_Paint3_CT - Archive [Date 2012.08.16 Time 20.26].zip

    It actually works better than I expected...
  • T ChapT Chap Posts: 4,223
    edited 2012-08-16 17:57
    I must not have the small ribbon connected correctly, no response on touch but the screen looks good. I can recheck the connections at the shop tomorrow and let you know.
  • RaymanRayman Posts: 14,670
    edited 2012-08-16 18:05
    Make sure you don't have SCL and SDA reversed... Also, if you're not using a regular Prop board on P28 and P29, you'll need a 10k pullup resistor on SDA... Also, make sure you don't have the ribbon connector in upside down...
  • T ChapT Chap Posts: 4,223
    edited 2012-08-16 18:23
    Ok good call, I am using a Prop stick which I believe has pullups to the on board eeprom. The ribbon was reversed, still no luck. I will have to retrace the connections tomorrow. Thanks
  • T ChapT Chap Posts: 4,223
    edited 2012-08-17 11:30
    I had a few things wrong, but that demo works great! Much better than the resistive. It looks like you don't have it checking for a range like the resistive, so I without having looked at it much I assume that it is either being touched or not to the code. But, it does respond to the lightest touch so that is the goal for my project anyway. Thanks for putting all this stuff together.
  • T ChapT Chap Posts: 4,223
    edited 2012-08-17 12:06
    This is my first steps with graphics and LCDs, and I want to learn how to create some bitmaps for elements on the screen like buttons, logos, other graphics. I notice in the paint demo there are some externally loaded dat files that appear to hold the button image info. Can someone tell me how to go about creating elements like that? I also will be using the LCD in vertical modes on occasion, and would like to flip the graphics over. Is that something that must happen in the original bitmap or can the bitmaps be flipped during or after loading?
  • RaymanRayman Posts: 14,670
    edited 2012-08-17 14:52
    T Chap, glad you got capacitive touch working with the NH4! It really does work better than I expected with the paint program. I didn't think it would do smooth curves, but it does very well. It's also nice how you don't really need to push on it at all.

    The driver works just like the VGA driver. You can find apps to make 1 and 2-bit bitmaps on my website. There is also a very long thread around about the Samsung version of this driver... (actually the drivers are almost identical, it's mostly just the backlight circuit that is different).
  • T ChapT Chap Posts: 4,223
    edited 2012-08-19 09:34
    Rayman. I used the Prop Interleaved Generator to make a little symbol. I want the display to be background black for default for now, and the letters and other icons to be white. I loaded the bmp of 'logo' into the 1bitmap program you made, exported the .dat. For some reason the LCD shows the logo plus some chopped off part of one of the buttons you made. If i delete the other parts of the code that load the buttons, the screen stays blue and never shows anything. Is it possible to just show this one symbol, then create more symbols like and stick them together to create words? Secondly, the char gen only allows for vertical oriented chars, but I may have versions of the LCD flipped vertical, in which case is it doable in SPIN to flip the data by 90 degrees or does the bit map have to be flipped for example in any image editor(photoshop, preview etc), then resaved?

    The goal is to create some white icons, logos, text, arrows, etc, then position on the screen in a horizontal or vertical manner.

    Thanks for all the hard work putting those apps together.
  • RaymanRayman Posts: 14,670
    edited 2012-08-19 10:07
    T Chap, there's one unfortunate "trick" to making this work... We have to align all the graphics to a 16-long boundary before using them...
    This is done at the beginning of the code...
    But, in some earlier versions of code, you need to manually specify how many tiles worth of graphics need to be moved. I think it was usually called "nuchars".
    If you have the wrong number there, bad things will happen.

    In newer codes, I have it automatically do this...
  • T ChapT Chap Posts: 4,223
    edited 2012-08-19 10:42
    Since what I want is static and small parts to display, maybe I need just a simple method of turning on pixels on the screen from SPIN versus loading bit maps?
  • RaymanRayman Posts: 14,670
    edited 2012-08-19 11:34
    Well, another option is to use one or more "Graphics" areas and use "Graphics.spin" to control them.
    This uses up a lot of memory, but you can save room by making it single buffered instead of double buffered...

    You can start from the NH4 Paint example to do it this way...
  • T ChapT Chap Posts: 4,223
    edited 2012-08-19 12:50
    Not sure if you meant graphics demo instead, but stripping out all the graphics animation code and using only plot allows easy access to create fonts in any direction, etc. This is perfect for the task.
  • RaymanRayman Posts: 14,670
    edited 2012-08-19 12:56
    Ok, great, that should work too.
  • T ChapT Chap Posts: 4,223
    edited 2012-08-19 13:02
    Only one thing left, can an arc be something other than a perfect circle? Or can an acr be changed to an ellipse?

    EDIT Nevermind, dumb question.
  • T ChapT Chap Posts: 4,223
    edited 2012-08-19 15:37
    This is very close to how I need it to work. It allows drawing plots, lines, arcs etc to create the graphics for the user interface, and also upon touching the screen allows ti show the counter on the screen for feedback for testing. The only problem is the background color. In this version, the screen is solid blue, but I am after solid black. I have found some ways to create a black rectangle like in your button test demo, but when trying to expand the black area to fill the screen the ram is exceeded. Can you please have a look and let me know if it is possible to have the custom graphic elements in white( or gray ) and allow the background to be set at solid black or other solid background?
  • RaymanRayman Posts: 14,670
    edited 2012-08-19 16:54
    I can take a look at tomorrow... But, perhaps the problem is the default text background...
    This is defined by the first two longs under "vgacolors"

    Try changing the numbers here and see if that helps:
    DAT
    vgacolors               long
                            long    $F00CF00C       'blue background with yellow letters
                            long    $F0F00C0C
    

    BTW: I have a vga colors app on my website that might help decipher these values...


    All zeros should be black on black...
  • T ChapT Chap Posts: 4,223
    edited 2012-08-19 17:12
    Awesome, that does it.
  • RaymanRayman Posts: 14,670
    edited 2012-08-19 17:38
    Great! BTW: Just got the Newhaven 5" capacitive touch LCD working with NH4.
    This was a quick mod, but kinda fun.
    You can see by how small the graphics area looks, how much bigger resolution and DPI you get with the 5" screen:

    5p0_NH4.jpg
    NH4_5p0_Paint.jpg
    1024 x 768 - 94K
    1024 x 768 - 77K
  • T ChapT Chap Posts: 4,223
    edited 2012-08-19 17:43
    Ok problem still only partially solved. The background can go to solid black by changing the default vga colors. But, it seems like there is still some area of screen that is available to add my custom graphics so that it actually appears. If the x_tiles and y_tiles exceeds 22x17 then there isn't enough memory(optimizing in BST). This means although the whole screen is black, once anything goes past X175(0 = center screen), nothing shows up. I need to use the entire screen for buttons and other parts. Is there a workaround? Since the screen background is black, can the vga values be reduced from many colors down to just black for the background and reduce the memory?

    EDIT you said to run in single buffer to save memory but I cannot find what that means or where to change it from dual.
  • RaymanRayman Posts: 14,670
    edited 2012-08-20 03:39
    The graphics demo is double buffered... In the CON section you can see that "bitmap_base" and "display_base" have different addresses.
    The "Paint" example is single buffered and these values have the same addresses.

    But, even with single buffering, I don't think there's enough HUB RAM to cover the whole screen with graphics. But, you can do most of it.
    The Paint example saves memory by using 2-bit bitmaps for buttons.
  • T ChapT Chap Posts: 4,223
    edited 2012-08-20 05:21
    bitmap_base = $8000-GraphicsBytes'$5000 'these are the same because not double buffering...
    display_base = $8000-GraphicsBytes'$5000

    This is what I have that was the original, I never changed it. There are only several graphic parts to display, but they are from one end to the other with large sections of black in between. Instead of declaring one large area for graphics, can I call several sections only where the graphics need to live?
  • RaymanRayman Posts: 14,670
    edited 2012-08-20 06:04
    Yes, it is possible to have several graphics windows at different places on the screen.
    I just took a quick look for an example, but didn't see one...

    As I recall, you just create several instances of the "Graphics" object and treat them all individually...


    Memory allocation might be the hard part... You might need something like this:
    bitmap_base1 = $8000-GraphicsBytes1'    'these are the same because not double buffering...
    display_base1 = $8000-GraphicsBytes1
    
    bitmap_base2 = $8000-GraphicsBytes1-GraphicsBytes2'    'these are the same because not double buffering...
    display_base2 = $8000-GraphicsBytes1-GraphicsBytes2
    
    
Sign In or Register to comment.