PyPortal Titano Touchscreen problem

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
chrisw63
 
Posts: 34
Joined: Thu Nov 07, 2013 5:39 pm

PyPortal Titano Touchscreen problem

Post by chrisw63 »

I ordered the PyPortal Titano on Oct 12, 2020, and received it 4 days later. (Order #2381944-7604027593). The demo code seemed to work okay, but the Learn guide said I should download the latest CircuitPython for it, so I did (it had one of the version 5's on it, replaced with the newest 6.0 at the time). I then downloaded the code for the PyPortal Alarm Clock and got it running (https://learn.adafruit.com/pyportal-alarm-clock). Yes, I know it's not for the Titano. But all the product info said the screen size was the only difference, and making the Titano into a high-tech alarm clock as a gift was the reason for getting it.

The Touch Screen seemed a little off with the original code. I could get to the Settings by touching the Alarm icon, but it would misbehave after that. Sometimes touching the alarm screen would do what it was supposed to, sometimes it wouldn't, and most of the time it would just return to the main Time screen. I figured this had to do with the screen size difference. I was wrong.

I proceeded to alter the graphics and the code, and got the basics running fine on the Titano. Once I had the graphics resized, I figured out the new touch areas for the various parts and changed them. Again, sometimes I could get the correct response and sometimes it wouldn't do anything, but most of the time it would just return to the main screen.

So I dove into the code. That State Machine was something new to me, so it took a little work. So was the Logging module, with so little documentation as to be annoying. In the REPL, dir(logging) showed me the Git URL. Almost no documentation in the Readme, and only a bit more in the code itself. I finally figured out it had levels of logging, so
I set it to DEBUG and added some logging.DEBUG() lines to the code.

And this is where I found the problem. Touching the screen looks to give the right numbers, but then as I remove my finger, more often than not it gives erroneous values that make it return to the Time screen - Usually x = 0 or very close to it, and y = close to the middle of the range. Which, coincidentally, is the Return touch area.

So I decided to try the PyPortal Titano Weather Station code. It needed an SD card to work, so I got one, formatted it to FAT32, and inserted it into the Titano. "No SD card found: timeout waiting for v2 card" I tried several things, including reformatting, another SD card (same brand - Patriot, if that helps?), and nothing worked. A web search
found references to problems with Samsung EVO SD cards, but nothing else, and no solutions.

As you can imagine, I'm feeling a bit frustrated by now. I thought I'd be working on the 3D printer model for the case by now, and I'm supposed to have it ready in two weeks. I can use the files for the Titano Weather Station for a reference, but I'm trying to fit a USB phone charger in the base, so it'll need some modifications. The only thing I can think to do is hack the adafruit_touchscreen code, but how? It would seem to need some kind of delay or averaging - ideally a routine that would throw out one time responses that don't conform to the average. But while I could hack something together to do that, I'm fairly sure it would slow everything down to a crawl. I'm less concerned with the SD card issue, but it would still be nice to get it solved. The price was a bit more than I'd normally be comfortable with for something just to hack. Making something that could be a nice gift was my justification, and that seems to be falling apart.

Please help me to finish this. Since my original schedule seems to be impossible, I'd like to try getting it done by Christmas. I've attached the modified code.py. The only other mods are the screen bmp's, which were simply scaled from 320 x 240 to 480 x 320.
Attachments
code.py
(18.27 KiB) Downloaded 6 times

User avatar
siddacious
 
Posts: 407
Joined: Fri Apr 21, 2017 3:09 pm

Re: PyPortal Titano Touchscreen problem

Post by siddacious »

I'm sorry to hear that you're having such a frustrating experience, I've been there and it sucks, especially when you're on a deadline.

CircuitPython 6.x is still in development so please try 5.x. There could well be a bug in 6.x however 5.x should be stable.

Regarding the button issue, I would try something like what you suggested to see if it does what you need and then optimize from there if it looks like performance is an issue. You would probably want to pass the whole touchscreen object into current_state.touch and then modify touch_in_button to take a number of readings with no sleep and average them. You can limit the amount of time by noting the start time and breaking from the loop when the current time- start time is greater than your threshold. Keep in mind that time.monotonic returns a value in seconds as a float, so 0.001 would be one millisecond.

Here is a timer class I wrote wrote and code that uses it that uses that approach:
https://github.com/adafruit/Adafruit_Ci ... 5/timer.py
https://github.com/adafruit/Adafruit_Ci ... t__.py#L33
https://github.com/adafruit/Adafruit_Ci ... __.py#L256
https://github.com/adafruit/Adafruit_Ci ... __.py#L626

User avatar
haroldf
 
Posts: 6
Joined: Sun Oct 11, 2020 12:20 pm

Re: PyPortal Titano Touchscreen problem

Post by haroldf »

I share chrisw63's frustration. I got my titano 10/8, loaded 6.0beta, and I used old-school debugging methods (print statements in the library code) to convince myself that the only solutions were to wait on an updated library (which I tried, no good) or to revert to 5.3.1, which I did last night. My basic wget() tests still failed, and while I was writing this post, I saw an email saying there was yet another library upgrade. I expressed my disappointment to tannewt on last week's deep-dive, and maybe (hopefully) that had some effect.

User avatar
lupis11
 
Posts: 14
Joined: Tue May 09, 2017 9:56 pm

Re: PyPortal Titano Touchscreen problem

Post by lupis11 »

I too have purchased the PyPortal Titino and am trying to convert the PyPortal Alarm Clock. I resized the graphics. I'm running the latest stable version 6.0.0 of CircuitPython. when I run it, I get an error that the time service requires a login/password. So I added my aio_username and aio_key to my secrets file as directed in the error. Now I get the following error: ValueError: {"error":"not found - that is an invalid URL, please check the API documentation at https://io.adafruti.com/api/docs to make sure your URL is correct"]. I'm not sure what URL its referring to. I could not find anything in the https://learn.adafruit.com/pyportal-alarm-clock web page about this. Have I missed something? Does anyone know what the problem might be?

User avatar
chrisw63
 
Posts: 34
Joined: Thu Nov 07, 2013 5:39 pm

Re: PyPortal Titano Touchscreen problem

Post by chrisw63 »

Comma. Almost certainly. The URL for Time is in imported code, which you probably didn't change. The AIO ID and Token are passed in the URL, and a missing comma in secrets.py will cause havoc if the compiler doesn't catch it. It's pretty much the only way the URL can be changed without editing one of the imported files.

So, check your secrets.py for commas after the entries you added. I forgot one the first time, but the compiler caught it and I got a different error. Every line in between the brackets needs a comma after it, except the last one. It should look like this (with your data instead of the fake entries, of course):

Code: Select all

# This file is where you keep secret settings, passwords, and tokens!
# If you put them in the code you risk committing that info or sharing it

secrets = {
    'ssid' : 'URSSID',
    'password' : 'UrWiFiPwD',
    'timezone' : "America/New_York", # http://worldtimeapi.org/timezones
#    'github_token' : 'fawfj23rakjnfawiefa',
#    'hackaday_token' : 'h4xx0rs3kret',
    'openweather_token' : '1234n1234n1234n1234n1234n',
    'celcius' : False,
    'city_id' : "BANNED",
    'aio_username' : 'aionamehere',
    'aio_key' : 'b1234n1234n1234n1234n1234'
    }

User avatar
lupis11
 
Posts: 14
Joined: Tue May 09, 2017 9:56 pm

Re: PyPortal Titano Touchscreen problem

Post by lupis11 »

Thanks for the reply chrisw63. You called it, I was missing the comma and that fixed it. I'm now experiencing the same issue with the touch screen you explained in your previous post. Were you able to find a solution to fix that issue?

User avatar
chrisw63
 
Posts: 34
Joined: Thu Nov 07, 2013 5:39 pm

Re: PyPortal Titano Touchscreen problem

Post by chrisw63 »

I reloaded everything, starting with CircuitPython 5.3.1 - the latest 5.x version. Absolutely no difference.

I've done some more code diving, and I don't have a solution for the intermittent position errors yet, but I have found one thing: I cannot get an X value above 320, nor a Y value above 240. It seems to be set to the same values used in the original PyPortal (320x240 screen) But the values used to set up adafruit_touchscreen - board.DISPLAY.width and board.DISPLAY.height return CORRECTLY (480x320) in the REPL when I import board manually.

One other thing, which I'm not sure is related: The file adafruit_pyportal.py has calibration numbers hard coded for the touchscreen. I'm fairly sure these cannot be the same for two different size touchscreens, but I have no idea how to determine them for this screen. I suspect this may be the issue with the constant false X=0's being returned by the touchscreen.

I'm going to need help here. I just cannot find the code limiting the X and Y values. The two files listed above seem to be doing everything right. I'm not that great with Python, and I just don't know how to go deeper to find the culprit. And I have no clue how to determine the correct calibration numbers.

Please Help.

User avatar
aob003
 
Posts: 4
Joined: Tue Apr 13, 2021 11:15 pm

Re: PyPortal Titano Touchscreen problem

Post by aob003 »

I also have the same issue with the 'x' coordinate on the touch screen, it often reverts to zero when the touch is in the middle of the screen.

Is it a calibration issue? has anyone managed to fix it?

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”