Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 08:19 17 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Micromite V4.7 Beta 8

     Page 1 of 2    
Author Message
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 11:06pm 26 May 2015
Copy link to clipboard 
Print this post

I have a new beta version of V4.7 for the Micromite for anyone who would like to try it out. It can be download it using this link:
http://geoffg.net/Downloads/Micromite/Micromite_4.7_Beta8.zip

This has three major changes over beta 3.

- The character set of font 2 has been expanded to include the space, plus, minus and equals characters in addition to the existing numbers and colon.

- The SPI port can also be used within a BASIC program at the same time as it is being used with the LCD and touch controllers.

- CFunctions now have the ability to call some functions within MMBasic. This means that they can do more intelligent things. As an example, included in the zip files are new versions of SerialTx and SerialRx that now work with any I/O pin (you simply specify just the pin number, no lookup table is required). @G8JCF will be updating his tutorial to suit and I believe that @matherp will have some new and interesting CFunctions that use this new ability. Great thanks to both of these gentleman who helped to refine this feature.

Also included are the updated pages from the Micromite Manual describing the new features (changes are highlighted in yellow).

Geoff

Geoff Graham - http://geoffg.net
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1139
Posted: 04:36am 27 May 2015
Copy link to clipboard 
Print this post

Thanks Geoff, thanks PeterM!

  Quote  The SPI port can also be used within a BASIC program at the same time as it is being used with the LCD and touch controllers.


That's fantastic!



Do you think that we can get an extension of the PEEK function to locate the character set table (to replace some characters using POKE e.g. "°" the degree sign)?



  Quote  CFunctions now have the ability to call some functions within MMBasic.


That's seems to open a new world!

Regards
Michael

EDIT:
The chr$(127) looks a bit strange! Or I need glasses. Edited by twofingers 2015-05-28
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8603
Posted: 05:01am 27 May 2015
Copy link to clipboard 
Print this post

  Quote  Do you think that we get an extention of the PEEK function to locate the character set table (to replace some characters using POKE e.g. "°" the degree)?


Michael

The font table is in flash so can't be changed with POKE. You can use the Bitmap command to output any arbitrary 8x8 bitmap.

Try
bitmap x,y,&H0000000c12120c00 Edited by matherp 2015-05-28
 
twofingers
Guru

Joined: 02/06/2014
Location: Germany
Posts: 1139
Posted: 05:47am 27 May 2015
Copy link to clipboard 
Print this post

Hi Peter,

thanks for the quick clarification!
Maybe I can patch the hex file. For your Graphic Library I replaced chr$(127) with the degree symbol. BITMAP can serve as a workaround, I think. But the degree symbol in the character set would be more convenient. I'm lazy! [)]

Regards
Michael

EDIT:
  Quote  Try
bitmap x,y,&H0000000c12120c00

or
BitMap 10,20,&HFFFFFFF3EDEDF3FF (black on white)
BitMap 10,30,&H0000000006090600
BitMap 10,60,&HFFFFFFFFF9F6F9FF (black on white)

Jims(Tassyjim) font editor (called "fontoMite") can be a tool for creating bitmap patterns. Edited by twofingers 2015-05-28
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 12:43pm 27 May 2015
Copy link to clipboard 
Print this post

Very nice additions Geoff..!

I love the "auto control" of the CS pin... Makes it dead easy for the end user to get things working... Ok... as you close the SPI port, the CS pin goes back to open pin assignment... So, each SPI device's CS pin needs a soft (10k) pull-up to keep it off the bus... Also, should there be pull-up's for the display and touch controller also..?

Not trying to be a pest, but wanted to set my thinking straight on this from the get-go...
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 01:55pm 27 May 2015
Copy link to clipboard 
Print this post

Hi Zonker,

My thinking was that before any command was run (SPI OPEN, CONFIG LCDPANEL, etc) the chip select pins could be used for anything - therefore they should not have a soft pullup enabled.

After they are opened they are driven by the firmware both high and low so no pullups are required.

I am not sure that many programs would want to close the SPI channel after it was opened but if they did, and they wanted CS to be high, then yes, an external pullup would be required. If CONFIG LCDPANEL DISABLE was used the user obviously does not want to use the LCD any more so the chip select (and other pins) should go to unconfigured as they were before CONFIG LCDPANEL was used.

Geoff
Geoff Graham - http://geoffg.net
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 02:07pm 27 May 2015
Copy link to clipboard 
Print this post

  twofingers said  The chr$(127) looks a bit strange! Or I need glasses.

No, your eyes are OK. That is a bug, the character is not in the printable character set and therefore should have printed as a blank (I will fix it in the next release).

By the way, in this version unprintable characters will print as a space. I thought that this was more helpful than the previous version which did nothing.

Geoff
Geoff Graham - http://geoffg.net
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 06:27pm 28 May 2015
Copy link to clipboard 
Print this post

Beta 8 meter test... (more playing)...

2015-05-29_042724_2-4_inch_meter_test.zip
 
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 07:32am 30 May 2015
Copy link to clipboard 
Print this post

Just tried your meter code Zonker. Very cool. Thanks for posting!
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 06:38pm 30 May 2015
Copy link to clipboard 
Print this post

Gday Zonker,

Hey! I love that Meter test..

Any chance of implementing it to read actual ANALOG inputs ?

Regards,

Mick
Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
ThierryP
Newbie

Joined: 12/04/2012
Location: Netherlands
Posts: 12
Posted: 11:49am 31 May 2015
Copy link to clipboard 
Print this post

Tested the Micromite with 4.7 beta 8 on a "HY-1.8 SPI" display I had lying around.
Works OK, which I hoped it would, as it's an ST7735 with same specs as advised in the manual.
Difference: works with 3.3V or 5V and has a LED current limiting resistor built-in.

see: Ebay
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 12:18pm 31 May 2015
Copy link to clipboard 
Print this post

@bigmik

Ok... get R1=100k and R2=20k and a .1 cap and attach it to pin 5... This should scale down the 20 volt scale back in range... Then run this...

2015-05-31_221800_2-4_inch_volt_meter_demo.zip

Works OK here...
 
bigmik

Guru

Joined: 20/06/2011
Location: Australia
Posts: 2870
Posted: 12:44pm 31 May 2015
Copy link to clipboard 
Print this post

Hi Zonker,

Have I missed something here?
It must be too early in the morning for me.

20V range is on the `meter' ... Where would I connect the R1, R2 and Cap?

I would have just fitted a potentiometer between 3v3 and GNd with the wiper on pin(5) and adjusted the scale to read 0-3.3 or similar..

Regards,

Mick


PS.

Ohhh, I am waking up... I think you intend me to connect up to 20V with a voltage divider that would make the max reading 1/6 of 20v or 3.3v on pin(5) with presumably a smoothing cap pin(5) to Gnd??


Mik



Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<<
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2794
Posted: 01:22pm 31 May 2015
Copy link to clipboard 
Print this post

Mike,

I was wondering where the 20v had come from too - was that another thread?

If anyone tries this, can they post a video please?

WW
For everything Micromite visit micromite.org

Direct Email: whitewizzard@micromite.o
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 03:30pm 31 May 2015
Copy link to clipboard 
Print this post

Yep... That was the Idea...

Of course, you can play around with the code and make the meter scale to be different.. I figured 20v would be useful for something..!

The main thing, is to try creating more GUI toys to share about..!!

I kinda like the graph chart trend display..!!

These touch panels are awesome....
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 05:05pm 09 Jun 2015
Copy link to clipboard 
Print this post

Good evening Gents...

I must admit to a little head scratching going on here...

I am trying to talk to an external SPI chip while running the 2.4" touch panel and just keep getting back zeros for the IC data.. After looking through the PDF, and trying several things, I'm kind of stuck, not knowing what to try next...

I am trying to read the status reg inside the IC. To do that you need to send the read command byte, (value=3), address MSB byte, (0) address LSB byte, (0) and then read back the value of the status reg...

So, taking the advice in the PDF, I let MMBasic control the SPI CS pin and setup a simple test:


Sub LTCread_status_reg
SPI open 4000000,0,8,26 ' 4meg speed, mode 0, 8bits, CS=26
SPI write 3,3,0,0
SPI read 1, LTCrxdata%(1)
SPI close
end sub


I do dim the LTCrxdata var before calling. If I unplug the IC I do get back the expected 255 (hex FF) so I think the hardware and code snippet are working...

I guess the first question is how does the CS get turned on and off... Each transaction in the snippet starts by opening the SPI port, then starting to do the write command... this should drop the CS line low.. After completing the read command, the SPI port is closed.. (just like the example in the PDF)

Now, to me, this doesn't make sense... If you close the SPI port. the CS pin will be "de-inited" back to a floating pin, and without a pull-up, might interfere withe the LCD display... I would like to open the the SPI port just once and leave it open...
If I do that, then how does the MM firmware know when the CS pin needs to go high..?

Or, does it cycle the CS pin on every read or write command..? If so, this could be the cause of my problem.. The CS pin must stay low during the writing and reading commands as a group... It's to late tonight to get out the scope to check...

I have two 28pin based DIP-600-28 boards both running v4.07 beta 8 firmware

The original program without the LCD installed is using the standard SPI type commands and was written for the v4.6B firmware and works fine... I then moved it to v4.07B8 firmware on the first board and works just fine using the standard SPI commands as used in v4.6B...

The second board has the LCD installed... It was tested and the touch cal went OK... I can write a "time$" string to it and seems to work correctly...
I tried at first using the program "as-is" but kept getting back zeros...

So, after going over the examples again in the PDF, i decided to rewrite the subroutine like above and test it... yep, still getting back zeros...

Yikes.. Losing beard hair over here..!!

Has anyone else tried doing this type of setup..?

Any feedback might help...
Thanks Gent's..!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8603
Posted: 09:32pm 09 Jun 2015
Copy link to clipboard 
Print this post

  Quote  Or, does it cycle the CS pin on every read or write command..?


It has to do this as otherwise a graphic or touch call between two SPI calls will fail.

  Quote  The CS pin must stay low during the writing and reading commands as a group...


In this case you must handle CS manually rather than letting the software do it for you.

I think there may be a case for a new SPI command "SPI exchange" in which the outgoing data is replaced with the incoming data. Thus would allow you to combine the write and read commands into a single statement. Remember in all SPI transactions at a hardware level a databyte is read for each byte output and visa versa
 
Zonker

Guru

Joined: 18/08/2012
Location: United States
Posts: 761
Posted: 05:03pm 10 Jun 2015
Copy link to clipboard 
Print this post

I tried going back to controlling the CS with the old routines and still got back zeros... So, I disabled touch and LCD and hit run again... Works like a champ... Next , i tried pulling up the SPI data pins with a 2.2k resistor to see if that would help... No luck... I will try connecting just a single channel thermo IC to see if that is affected also...

Has anyone else out there tried the SPI Port..?

Will keep playing...
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3167
Posted: 09:39pm 10 Jun 2015
Copy link to clipboard 
Print this post

  Quote  does it cycle the CS pin on every read or write command..?

Yes it does... and that I think is the cause of the problem.

This issue with SPI has been causing me some angst also. Sharing the SPI with the display and touch is not as easy as it first seems. The main problem is that SPI is not really standardised, especially the behaviour of the chip select signal.

My thinking at this time is that it is best to scrap the idea of letting MMBasic manipulate the CS pin and trying to switch configurations back and forth.

So, in your program you should initialise CS and manipulate as you wish. This means that pullup resistors are not required. Also, the SPI port should be opened just before any send/receive and closed straight after. Between the OPEN/CLOSE you should not use a command that sends something to the display or use the TOUCH() function - MMBasic will throw an error if you do (in the next beta).

The following example (using your code) will work in the current beta:


' initialise everything
DIM LTCrxdata%(2)
PIN(26) = 1
SETPIN 26, DOUT ‘ pin 26 will be used as the enable signal
' other stuff including possible display and touch commands

LTCread_status_reg ' get the status reg
' more general code including possibly more display and touch commands

LTCread_status_reg ' get the status reg for a second time
' more stuff

END

' sub to get the LTC status
Sub LTCread_status_reg
SPI open 4000000,0,8 ' 4meg speed, mode 0, 8bits
PIN(26) = 0 ' chip select low
SPI write 3,3,0,0
SPI read 1, LTCrxdata%(1)
PIN(26) = 1 ' chip select high
SPI CLOSE
end sub


Does this sound workable?

Geoff
Geoff Graham - http://geoffg.net
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8603
Posted: 09:45pm 10 Jun 2015
Copy link to clipboard 
Print this post

Zonker

I've just tested this by patching the touch controller across to another pair of control pins. So I have "option touch 3,4" and "option lcdpanel ili9341,p,15,9,11" set up

The touch control pins are then actually connected to pins 2,1

The attached program then works fine.


'Display commands on MX170:
'
'DISPLAY OPEN displayname, command/data pin, chip select pin, reset pin
' Valid displaynames are ILI9341 and ILI9163
'DISPLAY CLOSE
'DISPLAY xstart, ystart, foreground colour, background colour, textstring, (optional x-scale, or x and y if only this parameter specified),(Optional y-scale)
'PIXEL x-coordinate, y-coordinate, colour
'LINE x-start-coordinate, y-start-coordinate, x-end-coordinate, y-end-coordinate, colour
'CLS (optional parameter colour)
'BOX x-coordinate, y-coordinate, width, height, colour, (optional parameter F to fill)
'CIRCLE x-coordinate, y-coordinate, radius, colour, (optional parameter F to fill)
'TRIANGLE x1-coordinate, y1-coordinate, x2-coordinate, y2-coordinate, x3-coordinate, y3-coordinate, colour, (optional parameter F to fill)
'BITMAP x-coordinate, y-coordinate, foreground colour, background colour, bitmap (long long integer giving 8 x 8 bitmap).
' The code treats this as an array of type char[8]. This is read bit7 to bit0, array-index[0] to array-index[n]. The screen then updates the 8 x 8 box top left to bottom right.
'RBOX x-coordinate, y-coordinate, width, height, radius of corners, colour, (optional parameter F to fill)
'ROTATE orientation. Orientation can be:
' 0: Portrait
' 1: Portrait 180
' 2: Landscape
' 3: Landscape 180
'
'
option explicit
option default NONE
CPU 48
'
const NSAMPLES=9 'number of times to sample each touch point
const t_CS=2 'chip select pin for XPT2046 touch controller
const T_IRQ=1 'interrupt pin for XPT2046 touch controller
DIM INTEGER XLEFT0, XRIGHT0, YTOP0, YBOTTOM0 ' global variables to hold calibration values
DIM INTEGER XLEFT, XRIGHT, YTOP, YBOTTOM ' global variables to hold active values
DIM INTEGER xvalues(NSAMPLES-1),yvalues(NSAMPLES-1)' arrays to hold raw sample values
pin(t_CS)=1
setpin t_irq,din
setpin t_cs,dout
CONST default_rotation=0 'default screen orientation for this display type, in this case portrait
const screen_width=240 'width of display in use
const screen_height=320 'height of display in use
dim integer width=screen_width, height=screen_height 'set active values based on default orientation
' 0=portrait, 1=portrait inverted, 2=landscale, 3=landscape inverted
DIM integer XSAMPLE0=&H90 'parameters to hold XPT commands, these may be reversed by the calibration routine
'for a particular application these values can be saved and set as constants
DIM integer YSAMPLE0=&HD0
DIM INTEGER XSAMPLE, YSAMPLE
'
dim integer x,y 'main program variables
'
spi open 1000000,3,8
'
pause 1000
T.calibrate 'calibrate the touch sensor
xleft=xleft0: xright=xright0 : ytop=ytop0 : ybottom=ybottom0 ' set the parameters for the default orientation
'for a particular application these values can be saved and set as constants
main:
if t.screenpos(x,y,1000) then
if x>3 and x<width-3 and y>3 and y<height-3 then circle x,y,3
endif
goto main

sub T.rotate(r as integer)
local integer temp
rotate r 'set the screen rotation
if default_rotation\2=r\2 then
XSAMPLE=XSAMPLE0
YSAMPLE=YSAMPLE0
width=screen_width
height=screen_height
if r=default_rotation then
xleft=xleft0: xright=xright0 : ytop=ytop0 : ybottom=ybottom0
else
xleft=xright0: xright=xleft0 : ytop=ybottom0 : ybottom=ytop0
endif
else
XSAMPLE=YSAMPLE0
YSAMPLE=XSAMPLE0
width=screen_height
height=screen_width
if ((r mod 2) = (default_rotation mod 2)) then
if default_rotation=2 then
xleft=ybottom0
xright=ytop0
ytop=xleft0
ybottom=xright0
else
xleft=ytop0
xright=ybottom0
ytop=xright0
ybottom=xleft0
endif
else
if default_rotation=0 then
xleft=ybottom0
xright=ytop0
ytop=xleft0
ybottom=xright0
else
xleft=ytop0
xright=ybottom0
ytop=xright0
ybottom=xleft0
endif
endif
endif
end sub
'
sub T.calibrate 'gets the orientation correct and then sets global variables XLEFT0, XRIGHT0, YTOP0, YBOTTOM0
LOCAL integer x,y,refsize=(height+width)/100, refoffset=refsize\2, charsize=refsize\3
print ""
XSAMPLE=XSAMPLE0
YSAMPLE=YSAMPLE0
if (refsize mod 2) then refsize=refsize+1
if charsize=0 then charsize=1
SWITCHXY:
box 0,height\2-refoffset,refsize,refsize
text width\2-charsize*4*6,height\2-charsize*4,"Touch box"
print "Touch left edge in centre"
T.gettouch(xleft0,y)
if xleft0>500 and xleft0<1500 then 'Switching orientation
XSAMPLE0=&HD0:XSAMPLE=XSAMPLE0
YSAMPLE0=&H90:YSAMPLE=YSAMPLE0
GOTO SWITCHXY
endif
PRINT "XSAMPLE0=",hex$(XSAMPLE0)
PRINT "YSAMPLE0=",HEX$(YSAMPLE0)
print "XLEFT0=",xleft0
cls : pause 1000
box width-refsize,height\2-refoffset,refsize,refsize
text width\2-charsize*4*6,height\2-charsize*4,"Touch box"
print "Touch right edge in centre"
T.gettouch(xright0,y)
print "XRIGHT0=",xright0
cls : pause 1000
box width\2-refoffset,0,refsize,refsize
text width\2-charsize*4*6,height\2-charsize*4,"Touch box"
print "Touch top edge in centre"
T.gettouch(x,ytop0)
print "YTOP0=",ytop0
cls : pause 1000
box width\2-refoffset,height-refsize,refsize,refsize
text width\2-charsize*4*6,height\2-charsize*4,"Touch box"
print "Touch bottom edge in centre"
T.gettouch(x,ybottom0)
print "YBOTTOM0=",ybottom0
cls : pause 1000
end sub
'
function T.screenpos(x as integer, y as integer, timeout as integer) as integer
local integer j
IF T.getxy(xvalues(),yvalues(),timeout,NSAMPLES)<>0 then
' j=shellsortARM(xvalues(),NSAMPLES) 'uncomment to use sort as required
j=shellsortMX(xvalues(),NSAMPLES) 'uncomment to use sort as required
' j=shellsortARM(yvalues(),NSAMPLES) 'uncomment to use sort as required
j=shellsortMX(yvalues(),NSAMPLES) 'uncomment to use sort as required
x=xvalues(NSAMPLES\2) 'get the median value
y=yvalues(NSAMPLES\2) 'get the median value
if xleft>xright then 'x coordinates reversed
if x<xright then x=xright
if x>xleft then x=xleft
x=width-((x-xright)*width/(xleft-xright))
else 'x coordinates normal
if x<xleft then x=xleft
if x>xright then x=xright
x=(x-xleft)*width/(xright-xleft)
endif
if ytop>ybottom then ' y coordinates reversed
if y>ytop then y=ytop
if y<ybottom then y=ybottom
y=height-((y-ybottom)*height/(ytop-ybottom))
else 'y coordinates normal
if y<ytop then y=ytop
if y>ybottom then y=ybottom
y=(y-ytop)*height/(ybottom-ytop)
endif
T.screenpos=1
else
T.screenpos=0
endif
end function

sub T.gettouch(x as integer, y as integer)
local integer j, n=51,xvalues(n-1),yvalues(n-1)
loophere:
x=-500
IF T.getxy(xvalues(),yvalues(),1000,n)<>0 then
j=shellsortMX(xvalues(),n) 'change to use sort as required
j=shellsortMX(yvalues(),n) 'change to use sort as required
x=xvalues(n\2) 'get the median value
y=yvalues(n\2) 'get the median value
endif
if x=-500 then goto loophere
end sub
'
function T.Getdata(command as integer) as integer 'get data from the touch controller
local integer i,j,k
pin(T_CS)=0
i=spi(command)
j=spi(0)
k=spi(0)
pin(T_CS)=1
T.Getdata= (j*256+k)>>4
end function
'
function T.getxy(x() as integer, y() as integer, timeout as integer, samples as integer) as integer
local integer i
timer=0
T.getxy=1
for i=0 to samples-1
do while timer<timeout and pin(T_IRQ)=1:loop
if timer>=timeout then
T.getxy=0
else
y(i)=T.getdata(YSAMPLE)
x(i)=T.getdata(XSAMPLE)
endif
next i
end function
'
CFunction shellsortMX
00000000
8ca20000 27bdfff8 afb10004 afb00000 00401821 00032fc2 00a31821 00031843
5060003d 00001021 0062282a 10a0fffa 00032fc2 00036823 000370c0 000d60c0
008e7021 0080c021 008c8021 00607821 0000c821 01e3282a 01c03021 8dd10000
14a0001e 8dcb0004 8f070004 03202821 0167402a 11000034 8f090000 01e04021
000840c0 00884021 00a3502a 02003021 ad090000 1540000f ad070004 8cc70004
8cc90000 0167402a 00ad5021 1100001f 00cc3021 00a04021 01402821 000840c0
00884021 00a3502a ad090000 1140fff3 ad070004 000528c0 00853021 25ef0001
01e2282a acd10000 accb0004 27390001 25ce0008 27180008 14a0ffd6 26100008
00032fc2 00a31821 00031843 1460ffc7 0062282a 00001021 00001821 8fb10004
8fb00000 03e00008 27bd0008 14ebffe9 0229402b 5100ffe8 000528c0 00a04021
1000ffde 01402821 54ebffe5 25ef0001 0229402b 5500ffca 01e04021 1000ffe0
25ef0001
End CFunction
 
     Page 1 of 2    
Print this page
© JAQ Software 2024