Hi2cin problems when reading touch screen

JanJor

Member
Dear Forum, when I use (merely as an example) the command hi2cout 0, ("SD",1) (after HI2CSETUP) ,I can send this command to my touch screen (Digole 320x240 touchscreen). That works OK.
As I understand it, the command hi2cin 0,(B0,B1,B2,B3) should read a series of bytes that are send from the touchscreen to the Picaxe after I've sent the command hi2cout 0, ("RPNXYC").
However, the screen returns either 79, 2552, 255, 255 or 158, 60, 120, 240, depending on if the screen is touched or not. These values do not depend on where one touches the screen although this should be the case.
I now have two questions: 1) is the command hi2cin 0,(B0,B1,B2,B3) the right format for receiving a command from the slave (what is the meaning of the "0" ?) and 2) does the Picaxe (28x2) wait for an input forever, or does it continue after a time-out?
Attached is the programme I used.
Thanks very much in advance, Jan Jor.
 

Attachments

hippy

Ex-Staff (retired)
The datasheet I found doesn't describe the I2C packet format or protocol so it's not clear if the communications required to read a result can be achieved using consecutive HI2COUT plus HI2CIN. It is not explained how one is meant to wait for a result to be ready for reading.

You could try using some other command; "RPNXYI" which should return a touch result immediately, or "RDBAT", "RDTMP" to read the battery voltage and temperature respectively.

Is it possible for you to use the UART protocol rather than I2C which may be easier to handle ?
 

JanJor

Member
Thanks for your reply Hippy, RPNXYI, RPNXYW and RPNXYC all do not give a satisfactory result, but I didn't think of sending "RDTMP"to the touch screen. I'll try that first and see what happens. With regard to the UART protocol, I'm a real beginner. Never used that. I2C and serial are the two ways of communication I use with my good old Picaxes ;-)
 

JanJor

Member
Hi Hippy, I tried RDTMP and RDBAT and they both give w0 = 15518. Re-loading and restarting does not change the outcome. Very strange. I'm afraid that I have to dive into the UART stuff. I didn't find any info about UART protocol in the manual, but from Google I understand that it is a matter of connecting TX to RX and vice versa, and just trying to find the correct baud rate which usually should be 9600. Sounds easy, roughly like I would set up a connection between two picaxes using the HC-12 transceiver.
I'll give it a try !
Thanks again.
 

JanJor

Member
Hippy, sorry to bother you again. The baud rate of an older (non-touch) Digole screen I have (and that I now use for testing UART protocoll) is 9600. I assume that under the UART protocoll sending the command SEROUT b.0 ,N9600_8,("CL") or SEROUT b.0 ,T9600_8,("CL") should suffice to clear the screen. The command in I2C that I used is HI2COUT 0,("CL") and that works OK.
But SEROUT b.0 ,N9600_8,("CL") or SEROUT b.0 ,T9600_8,("CL") doesn't work. (b.o is the pin of my 28X2 that I've randomly chosen)
Did I make any obvious mistake?
Thanks again.
 

hippy

Ex-Staff (retired)
There doesn't seem to be a lot out there describing reading via I2c which clearly explains how things work but I would try this, see if the battery reading does give any meaningful values ...
Code:
#Picaxe 28X2
#Terminal 9600
#No_Data
#No_Table

PowerOnReset:
  HI2cSetup I2CMASTER, $4E, I2CSLOW, I2CBYTE
  Pause 3000
  SerTxd( "Started", CR, LF )
  HI2cOut ( "SOO", 1 )
  Pause 1000

BatteryLoop:
  Do
    HI2cOut ( "RDBAT" )
    HI2cIn 2, ( b1, b0 )
    b4 = b0 : Gosub ShowB4Hex
    b4 = b1 : Gosub ShowB4HexSpaced
    w1 = b0 * 256 + b1
    SerTxd( TAB, #w0, "mV", TAB, #w1, "mV", CR, LF )
    Pause 1000
  Loop

TouchLoop:
  Do
    HI2cOut ( "RPNXYI" )
    HI2cIn 4, ( b0, b1, b2, b3 )
    b4 = b0 : Gosub ShowB4Hex
    b4 = b1 : Gosub ShowB4HexSpaced
    b4 = b2 : Gosub ShowB4HexSpaced
    b4 = b3 : Gosub ShowB4HexSpaced
    SerTxd( CR, LF )
    Pause 1000
  Loop

ShowB4HexSpaced:
  SerTxd( " " )
ShowB4Hex:
  b5 = b4 / $10 + "0" : If b5 > "9" Then : b5 = b5 + 7 : End If
  b4 = b4 & $0F + "0" : If b4 > "9" Then : b4 = b4 + 7 : End If
  SerTxd( b5, b4 )
  Return
Then comment out the 'BatteryLoop:" to 'TouchLoop:' and see if that works for reporting any sensible values when touched.
 

JanJor

Member
Hippy, first of all, and I'm certainly not the only one on the forum, I'm always surprised how you manage to design a program in such a short time. To my regret, even your proposal did not work. I tried both the battery check and the temp check (RDTMP) but they both give the same figure, even if I cut loose the wire from the battery. Also, for the touchloop program that you proposed, I get 4F FF FF FF if I leave the screen untouched, and 9E 3C 78 F0 when I press the screen, regardless where I presss the screen. I actually bought two of these screens and I tested them both, but the outcome is the same. I think that I'l lhave to send them back to the vendor (DIGOLE), and forget about these touch screens. Anyway, thank you very much for your help, and maybe some other members will take a lesson from this issue. Thanks again!.
 

JanJor

Member
Hippy, further to my earlier post; your idea of trying UART for transmission between the Digole touch-screen and my Picaxe indeed worked well after all. I could not stand the idea of not getting this on the rails, so I spent many hours, but it works fine now with UART.
So I underestimated the display after all, I must admit. I2C does indeed not work for sending comments from the display to the Picaxe, but UART works fine in both directions.
I've attached the program that I used, so may be some other forum member can also use it.
Thanks,
Jan Jor
 

Attachments

lbenson

Senior Member
Glad you persisted and got it working.

You're likely to have more people look at your code if instead of attaching a file which must be downloaded and opened, you copy it into your post enclosed in the forum tags, "[ code]" and "[ /code]" (without the spaces). This allows indentations (if any) which show the block structure of the program to be retained.
 

JanJor

Member
Hi Ibenson, I thought that "attach files" was the way to attach files to questions, but here's the code for the 28X2:

setfreq m8

#no_data
#no_table

pause 6000 'This gives the display the time to start up.

serout a.0,T9600_8,("CL")
pause 50

serout a.0,T9600_8,("TP",10,0)
pause 1000
serout a.0,T9600_8,("TT","Apen",0) 'merely to ensure that transmission from Picaxe to Display is OK
pause 100

rep:

serout a.0,T9600_8,("RPNXYC")
pause 50

high b.7
sertxd("Start",#b1,13,10)

pause 200

low b.7
serin b.0,T9600_8,b1,b2,b3,b4
pause 50
sertxd("Watch this ",#b1," ",#b2," ",#b3," ",#b4," ",13,10)
goto rep
 

lbenson

Senior Member
Putting the code within the tags, "[ code]" and "[ /code]" (without the spaces) puts it in a scrollable box, and makes it more convenient for viewers, especially for programs which are not lengthy. Like so:
Code:
setfreq m8

#no_data
#no_table

pause 6000 'This gives the display the time to start up.

serout a.0,T9600_8,("CL")
pause 50

serout a.0,T9600_8,("TP",10,0)
pause 1000
serout a.0,T9600_8,("TT","Apen",0) 'merely to ensure that transmission from Picaxe to Display is OK
pause 100

rep:

serout a.0,T9600_8,("RPNXYC")
pause 50

high b.7
sertxd("Start",#b1,13,10)

pause 200

low b.7
serin b.0,T9600_8,b1,b2,b3,b4
pause 50
sertxd("Watch this ",#b1," ",#b2," ",#b3," ",#b4," ",13,10)
goto rep
If you do have indented blocks of code (like within IF...THEN, DO...LOOP, FOR...NEXT) the indentation will be preserved, whereas it will not be if the code is copied in without the tags.
 
Top